Skip to content

Commit ef03c55

Browse files
liviutintachromium-wpt-export-bot
authored andcommitted
Add test coverage for pointerId, pointerType for click as PointerEvent
Check pointerId, pointerType are the same as for the pointer event stream that generated the click/auxclick event. Bug: 1150441 Change-Id: Ic3c7bc05efad1b4024edbe3fc83cdbd812111c31 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2549464 Commit-Queue: Liviu Tinta <[email protected]> Reviewed-by: Mustaq Ahmed <[email protected]> Cr-Commit-Position: refs/heads/master@{#830213}
1 parent 858185d commit ef03c55

File tree

3 files changed

+98
-30
lines changed

3 files changed

+98
-30
lines changed

pointerevents/pointerevent_auxclick_is_a_pointerevent.html

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,47 @@
1010
<input id="target" style="margin: 20px">
1111

1212
<script>
13-
'use strict';
14-
let auxclickTest = async_test("auxclick is a PointerEvent");
15-
let target = document.getElementById("target");
13+
'use strict';
14+
let target = document.getElementById("target");
15+
let pointerId = 0;
16+
let pointerType = "";
1617

17-
target.addEventListener("auxclick", auxclickTest.step_func((e)=>{
18+
target.addEventListener("pointerdown", (e)=>{
19+
pointerId = e.pointerId;
20+
pointerType = e.pointerType;
21+
});
22+
23+
function testFunction(test){
24+
return test.step_func(e=>{
25+
assert_equals(e.constructor, window.PointerEvent, "auxclick should use a PointerEvent constructor");
1826
assert_true(e instanceof PointerEvent, "auxclick should be a PointerEvent");
19-
}));
20-
let eventWatcher = new EventWatcher(auxclickTest, target, ["auxclick"]);
21-
let actions = new test_driver.Actions();
22-
actions = actions.pointerMove(0,0, {origin:target})
23-
.pointerDown({button:actions.ButtonType.MIDDLE})
24-
.pointerUp({button:actions.ButtonType.MIDDLE});
25-
Promise.all([eventWatcher.wait_for("auxclick"), actions.send()]).then(()=>auxclickTest.done());
27+
assert_equals(e.pointerId, pointerId, "auxclick's pointerId should match the pointerId of the pointer event that triggers it");
28+
assert_equals(e.pointerType, pointerType, "axclick's pointerType should match the pointerType of the pointer event that triggers it");
29+
});
30+
}
31+
32+
function run_test(pointerType){
33+
promise_test((test) => new Promise((resolve, reject) => {
34+
const testPointer = "TestPointer";
35+
let auxclickFunc = testFunction(test);
36+
test.add_cleanup(() => {
37+
target.removeEventListener("auxclick", auxclickFunc);
38+
pointerId = 0;
39+
pointerType = "";
40+
});
41+
target.addEventListener("auxclick", auxclickFunc);
42+
let eventWatcher = new EventWatcher(test, target, ["auxclick"]);
43+
let actions = new test_driver.Actions();
44+
actions = actions
45+
.addPointer(testPointer, pointerType)
46+
.pointerMove(0,0, {origin:target, sourceName:testPointer})
47+
.pointerDown({button:actions.ButtonType.MIDDLE, sourceName:testPointer})
48+
.pointerUp({button:actions.ButtonType.MIDDLE, sourceName:testPointer});
49+
Promise.all([eventWatcher.wait_for("auxclick"), actions.send()]).then(()=>resolve());
50+
}), "auxclick using " + pointerType + " is a PointerEvent");
51+
}
52+
53+
run_test("mouse");
54+
run_test("pen");
55+
// TODO(crbug.com/1150441): Add test for auxclick from touch.Note: Calling run_test("touch") here times out.
2656
</script>

pointerevents/pointerevent_click_is_a_pointerevent.html

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,53 @@
44
<script src="/resources/testharness.js"></script>
55
<script src="/resources/testharnessreport.js"></script>
66
<script src="/resources/testdriver.js"></script>
7+
<script src="/resources/testdriver-actions.js"></script>
78
<script src="/resources/testdriver-vendor.js"></script>
89

910
<input id="target" style="margin: 20px">
1011

1112
<script>
12-
'use strict';
13-
let clickTest = async_test("click is a PointerEvent");
14-
let target = document.getElementById("target");
13+
'use strict';
14+
let target = document.getElementById("target");
15+
let pointerId = 0;
16+
let pointerType = "";
1517

16-
target.addEventListener("click", clickTest.step_func((e)=>{
18+
target.addEventListener("pointerdown", (e)=>{
19+
pointerId = e.pointerId;
20+
pointerType = e.pointerType;
21+
});
22+
23+
function testFunction(test){
24+
return test.step_func(e=>{
25+
assert_equals(e.constructor, window.PointerEvent, "click should use a PointerEvent constructor");
1726
assert_true(e instanceof PointerEvent, "click should be a PointerEvent");
18-
}));
19-
let eventWatcher = new EventWatcher(clickTest, target, ["click"]);
20-
Promise.all([eventWatcher.wait_for("click"), test_driver.click(target)]).then(()=>clickTest.done());
27+
assert_equals(e.pointerId, pointerId, "click's pointerId should match the pointerId of the pointer event that triggers it");
28+
assert_equals(e.pointerType, pointerType, "click's pointerType should match the pointerType of the pointer event that triggers it");
29+
});
30+
}
31+
32+
function run_test(pointerType){
33+
promise_test((test) => new Promise((resolve, reject) => {
34+
const testPointer = "TestPointer";
35+
let clickFunc = testFunction(test);
36+
test.add_cleanup(() => {
37+
target.removeEventListener("click", clickFunc);
38+
pointerId = 0;
39+
pointerType = "";
40+
});
41+
target.addEventListener("click", clickFunc);
42+
let eventWatcher = new EventWatcher(test, target, ["click"]);
43+
let actions = new test_driver.Actions();
44+
actions = actions
45+
.addPointer(testPointer, pointerType)
46+
.pointerMove(0,0, {origin:target, sourceName:testPointer})
47+
.pointerDown({sourceName:testPointer})
48+
.pointerUp({sourceName:testPointer});
49+
Promise.all([eventWatcher.wait_for("click"), actions.send()]).then(()=>resolve());
50+
}), "click using " + pointerType + " is a PointerEvent");
51+
}
52+
53+
run_test("mouse");
54+
run_test("pen");
55+
// TODO(crbug.com/1150593): Add wpt test for touch (reuse run_test)
2156
</script>

pointerevents/pointerevent_contextmenu_is_a_pointerevent.html

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,20 @@
1010
<input id="target" style="margin: 20px">
1111

1212
<script>
13-
'use strict';
14-
let contextmenuTest = async_test("contextmenu is a PointerEvent");
15-
let target = document.getElementById("target");
13+
'use strict';
14+
let contextmenuTest = async_test("contextmenu is a PointerEvent");
15+
let target = document.getElementById("target");
1616

17-
target.addEventListener("contextmenu", contextmenuTest.step_func((e)=>{
18-
assert_true(e instanceof PointerEvent, "contextmenu should be a PointerEvent");
19-
}));
20-
let eventWatcher = new EventWatcher(contextmenuTest, target, ["contextmenu"]);
21-
let actions = new test_driver.Actions();
22-
actions = actions.pointerMove(0,0, {origin:target})
23-
.pointerDown({button:actions.ButtonType.RIGHT})
24-
.pointerUp({button:actions.ButtonType.RIGHT});
25-
Promise.all([eventWatcher.wait_for("contextmenu"), actions.send()]).then(()=>contextmenuTest.done());
17+
target.addEventListener("contextmenu", contextmenuTest.step_func((e)=>{
18+
assert_equals(e.constructor, window.PointerEvent, "contextmenu should use a PointerEvent constructor");
19+
assert_true(e instanceof PointerEvent, "contextmenu should be a PointerEvent");
20+
// TODO(crbug.com/1150441,crbug.com/1150442): Test pointerId, pointerType are properly populated from the pointer event stream
21+
}));
22+
23+
let eventWatcher = new EventWatcher(contextmenuTest, target, ["contextmenu"]);
24+
let actions = new test_driver.Actions();
25+
actions = actions.pointerMove(0,0, {origin:target})
26+
.pointerDown({button:actions.ButtonType.RIGHT})
27+
.pointerUp({button:actions.ButtonType.RIGHT});
28+
Promise.all([eventWatcher.wait_for("contextmenu"), actions.send()]).then(()=>contextmenuTest.done());
2629
</script>

0 commit comments

Comments
 (0)