diff options
author | Balazs Egedi <egedib@inf.u-szeged.hu> | 2021-06-16 14:55:18 +0200 |
---|---|---|
committer | Michal Klocek <michal.klocek@qt.io> | 2021-07-06 13:05:49 +0000 |
commit | a060012ecef7ecc60f5518b6718136b22a10dc6b (patch) | |
tree | f8caddb6190f3a4bea0b8e1e161b9e0708333181 /tests/auto/quick/uidelegates | |
parent | ccb3fece7d9306bf2c02fcd80505d6a4c3822f35 (diff) |
Remove Quick Controls 1 UIDelegates and introduce UIDelegates test
- Renamed Controls2Delegates to ControlsDelegates
- Removed option to use Quick Controls 1 delegates
- Added test to check if controls are shown
Task-number: QTBUG-93666
Change-Id: Iccca948615309285db7fc57d14fb1cdcdef28051
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Peter Varga <pvarga@inf.u-szeged.hu>
(cherry picked from commit 4fe808a8c0ecd143199781e9644a46e4b1b90653)
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'tests/auto/quick/uidelegates')
-rw-r--r-- | tests/auto/quick/uidelegates/CMakeLists.txt | 14 | ||||
-rw-r--r-- | tests/auto/quick/uidelegates/tst_uidelegates.cpp | 256 |
2 files changed, 270 insertions, 0 deletions
diff --git a/tests/auto/quick/uidelegates/CMakeLists.txt b/tests/auto/quick/uidelegates/CMakeLists.txt new file mode 100644 index 000000000..d8699ccfc --- /dev/null +++ b/tests/auto/quick/uidelegates/CMakeLists.txt @@ -0,0 +1,14 @@ +include(../../httpserver/httpserver.cmake) +include(../../util/util.cmake) + +qt_internal_add_test(tst_uidelegates + SOURCES + tst_uidelegates.cpp + LIBRARIES + Qt::WebEngineCorePrivate + Qt::WebEngineQuick + Qt::GuiPrivate + Qt::WebEngineQuickPrivate + Test::HttpServer + Test::Util +) diff --git a/tests/auto/quick/uidelegates/tst_uidelegates.cpp b/tests/auto/quick/uidelegates/tst_uidelegates.cpp new file mode 100644 index 000000000..95f083f12 --- /dev/null +++ b/tests/auto/quick/uidelegates/tst_uidelegates.cpp @@ -0,0 +1,256 @@ +/**************************************************************************** +** +** Copyright (C) 2021 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$ +** +****************************************************************************/ + +#include "testwindow.h" +#include "quickutil.h" + +#include <QScopedPointer> +#include <QtQml/QQmlEngine> +#include <QtTest/QtTest> +#include <QtWebEngineQuick/private/qquickwebengineview_p.h> +#include <httpserver.h> +#include <QNetworkProxy> +#include <QObject> + +class tst_UIDelegates : public QObject +{ + Q_OBJECT +public: + tst_UIDelegates(); + +private Q_SLOTS: + void init(); + void initTestCase(); + void cleanup(); + void javaScriptDialog(); + void javaScriptDialog_data(); + void fileDialog(); + void contextMenu(); + void tooltip(); + void colorDialog(); + void authenticationDialog_data(); + void authenticationDialog(); + +private: + inline QQuickWebEngineView *newWebEngineView(); + inline QQuickWebEngineView *webEngineView() const; + void runJavaScript(const QString &script); + QScopedPointer<TestWindow> m_window; + QScopedPointer<QQmlComponent> m_component; +}; + +tst_UIDelegates::tst_UIDelegates() +{ + QtWebEngineQuick::initialize(); + static QQmlEngine *engine = new QQmlEngine(this); + m_component.reset(new QQmlComponent(engine, this)); + m_component->setData(QByteArrayLiteral("import QtQuick\n" + "import QtWebEngine\n" + "WebEngineView {}"), + QUrl()); +} + +QQuickWebEngineView *tst_UIDelegates::newWebEngineView() +{ + QObject *viewInstance = m_component->create(); + QQuickWebEngineView *webEngineView = qobject_cast<QQuickWebEngineView *>(viewInstance); + return webEngineView; +} + +void tst_UIDelegates::init() +{ + m_window.reset(new TestWindow(newWebEngineView())); +} + +void tst_UIDelegates::initTestCase() +{ + QNetworkProxy proxy; + proxy.setType(QNetworkProxy::HttpProxy); + proxy.setHostName("localhost"); + proxy.setPort(5555); + QNetworkProxy::setApplicationProxy(proxy); +} + +void tst_UIDelegates::cleanup() +{ + m_window.reset(); +} + +inline QQuickWebEngineView *tst_UIDelegates::webEngineView() const +{ + return static_cast<QQuickWebEngineView *>(m_window->webEngineView.data()); +} + +void tst_UIDelegates::runJavaScript(const QString &script) +{ + webEngineView()->runJavaScript(script); +} + +void tst_UIDelegates::javaScriptDialog_data() +{ + QTest::addColumn<QString>("javaScriptCode"); + QTest::addColumn<QString>("expectedObjectName"); + + QTest::newRow("AlertDialog") << QString("alert('This is the Alert Dialog!');") + << QString("alertDialog"); + QTest::newRow("ConfirmDialog") << QString("confirm('This is the Confirm Dialog.');") + << QString("confirmDialog"); + QTest::newRow("PromptDialog") << QString("prompt('Is this the Prompt Dialog?', 'Yes');") + << QString("promptDialog"); +} + +void tst_UIDelegates::javaScriptDialog() +{ + QFETCH(QString, javaScriptCode); + QFETCH(QString, expectedObjectName); + + m_window->show(); + QTRY_VERIFY(qApp->focusObject()); + QQuickWebEngineView *view = webEngineView(); + + view->loadHtml("<html><body>" + "</body></html>"); + QVERIFY(waitForLoadSucceeded(view)); + + runJavaScript(javaScriptCode); + QTRY_VERIFY(view->findChild<QObject *>(expectedObjectName)); +} + +void tst_UIDelegates::fileDialog() +{ + QSKIP("There is no FilePicker Control in Quick Controls 2."); + m_window->show(); + QTRY_VERIFY(qApp->focusObject()); + QQuickWebEngineView *view = webEngineView(); + + view->loadHtml("<html><body>" + "<input type='file' id='filePicker'/>" + "</body></html>"); + QVERIFY(waitForLoadSucceeded(view)); + QString filePickerStr = QStringLiteral("filePicker"); + + QPoint filePickerCenter = elementCenter(view, filePickerStr); + QTest::mouseClick(view->window(), Qt::LeftButton, {}, filePickerCenter); + QTRY_VERIFY(view->findChild<QObject *>(filePickerStr)); +} + +void tst_UIDelegates::contextMenu() +{ + m_window->show(); + QTRY_VERIFY(qApp->focusObject()); + QQuickWebEngineView *view = webEngineView(); + + view->loadHtml("<html><body>" + "</body></html>"); + QVERIFY(waitForLoadSucceeded(view)); + + QTest::mouseClick(view->window(), Qt::RightButton); + QTRY_VERIFY(view->findChild<QObject *>(QStringLiteral("menu"))); +} + +void tst_UIDelegates::tooltip() +{ + m_window->show(); + QTRY_VERIFY(qApp->focusObject()); + QQuickWebEngineView *view = webEngineView(); + + view->loadHtml("<html><body>" + "<p id='toolTip' title='I'm a tooltip.'>Hover this text to display a tooltip</p>" + "</body></html>"); + QVERIFY(waitForLoadSucceeded(view)); + QString toolTipStr = QStringLiteral("toolTip"); + + QPoint tooltipCenter = elementCenter(view, toolTipStr); + QPoint windowCenter = QPoint(view->window()->width() / 2, view->window()->height() / 2); + QVERIFY(tooltipCenter.x() == windowCenter.x()); + + int distance = windowCenter.y() - tooltipCenter.y(); + for (int i = 3; i > 0; i--) { + QTest::mouseMove(view->window(), QPoint(windowCenter.x(), windowCenter.y() - distance / i)); + } + QTRY_VERIFY(view->findChild<QObject *>(toolTipStr)); +} + +void tst_UIDelegates::colorDialog() +{ + QSKIP("There is no ColorPicker Control in Quick Controls 2."); + m_window->show(); + QTRY_VERIFY(qApp->focusObject()); + QQuickWebEngineView *view = webEngineView(); + + view->loadHtml("<html><body>" + "<input type='color' id='colorPicker'>" + "</body></html>"); + QVERIFY(waitForLoadSucceeded(view)); + + QPoint filePickerCenter = elementCenter(view, QStringLiteral("colorPicker")); + QTest::mouseClick(view->window(), Qt::LeftButton, {}, filePickerCenter); + QTRY_VERIFY(view->findChild<QObject *>(QStringLiteral("colorDialog"))); +} + +void tst_UIDelegates::authenticationDialog_data() +{ + QTest::addColumn<QUrl>("url"); + QTest::addColumn<QByteArray>("response"); + + QTest::newRow("Http Authentication Dialog") + << QUrl("http://localhost:5555/") + << QByteArrayLiteral("HTTP/1.1 401 Unauthorized\nWWW-Authenticate: " + "Basic realm=\"Very Restricted Area\"\r\n\r\n"); + QTest::newRow("Proxy Authentication Dialog") + << QUrl("http://qt.io/") + << QByteArrayLiteral("HTTP/1.1 407 Proxy Auth Required\nProxy-Authenticate: " + "Basic realm=\"Proxy requires authentication\"\r\n" + "content-length: 0\r\n\r\n"); +} + +void tst_UIDelegates::authenticationDialog() +{ + QFETCH(QUrl, url); + QFETCH(QByteArray, response); + + HttpServer server(QHostAddress::LocalHost, 5555); + connect(&server, &HttpServer::newRequest, + [url, response](HttpReqRep *rr) { rr->sendResponse(response); }); + QVERIFY(server.start()); + + m_window->show(); + QTRY_VERIFY(qApp->focusObject()); + QQuickWebEngineView *view = webEngineView(); + view->loadHtml("<html><body>" + "</body></html>"); + QVERIFY(waitForLoadSucceeded(view)); + + view->setUrl(url); + QTRY_VERIFY(view->findChild<QObject *>(QStringLiteral("authenticationDialog"))); + QVERIFY(server.stop()); +} + +QTEST_MAIN(tst_UIDelegates) +#include "tst_uidelegates.moc" +#include "moc_quickutil.cpp" |