pointerevent_contextmenu_is_a_pointerevent.html (3617B)
1 <!DOCTYPE HTML> 2 <title>contexmenu is a PointerEvent</title> 3 <meta name="variant" content="?mouse"> 4 <meta name="variant" content="?touch"> 5 <!-- TODO: Can we test "pen" just like "touch"? --> 6 <link rel="help" href="https://github.com/w3c/pointerevents/pull/317"> 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-actions.js"></script> 11 <script src="/resources/testdriver-vendor.js"></script> 12 <script src="pointerevent_support.js"></script> 13 14 <input id="target" style="margin: 20px"> 15 16 <script> 17 'use strict'; 18 const target = document.getElementById("target"); 19 const pointer_type = location.search.substring(1); 20 21 // Prevent opening contextmenu. 22 addEventListener("contextmenu", e => e.preventDefault()); 23 24 function assertContextmenuProperties(contextmenu_event, pointerdown_event) { 25 assert_equals(contextmenu_event.constructor, window.PointerEvent, 26 "contextmenu should use a PointerEvent constructor"); 27 assert_true(contextmenu_event instanceof PointerEvent, 28 "contextmenu should be a PointerEvent"); 29 assert_not_equals(contextmenu_event.pointerId, -1, 30 "contextmenu.pointerId should not be -1"); 31 assert_equals(contextmenu_event.pointerType, pointer_type, 32 "contextmenu.pointerType should match test action pointerType"); 33 assert_equals(contextmenu_event.composed, true, 34 "contextmenu.composed should be true"); 35 36 if (pointerdown_event) { 37 assert_equals(contextmenu_event.pointerId, pointerdown_event.pointerId, 38 "contextmenu.pointerId should match pointerdown.pointerId"); 39 } 40 } 41 42 promise_test(async test => { 43 const test_pointer = pointer_type + "TestPointer"; 44 45 let actions = new test_driver.Actions(); 46 actions = actions.addPointer(test_pointer, pointer_type) 47 .pointerMove(0,0, {sourceName:test_pointer, origin:target}) 48 .pointerDown({sourceName:test_pointer, button:actions.ButtonType.RIGHT}) 49 .pause(pointer_type === "touch" ? 1500 : 0, "pointer", {sourceName:test_pointer}) 50 .pointerUp({sourceName:test_pointer, button:actions.ButtonType.RIGHT}); 51 let pointerdown_prevented = preventDefaultPointerdownOnce(target, test); 52 let pointerdown_promise = getEvent("pointerdown", target, test); 53 let contextmenu_promise = getEvent("contextmenu", target, test); 54 55 await actions.send(); 56 await pointerdown_prevented; 57 let pointerdown_event = await pointerdown_promise; 58 let contextmenu_event = await contextmenu_promise; 59 60 assertContextmenuProperties(contextmenu_event, pointerdown_event); 61 }, "contextmenu using " + pointer_type + " is a PointerEvent with correct properties"); 62 63 promise_test(async test => { 64 const test_pointer = pointer_type + "TestPointer"; 65 66 let actions = new test_driver.Actions(); 67 actions = actions.addPointer(test_pointer, pointer_type) 68 .pointerMove(0,0, {sourceName:test_pointer, origin:target}) 69 .pointerDown({sourceName:test_pointer, button:actions.ButtonType.RIGHT}) 70 .pause(pointer_type === "touch" ? 1500 : 0, "pointer", {sourceName:test_pointer}) 71 .pointerUp({sourceName:test_pointer, button:actions.ButtonType.RIGHT}); 72 let contextmenu_promise = getEvent("contextmenu", target, test); 73 74 await actions.send(); 75 let contextmenu_event = await contextmenu_promise; 76 77 assertContextmenuProperties(contextmenu_event); 78 }, "contextmenu using " + pointer_type + " is a PointerEvent with correct properties" 79 + " when no other PointerEvent listeners are present"); 80 </script>