|
Lines 1-290
a/LayoutTests/imported/w3c/web-platform-tests/inert/inert-retargeting.tentative.html_sec1
|
| 1 |
<!DOCTYPE html> |
|
|
| 2 |
<html> |
| 3 |
<head> |
| 4 |
<script src="/resources/testharness.js"></script> |
| 5 |
<script src="/resources/testharnessreport.js"></script> |
| 6 |
<script src="/resources/testdriver.js"></script> |
| 7 |
<script src="/resources/testdriver-actions.js"></script> |
| 8 |
<script src="/resources/testdriver-vendor.js"></script> |
| 9 |
<style> |
| 10 |
button#foreground, |
| 11 |
button#background { |
| 12 |
position: absolute; |
| 13 |
top: 75px; |
| 14 |
left: 50px; |
| 15 |
width: 100px; |
| 16 |
height: 20px; |
| 17 |
} |
| 18 |
|
| 19 |
button#background { |
| 20 |
left: 75px; |
| 21 |
width: 150px; |
| 22 |
height: 40px; |
| 23 |
top: 125px; |
| 24 |
line-height: 53px; |
| 25 |
} |
| 26 |
|
| 27 |
.clicked { |
| 28 |
background-color: red; |
| 29 |
} |
| 30 |
|
| 31 |
#ancestorContainer.clicked { |
| 32 |
background-color: green; |
| 33 |
} |
| 34 |
|
| 35 |
#ancestorContainer { |
| 36 |
position: relative; |
| 37 |
width: 300px; |
| 38 |
height: 300px; |
| 39 |
background-color: blue; |
| 40 |
} |
| 41 |
|
| 42 |
#displacedAncestor { |
| 43 |
position: absolute; |
| 44 |
top: 13px; |
| 45 |
left: 240px; |
| 46 |
width: 300px; |
| 47 |
height: 250px; |
| 48 |
background-color: #ff89; |
| 49 |
} |
| 50 |
|
| 51 |
#displacedAncestor.clicked { |
| 52 |
background-color: #f009; |
| 53 |
} |
| 54 |
|
| 55 |
#inertContainer { |
| 56 |
background-color: #fff9; |
| 57 |
position: absolute; |
| 58 |
top: 35px; |
| 59 |
left: -192px; |
| 60 |
width: 200px; |
| 61 |
height: 200px; |
| 62 |
} |
| 63 |
|
| 64 |
fieldset { |
| 65 |
margin: 0; |
| 66 |
padding: 0; |
| 67 |
border: 1px solid black; |
| 68 |
} |
| 69 |
|
| 70 |
legend { |
| 71 |
background-color: white; |
| 72 |
border: 1px solid black; |
| 73 |
margin-left: 5px; |
| 74 |
} |
| 75 |
|
| 76 |
button.clicked::after { |
| 77 |
content: " (clicked)"; |
| 78 |
} |
| 79 |
|
| 80 |
.clicked > legend::after { |
| 81 |
content: " (clicked)"; |
| 82 |
} |
| 83 |
|
| 84 |
</style> |
| 85 |
</head> |
| 86 |
<body> |
| 87 |
<p>Click on "foreground".</p> |
| 88 |
<ul> |
| 89 |
<li>The blue square ("Non-inert ancestor container") should turn green.</li> |
| 90 |
<li>The yellow, semi-transparent square ("Non-inert, displaced container") should not turn red.</li> |
| 91 |
<li>"Non-inert button" should not turn red.</li> |
| 92 |
</ul> |
| 93 |
<p>(The full test suite checks a range of events.)</p> |
| 94 |
<fieldset id="ancestorContainer"> |
| 95 |
<legend>Non-inert ancestor container</legend> |
| 96 |
<button id="background">background</button> |
| 97 |
<fieldset id="displacedAncestor"> |
| 98 |
<legend>Non-inert, displaced ancestor</legend> |
| 99 |
<fieldset id="inertContainer" inert> |
| 100 |
<legend>Inert container</legend> |
| 101 |
<button id="foreground">foreground</button> |
| 102 |
</fieldset> |
| 103 |
</fieldset> |
| 104 |
</fieldset> |
| 105 |
|
| 106 |
<script> |
| 107 |
document.body.addEventListener('click', (e) => { |
| 108 |
e.target.classList.add('clicked'); |
| 109 |
}); |
| 110 |
|
| 111 |
function clickOn(element) { |
| 112 |
return new test_driver.Actions() |
| 113 |
.pointerMove(0, 0, {origin: element}) |
| 114 |
.pointerDown({button: test_driver.Actions.prototype.ButtonType.LEFT}) |
| 115 |
.pointerUp({button: test_driver.Actions.prototype.ButtonType.LEFT}) |
| 116 |
.send(); |
| 117 |
} |
| 118 |
|
| 119 |
function auxClickOn(element) { |
| 120 |
return new test_driver.Actions() |
| 121 |
.pointerMove(0, 0, {origin: element}) |
| 122 |
.pointerDown({button: test_driver.Actions.prototype.ButtonType.RIGHT}) |
| 123 |
.pointerUp({button: test_driver.Actions.prototype.ButtonType.RIGHT}) |
| 124 |
.send(); |
| 125 |
} |
| 126 |
|
| 127 |
function dblClickOn(element) { |
| 128 |
return new test_driver.Actions() |
| 129 |
.pointerMove(0, 0, {origin: element}) |
| 130 |
.pointerDown({button: test_driver.Actions.prototype.ButtonType.LEFT}) |
| 131 |
.pointerUp({button: test_driver.Actions.prototype.ButtonType.LEFT}) |
| 132 |
.pointerDown({button: test_driver.Actions.prototype.ButtonType.LEFT}) |
| 133 |
.pointerUp({button: test_driver.Actions.prototype.ButtonType.LEFT}) |
| 134 |
.send(); |
| 135 |
} |
| 136 |
|
| 137 |
function movePointerOver(element) { |
| 138 |
let rect = element.getBoundingClientRect(); |
| 139 |
return new test_driver.Actions() |
| 140 |
.pointerMove(0, 0, { origin: element }) |
| 141 |
.send(); |
| 142 |
} |
| 143 |
|
| 144 |
function movePointerTo(x, y) { |
| 145 |
return new test_driver.Actions() |
| 146 |
.pointerMove(x, y, { origin: "viewport" }) |
| 147 |
.send(); |
| 148 |
} |
| 149 |
|
| 150 |
function expectEventsOn(events, element) { |
| 151 |
let promises = []; |
| 152 |
for (event of events) { |
| 153 |
((event, element) => { |
| 154 |
var promise = new Promise((resolve, reject) => { |
| 155 |
let f = (e) => { |
| 156 |
assert_equals(e.type, event); |
| 157 |
assert_equals(e.target, element); |
| 158 |
resolve(); |
| 159 |
} |
| 160 |
element.addEventListener(event, f, { capture: true, once: true }); |
| 161 |
|
| 162 |
step_timeout(() => { |
| 163 |
element.removeEventListener(event, f, { capture: true }); |
| 164 |
reject("did not get " + event + " on " + element.id); |
| 165 |
}, 1000); |
| 166 |
}); |
| 167 |
promises.push(promise); |
| 168 |
})(event, element); |
| 169 |
} |
| 170 |
return promises; |
| 171 |
} |
| 172 |
|
| 173 |
function unexpectEventsOn(events, element) { |
| 174 |
let promises = []; |
| 175 |
for (event of events) { |
| 176 |
((event, element) => { |
| 177 |
var promise = new Promise((resolve, reject) => { |
| 178 |
let f = (e) => { |
| 179 |
assert_equals(e.type, event); |
| 180 |
assert_equals(e.target, element); |
| 181 |
reject("got " + e.type + " on " + e.target.id); |
| 182 |
} |
| 183 |
element.addEventListener(event, f, { capture: true, once: true }); |
| 184 |
|
| 185 |
step_timeout(() => { |
| 186 |
element.removeEventListener(event, f, { capture: true }); |
| 187 |
resolve(); |
| 188 |
}, 1000); |
| 189 |
}); |
| 190 |
promises.push(promise); |
| 191 |
})(event, element); |
| 192 |
} |
| 193 |
return promises; |
| 194 |
} |
| 195 |
|
| 196 |
test(() => { |
| 197 |
let rect = foreground.getBoundingClientRect(); |
| 198 |
let center_x = rect.left + (rect.width / 2); |
| 199 |
let center_y = rect.top + (rect.height / 2); |
| 200 |
assert_equals(document.elementsFromPoint(center_x, center_y)[0], foreground); |
| 201 |
}, "elementsFromPoint returns inert element"); |
| 202 |
|
| 203 |
promise_test(async () => { |
| 204 |
// Test mouse events on non-inert element - events should go to "foreground" |
| 205 |
inertContainer.inert = false; |
| 206 |
await movePointerTo(0, 0); |
| 207 |
let promises = expectEventsOn(["mouseover", "mouseenter", "mousemove", "mousedown", |
| 208 |
"mouseup", "click", "auxclick", "mouseout", |
| 209 |
"mouseleave"], |
| 210 |
foreground); |
| 211 |
await clickOn(foreground); |
| 212 |
await auxClickOn(foreground); |
| 213 |
await dblClickOn(foreground); |
| 214 |
let ancestorBox = ancestorContainer.getBoundingClientRect(); |
| 215 |
let inertBox = inertContainer.getBoundingClientRect(); |
| 216 |
let x = ancestorBox.left + (ancestorBox.width / 2); |
| 217 |
let y = inertBox.bottom + ((ancestorBox.bottom - inertBox.bottom) / 2); |
| 218 |
await movePointerTo(x, y); |
| 219 |
await Promise.all(promises); |
| 220 |
}, "Tests that any mouse event on a non-inert element is correctly targeted to that element"); |
| 221 |
|
| 222 |
promise_test(async () => { |
| 223 |
// Make the containing element inert - now events should go to "container" |
| 224 |
// which is the non-inert ancestor at the same position |
| 225 |
inertContainer.inert = true; |
| 226 |
await movePointerTo(0, 0); |
| 227 |
|
| 228 |
let promises = expectEventsOn(["mouseover", "mouseenter", "mousemove", "mousedown", |
| 229 |
"mouseup", "click", "auxclick"], |
| 230 |
ancestorContainer); |
| 231 |
|
| 232 |
// TODO(aboxhall): We are getting these unexpected events. Why? |
| 233 |
promises = promises.concat(unexpectEventsOn(["mouseout", "mouseleave"], |
| 234 |
ancestorContainer)); |
| 235 |
|
| 236 |
await clickOn(foreground); |
| 237 |
await auxClickOn(foreground); |
| 238 |
await dblClickOn(foreground); |
| 239 |
let ancestorBox = ancestorContainer.getBoundingClientRect(); |
| 240 |
let inertBox = inertContainer.getBoundingClientRect(); |
| 241 |
let x = ancestorBox.left + (ancestorBox.width / 2); |
| 242 |
let y = inertBox.bottom + ((ancestorBox.bottom - inertBox.bottom) / 2); |
| 243 |
await movePointerTo(x, y); |
| 244 |
await Promise.all(promises); |
| 245 |
}, 'Tests that any mouse event on an inert element is targeted to the nearest non-inert ancestor at the same coordinates'); |
| 246 |
|
| 247 |
promise_test(async () => { |
| 248 |
// Test pointer events on non-inert element - events should go to "foreground" |
| 249 |
inertContainer.inert = false; |
| 250 |
await movePointerTo(0, 0); |
| 251 |
|
| 252 |
let promises = expectEventsOn(["pointerover", "pointerenter", "pointermove", |
| 253 |
"pointerdown", "pointerup", "pointerout", |
| 254 |
"pointerleave"], |
| 255 |
foreground); |
| 256 |
await clickOn(foreground); |
| 257 |
let ancestorBox = ancestorContainer.getBoundingClientRect(); |
| 258 |
let inertBox = inertContainer.getBoundingClientRect(); |
| 259 |
let x = ancestorBox.left + (ancestorBox.width / 2); |
| 260 |
let y = inertBox.bottom + ((ancestorBox.bottom - inertBox.bottom) / 2); |
| 261 |
await movePointerTo(x, y); |
| 262 |
await Promise.all(promises); |
| 263 |
}, "Tests that any pointer event on a non-inert element is correctly targeted to that element"); |
| 264 |
|
| 265 |
promise_test(async () => { |
| 266 |
// Make the containing element inert - now events should go to "container" |
| 267 |
// which is the non-inert ancestor at the same position |
| 268 |
inertContainer.inert = true; |
| 269 |
await movePointerTo(0, 0); |
| 270 |
|
| 271 |
let promises = expectEventsOn(["pointerover", "pointerenter", "pointermove", |
| 272 |
"pointerdown", "pointerup" ], |
| 273 |
ancestorContainer); |
| 274 |
|
| 275 |
// TODO(aboxhall): We are getting these unexpected events. Why? |
| 276 |
promises = promises.concat(unexpectEventsOn(["pointerout", "pointerleave"], |
| 277 |
ancestorContainer)); |
| 278 |
|
| 279 |
await clickOn(foreground); |
| 280 |
let ancestorBox = ancestorContainer.getBoundingClientRect(); |
| 281 |
let inertBox = inertContainer.getBoundingClientRect(); |
| 282 |
let x = ancestorBox.left + (ancestorBox.width / 2); |
| 283 |
let y = inertBox.bottom + ((ancestorBox.bottom - inertBox.bottom) / 2); |
| 284 |
await movePointerTo(x, y); |
| 285 |
await Promise.all(promises); |
| 286 |
}, 'Tests that any pointer event on an inert element is targeted to the nearest non-inert ancestor at the same coordinates'); |
| 287 |
|
| 288 |
</script> |
| 289 |
</body> |
| 290 |
</html> |