tor-browser

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

helper_scroll_anchoring_on_wheel.html (2253B)


      1 <!DOCTYPE HTML>
      2 <meta charset="utf-8">
      3 <meta name="viewport" content="width=device-width, minimum-scale=1.0">
      4 <title>Tests scroll anchoring updates in-progress wheel scrolling __relatively__</title>
      5 <script src="apz_test_utils.js"></script>
      6 <script src="apz_test_native_event_utils.js"></script>
      7 <script src="/tests/SimpleTest/paint_listener.js"></script>
      8 <style>
      9  body { margin: 0 }
     10  #target > div {
     11    height: 500px;
     12  }
     13 </style>
     14 <div id="target"></div>
     15 <div class="spacer" style="height: 1000vh"></div>
     16 <script>
     17  const targetElement = document.getElementById("target");
     18 
     19  async function test() {
     20    // Fistly send a wheel event to measure the scroll amount of one event.
     21    let transformEndPromise = promiseTransformEnd();
     22    await synthesizeNativeWheel(window, 50, 50, 0, -50);
     23    await transformEndPromise;
     24 
     25    ok(window.scrollY > 0, "Should be scrolled to some amount");
     26 
     27    const firstScrollAmount = window.scrollY;
     28 
     29    // Now send a wheel event again.
     30    transformEndPromise = promiseTransformEnd();
     31    await synthesizeNativeWheel(window, 50, 50, 0, -50);
     32    await promiseApzFlushedRepaints();
     33 
     34    // And insert an element during the wheel scrolling is still in progress.
     35    targetElement.appendChild(document.createElement("div"));
     36 
     37    await transformEndPromise;
     38 
     39    // Give scroll offsets a chance to sync.
     40    await promiseApzFlushedRepaints();
     41 
     42    // Though in an ideal environment, the expected total scroll amount should
     43    // be `firstScrollAmount * 2 + 500`, we don't expect it on our CIs, so we
     44    // assume here;
     45    // 1) it's greater than double of the first scroll amount since it should
     46    //     include the height of the inserted element.
     47    // 2) it's greater than the first scroll amount + the height of the inserted
     48    //    element.
     49    ok(window.scrollY > firstScrollAmount * 2,
     50       `the scroll amount ${window.scrollY} should be greater than double of the first scroll amount ${firstScrollAmount*2}`);
     51    ok(window.scrollY > firstScrollAmount + 500,
     52       `the scroll amount ${window.scrollY} should also be greater than the first scroll amount + the inserted element height  ${firstScrollAmount+500}`);
     53  }
     54 
     55  waitUntilApzStable()
     56  .then(test)
     57  .then(subtestDone, subtestFailed);
     58 </script>