diff options
author | Peter Varga <pvarga@inf.u-szeged.hu> | 2016-07-27 09:14:52 +0200 |
---|---|---|
committer | Peter Varga <pvarga@inf.u-szeged.hu> | 2016-08-24 21:24:30 +0000 |
commit | 822763ddda98f04339df44641f9b0d0f72ff6466 (patch) | |
tree | b46d1bb211165acb3445ddc6bbb92d723726387f /tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp | |
parent | 7da3fa4e73a37b0d63a98a4d476447071075935f (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/widgets/qwebenginepage/tst_qwebenginepage.cpp')
-rw-r--r-- | tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp | 49 |
1 files changed, 49 insertions, 0 deletions
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" |