window-open-popup.html (1718B)
1 <!DOCTYPE html> 2 <meta charset="utf-8"> 3 <script src="/resources/testharness.js"></script> 4 <script src="/resources/testharnessreport.js"></script> 5 <script src="/common/utils.js"></script> 6 7 <body> 8 <script> 9 "use strict"; 10 promise_test(async t => { 11 // Generating a new one instead of hard-coding makes running manual tests a bit easier. 12 const windowName = token(); 13 14 const code = ` 15 window.onload = () => { window.onloadFired = true; }; 16 `; 17 18 const startURL = "resources/slow-code-injector.html?pipe=sub(none)&code=" + encodeURIComponent(code); 19 const absoluteStartURL = (new URL(startURL, location.href)).href; 20 21 const afterReplacementURL = "resources/message-opener.html"; 22 const absoluteAfterReplacementURL = (new URL(afterReplacementURL, location.href)).href; 23 24 const w = window.open(startURL, windowName); 25 t.add_cleanup(() => w.close()); 26 27 // Wait to get past any initial about:blank 28 while (true) { 29 if (w.location.href === absoluteStartURL) { 30 break; 31 } 32 await new Promise(r => setTimeout(r, 0)); 33 } 34 35 assert_equals(w.onloadFired, undefined, "onload must not yet have fired"); 36 assert_equals(w.history.length, 1, "history.length for the opened window must start at 1"); 37 38 window.open(afterReplacementURL, windowName); 39 await new Promise(r => { window.onmessage = r; }); 40 41 assert_equals(w.history.length, 2, "history.length must increase"); 42 assert_equals(w.location.href, absoluteAfterReplacementURL); 43 44 w.history.back(); 45 46 await new Promise(r => t.step_timeout(r, 1000)); 47 assert_equals(w.location.href, absoluteStartURL, "1 second after attempting to go back, it indeed went back"); 48 }, "No replace before load, triggered by window.open() on a non-_self window"); 49 </script>