diff --git a/testing/marionette/action.js b/testing/marionette/action.js index 11f196b09280..22a77019ed95 100644 --- a/testing/marionette/action.js +++ b/testing/marionette/action.js @@ -1213,6 +1213,15 @@ function dispatchPointerDown(a, inputState, win) { inputState.y, mouseEvent, win); + if (event.MouseButton.isSecondary(a.button)) { + let contextMenuEvent = Object.assign({}, + mouseEvent, {type: "contextmenu"}); + event.synthesizeMouseAtPoint( + inputState.x, + inputState.y, + contextMenuEvent, + win); + } break; case action.PointerType.Pen: diff --git a/testing/marionette/event.js b/testing/marionette/event.js index 804c57c59db1..b3b4a7082cb4 100644 --- a/testing/marionette/event.js +++ b/testing/marionette/event.js @@ -57,6 +57,18 @@ event.Modifiers = { metaKey: 3, }; +event.MouseButton = { + isPrimary(button) { + return button === 0; + }, + isAuxiliary(button) { + return button === 1; + }, + isSecondary(button) { + return button === 2; + }, +}; + /** * Sends a mouse event to given target. * diff --git a/testing/web-platform/tests/webdriver/tests/actions/mouse.py b/testing/web-platform/tests/webdriver/tests/actions/mouse.py index 5ddcef4baa38..3ff1e3eb5a79 100644 --- a/testing/web-platform/tests/webdriver/tests/actions/mouse.py +++ b/testing/web-platform/tests/webdriver/tests/actions/mouse.py @@ -50,6 +50,30 @@ def test_click_at_coordinates(session, test_actions_page, mouse_chain): assert expected == filtered_events[1:] +def test_context_menu_at_coordinates(session, test_actions_page, mouse_chain): + div_point = { + "x": 82, + "y": 187, + } + mouse_chain \ + .pointer_move(div_point["x"], div_point["y"]) \ + .pointer_down(button=2) \ + .pointer_up(button=2) \ + .perform() + events = get_events(session) + expected = [ + {"type": "mousedown", "button": 2}, + {"type": "contextmenu", "button": 2}, + ] + assert len(events) == 4 + filtered_events = [filter_dict(e, expected[0]) for e in events] + mousedown_contextmenu_events = [ + x for x in filtered_events + if x["type"] in ["mousedown", "contextmenu"] + ] + assert expected == mousedown_contextmenu_events + + def test_click_element_center(session, test_actions_page, mouse_chain): outer = session.find.css("#outer", all=False) center = get_center(outer.rect) diff --git a/testing/web-platform/tests/webdriver/tests/actions/support/test_actions_wdspec.html b/testing/web-platform/tests/webdriver/tests/actions/support/test_actions_wdspec.html index c3d6d12daa02..be273229a3b4 100644 --- a/testing/web-platform/tests/webdriver/tests/actions/support/test_actions_wdspec.html +++ b/testing/web-platform/tests/webdriver/tests/actions/support/test_actions_wdspec.html @@ -64,6 +64,9 @@ } function recordPointerEvent(event) { + if (event.type === "contextmenu") { + event.preventDefault(); + } allEvents.events.push({ "type": event.type, "button": event.button,