summaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorPeter Varga <pvarga@inf.u-szeged.hu>2015-12-01 10:50:02 +0100
committerPeter Varga <pvarga@inf.u-szeged.hu>2016-02-03 16:21:12 +0000
commit41d69eb0fa2375f0da6ba9b35136f5598be4b3a4 (patch)
tree3c754447cf5d1c854eb1bc7fdbe3d6777fcdac0c /tests/auto
parent4713387c052d54e0f5ea02efaeaa25931d1cd7ee (diff)
Add FaviconManager to core
The new icon manager uses the WebContents::DownloadImage() API for downloading icons. It proposes the best quality among the available favicons via the iconChanged signal. Change-Id: I66a014365b6f6560ff34d40ee870aee84e4e70e4 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@theqtcompany.com>
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/core/qwebengineurlrequestinterceptor/tst_qwebengineurlrequestinterceptor.cpp3
-rw-r--r--tests/auto/quick/qmltests/data/favicon-misc.html11
-rw-r--r--tests/auto/quick/qmltests/data/favicon-shortcut.html10
-rw-r--r--tests/auto/quick/qmltests/data/favicon-single.html9
-rw-r--r--tests/auto/quick/qmltests/data/favicon-touch.html10
-rw-r--r--tests/auto/quick/qmltests/data/favicon-unavailable.html9
-rw-r--r--tests/auto/quick/qmltests/data/favicon.html4
-rw-r--r--tests/auto/quick/qmltests/data/favicon2.html4
-rw-r--r--tests/auto/quick/qmltests/data/icons/favicon.png (renamed from tests/auto/quick/qmltests/data/favicon.png)bin3961 -> 3961 bytes
-rw-r--r--tests/auto/quick/qmltests/data/icons/qt144.pngbin0 -> 8315 bytes
-rw-r--r--tests/auto/quick/qmltests/data/icons/qt32.icobin0 -> 4286 bytes
-rw-r--r--tests/auto/quick/qmltests/data/icons/small-favicon.png (renamed from tests/auto/quick/qmltests/data/small-favicon.png)bin891 -> 891 bytes
-rw-r--r--tests/auto/quick/qmltests/data/tst_favicon.qml166
-rw-r--r--tests/auto/quick/qmltests/data/tst_faviconImage.qml (renamed from tests/auto/quick/qmltests/data/tst_favIconLoad.qml)81
-rw-r--r--tests/auto/quick/qmltests/qmltests.pro13
-rw-r--r--tests/auto/widgets/qwebenginefaviconmanager/qwebenginefaviconmanager.pro2
-rw-r--r--tests/auto/widgets/qwebenginefaviconmanager/resources/favicon-misc.html11
-rw-r--r--tests/auto/widgets/qwebenginefaviconmanager/resources/favicon-shortcut.html10
-rw-r--r--tests/auto/widgets/qwebenginefaviconmanager/resources/favicon-single.html9
-rw-r--r--tests/auto/widgets/qwebenginefaviconmanager/resources/favicon-touch.html10
-rw-r--r--tests/auto/widgets/qwebenginefaviconmanager/resources/favicon-unavailable.html9
-rw-r--r--tests/auto/widgets/qwebenginefaviconmanager/resources/icons/qt144.pngbin0 -> 8315 bytes
-rw-r--r--tests/auto/widgets/qwebenginefaviconmanager/resources/icons/qt32.icobin0 -> 4286 bytes
-rw-r--r--tests/auto/widgets/qwebenginefaviconmanager/resources/test1.html1
-rw-r--r--tests/auto/widgets/qwebenginefaviconmanager/tst_qwebenginefaviconmanager.cpp279
-rw-r--r--tests/auto/widgets/qwebenginefaviconmanager/tst_qwebenginefaviconmanager.qrc12
-rw-r--r--tests/auto/widgets/widgets.pro1
27 files changed, 634 insertions, 30 deletions
diff --git a/tests/auto/core/qwebengineurlrequestinterceptor/tst_qwebengineurlrequestinterceptor.cpp b/tests/auto/core/qwebengineurlrequestinterceptor/tst_qwebengineurlrequestinterceptor.cpp
index a65ffb868..180953ed4 100644
--- a/tests/auto/core/qwebengineurlrequestinterceptor/tst_qwebengineurlrequestinterceptor.cpp
+++ b/tests/auto/core/qwebengineurlrequestinterceptor/tst_qwebengineurlrequestinterceptor.cpp
@@ -150,6 +150,9 @@ public:
void interceptRequest(QWebEngineUrlRequestInfo &info) override
{
+ if (info.resourceType() == QWebEngineUrlRequestInfo::ResourceTypeFavicon)
+ return;
+
requestedUrls.append(info.requestUrl());
info.redirect(QUrl("data:text/html,<p>hello"));
}
diff --git a/tests/auto/quick/qmltests/data/favicon-misc.html b/tests/auto/quick/qmltests/data/favicon-misc.html
new file mode 100644
index 000000000..9e788bdf4
--- /dev/null
+++ b/tests/auto/quick/qmltests/data/favicon-misc.html
@@ -0,0 +1,11 @@
+<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/unavailable.ico" />
+ </head>
+ <body>
+ <h1>Favicon Test</h1>
+ </body>
+</html>
diff --git a/tests/auto/quick/qmltests/data/favicon-shortcut.html b/tests/auto/quick/qmltests/data/favicon-shortcut.html
new file mode 100644
index 000000000..786cdb816
--- /dev/null
+++ b/tests/auto/quick/qmltests/data/favicon-shortcut.html
@@ -0,0 +1,10 @@
+<html>
+ <head>
+ <title>Favicon Test</title>
+ <link rel="shortcut icon" href="icons/qt32.ico" />
+ <link rel="shortcut icon" href="icons/qt144.png" />
+ </head>
+ <body>
+ <h1>Favicon Test</h1>
+ </body>
+</html>
diff --git a/tests/auto/quick/qmltests/data/favicon-single.html b/tests/auto/quick/qmltests/data/favicon-single.html
new file mode 100644
index 000000000..eb4675c75
--- /dev/null
+++ b/tests/auto/quick/qmltests/data/favicon-single.html
@@ -0,0 +1,9 @@
+<html>
+ <head>
+ <title>Favicon Test</title>
+ <link rel="shortcut icon" href="icons/qt32.ico" />
+ </head>
+ <body>
+ <h1>Favicon Test</h1>
+ </body>
+</html>
diff --git a/tests/auto/quick/qmltests/data/favicon-touch.html b/tests/auto/quick/qmltests/data/favicon-touch.html
new file mode 100644
index 000000000..271783434
--- /dev/null
+++ b/tests/auto/quick/qmltests/data/favicon-touch.html
@@ -0,0 +1,10 @@
+<html>
+ <head>
+ <title>Favicon Test</title>
+ <link rel="apple-touch-icon" href="icons/qt32.ico" />
+ <link rel="apple-touch-icon" href="icons/qt144.png" />
+ </head>
+ <body>
+ <h1>Favicon Test</h1>
+ </body>
+</html>
diff --git a/tests/auto/quick/qmltests/data/favicon-unavailable.html b/tests/auto/quick/qmltests/data/favicon-unavailable.html
new file mode 100644
index 000000000..c45664294
--- /dev/null
+++ b/tests/auto/quick/qmltests/data/favicon-unavailable.html
@@ -0,0 +1,9 @@
+<html>
+ <head>
+ <title>Favicon Test</title>
+ <link rel="shortcut icon" href="icons/unavailable.ico" />
+ </head>
+ <body>
+ <h1>Favicon Test</h1>
+ </body>
+</html>
diff --git a/tests/auto/quick/qmltests/data/favicon.html b/tests/auto/quick/qmltests/data/favicon.html
index c9f225c52..9823fa323 100644
--- a/tests/auto/quick/qmltests/data/favicon.html
+++ b/tests/auto/quick/qmltests/data/favicon.html
@@ -1,10 +1,10 @@
<html>
<head>
</head>
-<link type="image/png" href="favicon.png" sizes="48x48" rel="icon" />
+<link type="image/png" href="icons/favicon.png" sizes="48x48" rel="icon" />
<body>
<p>It's expected that you see a favicon displayed for this page when you open it as a local file.</p>
<p>The favicon looks like this:</p>
-<img src="favicon.png"/>
+<img src="icons/favicon.png"/>
</body>
</html>
diff --git a/tests/auto/quick/qmltests/data/favicon2.html b/tests/auto/quick/qmltests/data/favicon2.html
index 5548b867f..81c2690fe 100644
--- a/tests/auto/quick/qmltests/data/favicon2.html
+++ b/tests/auto/quick/qmltests/data/favicon2.html
@@ -1,10 +1,10 @@
<html>
<head>
</head>
-<link type="image/png" href="small-favicon.png" sizes="16x16" rel="icon" />
+<link type="image/png" href="icons/small-favicon.png" sizes="16x16" rel="icon" />
<body>
<p>It's expected that you see a favicon displayed for this page when you open it as a local file.</p>
<p>The favicon looks like this:</p>
-<img src="small-favicon.png"/>
+<img src="icons/small-favicon.png"/>
</body>
</html>
diff --git a/tests/auto/quick/qmltests/data/favicon.png b/tests/auto/quick/qmltests/data/icons/favicon.png
index 35717cca5..35717cca5 100644
--- a/tests/auto/quick/qmltests/data/favicon.png
+++ b/tests/auto/quick/qmltests/data/icons/favicon.png
Binary files differ
diff --git a/tests/auto/quick/qmltests/data/icons/qt144.png b/tests/auto/quick/qmltests/data/icons/qt144.png
new file mode 100644
index 000000000..050b1e066
--- /dev/null
+++ b/tests/auto/quick/qmltests/data/icons/qt144.png
Binary files differ
diff --git a/tests/auto/quick/qmltests/data/icons/qt32.ico b/tests/auto/quick/qmltests/data/icons/qt32.ico
new file mode 100644
index 000000000..2f6fcb5bc
--- /dev/null
+++ b/tests/auto/quick/qmltests/data/icons/qt32.ico
Binary files differ
diff --git a/tests/auto/quick/qmltests/data/small-favicon.png b/tests/auto/quick/qmltests/data/icons/small-favicon.png
index 4462752a5..4462752a5 100644
--- a/tests/auto/quick/qmltests/data/small-favicon.png
+++ b/tests/auto/quick/qmltests/data/icons/small-favicon.png
Binary files differ
diff --git a/tests/auto/quick/qmltests/data/tst_favicon.qml b/tests/auto/quick/qmltests/data/tst_favicon.qml
new file mode 100644
index 000000000..fab2e9755
--- /dev/null
+++ b/tests/auto/quick/qmltests/data/tst_favicon.qml
@@ -0,0 +1,166 @@
+/****************************************************************************
+**
+** 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 QtWebEngine.testsupport 1.0
+
+TestWebEngineView {
+ id: webEngineView
+ width: 200
+ height: 400
+
+ testSupport: WebEngineTestSupport {
+ property var errorPageLoadStatus: null
+
+ function waitForErrorPageLoadSucceeded() {
+ var success = _waitFor(function() { return testSupport.errorPageLoadStatus == WebEngineView.LoadSucceededStatus })
+ testSupport.errorPageLoadStatus = null
+ return success
+ }
+
+ errorPage.onLoadingChanged: {
+ errorPageLoadStatus = loadRequest.status
+ }
+ }
+
+ SignalSpy {
+ id: iconChangedSpy
+ target: webEngineView
+ signalName: "iconChanged"
+ }
+
+ TestCase {
+ id: test
+ name: "WebEngineFavicon"
+ when: windowShown
+
+ function init() {
+ 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 test_noFavicon() {
+ compare(iconChangedSpy.count, 0)
+
+ var url = Qt.resolvedUrl("test1.html")
+ webEngineView.url = url
+ verify(webEngineView.waitForLoadSucceeded())
+
+ iconChangedSpy.wait()
+ compare(iconChangedSpy.count, 1)
+
+ var iconUrl = webEngineView.icon
+ compare(iconUrl, Qt.resolvedUrl(""))
+ }
+
+ function test_aboutBlank() {
+ compare(iconChangedSpy.count, 0)
+
+ var url = Qt.resolvedUrl("about:blank")
+ webEngineView.url = url
+ verify(webEngineView.waitForLoadSucceeded())
+
+ iconChangedSpy.wait()
+ compare(iconChangedSpy.count, 1)
+
+ var iconUrl = webEngineView.icon
+ compare(iconUrl, Qt.resolvedUrl(""))
+ }
+
+ function test_unavailableFavicon() {
+ compare(iconChangedSpy.count, 0)
+
+ var url = Qt.resolvedUrl("favicon-unavailable.html")
+ webEngineView.url = url
+ verify(webEngineView.waitForLoadSucceeded())
+
+ iconChangedSpy.wait()
+ compare(iconChangedSpy.count, 1)
+
+ var iconUrl = webEngineView.icon
+ compare(iconUrl, Qt.resolvedUrl("icons/unavailable.ico"))
+ }
+
+ function test_errorPageEnabled() {
+ skip("Error page does not work properly: QTBUG-48995")
+ WebEngine.settings.errorPageEnabled = true
+
+ compare(iconChangedSpy.count, 0)
+
+ var url = Qt.resolvedUrl("http://non.existent/url")
+ webEngineView.url = url
+ verify(webEngineView.testSupport.waitForErrorPageLoadSucceeded())
+
+ iconChangedSpy.wait()
+ // Icon is reseted at load start.
+ // Load is started twice: once for unavailale page then error page
+ compare(iconChangedSpy.count, 2)
+
+ var iconUrl = webEngineView.icon
+ compare(iconUrl, Qt.resolvedUrl(""))
+ }
+
+ function test_errorPageDisabled() {
+ WebEngine.settings.errorPageEnabled = false
+
+ compare(iconChangedSpy.count, 0)
+
+ var url = Qt.resolvedUrl("http://non.existent/url")
+ webEngineView.url = url
+ verify(webEngineView.waitForLoadFailed())
+
+ iconChangedSpy.wait()
+ compare(iconChangedSpy.count, 1)
+
+ var iconUrl = webEngineView.icon
+ compare(iconUrl, Qt.resolvedUrl(""))
+ }
+
+ function test_touchIcon() {
+ compare(iconChangedSpy.count, 0)
+
+ var url = Qt.resolvedUrl("favicon-touch.html")
+ webEngineView.url = url
+ verify(webEngineView.waitForLoadSucceeded())
+
+ iconChangedSpy.wait()
+ compare(iconChangedSpy.count, 1)
+
+ var iconUrl = webEngineView.icon
+ compare(iconUrl, Qt.resolvedUrl(""))
+ }
+ }
+}
diff --git a/tests/auto/quick/qmltests/data/tst_favIconLoad.qml b/tests/auto/quick/qmltests/data/tst_faviconImage.qml
index 2527cc740..603f76954 100644
--- a/tests/auto/quick/qmltests/data/tst_favIconLoad.qml
+++ b/tests/auto/quick/qmltests/data/tst_faviconImage.qml
@@ -28,7 +28,7 @@
import QtQuick 2.0
import QtTest 1.0
-import QtWebEngine 1.2
+import QtWebEngine 1.3
TestWebEngineView {
id: webEngineView
@@ -36,25 +36,19 @@ TestWebEngineView {
height: 400
SignalSpy {
- id: spy
+ id: iconChangedSpy
target: webEngineView
signalName: "iconChanged"
}
- // FIXME: This test is flaky if the loading of the icon image is asynchronous,
- // because the iconChanged signal is emitted before the image has been downloaded.
- // We can set this property to true after we have some kind of favicon downloading
- // logic in the WebEngine.
-
Image {
- id: favicon
- asynchronous: false
+ id: faviconImage
source: webEngineView.icon
}
TestCase {
id: test
- name: "WebEngineViewLoadFavIcon"
+ name: "WebEngineFaviconImage"
when: windowShown
function init() {
@@ -62,31 +56,70 @@ TestWebEngineView {
// 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())
- spy.wait()
+ iconChangedSpy.wait()
}
- spy.clear()
+
+ iconChangedSpy.clear()
}
- function test_favIconLoad() {
- compare(spy.count, 0)
+ function test_faviconImageLoad() {
+ compare(iconChangedSpy.count, 0)
+
var url = Qt.resolvedUrl("favicon.html")
webEngineView.url = url
verify(webEngineView.waitForLoadSucceeded())
- spy.wait()
- compare(spy.count, 1)
- compare(favicon.width, 48)
- compare(favicon.height, 48)
+
+ iconChangedSpy.wait()
+ compare(iconChangedSpy.count, 1)
+
+ compare(faviconImage.width, 48)
+ compare(faviconImage.height, 48)
}
- function test_favIconLoadEncodedUrl() {
- compare(spy.count, 0)
+ function test_faviconImageLoadEncodedUrl() {
+ compare(iconChangedSpy.count, 0)
+
var url = Qt.resolvedUrl("favicon2.html?favicon=load should work with#whitespace!")
webEngineView.url = url
verify(webEngineView.waitForLoadSucceeded())
- spy.wait()
- compare(spy.count, 1)
- compare(favicon.width, 16)
- compare(favicon.height, 16)
+
+ iconChangedSpy.wait()
+ compare(iconChangedSpy.count, 1)
+
+ compare(faviconImage.width, 16)
+ compare(faviconImage.height, 16)
+ }
+
+ function test_bestFaviconImage() {
+ compare(iconChangedSpy.count, 0)
+ var url, iconUrl
+
+ url = Qt.resolvedUrl("favicon-misc.html")
+ webEngineView.url = url
+ verify(webEngineView.waitForLoadSucceeded())
+
+ iconChangedSpy.wait()
+ compare(iconChangedSpy.count, 1)
+
+ iconUrl = webEngineView.icon
+ // Touch icon is ignored
+ compare(iconUrl, Qt.resolvedUrl("icons/qt32.ico"))
+ compare(faviconImage.width, 32)
+ compare(faviconImage.height, 32)
+
+ iconChangedSpy.clear()
+
+ url = Qt.resolvedUrl("favicon-shortcut.html")
+ webEngineView.url = url
+ verify(webEngineView.waitForLoadSucceeded())
+
+ iconChangedSpy.wait()
+ compare(iconChangedSpy.count, 1)
+
+ iconUrl = webEngineView.icon
+ compare(iconUrl, Qt.resolvedUrl("icons/qt144.png"))
+ compare(faviconImage.width, 144)
+ compare(faviconImage.height, 144)
}
}
}
diff --git a/tests/auto/quick/qmltests/qmltests.pro b/tests/auto/quick/qmltests/qmltests.pro
index 57649384d..d1849d020 100644
--- a/tests/auto/quick/qmltests/qmltests.pro
+++ b/tests/auto/quick/qmltests/qmltests.pro
@@ -15,8 +15,12 @@ OTHER_FILES += \
$$PWD/data/confirmclose.html \
$$PWD/data/directoryupload.html \
$$PWD/data/favicon.html \
- $$PWD/data/favicon.png \
$$PWD/data/favicon2.html \
+ $$PWD/data/favicon-misc.html \
+ $$PWD/data/favicon-single.html \
+ $$PWD/data/favicon-shortcut.html \
+ $$PWD/data/favicon-touch.html \
+ $$PWD/data/favicon-unavailable.html \
$$PWD/data/forms.html \
$$PWD/data/geolocation.html \
$$PWD/data/javascript.html \
@@ -34,7 +38,8 @@ OTHER_FILES += \
$$PWD/data/titleupdate.js \
$$PWD/data/tst_desktopBehaviorLoadHtml.qml \
$$PWD/data/tst_download.qml \
- $$PWD/data/tst_favIconLoad.qml \
+ $$PWD/data/tst_favicon.qml \
+ $$PWD/data/tst_faviconImage.qml \
$$PWD/data/tst_filePicker.qml \
$$PWD/data/tst_formValidation.qml \
$$PWD/data/tst_geopermission.qml \
@@ -55,6 +60,10 @@ OTHER_FILES += \
$$PWD/data/tst_userScripts.qml \
$$PWD/data/tst_webchannel.qml \
$$PWD/data/tst_keyboardModifierMapping.qml \
+ $$PWD/data/icons/favicon.png \
+ $$PWD/data/icons/small-favicon.png \
+ $$PWD/data/icons/qt144.png \
+ $$PWD/data/icons/qt32.ico \
$$PWD/mock-delegates/QtWebEngine/UIDelegates/AlertDialog.qml \
$$PWD/mock-delegates/QtWebEngine/UIDelegates/ConfirmDialog.qml \
$$PWD/mock-delegates/QtWebEngine/UIDelegates/FilePicker.qml \
diff --git a/tests/auto/widgets/qwebenginefaviconmanager/qwebenginefaviconmanager.pro b/tests/auto/widgets/qwebenginefaviconmanager/qwebenginefaviconmanager.pro
new file mode 100644
index 000000000..70786e70f
--- /dev/null
+++ b/tests/auto/widgets/qwebenginefaviconmanager/qwebenginefaviconmanager.pro
@@ -0,0 +1,2 @@
+include(../tests.pri)
+QT *= core-private gui-private
diff --git a/tests/auto/widgets/qwebenginefaviconmanager/resources/favicon-misc.html b/tests/auto/widgets/qwebenginefaviconmanager/resources/favicon-misc.html
new file mode 100644
index 000000000..9e788bdf4
--- /dev/null
+++ b/tests/auto/widgets/qwebenginefaviconmanager/resources/favicon-misc.html
@@ -0,0 +1,11 @@
+<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/unavailable.ico" />
+ </head>
+ <body>
+ <h1>Favicon Test</h1>
+ </body>
+</html>
diff --git a/tests/auto/widgets/qwebenginefaviconmanager/resources/favicon-shortcut.html b/tests/auto/widgets/qwebenginefaviconmanager/resources/favicon-shortcut.html
new file mode 100644
index 000000000..786cdb816
--- /dev/null
+++ b/tests/auto/widgets/qwebenginefaviconmanager/resources/favicon-shortcut.html
@@ -0,0 +1,10 @@
+<html>
+ <head>
+ <title>Favicon Test</title>
+ <link rel="shortcut icon" href="icons/qt32.ico" />
+ <link rel="shortcut icon" href="icons/qt144.png" />
+ </head>
+ <body>
+ <h1>Favicon Test</h1>
+ </body>
+</html>
diff --git a/tests/auto/widgets/qwebenginefaviconmanager/resources/favicon-single.html b/tests/auto/widgets/qwebenginefaviconmanager/resources/favicon-single.html
new file mode 100644
index 000000000..eb4675c75
--- /dev/null
+++ b/tests/auto/widgets/qwebenginefaviconmanager/resources/favicon-single.html
@@ -0,0 +1,9 @@
+<html>
+ <head>
+ <title>Favicon Test</title>
+ <link rel="shortcut icon" href="icons/qt32.ico" />
+ </head>
+ <body>
+ <h1>Favicon Test</h1>
+ </body>
+</html>
diff --git a/tests/auto/widgets/qwebenginefaviconmanager/resources/favicon-touch.html b/tests/auto/widgets/qwebenginefaviconmanager/resources/favicon-touch.html
new file mode 100644
index 000000000..271783434
--- /dev/null
+++ b/tests/auto/widgets/qwebenginefaviconmanager/resources/favicon-touch.html
@@ -0,0 +1,10 @@
+<html>
+ <head>
+ <title>Favicon Test</title>
+ <link rel="apple-touch-icon" href="icons/qt32.ico" />
+ <link rel="apple-touch-icon" href="icons/qt144.png" />
+ </head>
+ <body>
+ <h1>Favicon Test</h1>
+ </body>
+</html>
diff --git a/tests/auto/widgets/qwebenginefaviconmanager/resources/favicon-unavailable.html b/tests/auto/widgets/qwebenginefaviconmanager/resources/favicon-unavailable.html
new file mode 100644
index 000000000..c45664294
--- /dev/null
+++ b/tests/auto/widgets/qwebenginefaviconmanager/resources/favicon-unavailable.html
@@ -0,0 +1,9 @@
+<html>
+ <head>
+ <title>Favicon Test</title>
+ <link rel="shortcut icon" href="icons/unavailable.ico" />
+ </head>
+ <body>
+ <h1>Favicon Test</h1>
+ </body>
+</html>
diff --git a/tests/auto/widgets/qwebenginefaviconmanager/resources/icons/qt144.png b/tests/auto/widgets/qwebenginefaviconmanager/resources/icons/qt144.png
new file mode 100644
index 000000000..050b1e066
--- /dev/null
+++ b/tests/auto/widgets/qwebenginefaviconmanager/resources/icons/qt144.png
Binary files differ
diff --git a/tests/auto/widgets/qwebenginefaviconmanager/resources/icons/qt32.ico b/tests/auto/widgets/qwebenginefaviconmanager/resources/icons/qt32.ico
new file mode 100644
index 000000000..2f6fcb5bc
--- /dev/null
+++ b/tests/auto/widgets/qwebenginefaviconmanager/resources/icons/qt32.ico
Binary files differ
diff --git a/tests/auto/widgets/qwebenginefaviconmanager/resources/test1.html b/tests/auto/widgets/qwebenginefaviconmanager/resources/test1.html
new file mode 100644
index 000000000..b323f966e
--- /dev/null
+++ b/tests/auto/widgets/qwebenginefaviconmanager/resources/test1.html
@@ -0,0 +1 @@
+<html><body><p>Some text 1</p></body></html>
diff --git a/tests/auto/widgets/qwebenginefaviconmanager/tst_qwebenginefaviconmanager.cpp b/tests/auto/widgets/qwebenginefaviconmanager/tst_qwebenginefaviconmanager.cpp
new file mode 100644
index 000000000..ececb0efd
--- /dev/null
+++ b/tests/auto/widgets/qwebenginefaviconmanager/tst_qwebenginefaviconmanager.cpp
@@ -0,0 +1,279 @@
+/****************************************************************************
+**
+** 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$
+**
+****************************************************************************/
+
+#include <QtTest/QtTest>
+#include "../util.h"
+
+#include <qwebenginepage.h>
+#include <qwebenginesettings.h>
+#include <qwebengineview.h>
+
+
+class tst_QWebEngineFaviconManager : public QObject {
+ Q_OBJECT
+
+public Q_SLOTS:
+ void init();
+ void initTestCase();
+ void cleanupTestCase();
+ void cleanup();
+
+private Q_SLOTS:
+ void faviconLoad();
+ void faviconLoadFromResources();
+ void faviconLoadEncodedUrl();
+ void noFavicon();
+ void aboutBlank();
+ void unavailableFavicon();
+ void errorPageEnabled();
+ void errorPageDisabled();
+ void bestFavicon();
+ void touchIcon();
+
+private:
+ QWebEngineView* m_view;
+ QWebEnginePage* m_page;
+};
+
+
+void tst_QWebEngineFaviconManager::init()
+{
+ m_view = new QWebEngineView();
+ m_page = m_view->page();
+}
+
+
+void tst_QWebEngineFaviconManager::initTestCase()
+{
+}
+
+void tst_QWebEngineFaviconManager::cleanupTestCase()
+{
+}
+
+
+void tst_QWebEngineFaviconManager::cleanup()
+{
+ delete m_view;
+}
+
+void tst_QWebEngineFaviconManager::faviconLoad()
+{
+ 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);
+
+ QSignalSpy loadFinishedSpy(m_page, SIGNAL(loadFinished(bool)));
+ QSignalSpy iconUrlChangedSpy(m_page, SIGNAL(iconUrlChanged(QUrl)));
+
+ QUrl url = QUrl::fromLocalFile(TESTS_SOURCE_DIR + QLatin1String("qwebenginefaviconmanager/resources/favicon-single.html"));
+ m_page->load(url);
+
+ QTRY_COMPARE(loadFinishedSpy.count(), 1);
+ QTRY_COMPARE(iconUrlChangedSpy.count(), 1);
+
+ QUrl iconUrl = iconUrlChangedSpy.at(0).at(0).toString();
+ QCOMPARE(iconUrl, QUrl::fromLocalFile(TESTS_SOURCE_DIR + QLatin1String("qwebenginefaviconmanager/resources/icons/qt32.ico")));
+}
+
+void tst_QWebEngineFaviconManager::faviconLoadFromResources()
+{
+ QSignalSpy loadFinishedSpy(m_page, SIGNAL(loadFinished(bool)));
+ QSignalSpy iconUrlChangedSpy(m_page, SIGNAL(iconUrlChanged(QUrl)));
+
+ QUrl url = QUrl("qrc:/resources/favicon-single.html");
+ m_page->load(url);
+
+ QTRY_COMPARE(loadFinishedSpy.count(), 1);
+ QTRY_COMPARE(iconUrlChangedSpy.count(), 1);
+
+ QUrl iconUrl = iconUrlChangedSpy.at(0).at(0).toString();
+ QCOMPARE(iconUrl, QUrl("qrc:/resources/icons/qt32.ico"));
+}
+
+void tst_QWebEngineFaviconManager::faviconLoadEncodedUrl()
+{
+ 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);
+
+ QSignalSpy loadFinishedSpy(m_page, SIGNAL(loadFinished(bool)));
+ QSignalSpy iconUrlChangedSpy(m_page, SIGNAL(iconUrlChanged(QUrl)));
+
+ QString urlString = QUrl::fromLocalFile(TESTS_SOURCE_DIR + QLatin1String("qwebenginefaviconmanager/resources/favicon-single.html")).toString();
+ QUrl url = QUrl(urlString + QLatin1String("?favicon=load should work with#whitespace!"));
+ m_page->load(url);
+
+ QTRY_COMPARE(loadFinishedSpy.count(), 1);
+ QTRY_COMPARE(iconUrlChangedSpy.count(), 1);
+
+ QUrl iconUrl = iconUrlChangedSpy.at(0).at(0).toString();
+ QCOMPARE(iconUrl, QUrl::fromLocalFile(TESTS_SOURCE_DIR + QLatin1String("qwebenginefaviconmanager/resources/icons/qt32.ico")));
+}
+
+void tst_QWebEngineFaviconManager::noFavicon()
+{
+ 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);
+
+ QSignalSpy loadFinishedSpy(m_page, SIGNAL(loadFinished(bool)));
+ QSignalSpy iconUrlChangedSpy(m_page, SIGNAL(iconUrlChanged(QUrl)));
+
+ QUrl url = QUrl::fromLocalFile(TESTS_SOURCE_DIR + QLatin1String("qwebenginefaviconmanager/resources/test1.html"));
+ m_page->load(url);
+
+ QTRY_COMPARE(loadFinishedSpy.count(), 1);
+ QTRY_COMPARE(iconUrlChangedSpy.count(), 1);
+
+ QUrl iconUrl = iconUrlChangedSpy.at(0).at(0).toString();
+ QVERIFY(iconUrl.isEmpty());
+}
+
+void tst_QWebEngineFaviconManager::aboutBlank()
+{
+ QSignalSpy loadFinishedSpy(m_page, SIGNAL(loadFinished(bool)));
+ QSignalSpy iconUrlChangedSpy(m_page, SIGNAL(iconUrlChanged(QUrl)));
+
+ QUrl url = QUrl("about:blank");
+ m_page->load(url);
+
+ QTRY_COMPARE(loadFinishedSpy.count(), 1);
+ QTRY_COMPARE(iconUrlChangedSpy.count(), 1);
+
+ QUrl iconUrl = iconUrlChangedSpy.at(0).at(0).toString();
+ QVERIFY(iconUrl.isEmpty());
+}
+
+void tst_QWebEngineFaviconManager::unavailableFavicon()
+{
+ 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);
+
+ QSignalSpy loadFinishedSpy(m_page, SIGNAL(loadFinished(bool)));
+ QSignalSpy iconUrlChangedSpy(m_page, SIGNAL(iconUrlChanged(QUrl)));
+
+ QUrl url = QUrl::fromLocalFile(TESTS_SOURCE_DIR + QLatin1String("qwebenginefaviconmanager/resources/favicon-unavailable.html"));
+ m_page->load(url);
+
+ QTRY_COMPARE(loadFinishedSpy.count(), 1);
+ QTRY_COMPARE(iconUrlChangedSpy.count(), 1);
+
+ QUrl iconUrl = iconUrlChangedSpy.at(0).at(0).toString();
+ QCOMPARE(iconUrl, QUrl::fromLocalFile(TESTS_SOURCE_DIR + QLatin1String("qwebenginefaviconmanager/resources/icons/unavailable.ico")));
+}
+
+void tst_QWebEngineFaviconManager::errorPageEnabled()
+{
+ m_page->settings()->setAttribute(QWebEngineSettings::ErrorPageEnabled, true);
+
+ QSignalSpy loadFinishedSpy(m_page, SIGNAL(loadFinished(bool)));
+ QSignalSpy iconUrlChangedSpy(m_page, SIGNAL(iconUrlChanged(QUrl)));
+
+ QUrl url = QUrl(QUrl("http://non.existent/url"));
+ m_page->load(url);
+
+ QTRY_COMPARE(loadFinishedSpy.count(), 1);
+ // Icon is reseted at load start.
+ // Load is started twice: once for unavailale page then error page
+ QTRY_COMPARE(iconUrlChangedSpy.count(), 2);
+
+ QUrl iconUrl;
+ iconUrl = iconUrlChangedSpy.at(0).at(0).toString();
+ QVERIFY(iconUrl.isEmpty());
+ iconUrl = iconUrlChangedSpy.at(1).at(0).toString();
+ QVERIFY(iconUrl.isEmpty());
+}
+
+void tst_QWebEngineFaviconManager::errorPageDisabled()
+{
+ m_page->settings()->setAttribute(QWebEngineSettings::ErrorPageEnabled, false);
+
+ QSignalSpy loadFinishedSpy(m_page, SIGNAL(loadFinished(bool)));
+ QSignalSpy iconUrlChangedSpy(m_page, SIGNAL(iconUrlChanged(QUrl)));
+
+ QUrl url = QUrl(QUrl("http://non.existent/url"));
+ m_page->load(url);
+
+ QTRY_COMPARE(loadFinishedSpy.count(), 1);
+ QTRY_COMPARE(iconUrlChangedSpy.count(), 1);
+
+ QUrl iconUrl = iconUrlChangedSpy.at(0).at(0).toString();
+ QVERIFY(iconUrl.isEmpty());
+}
+
+void tst_QWebEngineFaviconManager::bestFavicon()
+{
+ 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);
+
+ QSignalSpy loadFinishedSpy(m_page, SIGNAL(loadFinished(bool)));
+ QSignalSpy iconUrlChangedSpy(m_page, SIGNAL(iconUrlChanged(QUrl)));
+ QUrl url, iconUrl;
+
+ url = QUrl::fromLocalFile(TESTS_SOURCE_DIR + QLatin1String("qwebenginefaviconmanager/resources/favicon-misc.html"));
+ m_page->load(url);
+
+ QTRY_COMPARE(loadFinishedSpy.count(), 1);
+ QTRY_COMPARE(iconUrlChangedSpy.count(), 1);
+
+ iconUrl = iconUrlChangedSpy.at(0).at(0).toString();
+ // Touch icon is ignored
+ QCOMPARE(iconUrl, QUrl::fromLocalFile(TESTS_SOURCE_DIR + QLatin1String("qwebenginefaviconmanager/resources/icons/qt32.ico")));
+
+ loadFinishedSpy.clear();
+ iconUrlChangedSpy.clear();
+
+ url = QUrl::fromLocalFile(TESTS_SOURCE_DIR + QLatin1String("qwebenginefaviconmanager/resources/favicon-shortcut.html"));
+ m_page->load(url);
+
+ QTRY_COMPARE(loadFinishedSpy.count(), 1);
+ QTRY_COMPARE(iconUrlChangedSpy.count(), 1);
+
+ iconUrl = iconUrlChangedSpy.at(0).at(0).toString();
+ QCOMPARE(iconUrl, QUrl::fromLocalFile(TESTS_SOURCE_DIR + QLatin1String("qwebenginefaviconmanager/resources/icons/qt144.png")));
+}
+
+void tst_QWebEngineFaviconManager::touchIcon()
+{
+ 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);
+
+ QSignalSpy loadFinishedSpy(m_page, SIGNAL(loadFinished(bool)));
+ QSignalSpy iconUrlChangedSpy(m_page, SIGNAL(iconUrlChanged(QUrl)));
+
+ QUrl url = QUrl::fromLocalFile(TESTS_SOURCE_DIR + QLatin1String("qwebenginefaviconmanager/resources/favicon-touch.html"));
+ m_page->load(url);
+
+ QTRY_COMPARE(loadFinishedSpy.count(), 1);
+ QTRY_COMPARE(iconUrlChangedSpy.count(), 1);
+
+ QUrl iconUrl = iconUrlChangedSpy.at(0).at(0).toString();
+ QVERIFY(iconUrl.isEmpty());
+}
+
+QTEST_MAIN(tst_QWebEngineFaviconManager)
+
+#include "tst_qwebenginefaviconmanager.moc"
diff --git a/tests/auto/widgets/qwebenginefaviconmanager/tst_qwebenginefaviconmanager.qrc b/tests/auto/widgets/qwebenginefaviconmanager/tst_qwebenginefaviconmanager.qrc
new file mode 100644
index 000000000..65d8ed928
--- /dev/null
+++ b/tests/auto/widgets/qwebenginefaviconmanager/tst_qwebenginefaviconmanager.qrc
@@ -0,0 +1,12 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource>
+ <file>resources/favicon-misc.html</file>
+ <file>resources/favicon-shortcut.html</file>
+ <file>resources/favicon-single.html</file>
+ <file>resources/favicon-touch.html</file>
+ <file>resources/favicon-unavailable.html</file>
+ <file>resources/icons/qt144.png</file>
+ <file>resources/icons/qt32.ico</file>
+ <file>resources/test1.html</file>
+</qresource>
+</RCC>
diff --git a/tests/auto/widgets/widgets.pro b/tests/auto/widgets/widgets.pro
index 986d5bbee..c65d7dd6c 100644
--- a/tests/auto/widgets/widgets.pro
+++ b/tests/auto/widgets/widgets.pro
@@ -2,6 +2,7 @@ TEMPLATE = subdirs
SUBDIRS += \
qwebengineaccessibility \
+ qwebenginefaviconmanager \
qwebenginepage \
qwebenginehistory \
qwebenginehistoryinterface \