Bug 1849622 [wpt PR 41564] - Minor formatting fix, a=testonly
[gecko.git] / testing / web-platform / tests / html / browsers / windows / resources / window-name.sub.html
blob9255ba340159ba67d08f90837cb77c0aa514a5f0
1 <!doctype html>
2 <title>popup helper</title>
3 <script>
5 const search = decodeURIComponent(window.location.search.replace("?", ""));
6 const steps = search.split("|");
8 async function proceedTest() {
9 while (steps.length) {
10 const step = steps.shift();
12 if (step.startsWith("report=")) {
13 const id = step.split("=")[1];
14 const stashURL = new URL("window-name-stash.py", location);
15 stashURL.searchParams.set('id', id);
16 stashURL.searchParams.set('value', window.name);
18 await fetch(stashURL, { method: "POST" });
19 continue;
22 if (step === "close") {
23 window.close();
24 break;
27 if (step === "cross") {
28 const url = new URL(window.location);
29 url.host = "{{hosts[alt][]}}:{{ports[https][0]}}";
30 url.search = "?" + steps.join("|");
31 window.location = url.href;
32 break;
35 if (step === "same") {
36 const url = new URL(window.location);
37 url.host = "{{host}}:{{ports[https][0]}}";
38 url.search = "?" + steps.join("|");
39 window.location = url.href;
40 break;
43 if (step === "sub") {
44 const url = new URL(window.location);
45 url.host = "{{hosts[][www]}}:{{ports[https][0]}}";
46 url.search = "?" + steps.join("|");
47 window.location = url.href;
48 break;
51 if (step === "closeOpener") {
52 if (window.opener) {
53 window.opener.close();
55 continue;
58 if (step.startsWith("navOpener=")) {
59 if (!window.opener) {
60 continue;
63 let url = step.split("=")[1];
64 window.opener.location.href = url;
66 continue;
69 if (step === "open") {
70 const url = new URL(window.location);
71 url.host = "{{host}}:{{ports[https][0]}}";
72 url.search = "?" + steps.join("|");
73 window.open(url);
74 break;
77 if (step.startsWith("reportOpener=")) {
78 const id = step.split("=")[1];
79 const stashURL = new URL("window-name-stash.py", location);
80 stashURL.searchParams.set('id', id);
81 stashURL.searchParams.set('value', window.opener.name);
83 await fetch(stashURL, { method: "POST" });
84 continue;
87 if (step.startsWith("set=")) {
88 window.name = step.split("=")[1];
89 continue;
92 if (step.startsWith("setDomain=")) {
93 document.domain = step.split("=")[1];
94 continue;
97 throw new Error("Unsupported step!");
101 proceedTest();
102 </script>