From 70c8be46f1223e10bcf82c4ccb265bc07bc657f1 Mon Sep 17 00:00:00 2001 From: Peter Varga Date: Fri, 9 Sep 2016 15:54:14 +0200 Subject: Add Quick auto test for QQuickWebEngineNewViewRequest Task-number: QTBUG-55765 Change-Id: I5576876191fe1c819aa85f2e312391126c904201 Reviewed-by: Christophe Chapuis Reviewed-by: Allan Sandfeld Jensen --- .../quick/qmltests/data/tst_newViewRequest.qml | 136 +++++++++++++++++++++ tests/auto/quick/qmltests/qmltests.pro | 1 + 2 files changed, 137 insertions(+) create mode 100644 tests/auto/quick/qmltests/data/tst_newViewRequest.qml (limited to 'tests/auto') 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( + "" + + ""); + 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( + "" + + ""); + 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( + "" + + "" + + " " + + ""); + 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 \ -- cgit v1.2.3