-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug 1929379 [wpt PR 48985] - [CodeHealth] Rewrite PointerEvent modifi…
…er WPT using promise_test., a=testonly Automatic update from web-platform-tests [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 <[email protected]> Auto-Submit: Mustaq Ahmed <[email protected]> Commit-Queue: Mustaq Ahmed <[email protected]> Reviewed-by: Kevin Ellis <[email protected]> Cr-Commit-Position: refs/heads/main@{#1378577} -- wpt-commits: 0a5ba65a140dc74ade845482466ed03699d0315e wpt-pr: 48985
- Loading branch information
1 parent
2b4ceeb
commit 1195919
Showing
1 changed file
with
59 additions
and
54 deletions.
There are no files selected for viewing
113 changes: 59 additions & 54 deletions
113
testing/web-platform/tests/pointerevents/compat/pointerevent_mouseevent_key_pressed.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +1,65 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<title>Mouse events with keys pressed</title> | ||
<link rel="author" title="Google" href="http://www.google.com/" /> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script src="/resources/testdriver.js"></script> | ||
<script src="/resources/testdriver-vendor.js"></script> | ||
<script src="/resources/testdriver-actions.js"></script> | ||
<script type="text/javascript" src="../pointerevent_support.js"></script> | ||
<script> | ||
let testMouseKeyPressed = async_test('Tests that the mouse events with some keys pressed.'); | ||
let activeKeys = false; | ||
<title>Pointer events correctly show the modifier keys pressed</title> | ||
<link rel="author" title="Google" href="http://www.google.com/" /> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script src="/resources/testdriver.js"></script> | ||
<script src="/resources/testdriver-vendor.js"></script> | ||
<script src="/resources/testdriver-actions.js"></script> | ||
<script type="text/javascript" src="../pointerevent_support.js"></script> | ||
<style> | ||
#target { | ||
width: 100px; | ||
height: 100px; | ||
} | ||
</style> | ||
<body> | ||
<div id="target"></div> | ||
</body> | ||
<script> | ||
"use strict"; | ||
|
||
window.addEventListener('pointermove', function(e) { | ||
activeKeys = e.getModifierState("Alt") && | ||
e.getModifierState("Control") && | ||
e.getModifierState("Meta") && | ||
e.getModifierState("Shift"); | ||
}); | ||
const target = document.getElementById("target"); | ||
|
||
async function runTest(){ | ||
let event_watcher = new EventWatcher(testMouseKeyPressed, window, ["pointermove"], | ||
()=>waitForAnimationFrames(200)); | ||
await Promise.all([event_watcher.wait_for(["pointermove"]), inject_input()]); | ||
testMouseKeyPressed.step_func_done(()=>{ | ||
assert_true(activeKeys, "Modifier keys not reflected in the pointermove event!"); | ||
})(); | ||
} | ||
const Modifiers = { | ||
"Shift" : '\uE008', | ||
"Control" : '\uE009', | ||
"Alt" : '\uE00A', | ||
"Meta" : '\uE03D' | ||
}; | ||
|
||
function inject_input() { | ||
const x = 100; | ||
const y = 100; | ||
const altKey = '\uE00A'; | ||
const ctrlKey = '\uE009'; | ||
const metaKey = '\uE03d'; | ||
const shiftKey = '\uE008' | ||
function testModifierList(modifier_list) { | ||
promise_test(async test => { | ||
let pointermove_promise = getEvent("pointermove", target, test); | ||
|
||
// First press Alt, Control, Meta, Shift keys and then send a mouse move. | ||
return new test_driver.Actions() | ||
.keyDown(altKey) | ||
.keyDown(ctrlKey) | ||
.keyDown(metaKey) | ||
.keyDown(shiftKey) | ||
.pointerMove(x,y) | ||
.send(); | ||
} | ||
</script> | ||
let actions = new test_driver.Actions(); | ||
for (let modifier of modifier_list) { | ||
actions = actions.keyDown(Modifiers[modifier]); | ||
} | ||
// Move the pointer off the center of "target" in case the pointer was | ||
// hovering at that position before the test started. | ||
actions = actions.pointerMove(0, 0, {origin:target}) | ||
.pointerMove(10, 10, {origin:target}); | ||
for (let modifier of modifier_list) { | ||
actions = actions.keyUp(Modifiers[modifier]); | ||
} | ||
|
||
</head> | ||
<body id="target" onload="runTest()"> | ||
<h4>Test Description: Tests that the mouse events with some keys pressed. | ||
<ol> | ||
<li>Press Alt, Control, Meta, Shift keys and move the mouse</li> | ||
</ol> | ||
</h4> | ||
</body> | ||
</html> | ||
await actions.send(); | ||
let pointermove_event = await pointermove_promise; | ||
|
||
for (let modifier of Object.keys(Modifiers)) { | ||
let actual = pointermove_event.getModifierState(modifier); | ||
let expected = modifier_list.includes(modifier); | ||
assert_equals(actual, expected, `getModifierState(${modifier})`); | ||
} | ||
}, `Pointer events correctly show ${modifier_list.join()} pressed`); | ||
} | ||
|
||
window.onload = () => { | ||
testModifierList(["Alt"]); | ||
testModifierList(["Control"]); | ||
testModifierList(["Meta"]); | ||
testModifierList(["Shift"]); | ||
testModifierList(["Alt", "Control", "Meta", "Shift"]); | ||
} | ||
</script> |