location-setter-user-click.html (3389B)
1 <!DOCTYPE html> 2 <meta charset="utf-8"> 3 <title>No replace before load, triggered by location setters called as part of user-initiated clicks</title> 4 <script src="/resources/testharness.js"></script> 5 <script src="/resources/testharnessreport.js"></script> 6 <script src="resources/helpers.js"></script> 7 <script src="/resources/testdriver.js"></script> 8 <script src="/resources/testdriver-vendor.js"></script> 9 10 <body> 11 <script> 12 "use strict"; 13 14 promise_test(async t => { 15 const sentinelIframe = await setupSentinelIframe(t); 16 const startingHistoryLength = history.length; 17 18 const code = ` 19 const button = document.createElement("button"); 20 button.id = "the-button"; 21 button.textContent = "needs to have content to be clickable"; 22 button.onclick = () => { location.href = "/common/blank.html?thereplacement"; }; 23 document.currentScript.before(button); 24 parent.test_driver.click(button); 25 `; 26 27 const startURL = "resources/slow-code-injector.html?pipe=sub(none)&code=" + encodeURIComponent(code); 28 const afterReplacementURL = "/common/blank.html?thereplacement"; 29 const iframe = insertIframe(t, startURL); 30 31 assert_equals(history.length, startingHistoryLength, "Inserting the under-test iframe must not change history.length"); 32 33 await waitForLoad(t, iframe, afterReplacementURL); 34 assert_equals(history.length, startingHistoryLength + 1, "history.length must change after waiting for the load"); 35 }, "href"); 36 37 promise_test(async t => { 38 const sentinelIframe = await setupSentinelIframe(t); 39 const startingHistoryLength = history.length; 40 41 const code = ` 42 const button = document.createElement("button"); 43 button.id = "the-button"; 44 button.textContent = "needs to have content to be clickable"; 45 button.onclick = () => { location.search = "thereplacement"; }; 46 document.currentScript.before(button); 47 parent.test_driver.click(button); 48 `; 49 50 const startURL = "resources/slow-code-injector.html?pipe=sub(none)&code=" + encodeURIComponent(code); 51 const afterReplacementURL = "resources/slow-code-injector.html?thereplacement"; 52 const iframe = insertIframe(t, startURL); 53 54 assert_equals(history.length, startingHistoryLength, "Inserting the under-test iframe must not change history.length"); 55 56 await waitForLoad(t, iframe, afterReplacementURL); 57 assert_equals(history.length, startingHistoryLength + 1, "history.length must change after waiting for the load"); 58 }, "search"); 59 60 promise_test(async t => { 61 const sentinelIframe = await setupSentinelIframe(t); 62 const startingHistoryLength = history.length; 63 64 const code = ` 65 const button = document.createElement("button"); 66 button.id = "the-button"; 67 button.textContent = "needs to have content to be clickable"; 68 button.onclick = () => { location.hash = "thereplacement"; }; 69 document.currentScript.before(button); 70 parent.test_driver.click(button); 71 `; 72 73 const startURL = "resources/slow-code-injector.html?pipe=sub(none)&code=" + encodeURIComponent(code); 74 const afterReplacementURL = startURL + "#thereplacement"; 75 const iframe = insertIframe(t, startURL); 76 77 assert_equals(history.length, startingHistoryLength, "Inserting the under-test iframe must not change history.length"); 78 79 await waitForLoad(t, iframe, afterReplacementURL); 80 assert_equals(history.length, startingHistoryLength + 1, "history.length must change after waiting for the load"); 81 }, "hash"); 82 </script>