diff options
Diffstat (limited to 'tests/auto/inputpanel/data/inputpanel/inputpanel.qml')
-rw-r--r-- | tests/auto/inputpanel/data/inputpanel/inputpanel.qml | 246 |
1 files changed, 121 insertions, 125 deletions
diff --git a/tests/auto/inputpanel/data/inputpanel/inputpanel.qml b/tests/auto/inputpanel/data/inputpanel/inputpanel.qml index dd46a5b9..5204c5b7 100644 --- a/tests/auto/inputpanel/data/inputpanel/inputpanel.qml +++ b/tests/auto/inputpanel/data/inputpanel/inputpanel.qml @@ -1,36 +1,10 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Qt Virtual Keyboard module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL$ -** 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 or (at your option) 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.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-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -import QtTest 1.0 -import QtQuick 2.0 -import QtQuick.VirtualKeyboard 2.3 -import QtQuick.VirtualKeyboard.Settings 2.2 +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +import QtTest +import QtQuick +import QtQuick.VirtualKeyboard +import QtQuick.VirtualKeyboard.Settings import "handwriting.js" as Handwriting import "utils.js" as Utils @@ -55,25 +29,20 @@ InputPanel { readonly property var activeLocales: VirtualKeyboardSettings.activeLocales readonly property int inputMode: InputContext.inputEngine.inputMode readonly property var inputMethod: InputContext.inputEngine.inputMethod - readonly property var keyboard: Utils.findChildByProperty(inputPanel, "objectName", "keyboard", null) readonly property bool handwritingMode: keyboard.handwritingMode - readonly property var keyboardLayoutLoader: Utils.findChildByProperty(keyboard, "objectName", "keyboardLayoutLoader", null) - readonly property var keyboardInputArea: Utils.findChildByProperty(keyboard, "objectName", "keyboardInputArea", null) - readonly property var characterPreviewBubble: Utils.findChildByProperty(keyboard, "objectName", "characterPreviewBubble", null) - readonly property var alternativeKeys: Utils.findChildByProperty(keyboard, "objectName", "alternativeKeys", null) - readonly property var naviationHighlight: Utils.findChildByProperty(keyboard, "objectName", "naviationHighlight", null) - readonly property bool naviationHighlightAnimating: naviationHighlight.xAnimation.running || - naviationHighlight.yAnimation.running || - naviationHighlight.widthAnimation.running || - naviationHighlight.heightAnimation.running - readonly property var wordCandidateView: Utils.findChildByProperty(keyboard, "objectName", "wordCandidateView", null) - readonly property var wordCandidateContextMenu: Utils.findChildByProperty(keyboard, "objectName", "wordCandidateContextMenu", null) - readonly property var shadowInputControl: Utils.findChildByProperty(keyboard, "objectName", "shadowInputControl", null) - readonly property var shadowInput: Utils.findChildByProperty(keyboard, "objectName", "shadowInput", null) - readonly property var selectionControl: Utils.findChildByProperty(inputPanel, "objectName", "selectionControl", null) + readonly property Loader keyboardLayoutLoader: keyboard.keyboardLayoutLoader + readonly property MultiPointTouchArea keyboardInputArea: keyboard.keyboardInputArea + readonly property CharacterPreviewBubble characterPreviewBubble: keyboard.characterPreview + readonly property AlternativeKeys alternativeKeys: keyboard.alternativeKeys + readonly property Loader naviationHighlight: keyboard.naviationHighlight + readonly property ListView wordCandidateView: keyboard.wordCandidateView + readonly property Item wordCandidateContextMenu: keyboard.wordCandidateContextMenu + readonly property ShadowInputControl shadowInputControl: keyboard.shadowInputControl + readonly property TextInput shadowInput: keyboard.shadowInputControl.textEdit + readonly property SelectionControl selectionControl: Utils.findChildByProperty(inputPanel, "objectName", "selectionControl", null) readonly property var anchorHandle: selectionControl.children[0] readonly property var cursorHandle: selectionControl.children[1] - readonly property var fullScreenModeSelectionControl: Utils.findChildByProperty(inputPanel, "objectName", "fullScreenModeSelectionControl", null) + readonly property SelectionControl fullScreenModeSelectionControl: keyboard.fullScreenModeSelectionControl readonly property var fullScreenModeAnchorHandle: fullScreenModeSelectionControl.children[0] readonly property var fullScreenModeCursorHandle: fullScreenModeSelectionControl.children[1] readonly property bool wordCandidateListVisibleHint: InputContext.inputEngine.wordCandidateListVisibleHint @@ -89,8 +58,10 @@ InputPanel { property alias soundEffectSpy: soundEffectSpy property alias inputMethodResultSpy: inputMethodResultSpy property alias wordCandidateListChangedSpy: wordCandidateListChangedSpy + property alias wordCandidateListItemSelectedSpy: wordCandidateListItemSelectedSpy property alias inputMethodSelectionListChangedSpy: inputMethodSelectionListChangedSpy property alias wordCandidateListVisibleSpy: wordCandidateListVisibleSpy + property alias wordCandidateListCurrentIndexSpy: wordCandidateListCurrentIndexSpy property alias shiftStateSpy: shiftStateSpy property alias shadowInputControlVisibleSpy: shadowInputControlVisibleSpy property alias externalLanguageSwitchSpy: externalLanguageSwitchSpy @@ -179,6 +150,12 @@ InputPanel { } SignalSpy { + id: wordCandidateListItemSelectedSpy + target: wordCandidateView.model + signalName: "itemSelected" + } + + SignalSpy { id: inputMethodSelectionListChangedSpy target: InputContext.inputEngine.inputMethod signalName: "selectionListChanged" @@ -191,6 +168,12 @@ InputPanel { } SignalSpy { + id: wordCandidateListCurrentIndexSpy + target: wordCandidateView + signalName: "onCurrentIndexChanged" + } + + SignalSpy { id: wordCandidateContextMenuActiveSpy target: wordCandidateContextMenu signalName: "onActiveChanged" @@ -214,26 +197,18 @@ InputPanel { signalName: "onExternalLanguageSwitch" } - function findChildByProperty(parent, propertyName, propertyValue, compareCb) { - var obj = null - if (parent === null) - return null - var children = parent.children - for (var i = 0; i < children.length; i++) { - obj = children[i] - if (obj.hasOwnProperty(propertyName)) { - if (compareCb !== null) { - if (compareCb(obj[propertyName], propertyValue)) - break - } else if (obj[propertyName] === propertyValue) { - break - } - } - obj = findChildByProperty(obj, propertyName, propertyValue, compareCb) - if (obj) - break - } - return obj + // Disable all animations during tests + Binding { + target: keyboard + property: "noAnimations" + value: true + } + + // Reduce press and hold delay to avoid unnecessary wait during tests + Binding { + target: keyboard + property: "pressAndHoldDelay" + value: 50 } function isLocaleSupported(inputLocale) { @@ -252,6 +227,42 @@ InputPanel { VirtualKeyboardSettings.activeLocales = activeLocales } + function mapKeyboardFunction(keyboardFunctionName) { + if (keyboardFunctionName === "HideInputPanel") + return QtVirtualKeyboard.KeyboardFunction.HideInputPanel + if (keyboardFunctionName === "ChangeLanguage") + return QtVirtualKeyboard.KeyboardFunction.ChangeLanguage + if (keyboardFunctionName === "ToggleHandwritingMode") + return QtVirtualKeyboard.KeyboardFunction.ToggleHandwritingMode + return -1 + } + + function doKeyboardFunction(keyboardFunctionName) { + const keyboardFunction = mapKeyboardFunction(keyboardFunctionName) + testcase.verify(keyboardFunction !== -1) + keyboard.doKeyboardFunction(keyboardFunction) + } + + function mapKeyboardFunctionKey(functionKeyName) { + if (functionKeyName === "None") + return QtVirtualKeyboard.KeyboardFunctionKeys.None + if (functionKeyName === "Hide") + return QtVirtualKeyboard.KeyboardFunctionKeys.Hide + if (functionKeyName === "Language") + return QtVirtualKeyboard.KeyboardFunctionKeys.Language + if (functionKeyName === "All") + return QtVirtualKeyboard.KeyboardFunctionKeys.All + testcase.fail("Invalid function key '%1'".arg(functionKeyName)) + } + + function setVisibleFunctionKeys(functionKeyNames) { + let functionKeys = QtVirtualKeyboard.KeyboardFunctionKeys.None + for (const functionKeyName of functionKeyNames) { + functionKeys |= mapKeyboardFunctionKey(functionKeyName) + } + VirtualKeyboardSettings.visibleFunctionKeys = functionKeys + } + function setWclAutoHideDelay(wclAutoHideDelay) { VirtualKeyboardSettings.wordCandidateList.autoHideDelay = wclAutoHideDelay } @@ -305,6 +316,10 @@ InputPanel { return InputEngine.InputMode.KoreanHandwriting else if (inputModeName === "Thai") return InputEngine.InputMode.Thai + else if (inputModeName === "Stroke") + return InputEngine.InputMode.Stroke + else if (inputModeName === "Romaji") + return InputEngine.InputMode.Romaji else return -1 } @@ -343,6 +358,8 @@ InputPanel { testcase.verify(InputEngine.InputMode.JapaneseHandwriting !== undefined) testcase.verify(InputEngine.InputMode.KoreanHandwriting !== undefined) testcase.verify(InputEngine.InputMode.Thai !== undefined) + testcase.verify(InputEngine.InputMode.Stroke !== undefined) + testcase.verify(InputEngine.InputMode.Romaji !== undefined) testcase.verify(InputEngine.PatternRecognitionMode.None !== undefined) testcase.verify(InputEngine.PatternRecognitionMode.PatternRecognitionDisabled !== undefined) testcase.verify(InputEngine.PatternRecognitionMode.Handwriting !== undefined) @@ -356,40 +373,6 @@ InputPanel { testcase.verify(SelectionListModel.Role.Dictionary !== undefined) testcase.verify(SelectionListModel.DictionaryType.Default !== undefined) testcase.verify(SelectionListModel.DictionaryType.User !== undefined) - // Unscoped - testcase.verify(InputEngine.Lower !== undefined) - testcase.verify(InputEngine.Upper !== undefined) - testcase.verify(InputEngine.Latin !== undefined) - testcase.verify(InputEngine.Numeric !== undefined) - testcase.verify(InputEngine.Dialable !== undefined) - testcase.verify(InputEngine.Pinyin !== undefined) - testcase.verify(InputEngine.Cangjie !== undefined) - testcase.verify(InputEngine.Zhuyin !== undefined) - testcase.verify(InputEngine.Hangul !== undefined) - testcase.verify(InputEngine.Hiragana !== undefined) - testcase.verify(InputEngine.Katakana !== undefined) - testcase.verify(InputEngine.FullwidthLatin !== undefined) - testcase.verify(InputEngine.Greek !== undefined) - testcase.verify(InputEngine.Cyrillic !== undefined) - testcase.verify(InputEngine.Arabic !== undefined) - testcase.verify(InputEngine.Hebrew !== undefined) - testcase.verify(InputEngine.ChineseHandwriting !== undefined) - testcase.verify(InputEngine.JapaneseHandwriting !== undefined) - testcase.verify(InputEngine.KoreanHandwriting !== undefined) - testcase.verify(InputEngine.Thai !== undefined) - testcase.verify(InputEngine.None !== undefined) - testcase.verify(InputEngine.PatternRecognitionDisabled !== undefined) - testcase.verify(InputEngine.Handwriting !== undefined) - testcase.verify(InputEngine.HandwritingRecoginition !== undefined) - testcase.verify(InputEngine.WordBeforeCursor !== undefined) - testcase.verify(InputEngine.WordAfterCursor !== undefined) - testcase.verify(InputEngine.WordAtCursor !== undefined) - testcase.verify(SelectionListModel.WordCandidateList !== undefined) - testcase.verify(SelectionListModel.DisplayRole !== undefined) - testcase.verify(SelectionListModel.WordCompletionLengthRole !== undefined) - testcase.verify(SelectionListModel.DictionaryType !== undefined) - testcase.verify(SelectionListModel.Default !== undefined) - testcase.verify(SelectionListModel.User !== undefined) } function setExternalLanguageSwitchEnabled(enabled) { @@ -425,6 +408,19 @@ InputPanel { return Utils.findChildByProperty(keyboard, "objectName", objectName, null) } + function mapKeyboardKeyType(keyTypeName) { + if (keyTypeName === "ChangeLanguageKey") + return QtVirtualKeyboard.KeyType.ChangeLanguageKey + if (keyTypeName === "HideKeyboardKey") + return QtVirtualKeyboard.KeyType.HideKeyboardKey + testcase.fail("Invalid key type '%1'".arg(keyTypeName)) + } + + function findKeyByKeyType(keyTypeName) { + const keyType = mapKeyboardKeyType(keyTypeName) + return Utils.findChildByProperty(keyboard, "keyType", keyType, null) + } + function virtualKeyPressOnCurrentLayout(key) { var keyObj = typeof key == "object" && key.hasOwnProperty("key") ? key : findVirtualKey(key) var alternativeKey = false @@ -437,14 +433,14 @@ InputPanel { if (keyObj) { virtualKeyPressPoint = inputPanel.mapFromItem(keyObj, keyObj.width / 2, keyObj.height / 2) testcase.mousePress(inputPanel, virtualKeyPressPoint.x, virtualKeyPressPoint.y) - testcase.wait(20) + testcase.wait(1) if (alternativeKey) { alternativeKeysSpy.wait() var keyIndex = keyObj.effectiveAlternativeKeys.indexOf(key.toLowerCase()) var itemX = keyIndex * keyboard.style.alternateKeysListItemWidth + keyboard.style.alternateKeysListItemWidth / 2 virtualKeyPressPoint.x = inputPanel.mapFromItem(alternativeKeys.listView, itemX, 0).x testcase.mouseMove(inputPanel, virtualKeyPressPoint.x, virtualKeyPressPoint.y) - testcase.waitForRendering(inputPanel) + testcase.wait(1) } return true } @@ -453,7 +449,7 @@ InputPanel { function multiLayoutKeyActionHelper(key, keyActionOnCurrentLayoutCb) { if (!keyboardLayoutLoader.item) { - console.warn("Key not found \\u%1 (keyboard layout not loaded)".arg(key.charCodeAt(0).toString(16))) + console.warn("Key not found \\u%1 (keyboard layout not loaded)".arg(typeof key == "string" ? key.charCodeAt(0).toString(16) : key.toString(16))) return false } var success = keyActionOnCurrentLayoutCb(key) @@ -496,7 +492,7 @@ InputPanel { success = keyActionOnCurrentLayoutCb(key) } if (!success) - console.warn("Key not found \\u%1".arg(key.charCodeAt(0).toString(16))) + console.warn("Key not found \\u%1".arg(typeof key == "string" ? key.charCodeAt(0).toString(16) : key.toString(16))) return success } @@ -531,7 +527,6 @@ InputPanel { function virtualKeyClick(key) { if (virtualKeyPress(key)) { virtualKeyRelease() - testcase.waitForRendering(inputPanel) return true } return false @@ -539,13 +534,7 @@ InputPanel { function emulateNavigationKeyClick(navigationKey) { testcase.keyClick(navigationKey) - while (inputPanel.naviationHighlightAnimating) - testcase.wait(inputPanel.naviationHighlight.moveDuration / 2) - } - - function navigationHighlightContains(point) { - var navigationPoint = inputPanel.mapToItem(inputPanel.naviationHighlight, point.x, point.y) - return inputPanel.naviationHighlight.contains(Qt.point(navigationPoint.x, navigationPoint.y)) + testcase.wait(50) } function navigateToKeyOnPoint(point) { @@ -553,7 +542,7 @@ InputPanel { if (inputPanel.naviationHighlight.visible) { while (true) { var navigationPoint = inputPanel.mapToItem(inputPanel.naviationHighlight, point.x, point.y) - if (navigationHighlightContains(point)) + if (inputPanel.naviationHighlight.contains(Qt.point(navigationPoint.x, navigationPoint.y))) return true if (inputPanel.naviationHighlight.y > point.y) emulateNavigationKeyClick(Qt.Key_Up) @@ -613,12 +602,9 @@ InputPanel { function activateNavigationKeyMode() { if (!inputPanel.naviationHighlight.visible) { - inputPanel.naviationHighlight.moveDuration = 0 - inputPanel.naviationHighlight.resizeDuration = 0 emulateNavigationKeyClick(Qt.Key_Right) if (inputPanel.naviationHighlight.visible) { - while (inputPanel.naviationHighlightAnimating) - testcase.wait(inputPanel.naviationHighlight.moveDuration / 2) + testcase.wait(1) } } return inputPanel.naviationHighlight.visible @@ -658,6 +644,9 @@ InputPanel { origIndex = inputPanel.wordCandidateView.currentIndex } if (origIndex !== -1) { + while (inputPanel.wordCandidateView.currentIndex > 0) { + inputPanel.wordCandidateView.decrementCurrentIndex() + } while (true) { if (inputPanel.wordCandidateView.model.dataAt(inputPanel.wordCandidateView.currentIndex) === suggestion) { suggestionFound = true @@ -672,7 +661,6 @@ InputPanel { inputPanel.wordCandidateView.decrementCurrentIndex() } } - testcase.waitForRendering(inputPanel) } return suggestionFound } @@ -680,7 +668,6 @@ InputPanel { function selectionListSelectCurrentItem() { if (!inputPanel.wordCandidateView.currentItem) return false - testcase.wait(200) testcase.verify(inputPanel.wordCandidateView.currentItem, "Expected wordCandidateView to have a currentItem, but it's null." + " Its property values at the time of failure are:" @@ -696,7 +683,6 @@ InputPanel { inputPanel.wordCandidateView.currentItem.width / 2, inputPanel.wordCandidateView.currentItem.height / 2) testcase.mouseClick(inputPanel, itemPos.x, itemPos.y, Qt.LeftButton, 0, 20) - testcase.waitForRendering(inputPanel) return true } @@ -730,7 +716,6 @@ InputPanel { var wordCandidateContextMenuList = Utils.findChildByProperty(keyboard, "objectName", "wordCandidateContextMenuList", null) if (wordCandidateContextMenuList.currentIndex !== index) { wordCandidateContextMenuList.currentIndex = index - testcase.waitForRendering(inputPanel) } if (!wordCandidateContextMenuList.currentItem) return false @@ -738,10 +723,13 @@ InputPanel { wordCandidateContextMenuList.currentItem.width / 2, wordCandidateContextMenuList.currentItem.height / 2) testcase.mouseClick(inputPanel, itemPos.x, itemPos.y, Qt.LeftButton, 0, 20) - testcase.waitForRendering(inputPanel) return true } + function isHandwritingFeatureAvailable() { + return VirtualKeyboardFeatures.Handwriting + } + function setHandwritingMode(enabled) { if (inputPanel.keyboard.handwritingMode !== enabled) { if (!enabled || inputPanel.keyboard.isHandwritingAvailable()) @@ -773,4 +761,12 @@ InputPanel { return false return inputMethod != null && inputMethod.hasOwnProperty("superimposed") && inputMethod.superimposed } + + function closeOnReturn() { + return VirtualKeyboardSettings.closeOnReturn + } + + function setCloseOnReturn(enabled) { + VirtualKeyboardSettings.closeOnReturn = enabled + } } |