tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

location-setter-during-pageshow.html (3084B)


      1 <!DOCTYPE html>
      2 <meta charset="utf-8">
      3 <title>Replace during the pageshow event, triggered by location setters</title>
      4 <script src="/resources/testharness.js"></script>
      5 <script src="/resources/testharnessreport.js"></script>
      6 <script src="resources/helpers.js"></script>
      7 
      8 <body>
      9 <script>
     10 "use strict";
     11 
     12 promise_test(async t => {
     13  const sentinelIframe = await setupSentinelIframe(t);
     14  const startingHistoryLength = history.length;
     15 
     16  const code = `
     17    window.onpageshow = () => {
     18      location.href = "/common/blank.html?thereplacement";
     19    };
     20  `;
     21 
     22  const startURL = "resources/code-injector.html?pipe=sub(none)&code=" + encodeURIComponent(code);
     23  const afterReplacementURL = "/common/blank.html?thereplacement";
     24  const iframe = insertIframe(t, startURL);
     25  assert_equals(history.length, startingHistoryLength, "Inserting the under-test iframe must not change history.length");
     26 
     27  await waitForLoadAllowingIntermediateLoads(t, iframe, afterReplacementURL);
     28  assert_equals(history.length, startingHistoryLength, "history.length must not change after waiting for the replacement");
     29 
     30  await checkSentinelIframe(t, sentinelIframe);
     31  assert_equals(history.length, startingHistoryLength, "history.length must not change after checking the sentinel iframe");
     32 }, "href");
     33 
     34 promise_test(async t => {
     35  const sentinelIframe = await setupSentinelIframe(t);
     36  const startingHistoryLength = history.length;
     37 
     38  const code = `
     39    window.onpageshow = () => {
     40      location.search = "thereplacement";
     41    };
     42  `;
     43 
     44  const startURL = "resources/code-injector.html?pipe=sub(none)&code=" + encodeURIComponent(code);
     45  const afterReplacementURL = "resources/code-injector.html?thereplacement";
     46  const iframe = insertIframe(t, startURL);
     47  assert_equals(history.length, startingHistoryLength, "Inserting the under-test iframe must not change history.length");
     48 
     49  await waitForLoadAllowingIntermediateLoads(t, iframe, afterReplacementURL);
     50  assert_equals(history.length, startingHistoryLength, "history.length must not change after waiting for the replacement");
     51 
     52  await checkSentinelIframe(t, sentinelIframe);
     53 }, "search");
     54 
     55 promise_test(async t => {
     56  const sentinelIframe = await setupSentinelIframe(t);
     57  const startingHistoryLength = history.length;
     58 
     59  const code = `
     60    window.onpageshow = () => {
     61      location.hash = "thereplacement";
     62      parent.postMessage("done", "*");
     63    };
     64  `;
     65 
     66  const startURL = "resources/code-injector.html?pipe=sub(none)&code=" + encodeURIComponent(code);
     67  const afterReplacementURL = startURL + "#thereplacement";
     68  const iframe = insertIframe(t, startURL);
     69  assert_equals(history.length, startingHistoryLength, "Inserting the under-test iframe must not change history.length");
     70 
     71  assert_equals(await waitForMessage(), "done");
     72  assert_equals(history.length, startingHistoryLength, "history.length must not change after waiting for the replacement");
     73 
     74  await checkSentinelIframe(t, sentinelIframe);
     75  assert_equals(history.length, startingHistoryLength, "history.length must not change after checking the sentinel iframe");
     76 }, "hash");
     77 </script>