diff options
author | Peter Varga <pvarga@inf.u-szeged.hu> | 2016-03-22 09:56:00 +0100 |
---|---|---|
committer | Peter Varga <pvarga@inf.u-szeged.hu> | 2016-04-20 08:22:15 +0000 |
commit | ddc4c40e2dcba81d36c9a4c445f1540b90403997 (patch) | |
tree | 1b2ae4c8d5df228ba71a4e404fef4fe6907e4bbe /tests/auto/quick | |
parent | e46e76a8ffbfa87f488cd16f8720db1a5f3eed83 (diff) |
Add QQuickWebEngineFaviconProvider
The new QQuickImageProvider subclass is used to access downloaded icons
from the FaviconManager via the Quick API.
Change-Id: I6a52d3c737b2260cf480167764a931915cd99cab
Task-number: QTBUG-51179
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@theqtcompany.com>
Diffstat (limited to 'tests/auto/quick')
-rw-r--r-- | tests/auto/quick/qmltests/data/favicon-multi-gray.html | 9 | ||||
-rw-r--r-- | tests/auto/quick/qmltests/data/icons/grayicons.ico | bin | 0 -> 22150 bytes | |||
-rw-r--r-- | tests/auto/quick/qmltests/data/tst_favicon.qml | 92 | ||||
-rw-r--r-- | tests/auto/quick/qmltests/data/tst_faviconDownload.qml | 6 | ||||
-rw-r--r-- | tests/auto/quick/qmltests/qmltests.pro | 2 |
5 files changed, 101 insertions, 8 deletions
diff --git a/tests/auto/quick/qmltests/data/favicon-multi-gray.html b/tests/auto/quick/qmltests/data/favicon-multi-gray.html new file mode 100644 index 000000000..d6ac0909f --- /dev/null +++ b/tests/auto/quick/qmltests/data/favicon-multi-gray.html @@ -0,0 +1,9 @@ +<html> + <head> + <title>Gray Multi-sized Favicon Test</title> + <link rel="shortcut icon" href="icons/grayicons.ico" /> + </head> + <body> + <h1>Gray Multi-sized Favicon Test</h1> + </body> +</html> diff --git a/tests/auto/quick/qmltests/data/icons/grayicons.ico b/tests/auto/quick/qmltests/data/icons/grayicons.ico Binary files differnew file mode 100644 index 000000000..8d8fee839 --- /dev/null +++ b/tests/auto/quick/qmltests/data/icons/grayicons.ico diff --git a/tests/auto/quick/qmltests/data/tst_favicon.qml b/tests/auto/quick/qmltests/data/tst_favicon.qml index 26e39f48c..e959f19be 100644 --- a/tests/auto/quick/qmltests/data/tst_favicon.qml +++ b/tests/auto/quick/qmltests/data/tst_favicon.qml @@ -50,6 +50,10 @@ TestWebEngineView { } } + function removeFaviconProviderPrefix(url) { + return url.toString().substring(16) + } + SignalSpy { id: iconChangedSpy target: webEngineView @@ -64,6 +68,7 @@ TestWebEngineView { TestCase { id: test name: "WebEngineFavicon" + when: windowShown function init() { if (webEngineView.icon != '') { @@ -185,7 +190,7 @@ TestWebEngineView { iconChangedSpy.wait() compare(iconChangedSpy.count, 1) - iconUrl = webEngineView.icon + iconUrl = removeFaviconProviderPrefix(webEngineView.icon) // Touch icon is ignored compare(iconUrl, Qt.resolvedUrl("icons/qt32.ico")) compare(favicon.width, 32) @@ -199,13 +204,13 @@ TestWebEngineView { iconChangedSpy.wait() verify(iconChangedSpy.count >= 1) - iconUrl = webEngineView.icon + 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 = webEngineView.icon + iconUrl = removeFaviconProviderPrefix(webEngineView.icon) } compare(iconUrl, Qt.resolvedUrl("icons/qt144.png")) @@ -224,6 +229,21 @@ TestWebEngineView { var iconUrl = webEngineView.icon compare(iconUrl, Qt.resolvedUrl("")) + compare(favicon.width, 0) + compare(favicon.height, 0) + + WebEngine.settings.touchIconsEnabled = true + + url = Qt.resolvedUrl("favicon-touch.html") + webEngineView.url = url + verify(webEngineView.waitForLoadSucceeded()) + + iconChangedSpy.wait() + iconUrl = removeFaviconProviderPrefix(webEngineView.icon) + compare(iconUrl, Qt.resolvedUrl("icons/qt144.png")) + compare(iconChangedSpy.count, 1) + compare(favicon.width, 144) + compare(favicon.height, 144) } function test_multiIcon() { @@ -235,11 +255,69 @@ TestWebEngineView { iconChangedSpy.wait() compare(iconChangedSpy.count, 1) + compare(favicon.width, 64) + compare(favicon.height, 64) + } - // Image QML type does not support multi-sized icons thus - // chooses the first size - compare(favicon.width, 16) - compare(favicon.height, 16) + function test_faviconProvider_data() { + return [ + { tag: "8x8", size: 8, value: 16 }, + { tag: "16x16", size: 16, value: 16 }, + { tag: "17x17", size: 17, value: 32 }, + { tag: "31x31", size: 31, value: 32 }, + { tag: "32x32", size: 32, value: 32 }, + { tag: "33x33", size: 33, value: 64 }, + { tag: "64x64", size: 64, value: 64 }, + { tag: "128x128", size: 128, value: 128 }, + { tag: "255x255", size: 255, value: 255 }, + { tag: "256x256", size: 256, value: 255 }, + ]; + } + + function test_faviconProvider(row) { + var faviconImage = Qt.createQmlObject(" + import QtQuick 2.5\n + Image { sourceSize: Qt.size(width, height) }", test) + var grabImage = Qt.createQmlObject(" + import QtQuick 2.5\n + Image { }", test) + var faviconCanvas = Qt.createQmlObject(" + import QtQuick 2.5\n + Canvas { }", test) + + compare(iconChangedSpy.count, 0) + + var url = Qt.resolvedUrl("favicon-multi-gray.html") + webEngineView.url = url + verify(webEngineView.waitForLoadSucceeded()) + + iconChangedSpy.wait() + compare(iconChangedSpy.count, 1) + + faviconImage.width = row.size + faviconImage.height = row.size + faviconImage.source = webEngineView.icon + verify(_waitFor(function() { return faviconImage.status == Image.Ready } )) + + faviconImage.grabToImage(function(result) { + grabImage.source = result.url + }) + verify(_waitFor(function() { return grabImage.status == Image.Ready } )) + + faviconCanvas.width = faviconImage.width + faviconCanvas.height = faviconImage.height + var ctx = faviconCanvas.getContext("2d") + ctx.drawImage(grabImage, 0, 0, grabImage.width, grabImage.height) + + var center = Math.round(row.size/2) + var imageData = ctx.getImageData(center, center, center, center) + var pixel = imageData.data + + compare(pixel[0], row.value) + + faviconImage.destroy() + grabImage.destroy() + faviconCanvas.destroy() } } } diff --git a/tests/auto/quick/qmltests/data/tst_faviconDownload.qml b/tests/auto/quick/qmltests/data/tst_faviconDownload.qml index e4dfb36aa..406dfa3ea 100644 --- a/tests/auto/quick/qmltests/data/tst_faviconDownload.qml +++ b/tests/auto/quick/qmltests/data/tst_faviconDownload.qml @@ -35,6 +35,10 @@ TestWebEngineView { width: 200 height: 400 + function removeFaviconProviderPrefix(url) { + return url.toString().substring(16) + } + SignalSpy { id: iconChangedSpy target: webEngineView @@ -108,7 +112,7 @@ TestWebEngineView { iconChangedSpy.wait() compare(iconChangedSpy.count, 1) - var iconUrl = webEngineView.icon + var iconUrl = removeFaviconProviderPrefix(webEngineView.icon) compare(iconUrl, row.expectedIconUrl) } } diff --git a/tests/auto/quick/qmltests/qmltests.pro b/tests/auto/quick/qmltests/qmltests.pro index 257c1c4f6..af6e14c33 100644 --- a/tests/auto/quick/qmltests/qmltests.pro +++ b/tests/auto/quick/qmltests/qmltests.pro @@ -18,6 +18,7 @@ OTHER_FILES += \ $$PWD/data/favicon2.html \ $$PWD/data/favicon-misc.html \ $$PWD/data/favicon-multi.html \ + $$PWD/data/favicon-multi-gray.html \ $$PWD/data/favicon-single.html \ $$PWD/data/favicon-shortcut.html \ $$PWD/data/favicon-touch.html \ @@ -62,6 +63,7 @@ OTHER_FILES += \ $$PWD/data/tst_webchannel.qml \ $$PWD/data/tst_keyboardModifierMapping.qml \ $$PWD/data/icons/favicon.png \ + $$PWD/data/icons/grayicons.ico \ $$PWD/data/icons/small-favicon.png \ $$PWD/data/icons/qt144.png \ $$PWD/data/icons/qt32.ico \ |