diff options
Diffstat (limited to 'tests/auto/quick/dialogs')
-rw-r--r-- | tests/auto/quick/dialogs/BLACKLIST | 2 | ||||
-rw-r--r-- | tests/auto/quick/dialogs/CMakeLists.txt | 28 | ||||
-rw-r--r-- | tests/auto/quick/dialogs/WebView.qml | 39 | ||||
-rw-r--r-- | tests/auto/quick/dialogs/dialogs.pro | 13 | ||||
-rw-r--r-- | tests/auto/quick/dialogs/dialogs.qrc | 6 | ||||
-rw-r--r-- | tests/auto/quick/dialogs/server.cpp | 79 | ||||
-rw-r--r-- | tests/auto/quick/dialogs/server.h | 59 | ||||
-rw-r--r-- | tests/auto/quick/dialogs/testhandler.cpp | 31 | ||||
-rw-r--r-- | tests/auto/quick/dialogs/testhandler.h | 29 | ||||
-rw-r--r-- | tests/auto/quick/dialogs/tst_dialogs.cpp | 140 |
10 files changed, 100 insertions, 326 deletions
diff --git a/tests/auto/quick/dialogs/BLACKLIST b/tests/auto/quick/dialogs/BLACKLIST deleted file mode 100644 index 6d7e2a2fc..000000000 --- a/tests/auto/quick/dialogs/BLACKLIST +++ /dev/null @@ -1,2 +0,0 @@ -[contextMenuRequested] -osx-10.13 diff --git a/tests/auto/quick/dialogs/CMakeLists.txt b/tests/auto/quick/dialogs/CMakeLists.txt new file mode 100644 index 000000000..4d8dc853b --- /dev/null +++ b/tests/auto/quick/dialogs/CMakeLists.txt @@ -0,0 +1,28 @@ +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + +include(../../httpserver/httpserver.cmake) +include(../../util/util.cmake) + +qt_internal_add_test(tst_dialogs + SOURCES + testhandler.cpp testhandler.h + tst_dialogs.cpp + LIBRARIES + Qt::CorePrivate + Qt::WebEngineQuickPrivate + Test::HttpServer + Test::Util +) + +set(dialogs_resource_files + "WebView.qml" + "index.html" +) + +qt_internal_add_resource(tst_dialogs "dialogs" + PREFIX + "/" + FILES + ${dialogs_resource_files} +) diff --git a/tests/auto/quick/dialogs/WebView.qml b/tests/auto/quick/dialogs/WebView.qml index 01f4ac297..6db0e5777 100644 --- a/tests/auto/quick/dialogs/WebView.qml +++ b/tests/auto/quick/dialogs/WebView.qml @@ -1,36 +1,11 @@ -/**************************************************************************** -** -** Copyright (C) 2018 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$ -** -****************************************************************************/ +// Copyright (C) 2018 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only -import QtQuick 2.0 -import QtWebEngine 1.4 -import QtQuick.Window 2.0 -import QtTest 1.0 -import io.qt.tester 1.0 +import QtQuick +import QtWebEngine +import QtQuick.Window +import QtTest +import io.qt.tester Window { width: 50 diff --git a/tests/auto/quick/dialogs/dialogs.pro b/tests/auto/quick/dialogs/dialogs.pro deleted file mode 100644 index 29d509b20..000000000 --- a/tests/auto/quick/dialogs/dialogs.pro +++ /dev/null @@ -1,13 +0,0 @@ -include(../tests.pri) -QT += core-private webengine webengine-private - -HEADERS += \ - server.h \ - testhandler.h - -SOURCES += \ - server.cpp \ - testhandler.cpp - -RESOURCES += \ - dialogs.qrc diff --git a/tests/auto/quick/dialogs/dialogs.qrc b/tests/auto/quick/dialogs/dialogs.qrc deleted file mode 100644 index a0715dbce..000000000 --- a/tests/auto/quick/dialogs/dialogs.qrc +++ /dev/null @@ -1,6 +0,0 @@ -<RCC> - <qresource prefix="/"> - <file>index.html</file> - <file>WebView.qml</file> - </qresource> -</RCC> diff --git a/tests/auto/quick/dialogs/server.cpp b/tests/auto/quick/dialogs/server.cpp deleted file mode 100644 index dfc7c97ad..000000000 --- a/tests/auto/quick/dialogs/server.cpp +++ /dev/null @@ -1,79 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 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 "server.h" -#include <QDataStream> -#include <QTcpSocket> -#include <QDebug> - -Server::Server(QObject *parent) : QObject(parent) -{ - connect(&m_server, &QTcpServer::newConnection, this, &Server::handleNewConnection); -} - -bool Server::isListening() -{ - return m_server.isListening(); -} - -void Server::setReply(const QByteArray &reply) -{ - m_reply = reply; -} - -void Server::run() -{ - if (!m_server.listen(QHostAddress::LocalHost, 5555)) - qFatal("Could not start the test server"); -} - -void Server::handleNewConnection() -{ - // do one connection at the time - Q_ASSERT(m_data.isEmpty()); - QTcpSocket *socket = m_server.nextPendingConnection(); - Q_ASSERT(socket); - connect(socket, &QAbstractSocket::disconnected, socket, &QObject::deleteLater); - connect(socket, &QAbstractSocket::readyRead, this, &Server::handleReadReady); -} - -void Server::handleReadReady() -{ - QTcpSocket *socket = qobject_cast<QTcpSocket*>(sender()); - Q_ASSERT(socket); - - m_data.append(socket->readAll()); - - //simply wait for whole request - if (!m_data.endsWith("\r\n\r\n")) - return; - - socket->write(m_reply); - m_data.clear(); - socket->disconnectFromHost(); -} diff --git a/tests/auto/quick/dialogs/server.h b/tests/auto/quick/dialogs/server.h deleted file mode 100644 index fa9a73811..000000000 --- a/tests/auto/quick/dialogs/server.h +++ /dev/null @@ -1,59 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 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$ -** -****************************************************************************/ - -#ifndef SERVER_H -#define SERVER_H - -#include <QObject> -#include <QTcpServer> - -class Server : public QObject -{ - Q_OBJECT - -public: - explicit Server(QObject *parent = nullptr); - - bool isListening(); - void setReply(const QByteArray &reply); - -public slots: - void run(); - -private slots: - void handleNewConnection(); - void handleReadReady(); - -private: - QByteArray m_data; - QByteArray m_reply; - QTcpServer m_server; - -}; - -#endif // SERVER_H diff --git a/tests/auto/quick/dialogs/testhandler.cpp b/tests/auto/quick/dialogs/testhandler.cpp index bdd63a547..0596626f1 100644 --- a/tests/auto/quick/dialogs/testhandler.cpp +++ b/tests/auto/quick/dialogs/testhandler.cpp @@ -1,36 +1,11 @@ -/**************************************************************************** -** -** Copyright (C) 2018 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$ -** -****************************************************************************/ +// Copyright (C) 2018 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include "testhandler.h" TestHandler::TestHandler(QObject *parent) : QObject(parent) { - setObjectName(QStringLiteral("TestListner")); + setObjectName(QStringLiteral("TestListener")); } QObject* TestHandler::request() const diff --git a/tests/auto/quick/dialogs/testhandler.h b/tests/auto/quick/dialogs/testhandler.h index 93ecfcdcb..fef41d075 100644 --- a/tests/auto/quick/dialogs/testhandler.h +++ b/tests/auto/quick/dialogs/testhandler.h @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2018 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$ -** -****************************************************************************/ +// Copyright (C) 2018 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #ifndef TESTHANDLER_H #define TESTHANDLER_H diff --git a/tests/auto/quick/dialogs/tst_dialogs.cpp b/tests/auto/quick/dialogs/tst_dialogs.cpp index eee6b2bb6..6f54019c7 100644 --- a/tests/auto/quick/dialogs/tst_dialogs.cpp +++ b/tests/auto/quick/dialogs/tst_dialogs.cpp @@ -1,44 +1,22 @@ -/**************************************************************************** -** -** Copyright (C) 2018 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$ -** -****************************************************************************/ +// Copyright (C) 2018 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include "testhandler.h" -#include "server.h" -#include <QtWebEngine/private/qquickwebenginedialogrequests_p.h> -#include <QtWebEngine/private/qquickwebenginecontextmenurequest_p.h> +#include <quickutil.h> +#include <httpserver.h> + +#include <QtWebEngineQuick/private/qquickwebenginedialogrequests_p.h> +#include <QtWebEngineCore/qwebenginecontextmenurequest.h> #include <QQuickWebEngineProfile> + +#include <QNetworkProxy> #include <QQmlApplicationEngine> #include <QQuickWindow> -#include <QTest> #include <QSignalSpy> -#include <QNetworkProxy> - +#include <QTest> -class tst_Dialogs : public QObject { +class tst_Dialogs : public QObject +{ Q_OBJECT public: tst_Dialogs(){} @@ -55,24 +33,23 @@ private slots: void authenticationDialogRequested(); private: - void createDialog(const QLatin1String& dialog, bool &ok); + void createDialog(const QLatin1String &dialog, bool &ok); private: QScopedPointer<QQmlApplicationEngine> m_engine; - QQuickWindow *m_widnow; - TestHandler *m_listner; + QQuickWindow *m_window; + TestHandler *m_listener; }; void tst_Dialogs::initTestCase() { - QtWebEngine::initialize(); QQuickWebEngineProfile::defaultProfile()->setOffTheRecord(true); qmlRegisterType<TestHandler>("io.qt.tester", 1, 0, "TestHandler"); m_engine.reset(new QQmlApplicationEngine()); m_engine->load(QUrl(QStringLiteral("qrc:/WebView.qml"))); - m_widnow = qobject_cast<QQuickWindow*>(m_engine->rootObjects().first()); - Q_ASSERT(m_widnow); - m_listner = m_widnow->findChild<TestHandler*>(QStringLiteral("TestListner")); - Q_ASSERT(m_listner); + m_window = qobject_cast<QQuickWindow*>(m_engine->rootObjects().first()); + Q_ASSERT(m_window); + m_listener = m_window->findChild<TestHandler*>(QStringLiteral("TestListener")); + Q_ASSERT(m_listener); QNetworkProxy proxy; proxy.setType(QNetworkProxy::HttpProxy); @@ -83,29 +60,29 @@ void tst_Dialogs::initTestCase() void tst_Dialogs::init() { - m_listner->setRequest(nullptr); - m_listner->setReady(false); + m_listener->setRequest(nullptr); + m_listener->setReady(false); } -void tst_Dialogs::createDialog(const QLatin1String& dialog, bool &ok) +void tst_Dialogs::createDialog(const QLatin1String &dialog, bool &ok) { QString trigger = QStringLiteral("document.getElementById('buttonOne').onclick = function() {document.getElementById('%1').click()}"); - QSignalSpy dialogSpy(m_listner, &TestHandler::requestChanged); - m_listner->runJavaScript(trigger.arg(dialog)); - QTRY_VERIFY(m_listner->ready()); - QTest::mouseClick(m_widnow, Qt::LeftButton); - QTRY_COMPARE(dialogSpy.count(), 1); + QSignalSpy dialogSpy(m_listener, &TestHandler::requestChanged); + m_listener->runJavaScript(trigger.arg(dialog)); + QTRY_VERIFY(m_listener->ready()); + QTest::mouseClick(m_window, Qt::LeftButton); + QTRY_COMPARE(dialogSpy.size(), 1); ok = true; } void tst_Dialogs::colorDialogRequested() { - m_listner->load(QUrl("qrc:/index.html")); - QTRY_VERIFY(m_listner->ready()); + m_listener->load(QUrl("qrc:/index.html")); + QTRY_VERIFY(m_listener->ready()); bool ok = false; createDialog(QLatin1String("colorpicker"), ok); if (ok) { - auto dialog = qobject_cast<QQuickWebEngineColorDialogRequest*>(m_listner->request()); + auto *dialog = qobject_cast<QQuickWebEngineColorDialogRequest*>(m_listener->request()); QVERIFY2(dialog, "Incorrect dialog requested"); dialog->dialogReject(); QVERIFY2(dialog->isAccepted(), "Dialog is not accepted"); @@ -115,23 +92,23 @@ void tst_Dialogs::colorDialogRequested() void tst_Dialogs::contextMenuRequested() { - m_listner->load(QUrl("qrc:/index.html")); - QTRY_COMPARE_WITH_TIMEOUT(m_listner->ready(), true, 20000); - QSignalSpy dialogSpy(m_listner, &TestHandler::requestChanged); - QTest::mouseClick(m_widnow, Qt::RightButton); - QTRY_COMPARE(dialogSpy.count(), 1); - auto dialog = qobject_cast<QQuickWebEngineContextMenuRequest*>(m_listner->request()); + m_listener->load(QUrl("qrc:/index.html")); + QTRY_COMPARE_WITH_TIMEOUT(m_listener->ready(), true, 20000); + QSignalSpy dialogSpy(m_listener, &TestHandler::requestChanged); + QTest::mouseClick(m_window, Qt::RightButton); + QTRY_COMPARE(dialogSpy.size(), 1); + auto dialog = qobject_cast<QWebEngineContextMenuRequest *>(m_listener->request()); QVERIFY2(dialog, "Incorrect dialog requested"); } void tst_Dialogs::fileDialogRequested() { - m_listner->load(QUrl("qrc:/index.html")); - QTRY_VERIFY(m_listner->ready()); + m_listener->load(QUrl("qrc:/index.html")); + QTRY_VERIFY(m_listener->ready()); bool ok = false; createDialog(QLatin1String("filepicker"), ok); if (ok) { - auto dialog = qobject_cast<QQuickWebEngineFileDialogRequest*>(m_listner->request()); + auto dialog = qobject_cast<QQuickWebEngineFileDialogRequest*>(m_listener->request()); QVERIFY2(dialog, "Incorrect dialog requested"); dialog->dialogReject(); QVERIFY2(dialog->isAccepted(), "Dialog is not accepted"); @@ -145,7 +122,7 @@ void tst_Dialogs::authenticationDialogRequested_data() QTest::addColumn<QUrl>("url"); QTest::addColumn<QQuickWebEngineAuthenticationDialogRequest::AuthenticationType>("type"); QTest::addColumn<QString>("realm"); - QTest::addColumn<QByteArray>("reply"); + QTest::addColumn<QByteArray>("response"); QTest::newRow("Http Authentication Dialog") << QUrl("http://localhost:5555/") << QQuickWebEngineAuthenticationDialogRequest::AuthenticationTypeHTTP << QStringLiteral("Very Restricted Area") @@ -165,18 +142,19 @@ void tst_Dialogs::authenticationDialogRequested() QFETCH(QUrl, url); QFETCH(QQuickWebEngineAuthenticationDialogRequest::AuthenticationType, type); QFETCH(QString, realm); + QFETCH(QByteArray, response); - QFETCH(QByteArray, reply); - Server server; - server.setReply(reply); - server.run(); - QTRY_VERIFY2(server.isListening(), "Could not setup authentication server"); + HttpServer server(QHostAddress::LocalHost, 5555); + connect(&server, &HttpServer::newRequest, [url, response](HttpReqRep *rr) { + rr->sendResponse(response); + }); + QVERIFY(server.start()); - QSignalSpy dialogSpy(m_listner, &TestHandler::requestChanged); - m_listner->load(url); + QSignalSpy dialogSpy(m_listener, &TestHandler::requestChanged); + m_listener->load(url); - QTRY_COMPARE(dialogSpy.count(), 1); - auto dialog = qobject_cast<QQuickWebEngineAuthenticationDialogRequest*>(m_listner->request()); + QTRY_COMPARE(dialogSpy.size(), 1); + auto *dialog = qobject_cast<QQuickWebEngineAuthenticationDialogRequest*>(m_listener->request()); QVERIFY2(dialog, "Incorrect dialog requested"); dialog->dialogReject(); QVERIFY2(dialog->isAccepted(), "Dialog is not accepted"); @@ -184,6 +162,7 @@ void tst_Dialogs::authenticationDialogRequested() QCOMPARE(dialog->realm(),realm); QCOMPARE(dialog->url(), url); QCOMPARE(dialog->proxyHost(), QStringLiteral("localhost")); + QVERIFY(server.stop()); } void tst_Dialogs::javaScriptDialogRequested_data() @@ -213,22 +192,23 @@ void tst_Dialogs::javaScriptDialogRequested() QFETCH(QString, message); QFETCH(QString, defaultText); - m_listner->load(QUrl("qrc:/index.html")); - QTRY_VERIFY(m_listner->ready()); + m_listener->load(QUrl("qrc:/index.html")); + QTRY_VERIFY(m_listener->ready()); - QSignalSpy dialogSpy(m_listner, &TestHandler::requestChanged); - m_listner->runJavaScript(script); - QTRY_COMPARE(dialogSpy.count(), 1); - auto dialog = qobject_cast<QQuickWebEngineJavaScriptDialogRequest*>(m_listner->request()); + QSignalSpy dialogSpy(m_listener, &TestHandler::requestChanged); + m_listener->runJavaScript(script); + QTRY_COMPARE(dialogSpy.size(), 1); + auto *dialog = qobject_cast<QQuickWebEngineJavaScriptDialogRequest*>(m_listener->request()); QVERIFY2(dialog, "Incorrect dialog requested"); dialog->dialogReject(); QVERIFY2(dialog->isAccepted(), "Dialog is not accepted"); QCOMPARE(dialog->type(), type); QCOMPARE(dialog->message(), message); QCOMPARE(dialog->defaultText(), defaultText); - QTRY_VERIFY(m_listner->ready()); // make sure javascript executes no longer + QTRY_VERIFY(m_listener->ready()); // make sure javascript executes no longer } +static QByteArrayList params; +W_QTEST_MAIN(tst_Dialogs, params) #include "tst_dialogs.moc" -QTEST_MAIN(tst_Dialogs) |