From 822763ddda98f04339df44641f9b0d0f72ff6466 Mon Sep 17 00:00:00 2001 From: Peter Varga Date: Wed, 27 Jul 2016 09:14:52 +0200 Subject: Autocomplete view-source URL User may miss the URL scheme (eg. http://) when type a view-source url into the browser's location bar (eg. view-source:qt.io). This is not handled by the Chromium thus will produce an empty view-source page. The new autocompletion extends the incomplete view-source URL thus it will provide valid URL if it is possible (eg. view-source:http://qt.io/) Change-Id: I3edcd271cd0a971c9754e875db8f2a55a9a545de Reviewed-by: Allan Sandfeld Jensen --- tests/auto/quick/qmltests/data/tst_viewSource.qml | 34 +++++++++++++++ .../widgets/qwebenginepage/tst_qwebenginepage.cpp | 49 ++++++++++++++++++++++ 2 files changed, 83 insertions(+) (limited to 'tests') diff --git a/tests/auto/quick/qmltests/data/tst_viewSource.qml b/tests/auto/quick/qmltests/data/tst_viewSource.qml index 7c7dd34e0..746bfcfb3 100644 --- a/tests/auto/quick/qmltests/data/tst_viewSource.qml +++ b/tests/auto/quick/qmltests/data/tst_viewSource.qml @@ -63,6 +63,9 @@ TestWebEngineView { name: "WebEngineViewSource" function init() { + webEngineView.url = Qt.resolvedUrl("about:blank"); + verify(webEngineView.waitForLoadSucceeded()); + newViewRequestedSpy.clear(); titleChangedSpy.clear(); viewRequest = null; @@ -88,6 +91,37 @@ TestWebEngineView { compare(webEngineView.title, "test1.html"); compare(webEngineView.url, "view-source:" + Qt.resolvedUrl("test1.html")); } + + function test_viewSourceURL_data() { + var testLocalUrl = "view-source:" + Qt.resolvedUrl("test1.html"); + var testLocalUrlWithoutScheme = "view-source:" + Qt.resolvedUrl("test1.html").substring(7); + + return [ + { tag: "view-source:", userInputUrl: "view-source:", loadSucceed: true, url: "view-source:", title: "view-source:" }, + { tag: "view-source:about:blank", userInputUrl: "view-source:about:blank", loadSucceed: true, url: "view-source:about:blank", title: "view-source:about:blank" }, + { tag: testLocalUrl, userInputUrl: testLocalUrl, loadSucceed: true, url: testLocalUrl, title: "test1.html" }, + { tag: testLocalUrlWithoutScheme, userInputUrl: testLocalUrlWithoutScheme, loadSucceed: true, url: testLocalUrl, title: "test1.html" }, + { tag: "view-source:http://non.existent", userInputUrl: "view-source:http://non.existent", loadSucceed: false, url: "view-source:http://non.existent/", title: "http://non.existent/ is not available" }, + { tag: "view-source:non.existent", userInputUrl: "view-source:non.existent", loadSucceed: false, url: "view-source:http://non.existent/", title: "http://non.existent/ is not available" }, + ]; + } + + function test_viewSourceURL(row) { + WebEngine.settings.errorPageEnabled = true + webEngineView.url = row.userInputUrl; + + if (row.loadSucceed) { + verify(webEngineView.waitForLoadSucceeded()); + tryCompare(titleChangedSpy, "count", 1); + } else { + verify(webEngineView.waitForLoadFailed()); + tryCompare(titleChangedSpy, "count", 2); + } + + compare(webEngineView.url, row.url); + compare(webEngineView.title, row.title); + verify(!webEngineView.canViewSource); + } } } diff --git a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp index 4413ba615..3bc4d6662 100644 --- a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp +++ b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp @@ -243,6 +243,8 @@ private Q_SLOTS: void printToPdf(); void viewSource(); + void viewSourceURL_data(); + void viewSourceURL(); private: static QPoint elementCenter(QWebEnginePage *page, const QString &id); @@ -5051,5 +5053,52 @@ void tst_QWebEnginePage::viewSource() QVERIFY(!page.createdWindows[0]->canViewSource()); } +void tst_QWebEnginePage::viewSourceURL_data() +{ + QTest::addColumn("userInputUrl"); + QTest::addColumn("loadSucceed"); + QTest::addColumn("url"); + QTest::addColumn("title"); + + QTest::newRow("view-source:") << QUrl("view-source:") << true << QUrl("view-source:") << QString("view-source:"); + QTest::newRow("view-source:about:blank") << QUrl("view-source:about:blank") << true << QUrl("view-source:about:blank") << QString("view-source:about:blank"); + + QUrl testLocalUrl = QUrl(QString("view-source:%1").arg(QUrl::fromLocalFile(TESTS_SOURCE_DIR + QLatin1String("qwebenginepage/resources/test1.html")).toString())); + QUrl testLocalUrlWithoutScheme = QUrl(QString("view-source:%1").arg(TESTS_SOURCE_DIR + QLatin1String("qwebenginepage/resources/test1.html"))); + QTest::newRow(testLocalUrl.toString().toStdString().c_str()) << testLocalUrl << true << testLocalUrl << QString("test1.html"); + QTest::newRow(testLocalUrlWithoutScheme.toString().toStdString().c_str()) << testLocalUrlWithoutScheme << true << testLocalUrl << QString("test1.html"); + + QUrl testResourceUrl = QUrl("view-source:qrc:/resources/test1.html"); + QTest::newRow(testResourceUrl.toString().toStdString().c_str()) << testResourceUrl << true << testResourceUrl << testResourceUrl.toString(); + + QTest::newRow("view-source:http://non.existent") << QUrl("view-source:non.existent") << false << QUrl("view-source:http://non.existent/") << QString("http://non.existent/ is not available"); + QTest::newRow("view-source:non.existent") << QUrl("view-source:non.existent") << false << QUrl("view-source:http://non.existent/") << QString("http://non.existent/ is not available"); +} + +void tst_QWebEnginePage::viewSourceURL() +{ + if (!QDir(TESTS_SOURCE_DIR).exists()) + W_QSKIP(QString("This test requires access to resources found in '%1'").arg(TESTS_SOURCE_DIR).toLatin1().constData(), SkipAll); + + QFETCH(QUrl, userInputUrl); + QFETCH(bool, loadSucceed); + QFETCH(QUrl, url); + QFETCH(QString, title); + + QWebEnginePage *page = new QWebEnginePage; + QSignalSpy loadFinishedSpy(page, SIGNAL(loadFinished(bool))); + + page->load(userInputUrl); + QTRY_COMPARE(loadFinishedSpy.count(), 1); + QList arguments = loadFinishedSpy.takeFirst(); + + QCOMPARE(arguments.at(0).toBool(), loadSucceed); + QCOMPARE(page->url(), url); + QCOMPARE(page->title(), title); + QVERIFY(!page->canViewSource()); + + delete page; +} + QTEST_MAIN(tst_QWebEnginePage) #include "tst_qwebenginepage.moc" -- cgit v1.2.3