summaryrefslogtreecommitdiffstats
path: root/tests
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
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')
-rw-r--r--tests/auto/quick/CMakeLists.txt4
-rw-r--r--tests/auto/quick/publicapi/tst_publicapi.cpp6
-rw-r--r--tests/auto/quick/qmltests/CMakeLists.txt18
-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
-rw-r--r--tests/auto/quick/qmltests/qmltests.pro36
-rw-r--r--tests/auto/quick/qmltests/tst_qmltests.cpp108
-rw-r--r--tests/auto/quick/quick.pro5
-rw-r--r--tests/auto/util/qt_webengine_quicktest.h3
16 files changed, 255 insertions, 274 deletions
diff --git a/tests/auto/quick/CMakeLists.txt b/tests/auto/quick/CMakeLists.txt
index 6349e9335..d44d67d38 100644
--- a/tests/auto/quick/CMakeLists.txt
+++ b/tests/auto/quick/CMakeLists.txt
@@ -6,6 +6,4 @@ add_subdirectory(uidelegates)
add_subdirectory(inspectorserver)
add_subdirectory(qmltests)
add_subdirectory(qquickwebengineview)
-if(QT_FEATURE_webenginequick_testsupport)
- add_subdirectory(qquickwebengineviewgraphics)
-endif()
+add_subdirectory(qquickwebengineviewgraphics)
diff --git a/tests/auto/quick/publicapi/tst_publicapi.cpp b/tests/auto/quick/publicapi/tst_publicapi.cpp
index b133ea12e..62b8ae21c 100644
--- a/tests/auto/quick/publicapi/tst_publicapi.cpp
+++ b/tests/auto/quick/publicapi/tst_publicapi.cpp
@@ -101,8 +101,6 @@ static const QStringList hardcodedTypes = QStringList()
<< "QQmlListProperty<QQuickWebEngineClientCertificateOption>"
<< "const QQuickWebEngineClientCertificateOption*"
<< "QQmlWebChannel*"
- // Ignore the testSupport types without making a fuss.
- << "QQuickWebEngineTestSupport*"
<< "const QQuickWebEngineContextMenuData*"
<< "QWebEngineCookieStore*"
<< "Qt::LayoutDirection"
@@ -749,10 +747,6 @@ static const QStringList expectedAPI = QStringList()
<< "QQuickWebEngineView.setActiveFocusOnPress(bool) --> void"
<< "QQuickWebEngineView.settings --> QQuickWebEngineSettings*"
<< "QQuickWebEngineView.stop() --> void"
-#if QT_CONFIG(webenginequick_testsupport)
- << "QQuickWebEngineView.testSupport --> QQuickWebEngineTestSupport*"
- << "QQuickWebEngineView.testSupportChanged() --> void"
-#endif
<< "QQuickWebEngineView.title --> QString"
<< "QQuickWebEngineView.titleChanged() --> void"
<< "QQuickWebEngineView.tooltipRequested(QQuickWebEngineTooltipRequest*) --> void"
diff --git a/tests/auto/quick/qmltests/CMakeLists.txt b/tests/auto/quick/qmltests/CMakeLists.txt
index 2cbc52f5f..455c4c746 100644
--- a/tests/auto/quick/qmltests/CMakeLists.txt
+++ b/tests/auto/quick/qmltests/CMakeLists.txt
@@ -5,8 +5,10 @@ qt_internal_add_test(tst_qmltests
SOURCES
tst_qmltests.cpp
LIBRARIES
- Qt::WebEngineQuick
+ Qt::GuiPrivate
Qt::QuickTest
+ Qt::TestPrivate
+ Qt::WebEngineQuick
Test::HttpServer
Test::Util
)
@@ -26,13 +28,17 @@ set(testList
tst_fullScreenRequest.qml
tst_geopermission.qml
tst_getUserMedia.qml
+ tst_inputMethod.qml
+ tst_javaScriptDialogs.qml
tst_keyboardEvents.qml
tst_keyboardModifierMapping.qml
+ tst_linkHovered.qml
tst_loadFail.qml
tst_loadHtml.qml
tst_loadProgress.qml
tst_loadRecursionCrash.qml
tst_loadUrl.qml
+ tst_mouseClick.qml
tst_mouseMove.qml
tst_navigationHistory.qml
tst_navigationRequested.qml
@@ -56,16 +62,6 @@ if(QT_FEATURE_ssl)
list(APPEND testList tst_certificateError.qml)
endif()
-if(QT_FEATURE_webenginequick_testsupport)
- list(APPEND testList
- tst_inputMethod.qml
- tst_javaScriptDialogs.qml
- tst_linkHovered.qml
- tst_mouseClick.qml
- tst_viewSoure.qml
- )
-endif()
-
set(content "")
foreach(test ${testList})
set(contents "${contents}${CMAKE_CURRENT_LIST_DIR}/data/${test}\n")
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);
- }
- }
- }
-}
-
diff --git a/tests/auto/quick/qmltests/qmltests.pro b/tests/auto/quick/qmltests/qmltests.pro
index bc034790e..e5d4b26a1 100644
--- a/tests/auto/quick/qmltests/qmltests.pro
+++ b/tests/auto/quick/qmltests/qmltests.pro
@@ -14,17 +14,24 @@ QML_TESTS = \
$$PWD/data/tst_contextMenu.qml \
$$PWD/data/tst_desktopBehaviorLoadHtml.qml \
$$PWD/data/tst_download.qml \
+ $$PWD/data/tst_favicon.qml \
+ $$PWD/data/tst_faviconDatabase.qml \
$$PWD/data/tst_findText.qml \
$$PWD/data/tst_focusOnNavigation.qml \
$$PWD/data/tst_fullScreenRequest.qml \
$$PWD/data/tst_geopermission.qml \
$$PWD/data/tst_getUserMedia.qml \
+ $$PWD/data/tst_inputMethod.qml \
+ $$PWD/data/tst_javaScriptDialogs.qml
$$PWD/data/tst_keyboardEvents.qml \
$$PWD/data/tst_keyboardModifierMapping.qml \
+ $$PWD/data/tst_linkHovered.qml \
+ $$PWD/data/tst_loadFail.qml \
$$PWD/data/tst_loadHtml.qml \
$$PWD/data/tst_loadProgress.qml \
$$PWD/data/tst_loadRecursionCrash.qml \
$$PWD/data/tst_loadUrl.qml \
+ $$PWD/data/tst_mouseClick.qml \
$$PWD/data/tst_mouseMove.qml \
$$PWD/data/tst_navigationHistory.qml \
$$PWD/data/tst_navigationRequested.qml \
@@ -51,35 +58,6 @@ qtConfig(ssl) {
include(../../shared/http.pri)
}
-qtConfig(webenginequick-testsupport) {
- QML_TESTS += \
- $$PWD/data/tst_favicon.qml \
- $$PWD/data/tst_faviconDownload.qml \
- $$PWD/data/tst_inputMethod.qml \
- $$PWD/data/tst_javaScriptDialogs.qml \
- $$PWD/data/tst_linkHovered.qml \
- $$PWD/data/tst_loadFail.qml \
- $$PWD/data/tst_mouseClick.qml \
- $$PWD/data/tst_viewSoure.qml
-} else {
- PLUGIN_EXTENSION = .so
- PLUGIN_PREFIX = lib
- macos: PLUGIN_PREFIX = .dylib
- win32 {
- PLUGIN_EXTENSION = .dll
- PLUGIN_PREFIX =
- }
-
- TESTSUPPORT_MODULE = $$shell_path($$[QT_INSTALL_QML]/QtWebEngine/testsupport/$${PLUGIN_PREFIX}qtwebenginetestsupportplugin$${PLUGIN_EXTENSION})
- BUILD_DIR = $$shell_path($$clean_path($$OUT_PWD/../../../..))
- SRC_DIR = $$shell_path($$clean_path($$PWD/../../../..))
-
- warning("QML Test Support API is disabled. This means some QML tests that use Test Support API will fail.")
- warning("Use the following command to build Test Support module and rebuild WebEngineView API:")
- warning("cd $$BUILD_DIR && qmake -r $$shell_path($$SRC_DIR/qtwebengine.pro -- --feature-testsupport=yes) && make -C $$shell_path($$BUILD_DIR/src/webengine) clean && make")
- warning("After performing the command above make sure QML module \"QtWebEngine.testsupport\" is deployed at $$TESTSUPPORT_MODULE")
-}
-
qtHaveModule(quickcontrols) {
QML_TESTS += \
$$PWD/data/tst_filePicker.qml
diff --git a/tests/auto/quick/qmltests/tst_qmltests.cpp b/tests/auto/quick/qmltests/tst_qmltests.cpp
index a60994f85..78c167106 100644
--- a/tests/auto/quick/qmltests/tst_qmltests.cpp
+++ b/tests/auto/quick/qmltests/tst_qmltests.cpp
@@ -32,11 +32,16 @@
#include <httpsserver.h>
#endif
-#include <QtCore/QScopedPointer>
-#include <QTemporaryDir>
+#include <QtCore/qscopedpointer.h>
+#include <QtCore/qtemporarydir.h>
+#include <QtGui/private/qinputmethod_p.h>
+#include <QtQml/qqmlengine.h>
+#include <QtQuick/qquickitem.h>
+#include <QtQuick/qquickwindow.h>
#include <QtQuickTest/quicktest.h>
-#include <QtWebEngineQuick/QQuickWebEngineProfile>
-#include <QtQml/QQmlEngine>
+#include <QtTest/qtest.h>
+#include <QtWebEngineQuick/qquickwebengineprofile.h>
+#include <QtWebEngineQuick/qtwebenginequickglobal.h>
#include <qt_webengine_quicktest.h>
#if defined(Q_OS_LINUX) && defined(QT_DEBUG)
@@ -142,6 +147,99 @@ private:
QTemporaryDir tempDir;
};
+class TestInputContext : public QPlatformInputContext {
+ Q_OBJECT
+
+public:
+ TestInputContext() = default;
+ ~TestInputContext() { release(); }
+
+ Q_INVOKABLE void create()
+ {
+ QInputMethodPrivate *inputMethodPrivate = QInputMethodPrivate::get(qApp->inputMethod());
+ inputMethodPrivate->testContext = this;
+ }
+
+ Q_INVOKABLE void release()
+ {
+ QInputMethodPrivate *inputMethodPrivate = QInputMethodPrivate::get(qApp->inputMethod());
+ inputMethodPrivate->testContext = nullptr;
+ }
+
+ void showInputPanel() override { m_visible = true; }
+ void hideInputPanel() override { m_visible = false; }
+ bool isInputPanelVisible() const override { return m_visible; }
+
+private:
+ bool m_visible = false;
+};
+
+QT_BEGIN_NAMESPACE
+namespace QTest {
+ int Q_TESTLIB_EXPORT defaultMouseDelay();
+}
+QT_END_NAMESPACE
+
+class TestInputEvent : public QObject {
+ Q_OBJECT
+
+public:
+ TestInputEvent() = default;
+
+ Q_INVOKABLE bool mouseMultiClick(QObject *item, qreal x, qreal y, int clickCount)
+ {
+ QTEST_ASSERT(item);
+
+ QWindow *view = eventWindow(item);
+ if (!view)
+ return false;
+
+ for (int i = 0; i < clickCount; ++i) {
+ mouseEvent(QMouseEvent::MouseButtonPress, view, item, QPointF(x, y));
+ mouseEvent(QMouseEvent::MouseButtonRelease, view, item, QPointF(x, y));
+ }
+ QTest::lastMouseTimestamp += QTest::mouseDoubleClickInterval;
+
+ return true;
+ }
+
+private:
+ QWindow *eventWindow(QObject *item = nullptr)
+ {
+ QWindow *window = qobject_cast<QWindow *>(item);
+ if (window)
+ return window;
+
+ QQuickItem *quickItem = qobject_cast<QQuickItem *>(item);
+ if (quickItem)
+ return quickItem->window();
+
+ QQuickItem *testParentItem = qobject_cast<QQuickItem *>(parent());
+ if (testParentItem)
+ return testParentItem->window();
+
+ return nullptr;
+ }
+
+ void mouseEvent(QEvent::Type type, QWindow *window, QObject *item, const QPointF &_pos)
+ {
+ QTest::qWait(QTest::defaultMouseDelay());
+ QTest::lastMouseTimestamp += QTest::defaultMouseDelay();
+
+ QPoint pos;
+ QQuickItem *sgitem = qobject_cast<QQuickItem *>(item);
+ if (sgitem)
+ pos = sgitem->mapToScene(_pos).toPoint();
+
+ QMouseEvent me(type, pos, window->mapFromGlobal(pos), Qt::LeftButton, Qt::LeftButton, {});
+ me.setTimestamp(++QTest::lastMouseTimestamp);
+
+ QSpontaneKeyEvent::setSpontaneous(&me);
+ if (!qApp->notify(window, &me))
+ QTest::qWarn("Mouse click event not accepted by receiving window");
+ }
+};
+
int main(int argc, char **argv)
{
#if defined(Q_OS_LINUX) && defined(QT_DEBUG)
@@ -171,6 +269,8 @@ int main(int argc, char **argv)
QtWebEngineQuick::initialize();
QQuickWebEngineProfile::defaultProfile()->setOffTheRecord(true);
qmlRegisterType<TempDir>("Test.util", 1, 0, "TempDir");
+ qmlRegisterType<TestInputContext>("Test.util", 1, 0, "TestInputContext");
+ qmlRegisterType<TestInputEvent>("Test.util", 1, 0, "TestInputEvent");
QTEST_SET_MAIN_SOURCE_PATH
qmlRegisterSingletonType<HttpServer>("Test.Shared", 1, 0, "HttpServer", [&] (QQmlEngine *, QJSEngine *) {
diff --git a/tests/auto/quick/quick.pro b/tests/auto/quick/quick.pro
index 1b518c27f..13e4d78cc 100644
--- a/tests/auto/quick/quick.pro
+++ b/tests/auto/quick/quick.pro
@@ -9,11 +9,8 @@ SUBDIRS += \
qmltests \
publicapi \
qquickwebenginedefaultsurfaceformat \
+ qquickwebengineviewgraphics \
qquickwebengineview \
qtbug-70248
-qtConfig(webenginequick-testsupport) {
- SUBDIRS += qquickwebengineviewgraphics
-}
-
boot2qt: SUBDIRS -= inspectorserver qquickwebengineview qmltests
diff --git a/tests/auto/util/qt_webengine_quicktest.h b/tests/auto/util/qt_webengine_quicktest.h
index 3fba3b905..0428783bf 100644
--- a/tests/auto/util/qt_webengine_quicktest.h
+++ b/tests/auto/util/qt_webengine_quicktest.h
@@ -37,9 +37,6 @@
#include <QtGui/QGuiApplication>
#endif
-#include "qopenglcontext.h"
-#include <QtWebEngineQuick/qtwebenginequickglobal.h>
-
QT_BEGIN_NAMESPACE
#ifdef QT_WIDGETS_LIB