Skip to content

Commit 0a5ba65

Browse files
[CodeHealth] Rewrite PointerEvent modifier WPT using promise_test.
The test was written as an old-style sync tests, used Promise.all which made any failures hard to debug because of lack of a clear resolution order, and didn't assert modifier states individually. This test passes on headless Chrome but not in content_shell! Bug: 368980630 Change-Id: I69a08aba7b4cd3719c25ca2e9ec76d77bdaea7fa Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5994451 Commit-Queue: Kevin Ellis <kevers@chromium.org> Auto-Submit: Mustaq Ahmed <mustaq@chromium.org> Commit-Queue: Mustaq Ahmed <mustaq@chromium.org> Reviewed-by: Kevin Ellis <kevers@chromium.org> Cr-Commit-Position: refs/heads/main@{#1378577}
1 parent 40792a6 commit 0a5ba65

File tree

1 file changed

+59
-54
lines changed

1 file changed

+59
-54
lines changed
Lines changed: 59 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,65 @@
11
<!DOCTYPE html>
2-
<html>
3-
<head>
4-
<meta charset="utf-8" />
5-
<title>Mouse events with keys pressed</title>
6-
<link rel="author" title="Google" href="http://www.google.com/" />
7-
<script src="/resources/testharness.js"></script>
8-
<script src="/resources/testharnessreport.js"></script>
9-
<script src="/resources/testdriver.js"></script>
10-
<script src="/resources/testdriver-vendor.js"></script>
11-
<script src="/resources/testdriver-actions.js"></script>
12-
<script type="text/javascript" src="../pointerevent_support.js"></script>
13-
<script>
14-
let testMouseKeyPressed = async_test('Tests that the mouse events with some keys pressed.');
15-
let activeKeys = false;
2+
<title>Pointer events correctly show the modifier keys pressed</title>
3+
<link rel="author" title="Google" href="http://www.google.com/" />
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-vendor.js"></script>
8+
<script src="/resources/testdriver-actions.js"></script>
9+
<script type="text/javascript" src="../pointerevent_support.js"></script>
10+
<style>
11+
#target {
12+
width: 100px;
13+
height: 100px;
14+
}
15+
</style>
16+
<body>
17+
<div id="target"></div>
18+
</body>
19+
<script>
20+
"use strict";
1621

17-
window.addEventListener('pointermove', function(e) {
18-
activeKeys = e.getModifierState("Alt") &&
19-
e.getModifierState("Control") &&
20-
e.getModifierState("Meta") &&
21-
e.getModifierState("Shift");
22-
});
22+
const target = document.getElementById("target");
2323

24-
async function runTest(){
25-
let event_watcher = new EventWatcher(testMouseKeyPressed, window, ["pointermove"],
26-
()=>waitForAnimationFrames(200));
27-
await Promise.all([event_watcher.wait_for(["pointermove"]), inject_input()]);
28-
testMouseKeyPressed.step_func_done(()=>{
29-
assert_true(activeKeys, "Modifier keys not reflected in the pointermove event!");
30-
})();
31-
}
24+
const Modifiers = {
25+
"Shift" : '\uE008',
26+
"Control" : '\uE009',
27+
"Alt" : '\uE00A',
28+
"Meta" : '\uE03D'
29+
};
3230

33-
function inject_input() {
34-
const x = 100;
35-
const y = 100;
36-
const altKey = '\uE00A';
37-
const ctrlKey = '\uE009';
38-
const metaKey = '\uE03d';
39-
const shiftKey = '\uE008'
31+
function testModifierList(modifier_list) {
32+
promise_test(async test => {
33+
let pointermove_promise = getEvent("pointermove", target, test);
4034

41-
// First press Alt, Control, Meta, Shift keys and then send a mouse move.
42-
return new test_driver.Actions()
43-
.keyDown(altKey)
44-
.keyDown(ctrlKey)
45-
.keyDown(metaKey)
46-
.keyDown(shiftKey)
47-
.pointerMove(x,y)
48-
.send();
49-
}
50-
</script>
35+
let actions = new test_driver.Actions();
36+
for (let modifier of modifier_list) {
37+
actions = actions.keyDown(Modifiers[modifier]);
38+
}
39+
// Move the pointer off the center of "target" in case the pointer was
40+
// hovering at that position before the test started.
41+
actions = actions.pointerMove(0, 0, {origin:target})
42+
.pointerMove(10, 10, {origin:target});
43+
for (let modifier of modifier_list) {
44+
actions = actions.keyUp(Modifiers[modifier]);
45+
}
5146

52-
</head>
53-
<body id="target" onload="runTest()">
54-
<h4>Test Description: Tests that the mouse events with some keys pressed.
55-
<ol>
56-
<li>Press Alt, Control, Meta, Shift keys and move the mouse</li>
57-
</ol>
58-
</h4>
59-
</body>
60-
</html>
47+
await actions.send();
48+
let pointermove_event = await pointermove_promise;
49+
50+
for (let modifier of Object.keys(Modifiers)) {
51+
let actual = pointermove_event.getModifierState(modifier);
52+
let expected = modifier_list.includes(modifier);
53+
assert_equals(actual, expected, `getModifierState(${modifier})`);
54+
}
55+
}, `Pointer events correctly show ${modifier_list.join()} pressed`);
56+
}
57+
58+
window.onload = () => {
59+
testModifierList(["Alt"]);
60+
testModifierList(["Control"]);
61+
testModifierList(["Meta"]);
62+
testModifierList(["Shift"]);
63+
testModifierList(["Alt", "Control", "Meta", "Shift"]);
64+
}
65+
</script>

0 commit comments

Comments
 (0)