summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichal Klocek <michal.klocek@qt.io>2018-05-18 11:27:54 +0200
committerMichal Klocek <michal.klocek@qt.io>2018-05-30 20:10:23 +0000
commitd282d2b1999f3b2b8ad68fbd8e243071f02bab2a (patch)
treeb040575a8ace0f3cfe88b307ef0e57a53e95de41
parent3bef9a742b48ed9b72877c346b7bdf6bbe03eb8c (diff)
Add dialog unit test
Add test to see if correct dialogs are requested Change-Id: I10a7d384b5704fd337b42ea788b6ec6411828d87 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Kai Koehne <kai.koehne@qt.io>
-rw-r--r--tests/auto/quick/dialogs/WebView.qml90
-rw-r--r--tests/auto/quick/dialogs/dialogs.pro13
-rw-r--r--tests/auto/quick/dialogs/dialogs.qrc6
-rw-r--r--tests/auto/quick/dialogs/index.html21
-rw-r--r--tests/auto/quick/dialogs/server.cpp80
-rw-r--r--tests/auto/quick/dialogs/server.h57
-rw-r--r--tests/auto/quick/dialogs/testhandler.cpp74
-rw-r--r--tests/auto/quick/dialogs/testhandler.h60
-rw-r--r--tests/auto/quick/dialogs/tst_dialogs.cpp225
-rw-r--r--tests/auto/quick/quick.pro3
10 files changed, 628 insertions, 1 deletions
diff --git a/tests/auto/quick/dialogs/WebView.qml b/tests/auto/quick/dialogs/WebView.qml
new file mode 100644
index 000000000..6509071b8
--- /dev/null
+++ b/tests/auto/quick/dialogs/WebView.qml
@@ -0,0 +1,90 @@
+/****************************************************************************
+**
+** 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$
+**
+****************************************************************************/
+
+import QtQuick 2.0
+import QtWebEngine 1.4
+import QtQuick.Window 2.0
+import QtTest 1.0
+import io.qt.tester 1.0
+
+Window {
+ width: 50
+ height: 50
+ visible: true
+
+ TestHandler {
+ id: handler
+ onJavaScript: function(script) {
+ view.runJavaScript(script , function(result) {
+ handler.ready = true
+ })
+ }
+ onLoadPage: function(url) {
+ if (view.url === url) {
+ handler.ready = true
+ return
+ }
+ view.url = url
+ }
+ }
+
+ WebEngineView {
+ id: view
+ anchors.fill: parent
+ onLoadingChanged: function(reqeust) {
+ if (reqeust.status === WebEngineView.LoadSucceededStatus) {
+ handler.ready = true
+ }
+ }
+
+ onContextMenuRequested: function(request) {
+ request.accepted = true;
+ handler.request = request;
+ }
+
+ onAuthenticationDialogRequested: function(request) {
+ request.accepted = true;
+ handler.request = request;
+ }
+
+ onJavaScriptDialogRequested: function(request) {
+ request.accepted = true;
+ handler.request = request;
+ }
+
+ onColorDialogRequested: function(request) {
+ request.accepted = true;
+ handler.request = request;
+ }
+
+ onFileDialogRequested: function(request) {
+ request.accepted = true;
+ handler.request = request;
+ }
+ }
+}
diff --git a/tests/auto/quick/dialogs/dialogs.pro b/tests/auto/quick/dialogs/dialogs.pro
new file mode 100644
index 000000000..e262c3814
--- /dev/null
+++ b/tests/auto/quick/dialogs/dialogs.pro
@@ -0,0 +1,13 @@
+include(../tests.pri)
+QT += 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
new file mode 100644
index 000000000..a0715dbce
--- /dev/null
+++ b/tests/auto/quick/dialogs/dialogs.qrc
@@ -0,0 +1,6 @@
+<RCC>
+ <qresource prefix="/">
+ <file>index.html</file>
+ <file>WebView.qml</file>
+ </qresource>
+</RCC>
diff --git a/tests/auto/quick/dialogs/index.html b/tests/auto/quick/dialogs/index.html
new file mode 100644
index 000000000..8b0520a0e
--- /dev/null
+++ b/tests/auto/quick/dialogs/index.html
@@ -0,0 +1,21 @@
+<!DOCTYPE html>
+<html lang="en">
+ <head>
+ <meta charset="utf-8">
+ <style type="text/css">
+ .fullscreen
+ {
+ position:absolute;
+ left: 0;
+ top: 0;
+ width: 100%;
+ height: 100%;
+ }
+ </style>
+ </head>
+ <body>
+ <button class="fullscreen" id="buttonOne">Click Me</button>
+ <input type="color" id="colorpicker" value="#ff0000" style="visibility:hidden"/>
+ <input type="file" id="filepicker" accept=".cpp, .html, .h, .png, .qdoc, .qml" style="visibility:hidden"/>
+ </body>
+</html>
diff --git a/tests/auto/quick/dialogs/server.cpp b/tests/auto/quick/dialogs/server.cpp
new file mode 100644
index 000000000..dc9cfe582
--- /dev/null
+++ b/tests/auto/quick/dialogs/server.cpp
@@ -0,0 +1,80 @@
+/****************************************************************************
+**
+** 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)
+{
+ m_data.clear();
+ connect(&m_server, &QTcpServer::newConnection, this, &Server::handleNewConnection);
+}
+
+bool Server::isListening()
+{
+ return m_server.isListening();
+}
+
+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;
+
+ if (m_data.contains(QByteArrayLiteral("OPEN_AUTH")))
+ socket->write("HTTP/1.1 401 Unauthorized\nWWW-Authenticate: "
+ "Basic realm=\"Very Restricted Area\"\r\n\r\n");
+ if (m_data.contains(QByteArrayLiteral("OPEN_PROXY")))
+ socket->write("HTTP/1.1 407 Proxy Auth Required\nProxy-Authenticate: "
+ "Basic realm=\"Proxy requires authentication\"\r\n\r\n");
+ m_data.clear();
+ socket->disconnectFromHost();
+}
diff --git a/tests/auto/quick/dialogs/server.h b/tests/auto/quick/dialogs/server.h
new file mode 100644
index 000000000..24da47523
--- /dev/null
+++ b/tests/auto/quick/dialogs/server.h
@@ -0,0 +1,57 @@
+/****************************************************************************
+**
+** 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();
+
+public slots:
+ void run();
+
+private slots:
+ void handleNewConnection();
+ void handleReadReady();
+
+private:
+ QByteArray m_data;
+ QTcpServer m_server;
+
+};
+
+#endif // SERVER_H
diff --git a/tests/auto/quick/dialogs/testhandler.cpp b/tests/auto/quick/dialogs/testhandler.cpp
new file mode 100644
index 000000000..bdd63a547
--- /dev/null
+++ b/tests/auto/quick/dialogs/testhandler.cpp
@@ -0,0 +1,74 @@
+/****************************************************************************
+**
+** 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 "testhandler.h"
+
+TestHandler::TestHandler(QObject *parent) : QObject(parent)
+{
+ setObjectName(QStringLiteral("TestListner"));
+}
+
+QObject* TestHandler::request() const
+{
+ return m_request;
+}
+
+void TestHandler::setRequest(QObject *request)
+{
+ if (m_request == request)
+ return;
+
+ m_request = request;
+ emit requestChanged(m_request);
+}
+
+void TestHandler::runJavaScript(const QString &script)
+{
+ m_ready = false;
+ emit javaScript(script);
+}
+
+void TestHandler::load(const QUrl &page)
+{
+ m_ready = false;
+ emit loadPage(page);
+}
+
+bool TestHandler::ready() const
+{
+ return m_ready;
+}
+
+void TestHandler::setReady(bool ready)
+{
+ if (m_ready == ready)
+ return;
+
+ m_ready = ready;
+ emit readyChanged(ready);
+}
diff --git a/tests/auto/quick/dialogs/testhandler.h b/tests/auto/quick/dialogs/testhandler.h
new file mode 100644
index 000000000..93ecfcdcb
--- /dev/null
+++ b/tests/auto/quick/dialogs/testhandler.h
@@ -0,0 +1,60 @@
+/****************************************************************************
+**
+** 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 TESTHANDLER_H
+#define TESTHANDLER_H
+
+#include <QObject>
+
+class TestHandler : public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(QObject* request READ request WRITE setRequest NOTIFY requestChanged)
+ Q_PROPERTY(bool ready READ ready WRITE setReady NOTIFY readyChanged)
+public:
+ explicit TestHandler(QObject *parent = nullptr);
+ QObject* request() const;
+
+ bool ready() const;
+ void setReady(bool ready);
+ void setRequest(QObject *request);
+ void runJavaScript(const QString &script);
+ void load(const QUrl &page);
+
+signals:
+ void loadPage(const QUrl &page);
+ void javaScript(const QString &script);
+ void requestChanged(QObject *request);
+ void readyChanged(bool ready);
+
+private:
+ QObject *m_request = nullptr;
+ bool m_ready = false;
+};
+
+#endif // TESTHANDLER_H
diff --git a/tests/auto/quick/dialogs/tst_dialogs.cpp b/tests/auto/quick/dialogs/tst_dialogs.cpp
new file mode 100644
index 000000000..e1032f16c
--- /dev/null
+++ b/tests/auto/quick/dialogs/tst_dialogs.cpp
@@ -0,0 +1,225 @@
+/****************************************************************************
+**
+** 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 "qtwebengineglobal.h"
+#include "testhandler.h"
+#include "server.h"
+#include <QtWebEngine/private/qquickwebenginedialogrequests_p.h>
+#include <QtWebEngine/private/qquickwebenginecontextmenurequest_p.h>
+#include <QQuickWebEngineProfile>
+#include <QQmlApplicationEngine>
+#include <QQuickWindow>
+#include <QTest>
+#include <QSignalSpy>
+#include <QNetworkProxy>
+
+
+class tst_Dialogs : public QObject {
+ Q_OBJECT
+public:
+ tst_Dialogs(){}
+
+private slots:
+ void initTestCase();
+ void init();
+ void contextMenuRequested();
+ void javaScriptDialogRequested();
+ void javaScriptDialogRequested_data();
+ void colorDialogRequested();
+ void fileDialogRequested();
+ void authenticationDialogRequested_data();
+ void authenticationDialogRequested();
+
+private:
+ void createDialog(const QLatin1String& dialog, bool &ok);
+private:
+ QScopedPointer<QQmlApplicationEngine> m_engine;
+ QQuickWindow *m_widnow;
+ TestHandler *m_listner;
+};
+
+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);
+
+ QNetworkProxy proxy;
+ proxy.setType(QNetworkProxy::HttpProxy);
+ proxy.setHostName("localhost");
+ proxy.setPort(5555);
+ QNetworkProxy::setApplicationProxy(proxy);
+}
+
+void tst_Dialogs::init()
+{
+ m_listner->setRequest(nullptr);
+ m_listner->setReady(false);
+}
+
+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);
+ ok = true;
+}
+
+void tst_Dialogs::colorDialogRequested()
+{
+ m_listner->load(QUrl("qrc:/index.html"));
+ QTRY_VERIFY(m_listner->ready());
+ bool ok = false;
+ createDialog(QLatin1String("colorpicker"), ok);
+ if (ok) {
+ auto dialog = qobject_cast<QQuickWebEngineColorDialogRequest*>(m_listner->request());
+ QVERIFY2(dialog, "Incorrect dialog requested");
+ dialog->dialogReject();
+ QVERIFY2(dialog->isAccepted(), "Dialog is not accepted");
+ QCOMPARE(dialog->color(), QColor("#ff0000"));
+ }
+}
+
+void tst_Dialogs::contextMenuRequested()
+{
+ m_listner->load(QUrl("qrc:/index.html"));
+ QTRY_VERIFY(m_listner->ready());
+ 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());
+ QVERIFY2(dialog, "Incorrect dialog requested");
+}
+
+void tst_Dialogs::fileDialogRequested()
+{
+ m_listner->load(QUrl("qrc:/index.html"));
+ QTRY_VERIFY(m_listner->ready());
+ bool ok = false;
+ createDialog(QLatin1String("filepicker"), ok);
+ if (ok) {
+ auto dialog = qobject_cast<QQuickWebEngineFileDialogRequest*>(m_listner->request());
+ QVERIFY2(dialog, "Incorrect dialog requested");
+ dialog->dialogReject();
+ QVERIFY2(dialog->isAccepted(), "Dialog is not accepted");
+ QStringList mimeTypes {".cpp", ".html", ".h" , ".png", ".qdoc", ".qml"};
+ QCOMPARE(dialog->acceptedMimeTypes(), mimeTypes);
+ }
+}
+
+void tst_Dialogs::authenticationDialogRequested_data()
+{
+ QTest::addColumn<QUrl>("url");
+ QTest::addColumn<QQuickWebEngineAuthenticationDialogRequest::AuthenticationType>("type");
+ QTest::addColumn<QString>("realm");
+ QTest::newRow("Http Authentication Dialog") << QUrl("http://localhost:5555/OPEN_AUTH")
+ << QQuickWebEngineAuthenticationDialogRequest::AuthenticationTypeHTTP
+ << QStringLiteral("Very Restricted Area");
+ QTest::newRow("Proxy Authentication Dialog") << QUrl("http://localhost.:5555/OPEN_PROXY")
+ << QQuickWebEngineAuthenticationDialogRequest::AuthenticationTypeProxy
+ << QStringLiteral("Proxy requires authentication");
+}
+
+void tst_Dialogs::authenticationDialogRequested()
+{
+ QFETCH(QUrl, url);
+ QFETCH(QQuickWebEngineAuthenticationDialogRequest::AuthenticationType, type);
+ QFETCH(QString, realm);
+
+ Server server;
+ server.run();
+ QTRY_VERIFY2(server.isListening(), "Could not setup authentication server");
+
+ QSignalSpy dialogSpy(m_listner, &TestHandler::requestChanged);
+ m_listner->load(url);
+
+ QTRY_COMPARE(dialogSpy.count(), 1);
+ auto dialog = qobject_cast<QQuickWebEngineAuthenticationDialogRequest*>(m_listner->request());
+ QVERIFY2(dialog, "Incorrect dialog requested");
+ dialog->dialogReject();
+ QVERIFY2(dialog->isAccepted(), "Dialog is not accepted");
+ QCOMPARE(dialog->type(), type);
+ QCOMPARE(dialog->realm(),realm);
+ QCOMPARE(dialog->url(), url);
+ QCOMPARE(dialog->proxyHost(), "localhost");
+}
+
+void tst_Dialogs::javaScriptDialogRequested_data()
+{
+ QTest::addColumn<QString>("script");
+ QTest::addColumn<QQuickWebEngineJavaScriptDialogRequest::DialogType>("type");
+ QTest::addColumn<QString>("message");
+ QTest::addColumn<QString>("defaultText");
+ QTest::newRow("AlertDialog") << QStringLiteral("alert('This is the Alert Dialog !')")
+ << QQuickWebEngineJavaScriptDialogRequest::DialogTypeAlert
+ << QStringLiteral("This is the Alert Dialog !")
+ << QString();
+ QTest::newRow("PromptDialog")<< QStringLiteral("prompt('Is this the Prompt Dialog ?', 'Yes')")
+ << QQuickWebEngineJavaScriptDialogRequest::DialogTypePrompt
+ << QStringLiteral("Is this the Prompt Dialog ?")
+ << QStringLiteral("Yes");
+ QTest::newRow("ConfirmDialog")<< QStringLiteral("confirm('This is the Confirm Dialog.')")
+ << QQuickWebEngineJavaScriptDialogRequest::DialogTypeConfirm
+ << QStringLiteral("This is the Confirm Dialog.")
+ << QString();
+}
+
+void tst_Dialogs::javaScriptDialogRequested()
+{
+ QFETCH(QString, script);
+ QFETCH(QQuickWebEngineJavaScriptDialogRequest::DialogType, type);
+ QFETCH(QString, message);
+ QFETCH(QString, defaultText);
+
+ m_listner->load(QUrl("qrc:/index.html"));
+ QTRY_VERIFY(m_listner->ready());
+
+ QSignalSpy dialogSpy(m_listner, &TestHandler::requestChanged);
+ m_listner->runJavaScript(script);
+ QTRY_COMPARE(dialogSpy.count(), 1);
+ auto dialog = qobject_cast<QQuickWebEngineJavaScriptDialogRequest*>(m_listner->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);
+}
+
+#include "tst_dialogs.moc"
+QTEST_MAIN(tst_Dialogs)
+
diff --git a/tests/auto/quick/quick.pro b/tests/auto/quick/quick.pro
index 56c7d02aa..a28a401e9 100644
--- a/tests/auto/quick/quick.pro
+++ b/tests/auto/quick/quick.pro
@@ -3,6 +3,7 @@ QT_FOR_CONFIG += webengine-private
TEMPLATE = subdirs
SUBDIRS += \
+ dialogs \
inspectorserver \
publicapi \
qquickwebenginedefaultsurfaceformat \
@@ -15,4 +16,4 @@ qtConfig(webengine-testsupport) {
}
# QTBUG-66055
-boot2qt: SUBDIRS -= inspectorserver qquickwebenginedefaultsurfaceformat qquickwebengineview qmltests
+boot2qt: SUBDIRS -= inspectorserver qquickwebenginedefaultsurfaceformat qquickwebengineview qmltests dialogs