--- 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",