tor-browser

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

wheel-event-transactions-target-removal.html (3055B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <head>
      4 <meta charset="utf-8">
      5 <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1">
      6 <script src="/resources/testharness.js"></script>
      7 <script src="/resources/testharnessreport.js"></script>
      8 <script src="/resources/testdriver.js"></script>
      9 <script src="/resources/testdriver-actions.js"></script>
     10 <script src="/resources/testdriver-vendor.js"></script>
     11 <script src="scroll_support.js"></script>
     12 <style>
     13 body {
     14  margin: 0;
     15  padding: 0;
     16  height: 200vh;
     17 }
     18 
     19 .spacer {
     20  width: 100%;
     21  height: 25px;
     22  padding: 0;
     23  margin: 0;
     24 }
     25 
     26 </style>
     27 <head>
     28 <body>
     29 <div id="initialTarget" class="spacer" style="background: red"></div>
     30 <div id="firstRootSpacer" class="spacer" style="background: green"></div>
     31 <div id="secondRootSpacer" class="spacer" style="background: blue"></div>
     32 </body>
     33 
     34 <script>
     35 
     36 promise_test(async (t) => {
     37  await new Promise(resolve => addEventListener("load", resolve, {once: true}));
     38 
     39  await waitForCompositorReady();
     40 
     41  await waitForCompositorCommit();
     42 
     43 
     44  let initialTarget = null;
     45  let wheelEventTargets = [];
     46  let removedInitialTarget = false;
     47 
     48  // Remove the initial element the wheel event is targetted at once we fire the
     49  // first wheel event, then log the subsequent wheel event targets.
     50  function removeInitialElement(e) {
     51    wheelEventTargets.push(e.target);
     52    if (!removedInitialTarget) {
     53      initialTarget = e.target;
     54      e.target.remove();
     55      removedInitialTarget = true;
     56      initialTarget.addEventListener("wheel", () => {
     57        assert_true(false, "wheel event should never be fired after the target is removed")
     58      }, {passive: true});
     59    }
     60  }
     61  window.addEventListener("wheel", removeInitialElement, {passive: true});
     62 
     63  await waitForCompositorCommit();
     64 
     65  await new test_driver.Actions()
     66    .addWheel("wheel1")
     67    .scroll(40, 2, 0, 30, {origin: "viewport"})
     68    .pause(1)
     69    .scroll(40, 2, 0, 30, {origin: "viewport"})
     70    .send();
     71 
     72  // TODO(dlrobertson): Use the scrollend event here to wait for the
     73  // wheel scroll to finish instead of waitForAnimationEnd().
     74  await waitForAnimationEnd(() => { return document.scrollingElement.scrollTop; });
     75  await waitForCompositorCommit();
     76 
     77  assert_true(removedInitialTarget, "Removed the initial target");
     78  // The first wheel event should be targetted at the removed element.
     79  assert_equals(wheelEventTargets.shift(), initialTarget,
     80                "Initial wheel event has the removed element as the target");
     81 
     82  wheelEventTargets.forEach((wheelEventTarget, i) => {
     83    // TODO(dlrobertson): This assertion is pretty weak, but browsers seem to disagree
     84    // on what element the event should target. Find out what the target should be here
     85    // and make this assertion more restrictive.
     86    assert_not_equals(wheelEventTarget, initialTarget,
     87                      "Wheel event at index `" + i + "` targetted the initial element");
     88  });
     89  assert_greater_than(document.scrollingElement.scrollTop, 0, "The document has scrolled");
     90 }, "Remove the initial wheel event target.");
     91 </script>
     92 </html>