summaryrefslogtreecommitdiffstats
path: root/tests/auto/quick/qmltests
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/quick/qmltests')
-rw-r--r--tests/auto/quick/qmltests/data/TestWebEngineView.qml7
-rw-r--r--tests/auto/quick/qmltests/data/confirmclose.html5
-rw-r--r--tests/auto/quick/qmltests/data/tst_javaScriptDialogs.qml33
-rw-r--r--tests/auto/quick/qmltests/qmltests.pro1
4 files changed, 46 insertions, 0 deletions
diff --git a/tests/auto/quick/qmltests/data/TestWebEngineView.qml b/tests/auto/quick/qmltests/data/TestWebEngineView.qml
index 8a01dfa09..e2c5c9009 100644
--- a/tests/auto/quick/qmltests/data/TestWebEngineView.qml
+++ b/tests/auto/quick/qmltests/data/TestWebEngineView.qml
@@ -47,6 +47,7 @@ import QtWebEngine.experimental 1.0
WebEngineView {
property var loadStatus: null
property var viewportReady: false
+ property bool windowCloseRequestedSignalEmitted: false
function waitForLoadSucceeded() {
var success = _waitFor(function() { return loadStatus == WebEngineView.LoadSucceededStatus })
@@ -69,6 +70,9 @@ WebEngineView {
loadStatus = null
return stop
}
+ function waitForWindowCloseRequested() {
+ return _waitFor(function() { return windowCloseRequestedSignalEmitted; });
+ }
function _waitFor(predicate) {
var timeout = 5000
var i = 0
@@ -87,5 +91,8 @@ WebEngineView {
viewportReady = false
}
+ onWindowCloseRequested: {
+ windowCloseRequestedSignalEmitted = true;
+ }
}
diff --git a/tests/auto/quick/qmltests/data/confirmclose.html b/tests/auto/quick/qmltests/data/confirmclose.html
new file mode 100644
index 000000000..ba11da7a4
--- /dev/null
+++ b/tests/auto/quick/qmltests/data/confirmclose.html
@@ -0,0 +1,5 @@
+<html>
+<body onbeforeunload="return 'You are about to miss out on some awesome content.';">
+ Be greeted, precious viewer!
+</body>
+</html>
diff --git a/tests/auto/quick/qmltests/data/tst_javaScriptDialogs.qml b/tests/auto/quick/qmltests/data/tst_javaScriptDialogs.qml
index 75b45bfac..4294c5ba3 100644
--- a/tests/auto/quick/qmltests/data/tst_javaScriptDialogs.qml
+++ b/tests/auto/quick/qmltests/data/tst_javaScriptDialogs.qml
@@ -42,11 +42,26 @@
import QtQuick 2.0
import QtTest 1.0
import QtWebEngine 1.2
+import QtWebEngine.testsupport 1.0
import "../mock-delegates/TestParams" 1.0
TestWebEngineView {
id: webEngineView
+ testSupport: WebEngineTestSupport {
+ property bool windowCloseRejectedSignalEmitted: false
+
+ function waitForWindowCloseRejected() {
+ return _waitFor(function () {
+ return testSupport.windowCloseRejectedSignalEmitted;
+ });
+ }
+
+ onWindowCloseRejected: {
+ windowCloseRejectedSignalEmitted = true;
+ }
+ }
+
TestCase {
id: test
name: "WebEngineViewJavaScriptDialogs"
@@ -80,6 +95,24 @@ TestWebEngineView {
}
+ function test_confirmClose() {
+ webEngineView.url = Qt.resolvedUrl("confirmclose.html");
+ verify(webEngineView.waitForLoadSucceeded());
+ webEngineView.windowCloseRequestedSignalEmitted = false;
+ JSDialogParams.shouldAcceptDialog = true;
+ webEngineView.triggerWebAction(WebEngineView.RequestClose);
+ verify(webEngineView.waitForWindowCloseRequested());
+ }
+
+ function test_rejectClose() {
+ webEngineView.url = Qt.resolvedUrl("confirmclose.html");
+ verify(webEngineView.waitForLoadSucceeded());
+ webEngineView.testSupport.windowCloseRejectedSignalEmitted = false;
+ JSDialogParams.shouldAcceptDialog = false;
+ webEngineView.triggerWebAction(WebEngineView.RequestClose);
+ verify(webEngineView.testSupport.waitForWindowCloseRejected());
+ }
+
function test_prompt() {
JSDialogParams.inputForPrompt = "tQ olleH"
webEngineView.url = Qt.resolvedUrl("prompt.html")
diff --git a/tests/auto/quick/qmltests/qmltests.pro b/tests/auto/quick/qmltests/qmltests.pro
index 01517af47..57649384d 100644
--- a/tests/auto/quick/qmltests/qmltests.pro
+++ b/tests/auto/quick/qmltests/qmltests.pro
@@ -12,6 +12,7 @@ OTHER_FILES += \
$$PWD/data/change-document-title.js \
$$PWD/data/download.zip \
$$PWD/data/confirm.html \
+ $$PWD/data/confirmclose.html \
$$PWD/data/directoryupload.html \
$$PWD/data/favicon.html \
$$PWD/data/favicon.png \