File: eventOrder.html

package info (click to toggle)
firefox 147.0.2-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,683,484 kB
  • sloc: cpp: 7,607,246; javascript: 6,533,185; ansic: 3,775,227; python: 1,415,393; xml: 634,561; asm: 438,951; java: 186,241; sh: 62,752; makefile: 18,079; objc: 13,092; perl: 12,808; yacc: 4,583; cs: 3,846; pascal: 3,448; lex: 1,720; ruby: 1,003; php: 436; lisp: 258; awk: 247; sql: 66; sed: 54; csh: 10; exp: 6
file content (61 lines) | stat: -rw-r--r-- 2,362 bytes parent folder | download | duplicates (28)
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
<!DOCTYPE html>
<meta charset="utf-8">
<title>TestDriver actions: event order</title>
<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>

<button id="a">Button a</button>
<button id="b">Button b</button>
<input id="text-input">

<script>
// Pointer 1 is added before Pointer 2 so it comes first in the list of sources
// Therefore its actions happen first
let events = [];

promise_test(() => {
  Array.prototype.forEach.call(document.getElementsByTagName("button"),
                               (x) => x.addEventListener("mousedown", () => {events.push(x.id)}));

  let button_a = document.getElementById("a");
  let button_b = document.getElementById("b");
  return new test_driver.Actions()
    .addPointer("pointer1")
    .addPointer("pointer2")
    .pointerMove(0, 0, {origin: button_a, sourceName: "pointer1"})
    .pointerMove(0, 0, {origin: button_b, sourceName: "pointer2"})
    .pointerDown({sourceName: "pointer2"})
    .pointerDown({sourceName: "pointer1"})
    .pointerUp({sourceName: "pointer2"})
    .pointerUp({sourceName: "pointer1"})
    .send()
    .then(() => assert_array_equals(events, ["a", "b"]));
});

// This test uses a large number of keyboard sources to force race conditions
// in implementations which incorrectly dispatch events. Despite belonging to
// the same "tick," each action's initial event should be dispatched in series.
promise_test(() => {
  const input = document.getElementById("text-input");
  const actions = new test_driver.Actions();
  const code_for_a = "a".charCodeAt(0);
  const keys = Array.from(Array(26))
    .map((_, index) => ({
      sourceName: "keyboard" + index,
      code: String.fromCharCode(code_for_a + index)
    }));

  keys.forEach(({sourceName}) => actions.addKeyboard(sourceName));
  keys.forEach(({code, sourceName}) => actions.keyDown(code, {sourceName}));
  keys.forEach(({code, sourceName}) => actions.keyUp(code,{sourceName}));

  return test_driver.click(input)
    .then(() => actions.send())
    .then(() => {
      assert_equals(input.value, "abcdefghijklmnopqrstuvwxyz");
    });
}, "indivisible actions on the same track dispatch events in series");
</script>