diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2019-04-30 10:39:42 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2019-04-30 10:40:26 +0200 |
commit | 4181db05fc8f1c96d0bbf2e88a64e6d3bb11c6cf (patch) | |
tree | f4f9127216f92102f3420949f82e3186fee15e54 /tests | |
parent | b546cea1b5ba6721bf7fcb687c6c069d4442ba34 (diff) | |
parent | 26ac59af2306b4f6f83e791bb3e828b9f7b1a721 (diff) |
Merge remote-tracking branch 'origin/5.12' into 5.13
Change-Id: I051052a70a6e764202a90d77fc1a0f73688d3704
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/widgets/origins/tst_origins.cpp | 49 | ||||
-rw-r--r-- | tests/auto/widgets/qwebengineprofile/tst_qwebengineprofile.cpp | 6 | ||||
-rw-r--r-- | tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp | 46 |
3 files changed, 98 insertions, 3 deletions
diff --git a/tests/auto/widgets/origins/tst_origins.cpp b/tests/auto/widgets/origins/tst_origins.cpp index 61d16bc8a..c1307c5e6 100644 --- a/tests/auto/widgets/origins/tst_origins.cpp +++ b/tests/auto/widgets/origins/tst_origins.cpp @@ -172,6 +172,7 @@ private Q_SLOTS: void cleanupTestCase(); void jsUrlCanon(); + void jsUrlRelative(); void jsUrlOrigin(); void subdirWithAccess(); void subdirWithoutAccess(); @@ -281,6 +282,54 @@ void tst_Origins::jsUrlCanon() QVariant(QSL("hostportanduserinformationsyntax://a:b@foo/bar"))); } +// Test relative URL resolution. +void tst_Origins::jsUrlRelative() +{ + QVERIFY(load(QSL("about:blank"))); + + // Schemes with hosts, like http, work as expected. + QCOMPARE(eval(QSL("new URL('bar', 'http://foo').href")), QVariant(QSL("http://foo/bar"))); + QCOMPARE(eval(QSL("new URL('baz', 'http://foo/bar').href")), QVariant(QSL("http://foo/baz"))); + QCOMPARE(eval(QSL("new URL('baz', 'http://foo/bar/').href")), QVariant(QSL("http://foo/bar/baz"))); + QCOMPARE(eval(QSL("new URL('/baz', 'http://foo/bar/').href")), QVariant(QSL("http://foo/baz"))); + QCOMPARE(eval(QSL("new URL('./baz', 'http://foo/bar/').href")), QVariant(QSL("http://foo/bar/baz"))); + QCOMPARE(eval(QSL("new URL('../baz', 'http://foo/bar/').href")), QVariant(QSL("http://foo/baz"))); + QCOMPARE(eval(QSL("new URL('../../baz', 'http://foo/bar/').href")), QVariant(QSL("http://foo/baz"))); + QCOMPARE(eval(QSL("new URL('//baz', 'http://foo/bar/').href")), QVariant(QSL("http://baz/"))); + + // In the case of schemes without hosts, relative URLs only work if the URL + // starts with a single slash -- and canonicalization does not guarantee + // this. The following cases all fail with TypeErrors. + QCOMPARE(eval(QSL("new URL('bar', 'tst:foo').href")), QVariant()); + QCOMPARE(eval(QSL("new URL('baz', 'tst:foo/bar').href")), QVariant()); + QCOMPARE(eval(QSL("new URL('bar', 'tst://foo').href")), QVariant()); + QCOMPARE(eval(QSL("new URL('bar', 'tst:///foo').href")), QVariant()); + + // However, registered custom schemes have been patched to allow relative + // URLs even without an initial slash. + QCOMPARE(eval(QSL("new URL('bar', 'qrc:foo').href")), QVariant(QSL("qrc:bar"))); + QCOMPARE(eval(QSL("new URL('baz', 'qrc:foo/bar').href")), QVariant(QSL("qrc:foo/baz"))); + QCOMPARE(eval(QSL("new URL('bar', 'qrc://foo').href")), QVariant()); + QCOMPARE(eval(QSL("new URL('bar', 'qrc:///foo').href")), QVariant()); + + // With a slash it works the same as http except 'foo' is part of the path and not the host. + QCOMPARE(eval(QSL("new URL('bar', 'qrc:/foo').href")), QVariant(QSL("qrc:/bar"))); + QCOMPARE(eval(QSL("new URL('bar', 'qrc:/foo/').href")), QVariant(QSL("qrc:/foo/bar"))); + QCOMPARE(eval(QSL("new URL('baz', 'qrc:/foo/bar').href")), QVariant(QSL("qrc:/foo/baz"))); + QCOMPARE(eval(QSL("new URL('baz', 'qrc:/foo/bar/').href")), QVariant(QSL("qrc:/foo/bar/baz"))); + QCOMPARE(eval(QSL("new URL('/baz', 'qrc:/foo/bar/').href")), QVariant(QSL("qrc:/baz"))); + QCOMPARE(eval(QSL("new URL('./baz', 'qrc:/foo/bar/').href")), QVariant(QSL("qrc:/foo/bar/baz"))); + QCOMPARE(eval(QSL("new URL('../baz', 'qrc:/foo/bar/').href")), QVariant(QSL("qrc:/foo/baz"))); + QCOMPARE(eval(QSL("new URL('../../baz', 'qrc:/foo/bar/').href")), QVariant(QSL("qrc:/baz"))); + QCOMPARE(eval(QSL("new URL('../../../baz', 'qrc:/foo/bar/').href")), QVariant(QSL("qrc:/baz"))); + + // If the relative URL begins with >= 2 slashes, then the scheme is treated + // not as a Syntax::Path scheme but as a Syntax::HostPortAndUserInformation + // scheme. + QCOMPARE(eval(QSL("new URL('//baz', 'qrc:/foo/bar/').href")), QVariant(QSL("qrc://baz/"))); + QCOMPARE(eval(QSL("new URL('///baz', 'qrc:/foo/bar/').href")), QVariant(QSL("qrc://baz/"))); +} + // Test origin serialization in Blink, implemented by blink::KURL and // blink::SecurityOrigin as opposed to GURL and url::Origin. void tst_Origins::jsUrlOrigin() diff --git a/tests/auto/widgets/qwebengineprofile/tst_qwebengineprofile.cpp b/tests/auto/widgets/qwebengineprofile/tst_qwebengineprofile.cpp index ebd25e892..ff073799c 100644 --- a/tests/auto/widgets/qwebengineprofile/tst_qwebengineprofile.cpp +++ b/tests/auto/widgets/qwebengineprofile/tst_qwebengineprofile.cpp @@ -213,9 +213,8 @@ public: void requestStarted(QWebEngineUrlRequestJob *job) { - QBuffer *buffer = new QBuffer; + QBuffer *buffer = new QBuffer(job); buffer->setData(job->requestUrl().toString().toUtf8()); - connect(buffer, &QIODevice::aboutToClose, buffer, &QObject::deleteLater); m_buffers.append(buffer); job->reply("text/plain;charset=utf-8", buffer); } @@ -634,14 +633,15 @@ void tst_QWebEngineProfile::initiator() void tst_QWebEngineProfile::qtbug_71895() { QWebEngineView view; + QSignalSpy loadSpy(view.page(), SIGNAL(loadFinished(bool))); view.setUrl(QUrl("https://www.qt.io")); view.show(); - QSignalSpy loadSpy(view.page(), SIGNAL(loadFinished(bool))); view.page()->profile()->clearHttpCache(); view.page()->profile()->setHttpCacheType(QWebEngineProfile::NoCache); view.page()->profile()->cookieStore()->deleteAllCookies(); view.page()->profile()->setPersistentCookiesPolicy(QWebEngineProfile::NoPersistentCookies); QTRY_COMPARE_WITH_TIMEOUT(loadSpy.count(), 1, 20000); + QVERIFY(loadSpy.front().front().toBool()); } diff --git a/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp b/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp index 16a3d32b6..74adbaba9 100644 --- a/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp +++ b/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp @@ -196,6 +196,10 @@ private Q_SLOTS: void deletePage(); void closeOpenerTab(); void switchPage(); + void setPageDeletesImplicitPage(); + void setViewDeletesImplicitPage(); + void setPagePreservesExplicitPage(); + void setViewPreservesExplicitPage(); }; // This will be called before the first test function is executed. @@ -3197,5 +3201,47 @@ void tst_QWebEngineView::switchPage() QTRY_COMPARE(webView.grab().toImage().pixelColor(QPoint(150,150)), Qt::black); } +void tst_QWebEngineView::setPageDeletesImplicitPage() +{ + QWebEngineView view; + QPointer<QWebEnginePage> implicitPage = view.page(); + QWebEnginePage explicitPage; + view.setPage(&explicitPage); + QCOMPARE(view.page(), &explicitPage); + QVERIFY(!implicitPage); // should be deleted +} + +void tst_QWebEngineView::setViewDeletesImplicitPage() +{ + QWebEngineView view; + QPointer<QWebEnginePage> implicitPage = view.page(); + QWebEnginePage explicitPage; + explicitPage.setView(&view); + QCOMPARE(view.page(), &explicitPage); + QVERIFY(!implicitPage); // should be deleted +} + +void tst_QWebEngineView::setPagePreservesExplicitPage() +{ + QWebEngineView view; + QPointer<QWebEnginePage> explicitPage1 = new QWebEnginePage(&view); + QPointer<QWebEnginePage> explicitPage2 = new QWebEnginePage(&view); + view.setPage(explicitPage1.data()); + view.setPage(explicitPage2.data()); + QCOMPARE(view.page(), explicitPage2.data()); + QVERIFY(explicitPage1); // should not be deleted +} + +void tst_QWebEngineView::setViewPreservesExplicitPage() +{ + QWebEngineView view; + QPointer<QWebEnginePage> explicitPage1 = new QWebEnginePage(&view); + QPointer<QWebEnginePage> explicitPage2 = new QWebEnginePage(&view); + explicitPage1->setView(&view); + explicitPage2->setView(&view); + QCOMPARE(view.page(), explicitPage2.data()); + QVERIFY(explicitPage1); // should not be deleted +} + QTEST_MAIN(tst_QWebEngineView) #include "tst_qwebengineview.moc" |