diff options
Diffstat (limited to 'tests/auto/quick/qmltests')
-rw-r--r-- | tests/auto/quick/qmltests/CMakeLists.txt | 1 | ||||
-rw-r--r-- | tests/auto/quick/qmltests/data/TestWebEngineView.qml | 15 | ||||
-rw-r--r-- | tests/auto/quick/qmltests/data/tst_datalist.qml | 205 | ||||
-rw-r--r-- | tests/auto/quick/qmltests/data/tst_keyboardEvents.qml | 14 |
4 files changed, 221 insertions, 14 deletions
diff --git a/tests/auto/quick/qmltests/CMakeLists.txt b/tests/auto/quick/qmltests/CMakeLists.txt index d878bdfcf..53c8ed231 100644 --- a/tests/auto/quick/qmltests/CMakeLists.txt +++ b/tests/auto/quick/qmltests/CMakeLists.txt @@ -19,6 +19,7 @@ set(testList tst_audioMuted.qml tst_contextMenu.qml tst_basicProfiles.qml + tst_datalist.qml tst_desktopBehaviorLoadHtml.qml tst_download.qml tst_favicon.qml diff --git a/tests/auto/quick/qmltests/data/TestWebEngineView.qml b/tests/auto/quick/qmltests/data/TestWebEngineView.qml index 68417c6c5..869754c90 100644 --- a/tests/auto/quick/qmltests/data/TestWebEngineView.qml +++ b/tests/auto/quick/qmltests/data/TestWebEngineView.qml @@ -113,6 +113,21 @@ WebEngineView { return textSelection; } + function getElementValue(element) { + var elementValue; + runJavaScript("document.getElementById('" + element + "').value", function(result) { + elementValue = result; + }); + testCase.tryVerify(function() { return elementValue != undefined; }); + return elementValue; + } + + function compareElementValue(element, expected) { + testCase.tryVerify(function() { return expected == getElementValue(element); }, 5000, + "Value of element \"" + element + "\" is \"" + expected + "\""); + } + + TestResult { id: testResult } onLoadingChanged: function(load) { diff --git a/tests/auto/quick/qmltests/data/tst_datalist.qml b/tests/auto/quick/qmltests/data/tst_datalist.qml new file mode 100644 index 000000000..66cc49b0c --- /dev/null +++ b/tests/auto/quick/qmltests/data/tst_datalist.qml @@ -0,0 +1,205 @@ +/**************************************************************************** +** +** Copyright (C) 2022 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 +import QtQuick.Controls +import QtTest +import QtWebEngine + +TestWebEngineView { + id: webEngineView + width: 200 + height: 400 + + property string html: "<html><body>" + + "<input id='browserInput' list='browserDatalist'>" + + "<datalist id='browserDatalist'>" + + " <option value='Internet Explorer'>" + + " <option value='Firefox'>" + + " <option value='Chrome'>" + + " <option value='Opera'>" + + " <option value='Safari'>" + + "</datalist>" + + "</body></html>" + + function listView() { + if (webEngineView.parent.visibleChildren.length == 1) { + // No popup case. + return null; + } + + let overlay = null; + for (let i = 0; i < webEngineView.parent.visibleChildren.length; ++i) { + let child = webEngineView.parent.visibleChildren[i]; + if (child instanceof Overlay) { + overlay = child; + break; + } + } + + if (!overlay) + return null; + + let popupItem = null; + for (let i = 0; i < overlay.visibleChildren[0].visibleChildren.length; ++i) { + let child = overlay.visibleChildren[0].visibleChildren[i]; + if (child.objectName == "QQuickPopupItem") { + popupItem = child; + } + } + + if (!popupItem) + return null; + + for (let i = 0; i < popupItem.visibleChildren.length; ++i) { + let child = popupItem.visibleChildren[i]; + if (child instanceof ListView) + return child; + } + + return null; + } + + TestCase { + id: testCase + name: "WebEngineDatalist" + when: windowShown + + function test_showAndHide() { + webEngineView.loadHtml(webEngineView.html); + verify(webEngineView.waitForLoadSucceeded()); + + var values = ""; + webEngineView.runJavaScript( + "(function() {" + + " var browserDatalist = document.getElementById('browserDatalist');" + + " var options = browserDatalist.options;" + + " var result = [];" + + " for (let i = 0; i < options.length; ++i) {" + + " result.push(options[i].value);" + + " }" + + " return result;" + + "})();", function(result) { values = result; }); + tryVerify(function() { return values.length != 0; }); + compare(values, ["Internet Explorer", "Firefox", "Chrome", "Opera", "Safari"]); + compareElementValue("browserInput", ""); + + // Make sure there is no open popup yet. + verify(!listView()); + // Click in the input field. + var browserInputCenter = getElementCenter("browserInput"); + mouseClick(webEngineView, browserInputCenter.x, browserInputCenter.y, Qt.LeftButton); + // Wait for the popup. + tryVerify(function() { return listView() != null; }); + + // No suggestion is selected. + verify(!listView().currentItem); + compare(listView().count, 5); + + // Accepting suggestion does nothing. + keyClick(Qt.Key_Enter); + tryVerify(function() { return listView() != null; }); + verify(!listView().currentItem); + + // Escape should close popup. + keyClick(Qt.Key_Escape); + tryVerify(function() { return listView() == null; }); + + // Key Down should open the popup and select the first suggestion. + keyClick(Qt.Key_Down); + tryVerify(function() { return listView() != null; }); + compare(listView().currentIndex, 0); + verify(listView().currentItem); + } + + function test_keyboardNavigationAndAccept() { + webEngineView.loadHtml(html); + verify(webEngineView.waitForLoadSucceeded()); + setFocusToElement("browserInput"); + + // Make sure there is no open popup yet. + verify(!listView()); + + // Key Down should open the popup and select the first suggestion. + keyClick(Qt.Key_Down); + tryVerify(function() { return listView() != null; }); + compare(listView().currentIndex, 0); + + // Test keyboard navigation in list. + keyClick(Qt.Key_Up); + compare(listView().currentIndex, 4); + keyClick(Qt.Key_Up); + compare(listView().currentIndex, 3); + keyClick(Qt.Key_PageDown); + compare(listView().currentIndex, 4); + keyClick(Qt.Key_PageUp); + compare(listView().currentIndex, 0); + keyClick(Qt.Key_Down); + compare(listView().currentIndex, 1); + keyClick(Qt.Key_Down); + compare(listView().currentIndex, 2); + + // Test accepting suggestion. + compare(listView().currentItem.text, "Chrome"); + keyClick(Qt.Key_Enter); + compareElementValue("browserInput", "Chrome"); + // Accept closes popup. + tryVerify(function() { return listView() == null; }); + + // Clear input field, should not trigger popup. + webEngineView.runJavaScript("document.getElementById('browserInput').value = ''"); + compareElementValue("browserInput", ""); + verify(listView() == null); + } + + function test_filterSuggestion() { + webEngineView.loadHtml(html); + verify(webEngineView.waitForLoadSucceeded()); + setFocusToElement("browserInput"); + + // Make sure there is no open popup yet. + verify(!listView()); + + // Filter suggestions. + keyClick(Qt.Key_F); + tryVerify(function() { return listView() != null; }); + compare(listView().count, 2); + verify(!listView().currentItem); + compare(listView().itemAtIndex(0).text, "Firefox"); + compare(listView().itemAtIndex(1).text, "Safari"); + keyClick(Qt.Key_I); + tryVerify(function() { return listView().count == 1; }); + verify(!listView().currentItem); + compare(listView().itemAtIndex(0).text, "Firefox"); + keyClick(Qt.Key_L); + // Mismatch should close popup. + tryVerify(function() { return listView() == null; }); + compareElementValue("browserInput", "fil"); + } + } +} diff --git a/tests/auto/quick/qmltests/data/tst_keyboardEvents.qml b/tests/auto/quick/qmltests/data/tst_keyboardEvents.qml index 7c594d921..170dde5e7 100644 --- a/tests/auto/quick/qmltests/data/tst_keyboardEvents.qml +++ b/tests/auto/quick/qmltests/data/tst_keyboardEvents.qml @@ -54,20 +54,6 @@ TestWebEngineView { "Element \"" + element + "\" is " + (expected ? "" : "not") + " checked"); } - function getElementValue(element) { - var elementValue; - runJavaScript("document.getElementById('" + element + "').value", function(result) { - elementValue = result; - }); - tryVerify(function() { return elementValue != undefined; }); - return elementValue; - } - - function compareElementValue(element, expected) { - tryVerify(function() { return expected == getElementValue(element); }, 5000, - "Value of element \"" + element + "\" is \"" + expected + "\""); - } - function test_keyboardEvents() { webEngineView.url = Qt.resolvedUrl("keyboardEvents.html"); verify(webEngineView.waitForLoadSucceeded()); |