tor-browser

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

iframe-session-history.html (2464B)


      1 <!DOCTYPE HTML>
      2 <title>Test the correct sequence of pagevisibility-related events in conjunction with history navigation</title>
      3 <link rel="author" title="Noam Rosenthal"  href="mailto:noam@webkit.org">
      4 <link rel="help" href="https://www.w3.org/TR/page-visibility-2/">
      5 <meta name="timeout" content="long">
      6 <script src="/resources/testharness.js"></script>
      7 <script src="/resources/testharnessreport.js"></script>
      8 <body>
      9 <script>
     10 
     11 const iframePath1 = 'resources/iframe-post-load.html?v=1'
     12 const iframePath2 = 'resources/iframe-post-load.html?v=2'
     13 
     14 function waitForLoad(iframe) {
     15  return new Promise(resolve => {
     16    const callback = e => {
     17      if (e.data === 'load') {
     18        window.removeEventListener('message', callback)
     19        resolve()
     20      }
     21    }
     22 
     23    window.addEventListener('message', callback)
     24  })
     25 }
     26 
     27 function assert_sequence(sequence) {
     28  assert_equals(sequence.length, 2)
     29  assert_equals(sequence[0].type, 'pagehide')
     30  assert_equals(sequence[0].target, '#document')
     31  assert_equals(sequence[0].visibilityState, 'visible')
     32  assert_equals(sequence[0].cancelable, true)
     33  assert_equals(sequence[1].type, 'visibilitychange')
     34  assert_equals(sequence[1].target, '#document')
     35  assert_equals(sequence[1].visibilityState, 'hidden')
     36  assert_equals(sequence[1].cancelable, false)
     37 }
     38 promise_test(async t => {
     39    const iframe = document.createElement('iframe');
     40    iframe.src = iframePath1;
     41    document.body.appendChild(iframe);
     42    let sequence = [];
     43    t.add_cleanup(() => iframe.remove());
     44    iframe.src = iframePath1;
     45    await waitForLoad(iframe);
     46    const handler = t.step_func(event => sequence.push({
     47      type: event.type,
     48      target: event.target.nodeName,
     49      cancelable: event.cancelable,
     50      visibilityState: iframe.contentWindow.document.visibilityState
     51    }));
     52    iframe.contentWindow.document.addEventListener('visibilitychange', handler);
     53    iframe.contentWindow.addEventListener('pagehide', handler);
     54    iframe.contentWindow.location.href = iframePath2;
     55    await waitForLoad(iframe);
     56    assert_sequence(sequence);
     57    sequence = [];
     58    iframe.contentWindow.addEventListener('pagehide', handler);
     59    iframe.contentWindow.document.addEventListener('visibilitychange', handler);
     60    iframe.contentWindow.history.back();
     61    await waitForLoad(iframe);
     62    assert_sequence(sequence);
     63 }, "pagehide should be called before visibilitychange, and visibilityState should be set to hidden at the right time");
     64 </script>
     65 </body>