no-referrer-dynamic-url-censored.html (1912B)
1 <!doctype html> 2 <script src="/resources/testharness.js"></script> 3 <script src="/resources/testharnessreport.js"></script> 4 <iframe id="i" src="/common/blank.html"></iframe> 5 <script> 6 promise_test(async (t) => { 7 // Wait for after the load event so that the navigation doesn't get converted 8 // into a replace navigation. 9 await new Promise(r => window.onload = () => t.step_timeout(r, 0)); 10 11 // The entry for the first document has a visible url. 12 i.contentWindow.navigation.navigate("/common/blank.html?2"); 13 await new Promise(r => i.onload = () => t.step_timeout(r, 0)); 14 assert_not_equals(i.contentWindow.navigation.entries()[0].url, null); 15 assert_not_equals(i.contentWindow.navigation.activation.from.url, null); 16 17 // Apply no-referrer, the url should now be censored when no longer on that document. 18 i.contentWindow.navigation.back(); 19 await new Promise(r => i.onload = () => t.step_timeout(r, 0)); 20 i.contentDocument.head.innerHTML = `<meta name="referrer" content="no-referrer">`; 21 assert_not_equals(i.contentWindow.navigation.entries()[0].url, null); 22 i.contentWindow.navigation.forward(); 23 await new Promise(r => i.onload = () => t.step_timeout(r, 0)); 24 assert_equals(i.contentWindow.navigation.entries()[0].url, null); 25 assert_equals(i.contentWindow.navigation.activation.from.url, null); 26 27 // Overwrite the referrer policy, the url should be visible again. 28 i.contentWindow.navigation.back(); 29 await new Promise(r => i.onload = () => t.step_timeout(r, 0)); 30 i.contentDocument.head.innerHTML = `<meta name="referrer" content="same-origin">`; 31 i.contentWindow.navigation.forward(); 32 await new Promise(r => i.onload = () => t.step_timeout(r, 0)); 33 assert_not_equals(i.contentWindow.navigation.entries()[0].url, null); 34 assert_not_equals(i.contentWindow.navigation.activation.from.url, null); 35 }, "The url of a document is censored by a no-referrer policy dynamically"); 36 </script>