diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2019-07-24 10:40:08 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2019-07-24 10:40:08 +0200 |
commit | 5dd44f34a58b966ddc374d828b1979b9c689b1b5 (patch) | |
tree | c9beec83e2454bc7d001bdc116620b3cc323d7a4 /tests | |
parent | 57363264cd0ff4b2f45f5344e18436fe419e2e95 (diff) | |
parent | b73e4ce6f7cfe35a85b9a41e1a5ab36783e5edb0 (diff) |
Merge remote-tracking branch 'origin/5.13' into dev
Conflicts:
src/3rdparty
src/core/core_chromium.pri
tests/auto/quick/qmltests/BLACKLIST
tests/auto/quick/qquickwebengineview/BLACKLIST
tests/auto/widgets/qwebenginepage/BLACKLIST
tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp
tests/auto/widgets/qwebengineview/BLACKLIST
Change-Id: I11b26f5eebde29c4c62247b90e11e3ae40789fe4
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/quick/dialogs/WebView.qml | 9 | ||||
-rw-r--r-- | tests/auto/quick/inspectorserver/tst_inspectorserver.cpp | 2 | ||||
-rw-r--r-- | tests/auto/quick/qmltests/BLACKLIST | 5 | ||||
-rw-r--r-- | tests/auto/quick/qmltests/data/tst_findText.qml | 22 | ||||
-rw-r--r-- | tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp | 66 | ||||
-rw-r--r-- | tests/auto/widgets/qwebengineview/BLACKLIST | 4 | ||||
-rw-r--r-- | tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp | 4 | ||||
-rw-r--r-- | tests/auto/widgets/spellchecking/tst_spellchecking.cpp | 43 |
8 files changed, 126 insertions, 29 deletions
diff --git a/tests/auto/quick/dialogs/WebView.qml b/tests/auto/quick/dialogs/WebView.qml index 4f8b7a0ce..01f4ac297 100644 --- a/tests/auto/quick/dialogs/WebView.qml +++ b/tests/auto/quick/dialogs/WebView.qml @@ -56,11 +56,12 @@ Window { WebEngineView { id: view anchors.fill: parent - onLoadingChanged: function(reqeust) { - if (reqeust.status === WebEngineView.LoadSucceededStatus) { + onLoadingChanged: function(request) { + if (request.status === WebEngineView.LoadSucceededStatus) { handler.ready = true - } else { - console.log("Wooohooo loading page from qrc failed !") + } else if (request.status === WebEngineView.LoadFailedStatus) { + console.log("Page was not successfully loaded from qrc! Status: " + request.status + + ", error [code: " + request.errorCode + "]: '" + request.errorString + "'") } } diff --git a/tests/auto/quick/inspectorserver/tst_inspectorserver.cpp b/tests/auto/quick/inspectorserver/tst_inspectorserver.cpp index 8e23e86e8..922c7769e 100644 --- a/tests/auto/quick/inspectorserver/tst_inspectorserver.cpp +++ b/tests/auto/quick/inspectorserver/tst_inspectorserver.cpp @@ -167,7 +167,7 @@ void tst_InspectorServer::openRemoteDebuggingSession() // - The page list didn't return a valid inspector URL // - Or the front-end couldn't be loaded through the inspector HTTP server // - Or the web socket connection couldn't be established between the front-end and the page through the inspector server - QTRY_VERIFY(inspectorWebView->title().startsWith("DevTools -")); + QTRY_VERIFY_WITH_TIMEOUT(inspectorWebView->title().startsWith("DevTools -"), 20000); } QTEST_MAIN(tst_InspectorServer) diff --git a/tests/auto/quick/qmltests/BLACKLIST b/tests/auto/quick/qmltests/BLACKLIST index 0a71e9f27..46bc65923 100644 --- a/tests/auto/quick/qmltests/BLACKLIST +++ b/tests/auto/quick/qmltests/BLACKLIST @@ -1,7 +1,2 @@ -[WebViewFindText::test_findTextInterruptedByLoad] -linux -qemu -b2qt -windows [WebEngineViewSource::test_viewSourceURL] * diff --git a/tests/auto/quick/qmltests/data/tst_findText.qml b/tests/auto/quick/qmltests/data/tst_findText.qml index 1ec574fae..14053a675 100644 --- a/tests/auto/quick/qmltests/data/tst_findText.qml +++ b/tests/auto/quick/qmltests/data/tst_findText.qml @@ -43,13 +43,21 @@ TestWebEngineView { matchCount = -1 } + function findCallbackCalled() { return matchCount != -1 } + function findTextCallback(matchCount) { + // If this starts to fail then either clear was not called before findText + // or unexpected callback was triggered from some search. + // On c++ side callback id can be checked to verify + testcase.verify(!findCallbackCalled(), 'Unexpected callback call or uncleared state before findText call!') + webEngineView.matchCount = matchCount findFailed = matchCount == 0 } TestCase { + id: testcase name: "WebViewFindText" function getBodyInnerHTML() { @@ -207,13 +215,17 @@ TestWebEngineView { webEngineView.findText("hello", findFlags, webEngineView.findTextCallback); // This should not crash. - webEngineView.url = "https://www.qt.io"; - if (!webEngineView.waitForLoadSucceeded(12000)) - skip("Couldn't load page from network, skipping test."); + webEngineView.loadHtml("<html><body>New page with same hello text</body></html>") + verify(webEngineView.waitForLoadSucceeded()) // The callback is not supposed to be called, see QTBUG-61506. - // Check whether the callback was called (-1 = no, other values = yes). - tryVerify(function() { return webEngineView.matchCount == -1; }, 20000); + expectFailContinue('', 'No unexpected findText callback calls occurred.') + tryVerify(function() { return webEngineView.findCallbackCalled() }) + verify(!webEngineView.findCallbackCalled()) + + webEngineView.clear(); + webEngineView.findText('New page', findFlags, webEngineView.findTextCallback) + tryCompare(webEngineView, 'matchCount', 1) } } } diff --git a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp index 8fb7e05ca..713feca6d 100644 --- a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp +++ b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp @@ -220,6 +220,8 @@ private Q_SLOTS: void editActionsWithFocusOnIframe(); void editActionsWithoutSelection(); + void customUserAgentInNewTab(); + private: static QPoint elementCenter(QWebEnginePage *page, const QString &id); @@ -932,6 +934,7 @@ void tst_QWebEnginePage::findText() QTRY_COMPARE(loadSpy.count(), 1); // Select whole page contents. + QTRY_VERIFY(m_view->page()->action(QWebEnginePage::SelectAll)->isEnabled()); m_view->page()->triggerAction(QWebEnginePage::SelectAll); QTRY_COMPARE(m_view->hasSelection(), true); @@ -4183,6 +4186,69 @@ void tst_QWebEnginePage::editActionsWithoutSelection() QVERIFY(page->action(QWebEnginePage::Unselect)->isEnabled()); } +void tst_QWebEnginePage::customUserAgentInNewTab() +{ + HttpServer server; + QByteArray lastUserAgent; + connect(&server, &HttpServer::newRequest, [&](HttpReqRep *rr) { + QCOMPARE(rr->requestMethod(), "GET"); + lastUserAgent = rr->requestHeader("user-agent"); + rr->setResponseBody(QByteArrayLiteral("<html><body>Test</body></html>")); + rr->sendResponse(); + }); + QVERIFY(server.start()); + + class Page : public QWebEnginePage { + public: + QWebEngineProfile *targetProfile = nullptr; + QScopedPointer<QWebEnginePage> newPage; + Page(QWebEngineProfile *profile) : QWebEnginePage(profile) {} + private: + QWebEnginePage *createWindow(WebWindowType) override + { + newPage.reset(new QWebEnginePage(targetProfile ? targetProfile : profile(), nullptr)); + return newPage.data(); + } + }; + QWebEngineProfile profile1, profile2; + profile1.setHttpUserAgent(QStringLiteral("custom 1")); + profile2.setHttpUserAgent(QStringLiteral("custom 2")); + Page page(&profile1); + QWebEngineView view; + view.resize(500, 500); + view.setPage(&page); + view.show(); + QVERIFY(QTest::qWaitForWindowExposed(&view)); + QSignalSpy spy(&page, &QWebEnginePage::loadFinished); + + // First check we can get the user-agent passed through normally + page.setHtml(QString("<html><body><a id='link' target='_blank' href='") + + server.url("/test1").toEncoded() + + QString("'>link</a></body></html>")); + QTRY_COMPARE(spy.count(), 1); + QVERIFY(spy.takeFirst().value(0).toBool()); + QCOMPARE(evaluateJavaScriptSync(&page, QStringLiteral("navigator.userAgent")).toString(), profile1.httpUserAgent()); + QTest::mouseClick(view.focusProxy(), Qt::LeftButton, 0, elementCenter(&page, "link")); + QTRY_VERIFY(page.newPage); + QTRY_VERIFY(!lastUserAgent.isEmpty()); + QCOMPARE(lastUserAgent, profile1.httpUserAgent().toUtf8()); + + // Now check we can get the new user-agent of the profile + page.newPage.reset(); + page.targetProfile = &profile2; + spy.clear(); + lastUserAgent = { }; + page.setHtml(QString("<html><body><a id='link' target='_blank' href='") + + server.url("/test2").toEncoded() + + QString("'>link</a></body></html>")); + QTRY_COMPARE(spy.count(), 1); + QVERIFY(spy.takeFirst().value(0).toBool()); + QTest::mouseClick(view.focusProxy(), Qt::LeftButton, 0, elementCenter(&page, "link")); + QTRY_VERIFY(page.newPage); + QTRY_VERIFY(!lastUserAgent.isEmpty()); + QCOMPARE(lastUserAgent, profile2.httpUserAgent().toUtf8()); +} + static QByteArrayList params = {QByteArrayLiteral("--use-fake-device-for-media-stream")}; W_QTEST_MAIN(tst_QWebEnginePage, params) diff --git a/tests/auto/widgets/qwebengineview/BLACKLIST b/tests/auto/widgets/qwebengineview/BLACKLIST index 615400417..9087067f5 100644 --- a/tests/auto/widgets/qwebengineview/BLACKLIST +++ b/tests/auto/widgets/qwebengineview/BLACKLIST @@ -3,7 +3,3 @@ osx [textSelectionOutOfInputField] * - -[inputContextQueryInput] -osx -windows diff --git a/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp b/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp index b75fc459d..fa179f2f8 100644 --- a/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp +++ b/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp @@ -1894,7 +1894,7 @@ void tst_QWebEngineView::inputContextQueryInput() QApplication::sendEvent(view.focusProxy(), &event); } QTRY_COMPARE(testContext.infos.count(), 2); - QCOMPARE(selectionChangedSpy.count(), 1); + QTRY_COMPARE(selectionChangedSpy.count(), 1); // As a first step, Chromium moves the cursor to the start of the selection. // We don't filter this in QtWebEngine because we don't know yet if this is part of a selection. @@ -1920,7 +1920,7 @@ void tst_QWebEngineView::inputContextQueryInput() QApplication::sendEvent(view.focusProxy(), &event); } QTRY_COMPARE(testContext.infos.count(), 1); - QCOMPARE(selectionChangedSpy.count(), 1); + QTRY_COMPARE(selectionChangedSpy.count(), 1); QCOMPARE(testContext.infos[0].cursorPosition, 0); QCOMPARE(testContext.infos[0].anchorPosition, 0); QCOMPARE(testContext.infos[0].surroundingText, QStringLiteral("QtWebEngine!")); diff --git a/tests/auto/widgets/spellchecking/tst_spellchecking.cpp b/tests/auto/widgets/spellchecking/tst_spellchecking.cpp index a9123ec15..64df05d89 100644 --- a/tests/auto/widgets/spellchecking/tst_spellchecking.cpp +++ b/tests/auto/widgets/spellchecking/tst_spellchecking.cpp @@ -187,14 +187,41 @@ void tst_Spellchecking::spellcheck() QString result = evaluateJavaScriptSync(m_view->page(), "text();").toString(); QVERIFY(result == text); - // open menu on misspelled word - m_view->activateMenu(m_view->focusWidget(), rect.center()); - QSignalSpy spyMenuReady(m_view, &WebView::menuReady); - QVERIFY(spyMenuReady.wait()); - - // check if menu is valid - QVERIFY(m_view->data().isValid()); - QVERIFY(m_view->data().isContentEditable()); + bool gotMisspelledWord = false; // clumsy QTRY_VERIFY still execs expr after first success + QString detail; + + // check that spellchecker has done text processing and filled misspelled word + QTRY_VERIFY2([&] () { + detail.clear(); + if (gotMisspelledWord) + return true; + + // open menu on misspelled word + m_view->activateMenu(m_view->focusWidget(), rect.center()); + QSignalSpy spyMenuReady(m_view, &WebView::menuReady); + if (!spyMenuReady.wait()) { + detail = "menu was not shown"; + return false; + } + + if (!m_view->data().isValid()) { + detail = "invalid data"; + return false; + } + + if (!m_view->data().isContentEditable()) { + detail = "content is not editable"; + return false; + } + + if (m_view->data().misspelledWord().isEmpty()) { + detail = "no misspelled word"; + return false; + }; + + gotMisspelledWord = true; + return true; + } (), qPrintable(QString("Context menu: %1").arg(detail))); // check misspelled word QCOMPARE(m_view->data().misspelledWord(), QStringLiteral("lowe")); |