tor-browser

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

pageswap-replace-navigation.html (2207B)


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