diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2019-05-09 15:22:24 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2019-05-09 15:22:24 +0200 |
commit | 0eac492b5c66b1774118c387dd527ad419e51be7 (patch) | |
tree | 37324fdefd615e433dd65073390d7b9996d660d3 /tests | |
parent | 5d6086d1b97461b35c143839a8a6ba1b990bb87c (diff) | |
parent | 99d46a8a918dee7323bc3d4f1624c47c097f9a3a (diff) |
Merge remote-tracking branch 'origin/5.13' into dev
Change-Id: I495adfcbb010ac29dc64e051c030a92d27859ca6
Diffstat (limited to 'tests')
19 files changed, 306 insertions, 44 deletions
diff --git a/tests/auto/quick/dialogs/WebView.qml b/tests/auto/quick/dialogs/WebView.qml index 6509071b8..4f8b7a0ce 100644 --- a/tests/auto/quick/dialogs/WebView.qml +++ b/tests/auto/quick/dialogs/WebView.qml @@ -59,6 +59,8 @@ Window { onLoadingChanged: function(reqeust) { if (reqeust.status === WebEngineView.LoadSucceededStatus) { handler.ready = true + } else { + console.log("Wooohooo loading page from qrc failed !") } } diff --git a/tests/auto/quick/dialogs/tst_dialogs.cpp b/tests/auto/quick/dialogs/tst_dialogs.cpp index 26a0fe034..eee6b2bb6 100644 --- a/tests/auto/quick/dialogs/tst_dialogs.cpp +++ b/tests/auto/quick/dialogs/tst_dialogs.cpp @@ -116,7 +116,7 @@ void tst_Dialogs::colorDialogRequested() void tst_Dialogs::contextMenuRequested() { m_listner->load(QUrl("qrc:/index.html")); - QTRY_VERIFY(m_listner->ready()); + QTRY_COMPARE_WITH_TIMEOUT(m_listner->ready(), true, 20000); QSignalSpy dialogSpy(m_listner, &TestHandler::requestChanged); QTest::mouseClick(m_widnow, Qt::RightButton); QTRY_COMPARE(dialogSpy.count(), 1); @@ -226,6 +226,7 @@ void tst_Dialogs::javaScriptDialogRequested() QCOMPARE(dialog->type(), type); QCOMPARE(dialog->message(), message); QCOMPARE(dialog->defaultText(), defaultText); + QTRY_VERIFY(m_listner->ready()); // make sure javascript executes no longer } #include "tst_dialogs.moc" diff --git a/tests/auto/quick/qmltests/BLACKLIST b/tests/auto/quick/qmltests/BLACKLIST index dfafbaea4..957911c3b 100644 --- a/tests/auto/quick/qmltests/BLACKLIST +++ b/tests/auto/quick/qmltests/BLACKLIST @@ -4,15 +4,6 @@ osx [WebViewGeopermission::test_geoPermissionRequest] osx -[WebEngineViewSingleFileUpload::test_acceptDirectory] -* - -[WebEngineViewSingleFileUpload::test_acceptMultipleFilesSelection] -* - -[WebEngineViewSingleFileUpload::test_acceptSingleFileSelection] -* - [WebViewFindText::test_findTextInterruptedByLoad] * diff --git a/tests/auto/quick/qmltests/data/multifileupload.html b/tests/auto/quick/qmltests/data/multifileupload.html index 1f788a377..d41ea15c0 100644 --- a/tests/auto/quick/qmltests/data/multifileupload.html +++ b/tests/auto/quick/qmltests/data/multifileupload.html @@ -1,7 +1,7 @@ <html> <head> <meta name="viewport" content="width=device-width, initial-scale=1.0"> -<title> Mutli-file Upload </title> +<title> Failed to Upload </title> <script src = "./titleupdate.js"> </script> </head> diff --git a/tests/auto/quick/qmltests/data/singlefileupload.html b/tests/auto/quick/qmltests/data/singlefileupload.html index 6cfef7ade..ac91c2c0d 100644 --- a/tests/auto/quick/qmltests/data/singlefileupload.html +++ b/tests/auto/quick/qmltests/data/singlefileupload.html @@ -1,7 +1,7 @@ <html> <head> <meta name="viewport" content="width=device-width, initial-scale=1.0"> -<title> Single File Upload </title> +<title> Failed to Upload </title> <script src = "./titleupdate.js"> </script> </head> diff --git a/tests/auto/quick/qmltests/data/tst_filePicker.qml b/tests/auto/quick/qmltests/data/tst_filePicker.qml index 655789bb3..2f813b966 100644 --- a/tests/auto/quick/qmltests/data/tst_filePicker.qml +++ b/tests/auto/quick/qmltests/data/tst_filePicker.qml @@ -70,16 +70,61 @@ TestWebEngineView { webEngineView.waitForLoadSucceeded() } - function test_acceptSingleFileSelection() { - webEngineView.url = Qt.resolvedUrl("singlefileupload.html") - verify(webEngineView.waitForLoadSucceeded()) + function test_acceptSingleFileSelection_data() { + return [ + { tag: "/test.txt)", input: "/test.txt", passDefaultDialog: false, passCustomDialog: true }, + { tag: "/tést.txt", input: "/tést.txt", passDefaultDialog: false, passCustomDialog: true }, + { tag: "file:///test.txt", input: "file:///test.txt", passDefaultDialog: true, passCustomDialog: false }, + { tag: "file:///tést.txt", input: "file:///tést.txt", passDefaultDialog: true, passCustomDialog: false }, + { tag: "file:///t%C3%A9st.txt", input: "file:///t%C3%A9st.txt", passDefaultDialog: true, passCustomDialog: false }, + { tag: "file://test.txt", input: "file://test.txt", passDefaultDialog: false, passCustomDialog: false }, + { tag: "file:/test.txt", input: "file:/test.txt", passDefaultDialog: true, passCustomDialog: false }, + { tag: "file:test//test.txt", input: "file:test//test.txt", passDefaultDialog: false, passCustomDialog: false }, + { tag: "http://test.txt", input: "http://test.txt", passDefaultDialog: false, passCustomDialog: false }, + { tag: "qrc:/test.txt", input: "qrc:/test.txt", passDefaultDialog: false, passCustomDialog: false }, + ]; + } - FilePickerParams.selectFiles = true - FilePickerParams.selectedFilesUrl.push(Qt.resolvedUrl("test1.html")) + function test_acceptSingleFileSelection(row) { + var expectedFileName; - keyPress(Qt.Key_Enter) // Focus is on the button. Open FileDialog. - tryCompare(FilePickerParams, "filePickerOpened", true) - tryCompare(webEngineView, "title", "test1.html") + // Default dialog (expects URL). + expectedFileName = "Failed to Upload"; + if (row.passDefaultDialog) + expectedFileName = row.input.slice(row.input.lastIndexOf('/') + 1); + + webEngineView.url = Qt.resolvedUrl("singlefileupload.html"); + verify(webEngineView.waitForLoadSucceeded()); + + FilePickerParams.selectFiles = true; + FilePickerParams.selectedFilesUrl.push(row.input); + + keyClick(Qt.Key_Enter); // Focus is on the button. Open FileDialog. + tryCompare(FilePickerParams, "filePickerOpened", true); + tryCompare(webEngineView, "title", decodeURIComponent(expectedFileName)); + + + // Custom dialog (expects absolute path). + var finished = false; + + expectedFileName = "Failed to Upload"; + if (row.passCustomDialog) + expectedFileName = row.input.slice(row.input.lastIndexOf('/') + 1); + + function acceptedFileHandler(request) { + request.accepted = true; + request.dialogAccept(row.input); + finished = true; + } + + webEngineView.fileDialogRequested.connect(acceptedFileHandler); + webEngineView.url = Qt.resolvedUrl("singlefileupload.html"); + verify(webEngineView.waitForLoadSucceeded()); + + keyClick(Qt.Key_Enter); // Focus is on the button. Open FileDialog. + tryVerify(function() { return finished; }); + tryCompare(webEngineView, "title", expectedFileName); + webEngineView.fileDialogRequested.disconnect(acceptedFileHandler); } function test_acceptMultipleFilesSelection() { @@ -102,9 +147,10 @@ TestWebEngineView { FilePickerParams.selectFiles = true FilePickerParams.selectedFilesUrl.push(Qt.resolvedUrl("../data")) - keyPress(Qt.Key_Enter) // Focus is on the button. Open FileDialog. + keyClick(Qt.Key_Enter) // Focus is on the button. Open FileDialog. tryCompare(FilePickerParams, "filePickerOpened", true) - tryCompare(webEngineView, "title", "data") + // Check that the title is a file list (eg. "test1.html,test2.html") + tryVerify(function() { return webEngineView.title.match("^([^,]+,)+[^,]+$"); }) } function test_reject() { @@ -116,5 +162,45 @@ TestWebEngineView { wait(100) compare(titleSpy.count, 0) } + + function test_acceptMultipleFilesWithCustomDialog_data() { + return [ + { tag: "path", input: ["/test1.txt", "/test2.txt"], expectedValueForDefaultDialog: "Failed to Upload", expectedValueForCustomDialog: "test1.txt,test2.txt" }, + { tag: "file", input: ["file:///test1.txt", "file:///test2.txt"], expectedValueForDefaultDialog: "test1.txt,test2.txt", expectedValueForCustomDialog: "Failed to Upload" }, + { tag: "mixed", input: ["file:///test1.txt", "/test2.txt"], expectedValueForDefaultDialog: "test1.txt", expectedValueForCustomDialog: "test2.txt" }, + ]; + } + + function test_acceptMultipleFilesWithCustomDialog(row) { + // Default dialog (expects URL). + webEngineView.url = Qt.resolvedUrl("multifileupload.html"); + verify(webEngineView.waitForLoadSucceeded()); + + FilePickerParams.selectFiles = true; + FilePickerParams.selectedFilesUrl = row.input; + + keyClick(Qt.Key_Enter); // Focus is on the button. Open FileDialog. + tryCompare(FilePickerParams, "filePickerOpened", true); + tryCompare(webEngineView, "title", row.expectedValueForDefaultDialog); + + + // Custom dialog (expects absolute path). + var finished = false; + + function acceptedFileHandler(request) { + request.accepted = true; + request.dialogAccept(row.input); + finished = true; + } + + webEngineView.fileDialogRequested.connect(acceptedFileHandler); + webEngineView.url = Qt.resolvedUrl("multifileupload.html"); + verify(webEngineView.waitForLoadSucceeded()); + + keyClick(Qt.Key_Enter); // Focus is on the button. Open FileDialog. + tryVerify(function() { return finished; }); + tryCompare(webEngineView, "title", row.expectedValueForCustomDialog); + webEngineView.fileDialogRequested.disconnect(acceptedFileHandler); + } } } diff --git a/tests/auto/widgets/offscreen/test.html b/tests/auto/widgets/offscreen/test.html new file mode 100644 index 000000000..55063539f --- /dev/null +++ b/tests/auto/widgets/offscreen/test.html @@ -0,0 +1,7 @@ +<html> +<head><title>TEST</title></head> +<body> +Eat me ! +</body> +</html> + diff --git a/tests/auto/widgets/offscreen/tst_offscreen.cpp b/tests/auto/widgets/offscreen/tst_offscreen.cpp index 98cbe55fe..7573b0537 100644 --- a/tests/auto/widgets/offscreen/tst_offscreen.cpp +++ b/tests/auto/widgets/offscreen/tst_offscreen.cpp @@ -49,10 +49,11 @@ void tst_OffScreen::offscreen() QWebEngineView view; QSignalSpy loadFinishedSpy(&page, SIGNAL(loadFinished(bool))); view.setPage(&page); - page.load(QUrl("http://qt.io")); + page.load(QUrl("qrc:/test.html")); view.show(); QTRY_COMPARE(view.isVisible(), true); QTRY_COMPARE_WITH_TIMEOUT(loadFinishedSpy.count() > 0, true, 20000); + QCOMPARE(loadFinishedSpy.takeFirst().at(0).toBool(), true); } #include "tst_offscreen.moc" diff --git a/tests/auto/widgets/offscreen/tst_offscreen.qrc b/tests/auto/widgets/offscreen/tst_offscreen.qrc new file mode 100644 index 000000000..8a998fe85 --- /dev/null +++ b/tests/auto/widgets/offscreen/tst_offscreen.qrc @@ -0,0 +1,6 @@ +<!DOCTYPE RCC><RCC version="1.0"> +<qresource> + <file>test.html</file> +</qresource> +</RCC> + 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/proxypac/proxypac.pro b/tests/auto/widgets/proxypac/proxypac.pro index 1c2958d3a..4dbcd9365 100644 --- a/tests/auto/widgets/proxypac/proxypac.pro +++ b/tests/auto/widgets/proxypac/proxypac.pro @@ -4,7 +4,8 @@ HEADERS += proxyserver.h SOURCES += proxyserver.cpp proxy_pac.name = QTWEBENGINE_CHROMIUM_FLAGS -proxy_pac.value = --proxy-pac-url="file://$$PWD/proxy.pac" +boot2qt:proxy_pac.value = "--single-process --no-sandbox --proxy-pac-url=file://$$PWD/proxy.pac" +else: proxy_pac.value = --proxy-pac-url="file://$$PWD/proxy.pac" QT_TOOL_ENV += proxy_pac diff --git a/tests/auto/widgets/qwebenginedownloaditem/BLACKLIST b/tests/auto/widgets/qwebenginedownloaditem/BLACKLIST deleted file mode 100644 index a51117ae0..000000000 --- a/tests/auto/widgets/qwebenginedownloaditem/BLACKLIST +++ /dev/null @@ -1,2 +0,0 @@ -[downloadToReadOnlyDir] -windows diff --git a/tests/auto/widgets/qwebenginedownloaditem/tst_qwebenginedownloaditem.cpp b/tests/auto/widgets/qwebenginedownloaditem/tst_qwebenginedownloaditem.cpp index 8669c8f94..3a38c115d 100644 --- a/tests/auto/widgets/qwebenginedownloaditem/tst_qwebenginedownloaditem.cpp +++ b/tests/auto/widgets/qwebenginedownloaditem/tst_qwebenginedownloaditem.cpp @@ -73,7 +73,7 @@ private Q_SLOTS: void downloadDeletedByProfile(); void downloadUniqueFilename_data(); void downloadUniqueFilename(); - void downloadUniqueFileNameWithTimeStamp(); + void downloadUniqueFilenameWithTimestamp(); void downloadToDefaultLocation(); void downloadToNonExistentDir(); void downloadToReadOnlyDir(); @@ -917,11 +917,8 @@ void tst_QWebEngineDownloadItem::downloadUniqueFilename() } } -void tst_QWebEngineDownloadItem::downloadUniqueFileNameWithTimeStamp() +void tst_QWebEngineDownloadItem::downloadUniqueFilenameWithTimestamp() { -#ifdef Q_OS_WIN - QSKIP("QTBUG-74764: The download completes after the test fails thus would ruin subsequent tests on Windows."); -#endif // Set up HTTP server QString baseName("test(1.test)"); QString extension("txt"); @@ -988,8 +985,8 @@ void tst_QWebEngineDownloadItem::downloadUniqueFileNameWithTimeStamp() QRegularExpressionMatch match = fileNameCheck.match(downloadedFilePath); QVERIFY(match.hasMatch()); // ISO 8601 Date and time in UTC - QRegExp timeStamp("^(-?(?:[1-9][0-9]*)?[0-9]{4})-(1[0-2]|0[1-9])-(3[01]|0[1-9]|[12][0-9])T(2[0-3]|[01][0-9]):([0-5][0-9]):([0-5][0-9])([.][0-9]+)?(Z|[+-](?:2[0-3]|[01][0-9]):[0-5][0-9])?$"); - QVERIFY(timeStamp.exactMatch(match.captured(1))); + QRegExp timestamp("^(-?(?:[1-9][0-9]*)?[0-9]{4})-(1[0-2]|0[1-9])-(3[01]|0[1-9]|[12][0-9])T(2[0-3]|[01][0-9])([0-5][0-9])([0-5][0-9])([.][0-9]+)?(Z|[+-](?:2[0-3]|[01][0-9])[0-5][0-9])?$"); + QVERIFY(timestamp.exactMatch(match.captured(1))); } } @@ -1062,6 +1059,9 @@ void tst_QWebEngineDownloadItem::downloadToNonExistentDir() void tst_QWebEngineDownloadItem::downloadToReadOnlyDir() { +#ifdef Q_OS_WIN + QSKIP("Cannot change file permissions on Windows."); +#endif QString baseName("test(1.test)"); QString extension("txt"); QString fileName = QString("%1.%2").arg(baseName).arg(extension); diff --git a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp index 9ba242e68..19f9b6df1 100644 --- a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp +++ b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp @@ -200,6 +200,7 @@ private Q_SLOTS: void notificationRequest_data(); void notificationRequest(); void sendNotification(); + void contentsSize(); private: static QPoint elementCenter(QWebEnginePage *page, const QString &id); @@ -3357,6 +3358,34 @@ void tst_QWebEnginePage::sendNotification() QTRY_VERIFY2(page.messages.contains("onclose"), page.messages.join("\n").toLatin1().constData()); } +void tst_QWebEnginePage::contentsSize() +{ + m_view->resize(800, 600); + m_view->show(); + + QSignalSpy loadSpy(m_page, &QWebEnginePage::loadFinished); + QSignalSpy contentsSizeChangedSpy(m_page, &QWebEnginePage::contentsSizeChanged); + + m_view->setHtml(QString("<html><body style=\"width: 1600px; height: 1200px;\"><p>hi</p></body></html>")); + + QTRY_COMPARE(loadSpy.count(), 1); + QTRY_COMPARE(contentsSizeChangedSpy.count(), 1); + + // Verify the page's contents size is not limited by the view's size. + QCOMPARE(m_page->contentsSize().width(), 1608); + QCOMPARE(m_page->contentsSize().height(), 1216); + + // Verify resizing the view does not affect the contents size. + m_view->resize(2400, 1800); + QCOMPARE(m_page->contentsSize().width(), 1608); + QCOMPARE(m_page->contentsSize().height(), 1216); + + // Verify resizing the view does not affect the contents size. + m_view->resize(1600, 1200); + QCOMPARE(m_page->contentsSize().width(), 1608); + QCOMPARE(m_page->contentsSize().height(), 1216); +} + static QByteArrayList params = {QByteArrayLiteral("--use-fake-device-for-media-stream")}; W_QTEST_MAIN(tst_QWebEnginePage, params) diff --git a/tests/auto/widgets/qwebengineprofile/tst_qwebengineprofile.cpp b/tests/auto/widgets/qwebengineprofile/tst_qwebengineprofile.cpp index ebd25e892..1822069be 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,16 @@ 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); + bool gotSignal = loadSpy.count() || loadSpy.wait(20000); + if (!gotSignal) + QSKIP("Couldn't load page from network, skipping test."); } diff --git a/tests/auto/widgets/qwebenginescript/BLACKLIST b/tests/auto/widgets/qwebenginescript/BLACKLIST deleted file mode 100644 index b641aaf04..000000000 --- a/tests/auto/widgets/qwebenginescript/BLACKLIST +++ /dev/null @@ -1,3 +0,0 @@ -# FIXME post 72-merge -[webChannelWithBadString] -* diff --git a/tests/auto/widgets/qwebenginescript/tst_qwebenginescript.cpp b/tests/auto/widgets/qwebenginescript/tst_qwebenginescript.cpp index 0fe0ec6cf..9a2ee9311 100644 --- a/tests/auto/widgets/qwebenginescript/tst_qwebenginescript.cpp +++ b/tests/auto/widgets/qwebenginescript/tst_qwebenginescript.cpp @@ -23,6 +23,7 @@ #include <qwebengineprofile.h> #include <qwebenginescript.h> #include <qwebenginescriptcollection.h> +#include <qwebenginesettings.h> #include <qwebengineview.h> #include "../util.h" #if QT_CONFIG(webengine_webchannel) @@ -37,6 +38,8 @@ private Q_SLOTS: void loadEvents(); void scriptWorld_data(); void scriptWorld(); + void scriptDisabled(); + void viewSource(); void scriptModifications(); #if QT_CONFIG(webengine_webchannel) void webChannel_data(); @@ -218,6 +221,50 @@ void tst_QWebEngineScript::scriptWorld() QCOMPARE(evaluateJavaScriptSyncInWorld(&page, "typeof(userScriptTest) != \"undefined\" && userScriptTest == 1;", worldId), QVariant::fromValue(true)); } +// Based on QTBUG-74304 +void tst_QWebEngineScript::scriptDisabled() +{ + QWebEnginePage page; + page.settings()->setAttribute(QWebEngineSettings::JavascriptEnabled, false); + QWebEngineScript script; + script.setInjectionPoint(QWebEngineScript::DocumentCreation); + script.setWorldId(QWebEngineScript::MainWorld); + script.setSourceCode("var foo = 42"); + page.scripts().insert(script); + page.load(QUrl("about:blank")); + QSignalSpy spy(&page, &QWebEnginePage::loadFinished); + QTRY_COMPARE(spy.count(), 1); + QCOMPARE(spy.takeFirst().value(0).toBool(), true); + // MainWorld scripts are disabled by the setting... + QCOMPARE(evaluateJavaScriptSyncInWorld(&page, "foo", QWebEngineScript::MainWorld), QVariant()); + QCOMPARE(evaluateJavaScriptSyncInWorld(&page, "foo", QWebEngineScript::ApplicationWorld), QVariant()); + script.setWorldId(QWebEngineScript::ApplicationWorld); + page.scripts().clear(); + page.scripts().insert(script); + page.load(QUrl("about:blank")); + QTRY_COMPARE(spy.count(), 1); + QCOMPARE(spy.takeFirst().value(0).toBool(), true); + // ...but ApplicationWorld scripts should still work + QCOMPARE(evaluateJavaScriptSyncInWorld(&page, "foo", QWebEngineScript::MainWorld), QVariant()); + QCOMPARE(evaluateJavaScriptSyncInWorld(&page, "foo", QWebEngineScript::ApplicationWorld), QVariant(42)); +} + +// Based on QTBUG-66011 +void tst_QWebEngineScript::viewSource() +{ + QWebEnginePage page; + QWebEngineScript script; + script.setInjectionPoint(QWebEngineScript::DocumentCreation); + script.setWorldId(QWebEngineScript::MainWorld); + script.setSourceCode("var foo = 42"); + page.scripts().insert(script); + page.load(QUrl("view-source:about:blank")); + QSignalSpy spy(&page, &QWebEnginePage::loadFinished); + QTRY_COMPARE(spy.count(), 1); + QCOMPARE(spy.takeFirst().value(0).toBool(), true); + QCOMPARE(evaluateJavaScriptSync(&page, "foo"), QVariant(42)); +} + void tst_QWebEngineScript::scriptModifications() { QWebEnginePage page; @@ -499,7 +546,9 @@ void tst_QWebEngineScript::webChannelWithBadString() page.setWebChannel(&channel); page.setUrl(QStringLiteral("qrc:/resources/webChannelWithBadString.html")); QVERIFY(hostSpy.wait(20000)); - QCOMPARE(host.text(), QString(QChar(QChar::ReplacementCharacter))); + // expect 0xD800 see https://chromium-review.googlesource.com/c/1282993 + QChar data(0xd800); + QCOMPARE(host.text(), data); } #endif QTEST_MAIN(tst_QWebEngineScript) 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" diff --git a/tests/auto/widgets/widgets.pro b/tests/auto/widgets/widgets.pro index c99640b4b..92159bf83 100644 --- a/tests/auto/widgets/widgets.pro +++ b/tests/auto/widgets/widgets.pro @@ -42,8 +42,6 @@ qtConfig(webengine-spellchecker):!cross_compile { boot2qt: SUBDIRS -= accessibility defaultsurfaceformat devtools \ qwebenginepage \ qwebengineprofile \ - qwebengineview \ - qwebenginescript \ - proxypac offscreen + qwebengineview win32: SUBDIRS -= offscreen |