diff options
Diffstat (limited to 'tests/auto/quick')
4 files changed, 152 insertions, 61 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) |