summaryrefslogtreecommitdiffstats
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
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>
-rw-r--r--tests/auto/core/qwebengineurlrequestinterceptor/tst_qwebengineurlrequestinterceptor.cpp16
-rw-r--r--tests/auto/quick/qquickwebengineview/tst_qquickwebengineview.cpp3
-rw-r--r--tests/auto/quick/shared/util.h32
-rw-r--r--tests/auto/widgets/qwebengineaccessibility/tst_qwebengineaccessibility.cpp9
-rw-r--r--tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp83
-rw-r--r--tests/auto/widgets/qwebenginescript/tst_qwebenginescript.cpp27
-rw-r--r--tests/auto/widgets/qwebenginespellcheck/tst_qwebenginespellcheck.cpp7
-rw-r--r--tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp32
-rw-r--r--tests/auto/widgets/util.h23
9 files changed, 116 insertions, 116 deletions
diff --git a/tests/auto/core/qwebengineurlrequestinterceptor/tst_qwebengineurlrequestinterceptor.cpp b/tests/auto/core/qwebengineurlrequestinterceptor/tst_qwebengineurlrequestinterceptor.cpp
index 180953ed..89ebbac6 100644
--- a/tests/auto/core/qwebengineurlrequestinterceptor/tst_qwebengineurlrequestinterceptor.cpp
+++ b/tests/auto/core/qwebengineurlrequestinterceptor/tst_qwebengineurlrequestinterceptor.cpp
@@ -192,21 +192,21 @@ void tst_QWebEngineUrlRequestInterceptor::requestedUrl()
page.profile()->setRequestInterceptor(&interceptor);
page.setUrl(QUrl("qrc:///resources/__placeholder__"));
- waitForSignal(&page, SIGNAL(loadFinished(bool)));
+ QVERIFY(spy.wait());
QCOMPARE(spy.count(), 1);
QCOMPARE(interceptor.observedUrls.at(0), QUrl("qrc:///resources/content.html"));
QCOMPARE(page.requestedUrl(), QUrl("qrc:///resources/__placeholder__"));
QCOMPARE(page.url(), QUrl("qrc:///resources/content.html"));
page.setUrl(QUrl("qrc:/non-existent.html"));
- waitForSignal(&page, SIGNAL(loadFinished(bool)));
+ QVERIFY(spy.wait());
QCOMPARE(spy.count(), 2);
QCOMPARE(interceptor.observedUrls.at(2), QUrl("qrc:/non-existent.html"));
QCOMPARE(page.requestedUrl(), QUrl("qrc:///resources/__placeholder__"));
QCOMPARE(page.url(), QUrl("qrc:///resources/content.html"));
page.setUrl(QUrl("http://abcdef.abcdef"));
- waitForSignal(&page, SIGNAL(loadFinished(bool)));
+ QVERIFY(spy.wait());
QCOMPARE(spy.count(), 3);
QCOMPARE(interceptor.observedUrls.at(3), QUrl("http://abcdef.abcdef/"));
QCOMPARE(page.requestedUrl(), QUrl("qrc:///resources/__placeholder__"));
@@ -222,23 +222,23 @@ void tst_QWebEngineUrlRequestInterceptor::setUrlSameUrl()
QSignalSpy spy(&page, SIGNAL(loadFinished(bool)));
page.setUrl(QUrl("qrc:///resources/__placeholder__"));
- waitForSignal(&page, SIGNAL(loadFinished(bool)));
+ QVERIFY(spy.wait());
QCOMPARE(page.url(), QUrl("qrc:///resources/content.html"));
QCOMPARE(spy.count(), 1);
page.setUrl(QUrl("qrc:///resources/__placeholder__"));
- waitForSignal(&page, SIGNAL(loadFinished(bool)));
+ QVERIFY(spy.wait());
QCOMPARE(page.url(), QUrl("qrc:///resources/content.html"));
QCOMPARE(spy.count(), 2);
// Now a case without redirect.
page.setUrl(QUrl("qrc:///resources/content.html"));
- waitForSignal(&page, SIGNAL(loadFinished(bool)));
+ QVERIFY(spy.wait());
QCOMPARE(page.url(), QUrl("qrc:///resources/content.html"));
QCOMPARE(spy.count(), 3);
page.setUrl(QUrl("qrc:///resources/__placeholder__"));
- waitForSignal(&page, SIGNAL(loadFinished(bool)));
+ QVERIFY(spy.wait());
QCOMPARE(page.url(), QUrl("qrc:///resources/content.html"));
QCOMPARE(spy.count(), 4);
}
@@ -252,7 +252,7 @@ void tst_QWebEngineUrlRequestInterceptor::firstPartyUrl()
QSignalSpy spy(&page, SIGNAL(loadFinished(bool)));
page.setUrl(QUrl("qrc:///resources/firstparty.html"));
- waitForSignal(&page, SIGNAL(loadFinished(bool)));
+ QVERIFY(spy.wait());
QCOMPARE(interceptor.observedUrls.at(0), QUrl("qrc:///resources/firstparty.html"));
QCOMPARE(interceptor.observedUrls.at(1), QUrl("qrc:///resources/content.html"));
QCOMPARE(interceptor.firstPartyUrls.at(0), QUrl("qrc:///resources/firstparty.html"));
diff --git a/tests/auto/quick/qquickwebengineview/tst_qquickwebengineview.cpp b/tests/auto/quick/qquickwebengineview/tst_qquickwebengineview.cpp
index 2d68fd74..2a43c9c1 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 063caa76..674c2da3 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)
diff --git a/tests/auto/widgets/qwebengineaccessibility/tst_qwebengineaccessibility.cpp b/tests/auto/widgets/qwebengineaccessibility/tst_qwebengineaccessibility.cpp
index 3ed4bcc7..85bfa80f 100644
--- a/tests/auto/widgets/qwebengineaccessibility/tst_qwebengineaccessibility.cpp
+++ b/tests/auto/widgets/qwebengineaccessibility/tst_qwebengineaccessibility.cpp
@@ -88,7 +88,8 @@ void tst_QWebEngineAccessibility::hierarchy()
"<input type='text' value='some text'></input>" \
"</body></html>");
webView.show();
- ::waitForSignal(&webView, SIGNAL(loadFinished(bool)));
+ QSignalSpy spyFinished(&webView, &QWebEngineView::loadFinished);
+ QVERIFY(spyFinished.wait());
QAccessibleInterface *view = QAccessible::queryAccessibleInterface(&webView);
QVERIFY(view);
@@ -150,7 +151,8 @@ void tst_QWebEngineAccessibility::text()
"<input type='text' value='Good day!' placeholder='day'></input>" \
"</body></html>");
webView.show();
- ::waitForSignal(&webView, SIGNAL(loadFinished(bool)));
+ QSignalSpy spyFinished(&webView, &QWebEngineView::loadFinished);
+ QVERIFY(spyFinished.wait());
QAccessibleInterface *view = QAccessible::queryAccessibleInterface(&webView);
// Wait for accessibility to be fully initialized
@@ -215,7 +217,8 @@ void tst_QWebEngineAccessibility::value()
"<div class='progress' role='progressbar' aria-valuenow='77' aria-valuemin='22' aria-valuemax='99'></div>" \
"</body></html>");
webView.show();
- ::waitForSignal(&webView, SIGNAL(loadFinished(bool)));
+ QSignalSpy spyFinished(&webView, &QWebEngineView::loadFinished);
+ QVERIFY(spyFinished.wait());
QAccessibleInterface *view = QAccessible::queryAccessibleInterface(&webView);
QTRY_COMPARE(view->child(0)->childCount(), 2);
diff --git a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp
index 1377c9a5..a3525208 100644
--- a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp
+++ b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp
@@ -490,7 +490,8 @@ void tst_QWebEnginePage::pasteImage()
clipboard->setImage(origImage);
QWebEnginePage *page = m_view->page();
page->load(QUrl("qrc:///resources/pasteimage.html"));
- QVERIFY(waitForSignal(m_view, SIGNAL(loadFinished(bool))));
+ QSignalSpy spyFinished(m_view, &QWebEngineView::loadFinished);
+ QVERIFY(spyFinished.wait());
page->triggerAction(QWebEnginePage::Paste);
QTRY_VERIFY(evaluateJavaScriptSync(page,
"window.myImageDataURL ? window.myImageDataURL.length : 0").toInt() > 0);
@@ -661,7 +662,8 @@ void tst_QWebEnginePage::userStyleSheet()
m_page->settings()->setUserStyleSheetUrl(QUrl("data:text/css;charset=utf-8;base64,"
+ QByteArray("p { background-image: url('http://does.not/exist.png');}").toBase64()));
m_view->setHtml("<p>hello world</p>");
- QVERIFY(::waitForSignal(m_view, SIGNAL(loadFinished(bool))));
+ QSignalSpy spyFinished(m_view, &QWebEngineView::loadFinished);
+ QVERIFY(spyFinished.wait());
QVERIFY(networkManager->requestedUrls.count() >= 1);
QCOMPARE(networkManager->requestedUrls.at(0), QUrl("http://does.not/exist.png"));
@@ -679,7 +681,8 @@ void tst_QWebEnginePage::userStyleSheetFromLocalFileUrl()
QUrl styleSheetUrl = QUrl::fromLocalFile(TESTS_SOURCE_DIR + QLatin1String("qwebenginepage/resources/user.css"));
m_page->settings()->setUserStyleSheetUrl(styleSheetUrl);
m_view->setHtml("<p>hello world</p>");
- QVERIFY(::waitForSignal(m_view, SIGNAL(loadFinished(bool))));
+ QSignalSpy spyFinished(m_view, &QWebEngineView::loadFinished);
+ QVERIFY(spyFinished.wait());
QVERIFY(networkManager->requestedUrls.count() >= 1);
QCOMPARE(networkManager->requestedUrls.at(0), QUrl("http://does.not/exist.png"));
@@ -696,7 +699,8 @@ void tst_QWebEnginePage::userStyleSheetFromQrcUrl()
m_page->settings()->setUserStyleSheetUrl(QUrl("qrc:///resources/user.css"));
m_view->setHtml("<p>hello world</p>");
- QVERIFY(::waitForSignal(m_view, SIGNAL(loadFinished(bool))));
+ QSignalSpy spyFinished(m_view, &QWebEngineView::loadFinished);
+ QVERIFY(spyFinished.wait());
QVERIFY(networkManager->requestedUrls.count() >= 1);
QCOMPARE(networkManager->requestedUrls.at(0), QUrl("http://does.not/exist.png"));
@@ -723,10 +727,12 @@ void tst_QWebEnginePage::modified()
QSKIP("QWEBENGINEPAGE_ISMODIFIED");
#else
m_page->setUrl(QUrl("data:text/html,<body>blub"));
- QVERIFY(::waitForSignal(m_view, SIGNAL(loadFinished(bool))));
+ QSignalSpy spyFinished(m_view, &QWebEngineView::loadFinished);
+ QVERIFY(spyFinished.wait());
m_page->setUrl(QUrl("data:text/html,<body id=foo contenteditable>blah"));
- QVERIFY(::waitForSignal(m_view, SIGNAL(loadFinished(bool))));
+ QSignalSpy spyFinished(m_view, &QWebEngineView::loadFinished);
+ QVERIFY(spyFinished.wait());
QVERIFY(!m_page->isModified());
@@ -750,7 +756,8 @@ void tst_QWebEnginePage::modified()
QVERIFY(!m_page->history()->forwardItem().isValid());
m_page->history()->back();
- QVERIFY(::waitForSignal(m_view, SIGNAL(loadFinished(bool))));
+ QSignalSpy spyFinished(m_view, &QWebEngineView::loadFinished);
+ QVERIFY(spyFinished.wait());
QVERIFY(!m_page->history()->canGoBack());
QVERIFY(m_page->history()->canGoForward());
@@ -772,7 +779,8 @@ void tst_QWebEnginePage::modified()
m_page->setUrl(QUrl("data:text/html,<body>This is fourth page"));
QCOMPARE(m_page->history()->count(), 2);
m_page->setUrl(QUrl("data:text/html,<body>This is fifth page"));
- QVERIFY(::waitForSignal(m_page, SIGNAL(saveFrameStateRequested(QWebEngineFrame*,QWebEngineHistoryItem*))));
+ QSignalSpy spy(m_page, &QWebEnginePage::saveFrameStateRequested);
+ QVERIFY(spy.wait());
#endif
}
@@ -2739,7 +2747,8 @@ void tst_QWebEnginePage::screenshot()
QWebEnginePage* page = new QWebEnginePage;
page->settings()->setAttribute(QWebEngineSettings::PluginsEnabled, true);
page->setHtml(html, QUrl::fromLocalFile(TESTS_SOURCE_DIR));
- ::waitForSignal(page, SIGNAL(loadFinished(bool)), 2000);
+ QSignalSpy spyFinished(m_view, &QWebEngineView::loadFinished);
+ QVERIFY(spyFinished.wait(2000));
// take screenshot without a view
takeScreenshot(page);
@@ -2865,7 +2874,8 @@ void tst_QWebEnginePage::testStopScheduledPageRefresh()
"<meta http-equiv=\"refresh\"content=\"0;URL=qrc:///resources/index.html\">"
"</head><body><h1>Page redirects immediately...</h1>"
"</body></html>");
- QVERIFY(::waitForSignal(&page1, SIGNAL(loadFinished(bool))));
+ QSignalSpy spyFinished(&page1, &QWebEnginePage::loadFinished);
+ QVERIFY(spyFinished.wait();
QTest::qWait(500);
QCOMPARE(page1.url(), QUrl(QLatin1String("qrc:///resources/index.html")));
@@ -3217,7 +3227,8 @@ void tst_QWebEnginePage::deleteQWebEngineViewTwice()
mainWindow.setCentralWidget(webView);
webView->load(QUrl("qrc:///resources/frame_a.html"));
mainWindow.show();
- QVERIFY(::waitForSignal(webView, SIGNAL(loadFinished(bool))));
+ QSignalSpy spyFinished(webView, &QWebEngineView::loadFinished);
+ QVERIFY(spyFinished.wait());
}
}
@@ -3272,7 +3283,8 @@ void tst_QWebEnginePage::renderOnRepaintRequestedShouldNotRecurse()
page.setHtml("zalan loves trunk", QUrl());
- QVERIFY(::waitForSignal(&r, SIGNAL(finished())));
+ QSignalSpy spyFinished(&r, &RepaintRequestedRenderer::finished);
+ QVERIFY(spyFinished.wait());
#endif
}
@@ -3323,7 +3335,8 @@ void tst_QWebEnginePage::loadSignalsOrder()
QFETCH(QUrl, url);
QWebEnginePage page;
SpyForLoadSignalsOrder loadSpy(&page);
- waitForSignal(&loadSpy, SIGNAL(started()), 500);
+ QSignalSpy spyLoadSpy(&loadSpy, &SpyForLoadSignalsOrder::started);
+ QVERIFY(spyLoadSpy.wait(500));
page.load(url);
QTRY_VERIFY(loadSpy.isFinished());
}
@@ -3449,7 +3462,8 @@ void tst_QWebEnginePage::savePage()
const QString urlPrefix = QStringLiteral("data:text/html,<h1>");
const QString text = QStringLiteral("There is Thingumbob shouting!");
page->load(QUrl(urlPrefix + text));
- waitForSignal(page, SIGNAL(loadFinished(bool)));
+ QSignalSpy spyFinished(page, &QWebEnginePage::loadFinished);
+ QVERIFY(spyFinished.wait());
QCOMPARE(toPlainTextSync(page), text);
// Save the loaded page as HTML.
@@ -3460,12 +3474,12 @@ void tst_QWebEnginePage::savePage()
// Load something else.
page->load(QUrl(urlPrefix + QLatin1String("It's a Snark!")));
- waitForSignal(page, SIGNAL(loadFinished(bool)));
+ QVERIFY(spyFinished.wait());
QVERIFY(toPlainTextSync(page) != text);
// Load the saved page and compare the contents.
page->load(QUrl::fromLocalFile(filePath));
- waitForSignal(page, SIGNAL(loadFinished(bool)));
+ QVERIFY(spyFinished.wait());
QCOMPARE(toPlainTextSync(page), text);
}
@@ -3791,7 +3805,8 @@ void tst_QWebEnginePage::progressSignal()
QUrl dataUrl("data:text/html,<h1>Test");
m_view->setUrl(dataUrl);
- ::waitForSignal(m_view, SIGNAL(loadFinished(bool)));
+ QSignalSpy spyFinished(m_view, &QWebEngineView::loadFinished);
+ QVERIFY(spyFinished.wait());
QVERIFY(progressSpy.size() >= 2);
int previousValue = -1;
@@ -3812,14 +3827,14 @@ void tst_QWebEnginePage::urlChange()
QUrl dataUrl("data:text/html,<h1>Test");
m_view->setUrl(dataUrl);
- ::waitForSignal(m_page, SIGNAL(urlChanged(QUrl)));
+ QVERIFY(urlSpy.wait());
QCOMPARE(urlSpy.size(), 1);
QUrl dataUrl2("data:text/html,<html><head><title>title</title></head><body><h1>Test</body></html>");
m_view->setUrl(dataUrl2);
- ::waitForSignal(m_page, SIGNAL(urlChanged(QUrl)));
+ QVERIFY(urlSpy.wait());
QCOMPARE(urlSpy.size(), 2);
}
@@ -3922,7 +3937,7 @@ void tst_QWebEnginePage::requestedUrlAfterSetAndLoadFailures()
const QUrl first("http://abcdef.abcdef/");
page.setUrl(first);
- ::waitForSignal(&page, SIGNAL(loadFinished(bool)));
+ QVERIFY(spy.wait());
QCOMPARE(spy.count(), 1);
QCOMPARE(page.url(), first);
QCOMPARE(page.requestedUrl(), first);
@@ -3932,7 +3947,7 @@ void tst_QWebEnginePage::requestedUrlAfterSetAndLoadFailures()
QVERIFY(first != second);
page.load(second);
- ::waitForSignal(&page, SIGNAL(loadFinished(bool)));
+ QVERIFY(spy.wait());
QCOMPARE(spy.count(), 2);
QCOMPARE(page.url(), first);
QCOMPARE(page.requestedUrl(), second);
@@ -4016,14 +4031,15 @@ void tst_QWebEnginePage::setHtmlWithStylesheetResource()
QWebEngineElement webElement;
page.setHtml(html, QUrl(QLatin1String("qrc:///file")));
- waitForSignal(&page, SIGNAL(loadFinished(bool)), 200);
+ QSignalSpy spyFinished(&page, &QWebEnginePage::loadFinished);
+ QVERIFY(spyFinished.wait(200));
webElement = page.documentElement().findFirst("p");
QCOMPARE(webElement.styleProperty("color", QWebEngineElement::CascadedStyle), QLatin1String("red"));
// Now we test the opposite: without a baseUrl as a local file, we cannot request local resources.
page.setHtml(html, QUrl(QLatin1String("http://www.example.com/")));
- waitForSignal(&page, SIGNAL(loadFinished(bool)), 200);
+ QVERIFY(spyFinished.wait(200));
webElement = page.documentElement().findFirst("p");
QEXPECT_FAIL("", "https://bugs.webkit.org/show_bug.cgi?id=118659", Continue);
QCOMPARE(webElement.styleProperty("color", QWebEngineElement::CascadedStyle), QString());
@@ -4048,7 +4064,8 @@ void tst_QWebEnginePage::setHtmlWithBaseURL()
QSignalSpy spy(&page, SIGNAL(loadFinished(bool)));
page.setHtml(html, QUrl::fromLocalFile(TESTS_SOURCE_DIR));
- waitForSignal(&page, SIGNAL(loadFinished(bool)));
+ QSignalSpy spyFinished(&page, &QWebEnginePage::loadFinished);
+ QVERIFY(spyFinished.wait());
QCOMPARE(spy.count(), 1);
QCOMPARE(evaluateJavaScriptSync(&page, "document.images.length").toInt(), 1);
@@ -4079,7 +4096,8 @@ void tst_QWebEnginePage::setHtmlWithJSAlert()
QString html("<html><head></head><body><script>alert('foo');</script><p>hello world</p></body></html>");
MyPage page;
page.setHtml(html, QUrl(QStringLiteral("http://test.origin.com/path#fragment")));
- waitForSignal(&page, SIGNAL(loadFinished(bool)));
+ QSignalSpy spyFinished(&page, &QWebEnginePage::loadFinished);
+ QVERIFY(spyFinished.wait());
QCOMPARE(page.alerts, 1);
QCOMPARE(toHtmlSync(&page), html);
}
@@ -4259,9 +4277,9 @@ void tst_QWebEnginePage::scrollbarsOff()
"</body>");
- QSignalSpy loadSpy(&view, SIGNAL(loadFinished(bool)));
+ QSignalSpy loadSpy(&view, &QWebEngineView::loadFinished);
view.setHtml(html);
- ::waitForSignal(&view, SIGNAL(loadFinished(bool)), 200);
+ QVERIFY(loadSpy.wait(200);
QCOMPARE(loadSpy.count(), 1);
mainFrame->evaluateJavaScript("checkScrollbar();");
@@ -4327,7 +4345,8 @@ void tst_QWebEnginePage::evaluateWillCauseRepaint()
QTRY_COMPARE(loadSpy.count(), 1);
evaluateJavaScriptSync(view.page(), "document.getElementById('junk').style.display = 'none';");
- ::waitForSignal(&view, SIGNAL(repaintRequested()));
+ QSignalSpy repaintSpy(&view, &WebView::repaintRequested);
+ QVERIFY(repaintSpy.wait());
}
void tst_QWebEnginePage::setContent_data()
@@ -4441,7 +4460,7 @@ void tst_QWebEnginePage::setUrlToEmpty()
// Set existing url
page.setUrl(url);
expectedLoadFinishedCount++;
- ::waitForSignal(&page, SIGNAL(loadFinished(bool)));
+ QVERIFY(spy.wait());
QCOMPARE(spy.count(), expectedLoadFinishedCount);
QCOMPARE(page.url(), url);
@@ -4602,7 +4621,8 @@ void tst_QWebEnginePage::setUrlUsingStateObject()
url = QUrl("qrc:/resources/test1.html");
m_page->setUrl(url);
- waitForSignal(m_page, SIGNAL(loadFinished(bool)));
+ QSignalSpy spyFinished(m_page, &QWebEnginePage::loadFinished);
+ QVERIFY(spyFinished.wait());
expectedUrlChangeCount++;
QCOMPARE(urlChangedSpy.count(), expectedUrlChangeCount);
QCOMPARE(m_page->url(), url);
@@ -4802,7 +4822,8 @@ void tst_QWebEnginePage::loadInSignalHandlers()
URLSetter setter(m_page, signal, type, urlForSetter);
m_page->load(url);
- waitForSignal(&setter, SIGNAL(finished()));
+ QSignalSpy spy(&setter, &URLSetter::finished);
+ QVERIFY(spy.wait());
QCOMPARE(m_page->url(), urlForSetter);
}
diff --git a/tests/auto/widgets/qwebenginescript/tst_qwebenginescript.cpp b/tests/auto/widgets/qwebenginescript/tst_qwebenginescript.cpp
index d5ecd884..c10ae288 100644
--- a/tests/auto/widgets/qwebenginescript/tst_qwebenginescript.cpp
+++ b/tests/auto/widgets/qwebenginescript/tst_qwebenginescript.cpp
@@ -62,7 +62,8 @@ void tst_QWebEngineScript::domEditing()
page.scripts().insert(s);
page.load(QUrl("about:blank"));
view.show();
- waitForSignal(&page, SIGNAL(loadFinished(bool)));
+ QSignalSpy spyFinished(&page, &QWebEnginePage::loadFinished);
+ QVERIFY(spyFinished.wait());
QCOMPARE(evaluateJavaScriptSync(&page, "document.getElementById(\"banner\").innerText"), QVariant(QStringLiteral("Injected banner")));
// elementFromPoint only works for exposed elements
QTest::qWaitForWindowExposed(&view);
@@ -85,7 +86,8 @@ void tst_QWebEngineScript::injectionPoint()
document.body.innerText = contents;\
}, 550));\
</script></head><body></body></html>"));
- waitForSignal(&page, SIGNAL(loadFinished(bool)));
+ QSignalSpy spyFinished(&page, &QWebEnginePage::loadFinished);
+ QVERIFY(spyFinished.wait());
QTRY_COMPARE(evaluateJavaScriptSync(&page, "document.body.innerText"), QVariant::fromValue(QStringLiteral("SUCCESS")));
}
@@ -116,14 +118,15 @@ void tst_QWebEngineScript::scriptWorld()
script.setSourceCode(QStringLiteral("var userScriptTest = 1;"));
page.scripts().insert(script);
page.load(QUrl("about:blank"));
- waitForSignal(&page, SIGNAL(loadFinished(bool)));
+ QSignalSpy spyFinished(&page, &QWebEnginePage::loadFinished);
+ QVERIFY(spyFinished.wait());
QCOMPARE(evaluateJavaScriptSync(&page, "typeof(userScriptTest) != \"undefined\" && userScriptTest == 1;"), QVariant::fromValue(true));
QCOMPARE(evaluateJavaScriptSyncInWorld(&page, "typeof(userScriptTest) == \"undefined\"", QWebEngineScript::ApplicationWorld), QVariant::fromValue(true));
script.setWorldId(QWebEngineScript::ApplicationWorld);
page.scripts().clear();
page.scripts().insert(script);
page.load(QUrl("about:blank"));
- waitForSignal(&page, SIGNAL(loadFinished(bool)));
+ QVERIFY(spyFinished.wait());
QCOMPARE(evaluateJavaScriptSync(&page, "typeof(userScriptTest) == \"undefined\""), QVariant::fromValue(true));
QCOMPARE(evaluateJavaScriptSyncInWorld(&page, "typeof(userScriptTest) != \"undefined\" && userScriptTest == 1;", QWebEngineScript::ApplicationWorld), QVariant::fromValue(true));
}
@@ -141,11 +144,12 @@ void tst_QWebEngineScript::scriptModifications()
document.body.innerText = foo;});\
</script></head><body></body></html>"));
QVERIFY(page.scripts().count() == 1);
- waitForSignal(&page, SIGNAL(loadFinished(bool)));
+ QSignalSpy spyFinished(&page, &QWebEnginePage::loadFinished);
+ QVERIFY(spyFinished.wait());
QCOMPARE(evaluateJavaScriptSync(&page, "document.body.innerText"), QVariant::fromValue(QStringLiteral("SUCCESS")));
script.setSourceCode("var foo = \"FAILURE\"");
page.triggerAction(QWebEnginePage::ReloadAndBypassCache);
- waitForSignal(&page, SIGNAL(loadFinished(bool)));
+ QVERIFY(spyFinished.wait());
QCOMPARE(evaluateJavaScriptSync(&page, "document.body.innerText"), QVariant::fromValue(QStringLiteral("SUCCESS")));
QVERIFY(page.scripts().count() == 1);
QWebEngineScript s = page.scripts().findScript(QStringLiteral("String1"));
@@ -209,11 +213,12 @@ void tst_QWebEngineScript::webChannel()
script.setSourceCode(QString::fromLatin1(scriptSrc));
page.scripts().insert(script);
page.setHtml(QStringLiteral("<html><body></body></html>"));
- waitForSignal(&page, SIGNAL(loadFinished(bool)));
+ QSignalSpy spyFinished(&page, &QWebEnginePage::loadFinished);
+ QVERIFY(spyFinished.wait());
if (reloadFirst) {
// Check that the transport is also reinstalled on navigation
page.triggerAction(QWebEnginePage::Reload);
- waitForSignal(&page, SIGNAL(loadFinished(bool)));
+ QVERIFY(spyFinished.wait());
}
page.runJavaScript(QLatin1String(
"new QWebChannel(qt.webChannelTransport,"
@@ -221,7 +226,8 @@ void tst_QWebEngineScript::webChannel()
" channel.objects.object.text = 'test';"
" }"
");"), worldId);
- waitForSignal(&testObject, SIGNAL(textChanged(QString)));
+ QSignalSpy spyTextChanged(&testObject, &TestObject::textChanged);
+ QVERIFY(spyTextChanged.wait());
QCOMPARE(testObject.text(), QStringLiteral("test"));
if (worldId != QWebEngineScript::MainWorld)
@@ -235,7 +241,8 @@ void tst_QWebEngineScript::noTransportWithoutWebChannel()
QCOMPARE(evaluateJavaScriptSync(&page, "qt.webChannelTransport"), QVariant(QVariant::Invalid));
page.triggerAction(QWebEnginePage::Reload);
- waitForSignal(&page, SIGNAL(loadFinished(bool)));
+ QSignalSpy spyFinished(&page, &QWebEnginePage::loadFinished);
+ QVERIFY(spyFinished.wait());
QCOMPARE(evaluateJavaScriptSync(&page, "qt.webChannelTransport"), QVariant(QVariant::Invalid));
}
diff --git a/tests/auto/widgets/qwebenginespellcheck/tst_qwebenginespellcheck.cpp b/tests/auto/widgets/qwebenginespellcheck/tst_qwebenginespellcheck.cpp
index 4db5b947..c7b08366 100644
--- a/tests/auto/widgets/qwebenginespellcheck/tst_qwebenginespellcheck.cpp
+++ b/tests/auto/widgets/qwebenginespellcheck/tst_qwebenginespellcheck.cpp
@@ -103,7 +103,9 @@ void tst_QWebEngineSpellcheck::load()
{
m_view->page()->load(QUrl("qrc:///resources/index.html"));
m_view->show();
- waitForSignal(m_view->page(), SIGNAL(loadFinished(bool)));
+ QSignalSpy spyFinished(m_view->page(), &QWebEnginePage::loadFinished);
+ QVERIFY(spyFinished.wait());
+
}
void tst_QWebEngineSpellcheck::cleanup()
@@ -170,7 +172,8 @@ void tst_QWebEngineSpellcheck::spellcheck()
// open menu on misspelled word
m_view->activateMenu(m_view->focusWidget(), rect.center());
- waitForSignal(m_view, SIGNAL(menuReady()));
+ QSignalSpy spyMenuReady(m_view, &WebView::menuReady);
+ QVERIFY(spyMenuReady.wait());
// check if menu is valid
QVERIFY(m_view->data().isValid());
diff --git a/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp b/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp
index 829f1158..2baadd86 100644
--- a/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp
+++ b/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp
@@ -181,7 +181,8 @@ void tst_QWebEngineView::reusePage()
page->setHtml(html, QUrl::fromLocalFile(TESTS_SOURCE_DIR));
if (html.contains("</embed>")) {
// some reasonable time for the PluginStream to feed test.swf to flash and start painting
- waitForSignal(view1, SIGNAL(loadFinished(bool)), 2000);
+ QSignalSpy spyFinished(view1, &QWebEngineView::loadFinished);
+ QVERIFY(spyFinished.wait(2000));
}
view1->show();
@@ -285,7 +286,8 @@ void tst_QWebEngineView::focusInputTypes()
webView.load(url);
mainFrame->setFocus();
- QVERIFY(waitForSignal(&webView, SIGNAL(loadFinished(bool))));
+ QSignalSpy spyFinished(webView, &QWebEngineView::loadFinished);
+ QVERIFY(spyFinished.wait());
// 'text' type
QWebEngineElement inputElement = mainFrame->documentElement().findFirst(QLatin1String("input[type=text]"));
@@ -404,7 +406,8 @@ void tst_QWebEngineView::horizontalScrollbarTest()
webView.page()->load(url);
webView.page()->setFocus();
- QVERIFY(waitForSignal(&webView, SIGNAL(loadFinished(bool))));
+ QSignalSpy spyFinished(webView, &QWebEngineView::loadFinished);
+ QVERIFY(spyFinished.wait());
QVERIFY(webView.page()->scrollPosition() == QPoint(0, 0));
@@ -566,7 +569,8 @@ void tst_QWebEngineView::renderingAfterMaxAndBack()
QWebEngineView view;
view.page()->load(url);
- QVERIFY(waitForSignal(&view, SIGNAL(loadFinished(bool))));
+ QSignalSpy spyFinished(&view, &QWebEngineView::loadFinished);
+ QVERIFY(spyFinished.wait());
view.show();
view.page()->settings()->setMaximumPagesInCache(3);
@@ -588,7 +592,7 @@ void tst_QWebEngineView::renderingAfterMaxAndBack()
"</html>");
view.page()->load(url2);
- QVERIFY(waitForSignal(&view, SIGNAL(loadFinished(bool))));
+ QVERIFY(spyFinished.wait());
view.showMaximized();
@@ -844,25 +848,29 @@ void tst_QWebEngineView::changeLocale()
QWebEngineView viewDE;
viewDE.setUrl(url);
- QVERIFY(waitForSignal(&viewDE, SIGNAL(titleChanged(QString))));
- QVERIFY(waitForSignal(&viewDE, SIGNAL(loadFinished(bool))));
+ QSignalSpy spyTitleChangedDE(&viewDE, &QWebEngineView::titleChanged);
+ QVERIFY(spyTitleChangedDE.wait());
+ QSignalSpy spyFinishedDE(&viewDE, &QWebEngineView::loadFinished);
+ QVERIFY(spyFinishedDE.wait());
QCOMPARE(viewDE.title(), QStringLiteral("Nicht verf\u00FCgbar: %1").arg(url.toString()));
QLocale::setDefault(QLocale("en"));
QWebEngineView viewEN;
viewEN.setUrl(url);
- QVERIFY(waitForSignal(&viewEN, SIGNAL(titleChanged(QString))));
- QVERIFY(waitForSignal(&viewEN, SIGNAL(loadFinished(bool))));
+ QSignalSpy spyTitleChangedEN(&viewEN, &QWebEngineView::titleChanged);
+ QVERIFY(spyTitleChangedEN.wait());
+ QSignalSpy spyFinishedEN(&viewEN, &QWebEngineView::loadFinished);
+ QVERIFY(spyFinishedEN.wait());
QCOMPARE(viewEN.title(), QStringLiteral("%1 is not available").arg(url.toString()));
viewDE.setUrl(QUrl("about:blank"));
- QVERIFY(waitForSignal(&viewDE, SIGNAL(loadFinished(bool))));
+ QVERIFY(spyFinishedDE.wait());
viewDE.setUrl(url);
- QVERIFY(waitForSignal(&viewDE, SIGNAL(titleChanged(QString))));
- QVERIFY(waitForSignal(&viewDE, SIGNAL(loadFinished(bool))));
+ QVERIFY(spyTitleChangedDE.wait());
+ QVERIFY(spyFinishedDE.wait());
QCOMPARE(viewDE.title(), QStringLiteral("Nicht verf\u00FCgbar: %1").arg(url.toString()));
}
diff --git a/tests/auto/widgets/util.h b/tests/auto/widgets/util.h
index 770579f1..356cf6eb 100644
--- a/tests/auto/widgets/util.h
+++ b/tests/auto/widgets/util.h
@@ -42,29 +42,6 @@
#endif
/**
- * 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 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();
-}
-
-/**
* Just like QSignalSpy but facilitates sync and async
* signal emission. For example if you want to verify that
* page->foo() emitted a signal, it could be that the