Source code

Revision control

Copy as Markdown

Other Tools

Test Info:

<!DOCTYPE HTML>
<title>contexmenu is a PointerEvent</title>
<meta name="variant" content="?mouse">
<meta name="variant" content="?touch">
<!-- TODO: Can we test "pen" just like "touch"? -->
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-actions.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
<script src="pointerevent_support.js"></script>
<input id="target" style="margin: 20px">
<script>
'use strict';
const target = document.getElementById("target");
const pointer_type = location.search.substring(1);
function assertContextmenuProperties(contextmenu_event, pointerdown_event) {
assert_equals(contextmenu_event.constructor, window.PointerEvent,
"contextmenu should use a PointerEvent constructor");
assert_true(contextmenu_event instanceof PointerEvent,
"contextmenu should be a PointerEvent");
assert_not_equals(contextmenu_event.pointerId, -1,
"contextmenu.pointerId should not be -1");
assert_equals(contextmenu_event.pointerType, pointer_type,
"contextmenu.pointerType should match test action pointerType");
assert_equals(contextmenu_event.composed, true,
"contextmenu.composed should be true");
if (pointerdown_event) {
assert_equals(contextmenu_event.pointerId, pointerdown_event.pointerId,
"contextmenu.pointerId should match pointerdown.pointerId");
}
}
promise_test(async test => {
const test_pointer = pointer_type + "TestPointer";
let actions = new test_driver.Actions();
actions = actions.addPointer(test_pointer, pointer_type)
.pointerMove(0,0, {sourceName:test_pointer, origin:target})
.pointerDown({sourceName:test_pointer, button:actions.ButtonType.RIGHT})
.pause(pointer_type === "touch" ? 1500 : 0, "pointer", {sourceName:test_pointer})
.pointerUp({sourceName:test_pointer, button:actions.ButtonType.RIGHT});
let pointerdown_prevented = preventDefaultPointerdownOnce(target, test);
let pointerdown_promise = getEvent("pointerdown", target, test);
let contextmenu_promise = getEvent("contextmenu", target, test);
await actions.send();
await pointerdown_prevented;
let pointerdown_event = await pointerdown_promise;
let contextmenu_event = await contextmenu_promise;
assertContextmenuProperties(contextmenu_event, pointerdown_event);
}, "contextmenu using " + pointer_type + " is a PointerEvent with correct properties");
promise_test(async test => {
const test_pointer = pointer_type + "TestPointer";
let actions = new test_driver.Actions();
actions = actions.addPointer(test_pointer, pointer_type)
.pointerMove(0,0, {sourceName:test_pointer, origin:target})
.pointerDown({sourceName:test_pointer, button:actions.ButtonType.RIGHT})
.pause(pointer_type === "touch" ? 1500 : 0, "pointer", {sourceName:test_pointer})
.pointerUp({sourceName:test_pointer, button:actions.ButtonType.RIGHT});
let contextmenu_promise = getEvent("contextmenu", target, test);
await actions.send();
let contextmenu_event = await contextmenu_promise;
assertContextmenuProperties(contextmenu_event);
}, "contextmenu using " + pointer_type + " is a PointerEvent with correct properties"
+ " when no other PointerEvent listeners are present");
</script>