Bug 1337133 - Replace element with origin for pointerMove actions. r=ato, a=test-only
authorMaja Frydrychowicz <mjzffr@gmail.com>
Tue, 14 Feb 2017 15:58:47 -0500
changeset 376534 54ce59792538f9e33c96a572936e0a60b30c2b4e
parent 376533 bc5a0dc72fe0c60d7da3137ef48ee133c1d8a615
child 376535 406823a5be09b64a9eb07e61e9f538056eb68db1
push id6996
push userjlorenzo@mozilla.com
push dateMon, 06 Mar 2017 20:48:21 +0000
treeherdermozilla-beta@d89512dab048 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersato, test-only
bugs1337133
milestone53.0a2
Bug 1337133 - Replace element with origin for pointerMove actions. r=ato, a=test-only Sync processing of pointerMove with WebDriver spec. MozReview-Commit-ID: DaHNipOffov
testing/marionette/action.js
testing/marionette/test_action.js
--- a/testing/marionette/action.js
+++ b/testing/marionette/action.js
@@ -322,16 +322,52 @@ const KEY_CODE_LOOKUP = {
   "\uE050": "ShiftRight",
   "/": "Slash",
   "?": "Slash",
   "\uE00D": "Space",
   "  ": "Space",
   "\uE004": "Tab",
 };
 
+/** Represents possible values for a pointer-move origin. */
+action.PointerOrigin = {
+  Viewport: "viewport",
+  Pointer: "pointer",
+};
+
+/**
+ * Look up a PointerOrigin.
+ *
+ * @param {?} obj
+ *     Origin for a pointerMove action.
+ *
+ * @return {?}
+ *     A pointer origin that is either "viewport" (default), "pointer", or a
+ *     web-element reference.
+ *
+ * @throws {InvalidArgumentError}
+ *     If |obj| is not a valid origin.
+ */
+action.PointerOrigin.get = function(obj) {
+  let origin = obj;
+  if (typeof obj == "undefined") {
+    origin = this.Viewport;
+  } else if (typeof obj == "string") {
+    let name = capitalize(obj);
+    if (!(name in this)) {
+      throw new InvalidArgumentError(`Unknown pointer-move origin: ${obj}`);
+    }
+    origin = this[name];
+  } else if (!element.isWebElementReference(obj)) {
+    throw new InvalidArgumentError("Expected 'origin' to be a string or a " +
+      `web element reference, got: ${obj}`);
+  }
+  return origin;
+};
+
 /** Represents possible subtypes for a pointer input source. */
 action.PointerType = {
   Mouse: "mouse",
   Pen: "pen",
   Touch: "touch",
 };
 
 /**
@@ -608,24 +644,17 @@ action.Action = class {
         break;
 
       case action.PointerMove:
         item.duration = actionItem.duration;
         if (typeof item.duration != "undefined"){
           assert.positiveInteger(item.duration,
               error.pprint`Expected 'duration' (${item.duration}) to be >= 0`);
         }
-        if (typeof actionItem.element != "undefined" &&
-            !element.isWebElementReference(actionItem.element)) {
-          throw new InvalidArgumentError(
-              "Expected 'actionItem.element' to be a web element reference, " +
-              `got: ${actionItem.element}`);
-        }
-        item.element = actionItem.element;
-
+        item.origin = action.PointerOrigin.get(actionItem.origin);
         item.x = actionItem.x;
         if (typeof item.x != "undefined") {
           assert.positiveInteger(item.x, error.pprint`Expected 'x' (${item.x}) to be >= 0`);
         }
         item.y = actionItem.y;
         if (typeof item.y != "undefined") {
           assert.positiveInteger(item.y, error.pprint`Expected 'y' (${item.y}) to be >= 0`);
         }
--- a/testing/marionette/test_action.js
+++ b/testing/marionette/test_action.js
@@ -29,19 +29,22 @@ add_test(function test_defaultPointerPar
   deepEqual(action.PointerParameters.fromJson(), defaultParameters);
 
   run_next_test();
 });
 
 add_test(function test_processPointerParameters() {
   let check = (regex, message, arg) => checkErrors(
       regex, action.PointerParameters.fromJson, [arg], message);
-  let parametersData = {pointerType: "foo"};
-  let message = `parametersData: [pointerType: ${parametersData.pointerType}]`;
-  check(/Unknown pointerType/, message, parametersData);
+  let parametersData;
+  for (let d of ["foo", "", "get", "Get"]) {
+    parametersData = {pointerType: d};
+    let message = `parametersData: [pointerType: ${parametersData.pointerType}]`;
+    check(/Unknown pointerType/, message, parametersData);
+  }
   parametersData.pointerType = "pen";
   deepEqual(action.PointerParameters.fromJson(parametersData),
       {pointerType: action.PointerType.Pen});
 
   run_next_test();
 });
 
 add_test(function test_processPointerUpDownAction() {
@@ -80,72 +83,107 @@ add_test(function test_validateActionDur
     for (let name of ["x", "y"]) {
       actionItem[name] = d;
       check("pointer", "pointerMove", `${name}: ${actionItem[name]}`);
     }
   }
   run_next_test();
 });
 
-add_test(function test_processPointerMoveActionElementValidation() {
+add_test(function test_processPointerMoveActionOriginValidation() {
+  let actionSequence = {type: "pointer", id: "some_id"};
+  let actionItem = {duration: 5000, type: "pointerMove"};
+  for (let d of [-1, {a: "blah"}, []]) {
+    actionItem.origin = d;
+    checkErrors(/Expected \'origin\' to be a string or a web element reference/,
+        action.Action.fromJson,
+        [actionSequence, actionItem],
+        `actionItem.origin: (${getTypeString(d)})`);
+  }
+
+  run_next_test();
+});
+
+add_test(function test_processPointerMoveActionOriginStringValidation() {
   let actionSequence = {type: "pointer", id: "some_id"};
   let actionItem = {duration: 5000, type: "pointerMove"};
-  for (let d of [-1, "a", {a: "blah"}]) {
-    actionItem.element = d;
-    checkErrors(/Expected 'actionItem.element' to be a web element reference/,
+  for (let d of ["a", "", "get", "Get"]) {
+    actionItem.origin = d;
+    checkErrors(/Unknown pointer-move origin/,
         action.Action.fromJson,
         [actionSequence, actionItem],
-        `actionItem.element: (${getTypeString(d)})`);
+        `actionItem.origin: ${d}`);
   }
-  actionItem.element = {[element.Key]: "something"};
+
+  run_next_test();
+});
+
+add_test(function test_processPointerMoveActionElementOrigin() {
+  let actionSequence = {type: "pointer", id: "some_id"};
+  let actionItem = {duration: 5000, type: "pointerMove"};
+  actionItem.origin = {[element.Key]: "something"};
   let a = action.Action.fromJson(actionSequence, actionItem);
-  deepEqual(a.element, actionItem.element);
+  deepEqual(a.origin, actionItem.origin);
+  run_next_test();
+});
 
+add_test(function test_processPointerMoveActionDefaultOrigin() {
+  let actionSequence = {type: "pointer", id: "some_id"};
+  // origin left undefined
+  let actionItem = {duration: 5000, type: "pointerMove"};
+  let a = action.Action.fromJson(actionSequence, actionItem);
+  deepEqual(a.origin, action.PointerOrigin.Viewport);
   run_next_test();
 });
 
 add_test(function test_processPointerMoveAction() {
   let actionSequence = {id: "some_id", type: "pointer"};
   let actionItems = [
     {
       duration: 5000,
       type: "pointerMove",
-      element: undefined,
+      origin: undefined,
       x: undefined,
       y: undefined,
     },
     {
       duration: undefined,
       type: "pointerMove",
-      element: {[element.Key]: "id", [element.LegacyKey]: "id"},
+      origin: {[element.Key]: "id", [element.LegacyKey]: "id"},
       x: undefined,
       y: undefined,
     },
     {
       duration: 5000,
       type: "pointerMove",
       x: 0,
       y: undefined,
-      element: undefined,
+      origin: undefined,
     },
     {
       duration: 5000,
       type: "pointerMove",
       x: 1,
       y: 2,
-      element: undefined,
+      origin: undefined,
     },
   ];
   for (let expected of actionItems) {
     let actual = action.Action.fromJson(actionSequence, expected);
     ok(actual instanceof action.Action);
     equal(actual.duration, expected.duration);
-    equal(actual.element, expected.element);
     equal(actual.x, expected.x);
     equal(actual.y, expected.y);
+
+    let origin = expected.origin;
+    if (typeof origin == "undefined") {
+      origin = action.PointerOrigin.Viewport;
+    }
+    deepEqual(actual.origin, origin);
+
   }
   run_next_test();
 });
 
 add_test(function test_processPointerAction() {
   let actionSequence = {
     type: "pointer",
     id: "some_id",