diff options
author | Michael BrĂ¼ning <michael.bruning@qt.io> | 2016-12-07 13:55:20 +0100 |
---|---|---|
committer | Michael BrĂ¼ning <michael.bruning@qt.io> | 2016-12-07 13:55:20 +0100 |
commit | c7f8e360da41df8b81004fe45f1582845a951c2b (patch) | |
tree | 32cf6ecb336af7d89a0a86153bb07ee49f23baa9 /tests/auto | |
parent | 3d000cfc013158f56c0b088c9ee99b03938ef50b (diff) | |
parent | 5ec330cec86cd7781ced295790ce93ac8748dcc4 (diff) |
Merge remote-tracking branch 'origin/5.8' into dev
Conflicts:
src/3rdparty
Change-Id: Ie7b7c469aa24716816a23b8fe7a8df9f477a9f67
Diffstat (limited to 'tests/auto')
15 files changed, 325 insertions, 282 deletions
diff --git a/tests/auto/core/qwebengineurlrequestinterceptor/tst_qwebengineurlrequestinterceptor.cpp b/tests/auto/core/qwebengineurlrequestinterceptor/tst_qwebengineurlrequestinterceptor.cpp index 180953ed4..89ebbac62 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/qmltests/BLACKLIST b/tests/auto/quick/qmltests/BLACKLIST index d281020df..2673c7eb2 100644 --- a/tests/auto/quick/qmltests/BLACKLIST +++ b/tests/auto/quick/qmltests/BLACKLIST @@ -1,9 +1,3 @@ -[DesktopWebEngineViewLinkHovered::test_linkHovered] -* - -[DesktopWebEngineViewLinkHovered::test_linkHoveredDoesntEmitRepeated] -* - [WebViewGeopermission::test_deniedGeolocationByUser] osx diff --git a/tests/auto/quick/qmltests/data/tst_linkHovered.qml b/tests/auto/quick/qmltests/data/tst_linkHovered.qml index b049f07a3..362130bab 100644 --- a/tests/auto/quick/qmltests/data/tst_linkHovered.qml +++ b/tests/auto/quick/qmltests/data/tst_linkHovered.qml @@ -29,6 +29,7 @@ import QtQuick 2.0 import QtTest 1.0 import QtWebEngine 1.2 +import QtWebEngine.testsupport 1.0 TestWebEngineView { id: webEngineView @@ -38,8 +39,16 @@ TestWebEngineView { property string lastUrl + testSupport: WebEngineTestSupport { } + + SignalSpy { + id: loadVisuallyCommittedSpy + target: webEngineView.testSupport + signalName: "loadVisuallyCommitted" + } + SignalSpy { - id: spy + id: linkHoveredSpy target: webEngineView signalName: "linkHovered" } @@ -61,53 +70,60 @@ TestWebEngineView { } function init() { - webEngineView.lastUrl = "" - spy.clear() + webEngineView.lastUrl = ""; + loadVisuallyCommittedSpy.clear(); + linkHoveredSpy.clear(); } function test_linkHovered() { - compare(spy.count, 0) + compare(linkHoveredSpy.count, 0); mouseMove(webEngineView, 100, 300) webEngineView.url = Qt.resolvedUrl("test2.html") verify(webEngineView.waitForLoadSucceeded()) // We get a linkHovered signal with empty hoveredUrl after page load - spy.wait() - compare(spy.count, 1) + linkHoveredSpy.wait(); + compare(linkHoveredSpy.count, 1); compare(webEngineView.lastUrl, "") + // Wait for the page to be rendered before trying to test based on input events + loadVisuallyCommittedSpy.wait(); + mouseMove(webEngineView, 100, 100) - spy.wait() - compare(spy.count, 2) + linkHoveredSpy.wait(); + compare(linkHoveredSpy.count, 2); compare(webEngineView.lastUrl, Qt.resolvedUrl("test1.html")) mouseMove(webEngineView, 100, 300) - spy.wait() - compare(spy.count, 3) + linkHoveredSpy.wait(); + compare(linkHoveredSpy.count, 3); compare(webEngineView.lastUrl, "") } function test_linkHoveredDoesntEmitRepeated() { - compare(spy.count, 0) + compare(linkHoveredSpy.count, 0); webEngineView.url = Qt.resolvedUrl("test2.html") verify(webEngineView.waitForLoadSucceeded()) // We get a linkHovered signal with empty hoveredUrl after page load - spy.wait() - compare(spy.count, 1) + linkHoveredSpy.wait(); + compare(linkHoveredSpy.count, 1); compare(webEngineView.lastUrl, "") + // Wait for the page to be rendered before trying to test based on input events + loadVisuallyCommittedSpy.wait(); + for (var i = 0; i < 100; i += 10) mouseMove(webEngineView, 100, 100 + i) - spy.wait() - compare(spy.count, 2) + linkHoveredSpy.wait(); + compare(linkHoveredSpy.count, 2); compare(webEngineView.lastUrl, Qt.resolvedUrl("test1.html")) for (var i = 0; i < 100; i += 10) mouseMove(webEngineView, 100, 300 + i) - spy.wait() - compare(spy.count, 3) + linkHoveredSpy.wait(); + compare(linkHoveredSpy.count, 3); compare(webEngineView.lastUrl, "") } } 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) diff --git a/tests/auto/widgets/qwebengineaccessibility/tst_qwebengineaccessibility.cpp b/tests/auto/widgets/qwebengineaccessibility/tst_qwebengineaccessibility.cpp index 3ed4bcc71..85bfa80f3 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/qwebenginehistory/tst_qwebenginehistory.cpp b/tests/auto/widgets/qwebenginehistory/tst_qwebenginehistory.cpp index a329b7307..dffd995c9 100644 --- a/tests/auto/widgets/qwebenginehistory/tst_qwebenginehistory.cpp +++ b/tests/auto/widgets/qwebenginehistory/tst_qwebenginehistory.cpp @@ -370,22 +370,21 @@ void tst_QWebEngineHistory::saveAndRestore_crash_2() { QByteArray buffer; saveHistory(hist, &buffer); - QWebEnginePage* page2 = new QWebEnginePage(this); - QWebEngineHistory* hist2 = page2->history(); + QWebEnginePage page2(this); + QWebEngineHistory* hist2 = page2.history(); for (unsigned i = 0; i < 5; i++) { restoreHistory(hist2, &buffer); saveHistory(hist2, &buffer); } - delete page2; } void tst_QWebEngineHistory::saveAndRestore_crash_3() { QByteArray buffer; saveHistory(hist, &buffer); - QWebEnginePage* page2 = new QWebEnginePage(this); + QWebEnginePage page2(this); QWebEngineHistory* hist1 = hist; - QWebEngineHistory* hist2 = page2->history(); + QWebEngineHistory* hist2 = page2.history(); for (unsigned i = 0; i < 5; i++) { restoreHistory(hist1, &buffer); restoreHistory(hist2, &buffer); @@ -395,7 +394,6 @@ void tst_QWebEngineHistory::saveAndRestore_crash_3() saveHistory(hist2, &buffer); hist2->clear(); } - delete page2; } void tst_QWebEngineHistory::saveAndRestore_crash_4() @@ -406,18 +404,18 @@ void tst_QWebEngineHistory::saveAndRestore_crash_4() QByteArray buffer; saveHistory(hist, &buffer); - QWebEnginePage* page2 = new QWebEnginePage(this); + QScopedPointer<QWebEnginePage> page2(new QWebEnginePage(this)); // The initial crash was in PageCache. page2->settings()->setMaximumPagesInCache(3); // Load the history in a new page, waiting for the load to finish. QEventLoop waitForLoadFinished; - QObject::connect(page2, SIGNAL(loadFinished(bool)), &waitForLoadFinished, SLOT(quit()), Qt::QueuedConnection); + QObject::connect(page2.data(), SIGNAL(loadFinished(bool)), &waitForLoadFinished, SLOT(quit()), Qt::QueuedConnection); QDataStream load(&buffer, QIODevice::ReadOnly); load >> *page2->history(); waitForLoadFinished.exec(); - delete page2; + page2.reset(); // Give some time for the PageCache cleanup 0-timer to fire. QTest::qWait(50); #endif @@ -456,12 +454,11 @@ void tst_QWebEngineHistory::clear() QVERIFY(hist->count() == 1); // Leave current item. QVERIFY(!actionBack->isEnabled()); - QWebEnginePage* page2 = new QWebEnginePage(this); - QWebEngineHistory* hist2 = page2->history(); + QWebEnginePage page2(this); + QWebEngineHistory* hist2 = page2.history(); QVERIFY(hist2->count() == 0); hist2->clear(); QVERIFY(hist2->count() == 0); // Do not change anything. - delete page2; } void tst_QWebEngineHistory::historyItemFromDeletedPage() diff --git a/tests/auto/widgets/qwebenginepage/qwebenginepage.pro b/tests/auto/widgets/qwebenginepage/qwebenginepage.pro index 70786e70f..df733c473 100644 --- a/tests/auto/widgets/qwebenginepage/qwebenginepage.pro +++ b/tests/auto/widgets/qwebenginepage/qwebenginepage.pro @@ -1,2 +1,4 @@ include(../tests.pri) QT *= core-private gui-private + +contains(WEBENGINE_CONFIG, enable_pdf): DEFINES+=QWEBENGINEPAGE_PDFPRINTINGENABLED diff --git a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp index f16c42976..287af511f 100644 --- a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp +++ b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp @@ -333,25 +333,23 @@ protected: void tst_QWebEnginePage::acceptNavigationRequest() { - QWebEngineView *view = new QWebEngineView(); - QSignalSpy loadSpy(view, SIGNAL(loadFinished(bool))); + QWebEngineView view; + QSignalSpy loadSpy(&view, SIGNAL(loadFinished(bool))); - NavigationRequestOverride* newPage = new NavigationRequestOverride(view, false); - view->setPage(newPage); + NavigationRequestOverride* newPage = new NavigationRequestOverride(&view, false); + view.setPage(newPage); - view->setHtml(QString("<html><body><form name='tstform' action='data:text/html,foo'method='get'>" + view.setHtml(QString("<html><body><form name='tstform' action='data:text/html,foo'method='get'>" "<input type='text'><input type='submit'></form></body></html>"), QUrl()); QTRY_COMPARE(loadSpy.count(), 1); - evaluateJavaScriptSync(view->page(), "tstform.submit();"); + evaluateJavaScriptSync(view.page(), "tstform.submit();"); newPage->m_acceptNavigationRequest = true; - evaluateJavaScriptSync(view->page(), "tstform.submit();"); + evaluateJavaScriptSync(view.page(), "tstform.submit();"); QTRY_COMPARE(loadSpy.count(), 2); - QCOMPARE(toPlainTextSync(view->page()), QString("foo?")); - - delete view; + QCOMPARE(toPlainTextSync(view.page()), QString("foo?")); } class JSTestPage : public QWebEnginePage @@ -389,11 +387,10 @@ private: /* void tst_QWebEnginePage::infiniteLoopJS() { - JSTestPage* newPage = new JSTestPage(m_view); - m_view->setPage(newPage); + JSTestPage newPage(m_view); + m_view->setPage(&newPage); m_view->setHtml(QString("<html><body>test</body></html>"), QUrl()); m_view->page()->evaluateJavaScript("var run = true; var a = 1; while (run) { a++; }"); - delete newPage; } */ @@ -409,9 +406,9 @@ void tst_QWebEnginePage::geolocationRequestJS() { QFETCH(bool, allowed); QFETCH(int, errorCode); - QWebEngineView *view = new QWebEngineView; - JSTestPage *newPage = new JSTestPage(view); - newPage->setView(view); + QWebEngineView view; + JSTestPage *newPage = new JSTestPage(&view); + newPage->setView(&view); newPage->setGeolocationPermission(allowed); connect(newPage, SIGNAL(featurePermissionRequested(const QUrl&, QWebEnginePage::Feature)), @@ -420,10 +417,8 @@ void tst_QWebEnginePage::geolocationRequestJS() QSignalSpy spyLoadFinished(newPage, SIGNAL(loadFinished(bool))); newPage->setHtml(QString("<html><body>test</body></html>"), QUrl("qrc://secure/origin")); QTRY_COMPARE(spyLoadFinished.count(), 1); - if (evaluateJavaScriptSync(newPage, QLatin1String("!navigator.geolocation")).toBool()) { - delete view; + if (evaluateJavaScriptSync(newPage, QLatin1String("!navigator.geolocation")).toBool()) W_QSKIP("Geolocation is not supported.", SkipSingle); - } evaluateJavaScriptSync(newPage, "var errorCode = 0; var done = false; function error(err) { errorCode = err.code; done = true; } function success(pos) { done = true; } navigator.geolocation.getCurrentPosition(success, error)"); @@ -432,8 +427,6 @@ void tst_QWebEnginePage::geolocationRequestJS() if (result == 2) QEXPECT_FAIL("", "No location service available.", Continue); QCOMPARE(result, errorCode); - - delete view; } void tst_QWebEnginePage::loadFinished() @@ -490,7 +483,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 +655,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 +674,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 +692,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 +720,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 +749,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 +772,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 } @@ -1225,7 +1226,7 @@ void tst_QWebEnginePage::cursorMovements() #if !defined(QWEBENGINEPAGE_SELECTEDTEXT) QSKIP("QWEBENGINEPAGE_SELECTEDTEXT"); #else - CursorTrackedPage* page = new CursorTrackedPage; + QScopedPointer<CursorTrackedPage> page(new CursorTrackedPage); QString content("<html><body><p id=one>The quick brown fox</p><p id=two>jumps over the lazy dog</p><p>May the source<br/>be with you!</p></body></html>"); page->setHtml(content); @@ -1234,7 +1235,7 @@ void tst_QWebEnginePage::cursorMovements() "var node = document.getElementById(\"one\"); " \ "range.selectNode(node); " \ "getSelection().addRange(range);"; - evaluateJavaScriptSync(page, script); + evaluateJavaScriptSync(page.data(), script); QCOMPARE(page->selectedText().trimmed(), QString::fromLatin1("The quick brown fox")); QRegExp regExp(" style=\".*\""); @@ -1415,20 +1416,18 @@ void tst_QWebEnginePage::cursorMovements() page->triggerAction(QWebEnginePage::MoveToNextWord); QVERIFY(page->isSelectionCollapsed()); QCOMPARE(page->selectionStartOffset(), 12); - - delete page; #endif } void tst_QWebEnginePage::textSelection() { - QWebEngineView *view = new QWebEngineView; - CursorTrackedPage *page = new CursorTrackedPage(view); + QWebEngineView view; + CursorTrackedPage *page = new CursorTrackedPage(&view); QString content("<html><body><p id=one>The quick brown fox</p>" \ "<p id=two>jumps over the lazy dog</p>" \ "<p>May the source<br/>be with you!</p></body></html>"); - page->setView(view); - QSignalSpy loadSpy(view, SIGNAL(loadFinished(bool))); + page->setView(&view); + QSignalSpy loadSpy(&view, SIGNAL(loadFinished(bool))); page->setHtml(content); QTRY_COMPARE(loadSpy.count(), 1); @@ -1522,8 +1521,6 @@ void tst_QWebEnginePage::textSelection() QCOMPARE(page->action(QWebEnginePage::SelectStartOfDocument)->isEnabled(), true); QCOMPARE(page->action(QWebEnginePage::SelectEndOfDocument)->isEnabled(), true); #endif - - delete view; } void tst_QWebEnginePage::textEditing() @@ -1531,7 +1528,7 @@ void tst_QWebEnginePage::textEditing() #if !defined(QWEBENGINEPAGE_EVALUATEJAVASCRIPT) QSKIP("QWEBENGINEPAGE_EVALUATEJAVASCRIPT"); #else - CursorTrackedPage* page = new CursorTrackedPage; + QScopedPointer<CursorTrackedPage> page(new CursorTrackedPage); QString content("<html><body><p id=one>The quick brown fox</p>" \ "<p id=two>jumps over the lazy dog</p>" \ "<p>May the source<br/>be with you!</p></body></html>"); @@ -1644,8 +1641,6 @@ void tst_QWebEnginePage::textEditing() // this is only true if there is an editable selection QCOMPARE(page->action(QWebEnginePage::Cut)->isEnabled(), true); QCOMPARE(page->action(QWebEnginePage::RemoveFormat)->isEnabled(), true); - - delete page; #endif } @@ -1711,12 +1706,12 @@ void tst_QWebEnginePage::inputMethods() QFETCH(QString, viewType); QWebEnginePage* page = new QWebEnginePage; QObject* view = 0; - QObject* container = 0; + QScopedPointer<QObject> container(0); if (viewType == "QWebEngineView") { QWebEngineView* wv = new QWebEngineView; wv->setPage(page); view = wv; - container = view; + container.reset(view); } else if (viewType == "QGraphicsWebView") { QGraphicsWebView* wv = new QGraphicsWebView; wv->setPage(page); @@ -1728,7 +1723,7 @@ void tst_QWebEnginePage::inputMethods() scene->addItem(wv); wv->setGeometry(QRect(0, 0, 500, 500)); - container = gv; + container.reset(gv); } else QVERIFY2(false, "Unknown view type"); @@ -2396,8 +2391,6 @@ void tst_QWebEnginePage::inputMethods() QCOMPARE(inputValue2, QString("\n\nthird line")); // END - Newline test for textarea - - delete container; #endif } @@ -2736,22 +2729,19 @@ void tst_QWebEnginePage::screenshot() QDir::setCurrent(TESTS_SOURCE_DIR); QFETCH(QString, html); - QWebEnginePage* page = new QWebEnginePage; - page->settings()->setAttribute(QWebEngineSettings::PluginsEnabled, true); - page->setHtml(html, QUrl::fromLocalFile(TESTS_SOURCE_DIR)); - ::waitForSignal(page, SIGNAL(loadFinished(bool)), 2000); + QWebEnginePage page; + page.settings()->setAttribute(QWebEngineSettings::PluginsEnabled, true); + page.setHtml(html, QUrl::fromLocalFile(TESTS_SOURCE_DIR)); + QVERIFY(spyFinished.wait(2000)); // take screenshot without a view - takeScreenshot(page); + takeScreenshot(&page); - QWebEngineView* view = new QWebEngineView; - view->setPage(page); + QWebEngineView view; + view.setPage(&page); // take screenshot when attached to a view - takeScreenshot(page); - - delete page; - delete view; + takeScreenshot(&page); QDir::setCurrent(QApplication::applicationDirPath()); #endif @@ -2865,7 +2855,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 +3208,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 +3264,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,9 +3316,10 @@ 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_WITH_TIMEOUT(loadSpy.isFinished(), 500); + QTRY_VERIFY(loadSpy.isFinished()); } void tst_QWebEnginePage::undoActionHaveCustomText() @@ -3412,26 +3406,25 @@ private: void tst_QWebEnginePage::getUserMediaRequest() { - GetUserMediaTestPage *page = new GetUserMediaTestPage(); + GetUserMediaTestPage page; // We need to load content from a resource in order for the securityOrigin to be valid. - QSignalSpy loadSpy(page, SIGNAL(loadFinished(bool))); - page->load(QUrl("qrc:///resources/content.html")); + QSignalSpy loadSpy(&page, SIGNAL(loadFinished(bool))); + page.load(QUrl("qrc:///resources/content.html")); QTRY_COMPARE(loadSpy.count(), 1); - QVERIFY(evaluateJavaScriptSync(page, QStringLiteral("!!navigator.webkitGetUserMedia")).toBool()); - evaluateJavaScriptSync(page, QStringLiteral("navigator.webkitGetUserMedia({audio: true}, function() {}, function(){})")); - QTRY_VERIFY(page->gotFeatureRequest(QWebEnginePage::MediaAudioCapture)); + QVERIFY(evaluateJavaScriptSync(&page, QStringLiteral("!!navigator.webkitGetUserMedia")).toBool()); + evaluateJavaScriptSync(&page, QStringLiteral("navigator.webkitGetUserMedia({audio: true}, function() {}, function(){})")); + QTRY_VERIFY(page.gotFeatureRequest(QWebEnginePage::MediaAudioCapture)); // Might end up failing due to the lack of physical media devices deeper in the content layer, so the JS callback is not guaranteed to be called, // but at least we go through that code path, potentially uncovering failing assertions. - page->acceptPendingRequest(); + page.acceptPendingRequest(); - page->runJavaScript(QStringLiteral("errorCallbackCalled = false;")); - evaluateJavaScriptSync(page, QStringLiteral("navigator.webkitGetUserMedia({audio: true, video: true}, function() {}, function(){errorCallbackCalled = true;})")); - QTRY_VERIFY(page->gotFeatureRequest(QWebEnginePage::MediaAudioVideoCapture)); - page->rejectPendingRequest(); // Should always end up calling the error callback in JS. - QTRY_VERIFY(evaluateJavaScriptSync(page, QStringLiteral("errorCallbackCalled;")).toBool()); - delete page; + page.runJavaScript(QStringLiteral("errorCallbackCalled = false;")); + evaluateJavaScriptSync(&page, QStringLiteral("navigator.webkitGetUserMedia({audio: true, video: true}, function() {}, function(){errorCallbackCalled = true;})")); + QTRY_VERIFY(page.gotFeatureRequest(QWebEnginePage::MediaAudioVideoCapture)); + page.rejectPendingRequest(); // Should always end up calling the error callback in JS. + QTRY_VERIFY(evaluateJavaScriptSync(&page, QStringLiteral("errorCallbackCalled;")).toBool()); } void tst_QWebEnginePage::savePage() @@ -3449,7 +3442,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 +3454,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); } @@ -3704,13 +3698,13 @@ void tst_QWebEnginePage::runJavaScript() void tst_QWebEnginePage::fullScreenRequested() { JavaScriptCallbackWatcher watcher; - QWebEngineView* view = new QWebEngineView; - QWebEnginePage* page = view->page(); - view->show(); + QWebEngineView view; + QWebEnginePage* page = view.page(); + view.show(); page->settings()->setAttribute(QWebEngineSettings::FullScreenSupportEnabled, true); - QSignalSpy loadSpy(view, SIGNAL(loadFinished(bool))); + QSignalSpy loadSpy(&view, SIGNAL(loadFinished(bool))); page->load(QUrl("qrc:///resources/fullscreen.html")); QTRY_COMPARE(loadSpy.count(), 1); @@ -3725,7 +3719,7 @@ void tst_QWebEnginePage::fullScreenRequested() if (acceptRequest) request.accept(); else request.reject(); }); - QTest::keyPress(view->focusProxy(), Qt::Key_Space); + QTest::keyPress(view.focusProxy(), Qt::Key_Space); QTRY_VERIFY(evaluateJavaScriptSync(page, "document.webkitIsFullScreen").toBool()); page->runJavaScript("document.webkitExitFullscreen()", JavaScriptCallbackUndefined()); QVERIFY(watcher.wait()); @@ -3733,12 +3727,10 @@ void tst_QWebEnginePage::fullScreenRequested() acceptRequest = false; page->runJavaScript("document.webkitFullscreenEnabled", JavaScriptCallback(true)); - QTest::keyPress(view->focusProxy(), Qt::Key_Space); + QTest::keyPress(view.focusProxy(), Qt::Key_Space); QVERIFY(watcher.wait()); page->runJavaScript("document.webkitIsFullScreen", JavaScriptCallback(false)); QVERIFY(watcher.wait()); - - delete view; } void tst_QWebEnginePage::symmetricUrl() @@ -3791,7 +3783,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 +3805,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 +3915,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 +3925,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); @@ -3941,13 +3934,13 @@ void tst_QWebEnginePage::requestedUrlAfterSetAndLoadFailures() void tst_QWebEnginePage::asyncAndDelete() { - QWebEnginePage *page = new QWebEnginePage; + QScopedPointer<QWebEnginePage> page(new QWebEnginePage); CallbackSpy<QString> plainTextSpy; CallbackSpy<QString> htmlSpy; page->toPlainText(plainTextSpy.ref()); page->toHtml(htmlSpy.ref()); - delete page; + page.reset(); // Pending callbacks should be called with an empty value in the page's destructor. QCOMPARE(plainTextSpy.waitForResult(), QString()); QVERIFY(plainTextSpy.wasCalled()); @@ -4016,14 +4009,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 +4042,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 +4074,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 +4255,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 +4323,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 +4438,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 +4599,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,39 +4800,37 @@ 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); } void tst_QWebEnginePage::restoreHistory() { - QWebChannel *channel = new QWebChannel; - QWebEnginePage *page = new QWebEnginePage; - page->setWebChannel(channel); + QWebChannel channel; + QWebEnginePage page; + page.setWebChannel(&channel); QWebEngineScript script; script.setName(QStringLiteral("script")); - page->scripts().insert(script); + page.scripts().insert(script); - QSignalSpy spy(page, SIGNAL(loadFinished(bool))); - page->load(QUrl(QStringLiteral("qrc:/resources/test1.html"))); + QSignalSpy spy(&page, SIGNAL(loadFinished(bool))); + page.load(QUrl(QStringLiteral("qrc:/resources/test1.html"))); QTRY_COMPARE(spy.count(), 1); - QCOMPARE(page->webChannel(), channel); - QVERIFY(page->scripts().contains(script)); + QCOMPARE(page.webChannel(), &channel); + QVERIFY(page.scripts().contains(script)); QByteArray data; QDataStream out(&data, QIODevice::ReadWrite); - out << *page->history(); + out << *page.history(); QDataStream in(&data, QIODevice::ReadOnly); - in >> *page->history(); + in >> *page.history(); QTRY_COMPARE(spy.count(), 2); - QCOMPARE(page->webChannel(), channel); - QVERIFY(page->scripts().contains(script)); - - delete page; - delete channel; + QCOMPARE(page.webChannel(), &channel); + QVERIFY(page.scripts().contains(script)); } void tst_QWebEnginePage::toPlainTextLoadFinishedRace_data() @@ -4848,33 +4844,33 @@ void tst_QWebEnginePage::toPlainTextLoadFinishedRace() { QFETCH(bool, enableErrorPage); - QWebEnginePage *page = new QWebEnginePage; + QScopedPointer<QWebEnginePage> page(new QWebEnginePage); page->settings()->setAttribute(QWebEngineSettings::ErrorPageEnabled, enableErrorPage); - QSignalSpy spy(page, SIGNAL(loadFinished(bool))); + QSignalSpy spy(page.data(), SIGNAL(loadFinished(bool))); page->load(QUrl("data:text/plain,foobarbaz")); QTRY_VERIFY(spy.count() == 1); - QCOMPARE(toPlainTextSync(page), QString("foobarbaz")); + QCOMPARE(toPlainTextSync(page.data()), QString("foobarbaz")); page->load(QUrl("fail:unknown/scheme")); QTRY_VERIFY(spy.count() == 2); - QString s = toPlainTextSync(page); + QString s = toPlainTextSync(page.data()); QVERIFY(s.contains("foobarbaz") == !enableErrorPage); page->load(QUrl("data:text/plain,lalala")); QTRY_VERIFY(spy.count() == 3); - QCOMPARE(toPlainTextSync(page), QString("lalala")); - delete page; + QCOMPARE(toPlainTextSync(page.data()), QString("lalala")); + page.reset(); QVERIFY(spy.count() == 3); } void tst_QWebEnginePage::setZoomFactor() { - QWebEnginePage *page = new QWebEnginePage; + QWebEnginePage page; - QVERIFY(qFuzzyCompare(page->zoomFactor(), 1.0)); - page->setZoomFactor(2.5); - QVERIFY(qFuzzyCompare(page->zoomFactor(), 2.5)); + QVERIFY(qFuzzyCompare(page.zoomFactor(), 1.0)); + page.setZoomFactor(2.5); + QVERIFY(qFuzzyCompare(page.zoomFactor(), 2.5)); const QUrl urlToLoad("qrc:/resources/test1.html"); @@ -4882,19 +4878,20 @@ void tst_QWebEnginePage::setZoomFactor() m_page->setUrl(urlToLoad); QTRY_COMPARE(finishedSpy.count(), 1); QVERIFY(finishedSpy.at(0).first().toBool()); - QVERIFY(qFuzzyCompare(page->zoomFactor(), 2.5)); + QVERIFY(qFuzzyCompare(page.zoomFactor(), 2.5)); - page->setZoomFactor(5.5); - QVERIFY(qFuzzyCompare(page->zoomFactor(), 2.5)); + page.setZoomFactor(5.5); + QVERIFY(qFuzzyCompare(page.zoomFactor(), 2.5)); - page->setZoomFactor(0.1); - QVERIFY(qFuzzyCompare(page->zoomFactor(), 2.5)); - - delete page; + page.setZoomFactor(0.1); + QVERIFY(qFuzzyCompare(page.zoomFactor(), 2.5)); } void tst_QWebEnginePage::printToPdf() { +#if !defined(QWEBENGINEPAGE_PDFPRINTINGENABLED) + QSKIP("QWEBENGINEPAGE_PDFPRINTINGENABLED"); +#else QTemporaryDir tempDir(QDir::tempPath() + "/tst_qwebengineview-XXXXXX"); QVERIFY(tempDir.isValid()); QWebEnginePage page; @@ -4922,14 +4919,15 @@ void tst_QWebEnginePage::printToPdf() CallbackSpy<QByteArray> failedInvalidLayoutSpy; page.printToPdf(failedInvalidLayoutSpy.ref(), QPageLayout()); QCOMPARE(failedInvalidLayoutSpy.waitForResult().length(), 0); +#endif } void tst_QWebEnginePage::mouseButtonTranslation() { - QWebEngineView *view = new QWebEngineView; + QWebEngineView view; - QSignalSpy spy(view, SIGNAL(loadFinished(bool))); - view->setHtml(QStringLiteral( + QSignalSpy spy(&view, SIGNAL(loadFinished(bool))); + view.setHtml(QStringLiteral( "<html><head><script>\ var lastEvent = { 'button' : -1 }; \ function saveLastEvent(event) { console.log(event); lastEvent = event; }; \ @@ -4938,25 +4936,23 @@ void tst_QWebEnginePage::mouseButtonTranslation() <div style=\"height:600px;\" onmousedown=\"saveLastEvent(event)\">\ </div>\ </body></html>")); - view->show(); - QTest::qWaitForWindowExposed(view); + view.show(); + QTest::qWaitForWindowExposed(&view); QTRY_VERIFY(spy.count() == 1); - QVERIFY(view->focusProxy() != nullptr); - - QMouseEvent evpres(QEvent::MouseButtonPress, view->rect().center(), Qt::LeftButton, Qt::LeftButton, Qt::NoModifier); - QGuiApplication::sendEvent(view->focusProxy(), &evpres); + QVERIFY(view.focusProxy() != nullptr); - QTRY_COMPARE(evaluateJavaScriptSync(view->page(), "lastEvent.button").toInt(), 0); - QCOMPARE(evaluateJavaScriptSync(view->page(), "lastEvent.buttons").toInt(), 1); + QMouseEvent evpres(QEvent::MouseButtonPress, view.rect().center(), Qt::LeftButton, Qt::LeftButton, Qt::NoModifier); + QGuiApplication::sendEvent(view.focusProxy(), &evpres); - QMouseEvent evpres2(QEvent::MouseButtonPress, view->rect().center(), Qt::RightButton, Qt::LeftButton | Qt::RightButton, Qt::NoModifier); - QGuiApplication::sendEvent(view->focusProxy(), &evpres2); + QTRY_COMPARE(evaluateJavaScriptSync(view.page(), "lastEvent.button").toInt(), 0); + QCOMPARE(evaluateJavaScriptSync(view.page(), "lastEvent.buttons").toInt(), 1); - QTRY_COMPARE(evaluateJavaScriptSync(view->page(), "lastEvent.button").toInt(), 2); - QCOMPARE(evaluateJavaScriptSync(view->page(), "lastEvent.buttons").toInt(), 3); + QMouseEvent evpres2(QEvent::MouseButtonPress, view.rect().center(), Qt::RightButton, Qt::LeftButton | Qt::RightButton, Qt::NoModifier); + QGuiApplication::sendEvent(view.focusProxy(), &evpres2); - delete view; + QTRY_COMPARE(evaluateJavaScriptSync(view.page(), "lastEvent.button").toInt(), 2); + QCOMPARE(evaluateJavaScriptSync(view.page(), "lastEvent.buttons").toInt(), 3); } QPoint tst_QWebEnginePage::elementCenter(QWebEnginePage *page, const QString &id) @@ -5035,20 +5031,18 @@ void tst_QWebEnginePage::viewSourceURL() QFETCH(QUrl, requestedUrl); QFETCH(QString, title); - QWebEnginePage *page = new QWebEnginePage; - QSignalSpy loadFinishedSpy(page, SIGNAL(loadFinished(bool))); + QWebEnginePage page; + QSignalSpy loadFinishedSpy(&page, SIGNAL(loadFinished(bool))); - page->load(userInputUrl); + page.load(userInputUrl); QTRY_COMPARE(loadFinishedSpy.count(), 1); QList<QVariant> arguments = loadFinishedSpy.takeFirst(); QCOMPARE(arguments.at(0).toBool(), loadSucceed); - QCOMPARE(page->url(), url); - QCOMPARE(page->requestedUrl(), requestedUrl); - QCOMPARE(page->title(), title); - QVERIFY(!page->action(QWebEnginePage::ViewSource)->isEnabled()); - - delete page; + QCOMPARE(page.url(), url); + QCOMPARE(page.requestedUrl(), requestedUrl); + QCOMPARE(page.title(), title); + QVERIFY(!page.action(QWebEnginePage::ViewSource)->isEnabled()); } QTEST_MAIN(tst_QWebEnginePage) diff --git a/tests/auto/widgets/qwebenginescript/tst_qwebenginescript.cpp b/tests/auto/widgets/qwebenginescript/tst_qwebenginescript.cpp index d5ecd8841..c10ae2886 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 4db5b9477..c7b083660 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/BLACKLIST b/tests/auto/widgets/qwebengineview/BLACKLIST new file mode 100644 index 000000000..0a909d0f6 --- /dev/null +++ b/tests/auto/widgets/qwebengineview/BLACKLIST @@ -0,0 +1,2 @@ +[doNotSendMouseKeyboardEventsWhenDisabled] +windows diff --git a/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp b/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp index 9966ad9ee..2baadd869 100644 --- a/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp +++ b/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp @@ -31,8 +31,11 @@ #include <qdiriterator.h> #include <qstackedlayout.h> #include <qtemporarydir.h> +#include <QCompleter> #include <QLineEdit> #include <QHBoxLayout> +#include <QQuickItem> +#include <QQuickWidget> #define VERIFY_INPUTMETHOD_HINTS(actual, expect) \ QVERIFY(actual == expect); @@ -83,6 +86,7 @@ private Q_SLOTS: void inputMethodsTextFormat_data(); void inputMethodsTextFormat(); void keyboardEvents(); + void keyboardFocusAfterPopup(); }; // This will be called before the first test function is executed. @@ -177,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(); @@ -281,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]")); @@ -400,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)); @@ -562,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); @@ -584,7 +592,7 @@ void tst_QWebEngineView::renderingAfterMaxAndBack() "</html>"); view.page()->load(url2); - QVERIFY(waitForSignal(&view, SIGNAL(loadFinished(bool)))); + QVERIFY(spyFinished.wait()); view.showMaximized(); @@ -840,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())); } @@ -1014,5 +1026,60 @@ void tst_QWebEngineView::keyboardEvents() QVERIFY(loadFinishedSpy.wait()); } +void tst_QWebEngineView::keyboardFocusAfterPopup() +{ + QScopedPointer<QWidget> containerWidget(new QWidget); + + QLineEdit *urlLine = new QLineEdit(containerWidget.data()); + QStringList urlList; + urlList << "test"; + QCompleter *completer = new QCompleter(urlList, urlLine); + completer->setCompletionMode(QCompleter::PopupCompletion); + urlLine->setCompleter(completer); + urlLine->setFocus(); + + QWebEngineView *webView = new QWebEngineView(containerWidget.data()); + QSignalSpy loadFinishedSpy(webView, SIGNAL(loadFinished(bool))); + + connect(urlLine, &QLineEdit::editingFinished, [=] { + webView->setHtml("<html><body onload=\"document.getElementById('input1').focus()\">" + " <input type='text' id='input1' />" + "</body></html>"); + + // Check whether the RenderWidgetHostView has the keyboard focus + QQuickWidget *rwhv = qobject_cast<QQuickWidget *>(webView->focusProxy()); + QVERIFY(rwhv); + QVERIFY(rwhv->hasFocus()); + QVERIFY(rwhv->rootObject()->hasFocus()); + QVERIFY(rwhv->window()->windowHandle()->isActive()); + QVERIFY(rwhv->rootObject()->hasActiveFocus()); + }); + + QVBoxLayout *layout = new QVBoxLayout; + layout->addWidget(urlLine); + layout->addWidget(webView); + + containerWidget->setLayout(layout); + containerWidget->show(); + QTest::qWaitForWindowExposed(containerWidget.data()); + + // Trigger completer's popup and select the first suggestion + QTest::keyClick(urlLine, Qt::Key_T); + qApp->processEvents(); + QTRY_VERIFY(qApp->activePopupWidget()); + QTest::keyClick(qApp->activePopupWidget(), Qt::Key_Down); + qApp->processEvents(); + QTest::keyClick(qApp->activePopupWidget(), Qt::Key_Enter); + qApp->processEvents(); + + // After the load the focused window should forward the keyboard events to the webView + QVERIFY(loadFinishedSpy.wait()); + // Wait for active focus on the input field + QTRY_COMPARE(evaluateJavaScriptSync(webView->page(), "document.activeElement.id").toString(), QStringLiteral("input1")); + QTest::keyClick(qApp->focusWindow(), Qt::Key_X); + qApp->processEvents(); + QTRY_COMPARE(evaluateJavaScriptSync(webView->page(), "document.getElementById('input1').value").toString(), QStringLiteral("x")); +} + QTEST_MAIN(tst_QWebEngineView) #include "tst_qwebengineview.moc" diff --git a/tests/auto/widgets/tests.pri b/tests/auto/widgets/tests.pri index ca19a9496..14074cd08 100644 --- a/tests/auto/widgets/tests.pri +++ b/tests/auto/widgets/tests.pri @@ -12,7 +12,7 @@ INCLUDEPATH += $$PWD RESOURCES += ../resources/tests.qrc exists($$_PRO_FILE_PWD_/$${TARGET}.qrc): RESOURCES += $${TARGET}.qrc -QT += testlib network webenginewidgets widgets +QT += testlib network webenginewidgets widgets quick quickwidgets macx: CONFIG -= app_bundle # This define is used by some tests to look up resources in the source tree diff --git a/tests/auto/widgets/util.h b/tests/auto/widgets/util.h index 770579f1f..356cf6ebb 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 |