summaryrefslogtreecommitdiffstats
path: root/dom/base/test/test_window_close.html
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /dom/base/test/test_window_close.html
parentInitial commit. (diff)
downloadfirefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz
firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/base/test/test_window_close.html')
-rw-r--r--dom/base/test/test_window_close.html93
1 files changed, 93 insertions, 0 deletions
diff --git a/dom/base/test/test_window_close.html b/dom/base/test/test_window_close.html
new file mode 100644
index 0000000000..5b0d7e6fa6
--- /dev/null
+++ b/dom/base/test/test_window_close.html
@@ -0,0 +1,93 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+ <meta charset="utf-8">
+ <title>test window.close()</title>
+ <script src="/tests/SimpleTest/SimpleTest.js"></script>
+ <link rel="stylesheet" href="/tests/SimpleTest/test.css"/>
+ <script>
+ SimpleTest.waitForExplicitFinish();
+ var b = new BroadcastChannel("windowclose");
+
+ const link = "link";
+ const windowopen = "window.open()";
+ var tests = [
+ {
+ type: windowopen,
+ noopener: true,
+ shouldCloseWithoutHistory: true,
+ shouldCloseWithHistory: false
+ },
+ {
+ type: windowopen,
+ noopener: false,
+ shouldCloseWithoutHistory: true,
+ shouldCloseWithHistory: true
+ },
+ {
+ type: link,
+ noopener: true,
+ shouldCloseWithoutHistory: true,
+ shouldCloseWithHistory: false
+ },
+ {
+ type: link,
+ noopener: false,
+ shouldCloseWithoutHistory: true,
+ shouldCloseWithHistory: true
+ }
+ ];
+
+ var loadTypes = ["withouthistory", "withhistory"];
+
+ async function start() {
+ // If Fission is disabled, the pref is no-op.
+ await SpecialPowers.pushPrefEnv({set: [["fission.bfcacheInParent", true]]});
+
+ for (let test of tests) {
+ await SpecialPowers.pushPrefEnv({ set: [["dom.allow_scripts_to_close_windows", false]]});
+ if (test.type == windowopen) {
+ for (let loadType of loadTypes) {
+ var features = test.noopener ? "noopener" : "";
+ window.open("file_window_close.html?" + loadType, "", features);
+ await new Promise(function(r) {
+ b.onmessage = function(e) {
+ var expectedClose = loadType == "withouthistory" ?
+ test.shouldCloseWithoutHistory : test.shouldCloseWithHistory;
+ is(e.data, expectedClose ? "closed" : "blocked",
+ "Expected close on " + loadType + ": " + expectedClose);
+ r();
+ }
+ });
+ }
+ } else if (test.type == link) {
+ var rel = test.noopener ? "rel='noopener'" : "";
+ for (let loadType of loadTypes) {
+ document.getElementById("content").innerHTML =
+ "<a href='file_window_close.html?" + loadType + "'" +
+ " target='foo' " + rel + "'>link</a>";
+ var p = new Promise(function(r) {
+ b.onmessage = function(e) {
+ var expectedClose = loadType == "withouthistory" ?
+ test.shouldCloseWithoutHistory : test.shouldCloseWithHistory;
+ is(e.data, expectedClose ? "closed" : "blocked",
+ "Expected close on " + loadType + ": " + expectedClose);
+ r();
+ }
+ });
+ document.getElementById("content").firstChild.click();
+ await p;
+ }
+ }
+ }
+ SimpleTest.finish();
+ }
+
+ </script>
+</head>
+<body onload="setTimeout(start)">
+<p id="display"></p>
+<div id="content"></div>
+<pre id="test"></pre>
+</body>
+</html>