diff options
Diffstat (limited to 'tests/auto')
8 files changed, 235 insertions, 105 deletions
diff --git a/tests/auto/quick/qmltests/data/tst_settings.qml b/tests/auto/quick/qmltests/data/tst_settings.qml index 0c37d9569..2ff4f9c3c 100644 --- a/tests/auto/quick/qmltests/data/tst_settings.qml +++ b/tests/auto/quick/qmltests/data/tst_settings.qml @@ -1,39 +1,26 @@ /**************************************************************************** ** ** Copyright (C) 2016 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ +** Contact: https://www.qt.io/licensing/ ** ** This file is part of the QtWebEngine module of the Qt Toolkit. ** -** $QT_BEGIN_LICENSE:LGPL$ +** $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 http://www.qt.io/terms-conditions. For further -** information use the contact form at http://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 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** As a special exception, The Qt Company gives you certain additional -** rights. These rights are described in The Qt Company LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** 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.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** +** 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$ ** diff --git a/tests/auto/quick/qquickwebenginedefaultsurfaceformat/tst_qquickwebenginedefaultsurfaceformat.cpp b/tests/auto/quick/qquickwebenginedefaultsurfaceformat/tst_qquickwebenginedefaultsurfaceformat.cpp index 0139d266f..734c4ff7a 100644 --- a/tests/auto/quick/qquickwebenginedefaultsurfaceformat/tst_qquickwebenginedefaultsurfaceformat.cpp +++ b/tests/auto/quick/qquickwebenginedefaultsurfaceformat/tst_qquickwebenginedefaultsurfaceformat.cpp @@ -1,34 +1,26 @@ /**************************************************************************** ** ** Copyright (C) 2016 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ +** Contact: https://www.qt.io/licensing/ ** ** This file is part of the QtWebEngine module of the Qt Toolkit. ** -** $QT_BEGIN_LICENSE:LGPL$ +** $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 http://www.qt.io/terms-conditions. For further -** information use the contact form at http://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.LGPLv3 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.html. +** 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 2.0 or later as published by the Free -** Software Foundation and appearing in the file LICENSE.GPL included in -** the packaging of this file. Please review the following information to -** ensure the GNU General Public License version 2.0 requirements will be -** met: http://www.gnu.org/licenses/gpl-2.0.html. +** 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$ ** diff --git a/tests/auto/quick/qquickwebengineview/tst_qquickwebengineview.cpp b/tests/auto/quick/qquickwebengineview/tst_qquickwebengineview.cpp index 7af2263be..a64197b1c 100644 --- a/tests/auto/quick/qquickwebengineview/tst_qquickwebengineview.cpp +++ b/tests/auto/quick/qquickwebengineview/tst_qquickwebengineview.cpp @@ -35,8 +35,10 @@ #include <QtQml/QQmlEngine> #include <QtTest/QtTest> #include <QtWebEngine/QQuickWebEngineProfile> +#include <private/qinputmethod_p.h> #include <private/qquickwebengineview_p.h> #include <private/qquickwebenginesettings_p.h> +#include <qpa/qplatforminputcontext.h> #include <functional> @@ -71,6 +73,8 @@ private Q_SLOTS: void inputMethod(); void inputMethodHints(); + void interruptImeTextComposition_data(); + void interruptImeTextComposition(); void basicRenderingSanity(); void setZoomFactor(); void printToPdf(); @@ -463,6 +467,96 @@ void tst_QQuickWebEngineView::inputMethod() QVERIFY(!view->flags().testFlag(QQuickItem::ItemAcceptsInputMethod)); } +class TestInputContext : public QPlatformInputContext +{ +public: + TestInputContext() + : commitCallCount(0) + , resetCallCount(0) + { + QInputMethodPrivate* inputMethodPrivate = QInputMethodPrivate::get(qApp->inputMethod()); + inputMethodPrivate->testContext = this; + } + + ~TestInputContext() + { + QInputMethodPrivate* inputMethodPrivate = QInputMethodPrivate::get(qApp->inputMethod()); + inputMethodPrivate->testContext = 0; + } + + virtual void commit() { + commitCallCount++; + } + + virtual void reset() { + resetCallCount++; + } + + int commitCallCount; + int resetCallCount; +}; + +void tst_QQuickWebEngineView::interruptImeTextComposition_data() +{ + QTest::addColumn<QString>("eventType"); + + QTest::newRow("MouseButton") << QString("MouseButton"); +#ifndef Q_OS_MACOS + QTest::newRow("Touch") << QString("Touch"); +#endif +} + +void tst_QQuickWebEngineView::interruptImeTextComposition() +{ + m_window->show(); + QTRY_VERIFY(qApp->focusObject()); + QQuickItem *input; + + QQuickWebEngineView *view = webEngineView(); + view->settings()->setFocusOnNavigationEnabled(true); + view->loadHtml("<html><body>" + " <input type='text' id='input1' /><br>" + " <input type='text' id='input2' />" + "</body></html>"); + QVERIFY(waitForLoadSucceeded(view)); + + runJavaScript("document.getElementById('input1').focus();"); + QTRY_COMPARE(evaluateJavaScriptSync(view, "document.activeElement.id").toString(), QStringLiteral("input1")); + + TestInputContext testContext; + + // Send temporary text, which makes the editor has composition 'x' + QList<QInputMethodEvent::Attribute> attributes; + QInputMethodEvent event("x", attributes); + input = qobject_cast<QQuickItem *>(qApp->focusObject()); + QGuiApplication::sendEvent(input, &event); + QTRY_COMPARE(evaluateJavaScriptSync(view, "document.getElementById('input1').value").toString(), QStringLiteral("x")); + + // Focus 'input2' input field by an input event + QFETCH(QString, eventType); + if (eventType == "MouseButton") { + QPoint textInputCenter = elementCenter(view, QStringLiteral("input2")); + QTest::mouseClick(view->window(), Qt::LeftButton, 0, textInputCenter); + } else if (eventType == "Touch") { + QPoint textInputCenter = elementCenter(view, QStringLiteral("input2")); + QTouchDevice *touchDevice = QTest::createTouchDevice(); + QTest::touchEvent(view->window(), touchDevice).press(0, textInputCenter, view->window()); + QTest::touchEvent(view->window(), touchDevice).release(0, textInputCenter, view->window()); + } + QTRY_COMPARE(evaluateJavaScriptSync(view, "document.activeElement.id").toString(), QStringLiteral("input2")); +#ifndef Q_OS_WIN + QTRY_COMPARE(testContext.commitCallCount, 1); +#else + QTRY_COMPARE(testContext.resetCallCount, 1); +#endif + + // Check the composition text has been committed + runJavaScript("document.getElementById('input1').focus();"); + QTRY_COMPARE(evaluateJavaScriptSync(view, "document.activeElement.id").toString(), QStringLiteral("input1")); + input = qobject_cast<QQuickItem *>(qApp->focusObject()); + QTRY_COMPARE(input->inputMethodQuery(Qt::ImSurroundingText).toString(), QStringLiteral("x")); +} + void tst_QQuickWebEngineView::inputMethodHints() { m_window->show(); @@ -717,8 +811,8 @@ void tst_QQuickWebEngineView::changeLocale() viewDE->setUrl(url); QVERIFY(waitForLoadFailed(viewDE.data())); - QTRY_VERIFY(!bodyInnerText(viewDE.data()).isEmpty()); - errorLines = bodyInnerText(viewDE.data()).split(QRegExp("[\r\n]"), QString::SkipEmptyParts); + QTRY_VERIFY(!evaluateJavaScriptSync(viewDE.data(), "document.body.innerText").isNull()); + errorLines = evaluateJavaScriptSync(viewDE.data(), "document.body.innerText").toString().split(QRegExp("[\r\n]"), QString::SkipEmptyParts); QCOMPARE(errorLines.first().toUtf8(), QByteArrayLiteral("Diese Website ist nicht erreichbar")); QLocale::setDefault(QLocale("en")); @@ -726,8 +820,8 @@ void tst_QQuickWebEngineView::changeLocale() viewEN->setUrl(url); QVERIFY(waitForLoadFailed(viewEN.data())); - QTRY_VERIFY(!bodyInnerText(viewEN.data()).isEmpty()); - errorLines = bodyInnerText(viewEN.data()).split(QRegExp("[\r\n]"), QString::SkipEmptyParts); + QTRY_VERIFY(!evaluateJavaScriptSync(viewEN.data(), "document.body.innerText").isNull()); + errorLines = evaluateJavaScriptSync(viewEN.data(), "document.body.innerText").toString().split(QRegExp("[\r\n]"), QString::SkipEmptyParts); QCOMPARE(errorLines.first().toUtf8(), QByteArrayLiteral("This site can\xE2\x80\x99t be reached")); // Reset error page @@ -738,8 +832,8 @@ void tst_QQuickWebEngineView::changeLocale() viewDE->setUrl(url); QVERIFY(waitForLoadFailed(viewDE.data())); - QTRY_VERIFY(!bodyInnerText(viewDE.data()).isEmpty()); - errorLines = bodyInnerText(viewDE.data()).split(QRegExp("[\r\n]"), QString::SkipEmptyParts); + QTRY_VERIFY(!evaluateJavaScriptSync(viewDE.data(), "document.body.innerText").isNull()); + errorLines = evaluateJavaScriptSync(viewDE.data(), "document.body.innerText").toString().split(QRegExp("[\r\n]"), QString::SkipEmptyParts); QCOMPARE(errorLines.first().toUtf8(), QByteArrayLiteral("Diese Website ist nicht erreichbar")); } diff --git a/tests/auto/quick/shared/util.h b/tests/auto/quick/shared/util.h index 16456601f..bfe3ff9c6 100644 --- a/tests/auto/quick/shared/util.h +++ b/tests/auto/quick/shared/util.h @@ -30,6 +30,7 @@ #define UTIL_H #include <QEventLoop> +#include <QQmlEngine> #include <QSignalSpy> #include <QTimer> #include <QtTest/QtTest> @@ -120,26 +121,43 @@ inline bool waitForViewportReady(QQuickWebEngineView *webEngineView, int timeout #endif } -inline QString bodyInnerText(QQuickWebEngineView *webEngineView) +inline QVariant evaluateJavaScriptSync(QQuickWebEngineView *view, const QString &script) { - qRegisterMetaType<QQuickWebEngineView::JavaScriptConsoleMessageLevel>("JavaScriptConsoleMessageLevel"); - QSignalSpy consoleMessageSpy(webEngineView, &QQuickWebEngineView::javaScriptConsoleMessage); - - webEngineView->runJavaScript( - "if (document.body == null)" - " console.log('');" - "else" - " console.log(document.body.innerText);" - ); + QQmlEngine *engine = qmlEngine(view); + engine->globalObject().setProperty("called", false); + engine->globalObject().setProperty("result", QJSValue()); + QJSValue callback = engine->evaluate( + "(function callback(r) {" + " called = true;" + " result = r;" + "})" + ); + view->runJavaScript(script, callback); + QTRY_LOOP_IMPL(engine->globalObject().property("called").toBool(), 5000, 50); + if (!engine->globalObject().property("called").toBool()) { + qWarning("JavaScript wasn't evaluated"); + return QVariant(); + } - if (!consoleMessageSpy.wait()) - return QString(); + return engine->globalObject().property("result").toVariant(); +} - QList<QVariant> arguments = consoleMessageSpy.takeFirst(); - if (static_cast<QQuickWebEngineView::JavaScriptConsoleMessageLevel>(arguments.at(0).toInt()) != QQuickWebEngineView::InfoMessageLevel) - return QString(); +inline QPoint elementCenter(QQuickWebEngineView *view, const QString &id) +{ + const QString jsCode( + "(function(){" + " var elem = document.getElementById('" + id + "');" + " var rect = elem.getBoundingClientRect();" + " return [(rect.left + rect.right) / 2, (rect.top + rect.bottom) / 2];" + "})()"); + QVariantList rectList = evaluateJavaScriptSync(view, jsCode).toList(); + + if (rectList.count() != 2) { + qWarning("elementCenter failed."); + return QPoint(); + } - return arguments.at(1).toString(); + return QPoint(rectList.at(0).toInt(), rectList.at(1).toInt()); } inline QString activeElementId(QQuickWebEngineView *webEngineView) diff --git a/tests/auto/widgets/qwebengineaccessibility/tst_qwebengineaccessibility.cpp b/tests/auto/widgets/qwebengineaccessibility/tst_qwebengineaccessibility.cpp index bed2745e3..759158a50 100644 --- a/tests/auto/widgets/qwebengineaccessibility/tst_qwebengineaccessibility.cpp +++ b/tests/auto/widgets/qwebengineaccessibility/tst_qwebengineaccessibility.cpp @@ -259,6 +259,7 @@ void tst_QWebEngineAccessibility::roles_data() QTest::newRow("AX_ROLE_ABBR") << QString("<abbr>a</abbr>") << false << QAccessible::StaticText; QTest::newRow("AX_ROLE_ALERT") << QString("<div role='alert'>alert</div>") << true << QAccessible::AlertMessage; QTest::newRow("AX_ROLE_ALERT_DIALOG") << QString("<div role='alertdialog'>alert</div>") << true << QAccessible::AlertMessage; + //QTest::newRow("AX_ROLE_ANCHOR") << QString("<a>target</a>") << false << QAccessible::Link; // FIXME: The test case might be wrong (see https://codereview.chromium.org/2713193003) QTest::newRow("AX_ROLE_ANNOTATION") << QString("<rt>a</rt>") << false << QAccessible::StaticText; QTest::newRow("AX_ROLE_APPLICATION") << QString("<div role='application'>landmark</div>") << true << QAccessible::Document; QTest::newRow("AX_ROLE_ARTICLE") << QString("<article>a</article>") << true << QAccessible::Section; @@ -270,6 +271,7 @@ void tst_QWebEngineAccessibility::roles_data() //QTest::newRow("AX_ROLE_BUTTON_DROP_DOWN"); // Not a blink accessibility role //QTest::newRow("AX_ROLE_CANVAS") << QString("<canvas width='10' height='10'></canvas>") << true << QAccessible::Canvas; // FIXME: The test case might be wrong (see AXLayoutObject.cpp) QTest::newRow("AX_ROLE_CAPTION") << QString("<table><caption>a</caption></table>") << false << QAccessible::Heading; + //QTest::newRow("AX_ROLE_CARET"); // Not a blink accessibility role //QTest::newRow("AX_ROLE_CELL") << QString("<td role='cell'>a</td>") << true << QAccessible::Cell; // FIXME: Aria role 'cell' should work for <td> QTest::newRow("AX_ROLE_CHECK_BOX") << QString("<input type='checkbox'>a</input>") << false << QAccessible::CheckBox; QTest::newRow("AX_ROLE_CLIENT") << QString("") << true << QAccessible::Client; @@ -378,7 +380,7 @@ void tst_QWebEngineAccessibility::roles_data() QTest::newRow("AX_ROLE_TOOLBAR") << QString("<div role='toolbar'>a</div>") << true << QAccessible::ToolBar; QTest::newRow("AX_ROLE_TOOLTIP") << QString("<div role='tooltip'>a</div>") << true << QAccessible::ToolTip; QTest::newRow("AX_ROLE_TREE") << QString("<div role='tree'>a</div>") << true << QAccessible::Tree; - //QTest::newRow("AX_ROLE_TREE_GRID") << QString("<div role='treegrid'>a</div>") << true << QAccessible::Tree; // FIXME: Aria role 'treegrid' should work + QTest::newRow("AX_ROLE_TREE_GRID") << QString("<div role='treegrid'>a</div>") << true << QAccessible::Tree; QTest::newRow("AX_ROLE_TREE_ITEM") << QString("<div role='treeitem'>a</div>") << true << QAccessible::TreeItem; QTest::newRow("AX_ROLE_VIDEO") << QString("<video><source src='test.mp4' type='video/mp4'></video>") << false << QAccessible::Animation; //QTest::newRow("AX_ROLE_WINDOW"); // No mapping to ARIA role diff --git a/tests/auto/widgets/qwebenginedefaultsurfaceformat/tst_qwebenginedefaultsurfaceformat.cpp b/tests/auto/widgets/qwebenginedefaultsurfaceformat/tst_qwebenginedefaultsurfaceformat.cpp index da47c5f0f..3ac8943a5 100644 --- a/tests/auto/widgets/qwebenginedefaultsurfaceformat/tst_qwebenginedefaultsurfaceformat.cpp +++ b/tests/auto/widgets/qwebenginedefaultsurfaceformat/tst_qwebenginedefaultsurfaceformat.cpp @@ -1,34 +1,26 @@ /**************************************************************************** ** ** Copyright (C) 2016 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ +** Contact: https://www.qt.io/licensing/ ** ** This file is part of the QtWebEngine module of the Qt Toolkit. ** -** $QT_BEGIN_LICENSE:LGPL$ +** $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 http://www.qt.io/terms-conditions. For further -** information use the contact form at http://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.LGPLv3 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.html. +** 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 2.0 or later as published by the Free -** Software Foundation and appearing in the file LICENSE.GPL included in -** the packaging of this file. Please review the following information to -** ensure the GNU General Public License version 2.0 requirements will be -** met: http://www.gnu.org/licenses/gpl-2.0.html. +** 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$ ** diff --git a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp index f8a87f309..5c02d3312 100644 --- a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp +++ b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp @@ -2137,29 +2137,55 @@ void tst_QWebEnginePage::testStopScheduledPageRefresh() void tst_QWebEnginePage::findText() { - QSignalSpy loadSpy(m_page, SIGNAL(loadFinished(bool))); - m_page->setHtml(QString("<html><head></head><body><div>foo bar</div></body></html>")); + QSignalSpy loadSpy(m_view, SIGNAL(loadFinished(bool))); + m_view->setHtml(QString("<html><head></head><body><div>foo bar</div></body></html>")); + + // Showing is required, otherwise all find operations fail. + m_view->show(); QTRY_COMPARE(loadSpy.count(), 1); // Select whole page contents. - m_page->triggerAction(QWebEnginePage::SelectAll); - QTRY_COMPARE(m_page->hasSelection(), true); + m_view->page()->triggerAction(QWebEnginePage::SelectAll); + QTRY_COMPARE(m_view->hasSelection(), true); - // Invoke a stopFinding() operation, which should clear the currently selected text. - m_page->findText(""); - QTRY_VERIFY(m_page->selectedText().isEmpty()); + // Invoking a stopFinding operation will not change or clear the currently selected text, + // if nothing was found beforehand. + { + CallbackSpy<bool> spy; + m_view->findText("", 0, spy.ref()); + QVERIFY(spy.wasCalled()); + QTRY_COMPARE(m_view->selectedText(), QString("foo bar")); + } - QStringList words = (QStringList() << "foo" << "bar"); - foreach (QString subString, words) { - // Invoke a find operation, which should clear the currently selected text, should - // highlight all the found ocurrences, but should not update the selected text to the - // searched for string. - m_page->findText(subString); - QTRY_VERIFY(m_page->selectedText().isEmpty()); - - // Search highlights should be cleared, selected text should still be empty. - m_page->findText(""); - QTRY_VERIFY(m_page->selectedText().isEmpty()); + // Invoking a startFinding operation with text that won't be found, will clear the current + // selection. + { + CallbackSpy<bool> spy; + m_view->findText("Will not be found", 0, spy.ref()); + QCOMPARE(spy.waitForResult(), false); + QTRY_VERIFY(m_view->selectedText().isEmpty()); + } + + // Select whole page contents again. + m_view->page()->triggerAction(QWebEnginePage::SelectAll); + QTRY_COMPARE(m_view->hasSelection(), true); + + // Invoking a startFinding operation with text that will be found, will clear the current + // selection as well. + { + CallbackSpy<bool> spy; + m_view->findText("foo", 0, spy.ref()); + QVERIFY(spy.waitForResult()); + QTRY_VERIFY(m_view->selectedText().isEmpty()); + } + + // Invoking a stopFinding operation after text was found, will set the selected text to the + // found text. + { + CallbackSpy<bool> spy; + m_view->findText("", 0, spy.ref()); + QTRY_VERIFY(spy.wasCalled()); + QTRY_COMPARE(m_view->selectedText(), QString("foo")); } } diff --git a/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp b/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp index f1bb181d1..f46590bdf 100644 --- a/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp +++ b/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp @@ -364,6 +364,9 @@ void tst_QWebEngineView::microFocusCoordinates() void tst_QWebEngineView::focusInputTypes() { + const QPlatformInputContext *context = QGuiApplicationPrivate::platformIntegration()->inputContext(); + bool imeHasHiddenTextCapability = context && context->hasCapability(QPlatformInputContext::HiddenTextCapability); + QWebEngineView webView; webView.show(); QTest::qWaitForWindowExposed(&webView); @@ -372,19 +375,27 @@ void tst_QWebEngineView::focusInputTypes() webView.load(QUrl("qrc:///resources/input_types.html")); QVERIFY(loadFinishedSpy.wait()); + auto inputMethodQuery = [&webView](Qt::InputMethodQuery query) { + QInputMethodQueryEvent event(query); + QApplication::sendEvent(webView.focusProxy(), &event); + return event.value(query); + }; + // 'text' field QPoint textInputCenter = elementCenter(webView.page(), "textInput"); QTest::mouseClick(webView.focusProxy(), Qt::LeftButton, 0, textInputCenter); QTRY_COMPARE(evaluateJavaScriptSync(webView.page(), "document.activeElement.id").toString(), QStringLiteral("textInput")); VERIFY_INPUTMETHOD_HINTS(webView.focusProxy()->inputMethodHints(), Qt::ImhPreferLowercase); QVERIFY(webView.focusProxy()->testAttribute(Qt::WA_InputMethodEnabled)); + QTRY_VERIFY(inputMethodQuery(Qt::ImEnabled).toBool()); // 'password' field QPoint passwordInputCenter = elementCenter(webView.page(), "passwordInput"); QTest::mouseClick(webView.focusProxy(), Qt::LeftButton, 0, passwordInputCenter); QTRY_COMPARE(evaluateJavaScriptSync(webView.page(), "document.activeElement.id").toString(), QStringLiteral("passwordInput")); VERIFY_INPUTMETHOD_HINTS(webView.focusProxy()->inputMethodHints(), (Qt::ImhSensitiveData | Qt::ImhNoPredictiveText | Qt::ImhNoAutoUppercase | Qt::ImhHiddenText)); - QVERIFY(webView.focusProxy()->testAttribute(Qt::WA_InputMethodEnabled)); + QVERIFY(!webView.focusProxy()->testAttribute(Qt::WA_InputMethodEnabled)); + QTRY_COMPARE(inputMethodQuery(Qt::ImEnabled).toBool(), imeHasHiddenTextCapability); // 'tel' field QPoint telInputCenter = elementCenter(webView.page(), "telInput"); @@ -392,6 +403,7 @@ void tst_QWebEngineView::focusInputTypes() QTRY_COMPARE(evaluateJavaScriptSync(webView.page(), "document.activeElement.id").toString(), QStringLiteral("telInput")); VERIFY_INPUTMETHOD_HINTS(webView.focusProxy()->inputMethodHints(), Qt::ImhDialableCharactersOnly); QVERIFY(webView.focusProxy()->testAttribute(Qt::WA_InputMethodEnabled)); + QTRY_VERIFY(inputMethodQuery(Qt::ImEnabled).toBool()); // 'number' field QPoint numberInputCenter = elementCenter(webView.page(), "numberInput"); @@ -399,6 +411,7 @@ void tst_QWebEngineView::focusInputTypes() QTRY_COMPARE(evaluateJavaScriptSync(webView.page(), "document.activeElement.id").toString(), QStringLiteral("numberInput")); VERIFY_INPUTMETHOD_HINTS(webView.focusProxy()->inputMethodHints(), Qt::ImhFormattedNumbersOnly); QVERIFY(webView.focusProxy()->testAttribute(Qt::WA_InputMethodEnabled)); + QTRY_VERIFY(inputMethodQuery(Qt::ImEnabled).toBool()); // 'email' field QPoint emailInputCenter = elementCenter(webView.page(), "emailInput"); @@ -406,6 +419,7 @@ void tst_QWebEngineView::focusInputTypes() QTRY_COMPARE(evaluateJavaScriptSync(webView.page(), "document.activeElement.id").toString(), QStringLiteral("emailInput")); VERIFY_INPUTMETHOD_HINTS(webView.focusProxy()->inputMethodHints(), Qt::ImhEmailCharactersOnly); QVERIFY(webView.focusProxy()->testAttribute(Qt::WA_InputMethodEnabled)); + QTRY_VERIFY(inputMethodQuery(Qt::ImEnabled).toBool()); // 'url' field QPoint urlInputCenter = elementCenter(webView.page(), "urlInput"); @@ -413,24 +427,28 @@ void tst_QWebEngineView::focusInputTypes() QTRY_COMPARE(evaluateJavaScriptSync(webView.page(), "document.activeElement.id").toString(), QStringLiteral("urlInput")); VERIFY_INPUTMETHOD_HINTS(webView.focusProxy()->inputMethodHints(), (Qt::ImhUrlCharactersOnly | Qt::ImhNoPredictiveText | Qt::ImhNoAutoUppercase)); QVERIFY(webView.focusProxy()->testAttribute(Qt::WA_InputMethodEnabled)); + QTRY_VERIFY(inputMethodQuery(Qt::ImEnabled).toBool()); // 'password' field QTest::mouseClick(webView.focusProxy(), Qt::LeftButton, 0, passwordInputCenter); QTRY_COMPARE(evaluateJavaScriptSync(webView.page(), "document.activeElement.id").toString(), QStringLiteral("passwordInput")); VERIFY_INPUTMETHOD_HINTS(webView.focusProxy()->inputMethodHints(), (Qt::ImhSensitiveData | Qt::ImhNoPredictiveText | Qt::ImhNoAutoUppercase | Qt::ImhHiddenText)); - QVERIFY(webView.focusProxy()->testAttribute(Qt::WA_InputMethodEnabled)); + QVERIFY(!webView.focusProxy()->testAttribute(Qt::WA_InputMethodEnabled)); + QTRY_COMPARE(inputMethodQuery(Qt::ImEnabled).toBool(), imeHasHiddenTextCapability); // 'text' type QTest::mouseClick(webView.focusProxy(), Qt::LeftButton, 0, textInputCenter); QTRY_COMPARE(evaluateJavaScriptSync(webView.page(), "document.activeElement.id").toString(), QStringLiteral("textInput")); VERIFY_INPUTMETHOD_HINTS(webView.focusProxy()->inputMethodHints(), Qt::ImhPreferLowercase); QVERIFY(webView.focusProxy()->testAttribute(Qt::WA_InputMethodEnabled)); + QTRY_VERIFY(inputMethodQuery(Qt::ImEnabled).toBool()); // 'password' field QTest::mouseClick(webView.focusProxy(), Qt::LeftButton, 0, passwordInputCenter); QTRY_COMPARE(evaluateJavaScriptSync(webView.page(), "document.activeElement.id").toString(), QStringLiteral("passwordInput")); VERIFY_INPUTMETHOD_HINTS(webView.focusProxy()->inputMethodHints(), (Qt::ImhSensitiveData | Qt::ImhNoPredictiveText | Qt::ImhNoAutoUppercase | Qt::ImhHiddenText)); - QVERIFY(webView.focusProxy()->testAttribute(Qt::WA_InputMethodEnabled)); + QVERIFY(!webView.focusProxy()->testAttribute(Qt::WA_InputMethodEnabled)); + QTRY_COMPARE(inputMethodQuery(Qt::ImEnabled).toBool(), imeHasHiddenTextCapability); // 'text area' field QPoint textAreaCenter = elementCenter(webView.page(), "textArea"); @@ -438,6 +456,7 @@ void tst_QWebEngineView::focusInputTypes() QTRY_COMPARE(evaluateJavaScriptSync(webView.page(), "document.activeElement.id").toString(), QStringLiteral("textArea")); VERIFY_INPUTMETHOD_HINTS(webView.focusProxy()->inputMethodHints(), (Qt::ImhMultiLine | Qt::ImhPreferLowercase)); QVERIFY(webView.focusProxy()->testAttribute(Qt::WA_InputMethodEnabled)); + QTRY_VERIFY(inputMethodQuery(Qt::ImEnabled).toBool()); } class KeyEventRecordingWidget : public QWidget { @@ -1885,7 +1904,7 @@ void tst_QWebEngineView::hiddenText() QTest::mouseClick(view.focusProxy(), Qt::LeftButton, 0, passwordInputCenter); QTRY_COMPARE(evaluateJavaScriptSync(view.page(), "document.activeElement.id").toString(), QStringLiteral("password1")); - QVERIFY(view.focusProxy()->testAttribute(Qt::WA_InputMethodEnabled)); + QVERIFY(!view.focusProxy()->testAttribute(Qt::WA_InputMethodEnabled)); QVERIFY(view.focusProxy()->inputMethodHints() & Qt::ImhHiddenText); QPoint textInputCenter = elementCenter(view.page(), "input1"); @@ -1914,8 +1933,8 @@ void tst_QWebEngineView::emptyInputMethodEvent() QApplication::sendEvent(view.focusProxy(), &emptyEvent); QString inputValue = evaluateJavaScriptSync(view.page(), "document.getElementById('input1').value").toString(); - QCOMPARE(inputValue, QStringLiteral("QtWebEngine")); - QCOMPARE(view.focusProxy()->inputMethodQuery(Qt::ImSurroundingText).toString(), QStringLiteral("QtWebEngine")); + QTRY_COMPARE(inputValue, QStringLiteral("QtWebEngine")); + QTRY_COMPARE(view.focusProxy()->inputMethodQuery(Qt::ImSurroundingText).toString(), QStringLiteral("QtWebEngine")); // Reset: clear input field evaluateJavaScriptSync(view.page(), "var inputEle = document.getElementById('input1').value = ''"); @@ -1928,12 +1947,12 @@ void tst_QWebEngineView::emptyInputMethodEvent() QInputMethodEvent eventComposition("a", attributes); QApplication::sendEvent(view.focusProxy(), &eventComposition); QTRY_COMPARE(evaluateJavaScriptSync(view.page(), "document.getElementById('input1').value").toString(), QStringLiteral("a")); - QVERIFY(view.focusProxy()->inputMethodQuery(Qt::ImSurroundingText).toString().isEmpty()); + QTRY_VERIFY(view.focusProxy()->inputMethodQuery(Qt::ImSurroundingText).toString().isEmpty()); // Cancel IME composition QApplication::sendEvent(view.focusProxy(), &emptyEvent); QTRY_VERIFY(evaluateJavaScriptSync(view.page(), "document.getElementById('input1').value").toString().isEmpty()); - QVERIFY(view.focusProxy()->inputMethodQuery(Qt::ImSurroundingText).toString().isEmpty()); + QTRY_VERIFY(view.focusProxy()->inputMethodQuery(Qt::ImSurroundingText).toString().isEmpty()); // Try key press after cancelled IME composition QTest::keyClick(view.focusProxy(), Qt::Key_B); |