File: coalesced_events_attributes_under_load.https.optional.html

package info (click to toggle)
firefox-esr 140.5.0esr-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,538,920 kB
  • sloc: cpp: 7,381,527; javascript: 6,388,905; ansic: 3,710,087; python: 1,393,776; xml: 628,165; asm: 426,916; java: 184,004; sh: 65,744; makefile: 19,302; objc: 13,059; perl: 12,912; yacc: 4,583; cs: 3,846; pascal: 3,352; lex: 1,720; ruby: 1,226; exp: 762; php: 436; lisp: 258; awk: 247; sql: 66; sed: 54; csh: 10
file content (113 lines) | stat: -rw-r--r-- 4,216 bytes parent folder | download | duplicates (13)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<!doctype html>
<title>Event coalescing under load</title>
<!--
  This test is optional because event coalescing under load is an optional
  spec requirement: https://w3c.github.io/pointerevents/#coalesced-events
-->
<meta name="variant" content="?mouse">
<meta name="variant" content="?pen">
<meta name="variant" content="?touch">
<meta name="viewport" content="width=device-width">
<meta name="timeout" content="long">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-actions.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
<script src="pointerevent_support.js"></script>
<style>
  #target {
    width: 100px;
    height: 100px;
    touch-action: none;
  }
</style>
<div id="target"></div>

<script>
  "use strict";
  const pointer_type = location.search.substring(1);
  const target = document.getElementById("target");

  // Busy-loop load parameters:
  const load_initial_ms = 5;
  const load_multiplier = 4;
  const load_max_ms = 500;
  // Max total delay = 5+20+80+320 = 425ms

  // https://w3c.github.io/pointerevents/#coalesced-events
  function checkCoalescedMoveEventAttributes(event) {
    let coalesced_events = event.getCoalescedEvents();
    assert_greater_than_equal(coalesced_events.length, 1,
        "pointermove.getCoalescedEvents() has at least 1 entry");

    for (let i = 0; i < coalesced_events.length; i++) {
      let coalesced_event = coalesced_events[i];

      assert_equals(coalesced_event.isTrusted, true,
        "coalesced_event.isTrusted is true");
      assert_equals(coalesced_event.bubbles, false,
        "coalesced_event.bubbles is false");
      assert_equals(coalesced_event.cancelable, false,
        "coalesced_event.cancelable is false");

      assert_equals(coalesced_event.pointerId, event.pointerId,
        "coalesced_event.pointerId matches the same in the container event");
      assert_equals(coalesced_event.pointerType, event.pointerType,
        "coalesced_event.pointerType matches the same in the container event");
      assert_equals(coalesced_event.isPrimary, event.isPrimary,
        "coalesced_event.isPrimary matches the same in the container event");
      assert_equals(coalesced_event.target, event.target,
        "coalesced_event.target matches the same in the container event");

      if (i > 0) {
        assert_greater_than_equal(coalesced_event.timeStamp,
            coalesced_events[i-1].timeStamp,
            "coalesced_event.timeStamp must be ascending");
      }
    }
  }

  let coalesced_event_received = false;

  promise_test(async t => {
    let current_busyloop_ms = load_initial_ms;

    target.addEventListener("pointerdown", event => {
      // Every pointerdown blocks the main thread for a certain time limit,
      // and then increases the time limit for next round in case the
      // current limit fails to cause event coalescing.
      let start = performance.now();
      while (performance.now() < start + current_busyloop_ms)
        continue;
      current_busyloop_ms *= load_multiplier;
    });

    target.addEventListener("pointermove", t.step_func(event => {
      checkCoalescedMoveEventAttributes(event);
      if (event.getCoalescedEvents().length > 1)
        coalesced_event_received = true;
    }));

    // Repeatedly send a long action sequence until either a coalesced event is
    // encountered or the busyloop becomes too long.
    while (!coalesced_event_received && current_busyloop_ms < load_max_ms) {
      let pointerup_promise = getEvent("pointerup", target);

      let actions = new test_driver.Actions()
          .addPointer("TestPointer", pointer_type)
          .pointerMove(0, 0, { origin: target })
          .pointerDown();
      for (let i = 0; i < 5; i++) {
        actions = actions.pointerMove(20, 20, { origin: target })
            .pointerMove(0, 0, { origin: target });
      }
      actions = actions.pointerUp();

      await actions.send();
      await pointerup_promise;
    }

    assert_true(coalesced_event_received, "Coalesed pointermoves received");
  }, "Coalesced pointermoves under load");
</script>