tor-browser

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

test_bug1850335.html (2465B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <head>
      4  <meta charset="utf-8">
      5  <title>Test referrer with going back</title>
      6  <script src="/tests/SimpleTest/SimpleTest.js"></script>
      7  <link rel="stylesheet" href="/tests/SimpleTest/test.css"/>
      8  <script>
      9    SimpleTest.waitForExplicitFinish();
     10 
     11    function waitForMessage(bc) {
     12      return new Promise(resolve => {
     13        bc.addEventListener("message", ({ data }) => { resolve(data); }, { once: true });
     14      });
     15    }
     16 
     17    async function runTest() {
     18      let bc = SpecialPowers.wrap(BroadcastChannel).unpartitionedTestingChannel("bug1850335");
     19 
     20      // Load the first page.
     21      let waitForPage1 = waitForMessage(bc);
     22      window.open("file_bug1850335_1.html", "_blank", "noopener");
     23      let { persisted, value: initial } = await waitForPage1;
     24 
     25      ok(!persisted, "Loaded first page");
     26      is(initial, "", "Initial value is empty string");
     27 
     28      // Set the value of the input element in the first page.
     29      let waitForValue = waitForMessage(bc);
     30      bc.postMessage({ cmd: "setValue", arg: "ok" });
     31      let { value: expected }= await waitForValue;
     32      is(expected, "ok", "Loaded first page");
     33 
     34      // Load the second page (same origin with the first page).
     35      let waitForPage2 = waitForMessage(bc);
     36      bc.postMessage({ cmd: "load", arg: "file_bug1850335_2.html" });
     37      ({ persisted } = await waitForPage2);
     38 
     39      ok(!persisted, "Loaded second page (same-origin)");
     40 
     41      // Load the third page (cross origin with the first and second pages). The
     42      // third page will immediately do |history.back()| to go back to the
     43      // second page.
     44      waitForPage2 = waitForMessage(bc);
     45      const crossOrigin = new URL("file_bug1850335_3.html", `https://example.com${location.pathname}`);
     46      bc.postMessage({ cmd: "load", arg: crossOrigin.href });
     47      ({ persisted } = await waitForPage2);
     48 
     49      ok(!persisted, "Second page should not be in the BFCache");
     50 
     51      // Go back to the first page.
     52      waitForPage1 = waitForMessage(bc);
     53      bc.postMessage({ cmd: "back" });
     54      let { persisted: fromBFCache, value: result } = await waitForPage1;
     55 
     56      ok(fromBFCache, "Page came from BFCache");
     57      is(result, expected, "Value wasn't cleared");
     58 
     59      bc.postMessage({ cmd: "close" });
     60 
     61      bc.close();
     62 
     63      SimpleTest.finish();
     64    }
     65  </script>
     66 </head>
     67 <body onload="runTest();">
     68 <p id="display"></p>
     69 <div id="content" style="display: none"></div>
     70 <pre id="test"></pre>
     71 </body>
     72 </html>