summaryrefslogtreecommitdiffstats
path: root/tests/auto/quick/shared
diff options
context:
space:
mode:
authorDavid Faure <david.faure@kdab.com>2016-10-23 20:22:52 +0200
committerDavid Faure <david.faure@kdab.com>2016-11-29 15:06:18 +0000
commitc0950098f3a7d4994ff07b06b8ff32e2a60ee7bf (patch)
tree30a76adcebee0dd93d63420eab125c148bac1423 /tests/auto/quick/shared
parent01c029fd90162bdbbcf9534537f26138a333c570 (diff)
Port autotests from own waitForSignal() to QSignalSpy::wait()
I added QSignalSpy::wait() in Qt 5.0 exactly for this purpose. Change-Id: I895a92f5f7e4e8554e00f6668e6973cc2c903adf Reviewed-by: Peter Varga <pvarga@inf.u-szeged.hu> Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'tests/auto/quick/shared')
-rw-r--r--tests/auto/quick/shared/util.h32
1 files changed, 6 insertions, 26 deletions
diff --git a/tests/auto/quick/shared/util.h b/tests/auto/quick/shared/util.h
index 063caa766..674c2da34 100644
--- a/tests/auto/quick/shared/util.h
+++ b/tests/auto/quick/shared/util.h
@@ -91,45 +91,25 @@ private:
QQuickWebEngineView *m_webEngineView;
};
-/**
- * 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
- */
-inline 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();
-}
-
inline bool waitForLoadSucceeded(QQuickWebEngineView *webEngineView, int timeout = 10000)
{
LoadSpy loadSpy(webEngineView);
- return waitForSignal(&loadSpy, SIGNAL(loadSucceeded()), timeout);
+ QSignalSpy spy(&loadSpy, &LoadSpy::loadSucceeded);
+ return spy.wait(timeout);
}
inline bool waitForLoadFailed(QQuickWebEngineView *webEngineView, int timeout = 10000)
{
LoadSpy loadSpy(webEngineView);
- return waitForSignal(&loadSpy, SIGNAL(loadFailed()), timeout);
+ QSignalSpy spy(&loadSpy, &LoadSpy::loadFailed);
+ return spy.wait(timeout);
}
inline bool waitForViewportReady(QQuickWebEngineView *webEngineView, int timeout = 10000)
{
#ifdef ENABLE_QML_TESTSUPPORT_API
- return waitForSignal(reinterpret_cast<QObject *>(webEngineView->testSupport()), SIGNAL(loadVisuallyCommitted()), timeout);
+ QSignalSpy spy(reinterpret_cast<QObject *>(webEngineView->testSupport()), SIGNAL(loadVisuallyCommitted()));
+ return spy.wait(timeout);
#else
Q_UNUSED(webEngineView)
Q_UNUSED(timeout)