From 84b72e6b2387991f90293984f2666563c93cf13c Mon Sep 17 00:00:00 2001 From: Peter Varga Date: Mon, 24 Apr 2017 14:58:11 +0200 Subject: Add back input method auto tests and test virtual keyboard for Quick This patch also fixes the update of the ItemAcceptsInputMethod flag of QQuickWebEngineView regarding to the focused element in the view. Change-Id: Ic6e39401bdc7ca5fab9cc03e878aa731f23fc147 Reviewed-by: Allan Sandfeld Jensen --- tests/auto/quick/qmltests/data/tst_inputMethod.qml | 76 ++++++++++++++++++++++ tests/auto/quick/qmltests/qmltests.pro | 1 + .../tst_qquickwebengineview.cpp | 49 +++++++++----- .../qquickwebengineviewgraphics.pro | 2 +- tests/auto/quick/shared/util.h | 22 +++++++ 5 files changed, 134 insertions(+), 16 deletions(-) create mode 100644 tests/auto/quick/qmltests/data/tst_inputMethod.qml (limited to 'tests/auto/quick') diff --git a/tests/auto/quick/qmltests/data/tst_inputMethod.qml b/tests/auto/quick/qmltests/data/tst_inputMethod.qml new file mode 100644 index 000000000..c09a8bdd9 --- /dev/null +++ b/tests/auto/quick/qmltests/data/tst_inputMethod.qml @@ -0,0 +1,76 @@ +/**************************************************************************** +** +** Copyright (C) 2017 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 + +TestWebEngineView { + id: webEngineView + width: 200 + height: 400 + + testSupport: WebEngineTestSupport { } + + TestCase { + name: "WebEngineViewInputMethod" + when: windowShown + + function init() { + testSupport.testInputContext.create(); + } + + function cleanup() { + testSupport.testInputContext.release(); + } + + function test_softwareInputPanel() { + verify(!Qt.inputMethod.visible); + webEngineView.loadHtml( + "" + + "
" + + "show(); + QTRY_VERIFY(qApp->focusObject()); + QQuickItem *input; + QQuickWebEngineView *view = webEngineView(); view->setUrl(urlFromTestPath("html/inputmethod.html")); QVERIFY(waitForLoadSucceeded(view)); + input = qobject_cast(qApp->focusObject()); + QVERIFY(!input->flags().testFlag(QQuickItem::ItemAcceptsInputMethod)); QVERIFY(!view->flags().testFlag(QQuickItem::ItemAcceptsInputMethod)); + runJavaScript("document.getElementById('inputField').focus();"); + QTRY_COMPARE(activeElementId(view), QStringLiteral("inputField")); + input = qobject_cast(qApp->focusObject()); + QTRY_VERIFY(input->flags().testFlag(QQuickItem::ItemAcceptsInputMethod)); QVERIFY(view->flags().testFlag(QQuickItem::ItemAcceptsInputMethod)); + runJavaScript("document.getElementById('inputField').blur();"); + QTRY_VERIFY(activeElementId(view).isEmpty()); + input = qobject_cast(qApp->focusObject()); + QTRY_VERIFY(!input->flags().testFlag(QQuickItem::ItemAcceptsInputMethod)); QVERIFY(!view->flags().testFlag(QQuickItem::ItemAcceptsInputMethod)); -#endif } void tst_QQuickWebEngineView::inputMethodHints() { -#if !defined(QQUICKWEBENGINEVIEW_ITEMACCEPTSINPUTMETHOD) - QSKIP("QQUICKWEBENGINEVIEW_ITEMACCEPTSINPUTMETHOD"); -#else - QQuickWebEngineView *view = webEngineView(); + m_window->show(); + QTRY_VERIFY(qApp->focusObject()); + QQuickItem *input; + QQuickWebEngineView *view = webEngineView(); view->setUrl(urlFromTestPath("html/inputmethod.html")); QVERIFY(waitForLoadSucceeded(view)); + // Initialize input fields with values to check input method query is being updated. + runJavaScript("document.getElementById('emailInputField').value = 'a@b.com';"); + runJavaScript("document.getElementById('editableDiv').innerText = 'bla';"); + // Setting focus on an input element results in an element in its shadow tree becoming the focus node. // Input hints should not be set from this shadow tree node but from the input element itself. runJavaScript("document.getElementById('emailInputField').focus();"); + QTRY_COMPARE(activeElementId(view), QStringLiteral("emailInputField")); + input = qobject_cast(qApp->focusObject()); + QTRY_COMPARE(input->inputMethodQuery(Qt::ImSurroundingText).toString(), QString("a@b.com")); + QVERIFY(input->flags().testFlag(QQuickItem::ItemAcceptsInputMethod)); QVERIFY(view->flags().testFlag(QQuickItem::ItemAcceptsInputMethod)); QInputMethodQueryEvent query(Qt::ImHints); - QGuiApplication::sendEvent(view, &query); - Qt::InputMethodHints hints(query.value(Qt::ImHints).toUInt() & Qt::ImhExclusiveInputMask); - QCOMPARE(hints, Qt::ImhEmailCharactersOnly); + QGuiApplication::sendEvent(input, &query); + QTRY_COMPARE(Qt::InputMethodHints(query.value(Qt::ImHints).toUInt() & Qt::ImhExclusiveInputMask), Qt::ImhEmailCharactersOnly); // The focus of an editable DIV is given directly to it, so no shadow root element // is necessary. This tests the WebPage::editorState() method ability to get the // right element without breaking. runJavaScript("document.getElementById('editableDiv').focus();"); + QTRY_COMPARE(activeElementId(view), QStringLiteral("editableDiv")); + input = qobject_cast(qApp->focusObject()); + QTRY_COMPARE(input->inputMethodQuery(Qt::ImSurroundingText).toString(), QString("bla")); + QVERIFY(input->flags().testFlag(QQuickItem::ItemAcceptsInputMethod)); QVERIFY(view->flags().testFlag(QQuickItem::ItemAcceptsInputMethod)); query = QInputMethodQueryEvent(Qt::ImHints); - QGuiApplication::sendEvent(view, &query); - hints = Qt::InputMethodHints(query.value(Qt::ImHints).toUInt()); - QCOMPARE(hints, Qt::ImhNone); -#endif + QGuiApplication::sendEvent(input, &query); + QTRY_COMPARE(Qt::InputMethodHints(query.value(Qt::ImHints).toUInt()), Qt::ImhPreferLowercase | Qt::ImhMultiLine); } void tst_QQuickWebEngineView::setZoomFactor() diff --git a/tests/auto/quick/qquickwebengineviewgraphics/qquickwebengineviewgraphics.pro b/tests/auto/quick/qquickwebengineviewgraphics/qquickwebengineviewgraphics.pro index 9471def00..2a2155e44 100644 --- a/tests/auto/quick/qquickwebengineviewgraphics/qquickwebengineviewgraphics.pro +++ b/tests/auto/quick/qquickwebengineviewgraphics/qquickwebengineviewgraphics.pro @@ -1,4 +1,4 @@ include(../tests.pri) CONFIG -= testcase # remove, once this passes in the CI exists($${TARGET}.qrc):RESOURCES += $${TARGET}.qrc -QT_PRIVATE += webengine-private +QT_PRIVATE += webengine-private gui-private diff --git a/tests/auto/quick/shared/util.h b/tests/auto/quick/shared/util.h index dce0afb8e..98f19bd49 100644 --- a/tests/auto/quick/shared/util.h +++ b/tests/auto/quick/shared/util.h @@ -142,4 +142,26 @@ inline QString bodyInnerText(QQuickWebEngineView *webEngineView) return arguments.at(1).toString(); } +inline QString activeElementId(QQuickWebEngineView *webEngineView) +{ + qRegisterMetaType("JavaScriptConsoleMessageLevel"); + QSignalSpy consoleMessageSpy(webEngineView, &QQuickWebEngineView::javaScriptConsoleMessage); + + webEngineView->runJavaScript( + "if (document.activeElement == null)" + " console.log('');" + "else" + " console.log(document.activeElement.id);" + ); + + if (!consoleMessageSpy.wait()) + return QString(); + + QList arguments = consoleMessageSpy.takeFirst(); + if (static_cast(arguments.at(0).toInt()) != QQuickWebEngineView::InfoMessageLevel) + return QString(); + + return arguments.at(1).toString(); +} + #endif /* UTIL_H */ -- cgit v1.2.3