tor-browser

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

pageswap-reload-navigation.html (2073B)


      1 <!DOCTYPE html>
      2 <title>pageswap navigationactivation for replace navigations</title>
      3 <link rel="help" href="https://html.spec.whatwg.org/">
      4 <link rel="author" href="mailto:khushalsagar@chromium.org">
      5 <script src="/resources/testharness.js"></script>
      6 <script src="/resources/testharnessreport.js"></script>
      7 <script>
      8 const expectedUrl = location.href + '?new';
      9 
     10 const params = new URLSearchParams(location.search);
     11 // The initial page in the popup.
     12 const is_popup_page = params.has('popup') && !window.opener.didreload;
     13 // The test page itself.
     14 const is_test_page = !params.has('popup');
     15 
     16 const channel = new BroadcastChannel("testchannel");
     17 
     18 if (is_test_page) {
     19  const expectedUrl = location.href.split('?')[0] + "?popup";
     20  const expectedEvents = ["pageswap", "entry", "reload","from", "pagehide"];
     21 
     22  promise_test(async t => {
     23    let popup;
     24    onload = () => {
     25      window.events = [];
     26      window.didreload = false;
     27      popup = window.open("?popup");
     28    };
     29 
     30    await new Promise(resolve => {
     31      channel.addEventListener(
     32        "message", t.step_func(async (e) => {
     33          if (e.data === "nav") {
     34            assert_array_equals(window.events, expectedEvents, 'incorrect event order');
     35            popup.close();
     36            resolve();
     37          }
     38      }));
     39    });
     40  }, `pageswap on replace navigation from script`);
     41 } else if (is_popup_page) {
     42  onload = () => {
     43    requestAnimationFrame(() => requestAnimationFrame(() => {
     44      window.opener.didreload = true;
     45      location.reload();
     46    }));
     47 
     48    onpageswap = (e) => {
     49      window.opener.events.push("pageswap");
     50      if (e.viewTransition != null)
     51        window.opener.events.push("transition");
     52      if (e.activation.entry == navigation.currentEntry)
     53        window.opener.events.push("entry");
     54      window.opener.events.push(e.activation.navigationType);
     55      if (e.activation.from == navigation.currentEntry)
     56        window.opener.events.push("from");
     57    };
     58 
     59    onpagehide = () => {
     60      window.opener.events.push("pagehide");
     61      channel.postMessage("nav");
     62    };
     63  };
     64 }
     65 </script>