Bug 1370403 - Synthesize contextmenu MouseEvent when performing webdriver actions. r=maja_zf, a=test-only
authormuthuraj90ec <muthuraj90ec@gmail.com>
Wed, 09 Aug 2017 07:51:18 -0400
changeset 421189 9c5b86d50b9bdd3dba2f1938a64ac39fe8503f74
parent 421188 8b3ea08178d1e15029c515d0173fdf67c0c5ab6e
child 421190 b6b61f8221fb1636fee4445b7a94b0df23ffeda6
push id7617
push userryanvm@gmail.com
push dateTue, 15 Aug 2017 14:10:45 +0000
treeherdermozilla-beta@efabe9b3a88e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmaja_zf, test-only
bugs1370403
milestone56.0
Bug 1370403 - Synthesize contextmenu MouseEvent when performing webdriver actions. r=maja_zf, a=test-only MozReview-Commit-ID: 85nQTsTRttF
testing/marionette/action.js
testing/marionette/event.js
testing/web-platform/tests/webdriver/tests/actions/mouse.py
testing/web-platform/tests/webdriver/tests/actions/support/test_actions_wdspec.html
--- a/testing/marionette/action.js
+++ b/testing/marionette/action.js
@@ -1208,16 +1208,25 @@ function dispatchPointerDown(a, inputSta
       case action.PointerType.Mouse:
         let mouseEvent = new action.Mouse("mousedown", a.button);
         mouseEvent.update(inputState);
         event.synthesizeMouseAtPoint(
             inputState.x,
             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:
       case action.PointerType.Touch:
         throw new UnsupportedOperationError("Only 'mouse' pointer type is supported");
 
       default:
         throw new TypeError(`Unknown pointer type: ${inputState.subtype}`);
--- a/testing/marionette/event.js
+++ b/testing/marionette/event.js
@@ -52,16 +52,28 @@ event.MouseEvents = {
 
 event.Modifiers = {
   shiftKey: 0,
   ctrlKey: 1,
   altKey: 2,
   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.
  *
  * @param {nsIDOMMouseEvent} mouseEvent
  *     Event to send.
  * @param {(DOMElement|string)} target
  *     Target of event.  Can either be an element or the ID of an element.
  * @param {Window=} window
--- a/testing/web-platform/tests/webdriver/tests/actions/mouse.py
+++ b/testing/web-platform/tests/webdriver/tests/actions/mouse.py
@@ -45,16 +45,40 @@ def test_click_at_coordinates(session, t
         {"type": "mousedown", "buttons": 1},
         {"type": "mouseup",  "buttons": 0},
         {"type": "click", "buttons": 0},
     ]
     filtered_events = [filter_dict(e, expected[0]) for e in events]
     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)
     mouse_chain.click(element=outer).perform()
     events = get_events(session)
     assert len(events) == 4
     event_types = [e["type"] for e in events]
     assert ["mousemove", "mousedown", "mouseup", "click"] == event_types
--- 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
@@ -59,16 +59,19 @@
           appendMessage(`${event.type}(` +
               `code: ${event.code}, ` +
               `key: ${key}, ` +
               `which: ${event.which}, ` +
               `keyCode: ${event.keyCode})`);
         }
 
         function recordPointerEvent(event) {
+          if (event.type === "contextmenu") {
+            event.preventDefault();
+          }
           allEvents.events.push({
             "type": event.type,
             "button": event.button,
             "buttons": event.buttons,
             "pageX": event.pageX,
             "pageY": event.pageY,
             "ctrlKey": event.ctrlKey,
             "metaKey": event.metaKey,