summaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorPeter Varga <pvarga@inf.u-szeged.hu>2016-09-09 15:54:14 +0200
committerPeter Varga <pvarga@inf.u-szeged.hu>2016-10-07 05:42:21 +0000
commit70c8be46f1223e10bcf82c4ccb265bc07bc657f1 (patch)
treebd4972371cd58abe345dedaf786f5ee7867c8d10 /tests/auto
parent1c16d39da263ba97e8bafcc55e9dd78592d7b9bd (diff)
Add Quick auto test for QQuickWebEngineNewViewRequest
Task-number: QTBUG-55765 Change-Id: I5576876191fe1c819aa85f2e312391126c904201 Reviewed-by: Christophe Chapuis <chris.chapuis@gmail.com> Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/quick/qmltests/data/tst_newViewRequest.qml136
-rw-r--r--tests/auto/quick/qmltests/qmltests.pro1
2 files changed, 137 insertions, 0 deletions
diff --git a/tests/auto/quick/qmltests/data/tst_newViewRequest.qml b/tests/auto/quick/qmltests/data/tst_newViewRequest.qml
new file mode 100644
index 000000000..be56f3251
--- /dev/null
+++ b/tests/auto/quick/qmltests/data/tst_newViewRequest.qml
@@ -0,0 +1,136 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 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 QtTest 1.0
+import QtWebEngine 1.2
+
+TestWebEngineView {
+ id: webEngineView
+ width: 200
+ height: 400
+
+ property var newViewRequest: null
+ property var dialog: null
+
+ SignalSpy {
+ id: newViewRequestedSpy
+ target: webEngineView
+ signalName: "newViewRequested"
+ }
+
+ onNewViewRequested: {
+ newViewRequest = {
+ "destination": request.destination,
+ "userInitiated": request.userInitiated
+ };
+
+ dialog = Qt.createQmlObject(
+ "import QtQuick.Window 2.0\n" +
+ "Window {\n" +
+ " width: 100; height: 100\n" +
+ " visible: true; flags: Qt.Dialog\n" +
+ " property alias webEngineView: webView\n" +
+ " TestWebEngineView { id: webView; anchors.fill: parent }\n" +
+ "}", webEngineView);
+
+ request.openIn(dialog.webEngineView);
+ }
+
+ TestCase {
+ id: test
+ name: "NewViewRequest"
+ when: windowShown
+
+ function init() {
+ webEngineView.url = Qt.resolvedUrl("about:blank");
+ verify(webEngineView.waitForLoadSucceeded());
+
+ newViewRequestedSpy.clear();
+ newViewRequest = null;
+ }
+
+ function cleanup() {
+ if (dialog)
+ dialog.destroy();
+ }
+
+ function test_jsWindowOpen() {
+ // Open an empty page in a new tab
+ webEngineView.loadHtml(
+ "<html><head><script>" +
+ " function popup() { window.open(''); }" +
+ "</script></head>" +
+ "<body onload='popup()'></body></html>");
+ verify(webEngineView.waitForLoadSucceeded());
+ tryCompare(newViewRequestedSpy, "count", 1);
+
+ compare(newViewRequest.destination, WebEngineView.NewViewInTab);
+ verify(!newViewRequest.userInitiated);
+
+ verify(dialog.webEngineView.waitForLoadSucceeded);
+ compare(dialog.webEngineView.url, "");
+ newViewRequestedSpy.clear();
+ dialog.destroy();
+
+ // Open an empty page in a new dialog
+ webEngineView.loadHtml(
+ "<html><head><script>" +
+ " function popup() { window.open('', '_blank', 'width=200,height=100'); }" +
+ "</script></head>" +
+ "<body onload='popup()'></body></html>");
+ verify(webEngineView.waitForLoadSucceeded());
+ tryCompare(newViewRequestedSpy, "count", 1);
+
+ compare(newViewRequest.destination, WebEngineView.NewViewInDialog);
+ verify(!newViewRequest.userInitiated);
+ verify(dialog.webEngineView.waitForLoadSucceeded);
+ newViewRequestedSpy.clear();
+ dialog.destroy();
+
+ // Open an empty page in a new dialog by user
+ webEngineView.loadHtml(
+ "<html><head><script>" +
+ " function popup() { window.open('', '_blank', 'width=200,height=100'); }" +
+ "</script></head>" +
+ "<body onload=\"document.getElementById('popupButton').focus();\">" +
+ " <button id='popupButton' onclick='popup()'>Pop Up!</button>" +
+ "</body></html>");
+ verify(webEngineView.waitForLoadSucceeded());
+ keyPress(Qt.Key_Enter);
+ tryCompare(newViewRequestedSpy, "count", 1);
+
+ compare(newViewRequest.destination, WebEngineView.NewViewInDialog);
+ verify(newViewRequest.userInitiated);
+ verify(dialog.webEngineView.waitForLoadSucceeded);
+ newViewRequestedSpy.clear();
+ dialog.destroy();
+ }
+ }
+}
+
diff --git a/tests/auto/quick/qmltests/qmltests.pro b/tests/auto/quick/qmltests/qmltests.pro
index 30c3aab30..cc5434807 100644
--- a/tests/auto/quick/qmltests/qmltests.pro
+++ b/tests/auto/quick/qmltests/qmltests.pro
@@ -58,6 +58,7 @@ OTHER_FILES += \
$$PWD/data/tst_loadUrl.qml \
$$PWD/data/tst_navigationHistory.qml \
$$PWD/data/tst_navigationRequested.qml \
+ $$PWD/data/tst_newViewRequest.qml \
$$PWD/data/tst_properties.qml \
$$PWD/data/tst_runJavaScript.qml \
$$PWD/data/tst_scrollPosition.qml \