tor-browser

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

coalesced_events_attributes_under_load.https.optional.html (4216B)


      1 <!doctype html>
      2 <title>Event coalescing under load</title>
      3 <!--
      4  This test is optional because event coalescing under load is an optional
      5  spec requirement: https://w3c.github.io/pointerevents/#coalesced-events
      6 -->
      7 <meta name="variant" content="?mouse">
      8 <meta name="variant" content="?pen">
      9 <meta name="variant" content="?touch">
     10 <meta name="viewport" content="width=device-width">
     11 <meta name="timeout" content="long">
     12 <script src="/resources/testharness.js"></script>
     13 <script src="/resources/testharnessreport.js"></script>
     14 <script src="/resources/testdriver.js"></script>
     15 <script src="/resources/testdriver-actions.js"></script>
     16 <script src="/resources/testdriver-vendor.js"></script>
     17 <script src="pointerevent_support.js"></script>
     18 <style>
     19  #target {
     20    width: 100px;
     21    height: 100px;
     22    touch-action: none;
     23  }
     24 </style>
     25 <div id="target"></div>
     26 
     27 <script>
     28  "use strict";
     29  const pointer_type = location.search.substring(1);
     30  const target = document.getElementById("target");
     31 
     32  // Busy-loop load parameters:
     33  const load_initial_ms = 5;
     34  const load_multiplier = 4;
     35  const load_max_ms = 500;
     36  // Max total delay = 5+20+80+320 = 425ms
     37 
     38  // https://w3c.github.io/pointerevents/#coalesced-events
     39  function checkCoalescedMoveEventAttributes(event) {
     40    let coalesced_events = event.getCoalescedEvents();
     41    assert_greater_than_equal(coalesced_events.length, 1,
     42        "pointermove.getCoalescedEvents() has at least 1 entry");
     43 
     44    for (let i = 0; i < coalesced_events.length; i++) {
     45      let coalesced_event = coalesced_events[i];
     46 
     47      assert_equals(coalesced_event.isTrusted, true,
     48        "coalesced_event.isTrusted is true");
     49      assert_equals(coalesced_event.bubbles, false,
     50        "coalesced_event.bubbles is false");
     51      assert_equals(coalesced_event.cancelable, false,
     52        "coalesced_event.cancelable is false");
     53 
     54      assert_equals(coalesced_event.pointerId, event.pointerId,
     55        "coalesced_event.pointerId matches the same in the container event");
     56      assert_equals(coalesced_event.pointerType, event.pointerType,
     57        "coalesced_event.pointerType matches the same in the container event");
     58      assert_equals(coalesced_event.isPrimary, event.isPrimary,
     59        "coalesced_event.isPrimary matches the same in the container event");
     60      assert_equals(coalesced_event.target, event.target,
     61        "coalesced_event.target matches the same in the container event");
     62 
     63      if (i > 0) {
     64        assert_greater_than_equal(coalesced_event.timeStamp,
     65            coalesced_events[i-1].timeStamp,
     66            "coalesced_event.timeStamp must be ascending");
     67      }
     68    }
     69  }
     70 
     71  let coalesced_event_received = false;
     72 
     73  promise_test(async t => {
     74    let current_busyloop_ms = load_initial_ms;
     75 
     76    target.addEventListener("pointerdown", event => {
     77      // Every pointerdown blocks the main thread for a certain time limit,
     78      // and then increases the time limit for next round in case the
     79      // current limit fails to cause event coalescing.
     80      let start = performance.now();
     81      while (performance.now() < start + current_busyloop_ms)
     82        continue;
     83      current_busyloop_ms *= load_multiplier;
     84    });
     85 
     86    target.addEventListener("pointermove", t.step_func(event => {
     87      checkCoalescedMoveEventAttributes(event);
     88      if (event.getCoalescedEvents().length > 1)
     89        coalesced_event_received = true;
     90    }));
     91 
     92    // Repeatedly send a long action sequence until either a coalesced event is
     93    // encountered or the busyloop becomes too long.
     94    while (!coalesced_event_received && current_busyloop_ms < load_max_ms) {
     95      let pointerup_promise = getEvent("pointerup", target);
     96 
     97      let actions = new test_driver.Actions()
     98          .addPointer("TestPointer", pointer_type)
     99          .pointerMove(0, 0, { origin: target })
    100          .pointerDown();
    101      for (let i = 0; i < 5; i++) {
    102        actions = actions.pointerMove(20, 20, { origin: target })
    103            .pointerMove(0, 0, { origin: target });
    104      }
    105      actions = actions.pointerUp();
    106 
    107      await actions.send();
    108      await pointerup_promise;
    109    }
    110 
    111    assert_true(coalesced_event_received, "Coalesed pointermoves received");
    112  }, "Coalesced pointermoves under load");
    113 </script>