summaryrefslogtreecommitdiffstats
path: root/WebKit/qt/tests/util.h
diff options
context:
space:
mode:
Diffstat (limited to 'WebKit/qt/tests/util.h')
-rw-r--r--WebKit/qt/tests/util.h28
1 files changed, 27 insertions, 1 deletions
diff --git a/WebKit/qt/tests/util.h b/WebKit/qt/tests/util.h
index 7f7e613..15af262 100644
--- a/WebKit/qt/tests/util.h
+++ b/WebKit/qt/tests/util.h
@@ -18,6 +18,33 @@
*/
// Functions and macros that really need to be in QTestLib
+#include <QEventLoop>
+#include <QSignalSpy>
+#include <QTimer>
+
+/**
+ * Starts an event loop that runs until the given signal is received.
+ * Optionally the event loop
+ * can return earlier on a timeout.
+ *
+ * \return \p true if the requested signal was received
+ * \p false on timeout
+ */
+static bool waitForSignal(QObject* obj, const char* signal, int timeout = 10000)
+{
+ QEventLoop loop;
+ QObject::connect(obj, signal, &loop, SLOT(quit()));
+ QTimer timer;
+ QSignalSpy timeoutSpy(&timer, SIGNAL(timeout()));
+ if (timeout > 0) {
+ QObject::connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit()));
+ timer.setSingleShot(true);
+ timer.start(timeout);
+ }
+ loop.exec();
+ return timeoutSpy.isEmpty();
+}
+
// Will try to wait for the condition while allowing event processing
#define QTRY_VERIFY(__expr) \
do { \
@@ -45,4 +72,3 @@
} \
QCOMPARE(__expr, __expected); \
} while(0)
-