summaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorPeter Varga <pvarga@inf.u-szeged.hu>2016-07-27 09:14:52 +0200
committerPeter Varga <pvarga@inf.u-szeged.hu>2016-08-24 21:24:30 +0000
commit822763ddda98f04339df44641f9b0d0f72ff6466 (patch)
treeb46d1bb211165acb3445ddc6bbb92d723726387f /tests/auto
parent7da3fa4e73a37b0d63a98a4d476447071075935f (diff)
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 <allan.jensen@qt.io>
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/quick/qmltests/data/tst_viewSource.qml34
-rw-r--r--tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp49
2 files changed, 83 insertions, 0 deletions
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<QUrl>("userInputUrl");
+ QTest::addColumn<bool>("loadSucceed");
+ QTest::addColumn<QUrl>("url");
+ QTest::addColumn<QString>("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<QVariant> 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"