Bug 1892041 - Part 1: Update test262 features. r=spidermonkey-reviewers,dminor
[gecko.git] / dom / base / test / test_window_close.html
blob5b0d7e6fa695673b18fbfa30fa14056943f9fa7c
1 <!DOCTYPE HTML>
2 <html>
3 <head>
4 <meta charset="utf-8">
5 <title>test window.close()</title>
6 <script src="/tests/SimpleTest/SimpleTest.js"></script>
7 <link rel="stylesheet" href="/tests/SimpleTest/test.css"/>
8 <script>
9 SimpleTest.waitForExplicitFinish();
10 var b = new BroadcastChannel("windowclose");
12 const link = "link";
13 const windowopen = "window.open()";
14 var tests = [
16 type: windowopen,
17 noopener: true,
18 shouldCloseWithoutHistory: true,
19 shouldCloseWithHistory: false
22 type: windowopen,
23 noopener: false,
24 shouldCloseWithoutHistory: true,
25 shouldCloseWithHistory: true
28 type: link,
29 noopener: true,
30 shouldCloseWithoutHistory: true,
31 shouldCloseWithHistory: false
34 type: link,
35 noopener: false,
36 shouldCloseWithoutHistory: true,
37 shouldCloseWithHistory: true
41 var loadTypes = ["withouthistory", "withhistory"];
43 async function start() {
44 // If Fission is disabled, the pref is no-op.
45 await SpecialPowers.pushPrefEnv({set: [["fission.bfcacheInParent", true]]});
47 for (let test of tests) {
48 await SpecialPowers.pushPrefEnv({ set: [["dom.allow_scripts_to_close_windows", false]]});
49 if (test.type == windowopen) {
50 for (let loadType of loadTypes) {
51 var features = test.noopener ? "noopener" : "";
52 window.open("file_window_close.html?" + loadType, "", features);
53 await new Promise(function(r) {
54 b.onmessage = function(e) {
55 var expectedClose = loadType == "withouthistory" ?
56 test.shouldCloseWithoutHistory : test.shouldCloseWithHistory;
57 is(e.data, expectedClose ? "closed" : "blocked",
58 "Expected close on " + loadType + ": " + expectedClose);
59 r();
61 });
63 } else if (test.type == link) {
64 var rel = test.noopener ? "rel='noopener'" : "";
65 for (let loadType of loadTypes) {
66 document.getElementById("content").innerHTML =
67 "<a href='file_window_close.html?" + loadType + "'" +
68 " target='foo' " + rel + "'>link</a>";
69 var p = new Promise(function(r) {
70 b.onmessage = function(e) {
71 var expectedClose = loadType == "withouthistory" ?
72 test.shouldCloseWithoutHistory : test.shouldCloseWithHistory;
73 is(e.data, expectedClose ? "closed" : "blocked",
74 "Expected close on " + loadType + ": " + expectedClose);
75 r();
77 });
78 document.getElementById("content").firstChild.click();
79 await p;
83 SimpleTest.finish();
86 </script>
87 </head>
88 <body onload="setTimeout(start)">
89 <p id="display"></p>
90 <div id="content"></div>
91 <pre id="test"></pre>
92 </body>
93 </html>