summaryrefslogtreecommitdiffstats
path: root/tests/auto/quick
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
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')
-rw-r--r--tests/auto/quick/qquickwebengineview/tst_qquickwebengineview.cpp3
-rw-r--r--tests/auto/quick/shared/util.h32
2 files changed, 8 insertions, 27 deletions
diff --git a/tests/auto/quick/qquickwebengineview/tst_qquickwebengineview.cpp b/tests/auto/quick/qquickwebengineview/tst_qquickwebengineview.cpp
index 2d68fd744..2a43c9c1c 100644
--- a/tests/auto/quick/qquickwebengineview/tst_qquickwebengineview.cpp
+++ b/tests/auto/quick/qquickwebengineview/tst_qquickwebengineview.cpp
@@ -151,7 +151,8 @@ void tst_QQuickWebEngineView::stopEnabledAfterLoadStarted()
LoadStartedCatcher catcher(webEngineView());
webEngineView()->setUrl(urlFromTestPath("html/basic_page.html"));
- waitForSignal(&catcher, SIGNAL(finished()));
+ QSignalSpy spy(&catcher, &LoadStartedCatcher::finished);
+ QVERIFY(spy.wait());
QCOMPARE(webEngineView()->isLoading(), true);
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)