summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorBalazs Egedi <egedib@inf.u-szeged.hu>2021-06-01 17:57:04 +0200
committerMichal Klocek <michal.klocek@qt.io>2021-07-06 08:42:48 +0000
commit4786b8c7ed94da77e73c4719fb1c66b080375a19 (patch)
tree6617751a9df560a215bdca859e0a73a6ecc9daff /tests
parent9e8c712eeea2170e889607eadc614ce7012a3ae0 (diff)
Add mock Menu UIDelegates for Quick Controls 2
Menu and MenuItem are added to Controls2Delegates. contextMenu auto test now works without any Quick Controls. Task-number: QTBUG-93666 Change-Id: Ia2fdaef3456a44cc8792ed4e26c1c13bfee7858e Reviewed-by: Michal Klocek <michal.klocek@qt.io> (cherry picked from commit d65c2dc52f758657cce4617517d11cbd1912a4ed) Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/quick/qmltests/BLACKLIST3
-rw-r--r--tests/auto/quick/qmltests/CMakeLists.txt9
-rw-r--r--tests/auto/quick/qmltests/data/tst_contextMenu.qml81
-rw-r--r--tests/auto/quick/qmltests/mock-delegates/QtWebEngine/Controls2Delegates/Menu.qml (renamed from tests/auto/quick/qmltests/mock-delegates/QtWebEngine/Controls1Delegates/Menu.qml)23
-rw-r--r--tests/auto/quick/qmltests/mock-delegates/QtWebEngine/Controls2Delegates/MenuItem.qml (renamed from tests/auto/quick/qmltests/mock-delegates/QtWebEngine/Controls1Delegates/MenuItem.qml)10
-rw-r--r--tests/auto/quick/qmltests/mock-delegates/TestParams/MenuParams.qml34
-rw-r--r--tests/auto/quick/qmltests/mock-delegates/TestParams/qmldir1
-rw-r--r--tests/auto/quick/qmltests/qmltests.pro6
8 files changed, 66 insertions, 101 deletions
diff --git a/tests/auto/quick/qmltests/BLACKLIST b/tests/auto/quick/qmltests/BLACKLIST
index 3d98566f5..f4d7d98df 100644
--- a/tests/auto/quick/qmltests/BLACKLIST
+++ b/tests/auto/quick/qmltests/BLACKLIST
@@ -1,2 +1,5 @@
[NewViewRequest::test_loadNewViewRequest]
macos
+
+[WebEngineViewContextMenu::test_contextMenuLinkAndSelectedText]
+macos
diff --git a/tests/auto/quick/qmltests/CMakeLists.txt b/tests/auto/quick/qmltests/CMakeLists.txt
index a05cd9fd3..0d3b973bc 100644
--- a/tests/auto/quick/qmltests/CMakeLists.txt
+++ b/tests/auto/quick/qmltests/CMakeLists.txt
@@ -15,6 +15,7 @@ set(testList
tst_action.qml
tst_activeFocusOnPress.qml
tst_audioMuted.qml
+ tst_contextMenu.qml
tst_desktopBehaviorLoadHtml.qml
tst_download.qml
tst_favicon.qml
@@ -66,14 +67,6 @@ if(QT_FEATURE_webenginequick_testsupport)
)
endif()
-if(TARGET Qt::QuickControls) #FIXME
- list(APPEND testList
- tst_contextMenu.qml
- )
-else()
- message("\n!!!! QuickControls target is missing, some tests are not executed !!! FIXME \n")
-endif()
-
set(content "")
foreach(test ${testList})
set(contents "${contents}${CMAKE_CURRENT_LIST_DIR}/data/${test}\n")
diff --git a/tests/auto/quick/qmltests/data/tst_contextMenu.qml b/tests/auto/quick/qmltests/data/tst_contextMenu.qml
index 8493ba1c7..d415996bd 100644
--- a/tests/auto/quick/qmltests/data/tst_contextMenu.qml
+++ b/tests/auto/quick/qmltests/data/tst_contextMenu.qml
@@ -26,10 +26,10 @@
**
****************************************************************************/
-import QtQuick 2.0
-import QtQuick.Controls 1.4
-import QtTest 1.0
-import QtWebEngine 1.6
+import QtQuick
+import QtTest
+import QtWebEngine
+import "../mock-delegates/TestParams"
TestWebEngineView {
id: webEngineView
@@ -40,7 +40,7 @@ TestWebEngineView {
property var mediaType: null
property string selectedText: ""
- onContextMenuRequested: {
+ onContextMenuRequested: function (request) {
linkText = request.linkText;
mediaType = request.mediaType;
selectedText = request.selectedText;
@@ -52,38 +52,20 @@ TestWebEngineView {
signalName: "contextMenuRequested"
}
- function getContextMenus() {
- var data = webEngineView.data;
- var contextMenus = [];
-
- for (var i = 0; i < data.length; i++) {
- if (data[i].type == MenuItemType.Menu) {
- contextMenus.push(data[i]);
- }
- }
- return contextMenus;
- }
-
- function destroyContextMenu() {
- testCase.keyPress(Qt.Key_Escape);
- return getContextMenus().length == 0;
- }
-
TestCase {
id: testCase
name: "WebEngineViewContextMenu"
when: windowShown
function init() {
- var contextMenus = getContextMenus();
- compare(contextMenus.length, 0);
+ MenuParams.isMenuOpened = false;
}
function cleanup() {
contextMenuRequestedSpy.clear();
}
- function test_contextMenu_data() {
+ function test_contextMenuRequest_data() {
return [
{ tag: "defaultContextMenu", userHandled: false, accepted: false },
{ tag: "defaultContextMenuWithConnect", userHandled: true, accepted: false },
@@ -91,11 +73,7 @@ TestWebEngineView {
];
}
- function test_contextMenu(row) {
- if (Qt.platform.os == "osx") {
- skip("When the menu pops up on macOS, it does not return and the test fails after time out.");
- }
-
+ function test_contextMenuRequest(row) {
function contextMenuHandler(request) {
request.accepted = row.accepted;
}
@@ -109,22 +87,12 @@ TestWebEngineView {
mouseClick(webEngineView, 20, 20, Qt.RightButton);
contextMenuRequestedSpy.wait();
compare(contextMenuRequestedSpy.count, 1);
+ tryCompare(MenuParams, "isMenuOpened", !row.accepted);
- // There should be maximum one ContextMenu present at a time
- var contextMenus = getContextMenus();
- verify(contextMenus.length <= 1);
- compare(contextMenus[0] != null, !row.accepted);
-
- // FIXME: Sometimes the keyPress(Qt.Key_Escape) event isn't caught so we keep trying
- tryVerify(destroyContextMenu);
webEngineView.contextMenuRequested.disconnect(contextMenuHandler);
}
function test_contextMenuLinkAndSelectedText() {
- if (Qt.platform.os == "osx") {
- skip("When the menu pops up on macOS, it does not return and the test fails after time out.");
- }
-
webEngineView.loadHtml("<html><body>" +
"<span id='text'>Text </span>" +
"<a id='link' href='test1.html'>Link</a>" +
@@ -137,9 +105,6 @@ TestWebEngineView {
contextMenuRequestedSpy.wait();
compare(contextMenuRequestedSpy.count, 1);
- var contextMenus = getContextMenus();
- compare(contextMenus.length, 1);
- verify(contextMenus[0]);
compare(linkText, "Link");
compare(mediaType, ContextMenuRequest.MediaTypeNone);
compare(selectedText, "");
@@ -150,8 +115,6 @@ TestWebEngineView {
verify(webEngineView.action(WebEngineView.CopyLinkToClipboard).enabled);
contextMenuRequestedSpy.clear();
- // FIXME: Sometimes the keyPress(Qt.Key_Escape) event isn't caught so we keep trying
- tryVerify(destroyContextMenu);
// 2. Everything is selected, right click on the link
webEngineView.triggerWebAction(WebEngineView.SelectAll);
@@ -161,16 +124,11 @@ TestWebEngineView {
contextMenuRequestedSpy.wait();
compare(contextMenuRequestedSpy.count, 1);
- contextMenus = getContextMenus();
- compare(contextMenus.length, 1);
- verify(contextMenus[0]);
compare(linkText, "Link");
compare(mediaType, ContextMenuRequest.MediaTypeNone);
compare(selectedText, "Text Link");
contextMenuRequestedSpy.clear();
- // FIXME: Sometimes the keyPress(Qt.Key_Escape) event isn't caught so we keep trying
- tryVerify(destroyContextMenu);
// 3. Everything is selected, right click on the text
var textCenter = getElementCenter("text");
@@ -178,22 +136,12 @@ TestWebEngineView {
contextMenuRequestedSpy.wait();
compare(contextMenuRequestedSpy.count, 1);
- contextMenus = getContextMenus();
- compare(contextMenus.length, 1);
- verify(contextMenus[0]);
compare(linkText, "");
compare(mediaType, ContextMenuRequest.MediaTypeNone);
compare(selectedText, "Text Link");
-
- // FIXME: Sometimes the keyPress(Qt.Key_Escape) event isn't caught so we keep trying
- tryVerify(destroyContextMenu);
}
function test_contextMenuMediaType() {
- if (Qt.platform.os == "osx") {
- skip("When the menu pops up on macOS, it does not return and the test fails after time out.");
- }
-
webEngineView.url = Qt.resolvedUrl("favicon.html");
verify(webEngineView.waitForLoadSucceeded());
// 1. Right click on the image
@@ -202,30 +150,19 @@ TestWebEngineView {
contextMenuRequestedSpy.wait();
compare(contextMenuRequestedSpy.count, 1);
- var contextMenus = getContextMenus();
- compare(contextMenus.length, 1);
- verify(contextMenus[0]);
compare(linkText, "");
compare(mediaType, ContextMenuRequest.MediaTypeImage);
compare(selectedText, "");
contextMenuRequestedSpy.clear();
- // FIXME: Sometimes the keyPress(Qt.Key_Escape) event isn't caught so we keep trying
- tryVerify(destroyContextMenu);
// 2. Right click out of the image
mouseClick(webEngineView, center.x + 30, center.y, Qt.RightButton);
contextMenuRequestedSpy.wait();
compare(contextMenuRequestedSpy.count, 1);
- contextMenus = getContextMenus();
- compare(contextMenus.length, 1);
- verify(contextMenus[0]);
compare(linkText, "");
compare(mediaType, ContextMenuRequest.MediaTypeNone);
compare(selectedText, "");
-
- // FIXME: Sometimes the keyPress(Qt.Key_Escape) event isn't caught so we keep trying
- tryVerify(destroyContextMenu);
}
}
}
diff --git a/tests/auto/quick/qmltests/mock-delegates/QtWebEngine/Controls1Delegates/Menu.qml b/tests/auto/quick/qmltests/mock-delegates/QtWebEngine/Controls2Delegates/Menu.qml
index 36efa7680..aa03a9d30 100644
--- a/tests/auto/quick/qmltests/mock-delegates/QtWebEngine/Controls1Delegates/Menu.qml
+++ b/tests/auto/quick/qmltests/mock-delegates/QtWebEngine/Controls2Delegates/Menu.qml
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2016 The Qt Company Ltd.
+** Copyright (C) 2021 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtWebEngine module of the Qt Toolkit.
@@ -37,21 +37,18 @@
**
****************************************************************************/
-import QtQuick 2.5
-import QtQuick.Controls 1.4 as Controls
+import QtQml
+import "../../TestParams"
-Controls.Menu {
+QtObject {
id: menu
- signal done()
+ property string linkText: ""
+ property var mediaType: null
+ property string selectedText: ""
- // Use private API for now
- onAboutToHide: doneTimer.start()
+ signal done()
- // WORKAROUND On Mac the Menu may be destroyed before the MenuItem
- // is actually triggered (see qtbase commit 08cc9b9991ae9ab51)
- Timer {
- id: doneTimer
- interval: 100
- onTriggered: menu.done()
+ function open() {
+ MenuParams.isMenuOpened = true;
}
}
diff --git a/tests/auto/quick/qmltests/mock-delegates/QtWebEngine/Controls1Delegates/MenuItem.qml b/tests/auto/quick/qmltests/mock-delegates/QtWebEngine/Controls2Delegates/MenuItem.qml
index e61f4c230..dcc1ca4b6 100644
--- a/tests/auto/quick/qmltests/mock-delegates/QtWebEngine/Controls1Delegates/MenuItem.qml
+++ b/tests/auto/quick/qmltests/mock-delegates/QtWebEngine/Controls2Delegates/MenuItem.qml
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2016 The Qt Company Ltd.
+** Copyright (C) 2021 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtWebEngine module of the Qt Toolkit.
@@ -37,8 +37,8 @@
**
****************************************************************************/
-import QtQuick 2.5
-import QtQuick.Controls 1.4 as Controls
-
-Controls.MenuItem { }
+import QtQml
+QtObject {
+ signal triggered()
+}
diff --git a/tests/auto/quick/qmltests/mock-delegates/TestParams/MenuParams.qml b/tests/auto/quick/qmltests/mock-delegates/TestParams/MenuParams.qml
new file mode 100644
index 000000000..952eb5ebe
--- /dev/null
+++ b/tests/auto/quick/qmltests/mock-delegates/TestParams/MenuParams.qml
@@ -0,0 +1,34 @@
+/****************************************************************************
+**
+** Copyright (C) 2021 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtWebEngine module of the Qt Toolkit.
+**
+** $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$
+**
+****************************************************************************/
+
+pragma Singleton
+import QtQml
+
+QtObject {
+ property bool isMenuOpened: false;
+}
diff --git a/tests/auto/quick/qmltests/mock-delegates/TestParams/qmldir b/tests/auto/quick/qmltests/mock-delegates/TestParams/qmldir
index 5807f1e6e..2702ad30f 100644
--- a/tests/auto/quick/qmltests/mock-delegates/TestParams/qmldir
+++ b/tests/auto/quick/qmltests/mock-delegates/TestParams/qmldir
@@ -2,3 +2,4 @@
module TestParams
singleton FilePickerParams 1.0 FilePickerParams.qml
singleton JSDialogParams 1.0 JSDialogParams.qml
+singleton MenuParams 1.0 MenuParams.qml
diff --git a/tests/auto/quick/qmltests/qmltests.pro b/tests/auto/quick/qmltests/qmltests.pro
index 513af0f3d..c5755e46a 100644
--- a/tests/auto/quick/qmltests/qmltests.pro
+++ b/tests/auto/quick/qmltests/qmltests.pro
@@ -11,6 +11,7 @@ QML_TESTS = \
$$PWD/data/tst_action.qml \
$$PWD/data/tst_activeFocusOnPress.qml \
$$PWD/data/tst_audioMuted.qml \
+ $$PWD/data/tst_contextMenu.qml \
$$PWD/data/tst_desktopBehaviorLoadHtml.qml \
$$PWD/data/tst_download.qml \
$$PWD/data/tst_findText.qml \
@@ -81,7 +82,6 @@ qtConfig(webenginequick-testsupport) {
qtHaveModule(quickcontrols) {
QML_TESTS += \
- $$PWD/data/tst_contextMenu.qml \
$$PWD/data/tst_filePicker.qml
}
@@ -134,8 +134,6 @@ OTHER_FILES += \
$$PWD/data/icons/qt32.ico \
$$PWD/data/icons/qtmulti.ico \
$$PWD/data/icons/small-favicon.png \
- $$PWD/mock-delegates/QtWebEngine/Controls1Delegates/Menu.qml \
- $$PWD/mock-delegates/QtWebEngine/Controls1Delegates/MenuItem.qml \
$$PWD/mock-delegates/QtWebEngine/Controls1Delegates/qmldir \
$$PWD/mock-delegates/TestParams/FilePickerParams.qml \
$$PWD/mock-delegates/TestParams/JSDialogParams.qml \
@@ -143,6 +141,8 @@ OTHER_FILES += \
$$PWD/mock-delegates/QtWebEngine/Controls2Delegates/AlertDialog.qml \
$$PWD/mock-delegates/QtWebEngine/Controls2Delegates/ConfirmDialog.qml \
$$PWD/mock-delegates/QtWebEngine/Controls2Delegates/FilePicker.qml \
+ $$PWD/mock-delegates/QtWebEngine/Controls2Delegates/Menu.qml \
+ $$PWD/mock-delegates/QtWebEngine/Controls2Delegates/MenuItem.qml \
$$PWD/mock-delegates/QtWebEngine/Controls2Delegates/PromptDialog.qml \
$$PWD/mock-delegates/QtWebEngine/Controls2Delegates/qmldir