-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Expand file tree
/
Copy pathevents-on-pseudo-element-shadow-dom.html
More file actions
246 lines (215 loc) · 6.87 KB
/
Copy pathevents-on-pseudo-element-shadow-dom.html
File metadata and controls
246 lines (215 loc) · 6.87 KB
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
<!DOCTYPE html>
<link rel=author href="mailto:jarhar@chromium.org">
<link rel=help href="https://github.com/w3c/uievents/pull/413">
<link rel=help href="https://drafts.csswg.org/css-pseudo/#CSSPseudoElement-interface">
<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>
#host {
margin: 20px;
}
#host2 {
margin: 20px;
}
#host2::before {
content: "HOST_BEFORE";
display: block;
width: 100px;
height: 100px;
background: red;
}
#host3 {
margin: 20px;
}
#host4 {
margin: 20px;
}
#host4::before {
content: "before";
display: list-item;
list-style-position: inside;
height: 40px;
}
#host4::after {
content: "after";
display: list-item;
list-style-position: inside;
height: 40px;
}
#host4::before::marker {
content: "before-marker";
font-size: 20px;
}
#host4::after::marker {
content: "after-marker";
font-size: 20px;
}
</style>
<div id=host>
<template shadowrootmode=open>
<style>
#inner::before {
content: "BEFORE";
display: block;
width: 100px;
height: 100px;
background: blue;
}
</style>
<div id=inner></div>
</template>
</div>
<div id=host2>
<template shadowrootmode=open>
</template>
</div>
<div id=host3>
<template shadowrootmode=open>
<style>
#inner3::before {
content: "before";
display: list-item;
list-style-position: inside;
height: 40px;
}
#inner3::after {
content: "after";
display: list-item;
list-style-position: inside;
height: 40px;
}
#inner3::before::marker {
content: "before-marker";
font-size: 20px;
}
#inner3::after::marker {
content: "after-marker";
font-size: 20px;
}
</style>
<div id=inner3></div>
</template>
</div>
<div id=host4>
<template shadowrootmode=open>
</template>
</div>
<script>
promise_test(async () => {
const host = document.getElementById('host');
const shadowRoot = host.shadowRoot;
const inner = shadowRoot.getElementById('inner');
let innerPseudoTarget = undefined;
let hostPseudoTarget = undefined;
let clickEvent = undefined;
inner.addEventListener('click', event => {
innerPseudoTarget = event.pseudoTarget;
clickEvent = event;
});
host.addEventListener('click', event => {
hostPseudoTarget = event.pseudoTarget;
});
const pseudo = inner.pseudo('::before');
const rect = inner.getBoundingClientRect();
const x = rect.left + 50;
const y = rect.top + 50;
await new test_driver.Actions()
.pointerMove(x, y)
.pointerDown()
.pointerUp()
.send();
assert_not_equals(innerPseudoTarget, undefined,
'Inner listener should have fired');
assert_not_equals(hostPseudoTarget, undefined,
'Host listener should have fired');
assert_equals(innerPseudoTarget, pseudo,
'Inside shadow DOM: pseudoTarget should be the CSSPseudoElement');
assert_equals(hostPseudoTarget, null,
'Outside shadow DOM (retargeted): pseudoTarget should be null');
assert_equals(clickEvent.pseudoTarget, null,
'After dispatch, pseudoTarget should be null');
}, 'event.pseudoTarget is null when retargeted across shadow boundary');
promise_test(async () => {
const host2 = document.getElementById('host2');
let hostPseudoTarget = undefined;
let clickEvent = undefined;
host2.addEventListener('click', event => {
hostPseudoTarget = event.pseudoTarget;
clickEvent = event;
});
const pseudo = host2.pseudo('::before');
const rect = host2.getBoundingClientRect();
const x = rect.left + 50;
const y = rect.top + 50;
await new test_driver.Actions()
.pointerMove(x, y)
.pointerDown()
.pointerUp()
.send();
assert_equals(hostPseudoTarget, pseudo,
'pseudoTarget should be the CSSPseudoElement during event dispatch.');
assert_equals(clickEvent.pseudoTarget, null,
'pseudoTarget should be null after event dispatch.');
}, 'event.pseudoTarget is preserved when clicking host pseudo-element');
for (const pseudoType of ['::before', '::after']) {
promise_test(async () => {
const host3 = document.getElementById('host3');
const shadowRoot = host3.shadowRoot;
const inner3 = shadowRoot.getElementById('inner3');
let innerPseudoTarget = undefined;
let hostPseudoTarget = undefined;
let clickEvent = undefined;
inner3.addEventListener('click', event => {
innerPseudoTarget = event.pseudoTarget;
clickEvent = event;
});
host3.addEventListener('click', event => {
hostPseudoTarget = event.pseudoTarget;
});
const pseudo = inner3.pseudo(pseudoType).pseudo('::marker');
const rect = inner3.getBoundingClientRect();
const x = rect.left + 15;
const y = pseudoType === '::before' ? rect.top + 10 : rect.top + 50;
await new test_driver.Actions()
.pointerMove(x, y)
.pointerDown()
.pointerUp()
.send();
assert_not_equals(innerPseudoTarget, undefined,
'Inner listener should have fired');
assert_not_equals(hostPseudoTarget, undefined,
'Host listener should have fired');
assert_equals(innerPseudoTarget, pseudo,
'Inside shadow DOM: pseudoTarget should be the CSSPseudoElement');
assert_equals(hostPseudoTarget, null,
'Outside shadow DOM (retargeted): pseudoTarget should be null');
assert_equals(clickEvent.pseudoTarget, null,
'After dispatch, pseudoTarget should be null');
}, `event.pseudoTarget is null when clicking ${pseudoType}::marker retargeted across shadow boundary`);
promise_test(async () => {
const host4 = document.getElementById('host4');
let hostPseudoTarget = undefined;
let clickEvent = undefined;
host4.addEventListener('click', event => {
hostPseudoTarget = event.pseudoTarget;
clickEvent = event;
});
const pseudo = host4.pseudo(pseudoType).pseudo('::marker');
const rect = host4.getBoundingClientRect();
const x = rect.left + 15;
const y = pseudoType === '::before' ? rect.top + 10 : rect.top + 50;
await new test_driver.Actions()
.pointerMove(x, y)
.pointerDown()
.pointerUp()
.send();
assert_equals(hostPseudoTarget, pseudo,
'pseudoTarget should be the CSSPseudoElement during event dispatch.');
assert_equals(clickEvent.pseudoTarget, null,
'pseudoTarget should be null after event dispatch.');
}, `event.pseudoTarget is preserved when clicking host ${pseudoType}::marker pseudo-element`);
}
</script>