diff options
Diffstat (limited to 'tests/auto')
-rw-r--r-- | tests/auto/core/qwebenginecookiestore/tst_qwebenginecookiestore.cpp | 10 | ||||
-rw-r--r-- | tests/auto/quick/qmltests/CMakeLists.txt | 3 | ||||
-rw-r--r-- | tests/auto/quick/qmltests/data/favicon-misc.html | 4 | ||||
-rw-r--r-- | tests/auto/quick/qmltests/data/tst_favicon.qml | 337 | ||||
-rw-r--r-- | tests/auto/quick/qmltests/data/tst_faviconDownload.qml | 121 | ||||
-rw-r--r-- | tests/auto/widgets/CMakeLists.txt | 2 | ||||
-rw-r--r-- | tests/auto/widgets/favicon/CMakeLists.txt (renamed from tests/auto/widgets/faviconmanager/CMakeLists.txt) | 10 | ||||
-rw-r--r-- | tests/auto/widgets/favicon/favicon.pro (renamed from tests/auto/widgets/faviconmanager/faviconmanager.pro) | 0 | ||||
-rw-r--r-- | tests/auto/widgets/favicon/resources/favicon-misc.html (renamed from tests/auto/widgets/faviconmanager/resources/favicon-misc.html) | 4 | ||||
-rw-r--r-- | tests/auto/widgets/favicon/resources/favicon-multi.html (renamed from tests/auto/widgets/faviconmanager/resources/favicon-multi.html) | 2 | ||||
-rw-r--r-- | tests/auto/widgets/favicon/resources/favicon-shortcut.html (renamed from tests/auto/widgets/faviconmanager/resources/favicon-shortcut.html) | 0 | ||||
-rw-r--r-- | tests/auto/widgets/favicon/resources/favicon-single.html (renamed from tests/auto/widgets/faviconmanager/resources/favicon-single.html) | 0 | ||||
-rw-r--r-- | tests/auto/widgets/favicon/resources/favicon-touch.html (renamed from tests/auto/widgets/faviconmanager/resources/favicon-touch.html) | 0 | ||||
-rw-r--r-- | tests/auto/widgets/favicon/resources/favicon-unavailable.html (renamed from tests/auto/widgets/faviconmanager/resources/favicon-unavailable.html) | 0 | ||||
-rw-r--r-- | tests/auto/widgets/favicon/resources/icons/qt144.png (renamed from tests/auto/widgets/faviconmanager/resources/icons/qt144.png) | bin | 8315 -> 8315 bytes | |||
-rw-r--r-- | tests/auto/widgets/favicon/resources/icons/qt32.ico (renamed from tests/auto/widgets/faviconmanager/resources/icons/qt32.ico) | bin | 4286 -> 4286 bytes | |||
-rw-r--r-- | tests/auto/widgets/favicon/resources/icons/qtmulti.ico (renamed from tests/auto/widgets/faviconmanager/resources/icons/qtmulti.ico) | bin | 22382 -> 22382 bytes | |||
-rw-r--r-- | tests/auto/widgets/favicon/resources/test1.html (renamed from tests/auto/widgets/faviconmanager/resources/test1.html) | 0 | ||||
-rw-r--r-- | tests/auto/widgets/favicon/tst_favicon.cpp (renamed from tests/auto/widgets/faviconmanager/tst_faviconmanager.cpp) | 282 | ||||
-rw-r--r-- | tests/auto/widgets/favicon/tst_favicon.qrc (renamed from tests/auto/widgets/faviconmanager/tst_faviconmanager.qrc) | 0 | ||||
-rw-r--r-- | tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp | 6 |
21 files changed, 380 insertions, 401 deletions
diff --git a/tests/auto/core/qwebenginecookiestore/tst_qwebenginecookiestore.cpp b/tests/auto/core/qwebenginecookiestore/tst_qwebenginecookiestore.cpp index 0e8248508..ef3b84691 100644 --- a/tests/auto/core/qwebenginecookiestore/tst_qwebenginecookiestore.cpp +++ b/tests/auto/core/qwebenginecookiestore/tst_qwebenginecookiestore.cpp @@ -294,9 +294,9 @@ void tst_QWebEngineCookieStore::basicFilterOverHTTP() QVERIFY(loadSpy.takeFirst().takeFirst().toBool()); QVERIFY(!cookieRequestHeader.isEmpty()); QTRY_COMPARE(cookieAddedSpy.count(), 1); - QTRY_COMPARE(accessTested.loadAcquire(), 7); + QTRY_COMPARE(accessTested.loadAcquire(), 6); - QTRY_COMPARE(serverSpy.count(), 6); + QTRY_COMPARE(serverSpy.count(), 5); client->deleteAllCookies(); QTRY_COMPARE(cookieRemovedSpy.count(), 1); @@ -313,9 +313,9 @@ void tst_QWebEngineCookieStore::basicFilterOverHTTP() // Test cookies are NOT added: QTest::qWait(100); QCOMPARE(cookieAddedSpy.count(), 1); - QTRY_COMPARE(accessTested.loadAcquire(), 11); + QTRY_COMPARE(accessTested.loadAcquire(), 9); - QTRY_COMPARE(serverSpy.count(), 9); + QTRY_COMPARE(serverSpy.count(), 7); page.triggerAction(QWebEnginePage::Reload); QTRY_COMPARE(loadSpy.count(), 1); @@ -324,7 +324,7 @@ void tst_QWebEngineCookieStore::basicFilterOverHTTP() QCOMPARE(cookieAddedSpy.count(), 1); // Wait for last GET /favicon.ico - QTRY_COMPARE(serverSpy.count(), 12); + QTRY_COMPARE(serverSpy.count(), 9); (void) httpServer.stop(); QCOMPARE(resourceFirstParty.size(), accessTested.loadAcquire()); diff --git a/tests/auto/quick/qmltests/CMakeLists.txt b/tests/auto/quick/qmltests/CMakeLists.txt index b5898cc2a..1c77e1a05 100644 --- a/tests/auto/quick/qmltests/CMakeLists.txt +++ b/tests/auto/quick/qmltests/CMakeLists.txt @@ -16,6 +16,7 @@ set(testList tst_activeFocusOnPress.qml tst_audioMuted.qml tst_desktopBehaviorLoadHtml.qml + tst_favicon.qml tst_findText.qml tst_focusOnNavigation.qml tst_fullScreenRequest.qml @@ -53,8 +54,6 @@ endif() if(QT_FEATURE_webengine_testsupport) list(APPEND testList - tst_favicon.qml - tst_faviconDownload.qml tst_inputMethod.qml tst_javaScriptDialogs.qml tst_linkHovered.qml diff --git a/tests/auto/quick/qmltests/data/favicon-misc.html b/tests/auto/quick/qmltests/data/favicon-misc.html index 9e788bdf4..03d1086ff 100644 --- a/tests/auto/quick/qmltests/data/favicon-misc.html +++ b/tests/auto/quick/qmltests/data/favicon-misc.html @@ -1,8 +1,8 @@ <html> <head> <title>Favicon Test</title> - <link rel="shortcut icon" href="icons/qt32.ico" /> - <link rel="apple-touch-icon" href="icons/qt144.png" /> + <link rel="shortcut icon" href="icons/qt32.ico" sizes="32x32" /> + <link rel="apple-touch-icon" href="icons/qt144.png" sizes="144x144"/> <link rel="shortcut icon" href="icons/unavailable.ico" /> </head> <body> diff --git a/tests/auto/quick/qmltests/data/tst_favicon.qml b/tests/auto/quick/qmltests/data/tst_favicon.qml index fc8b90542..4d13d1e76 100644 --- a/tests/auto/quick/qmltests/data/tst_favicon.qml +++ b/tests/auto/quick/qmltests/data/tst_favicon.qml @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2021 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the QtWebEngine module of the Qt Toolkit. @@ -26,30 +26,26 @@ ** ****************************************************************************/ -import QtQuick 2.0 -import QtTest 1.0 -import QtWebEngine 1.3 -import QtWebEngine.testsupport 1.0 -import QtQuick.Window 2.0 -import "../../qmltests/data" 1.0 +import QtQuick +import QtTest +import QtWebEngine +import Test.util +import "../../qmltests/data" TestWebEngineView { id: webEngineView width: 200 height: 400 - testSupport: WebEngineTestSupport { - property var errorPageLoadStatus: null + TempDir { id: tempDir } - function waitForErrorPageLoadSucceeded() { - var success = _waitFor(function() { return testSupport.errorPageLoadStatus == WebEngineView.LoadSucceededStatus }) - testSupport.errorPageLoadStatus = null - return success - } + property QtObject defaultProfile: WebEngineProfile { + offTheRecord: true + } - errorPage.onLoadingChanged: function(load) { - errorPageLoadStatus = load.status - } + property QtObject nonOTRProfile: WebEngineProfile { + persistentStoragePath: tempDir.path() + '/WebEngineFavicon' + offTheRecord: false } function removeFaviconProviderPrefix(url) { @@ -58,10 +54,10 @@ TestWebEngineView { function getFaviconPixel(faviconImage) { var grabImage = Qt.createQmlObject(" - import QtQuick 2.5\n + import QtQuick\n Image { }", testCase) var faviconCanvas = Qt.createQmlObject(" - import QtQuick 2.5\n + import QtQuick\n Canvas { }", testCase) testCase.tryVerify(function() { return faviconImage.status == Image.Ready }); @@ -104,12 +100,22 @@ TestWebEngineView { function init() { // It is worth to restore the initial state with loading a blank page before all test functions. - webEngineView.url = 'about:blank' - verify(webEngineView.waitForLoadSucceeded()) - iconChangedSpy.clear() + webEngineView.url = 'about:blank'; + verify(webEngineView.waitForLoadSucceeded()); + iconChangedSpy.clear(); + webEngineView.settings.touchIconsEnabled = false; + webEngineView.settings.autoLoadIconsForPage = true; } - function test_faviconLoad() { + function test_faviconLoad_data() { + return [ + { tag: "OTR", profile: defaultProfile }, + { tag: "non-OTR", profile: nonOTRProfile }, + ]; + } + + function test_faviconLoad(row) { + webEngineView.profile = row.profile compare(iconChangedSpy.count, 0) var url = Qt.resolvedUrl("favicon.html") @@ -119,11 +125,20 @@ TestWebEngineView { iconChangedSpy.wait() compare(iconChangedSpy.count, 1) - compare(favicon.width, 48) - compare(favicon.height, 48) + tryCompare(favicon, "status", Image.Ready) + compare(favicon.width, 32) + compare(favicon.height, 32) + } + + function test_faviconLoadEncodedUrl_data() { + return [ + { tag: "OTR", profile: defaultProfile }, + { tag: "non-OTR", profile: nonOTRProfile }, + ]; } - function test_faviconLoadEncodedUrl() { + function test_faviconLoadEncodedUrl(row) { + webEngineView.profile = row.profile compare(iconChangedSpy.count, 0) var url = Qt.resolvedUrl("favicon2.html?favicon=load should work with#whitespace!") @@ -133,11 +148,62 @@ TestWebEngineView { iconChangedSpy.wait() compare(iconChangedSpy.count, 1) - compare(favicon.width, 16) - compare(favicon.height, 16) + tryCompare(favicon, "status", Image.Ready) + compare(favicon.width, 32) + compare(favicon.height, 32) } - function test_noFavicon() { + function test_faviconLoadAfterHistoryNavigation_data() { + return [ + { tag: "OTR", profile: defaultProfile }, + { tag: "non-OTR", profile: nonOTRProfile }, + ]; + } + + function test_faviconLoadAfterHistoryNavigation(row) { + webEngineView.profile = row.profile + compare(iconChangedSpy.count, 0) + + var iconUrl + + webEngineView.url = Qt.resolvedUrl("favicon.html") + verify(webEngineView.waitForLoadSucceeded()) + tryCompare(iconChangedSpy, "count", 1) + iconUrl = removeFaviconProviderPrefix(webEngineView.icon) + compare(iconUrl, Qt.resolvedUrl("icons/favicon.png")) + + iconChangedSpy.clear() + webEngineView.url = Qt.resolvedUrl("favicon-shortcut.html") + verify(webEngineView.waitForLoadSucceeded()) + tryCompare(iconChangedSpy, "count", 2) + iconUrl = removeFaviconProviderPrefix(webEngineView.icon) + compare(iconUrl, Qt.resolvedUrl("icons/qt32.ico")) + + iconChangedSpy.clear() + webEngineView.goBack(); + verify(webEngineView.waitForLoadSucceeded()) + tryCompare(iconChangedSpy, "count", 2) + iconUrl = removeFaviconProviderPrefix(webEngineView.icon) + compare(iconUrl, Qt.resolvedUrl("icons/favicon.png")) + + iconChangedSpy.clear() + webEngineView.goForward(); + verify(webEngineView.waitForLoadSucceeded()) + tryCompare(iconChangedSpy, "count", 2) + iconUrl = removeFaviconProviderPrefix(webEngineView.icon) + compare(iconUrl, Qt.resolvedUrl("icons/qt32.ico")) + } + + + function test_noFavicon_data() { + return [ + { tag: "OTR", profile: defaultProfile }, + { tag: "non-OTR", profile: nonOTRProfile }, + ]; + } + + function test_noFavicon(row) { + webEngineView.profile = row.profile compare(iconChangedSpy.count, 0) var url = Qt.resolvedUrl("test1.html") @@ -150,7 +216,15 @@ TestWebEngineView { compare(iconUrl, Qt.resolvedUrl("")) } - function test_aboutBlank() { + function test_aboutBlank_data() { + return [ + { tag: "OTR", profile: defaultProfile }, + { tag: "non-OTR", profile: nonOTRProfile }, + ]; + } + + function test_aboutBlank(row) { + webEngineView.profile = row.profile compare(iconChangedSpy.count, 0) var url = Qt.resolvedUrl("about:blank") @@ -163,7 +237,15 @@ TestWebEngineView { compare(iconUrl, Qt.resolvedUrl("")) } - function test_unavailableFavicon() { + function test_unavailableFavicon_data() { + return [ + { tag: "OTR", profile: defaultProfile }, + { tag: "non-OTR", profile: nonOTRProfile }, + ]; + } + + function test_unavailableFavicon(row) { + webEngineView.profile = row.profile compare(iconChangedSpy.count, 0) var url = Qt.resolvedUrl("favicon-unavailable.html") @@ -176,15 +258,25 @@ TestWebEngineView { compare(iconUrl, Qt.resolvedUrl("")) } - function test_errorPageEnabled() { - WebEngine.settings.errorPageEnabled = true + function test_errorPageEnabled_data() { + return [ + { tag: "OTR", profile: defaultProfile }, + { tag: "non-OTR", profile: nonOTRProfile }, + ]; + } + + function test_errorPageEnabled(row) { + webEngineView.profile = row.profile + webEngineView.settings.errorPageEnabled = true compare(iconChangedSpy.count, 0) var url = Qt.resolvedUrl("http://url.invalid") webEngineView.url = url verify(webEngineView.waitForLoadFailed(20000)) - verify(webEngineView.testSupport.waitForErrorPageLoadSucceeded()) + // FIXME: Wait for error page load to finish. + // This should be done without testSupport API. + wait(500) compare(iconChangedSpy.count, 0) @@ -192,8 +284,16 @@ TestWebEngineView { compare(iconUrl, Qt.resolvedUrl("")) } - function test_errorPageDisabled() { - WebEngine.settings.errorPageEnabled = false + function test_errorPageDisabled_data() { + return [ + { tag: "OTR", profile: defaultProfile }, + { tag: "non-OTR", profile: nonOTRProfile }, + ]; + } + + function test_errorPageDisabled(row) { + webEngineView.profile = row.profile + webEngineView.settings.errorPageEnabled = false compare(iconChangedSpy.count, 0) @@ -207,7 +307,15 @@ TestWebEngineView { compare(iconUrl, Qt.resolvedUrl("")) } - function test_bestFavicon() { + function test_bestFavicon_data() { + return [ + { tag: "OTR", profile: defaultProfile }, + { tag: "non-OTR", profile: nonOTRProfile }, + ]; + } + + function test_bestFavicon(row) { + webEngineView.profile = row.profile compare(iconChangedSpy.count, 0) var url, iconUrl @@ -221,6 +329,7 @@ TestWebEngineView { iconUrl = removeFaviconProviderPrefix(webEngineView.icon) // Touch icon is ignored compare(iconUrl, Qt.resolvedUrl("icons/qt32.ico")) + tryCompare(favicon, "status", Image.Ready) compare(favicon.width, 32) compare(favicon.height, 32) @@ -230,23 +339,25 @@ TestWebEngineView { webEngineView.url = url verify(webEngineView.waitForLoadSucceeded()) - iconChangedSpy.wait() - verify(iconChangedSpy.count >= 1) + tryCompare(iconChangedSpy, "count", 2) iconUrl = removeFaviconProviderPrefix(webEngineView.icon) - // If the icon URL is empty we have to wait for - // the second iconChanged signal that propagates the expected URL - if (iconUrl == Qt.resolvedUrl("")) { - tryCompare(iconChangedSpy, "count", 2) - iconUrl = removeFaviconProviderPrefix(webEngineView.icon) - } + // If touch icon is disabled, FaviconHandler propagates the icon closest to size 16x16 + compare(iconUrl, Qt.resolvedUrl("icons/qt32.ico")) + tryCompare(favicon, "status", Image.Ready) + compare(favicon.width, 32) + compare(favicon.height, 32) + } - compare(iconUrl, Qt.resolvedUrl("icons/qt144.png")) - compare(favicon.width, 144) - compare(favicon.height, 144) + function test_touchIcon_data() { + return [ + { tag: "OTR", profile: defaultProfile }, + { tag: "non-OTR", profile: nonOTRProfile }, + ]; } - function test_touchIcon() { + function test_touchIcon(row) { + webEngineView.profile = row.profile compare(iconChangedSpy.count, 0) var url = Qt.resolvedUrl("favicon-touch.html") @@ -260,7 +371,7 @@ TestWebEngineView { compare(favicon.width, 0) compare(favicon.height, 0) - WebEngine.settings.touchIconsEnabled = true + webEngineView.settings.touchIconsEnabled = true url = Qt.resolvedUrl("favicon-touch.html") webEngineView.url = url @@ -270,11 +381,20 @@ TestWebEngineView { iconUrl = removeFaviconProviderPrefix(webEngineView.icon) compare(iconUrl, Qt.resolvedUrl("icons/qt144.png")) compare(iconChangedSpy.count, 1) + tryCompare(favicon, "status", Image.Ready) compare(favicon.width, 144) compare(favicon.height, 144) } - function test_multiIcon() { + function test_multiIcon_data() { + return [ + { tag: "OTR", profile: defaultProfile }, + { tag: "non-OTR", profile: nonOTRProfile }, + ]; + } + + function test_multiIcon(row) { + webEngineView.profile = row.profile compare(iconChangedSpy.count, 0) var url = Qt.resolvedUrl("favicon-multi.html") @@ -283,61 +403,24 @@ TestWebEngineView { iconChangedSpy.wait() compare(iconChangedSpy.count, 1) - compare(favicon.width, 64) - compare(favicon.height, 64) + tryCompare(favicon, "status", Image.Ready) + compare(favicon.width, 32) + compare(favicon.height, 32) } - function test_faviconProvider_data() { + function test_dynamicFavicon_data() { return [ - { tag: "multi 8x8", url: Qt.resolvedUrl("favicon-multi-gray.html"), size: 8, value: 16 }, - { tag: "multi 16x16", url: Qt.resolvedUrl("favicon-multi-gray.html"), size: 16, value: 16 }, - { tag: "multi 17x17", url: Qt.resolvedUrl("favicon-multi-gray.html"), size: 17, value: 32 }, - { tag: "multi 31x31", url: Qt.resolvedUrl("favicon-multi-gray.html"), size: 31, value: 32 }, - { tag: "multi 32x32", url: Qt.resolvedUrl("favicon-multi-gray.html"), size: 32, value: 32 }, - { tag: "multi 33x33", url: Qt.resolvedUrl("favicon-multi-gray.html"), size: 33, value: 64 }, - { tag: "multi 64x64", url: Qt.resolvedUrl("favicon-multi-gray.html"), size: 64, value: 64 }, - { tag: "multi 128x128", url: Qt.resolvedUrl("favicon-multi-gray.html"), size: 128, value: 128 }, - { tag: "multi 255x255", url: Qt.resolvedUrl("favicon-multi-gray.html"), size: 255, value: 255 }, - { tag: "multi 256x256", url: Qt.resolvedUrl("favicon-multi-gray.html"), size: 256, value: 255 }, - { tag: "candidate 8x8", url: Qt.resolvedUrl("favicon-candidates-gray.html"), size: 8, value: 16 }, - { tag: "candidate 16x16", url: Qt.resolvedUrl("favicon-candidates-gray.html"), size: 16, value: 16 }, - { tag: "candidate 17x17", url: Qt.resolvedUrl("favicon-candidates-gray.html"), size: 17, value: 32 }, - { tag: "candidate 31x31", url: Qt.resolvedUrl("favicon-candidates-gray.html"), size: 31, value: 32 }, - { tag: "candidate 32x32", url: Qt.resolvedUrl("favicon-candidates-gray.html"), size: 32, value: 32 }, - { tag: "candidate 33x33", url: Qt.resolvedUrl("favicon-candidates-gray.html"), size: 33, value: 64 }, - { tag: "candidate 64x64", url: Qt.resolvedUrl("favicon-candidates-gray.html"), size: 64, value: 64 }, - { tag: "candidate 128x128", url: Qt.resolvedUrl("favicon-candidates-gray.html"), size: 128, value: 128 }, - { tag: "candidate 255x255", url: Qt.resolvedUrl("favicon-candidates-gray.html"), size: 255, value: 255 }, - { tag: "candidate 256x256", url: Qt.resolvedUrl("favicon-candidates-gray.html"), size: 256, value: 255 }, + { tag: "OTR", profile: defaultProfile }, + { tag: "non-OTR", profile: nonOTRProfile }, ]; } - function test_faviconProvider(row) { - var faviconImage = Qt.createQmlObject(" - import QtQuick 2.5\n - Image { sourceSize: Qt.size(width, height) }", testCase) - + function test_dynamicFavicon(row) { + webEngineView.profile = row.profile compare(iconChangedSpy.count, 0) - webEngineView.url = row.url - verify(webEngineView.waitForLoadSucceeded()) - - iconChangedSpy.wait() - compare(iconChangedSpy.count, 1) - - faviconImage.width = row.size / Screen.devicePixelRatio - faviconImage.height = row.size / Screen.devicePixelRatio - faviconImage.source = webEngineView.icon - - var pixel = getFaviconPixel(faviconImage); - compare(pixel[0], row.value) - - faviconImage.destroy() - } - - function test_dynamicFavicon() { var faviconImage = Qt.createQmlObject(" - import QtQuick 2.5\n + import QtQuick\n Image { width: 16; height: 16; sourceSize: Qt.size(width, height); }", testCase) faviconImage.source = Qt.binding(function() { return webEngineView.icon; }); @@ -377,9 +460,17 @@ TestWebEngineView { faviconImage.destroy() } - function test_touchIconWithSameURL() + function test_touchIconWithSameURL_data() { + return [ + { tag: "OTR", profile: defaultProfile }, + { tag: "non-OTR", profile: nonOTRProfile }, + ]; + } + + function test_touchIconWithSameURL(row) { - WebEngine.settings.touchIconsEnabled = false; + webEngineView.profile = row.profile; + compare(iconChangedSpy.count, 0); var icon = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNk+A8AAQUBAScY42YAAAAASUVORK5CYII="; @@ -409,5 +500,53 @@ TestWebEngineView { tryCompare(iconChangedSpy, "count", 1); verify(!webEngineView.icon.toString().replace(/^image:\/\/favicon\//, '')); } + + function test_iconsDisabled_data() { + return [ + { tag: "misc", url: Qt.resolvedUrl("favicon-misc.html") }, + { tag: "shortcut", url: Qt.resolvedUrl("favicon-shortcut.html") }, + { tag: "single", url: Qt.resolvedUrl("favicon-single.html") }, + { tag: "touch", url: Qt.resolvedUrl("favicon-touch.html") }, + { tag: "unavailable", url: Qt.resolvedUrl("favicon-unavailable.html") }, + ]; + } + + function test_iconsDisabled(row) { + webEngineView.settings.autoLoadIconsForPage = false + webEngineView.profile = defaultProfile + compare(iconChangedSpy.count, 0) + + webEngineView.url = row.url + verify(webEngineView.waitForLoadSucceeded()) + + compare(iconChangedSpy.count, 0) + + var iconUrl = webEngineView.icon + compare(iconUrl, Qt.resolvedUrl("")) + } + + function test_touchIconsEnabled_data() { + return [ + { tag: "misc", url: Qt.resolvedUrl("favicon-misc.html"), expectedIconUrl: Qt.resolvedUrl("icons/qt144.png") }, + { tag: "shortcut", url: Qt.resolvedUrl("favicon-shortcut.html"), expectedIconUrl: Qt.resolvedUrl("icons/qt144.png") }, + { tag: "single", url: Qt.resolvedUrl("favicon-single.html"), expectedIconUrl: Qt.resolvedUrl("icons/qt32.ico") }, + { tag: "touch", url: Qt.resolvedUrl("favicon-touch.html"), expectedIconUrl: Qt.resolvedUrl("icons/qt144.png") }, + ]; + } + + function test_touchIconsEnabled(row) { + webEngineView.settings.touchIconsEnabled = true + webEngineView.profile = defaultProfile + compare(iconChangedSpy.count, 0) + + webEngineView.url = row.url + verify(webEngineView.waitForLoadSucceeded()) + + iconChangedSpy.wait() + compare(iconChangedSpy.count, 1) + + var iconUrl = removeFaviconProviderPrefix(webEngineView.icon) + compare(iconUrl, row.expectedIconUrl) + } } } diff --git a/tests/auto/quick/qmltests/data/tst_faviconDownload.qml b/tests/auto/quick/qmltests/data/tst_faviconDownload.qml deleted file mode 100644 index 7d9c39814..000000000 --- a/tests/auto/quick/qmltests/data/tst_faviconDownload.qml +++ /dev/null @@ -1,121 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtWebEngine module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -import QtQuick 2.0 -import QtTest 1.0 -import QtWebEngine 1.3 -import "../../qmltests/data" 1.0 - -TestWebEngineView { - id: webEngineView - width: 200 - height: 400 - - function removeFaviconProviderPrefix(url) { - return url.toString().substring(16) - } - - SignalSpy { - id: iconChangedSpy - target: webEngineView - signalName: "iconChanged" - } - - TestCase { - id: testCase - name: "WebEngineFaviconDownload" - - function init() { - WebEngine.settings.autoLoadIconsForPage = true - WebEngine.settings.touchIconsEnabled = false - - if (webEngineView.icon != '') { - // If this is not the first test, then load a blank page without favicon, restoring the initial state. - webEngineView.url = 'about:blank' - verify(webEngineView.waitForLoadSucceeded()) - iconChangedSpy.wait() - } - - iconChangedSpy.clear() - } - - function cleanupTestCase() { - WebEngine.settings.autoLoadIconsForPage = true - WebEngine.settings.touchIconsEnabled = false - } - - function test_downloadIconsDisabled_data() { - return [ - { tag: "misc", url: Qt.resolvedUrl("favicon-misc.html") }, - { tag: "shortcut", url: Qt.resolvedUrl("favicon-shortcut.html") }, - { tag: "single", url: Qt.resolvedUrl("favicon-single.html") }, - { tag: "touch", url: Qt.resolvedUrl("favicon-touch.html") }, - { tag: "unavailable", url: Qt.resolvedUrl("favicon-unavailable.html") }, - ]; - } - - function test_downloadIconsDisabled(row) { - WebEngine.settings.autoLoadIconsForPage = false - - compare(iconChangedSpy.count, 0) - - webEngineView.url = row.url - verify(webEngineView.waitForLoadSucceeded()) - - compare(iconChangedSpy.count, 0) - - var iconUrl = webEngineView.icon - compare(iconUrl, Qt.resolvedUrl("")) - } - - function test_downloadTouchIconsEnabled_data() { - return [ - { tag: "misc", url: Qt.resolvedUrl("favicon-misc.html"), expectedIconUrl: Qt.resolvedUrl("icons/qt144.png") }, - { tag: "shortcut", url: Qt.resolvedUrl("favicon-shortcut.html"), expectedIconUrl: Qt.resolvedUrl("icons/qt144.png") }, - { tag: "single", url: Qt.resolvedUrl("favicon-single.html"), expectedIconUrl: Qt.resolvedUrl("icons/qt32.ico") }, - { tag: "touch", url: Qt.resolvedUrl("favicon-touch.html"), expectedIconUrl: Qt.resolvedUrl("icons/qt144.png") }, - ]; - } - - function test_downloadTouchIconsEnabled(row) { - WebEngine.settings.touchIconsEnabled = true - - compare(iconChangedSpy.count, 0) - - webEngineView.url = row.url - verify(webEngineView.waitForLoadSucceeded()) - - iconChangedSpy.wait() - compare(iconChangedSpy.count, 1) - - var iconUrl = removeFaviconProviderPrefix(webEngineView.icon) - compare(iconUrl, row.expectedIconUrl) - } - } -} - diff --git a/tests/auto/widgets/CMakeLists.txt b/tests/auto/widgets/CMakeLists.txt index 7072329c3..f7955b1f8 100644 --- a/tests/auto/widgets/CMakeLists.txt +++ b/tests/auto/widgets/CMakeLists.txt @@ -5,7 +5,7 @@ if(NOT boot2qt) add_subdirectory(qwebengineprofile) add_subdirectory(qwebengineview) endif() -add_subdirectory(faviconmanager) +add_subdirectory(favicon) add_subdirectory(loadsignals) add_subdirectory(origins) add_subdirectory(proxy) diff --git a/tests/auto/widgets/faviconmanager/CMakeLists.txt b/tests/auto/widgets/favicon/CMakeLists.txt index 89bee5a2a..64c4efc91 100644 --- a/tests/auto/widgets/faviconmanager/CMakeLists.txt +++ b/tests/auto/widgets/favicon/CMakeLists.txt @@ -1,14 +1,14 @@ include(../../util/util.cmake) -qt_internal_add_test(tst_faviconmanager +qt_internal_add_test(tst_favicon SOURCES - tst_faviconmanager.cpp + tst_favicon.cpp LIBRARIES Qt::WebEngineWidgets Test::Util ) -set(tst_faviconmanager_resource_files +set(tst_favicon_resource_files "resources/favicon-misc.html" "resources/favicon-multi.html" "resources/favicon-shortcut.html" @@ -21,9 +21,9 @@ set(tst_faviconmanager_resource_files "resources/test1.html" ) -qt_add_resource(tst_faviconmanager "tst_faviconmanager" +qt_add_resource(tst_favicon "tst_favicon" PREFIX "/" FILES - ${tst_faviconmanager_resource_files} + ${tst_favicon_resource_files} ) diff --git a/tests/auto/widgets/faviconmanager/faviconmanager.pro b/tests/auto/widgets/favicon/favicon.pro index e99c7f493..e99c7f493 100644 --- a/tests/auto/widgets/faviconmanager/faviconmanager.pro +++ b/tests/auto/widgets/favicon/favicon.pro diff --git a/tests/auto/widgets/faviconmanager/resources/favicon-misc.html b/tests/auto/widgets/favicon/resources/favicon-misc.html index 9e788bdf4..ea587886f 100644 --- a/tests/auto/widgets/faviconmanager/resources/favicon-misc.html +++ b/tests/auto/widgets/favicon/resources/favicon-misc.html @@ -1,8 +1,8 @@ <html> <head> <title>Favicon Test</title> - <link rel="shortcut icon" href="icons/qt32.ico" /> - <link rel="apple-touch-icon" href="icons/qt144.png" /> + <link rel="shortcut icon" href="icons/qt32.ico" sizes="32x32" /> + <link rel="apple-touch-icon" href="icons/qt144.png" sizes="144x144" /> <link rel="shortcut icon" href="icons/unavailable.ico" /> </head> <body> diff --git a/tests/auto/widgets/faviconmanager/resources/favicon-multi.html b/tests/auto/widgets/favicon/resources/favicon-multi.html index cc5f3fd66..56eeca8c4 100644 --- a/tests/auto/widgets/faviconmanager/resources/favicon-multi.html +++ b/tests/auto/widgets/favicon/resources/favicon-multi.html @@ -1,7 +1,7 @@ <html> <head> <title>Multi-sized Favicon Test</title> - <link rel="shortcut icon" sizes="16x16 32x23 64x64" href="icons/qtmulti.ico" /> + <link rel="shortcut icon" sizes="16x16 32x32 64x64" href="icons/qtmulti.ico" /> </head> <body> <h1>Multi-sized Favicon Test</h1> diff --git a/tests/auto/widgets/faviconmanager/resources/favicon-shortcut.html b/tests/auto/widgets/favicon/resources/favicon-shortcut.html index 786cdb816..786cdb816 100644 --- a/tests/auto/widgets/faviconmanager/resources/favicon-shortcut.html +++ b/tests/auto/widgets/favicon/resources/favicon-shortcut.html diff --git a/tests/auto/widgets/faviconmanager/resources/favicon-single.html b/tests/auto/widgets/favicon/resources/favicon-single.html index eb4675c75..eb4675c75 100644 --- a/tests/auto/widgets/faviconmanager/resources/favicon-single.html +++ b/tests/auto/widgets/favicon/resources/favicon-single.html diff --git a/tests/auto/widgets/faviconmanager/resources/favicon-touch.html b/tests/auto/widgets/favicon/resources/favicon-touch.html index 271783434..271783434 100644 --- a/tests/auto/widgets/faviconmanager/resources/favicon-touch.html +++ b/tests/auto/widgets/favicon/resources/favicon-touch.html diff --git a/tests/auto/widgets/faviconmanager/resources/favicon-unavailable.html b/tests/auto/widgets/favicon/resources/favicon-unavailable.html index c45664294..c45664294 100644 --- a/tests/auto/widgets/faviconmanager/resources/favicon-unavailable.html +++ b/tests/auto/widgets/favicon/resources/favicon-unavailable.html diff --git a/tests/auto/widgets/faviconmanager/resources/icons/qt144.png b/tests/auto/widgets/favicon/resources/icons/qt144.png Binary files differindex 050b1e066..050b1e066 100644 --- a/tests/auto/widgets/faviconmanager/resources/icons/qt144.png +++ b/tests/auto/widgets/favicon/resources/icons/qt144.png diff --git a/tests/auto/widgets/faviconmanager/resources/icons/qt32.ico b/tests/auto/widgets/favicon/resources/icons/qt32.ico Binary files differindex 2f6fcb5bc..2f6fcb5bc 100644 --- a/tests/auto/widgets/faviconmanager/resources/icons/qt32.ico +++ b/tests/auto/widgets/favicon/resources/icons/qt32.ico diff --git a/tests/auto/widgets/faviconmanager/resources/icons/qtmulti.ico b/tests/auto/widgets/favicon/resources/icons/qtmulti.ico Binary files differindex 81e5a22e8..81e5a22e8 100644 --- a/tests/auto/widgets/faviconmanager/resources/icons/qtmulti.ico +++ b/tests/auto/widgets/favicon/resources/icons/qtmulti.ico diff --git a/tests/auto/widgets/faviconmanager/resources/test1.html b/tests/auto/widgets/favicon/resources/test1.html index b323f966e..b323f966e 100644 --- a/tests/auto/widgets/faviconmanager/resources/test1.html +++ b/tests/auto/widgets/favicon/resources/test1.html diff --git a/tests/auto/widgets/faviconmanager/tst_faviconmanager.cpp b/tests/auto/widgets/favicon/tst_favicon.cpp index 8e9bb2470..377699aaa 100644 --- a/tests/auto/widgets/faviconmanager/tst_faviconmanager.cpp +++ b/tests/auto/widgets/favicon/tst_favicon.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2021 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the QtWebEngine module of the Qt Toolkit. @@ -29,13 +29,13 @@ #include <QtTest/QtTest> #include <util.h> -#include <qwebenginepage.h> -#include <qwebengineprofile.h> -#include <qwebenginesettings.h> -#include <qwebengineview.h> +#include <QWebEnginePage> +#include <QWebEngineProfile> +#include <QWebEngineSettings> +#include <QWebEngineView> - -class tst_FaviconManager : public QObject { +class tst_Favicon : public QObject +{ Q_OBJECT public Q_SLOTS: @@ -48,15 +48,14 @@ private Q_SLOTS: void faviconLoad(); void faviconLoadFromResources(); void faviconLoadEncodedUrl(); + void faviconLoadAfterHistoryNavigation(); void noFavicon(); void aboutBlank(); void unavailableFavicon(); void errorPageEnabled(); void errorPageDisabled(); - void bestFavicon(); void touchIcon(); void multiIcon(); - void candidateIcon(); void downloadIconsDisabled_data(); void downloadIconsDisabled(); void downloadTouchIconsEnabled_data(); @@ -70,8 +69,7 @@ private: QWebEngineProfile *m_profile; }; - -void tst_FaviconManager::init() +void tst_Favicon::init() { m_profile = new QWebEngineProfile(this); m_view = new QWebEngineView(); @@ -79,23 +77,17 @@ void tst_FaviconManager::init() m_view->setPage(m_page); } +void tst_Favicon::initTestCase() { } -void tst_FaviconManager::initTestCase() -{ -} - -void tst_FaviconManager::cleanupTestCase() -{ -} - +void tst_Favicon::cleanupTestCase() { } -void tst_FaviconManager::cleanup() +void tst_Favicon::cleanup() { delete m_view; delete m_profile; } -void tst_FaviconManager::faviconLoad() +void tst_Favicon::faviconLoad() { if (!QDir(QDir(QT_TESTCASE_SOURCEDIR).canonicalPath()).exists()) W_QSKIP(QString("This test requires access to resources found in '%1'") @@ -125,12 +117,12 @@ void tst_FaviconManager::faviconLoad() const QIcon &icon = m_page->icon(); QVERIFY(!icon.isNull()); - QCOMPARE(icon.availableSizes().count(), 1); - QSize iconSize = icon.availableSizes().first(); - QCOMPARE(iconSize, QSize(32, 32)); + QCOMPARE(icon.availableSizes().count(), 2); + QVERIFY(icon.availableSizes().contains(QSize(16, 16))); + QVERIFY(icon.availableSizes().contains(QSize(32, 32))); } -void tst_FaviconManager::faviconLoadFromResources() +void tst_Favicon::faviconLoadFromResources() { QSignalSpy loadFinishedSpy(m_page, SIGNAL(loadFinished(bool))); QSignalSpy iconUrlChangedSpy(m_page, SIGNAL(iconUrlChanged(QUrl))); @@ -150,12 +142,12 @@ void tst_FaviconManager::faviconLoadFromResources() const QIcon &icon = m_page->icon(); QVERIFY(!icon.isNull()); - QCOMPARE(icon.availableSizes().count(), 1); - QSize iconSize = icon.availableSizes().first(); - QCOMPARE(iconSize, QSize(32, 32)); + QCOMPARE(icon.availableSizes().count(), 2); + QVERIFY(icon.availableSizes().contains(QSize(16, 16))); + QVERIFY(icon.availableSizes().contains(QSize(32, 32))); } -void tst_FaviconManager::faviconLoadEncodedUrl() +void tst_Favicon::faviconLoadEncodedUrl() { if (!QDir(QDir(QT_TESTCASE_SOURCEDIR).canonicalPath()).exists()) W_QSKIP(QString("This test requires access to resources found in '%1'") @@ -187,12 +179,43 @@ void tst_FaviconManager::faviconLoadEncodedUrl() const QIcon &icon = m_page->icon(); QVERIFY(!icon.isNull()); - QCOMPARE(icon.availableSizes().count(), 1); - QSize iconSize = icon.availableSizes().first(); - QCOMPARE(iconSize, QSize(32, 32)); + QCOMPARE(icon.availableSizes().count(), 2); + QVERIFY(icon.availableSizes().contains(QSize(16, 16))); + QVERIFY(icon.availableSizes().contains(QSize(32, 32))); +} + +void tst_Favicon::faviconLoadAfterHistoryNavigation() +{ + QSignalSpy loadFinishedSpy(m_page, SIGNAL(loadFinished(bool))); + QSignalSpy iconUrlChangedSpy(m_page, SIGNAL(iconUrlChanged(QUrl))); + QSignalSpy iconChangedSpy(m_page, SIGNAL(iconChanged(QIcon))); + + m_page->load(QUrl("qrc:/resources/favicon-single.html")); + QTRY_COMPARE_WITH_TIMEOUT(loadFinishedSpy.count(), 1, 30000); + QTRY_COMPARE(iconUrlChangedSpy.count(), 1); + QTRY_COMPARE(iconChangedSpy.count(), 1); + QCOMPARE(m_page->iconUrl(), QUrl("qrc:/resources/icons/qt32.ico")); + + m_page->load(QUrl("qrc:/resources/favicon-multi.html")); + QTRY_COMPARE_WITH_TIMEOUT(loadFinishedSpy.count(), 2, 30000); + QTRY_COMPARE(iconUrlChangedSpy.count(), 3); + QTRY_COMPARE(iconChangedSpy.count(), 3); + QCOMPARE(m_page->iconUrl(), QUrl("qrc:/resources/icons/qtmulti.ico")); + + m_page->triggerAction(QWebEnginePage::Back); + QTRY_COMPARE_WITH_TIMEOUT(loadFinishedSpy.count(), 3, 30000); + QTRY_COMPARE(iconUrlChangedSpy.count(), 5); + QTRY_COMPARE(iconChangedSpy.count(), 5); + QCOMPARE(m_page->iconUrl(), QUrl("qrc:/resources/icons/qt32.ico")); + + m_page->triggerAction(QWebEnginePage::Forward); + QTRY_COMPARE_WITH_TIMEOUT(loadFinishedSpy.count(), 4, 30000); + QTRY_COMPARE(iconUrlChangedSpy.count(), 7); + QTRY_COMPARE(iconChangedSpy.count(), 7); + QCOMPARE(m_page->iconUrl(), QUrl("qrc:/resources/icons/qtmulti.ico")); } -void tst_FaviconManager::noFavicon() +void tst_Favicon::noFavicon() { if (!QDir(QDir(QT_TESTCASE_SOURCEDIR).canonicalPath()).exists()) W_QSKIP(QString("This test requires access to resources found in '%1'") @@ -217,7 +240,7 @@ void tst_FaviconManager::noFavicon() QVERIFY(m_page->icon().isNull()); } -void tst_FaviconManager::aboutBlank() +void tst_Favicon::aboutBlank() { QSignalSpy loadFinishedSpy(m_page, SIGNAL(loadFinished(bool))); QSignalSpy iconUrlChangedSpy(m_page, SIGNAL(iconUrlChanged(QUrl))); @@ -234,7 +257,7 @@ void tst_FaviconManager::aboutBlank() QVERIFY(m_page->icon().isNull()); } -void tst_FaviconManager::unavailableFavicon() +void tst_Favicon::unavailableFavicon() { if (!QDir(QDir(QT_TESTCASE_SOURCEDIR).canonicalPath()).exists()) W_QSKIP(QString("This test requires access to resources found in '%1'") @@ -259,7 +282,7 @@ void tst_FaviconManager::unavailableFavicon() QVERIFY(m_page->icon().isNull()); } -void tst_FaviconManager::errorPageEnabled() +void tst_Favicon::errorPageEnabled() { m_page->settings()->setAttribute(QWebEngineSettings::ErrorPageEnabled, true); @@ -278,7 +301,7 @@ void tst_FaviconManager::errorPageEnabled() QVERIFY(m_page->icon().isNull()); } -void tst_FaviconManager::errorPageDisabled() +void tst_Favicon::errorPageDisabled() { m_page->settings()->setAttribute(QWebEngineSettings::ErrorPageEnabled, false); @@ -297,80 +320,7 @@ void tst_FaviconManager::errorPageDisabled() QVERIFY(m_page->icon().isNull()); } -void tst_FaviconManager::bestFavicon() -{ - if (!QDir(QDir(QT_TESTCASE_SOURCEDIR).canonicalPath()).exists()) - W_QSKIP(QString("This test requires access to resources found in '%1'") - .arg(QDir(QT_TESTCASE_SOURCEDIR).canonicalPath()) - .toLatin1() - .constData(), - SkipAll); - - QSignalSpy loadFinishedSpy(m_page, SIGNAL(loadFinished(bool))); - QSignalSpy iconUrlChangedSpy(m_page, SIGNAL(iconUrlChanged(QUrl))); - QSignalSpy iconChangedSpy(m_page, SIGNAL(iconChanged(QIcon))); - - QUrl url, iconUrl; - QIcon icon; - QSize iconSize; - - url = QUrl::fromLocalFile(QDir(QT_TESTCASE_SOURCEDIR).canonicalPath() - + QLatin1String("/resources/favicon-misc.html")); - m_page->load(url); - - QTRY_COMPARE_WITH_TIMEOUT(loadFinishedSpy.count(), 1, 30000); - QTRY_COMPARE(iconUrlChangedSpy.count(), 1); - QTRY_COMPARE(iconChangedSpy.count(), 1); - - iconUrl = iconUrlChangedSpy.at(0).at(0).toString(); - QCOMPARE(iconUrl, m_page->iconUrl()); - // Touch icon is ignored - QCOMPARE(iconUrl, - QUrl::fromLocalFile(QDir(QT_TESTCASE_SOURCEDIR).canonicalPath() - + QLatin1String("/resources/icons/qt32.ico"))); - - icon = m_page->icon(); - QVERIFY(!icon.isNull()); - - QCOMPARE(icon.availableSizes().count(), 1); - iconSize = icon.availableSizes().first(); - QCOMPARE(iconSize, QSize(32, 32)); - - loadFinishedSpy.clear(); - iconUrlChangedSpy.clear(); - iconChangedSpy.clear(); - - url = QUrl::fromLocalFile(QDir(QT_TESTCASE_SOURCEDIR).canonicalPath() - + QLatin1String("/resources/favicon-shortcut.html")); - m_page->load(url); - - QTRY_COMPARE_WITH_TIMEOUT(loadFinishedSpy.count(), 1, 30000); - QTRY_VERIFY(iconUrlChangedSpy.count() >= 1); - QTRY_VERIFY(iconChangedSpy.count() >= 1); - - iconUrl = iconUrlChangedSpy.last().at(0).toString(); - - // If the icon URL is empty we have to wait for - // the second iconChanged signal that propagates the expected URL - if (iconUrl.isEmpty()) { - QTRY_COMPARE(iconUrlChangedSpy.count(), 2); - QTRY_COMPARE(iconChangedSpy.count(), 2); - iconUrl = iconUrlChangedSpy.last().at(0).toString(); - } - - QCOMPARE(iconUrl, m_page->iconUrl()); - QCOMPARE(iconUrl, - QUrl::fromLocalFile(QDir(QT_TESTCASE_SOURCEDIR).canonicalPath() - + QLatin1String("/resources/icons/qt144.png"))); - - icon = m_page->icon(); - QVERIFY(!icon.isNull()); - - QVERIFY(icon.availableSizes().count() >= 1); - QVERIFY(icon.availableSizes().contains(QSize(144, 144))); -} - -void tst_FaviconManager::touchIcon() +void tst_Favicon::touchIcon() { if (!QDir(QDir(QT_TESTCASE_SOURCEDIR).canonicalPath()).exists()) W_QSKIP(QString("This test requires access to resources found in '%1'") @@ -395,7 +345,7 @@ void tst_FaviconManager::touchIcon() QVERIFY(m_page->icon().isNull()); } -void tst_FaviconManager::multiIcon() +void tst_Favicon::multiIcon() { if (!QDir(QDir(QT_TESTCASE_SOURCEDIR).canonicalPath()).exists()) W_QSKIP(QString("This test requires access to resources found in '%1'") @@ -410,61 +360,60 @@ void tst_FaviconManager::multiIcon() QUrl url = QUrl::fromLocalFile(QDir(QT_TESTCASE_SOURCEDIR).canonicalPath() + QLatin1String("/resources/favicon-multi.html")); + QUrl iconUrl; + QIcon icon; + + // If touch icons are disabled, the favicon is provided in two sizes (16x16 and 32x32) according + // to the supported scale factors (100P, 200P). + m_page->settings()->setAttribute(QWebEngineSettings::TouchIconsEnabled, false); m_page->load(url); QTRY_COMPARE_WITH_TIMEOUT(loadFinishedSpy.count(), 1, 30000); QTRY_COMPARE(iconUrlChangedSpy.count(), 1); QTRY_COMPARE(iconChangedSpy.count(), 1); - QUrl iconUrl = iconUrlChangedSpy.at(0).at(0).toString(); + iconUrl = iconUrlChangedSpy.at(0).at(0).toString(); QCOMPARE(m_page->iconUrl(), iconUrl); QCOMPARE(iconUrl, QUrl::fromLocalFile(QDir(QT_TESTCASE_SOURCEDIR).canonicalPath() + QLatin1String("/resources/icons/qtmulti.ico"))); - const QIcon &icon = m_page->icon(); + icon = m_page->icon(); QVERIFY(!icon.isNull()); - QCOMPARE(icon.availableSizes().count(), 3); + QCOMPARE(icon.availableSizes().count(), 2); QVERIFY(icon.availableSizes().contains(QSize(16, 16))); QVERIFY(icon.availableSizes().contains(QSize(32, 32))); - QVERIFY(icon.availableSizes().contains(QSize(64, 64))); -} -void tst_FaviconManager::candidateIcon() -{ - if (!QDir(QDir(QT_TESTCASE_SOURCEDIR).canonicalPath()).exists()) - W_QSKIP(QString("This test requires access to resources found in '%1'") - .arg(QDir(QT_TESTCASE_SOURCEDIR).canonicalPath()) - .toLatin1() - .constData(), - SkipAll); - - QSignalSpy loadFinishedSpy(m_page, SIGNAL(loadFinished(bool))); - QSignalSpy iconUrlChangedSpy(m_page, SIGNAL(iconUrlChanged(QUrl))); - QSignalSpy iconChangedSpy(m_page, SIGNAL(iconChanged(QIcon))); + // Reset + loadFinishedSpy.clear(); + m_page->load(QUrl("about:blank")); + QTRY_COMPARE_WITH_TIMEOUT(loadFinishedSpy.count(), 1, 30000); + iconUrlChangedSpy.clear(); + iconChangedSpy.clear(); + loadFinishedSpy.clear(); + icon = QIcon(); - QUrl url = QUrl::fromLocalFile(QDir(QT_TESTCASE_SOURCEDIR).canonicalPath() - + QLatin1String("/resources/favicon-shortcut.html")); + // If touch icons are enabled, the largest icon is provided. + m_page->settings()->setAttribute(QWebEngineSettings::TouchIconsEnabled, true); m_page->load(url); QTRY_COMPARE_WITH_TIMEOUT(loadFinishedSpy.count(), 1, 30000); QTRY_COMPARE(iconUrlChangedSpy.count(), 1); QTRY_COMPARE(iconChangedSpy.count(), 1); - QUrl iconUrl = iconUrlChangedSpy.at(0).at(0).toString(); + iconUrl = iconUrlChangedSpy.at(0).at(0).toString(); QCOMPARE(m_page->iconUrl(), iconUrl); QCOMPARE(iconUrl, QUrl::fromLocalFile(QDir(QT_TESTCASE_SOURCEDIR).canonicalPath() - + QLatin1String("/resources/icons/qt144.png"))); + + QLatin1String("/resources/icons/qtmulti.ico"))); - const QIcon &icon = m_page->icon(); + icon = m_page->icon(); QVERIFY(!icon.isNull()); - QCOMPARE(icon.availableSizes().count(), 2); - QVERIFY(icon.availableSizes().contains(QSize(32, 32))); - QVERIFY(icon.availableSizes().contains(QSize(144, 144))); + QCOMPARE(icon.availableSizes().count(), 1); + QVERIFY(icon.availableSizes().contains(QSize(64, 64))); } -void tst_FaviconManager::downloadIconsDisabled_data() +void tst_Favicon::downloadIconsDisabled_data() { QTest::addColumn<QUrl>("url"); QTest::newRow("misc") << QUrl("qrc:/resources/favicon-misc.html"); @@ -474,7 +423,7 @@ void tst_FaviconManager::downloadIconsDisabled_data() QTest::newRow("unavailable") << QUrl("qrc:/resources/favicon-unavailable.html"); } -void tst_FaviconManager::downloadIconsDisabled() +void tst_Favicon::downloadIconsDisabled() { QFETCH(QUrl, url); @@ -494,18 +443,22 @@ void tst_FaviconManager::downloadIconsDisabled() QVERIFY(m_page->icon().isNull()); } -void tst_FaviconManager::downloadTouchIconsEnabled_data() +void tst_Favicon::downloadTouchIconsEnabled_data() { QTest::addColumn<QUrl>("url"); QTest::addColumn<QUrl>("expectedIconUrl"); QTest::addColumn<QSize>("expectedIconSize"); - QTest::newRow("misc") << QUrl("qrc:/resources/favicon-misc.html") << QUrl("qrc:/resources/icons/qt144.png") << QSize(144, 144); - QTest::newRow("shortcut") << QUrl("qrc:/resources/favicon-shortcut.html") << QUrl("qrc:/resources/icons/qt144.png") << QSize(144, 144); - QTest::newRow("single") << QUrl("qrc:/resources/favicon-single.html") << QUrl("qrc:/resources/icons/qt32.ico") << QSize(32, 32); - QTest::newRow("touch") << QUrl("qrc:/resources/favicon-touch.html") << QUrl("qrc:/resources/icons/qt144.png") << QSize(144, 144); + QTest::newRow("misc") << QUrl("qrc:/resources/favicon-misc.html") + << QUrl("qrc:/resources/icons/qt144.png") << QSize(144, 144); + QTest::newRow("shortcut") << QUrl("qrc:/resources/favicon-shortcut.html") + << QUrl("qrc:/resources/icons/qt144.png") << QSize(144, 144); + QTest::newRow("single") << QUrl("qrc:/resources/favicon-single.html") + << QUrl("qrc:/resources/icons/qt32.ico") << QSize(32, 32); + QTest::newRow("touch") << QUrl("qrc:/resources/favicon-touch.html") + << QUrl("qrc:/resources/icons/qt144.png") << QSize(144, 144); } -void tst_FaviconManager::downloadTouchIconsEnabled() +void tst_Favicon::downloadTouchIconsEnabled() { QFETCH(QUrl, url); QFETCH(QUrl, expectedIconUrl); @@ -530,23 +483,27 @@ void tst_FaviconManager::downloadTouchIconsEnabled() const QIcon &icon = m_page->icon(); QVERIFY(!icon.isNull()); - QVERIFY(icon.availableSizes().count() >= 1); - QVERIFY(icon.availableSizes().contains(expectedIconSize)); + QCOMPARE(icon.availableSizes().count(), 1); + QCOMPARE(icon.availableSizes().first(), expectedIconSize); } -void tst_FaviconManager::dynamicFavicon() +void tst_Favicon::dynamicFavicon() { QSignalSpy loadFinishedSpy(m_page, SIGNAL(loadFinished(bool))); QSignalSpy iconUrlChangedSpy(m_page, SIGNAL(iconUrlChanged(QUrl))); QSignalSpy iconChangedSpy(m_page, SIGNAL(iconChanged(QIcon))); QMap<Qt::GlobalColor, QString> colors; - colors.insert(Qt::red, QString("iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z8DwHwAFBQIAX8jx0gAAAABJRU5ErkJggg==")); - colors.insert(Qt::green, QString("iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M/wHwAEBgIApD5fRAAAAABJRU5ErkJggg==")); - colors.insert(Qt::blue, QString("iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNkYPj/HwADBwIAMCbHYQAAAABJRU5ErkJggg==")); + colors.insert(Qt::red, + QString("iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z8DwHwAFBQIAX8jx0gAAAABJRU5ErkJggg==")); + colors.insert(Qt::green, + QString("iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M/wHwAEBgIApD5fRAAAAABJRU5ErkJggg==")); + colors.insert(Qt::blue, + QString("iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNkYPj/HwADBwIAMCbHYQAAAABJRU5ErkJggg==")); m_page->setHtml("<html>" - "<link rel='icon' type='image/png' href='data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNk+A8AAQUBAScY42YAAAAASUVORK5CYII='/>" + "<link rel='icon' type='image/png' " + "href='data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNk+A8AAQUBAScY42YAAAAASUVORK5CYII='/>" "</html>"); QTRY_COMPARE_WITH_TIMEOUT(loadFinishedSpy.count(), 1, 30000); QTRY_COMPARE(iconUrlChangedSpy.count(), 1); @@ -556,14 +513,17 @@ void tst_FaviconManager::dynamicFavicon() for (Qt::GlobalColor color : colors.keys()) { iconChangedSpy.clear(); - evaluateJavaScriptSync(m_page, "document.getElementsByTagName('link')[0].href = 'data:image/png;base64," + colors[color] + "';"); + evaluateJavaScriptSync( + m_page, + "document.getElementsByTagName('link')[0].href = 'data:image/png;base64," + colors[color] + "';"); QTRY_COMPARE(iconChangedSpy.count(), 1); - QTRY_COMPARE(m_page->iconUrl().toString(), QString("data:image/png;base64," + colors[color])); + QTRY_COMPARE(m_page->iconUrl().toString(), + QString("data:image/png;base64," + colors[color])); QCOMPARE(m_page->icon().pixmap(1, 1).toImage().pixelColor(0, 0), QColor(color)); } } -void tst_FaviconManager::touchIconWithSameURL() +void tst_Favicon::touchIconWithSameURL() { m_page->settings()->setAttribute(QWebEngineSettings::TouchIconsEnabled, false); @@ -578,7 +538,8 @@ void tst_FaviconManager::touchIconWithSameURL() "</html>"); QTRY_COMPARE_WITH_TIMEOUT(loadFinishedSpy.count(), 1, 30000); - // The default favicon has to be loaded even if its URL is also set as a touch icon while touch icons are disabled. + // The default favicon has to be loaded even if its URL is also set as a touch icon while touch + // icons are disabled. QTRY_COMPARE(iconUrlChangedSpy.count(), 1); QCOMPARE(m_page->iconUrl().toString(), icon); QTRY_COMPARE(iconChangedSpy.count(), 1); @@ -592,14 +553,13 @@ void tst_FaviconManager::touchIconWithSameURL() "</html>"); QTRY_COMPARE(loadFinishedSpy.count(), 1); - // This page only has a touch icon. With disabled touch icons we don't expect any icon to be shown even if the same icon - // was loaded previously. + // This page only has a touch icon. With disabled touch icons we don't expect any icon to be + // shown even if the same icon was loaded previously. QTRY_COMPARE(iconUrlChangedSpy.count(), 1); QVERIFY(m_page->iconUrl().toString().isEmpty()); QTRY_COMPARE(iconChangedSpy.count(), 1); - } -QTEST_MAIN(tst_FaviconManager) +QTEST_MAIN(tst_Favicon) -#include "tst_faviconmanager.moc" +#include "tst_favicon.moc" diff --git a/tests/auto/widgets/faviconmanager/tst_faviconmanager.qrc b/tests/auto/widgets/favicon/tst_favicon.qrc index a352f8a83..a352f8a83 100644 --- a/tests/auto/widgets/faviconmanager/tst_faviconmanager.qrc +++ b/tests/auto/widgets/favicon/tst_favicon.qrc diff --git a/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp b/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp index 432a91224..170afaafc 100644 --- a/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp +++ b/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp @@ -311,7 +311,8 @@ void tst_QWebEngineView::changePage() if (!fromIsNullPage) { QVERIFY(!pageFrom->iconUrl().isEmpty()); QCOMPARE(spyIconUrl.last().value(0).toUrl(), pageFrom->iconUrl()); - QCOMPARE(spyIcon.last().value(0).value<QIcon>(), pageFrom->icon()); + QCOMPARE(spyIcon.last().value(0).value<QIcon>().availableSizes(), + pageFrom->icon().availableSizes()); } QScopedPointer<QWebEnginePage> pageTo(new QWebEnginePage); @@ -340,7 +341,8 @@ void tst_QWebEngineView::changePage() QCOMPARE(pageFrom->iconUrl() == pageTo->iconUrl(), iconIsSame); if (!iconIsSame) { QCOMPARE(spyIconUrl.last().value(0).toUrl(), pageTo->iconUrl()); - QCOMPARE(spyIcon.last().value(0).value<QIcon>(), pageTo->icon()); + QCOMPARE(spyIcon.last().value(0).value<QIcon>().availableSizes(), + pageTo->icon().availableSizes()); } // verify no emits on destroy with the same number of signals in spy |