File: pointerevent_pointerrawupdate_changes_pointer_capture.https.html

package info (click to toggle)
firefox 143.0.3-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,617,328 kB
  • sloc: cpp: 7,478,492; javascript: 6,417,157; ansic: 3,720,058; python: 1,396,372; xml: 627,523; asm: 438,677; java: 186,156; sh: 63,477; makefile: 19,171; objc: 13,059; perl: 12,983; yacc: 4,583; cs: 3,846; pascal: 3,405; lex: 1,720; ruby: 1,003; exp: 762; php: 436; lisp: 258; awk: 247; sql: 66; sed: 53; csh: 10
file content (295 lines) | stat: -rw-r--r-- 11,938 bytes parent folder | download | duplicates (4)
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="timeout" content="long">
<meta name="viewport" content="width=device-width, initial-scale:1, user-scalable=no">
<title>Test for handling of "fire a pointer event named pointerrawupdate"</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>
<style>
div#initPosition {
  height: 1em;
  margin: 50px;
}
div#parent, div#child {
  width: 200px;
  height: 200px;
  margin: 0px;
  padding: 0;
}
</style>
<script>
"use strict";

/**
 * `pointerrawupdate` is defined as:
 * > The user agent MUST fire a pointer event named pointerrawupdate, and only
 * > do so within a secure context, when a pointer changes any properties that
 * > don't fire pointerdown or pointerup events.
 *
 * The following `pointermove` event is also defined as:
 * > The user agent MUST fire a pointer event named pointermove
 *
 * So, when a set of `pointerrawupdate` and `pointermove` is dispatched, the
 * "fire a pointer event" runs twice.
 *
 * "fire a pointer event" defines:
 * > If the event is not a gotpointercapture, lostpointercapture, click,
 * > auxclick or contextmenu event, run the process pending pointer capture
 * > steps for this PointerEvent.
 *
 *  And also the section defines:
 * > Determine the target at which the event is fired as follows:
 * > - If the pointer capture target override has been set for the pointer, set
 * >   the target to pointer capture target override object.
 * > - Otherwise, set the target to the object returned by normal hit test
 * >   mechanisms (out of scope for this specification).
 *
 * So, dispatching `pointerrawupdate` should fix the pointer capture override
 * and cause dispatching `gotpointercapture` and/or `lostpointercapture` and
 * `pointermove` event should be retarget to the new pointer capture override.
 */

 addEventListener("load", () => {
  const ticksToPreventCoalescedPointerMove = 300;
  const initDiv = document.getElementById("initPosition");
  const parent = document.getElementById("parent");
  const child = document.getElementById("child");

  let events;
  function logEvent(event) {
    events.push({type: event.type, target: event.target});
  }
  function stringifyEvents(arrayOfEvents) {
    function stringifyEvent(event) {
      return `${event.type}@${event.target.localName}${
        event.target.id ? `#${event.target.id}` : ""
      }`;
    }
    let str = "";
    for (const event of arrayOfEvents) {
      if (str) {
        str += ", ";
      }
      str += stringifyEvent(event);
    }
    return str;
  }
  for (const type of ["pointerdown", "pointerup",
                      "pointerrawupdate", "pointermove",
                      "gotpointercapture", "lostpointercapture"]) {
    parent.addEventListener(type, logEvent, {capture: true});
  }

  promise_test(async t => {
    events = [];
    child.addEventListener("pointerdown", pointerDownEvent => {
      parent.setPointerCapture(pointerDownEvent.pointerId);
      parent.addEventListener("pointerrawupdate", pointerRawUpdateEvent => {
        parent.releasePointerCapture(pointerRawUpdateEvent.pointerId);
      }, {once: true});
    }, {once: true});
    await new test_driver.Actions()
      .pointerMove(0, 0, {origin: initDiv})
      .pause(ticksToPreventCoalescedPointerMove)
      .pointerMove(0, 0, {origin: child})
      .pointerDown()
      .pointerMove(1, 1, {origin: child})
      .pointerUp()
      .pointerMove(0, 0, {origin: initDiv})
      .send();
    assert_equals(
      stringifyEvents(events),
      stringifyEvents([
        {type: "pointerrawupdate", target: child},
        {type: "pointermove", target: child},
        {type: "pointerdown", target: child}, // set pending pointer capture to parent
        // The following `pointerrawupdate` event dispatching runs the
        // "process pending pointer capture" steps.
        {type: "gotpointercapture", target: parent},
        {type: "pointerrawupdate", target: parent}, // set pending pointer capture to null
        // The following `pointermove` event dispatching runs the
        // "process pending pointer capture" steps again.
        {type: "lostpointercapture", target: parent},
        {type: "pointermove", target: child},
        {type: "pointerup", target: child},
      ])
    );
  }, "Setting pointer capture at `pointerdown` and releasing pointer capture at `pointerrawupdate`");

  promise_test(async t => {
    events = [];
    child.addEventListener("pointerdown", () => {
      parent.addEventListener("pointerrawupdate", pointerRawUpdateEvent => {
        parent.setPointerCapture(pointerRawUpdateEvent.pointerId);
      }, {once: true});
    }, {once: true});
    await new test_driver.Actions()
      .pointerMove(0, 0, {origin: initDiv})
      .pause(ticksToPreventCoalescedPointerMove)
      .pointerMove(0, 0, {origin: child})
      .pointerDown()
      .pointerMove(1, 1, {origin: child})
      .pointerUp()
      .pointerMove(0, 0, {origin: initDiv})
      .send();
    assert_equals(
      stringifyEvents(events),
      stringifyEvents([
        {type: "pointerrawupdate", target: child},
        {type: "pointermove", target: child},
        {type: "pointerdown", target: child},
        {type: "pointerrawupdate", target: child}, // set pending pointer capture to parent
        // The following `pointermove` event dispatching runs the
        // "process pending pointer capture" steps.
        {type: "gotpointercapture", target: parent},
        {type: "pointermove", target: parent},
        {type: "pointerup", target: parent},
        {type: "lostpointercapture", target: parent},
      ])
    );
  }, "Setting pointer capture at `pointerrawupdate`");

  promise_test(async t => {
    events = [];
    child.addEventListener("pointerdown", pointerDownEvent => {
      parent.setPointerCapture(pointerDownEvent.pointerId);
      parent.addEventListener("gotpointercapture", gotPointerCaptureEvent => {
        parent.releasePointerCapture(gotPointerCaptureEvent.pointerId);
      }, {once: true});
    }, {once: true});
    await new test_driver.Actions()
      .pointerMove(0, 0, {origin: initDiv})
      .pause(ticksToPreventCoalescedPointerMove)
      .pointerMove(0, 0, {origin: child})
      .pointerDown()
      .pointerMove(1, 1, {origin: child})
      .pointerUp()
      .pointerMove(0, 0, {origin: initDiv})
      .send();
    assert_equals(
      stringifyEvents(events),
      stringifyEvents([
        {type: "pointerrawupdate", target: child},
        {type: "pointermove", target: child},
        {type: "pointerdown", target: child}, // set pending pointer capture to parent
        // The following `pointerrawupdate` event dispatching runs the
        // "process pending pointer capture" steps.
        {type: "gotpointercapture", target: parent}, // set pending pointer capture to null
        {type: "pointerrawupdate", target: parent},
        // The following `pointermove` event dispatching runs the
        // "process pending pointer capture" steps again.
        {type: "lostpointercapture", target: parent},
        {type: "pointermove", target: child},
        {type: "pointerup", target: child},
      ])
    );
  }, "Setting pointer capture at `pointerdown` and releasing pointer capture at `gotpointercapture`");

  promise_test(async t => {
    events = [];
    child.addEventListener("pointerdown", pointerDownEvent => {
      parent.setPointerCapture(pointerDownEvent.pointerId);
      parent.addEventListener("pointermove", pointerMoveEvent => {
        parent.releasePointerCapture(pointerMoveEvent.pointerId);
        parent.addEventListener("lostpointercapture", lostPointerCaptureEvent => {
          parent.setPointerCapture(lostPointerCaptureEvent.pointerId);
        }, {once: true});
      }, {once: true});
    }, {once: true});
    await new test_driver.Actions()
      .pointerMove(0, 0, {origin: initDiv})
      .pause(ticksToPreventCoalescedPointerMove)
      .pointerMove(0, 0, {origin: child})
      .pointerDown()
      .pointerMove(1, 1, {origin: child})
      .pause(ticksToPreventCoalescedPointerMove)
      .pointerMove(2, 2, {origin: child})
      .pointerUp()
      .pointerMove(0, 0, {origin: initDiv})
      .send();
    assert_equals(
      stringifyEvents(events),
      stringifyEvents([
        {type: "pointerrawupdate", target: child},
        {type: "pointermove", target: child},
        {type: "pointerdown", target: child}, // set pending pointer capture to parent
        // The following `pointerrawupdate` event dispatching runs the
        // "process pending pointer capture" steps.
        {type: "gotpointercapture", target: parent},
        {type: "pointerrawupdate", target: parent},
        {type: "pointermove", target: parent}, // set pending pointer capture to null
        // The following `pointerrawupdate` event dispatching runs the
        // "process pending pointer capture" steps again.
        {type: "lostpointercapture", target: parent}, // set pending pointer capture to parent again
        {type: "pointerrawupdate", target: child},
        // The following `pointermove` event dispatching runs the
        // "process pending pointer capture" steps again.
        {type: "gotpointercapture", target: parent},
        {type: "pointermove", target: parent},
        {type: "pointerup", target: parent},
        {type: "lostpointercapture", target: parent},
      ])
    );
  }, "Setting pointer capture at `lostpointercapture`");

  promise_test(async () => {
    parent.removeEventListener("pointerrawupdate", logEvent, {capture: true});
    // Now, there is no `pointerrawupdate` event listener.  So, browsers should
    // not dispatch `pointerrawupdate` event and the "fire a pointer event" steps
    // including the "process pending pointer capture" steps should not run twice
    // per `pointermove`.
    assert_true(true, "There is no `pointerrawupdate` event listener anymore");
  });

  promise_test(async t => {
    events = [];
    child.addEventListener("pointerdown", pointerDownEvent => {
      parent.setPointerCapture(pointerDownEvent.pointerId);
      parent.addEventListener("gotpointercapture", gotPointerCaptureEvent => {
        parent.releasePointerCapture(gotPointerCaptureEvent.pointerId);
      }, {once: true});
    }, {once: true});
    await new test_driver.Actions()
      .pointerMove(0, 0, {origin: initDiv})
      .pause(ticksToPreventCoalescedPointerMove)
      .pointerMove(0, 0, {origin: child})
      .pointerDown()
      .pointerMove(1, 1, {origin: child})
      .pause(ticksToPreventCoalescedPointerMove)
      .pointerMove(2, 2, {origin: child})
      .pointerUp()
      .pointerMove(0, 0, {origin: initDiv})
      .send();
    assert_equals(
      stringifyEvents(events),
      stringifyEvents([
        {type: "pointermove", target: child},
        {type: "pointerdown", target: child}, // set pending pointer capture to parent
        // The following `pointermove` event dispatching runs the
        // "process pending pointer capture" steps.
        {type: "gotpointercapture", target: parent}, // set pending pointer capture to null
        {type: "pointermove", target: parent},
        // The following `pointermove` event dispatching runs the
        // "process pending pointer capture" steps again.
        {type: "lostpointercapture", target: parent},
        {type: "pointermove", target: child},
        {type: "pointerup", target: child},
      ])
    );
  }, "Setting pointer capture at `pointerdown` and releasing pointer capture at `gotpointercapture` when no `pointerrawupdate` event listener");
 }, {once: true});
</script>
</head>
<body>
  <div id="initPosition"></div>
  <div id="parent">
    <div id="child">
    </div>
  </div>
</body>
</html>