tor-browser

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

test_bug1740516.html (3122B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <head>
      4  <meta charset="utf-8">
      5  <title>Test pageshow event order for iframe</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 waitForPageShow(outer, inner) {
     12      return new Promise((resolve) => {
     13        let results = [];
     14        outer.addEventListener("message", ({ data: persisted }) => {
     15          results.push({ name: outer.name, persisted });
     16          if (results.length == 2) {
     17            resolve(results);
     18          }
     19        }, { once: true });
     20        inner.addEventListener("message", ({ data: persisted }) => {
     21          results.push({ name: inner.name, persisted });
     22          if (results.length == 2) {
     23            resolve(results);
     24          }
     25        }, { once: true });
     26      });
     27    }
     28    async function runTest() {
     29      let outerBC = SpecialPowers.wrap(BroadcastChannel).unpartitionedTestingChannel("bug1740516_1");
     30      let innerBC = SpecialPowers.wrap(BroadcastChannel).unpartitionedTestingChannel("bug1740516_1_inner");
     31 
     32      let check = waitForPageShow(outerBC, innerBC).then(([first, second]) => {
     33        is(first.name, "bug1740516_1_inner", "Should get pageShow from inner iframe page first.");
     34        ok(!first.persisted, "First navigation shouldn't come from BFCache.");
     35        is(second.name, "bug1740516_1", "Should get pageShow from outer page second.");
     36        ok(!second.persisted, "First navigation shouldn't come from BFCache.");
     37      }, () => {
     38        ok(false, "The promises should not be rejected.");
     39      });
     40      window.open("file_bug1740516_1.html", "", "noopener");
     41      await check;
     42 
     43      check = waitForPageShow(outerBC, innerBC).then(([first, second]) => {
     44        is(first.name, "bug1740516_1_inner", "Should get pageShow from inner iframe page first.");
     45        ok(first.persisted, "Second navigation should come from BFCache");
     46        is(second.name, "bug1740516_1", "Should get pageShow from outer page second.");
     47        ok(second.persisted, "Second navigation should come from BFCache");
     48      }, () => {
     49        ok(false, "The promises should not be rejected.");
     50      });
     51      outerBC.postMessage("navigate");
     52      await check;
     53 
     54      check = waitForPageShow(outerBC, innerBC).then(([first, second]) => {
     55        is(first.name, "bug1740516_1_inner", "Should get pageShow from inner iframe page first.");
     56        ok(!first.persisted, "Third navigation should not come from BFCache");
     57        is(second.name, "bug1740516_1", "Should get pageShow from outer page second.");
     58        ok(!second.persisted, "Third navigation should not come from BFCache");
     59      }, () => {
     60        ok(false, "The promises should not be rejected.");
     61      });
     62      outerBC.postMessage("block_bfcache_and_navigate");
     63      await check;
     64 
     65      outerBC.postMessage("close");
     66 
     67      outerBC.close();
     68      innerBC.close();
     69 
     70      SimpleTest.finish();
     71    }
     72  </script>
     73 </head>
     74 <body onload="runTest();">
     75 <p id="display"></p>
     76 <div id="content" style="display: none"></div>
     77 <pre id="test"></pre>
     78 </body>
     79 </html>