-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathpointercaptureevents.html
162 lines (147 loc) · 5.13 KB
/
pointercaptureevents.html
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
<!DOCTYPE html>
<html>
<!--
Test cases for Pointer Events v1 spec
-->
<head>
<title>Pointer Events Capture Events Tests</title>
<meta name="viewport" content="width=device-width">
<link rel="author" href="mailto:[email protected]">
<link rel="help" href="http://www.w3.org/wiki/PointerEvents/TestAssertions">
<link rel="stylesheet" href="testharness.css"/>
<!-- http://w3c-test.org/resources/testharness.js -->
<script src="testharness.js"></script>
<script src="pointer-prefix.js"></script>
<script>
var test_capture = async_test("Capture events");
var test_related_target = async_test("Check target and relatedTarget");
function run() {
var target = document.getElementById("target");
var capturedId = -1;
var syncTestFlag;
var pointerCaptured = false;
var seenPointerCaptured = false;
var seenPointerReleased = false;
target.style[pointerPrefix["touchAction"]] = "none";
// NOTE: Not using assert_throws because it doesn't support InvalidPointerId
test(function() {
try {
target[pointerPrefix["setPointerCapture"]](-1);
assert_true(false, "Calling releasePointerCapture with invalid id didn't throw.");
} catch (ex) {
assert_equals(ex.name, "InvalidPointerId");
}
}, "Calling setPointerCapture with invalid id should throw InvalidPointerId DOMException");
test(function() {
try {
target[pointerPrefix["releasePointerCapture"]](-1);
assert_true(false, "Calling releasePointerCapture with invalid id didn't throw.");
} catch (ex) {
assert_equals(ex.name, "InvalidPointerId");
}
}, "Calling releasePointerCapture with invalid id should throw InvalidPointerId DOMException");
function onPointerEvent(event) {
if (event.pointerId !== capturedId)
return;
if (seenPointerCaptured) {
test(function() {
assert_equals(event.type, pointerPrefix["gotpointercapture"],
"First event to fire after setPointerCapture was " + pointerPrefix["gotpointercapture"])
}, "First event to fire after setPointerCapture was " + pointerPrefix["gotpointercapture"]);
seenPointerCaptured = false;
return;
}
if (seenPointerReleased) {
test(function() {
assert_equals(event.type, pointerPrefix["lostpointercapture"],
"First event to fire after releasePointerCapture was " + pointerPrefix["lostpointercapture"])
}, "First event to fire after releasePointerCapture was " + pointerPrefix["lostpointercapture"]);
seenPointerReleased = false;
return;
}
if (pointerCaptured) {
test_related_target.step(function() {
assert_equals(event.target, target,
"target of all pointer events should be the captuting element.");
assert_equals(event.relatedTarget, null,
"relatedTarget for all pointer events should be null while captuging.");
});
}
}
[
"pointerdown",
"pointerup",
"pointercancel",
"pointermove",
"pointerover",
"pointerout",
"pointerenter",
"gotpointercapture",
"lostpointercapture",
"mousedown",
"mouseup",
"mousemove",
"mouseover",
"mouseout"
].forEach(function(eventName){
on_event(target, pointerPrefix[eventName], onPointerEvent);
});
on_event(target, pointerPrefix["pointerdown"], function(event) {
capturedId = event.pointerId;
syncTestFlag = false;
target[pointerPrefix["setPointerCapture"]](capturedId);
seenPointerCaptured = true;
syncTestFlag = true;
});
on_event(target, pointerPrefix["gotpointercapture"], function(event) {
test(function(){
assert_true(syncTestFlag, "gotpointercapture fired asynchronously");
}, "gotpointercapture fired asynchronously");
test(function() {
assert_equals(event.pointerId, capturedId,
"gotpointercapture event received for pointerId " + capturedId);
}, "gotpointercapture event received for pointerId " + capturedId);
pointerCaptured = true;
});
on_event(target, pointerPrefix["pointerup"], function(event) {
test(function() {
assert_equals(event.pointerId, capturedId,
"pointerup event received for same id as pointer up " + capturedId);
}, "pointerup event received for same id as pointer up " + capturedId);
syncTestFlag = false;
target[pointerPrefix["releasePointerCapture"]](capturedId);
seenPointerReleased = true;
syncTestFlag = true;
});
on_event(target, pointerPrefix["lostpointercapture"], function(event) {
test(function(){
assert_true(syncTestFlag, "lostpointercapture fired asynchronously");
}, "lostpointercapture fired asynchronously");
test(function() {
assert_equals(event.pointerId, capturedId,
"lostpointercapture event received for pointerId " + capturedId);
}, "lostpointercapture event received for pointerId " + capturedId);
pointerCaptured = false;
test_related_target.done();
test_capture.done();
});
}
</script>
<style>
#target {
padding: 2em;
background: yellow;
border: 2px solid green;
text-align: center;
color: blue;
}
</style>
</head>
<body onload="run()">
<h1>Pointer Events Capture Events Tests</h1>
<div id="target">
Click or tap here
</div>
<div id="log"></div>
</body>
</html>