Bug 1839316: part 5) Guard the "fetchpriority" attribute behind a pref. r=kershaw...
[gecko.git] / docshell / test / navigation / test_bug1699721.html
blob687c5306cf4169d24574e5014ea3a6c271d935ed
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <script src="/tests/SimpleTest/SimpleTest.js"></script>
5 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
6 </head>
7 <body>
8 <pre id="test">
9 <script type="text/javascript">
10 add_task(async function() {
11 let popup = window.open("blank.html");
13 info("opened popup");
14 await new Promise(resolve => {
15 popup.addEventListener("load", resolve, { once: true });
16 });
18 info("popup blank.html loaded");
19 let tell_opener = new URL("file_tell_opener.html", location.href);
20 // eslint-disable-next-line @microsoft/sdl/no-insecure-url
21 let xorigin_url = new URL(tell_opener.pathname, "http://example.com");
23 let resolveStartedUnload;
24 let startedUnload = new Promise(resolve => {
25 resolveStartedUnload = resolve;
26 });
27 let didFinishUnload = false;
29 let finishUnload = false;
30 popup.addEventListener("unload", function() {
31 resolveStartedUnload();
32 try {
33 // Spin a nested event loop in unload until we set `finishUnload`.
34 SpecialPowers.Services.tm.spinEventLoopUntil(
35 "Test(test_switch_back_nested.html)", () => finishUnload);
36 } finally {
37 info("exiting from unload nested event loop...");
38 didFinishUnload = true;
40 });
42 info("wait for message from popup");
43 let messagePromise = new Promise(resolve => {
44 addEventListener("message", evt => {
45 resolve();
46 }, { once: true });
47 });
48 popup.location = xorigin_url.href;
49 await messagePromise;
51 info("popup loaded, ensuring we're in unload");
52 await startedUnload;
53 is(didFinishUnload, false, "unload shouldn't have finished");
55 let switchStarted = SpecialPowers.spawnChrome([], async () => {
56 await new Promise(resolve => {
57 async function observer(subject, topic) {
58 is(topic, "http-on-examine-response");
60 let uri = subject.QueryInterface(Ci.nsIChannel).URI;
61 if (!uri.filePath.endsWith("file_tell_opener.html")) {
62 return;
65 Services.obs.removeObserver(observer, "http-on-examine-response");
67 // spin the event loop a few times to ensure we resolve after the process switch
68 for (let i = 0; i < 10; ++i) {
69 await new Promise(res => Services.tm.dispatchToMainThread(res));
72 info("resolving!");
73 resolve();
75 Services.obs.addObserver(observer, "http-on-examine-response");
76 });
77 });
79 info("Navigating back to the current process");
80 await SpecialPowers.spawn(popup, [tell_opener.href], (href) => {
81 content.location.href = href;
82 });
84 let messagePromise2 = new Promise(resolve => {
85 addEventListener("message", evt => {
86 resolve();
87 }, { once: true });
88 });
90 info("Waiting for the process switch to start");
91 await switchStarted;
93 // Finish unloading, and wait for the unload to complete
94 is(didFinishUnload, false, "unload shouldn't be finished");
95 finishUnload = true;
96 await new Promise(resolve => setTimeout(resolve, 0));
97 is(didFinishUnload, true, "unload should be finished");
99 info("waiting for navigation to complete");
100 await messagePromise2;
102 info("closing popup");
103 popup.close();
105 ok(true, "Didn't crash");
107 </script>
108 </pre>
109 </body>
110 </html>