summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/infrastructure/testdriver/actions/penPointerEvents.html
blob: 7141fb56556795fdd25a8ed740c25b2d7edcac9d (plain)
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
<!DOCTYPE html>
<meta charset="utf-8">
<title>TestDriver actions: pointerevent properties of pen type</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>
<script src="/pointerevents/pointerevent_support.js"></script>

<style>
div#test {
  position: fixed;
  touch-action: none;
  top: 5px;
  left: 5px;
  width: 100px;
  height: 100px;
  background-color: blue;
}
</style>

<div id="test">
</div>

<script>
let eventList = [];

async_test(t => {
  let test = document.getElementById("test");
  [
    'pointerover', 'pointerenter', 'pointermove', 'pointerdown', 'pointerup',
    'pointerout', 'pointerleave'
  ].forEach(eventType => {
    test.addEventListener(eventType, e => {
      eventList.push(e);
    });
  });

  let div = document.getElementById("test");
  let actions = new test_driver.Actions()
    .addPointer("penPointer1", "pen")
    // Force initial position to be outside the test element
    .pointerMove(0, 0)
    // Prevent coalescence of move events.
    .pointerDown()
    .pointerUp()
    // Trigger over and enter events.
    .pointerMove(10, 10)
    // Toggle of pen-contact state between each move to prevent coalescence of
    // move events.
    .pointerDown()
    .pointerMove(0, 0, {origin: test})
    .pointerUp()
    .pointerMove(15, 0, {origin: test})
    .pointerDown()
    .pointerMove(30, 0, {origin: test})
    .pointerUp()
    .pointerMove(0, 0)
    .send()
    .then(t.step_func_done(() => {
      const expectedEvents = [
        {
          type: 'pointerover',
          button:  ButtonChange.NONE,
          buttons: ButtonsBitfield.NONE
        },
        {
          type: 'pointerenter',
          button:  ButtonChange.NONE,
          buttons: ButtonsBitfield.NONE
        },
        { type: 'pointermove',
          button:  ButtonChange.NONE,
          buttons: ButtonsBitfield.NONE,
          clientX: 10,
          clientY: 10
        },
        {
          type: 'pointerdown',
          button:  ButtonChange.PEN_CONTACT,
          buttons: ButtonsBitfield.PEN_CONTACT,
          clientX: 10,
          clientY: 10
        },
        {
          type: 'pointermove',
          button:  ButtonChange.NONE,
          buttons: ButtonsBitfield.PEN_CONTACT,
          clientX: 55,
          clientY: 55
        },
        {
          type: 'pointerup',
          button:  ButtonChange.PEN_CONTACT,
          buttons: ButtonsBitfield.NONE,
          clientX: 55,
          clientY: 55
        },
        {
          type: 'pointermove',
          button:  ButtonChange.NONE,
          buttons: ButtonsBitfield.NONE,
          clientX: 70,
          clientY: 55
        },
        {
          type: 'pointerdown',
          button:  ButtonChange.PEN_CONTACT,
          buttons: ButtonsBitfield.PEN_CONTACT,
          clientX: 70,
          clientY: 55
        },
        {
          type: 'pointermove',
          button:  ButtonChange.NONE,
          buttons: ButtonsBitfield.PEN_CONTACT,
          clientX: 85,
          clientY: 55
        },
        {
          type: 'pointerup',
          button:  ButtonChange.PEN_CONTACT,
          buttons: ButtonsBitfield.NONE,
          clientX: 85,
          clientY: 55
        },
        {
          type: 'pointerout',
          button:  ButtonChange.NONE,
          buttons: ButtonsBitfield.NONE,
          clientX: 0,
          clientY: 0
        },
        {
          type: 'pointerleave',
          button:  ButtonChange.NONE,
          buttons: ButtonsBitfield.NONE,
          clientX: 0,
          clientY: 0
        },
      ];

      for (let i = 0; i < expectedEvents.length; i++) {
        const expectedValue = expectedEvents[i];
        const actualValue = eventList[i];
        assert_true(!!actualValue, `Missing $[i}-th event`);
        assert_equals(actualValue.pointerType, 'pen', 'Unexpected pointer type');
        for (key in expectedValue) {
          assert_equals(actualValue[key], expectedValue[key],
                        `Mismatch in event[${i}].${key}`);
        }
      }

      assert_equals(eventList.length, expectedEvents.length,
                    'Unexpected number of events');
  })).catch(e => t.step_func(() => assert_unreached("Actions sequence failed " + e)));
});
</script>