clear-window-name.https.html (4302B)
1 <!doctype html> 2 <html> 3 <head> 4 <title>Clear window.name when cross-origin</title> 5 <meta name="timeout" content="long"> 6 <script src="/resources/testharness.js"></script> 7 <script src="/resources/testharnessreport.js"></script> 8 <script src="/common/utils.js"></script> 9 </head> 10 <body> 11 <script> 12 13 function anchorClick(n) { 14 const hyperlink = document.body.appendChild(document.createElement("a")) 15 hyperlink.rel = "noopener"; 16 hyperlink.target = "_blank"; 17 hyperlink.href = n; 18 hyperlink.click(); 19 } 20 21 async function pollResultAndCheck(t, id, expected) { 22 const stashURL = new URL("resources/window-name-stash.py", location); 23 stashURL.searchParams.set('id', id); 24 25 let res = "NONE"; 26 while (res == "NONE") { 27 await new Promise(resolve => { t.step_timeout(resolve, 100); }); 28 29 const response = await fetch(stashURL); 30 res = await response.text(); 31 } 32 if (res !== expected) { 33 assert_unreached('Stash result does not equal expected result.') 34 } 35 } 36 37 promise_test(async t => { 38 const id = token(); 39 40 window.open(`resources/window-name.sub.html?report=${id}|close`, id); 41 await pollResultAndCheck(t, id, id); 42 }, "Window.name is not reset when there is an opener around"); 43 44 promise_test(async t => { 45 const id = token(); 46 47 window.open(`resources/window-name.sub.html?cross|same|report=${id}|close`, id); 48 await pollResultAndCheck(t, id, id); 49 }, "Window.name is not reset when there is an opener around (cross-origin)"); 50 51 promise_test(async t => { 52 const id = token(); 53 54 w = window.open("about:blank", id); 55 w.location = `resources/window-name.sub.html?cross|same|report=${id}|close`; 56 await pollResultAndCheck(t, id, id); 57 }, "Window.name is not reset at the first navigation away from loaded initial about:blank"); 58 59 promise_test(async t => { 60 const id = token(); 61 62 window.open(`resources/window-name.sub.html?report=${id}|close`, id, "noopener"); 63 await pollResultAndCheck(t, id, id); 64 }, "Window.name is not reset at the first navigation away from initial about:blank with noopener"); 65 66 promise_test(async t => { 67 const id = token(); 68 69 window.open(`resources/window-name.sub.html?cross|same|report=${id}|close`, id, "noopener"); 70 await pollResultAndCheck(t, id, ""); 71 }, "Window.name is reset at the first cross-origin navigation with noopener"); 72 73 promise_test(async t => { 74 const id = token(); 75 76 let win = window.open(`resources/window-name.sub.html?report=${id}|close`, id); 77 win.opener = null; 78 await pollResultAndCheck(t, id, id); 79 }, "Window.name is not reset at the first navigation away from initial about:blank with window.opener set to null"); 80 81 promise_test(async t => { 82 const id = token(); 83 84 let win = window.open(`resources/window-name.sub.html?same|report=${id}|close`, id); 85 win.opener = null; 86 await pollResultAndCheck(t, id, id); 87 }, "Window.name is not reset at the same-origin navigation with window.opener set to null"); 88 89 promise_test(async t => { 90 const id = token(); 91 92 let win = window.open(`resources/window-name.sub.html?cross|same|report=${id}|close`, id); 93 win.opener = null; 94 await pollResultAndCheck(t, id, ""); 95 }, "Window.name is reset at the first first cross-origin navigation with window.opener set to null"); 96 97 promise_test(async t => { 98 const id = token(); 99 100 anchorClick(`resources/window-name.sub.html?set=${id}|report=${id}|close`); 101 await pollResultAndCheck(t, id, id); 102 }, "Window.name is set by the window"); 103 104 promise_test(async t => { 105 const id = token(); 106 107 anchorClick(`resources/window-name.sub.html?set=${id}|cross|same|report=${id}|close`); 108 await pollResultAndCheck(t, id, ""); 109 }, "Window.name is reset at the first cross-origin navigation"); 110 111 promise_test(async t => { 112 const id = token(); 113 114 window.open(`resources/window-name.sub.html?open|navOpener=about:blank|reportOpener=${id}|closeOpener|close`, id, "noopener"); 115 await pollResultAndCheck(t, id, id); 116 }, "window.name is not reset after navigating to an about:blank page from a non-about:blank page"); 117 118 119 promise_test(async t => { 120 const id = token(); 121 const domain = window.location.host; 122 123 anchorClick(`resources/window-name.sub.html?sub|set=${id}|setDomain=${domain}|sub|report=${id}|close`); 124 await pollResultAndCheck(t, id, id); 125 }, "Window.name is not reset if the document.domain is set to the parent domain"); 126 127 128 </script> 129 </body> 130 </html>