From 4786b8c7ed94da77e73c4719fb1c66b080375a19 Mon Sep 17 00:00:00 2001 From: Balazs Egedi Date: Tue, 1 Jun 2021 17:57:04 +0200 Subject: 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 (cherry picked from commit d65c2dc52f758657cce4617517d11cbd1912a4ed) Reviewed-by: Allan Sandfeld Jensen --- tests/auto/quick/qmltests/BLACKLIST | 3 + tests/auto/quick/qmltests/CMakeLists.txt | 9 +-- tests/auto/quick/qmltests/data/tst_contextMenu.qml | 81 +++------------------- .../QtWebEngine/Controls1Delegates/Menu.qml | 57 --------------- .../QtWebEngine/Controls1Delegates/MenuItem.qml | 44 ------------ .../QtWebEngine/Controls2Delegates/Menu.qml | 54 +++++++++++++++ .../QtWebEngine/Controls2Delegates/MenuItem.qml | 44 ++++++++++++ .../mock-delegates/TestParams/MenuParams.qml | 34 +++++++++ .../qmltests/mock-delegates/TestParams/qmldir | 1 + tests/auto/quick/qmltests/qmltests.pro | 6 +- 10 files changed, 149 insertions(+), 184 deletions(-) delete mode 100644 tests/auto/quick/qmltests/mock-delegates/QtWebEngine/Controls1Delegates/Menu.qml delete mode 100644 tests/auto/quick/qmltests/mock-delegates/QtWebEngine/Controls1Delegates/MenuItem.qml create mode 100644 tests/auto/quick/qmltests/mock-delegates/QtWebEngine/Controls2Delegates/Menu.qml create mode 100644 tests/auto/quick/qmltests/mock-delegates/QtWebEngine/Controls2Delegates/MenuItem.qml create mode 100644 tests/auto/quick/qmltests/mock-delegates/TestParams/MenuParams.qml (limited to 'tests') 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("" + "Text " + "Link" + @@ -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/Controls1Delegates/Menu.qml deleted file mode 100644 index 36efa7680..000000000 --- a/tests/auto/quick/qmltests/mock-delegates/QtWebEngine/Controls1Delegates/Menu.qml +++ /dev/null @@ -1,57 +0,0 @@ -/**************************************************************************** -** -** 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:LGPL$ -** 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 Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** 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-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -import QtQuick 2.5 -import QtQuick.Controls 1.4 as Controls - -Controls.Menu { - id: menu - signal done() - - // Use private API for now - onAboutToHide: doneTimer.start() - - // 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() - } -} diff --git a/tests/auto/quick/qmltests/mock-delegates/QtWebEngine/Controls1Delegates/MenuItem.qml b/tests/auto/quick/qmltests/mock-delegates/QtWebEngine/Controls1Delegates/MenuItem.qml deleted file mode 100644 index e61f4c230..000000000 --- a/tests/auto/quick/qmltests/mock-delegates/QtWebEngine/Controls1Delegates/MenuItem.qml +++ /dev/null @@ -1,44 +0,0 @@ -/**************************************************************************** -** -** 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:LGPL$ -** 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 Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** 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-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -import QtQuick 2.5 -import QtQuick.Controls 1.4 as Controls - -Controls.MenuItem { } - diff --git a/tests/auto/quick/qmltests/mock-delegates/QtWebEngine/Controls2Delegates/Menu.qml b/tests/auto/quick/qmltests/mock-delegates/QtWebEngine/Controls2Delegates/Menu.qml new file mode 100644 index 000000000..aa03a9d30 --- /dev/null +++ b/tests/auto/quick/qmltests/mock-delegates/QtWebEngine/Controls2Delegates/Menu.qml @@ -0,0 +1,54 @@ +/**************************************************************************** +** +** 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:LGPL$ +** 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 Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** 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-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQml +import "../../TestParams" + +QtObject { + id: menu + property string linkText: "" + property var mediaType: null + property string selectedText: "" + + signal done() + + function open() { + MenuParams.isMenuOpened = true; + } +} diff --git a/tests/auto/quick/qmltests/mock-delegates/QtWebEngine/Controls2Delegates/MenuItem.qml b/tests/auto/quick/qmltests/mock-delegates/QtWebEngine/Controls2Delegates/MenuItem.qml new file mode 100644 index 000000000..dcc1ca4b6 --- /dev/null +++ b/tests/auto/quick/qmltests/mock-delegates/QtWebEngine/Controls2Delegates/MenuItem.qml @@ -0,0 +1,44 @@ +/**************************************************************************** +** +** 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:LGPL$ +** 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 Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** 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-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +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 -- cgit v1.2.3