tor-browser

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

pointerdown-becomes-scroll.html (1866B)


      1 <!DOCTYPE html>
      2 <title>Layout Instability: shift in pointerdown becoming scroll</title>
      3 <link rel="help" href="https://wicg.github.io/layout-instability/" />
      4 <style>
      5 
      6 body { margin: 0; height: 2000px; }
      7 #box {
      8  left: 0px;
      9  top: 0px;
     10  width: 400px;
     11  height: 500px;
     12  background: yellow;
     13  position: relative;
     14 }
     15 
     16 </style>
     17 <div id="box"></div>
     18 <script src="/resources/testharness.js"></script>
     19 <script src="/resources/testharnessreport.js"></script>
     20 <script src="/resources/testdriver.js"></script>
     21 <script src="/resources/testdriver-actions.js"></script>
     22 <script src="/resources/testdriver-vendor.js"></script>
     23 <script src="resources/util.js"></script>
     24 <script>
     25 
     26 const box = document.querySelector("#box");
     27 box.addEventListener("pointerdown", (e) => {
     28  // Generate a layout shift before we know what type of input this pointer
     29  // event sequence will become.
     30  box.style.top = "100px";
     31  e.preventDefault();
     32 });
     33 
     34 generateScrollSequence = () => new test_driver.Actions()
     35    .addPointer("tp1", "touch")
     36    .pointerMove(0, 100, {sourceName: "tp1"})
     37    .pointerDown({sourceName: "tp1"})
     38    .pointerMove(0, 0, {sourceName: "tp1"})
     39    .pause(100)
     40    .pointerUp({sourceName: "tp1"})
     41    .pause(100);
     42 
     43 promise_test(async () => {
     44  const watcher = new ScoreWatcher;
     45 
     46  // Wait for the initial render to complete.
     47  await waitForAnimationFrames(2);
     48 
     49  // Send pointer events for a touch scroll.
     50  await generateScrollSequence().send();
     51 
     52  // The box is 400 x 500 and moves by 100px.
     53  const expectedScore = computeExpectedScore(400 * (500 + 100), 100);
     54 
     55  // Both scores should increase (scroll doesn't count as input for the purpose
     56  // of the LayoutShift.hadRecentInput bit).
     57  assert_equals(watcher.score, expectedScore);
     58  assert_equals(watcher.scoreWithInputExclusion, expectedScore);
     59 
     60 }, "Shift in pointerdown reported when it becomes a scroll.");
     61 
     62 </script>