summaryrefslogtreecommitdiffstats
path: root/layout/base/tests/browser_disableDialogs_onbeforeunload.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_disableDialogs_onbeforeunload.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_disableDialogs_onbeforeunload.js')
-rw-r--r--layout/base/tests/browser_disableDialogs_onbeforeunload.js56
1 files changed, 56 insertions, 0 deletions
diff --git a/layout/base/tests/browser_disableDialogs_onbeforeunload.js b/layout/base/tests/browser_disableDialogs_onbeforeunload.js
new file mode 100644
index 000000000..c9385f670
--- /dev/null
+++ b/layout/base/tests/browser_disableDialogs_onbeforeunload.js
@@ -0,0 +1,56 @@
+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", false]]});
+
+const PAGE_URL =
+ "data:text/html," + encodeURIComponent("<script>(" + pageScript.toSource() + ")();</script>");
+
+add_task(function* enableDialogs() {
+ // 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);
+});
+
+add_task(function* disableDialogs() {
+ // The onbeforeunload dialog should NOT appear.
+ yield openPage(false);
+ info("If we time out here, then the dialog was shown...");
+});
+
+function* openPage(enableDialogs) {
+ // Open about:blank in a new tab.
+ yield BrowserTestUtils.withNewTab({ gBrowser, url: "about:blank" }, function* (browser) {
+ // Load the content script in the frame.
+ let methodName = enableDialogs ? "enableDialogs" : "disableDialogs";
+ yield ContentTask.spawn(browser, methodName, function* (name) {
+ Components.utils.import("resource://gre/modules/Services.jsm");
+ Services.obs.addObserver(doc => {
+ if (content && doc == content.document) {
+ content.QueryInterface(Ci.nsIInterfaceRequestor).
+ getInterface(Ci.nsIDOMWindowUtils)[name]();
+ }
+ }, "document-element-inserted", false);
+ });
+ // Load the page.
+ yield BrowserTestUtils.loadURI(browser, PAGE_URL);
+ yield BrowserTestUtils.browserLoaded(browser);
+ // And then navigate away.
+ yield BrowserTestUtils.loadURI(browser, "http://example.com/");
+ yield BrowserTestUtils.browserLoaded(browser);
+ });
+}