mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-08 19:04:45 +00:00
Bug 1337133 - Replace element with origin for pointerMove actions; r=ato+446296
Sync processing of pointerMove with WebDriver spec. MozReview-Commit-ID: DaHNipOffov --HG-- extra : rebase_source : aa50717145b9e34a94a1a61c530522477062810c
This commit is contained in:
parent
d7f6b20374
commit
c5836d25cf
@ -327,6 +327,42 @@ const KEY_CODE_LOOKUP = {
|
||||
"\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",
|
||||
@ -613,14 +649,7 @@ action.Action = class {
|
||||
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`);
|
||||
|
@ -34,9 +34,12 @@ add_test(function test_defaultPointerParameters() {
|
||||
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});
|
||||
@ -85,37 +88,66 @@ add_test(function test_validateActionDurationAndCoordinates() {
|
||||
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", {a: "blah"}]) {
|
||||
actionItem.element = d;
|
||||
checkErrors(/Expected 'actionItem.element' to be a web element reference/,
|
||||
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.element: (${getTypeString(d)})`);
|
||||
`actionItem.origin: (${getTypeString(d)})`);
|
||||
}
|
||||
actionItem.element = {[element.Key]: "something"};
|
||||
let a = action.Action.fromJson(actionSequence, actionItem);
|
||||
deepEqual(a.element, actionItem.element);
|
||||
|
||||
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 ["a", "", "get", "Get"]) {
|
||||
actionItem.origin = d;
|
||||
checkErrors(/Unknown pointer-move origin/,
|
||||
action.Action.fromJson,
|
||||
[actionSequence, actionItem],
|
||||
`actionItem.origin: ${d}`);
|
||||
}
|
||||
|
||||
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.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,
|
||||
},
|
||||
@ -124,23 +156,29 @@ add_test(function test_processPointerMoveAction() {
|
||||
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();
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user