|
10 | 10 | <input id="target" style="margin: 20px">
|
11 | 11 |
|
12 | 12 | <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 = ""; |
16 | 17 |
|
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"); |
18 | 26 | 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. |
26 | 56 | </script>
|
0 commit comments