summaryrefslogtreecommitdiffstats
path: root/layout/base/tests/browser_onbeforeunload_only_after_interaction.js
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /layout/base/tests/browser_onbeforeunload_only_after_interaction.js
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'layout/base/tests/browser_onbeforeunload_only_after_interaction.js')
-rw-r--r--layout/base/tests/browser_onbeforeunload_only_after_interaction.js53
1 files changed, 53 insertions, 0 deletions
diff --git a/layout/base/tests/browser_onbeforeunload_only_after_interaction.js b/layout/base/tests/browser_onbeforeunload_only_after_interaction.js
new file mode 100644
index 000000000..d079bcb38
--- /dev/null
+++ b/layout/base/tests/browser_onbeforeunload_only_after_interaction.js
@@ -0,0 +1,53 @@
+function pageScript() {
+ window.addEventListener("beforeunload", function (event) {
+ var str = "Some text that causes the beforeunload dialog to be shown";
+ event.returnValue = str;
+ return str;
+ }, true);
+}
+
+SpecialPowers.pushPrefEnv({"set": [["dom.require_user_interaction_for_beforeunload", true]]});
+
+const PAGE_URL =
+ "data:text/html," + encodeURIComponent("<script>(" + pageScript.toSource() + ")();</script>");
+
+add_task(function* doClick() {
+ // The onbeforeunload dialog should appear.
+ let dialogShown = false;
+ function onDialogShown(node) {
+ dialogShown = true;
+ let dismissButton = node.ui.button0;
+ dismissButton.click();
+ }
+ let obsName = "tabmodal-dialog-loaded";
+ Services.obs.addObserver(onDialogShown, obsName, false);
+ yield* openPage(true);
+ Services.obs.removeObserver(onDialogShown, obsName);
+ Assert.ok(dialogShown, "Should have shown dialog.");
+});
+
+add_task(function* noClick() {
+ // The onbeforeunload dialog should NOT appear.
+ yield openPage(false);
+ info("If we time out here, then the dialog was shown...");
+});
+
+function* openPage(shouldClick) {
+ // Open about:blank in a new tab.
+ yield BrowserTestUtils.withNewTab({ gBrowser, url: "about:blank" }, function* (browser) {
+ // Load the page.
+ yield BrowserTestUtils.loadURI(browser, PAGE_URL);
+ yield BrowserTestUtils.browserLoaded(browser);
+
+ if (shouldClick) {
+ yield BrowserTestUtils.synthesizeMouse("body", 2, 2, {}, browser);
+ }
+ let hasInteractedWith = yield ContentTask.spawn(browser, "", function() {
+ return content.document.userHasInteracted;
+ });
+ is(shouldClick, hasInteractedWith, "Click should update document interactivity state");
+ // And then navigate away.
+ yield BrowserTestUtils.loadURI(browser, "http://example.com/");
+ yield BrowserTestUtils.browserLoaded(browser);
+ });
+}