tor-browser

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

old_vt_promises_bfcache.html (3970B)


      1 <!DOCTYPE html>
      2 <title>VT object created on the old Document is skipped before persisting in BFCache</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 <script src="/common/utils.js"></script>
      8 <script src="/common/dispatcher/dispatcher.js"></script>
      9 <script src="/html/browsers/browsing-the-web/back-forward-cache/resources/helper.sub.js"></script>
     10 <script>
     11 // runBfcacheTest opens a popup to pageA which navigates to pageB and then
     12 // back, ensuring pageA is stored in the BFCache.
     13 
     14 runBfcacheTest({
     15  funcBeforeNavigation: async () => {
     16    // This function executes in pageA
     17 
     18    function addTransitionOptIn() {
     19      let css = '@view-transition { navigation: auto; }';
     20      let style = document.createElement('style');
     21      style.appendChild(document.createTextNode(css));
     22      document.head.appendChild(style);
     23    }
     24    addTransitionOptIn();
     25 
     26    // Wait for at least one frame to ensure there is a transition on the
     27    // navigation.
     28    function waitForAtLeastOneFrame() {
     29      return new Promise(resolve => {
     30        // Different web engines work slightly different on this area but waiting
     31        // for two requestAnimationFrames() to happen, one after another, should be
     32        // sufficient to ensure at least one frame has been generated anywhere.
     33        window.requestAnimationFrame(() => {
     34          window.requestAnimationFrame(() => {
     35            resolve();
     36          });
     37        });
     38      });
     39    }
     40    await waitForAtLeastOneFrame();
     41 
     42    onpageswap = (e) => {
     43      if (e.viewTransition == null)
     44        return;
     45 
     46      document.documentElement.classList.add('transition');
     47 
     48      e.viewTransition.updateCallbackDone.then(() => {
     49        document.documentElement.classList.add('updateCallbackDone');
     50      });
     51 
     52      e.viewTransition.ready.catch(() => {
     53        document.documentElement.classList.add('ready');
     54      });
     55 
     56      e.viewTransition.finished.then(() => {
     57        document.documentElement.classList.add('finished');
     58      });
     59    }
     60  },
     61  funcBeforeBackNavigation: async () => {
     62    // This function executes in pageB
     63 
     64    function addTransitionOptIn() {
     65      let css = '@view-transition { navigation: auto; }';
     66      let style = document.createElement('style');
     67      style.appendChild(document.createTextNode(css));
     68      document.head.appendChild(style);
     69    }
     70    addTransitionOptIn();
     71 
     72    // Wait for at least one frame to ensure there is a transition on the
     73    // navigation.
     74    function waitForAtLeastOneFrame() {
     75      return new Promise(resolve => {
     76        // Different web engines work slightly different on this area but waiting
     77        // for two requestAnimationFrames() to happen, one after another, should be
     78        // sufficient to ensure at least one frame has been generated anywhere.
     79        window.requestAnimationFrame(() => {
     80          window.requestAnimationFrame(() => {
     81            resolve();
     82          });
     83        });
     84      });
     85    }
     86    await waitForAtLeastOneFrame();
     87  },
     88  funcAfterAssertion: async (pageA, pageB, t) => {
     89    assert_true(
     90      await pageA.execute_script(() => {
     91          return document.documentElement.classList.contains('transition');
     92      }),
     93      'navigation had viewTransition');
     94 
     95    assert_true(
     96      await pageA.execute_script(() => {
     97          return document.documentElement.classList.contains('updateCallbackDone');
     98      }),
     99      'updateCallbackDone was resolved');
    100 
    101    assert_true(
    102      await pageA.execute_script(() => {
    103          return document.documentElement.classList.contains('ready');
    104      }),
    105      'ready was rejected');
    106 
    107    assert_true(
    108      await pageA.execute_script(() => {
    109          return document.documentElement.classList.contains('finished');
    110      }),
    111      'finished was resolved');
    112  },
    113  targetOrigin: originSameOrigin,
    114 });
    115 </script>