tor-browser

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

coalesced_events_attributes.https.html (6021B)


      1 <!doctype html>
      2 <title>Coalesced events count and properties</title>
      3 <meta name="variant" content="?mouse">
      4 <meta name="variant" content="?pen">
      5 <meta name="variant" content="?touch">
      6 <meta name="viewport" content="width=device-width">
      7 <script src="/resources/testharness.js"></script>
      8 <script src="/resources/testharnessreport.js"></script>
      9 <script src="/resources/testdriver.js"></script>
     10 <script src="/resources/testdriver-actions.js"></script>
     11 <script src="/resources/testdriver-vendor.js"></script>
     12 <script src="pointerevent_support.js"></script>
     13 <link rel="stylesheet" type="text/css" href="pointerevent_styles.css">
     14 <style>
     15  div {
     16    width: 100px;
     17    height: 100px;
     18  }
     19 </style>
     20 <div id="target"></div>
     21 <div id="done"></div>
     22 
     23 <script>
     24  "use strict";
     25  const pointer_type = location.search.substring(1);
     26  const target = document.getElementById("target");
     27 
     28  // https://w3c.github.io/pointerevents/#coalesced-events
     29  function checkListAttributes(event) {
     30    assert_equals(typeof event.getCoalescedEvents, "function",
     31        event.type + ".getCoalescedEvents is a function");
     32    assert_equals(typeof event.getCoalescedEvents(), "object",
     33        event.type + ".getCoalescedEvents() returns an object");
     34 
     35    let coalesced_events = event.getCoalescedEvents();
     36 
     37    if (event.type == "pointermove") {
     38      assert_greater_than_equal(coalesced_events.length, 1,
     39          event.type + ".getCoalescedEvents() has at least 1 entry");
     40 
     41      for (let i = 0; i < coalesced_events.length; i++) {
     42        let coalesced_event = coalesced_events[i];
     43 
     44        assert_equals(coalesced_event.isTrusted, true,
     45          "coalesced_event.isTrusted is true");
     46        assert_equals(coalesced_event.bubbles, false,
     47          "coalesced_event.bubbles is false");
     48        assert_equals(coalesced_event.cancelable, false,
     49          "coalesced_event.cancelable is false");
     50 
     51        assert_equals(coalesced_event.pointerId, event.pointerId,
     52          "coalesced_event.pointerId matches the same in the container event");
     53        assert_equals(coalesced_event.pointerType, event.pointerType,
     54          "coalesced_event.pointerType matches the same in the container event");
     55        assert_equals(coalesced_event.isPrimary, event.isPrimary,
     56          "coalesced_event.isPrimary matches the same in the container event");
     57        assert_equals(coalesced_event.target, event.target,
     58          "coalesced_event.target matches the same in the container event");
     59 
     60        assert_equals(coalesced_event.getCoalescedEvents().length, 0,
     61                      "Coalesced events shouldn't have coalesced events themselves.");
     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    } else {
     70      assert_equals(coalesced_events.length, 0,
     71          event.type + ".getCoalescedEvents() has 0 entry");
     72    }
     73  }
     74 
     75  promise_test(async () => {
     76    const done = document.getElementById("done");
     77 
     78    let pointerover_promise  = getEvent("pointerover",  target);
     79    let pointerenter_promise = getEvent("pointerenter", target);
     80    let pointerout_promise   = getEvent("pointerout",   target);
     81    let pointerleave_promise = getEvent("pointerleave", target);
     82 
     83    await clickInTarget(pointer_type, target);
     84    await clickInTarget(pointer_type, done);
     85 
     86    checkListAttributes(await pointerover_promise);
     87    checkListAttributes(await pointerenter_promise);
     88    checkListAttributes(await pointerout_promise);
     89    checkListAttributes(await pointerleave_promise);
     90  }, "Coalesced list in boundary events");
     91 
     92  promise_test(async () => {
     93    // We need "touch-action:none" to guarantee pointermove events.
     94    target.classList.add("touchActionNone");
     95 
     96    target.addEventListener("pointerdown",
     97        e => target.setPointerCapture(e.pointerId),
     98        {once: true});
     99 
    100    target.addEventListener("pointermove",
    101        e => target.releasePointerCapture(e.pointerId),
    102        {once: true});
    103 
    104    let gotpointercapture_promise  = getEvent("gotpointercapture",  target);
    105    let lostpointercapture_promise = getEvent("lostpointercapture", target);
    106 
    107    await new test_driver.Actions()
    108        .addPointer("TestPointer", pointer_type)
    109        .pointerMove(0, 0, {origin: target})
    110        .pointerDown()
    111        .pointerMove(20, 20, {origin: target})
    112        .pointerUp()
    113        .send();
    114 
    115    checkListAttributes(await gotpointercapture_promise);
    116    checkListAttributes(await lostpointercapture_promise);
    117 
    118    target.classList.remove("touchActionNone");
    119  }, "Coalesced list in pointer-capture events");
    120 
    121  promise_test(async () => {
    122    // We need "touch-action:none" to guarantee pointermove events.
    123    target.classList.add("touchActionNone");
    124 
    125    let pointerdown_promise = getEvent("pointerdown", target);
    126    let pointermove_promise = getEvent("pointermove", target);
    127    let pointerup_promise   = getEvent("pointerup",   target);
    128 
    129    await new test_driver.Actions()
    130        .addPointer("TestPointer", pointer_type)
    131        .pointerMove(0, 0, {origin: target})
    132        .pointerDown()
    133        .pointerMove(20, 20, {origin: target})
    134        .pointerUp()
    135        .send();
    136 
    137    checkListAttributes(await pointerdown_promise);
    138    checkListAttributes(await pointermove_promise);
    139    checkListAttributes(await pointerup_promise);
    140 
    141    target.classList.remove("touchActionNone");
    142  }, "Coalesced list in pointerdown/move/up events");
    143 
    144  promise_test(async () => {
    145    if (pointer_type !== "touch") {
    146      assert_true(true, "Skipped for " + pointer_type);
    147      return;
    148    }
    149 
    150    let pointercancel_promise  = getEvent("pointercancel", target);
    151 
    152    await new test_driver.Actions()
    153        .addPointer("TestPointer", pointer_type)
    154        .pointerMove(0, 0, {origin: target})
    155        .pointerDown()
    156        .pointerMove(20, 20, {origin: target})
    157        .pointerUp()
    158        .send();
    159 
    160    checkListAttributes(await pointercancel_promise);
    161  }, "Coalesced list in pointercancel event");
    162 </script>