tor-browser

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

resize-event-order.html (2523B)


      1 <!doctype html>
      2 <title>Visual Viewport Resize Event Order</title>
      3 <meta charset=utf-8>
      4 <link rel="help" href="https://wicg.github.io/visual-viewport/index.html">
      5 <script src="/resources/testharness.js"></script>
      6 <script src="/resources/testharnessreport.js"></script>
      7 <script src="/resources/testdriver.js"></script>
      8 <script src="/resources/testdriver-vendor.js"></script>
      9 <style>
     10  iframe {
     11    width: 300px;
     12    height: 300px;
     13  }
     14 </style>
     15 
     16 <body>
     17  <iframe srcdoc="<!DOCTYPE html>"></iframe>
     18 </body>
     19 
     20 <script>
     21 
     22 async function oneRaf(win) {
     23  return new Promise((resolve) => {
     24    win.requestAnimationFrame(resolve);
     25  });
     26 }
     27 
     28 // Runs the test on the given window object, asserts that event handlers on the
     29 // DOMWindow object are fired before those on the VisualViewport object.
     30 // `resizeFunc` is used to perform the resize.
     31 async function runTest(win, resizeFunc) {
     32  const resize_events = [];
     33 
     34  win.onresize = () => { resize_events.push('window-attribute'); }
     35  win.addEventListener('resize', () => { resize_events.push('window-addEventListener'); });
     36  win.visualViewport.onresize = () => { resize_events.push('visualViewport-attribute'); }
     37  win.visualViewport.addEventListener('resize', () => {
     38        resize_events.push('visualViewport-addEventListener'); });
     39 
     40  assert_equals(resize_events.toString(), '', 'PRECONDITION');
     41  resizeFunc(500, 600);
     42 
     43  await oneRaf(win);
     44 
     45  assert_equals(resize_events.toString(),
     46                'window-attribute,window-addEventListener,' +
     47                'visualViewport-attribute,visualViewport-addEventListener');
     48 }
     49 
     50 onload = () => {
     51  // Test the event order in a top-level window which we will programmatically
     52  // resize.
     53  promise_test(async t => {
     54    let popup = null;
     55    test_driver.bless('Open a popup in a new window', () => {
     56        popup = window.open('about:blank', 'newwindow', 'width=300,height=300');
     57    });
     58    await t.step_wait(() => popup != null, "Opened popup window");
     59 
     60    await runTest(popup, (x, y) => {popup.resizeTo(x, y);});
     61  }, 'Popup: DOMWindow resize fired before VisualViewport.');
     62 
     63  // Also test the resize resulting from an iframe's size change.
     64  promise_test(async t => {
     65    const iframe = frames[0];
     66    await runTest(iframe, (x, y) => {iframe.frameElement.style.width = x + 'px';
     67                                     iframe.frameElement.style.height = y + 'px';
     68                                     iframe.frameElement.offsetWidth; /* force reflow */});
     69  }, 'iframe: DOMWindow resize fired before VisualViewport.');
     70 }
     71 
     72 </script>