summaryrefslogtreecommitdiffstats
path: root/tests/auto/quick/qmltests/data
diff options
context:
space:
mode:
authorPeter Varga <pvarga@inf.u-szeged.hu>2021-07-13 17:56:05 +0200
committerPeter Varga <pvarga@inf.u-szeged.hu>2021-07-20 17:06:20 +0200
commit9c663f51c63f7661edcc604ce89171b3f037543d (patch)
tree402291f9e6e6cfccb814dd5a323c4b6de53e7a4a /tests/auto/quick/qmltests/data
parent4a81478a493f337b516af8995e0f41e79f15c33c (diff)
Get rid of Quick's TestSupport API
- Moved TestInputContext and TestInputEvent APIs to tst_qmltests. - Removed loadVisuallyCommitted and use Item.grabToImage to check if page is rendered. - Removed windowCloseRejected signal and use a hidden callback instead. Pick-to: 6.2 Change-Id: Ica6e4c6017426e0171d738a6a59afa557c786698 Reviewed-by: Michal Klocek <michal.klocek@qt.io>
Diffstat (limited to 'tests/auto/quick/qmltests/data')
-rw-r--r--tests/auto/quick/qmltests/data/TestWebEngineView.qml39
-rw-r--r--tests/auto/quick/qmltests/data/test2.html2
-rw-r--r--tests/auto/quick/qmltests/data/tst_favicon.qml35
-rw-r--r--tests/auto/quick/qmltests/data/tst_inputMethod.qml14
-rw-r--r--tests/auto/quick/qmltests/data/tst_javaScriptDialogs.qml30
-rw-r--r--tests/auto/quick/qmltests/data/tst_linkHovered.qml34
-rw-r--r--tests/auto/quick/qmltests/data/tst_mouseClick.qml28
-rw-r--r--tests/auto/quick/qmltests/data/tst_viewSource.qml47
-rw-r--r--tests/auto/quick/qmltests/data/tst_viewSoure.qml120
9 files changed, 135 insertions, 214 deletions
diff --git a/tests/auto/quick/qmltests/data/TestWebEngineView.qml b/tests/auto/quick/qmltests/data/TestWebEngineView.qml
index f82589f7d..aa9d67d99 100644
--- a/tests/auto/quick/qmltests/data/TestWebEngineView.qml
+++ b/tests/auto/quick/qmltests/data/TestWebEngineView.qml
@@ -26,9 +26,9 @@
**
****************************************************************************/
-import QtQuick 2.0
-import QtTest 1.1
-import QtWebEngine 1.7
+import QtQuick
+import QtTest
+import QtWebEngine
WebEngineView {
property var loadStatus: null
@@ -119,5 +119,38 @@ WebEngineView {
testCase.tryVerify(function() { return text !== undefined })
return text
}
+
+ function getItemPixel(item) {
+ var grabImage = Qt.createQmlObject("
+ import QtQuick\n
+ Image { }", testCase)
+ var itemCanvas = Qt.createQmlObject("
+ import QtQuick\n
+ Canvas { }", testCase)
+
+ // Mark QML images with objectName: "image" to be able to check if the image is loaded.
+ if (item.objectName === "image") {
+ testCase.tryVerify(function() { return item.status === Image.Ready });
+ }
+
+ item.grabToImage(function(result) {
+ grabImage.source = result.url
+ });
+ testCase.tryVerify(function() { return grabImage.status === Image.Ready });
+
+ itemCanvas.width = item.width;
+ itemCanvas.height = item.height;
+ var ctx = itemCanvas.getContext("2d");
+ ctx.drawImage(grabImage, 0, 0, grabImage.width, grabImage.height);
+ var imageData = ctx.getImageData(Math.round(itemCanvas.width/2),
+ Math.round(itemCanvas.height/2),
+ itemCanvas.width,
+ itemCanvas.height);
+
+ grabImage.destroy();
+ itemCanvas.destroy();
+
+ return imageData.data;
+ }
}
diff --git a/tests/auto/quick/qmltests/data/test2.html b/tests/auto/quick/qmltests/data/test2.html
index 7a02bf1f2..06b1c40cb 100644
--- a/tests/auto/quick/qmltests/data/test2.html
+++ b/tests/auto/quick/qmltests/data/test2.html
@@ -1,6 +1,6 @@
<html>
<head><title>Test page with huge link area</title></head>
<body>
-<a id="link" title="A title" href="test1.html"><img width=200 height=200></a>
+<a id="link" title="A title" href="test1.html"><div style="width:200px; height:200px; background-color:red"></div></a>
</body>
</html>
diff --git a/tests/auto/quick/qmltests/data/tst_favicon.qml b/tests/auto/quick/qmltests/data/tst_favicon.qml
index 84b3db5e5..79c835c70 100644
--- a/tests/auto/quick/qmltests/data/tst_favicon.qml
+++ b/tests/auto/quick/qmltests/data/tst_favicon.qml
@@ -52,35 +52,6 @@ TestWebEngineView {
return url.toString().substring(16)
}
- function getFaviconPixel(faviconImage) {
- var grabImage = Qt.createQmlObject("
- import QtQuick\n
- Image { }", testCase)
- var faviconCanvas = Qt.createQmlObject("
- import QtQuick\n
- Canvas { }", testCase)
-
- testCase.tryVerify(function() { return faviconImage.status == Image.Ready });
- faviconImage.grabToImage(function(result) {
- grabImage.source = result.url
- });
- testCase.tryVerify(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 imageData = ctx.getImageData(Math.round(faviconCanvas.width/2),
- Math.round(faviconCanvas.height/2),
- faviconCanvas.width,
- faviconCanvas.height);
-
- grabImage.destroy();
- faviconCanvas.destroy();
-
- return imageData.data;
- }
-
SignalSpy {
id: iconChangedSpy
target: webEngineView
@@ -418,7 +389,7 @@ TestWebEngineView {
var faviconImage = Qt.createQmlObject("
import QtQuick\n
- Image { width: 16; height: 16; sourceSize: Qt.size(width, height); }", testCase)
+ Image { width: 16; height: 16; sourceSize: Qt.size(width, height); objectName: 'image' }", testCase)
faviconImage.source = Qt.binding(function() { return webEngineView.icon; });
var colors = [
@@ -437,7 +408,7 @@ TestWebEngineView {
verify(webEngineView.waitForLoadSucceeded());
tryCompare(iconChangedSpy, "count", 1);
- pixel = getFaviconPixel(faviconImage);
+ pixel = getItemPixel(faviconImage);
compare(pixel[0], 0);
compare(pixel[1], 0);
compare(pixel[2], 0);
@@ -448,7 +419,7 @@ TestWebEngineView {
tryCompare(faviconImage, "source", "image://favicon/data:image/png;base64," + colors[i]["url"]);
compare(iconChangedSpy.count, 1);
- pixel = getFaviconPixel(faviconImage);
+ pixel = getItemPixel(faviconImage);
compare(pixel[0], colors[i]["r"]);
compare(pixel[1], colors[i]["g"]);
compare(pixel[2], colors[i]["b"]);
diff --git a/tests/auto/quick/qmltests/data/tst_inputMethod.qml b/tests/auto/quick/qmltests/data/tst_inputMethod.qml
index 00f85cb71..16b7a06d5 100644
--- a/tests/auto/quick/qmltests/data/tst_inputMethod.qml
+++ b/tests/auto/quick/qmltests/data/tst_inputMethod.qml
@@ -26,10 +26,10 @@
**
****************************************************************************/
-import QtQuick 2.0
-import QtTest 1.0
-import QtWebEngine 1.4
-import QtWebEngine.testsupport 1.0
+import QtQuick
+import QtTest
+import QtWebEngine
+import Test.util
import "../../qmltests/data" 1.0
TestWebEngineView {
@@ -37,7 +37,7 @@ TestWebEngineView {
width: 200
height: 400
- testSupport: WebEngineTestSupport { }
+ TestInputContext { id: testInputContext }
TestCase {
id: testCase
@@ -45,11 +45,11 @@ TestWebEngineView {
when: windowShown
function init() {
- testSupport.testInputContext.create();
+ testInputContext.create();
}
function cleanup() {
- testSupport.testInputContext.release();
+ testInputContext.release();
}
function test_softwareInputPanel() {
diff --git a/tests/auto/quick/qmltests/data/tst_javaScriptDialogs.qml b/tests/auto/quick/qmltests/data/tst_javaScriptDialogs.qml
index a521ea0d6..91b57c101 100644
--- a/tests/auto/quick/qmltests/data/tst_javaScriptDialogs.qml
+++ b/tests/auto/quick/qmltests/data/tst_javaScriptDialogs.qml
@@ -26,29 +26,21 @@
**
****************************************************************************/
-import QtQuick 2.0
-import QtTest 1.0
-import QtWebEngine 1.2
-import QtWebEngine.testsupport 1.0
-import "../../qmltests/data" 1.0
-import "../mock-delegates/TestParams" 1.0
+import QtQuick
+import QtTest
+import QtWebEngine
+import "../../qmltests/data"
+import "../mock-delegates/TestParams"
TestWebEngineView {
id: webEngineView
anchors.fill: parent
- testSupport: WebEngineTestSupport {
- property bool windowCloseRejectedSignalEmitted: false
+ property bool windowCloseRejectedCalled: false
- function waitForWindowCloseRejected() {
- return _waitFor(function () {
- return testSupport.windowCloseRejectedSignalEmitted;
- });
- }
-
- onWindowCloseRejected: {
- windowCloseRejectedSignalEmitted = true;
- }
+ // Called by QQuickWebEngineViewPrivate::windowCloseRejected()
+ function windowCloseRejected() {
+ windowCloseRejectedCalled = true;
}
TestCase {
@@ -124,12 +116,12 @@ TestWebEngineView {
function test_rejectClose() {
webEngineView.url = Qt.resolvedUrl("confirmclose.html");
verify(webEngineView.waitForLoadSucceeded());
- webEngineView.testSupport.windowCloseRejectedSignalEmitted = false;
+ webEngineView.windowCloseRejectedCalled = false;
JSDialogParams.shouldAcceptDialog = false;
simulateUserGesture()
webEngineView.triggerWebAction(WebEngineView.RequestClose);
- verify(webEngineView.testSupport.waitForWindowCloseRejected());
+ tryVerify(function() { return webEngineView.windowCloseRejectedCalled; });
// Navigate away from page with onbeforeunload handler,
// otherwise it would trigger an extra dialog request when
diff --git a/tests/auto/quick/qmltests/data/tst_linkHovered.qml b/tests/auto/quick/qmltests/data/tst_linkHovered.qml
index faf943c55..d21d74434 100644
--- a/tests/auto/quick/qmltests/data/tst_linkHovered.qml
+++ b/tests/auto/quick/qmltests/data/tst_linkHovered.qml
@@ -26,10 +26,9 @@
**
****************************************************************************/
-import QtQuick 2.0
-import QtTest 1.0
-import QtWebEngine 1.2
-import QtWebEngine.testsupport 1.0
+import QtQuick
+import QtTest
+import QtWebEngine
import "../../qmltests/data" 1.0
TestWebEngineView {
@@ -40,25 +39,29 @@ TestWebEngineView {
property string lastUrl
- testSupport: WebEngineTestSupport { }
-
- SignalSpy {
- id: loadVisuallyCommittedSpy
- target: webEngineView.testSupport
- signalName: "loadVisuallyCommitted"
- }
-
SignalSpy {
id: linkHoveredSpy
target: webEngineView
signalName: "linkHovered"
}
- onLinkHovered: {
+ onLinkHovered: function(hoveredUrl) {
webEngineView.lastUrl = hoveredUrl
}
+ function isViewRendered() {
+ var pixel = getItemPixel(webEngineView);
+
+ // The center pixel is expected to be red.
+ if (pixel[0] !== 255) return false;
+ if (pixel[1] !== 0) return false;
+ if (pixel[2] !== 0) return false;
+
+ return true;
+ }
+
TestCase {
+ id: testCase
name: "DesktopWebEngineViewLinkHovered"
// Delayed windowShown to workaround problems with Qt5 in debug mode.
@@ -72,7 +75,6 @@ TestWebEngineView {
function init() {
webEngineView.lastUrl = "";
- loadVisuallyCommittedSpy.clear();
linkHoveredSpy.clear();
}
@@ -88,7 +90,7 @@ TestWebEngineView {
compare(webEngineView.lastUrl, "")
// Wait for the page to be rendered before trying to test based on input events
- loadVisuallyCommittedSpy.wait();
+ tryVerify(isViewRendered);
mouseMove(webEngineView, 100, 100)
linkHoveredSpy.wait(12000);
@@ -111,7 +113,7 @@ TestWebEngineView {
compare(webEngineView.lastUrl, "")
// Wait for the page to be rendered before trying to test based on input events
- loadVisuallyCommittedSpy.wait();
+ tryVerify(isViewRendered);
for (var i = 0; i < 100; i += 10)
mouseMove(webEngineView, 100, 100 + i)
diff --git a/tests/auto/quick/qmltests/data/tst_mouseClick.qml b/tests/auto/quick/qmltests/data/tst_mouseClick.qml
index 6c314d44c..647c84573 100644
--- a/tests/auto/quick/qmltests/data/tst_mouseClick.qml
+++ b/tests/auto/quick/qmltests/data/tst_mouseClick.qml
@@ -26,10 +26,10 @@
**
****************************************************************************/
-import QtQuick 2.0
-import QtTest 1.0
-import QtWebEngine 1.4
-import QtWebEngine.testsupport 1.0
+import QtQuick
+import QtTest
+import QtWebEngine
+import Test.util
import "../../qmltests/data" 1.0
TestWebEngineView {
@@ -37,8 +37,10 @@ TestWebEngineView {
width: 200
height: 200
- testSupport: WebEngineTestSupport {
- function mouseMultiClick(item, x, y, clickCount) {
+ TestInputEvent {
+ id: testInputEvent
+
+ function __mouseMultiClick(item, x, y, clickCount) {
if (!item)
qtest_fail("No item given to mouseMultiClick", 1);
@@ -46,20 +48,20 @@ TestWebEngineView {
x = item.width / 2;
if (y === undefined)
y = item.height / 2;
- if (!testEvent.mouseMultiClick(item, x, y, clickCount))
+ if (!mouseMultiClick(item, x, y, clickCount))
qtest_fail("window not shown", 2);
}
function mouseDoubleClick(item, x, y) {
- mouseMultiClick(item, x, y, 2);
+ __mouseMultiClick(item, x, y, 2);
}
function mouseTripleClick(item, x, y) {
- mouseMultiClick(item, x, y, 3);
+ __mouseMultiClick(item, x, y, 3);
}
function mouseQuadraClick(item, x, y) {
- mouseMultiClick(item, x, y, 4);
+ __mouseMultiClick(item, x, y, 4);
}
}
@@ -91,7 +93,7 @@ TestWebEngineView {
verify(webEngineView.waitForLoadSucceeded());
var center = getElementCenter("input");
- webEngineView.testSupport.mouseDoubleClick(webEngineView, center.x, center.y);
+ testInputEvent.mouseDoubleClick(webEngineView, center.x, center.y);
verifyElementHasFocus("input");
tryVerify(function() { return getTextSelection() == "Company" });
@@ -107,7 +109,7 @@ TestWebEngineView {
verify(webEngineView.waitForLoadSucceeded());
var center = getElementCenter("input");
- webEngineView.testSupport.mouseTripleClick(webEngineView, center.x, center.y);
+ testInputEvent.mouseTripleClick(webEngineView, center.x, center.y);
verifyElementHasFocus("input");
tryVerify(function() { return getTextSelection() == "The Qt Company" });
@@ -123,7 +125,7 @@ TestWebEngineView {
verify(webEngineView.waitForLoadSucceeded());
var center = getElementCenter("input");
- webEngineView.testSupport.mouseQuadraClick(webEngineView, center.x, center.y);
+ testInputEvent.mouseQuadraClick(webEngineView, center.x, center.y);
verifyElementHasFocus("input");
tryVerify(function() { return getTextSelection() == "" });
}
diff --git a/tests/auto/quick/qmltests/data/tst_viewSource.qml b/tests/auto/quick/qmltests/data/tst_viewSource.qml
index 0b5f6a7ab..8097758fd 100644
--- a/tests/auto/quick/qmltests/data/tst_viewSource.qml
+++ b/tests/auto/quick/qmltests/data/tst_viewSource.qml
@@ -26,9 +26,9 @@
**
****************************************************************************/
-import QtQuick 2.0
-import QtTest 1.0
-import QtWebEngine 1.4
+import QtQuick
+import QtTest
+import QtWebEngine
TestWebEngineView {
id: webEngineView
@@ -38,6 +38,12 @@ TestWebEngineView {
property var viewRequest: null
SignalSpy {
+ id: loadSpy
+ target: webEngineView
+ signalName: 'loadingChanged'
+ }
+
+ SignalSpy {
id: newViewRequestedSpy
target: webEngineView
signalName: "newViewRequested"
@@ -68,6 +74,7 @@ TestWebEngineView {
tryCompare(webEngineView, "loadStatus", WebEngineView.LoadSucceededStatus);
webEngineView.loadStatus = null;
+ loadSpy.clear();
newViewRequestedSpy.clear();
titleChangedSpy.clear();
viewRequest = null;
@@ -121,6 +128,40 @@ TestWebEngineView {
tryCompare(webEngineView, "url", "view-source:" + url.replace("user:passwd@", ""));
tryCompare(webEngineView, "title", "view-source:" + url.replace("http://user:passwd@", ""));
}
+
+ function test_viewSourceURL_data() {
+ var testLocalUrl = "view-source:" + Qt.resolvedUrl("test1.html");
+ var testLocalUrlWithoutScheme = "view-source:" + Qt.resolvedUrl("test1.html").toString().substring(7);
+
+ return [
+ { tag: "view-source:", userInputUrl: "view-source:", loadSucceed: true, url: "view-source:", title: "view-source:" },
+ { tag: "view-source:about:blank", userInputUrl: "view-source:about:blank", loadSucceed: true, url: "view-source:about:blank", title: "view-source:about:blank" },
+ { tag: testLocalUrl, userInputUrl: testLocalUrl, loadSucceed: true, url: testLocalUrl, title: "test1.html" },
+ { tag: testLocalUrlWithoutScheme, userInputUrl: testLocalUrlWithoutScheme, loadSucceed: true, url: testLocalUrl, title: "test1.html" },
+ { tag: "view-source:http://non.existent", userInputUrl: "view-source:http://non.existent", loadSucceed: false, url: "http://non.existent/", title: "non.existent" },
+ { tag: "view-source:non.existent", userInputUrl: "view-source:non.existent", loadSucceed: false, url: "http://non.existent/", title: "non.existent" },
+ ];
+ }
+
+ function test_viewSourceURL(row) {
+ WebEngine.settings.errorPageEnabled = true
+ webEngineView.url = row.userInputUrl;
+
+ tryCompare(loadSpy, 'count', 2);
+ let load = loadSpy.signalArguments[1][0]
+ let expectedStatus = row.loadSucceed ? WebEngineView.LoadSucceededStatus : WebEngineView.LoadFailedStatus
+ compare(load.status, expectedStatus);
+ compare(load.isErrorPage, !row.loadSucceed);
+ tryVerify(function() { return titleChangedSpy.count == 1; });
+
+ compare(webEngineView.url, row.url);
+ tryCompare(webEngineView, "title", row.title);
+ if (row.loadSucceed) {
+ verify(!webEngineView.action(WebEngineView.ViewSource).enabled);
+ } else {
+ verify(webEngineView.action(WebEngineView.ViewSource).enabled);
+ }
+ }
}
}
diff --git a/tests/auto/quick/qmltests/data/tst_viewSoure.qml b/tests/auto/quick/qmltests/data/tst_viewSoure.qml
deleted file mode 100644
index 8d7c052aa..000000000
--- a/tests/auto/quick/qmltests/data/tst_viewSoure.qml
+++ /dev/null
@@ -1,120 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2020 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.4
-import QtWebEngine.testsupport 1.0
-import "../../qmltests/data" 1.0
-
-TestWebEngineView {
- id: webEngineView
- width: 200
- height: 400
-
- property var viewRequest: null
-
- SignalSpy {
- id: loadSpy
- target: webEngineView
- signalName: 'loadingChanged'
- }
-
- SignalSpy {
- id: newViewRequestedSpy
- target: webEngineView
- signalName: "newViewRequested"
- }
-
- SignalSpy {
- id: titleChangedSpy
- target: webEngineView
- signalName: "titleChanged"
- }
-
- onNewViewRequested: {
- viewRequest = {
- "destination": request.destination,
- "userInitiated": request.userInitiated
- };
-
- request.openIn(webEngineView);
- }
-
- TestCase {
- id: testCase
- name: "WebEngineViewSource"
-
- function init() {
- webEngineView.loadStatus = null;
- webEngineView.url = Qt.resolvedUrl("test1.html");
- tryCompare(webEngineView, "loadStatus", WebEngineView.LoadSucceededStatus);
- webEngineView.loadStatus = null;
-
- loadSpy.clear()
- newViewRequestedSpy.clear();
- titleChangedSpy.clear();
- viewRequest = null;
- }
-
- function test_viewSourceURL_data() {
- var testLocalUrl = "view-source:" + Qt.resolvedUrl("test1.html");
- var testLocalUrlWithoutScheme = "view-source:" + Qt.resolvedUrl("test1.html").toString().substring(7);
-
- return [
- { tag: "view-source:", userInputUrl: "view-source:", loadSucceed: true, url: "view-source:", title: "view-source:" },
- { tag: "view-source:about:blank", userInputUrl: "view-source:about:blank", loadSucceed: true, url: "view-source:about:blank", title: "view-source:about:blank" },
- { tag: testLocalUrl, userInputUrl: testLocalUrl, loadSucceed: true, url: testLocalUrl, title: "test1.html" },
- { tag: testLocalUrlWithoutScheme, userInputUrl: testLocalUrlWithoutScheme, loadSucceed: true, url: testLocalUrl, title: "test1.html" },
- { tag: "view-source:http://non.existent", userInputUrl: "view-source:http://non.existent", loadSucceed: false, url: "http://non.existent/", title: "non.existent" },
- { tag: "view-source:non.existent", userInputUrl: "view-source:non.existent", loadSucceed: false, url: "http://non.existent/", title: "non.existent" },
- ];
- }
-
- function test_viewSourceURL(row) {
- WebEngine.settings.errorPageEnabled = true
- webEngineView.url = row.userInputUrl;
-
- tryCompare(loadSpy, 'count', 2);
- let load = loadSpy.signalArguments[1][0]
- let expectedStatus = row.loadSucceed ? WebEngineView.LoadSucceededStatus : WebEngineView.LoadFailedStatus
- compare(load.status, expectedStatus);
- compare(load.isErrorPage, !row.loadSucceed);
- tryVerify(function() { return titleChangedSpy.count == 1; });
-
- compare(webEngineView.url, row.url);
- tryCompare(webEngineView, "title", row.title);
- if (row.loadSucceed) {
- verify(!webEngineView.action(WebEngineView.ViewSource).enabled);
- } else {
- verify(webEngineView.action(WebEngineView.ViewSource).enabled);
- }
- }
- }
-}
-