diff --git a/testing/marionette/action.js b/testing/marionette/action.js index c9b4f428a425..ba007a5571dc 100644 --- a/testing/marionette/action.js +++ b/testing/marionette/action.js @@ -436,8 +436,8 @@ class InputState { /** * @param {?} obj - * Object with property |type|, representing an action sequence or an - * action item. + * Object with property |type| and optionally |parameters| or |pointerType|, + * representing an action sequence or an action item. * * @return {action.InputState} * An |action.InputState| object for the type of the |actionSequence|. @@ -451,7 +451,16 @@ class InputState { throw new InvalidArgumentError(`Unknown action type: ${type}`); } let name = type == "none" ? "Null" : capitalize(type); - return new action.InputState[name](); + if (name == "Pointer") { + if (!obj.pointerType && (!obj.parameters || !obj.parameters.pointerType)) { + throw new InvalidArgumentError( + error.pprint`Expected obj to have pointerType, got: ${obj}`); + } + let pointerType = obj.pointerType || obj.parameters.pointerType; + return new action.InputState[name](pointerType); + } else { + return new action.InputState[name](); + } } } @@ -546,12 +555,16 @@ action.InputState.Null = class Null extends InputState { * * @param {string} subtype * Kind of pointing device: mouse, pen, touch. + * + * @throws {InvalidArgumentError} + * If subtype is undefined or an invalid pointer type. */ action.InputState.Pointer = class Pointer extends InputState { constructor(subtype) { super(); this.pressed = new Set(); - this.subtype = subtype; + assert.defined(subtype, error.pprint`Expected subtype to be defined, got: ${subtype}`); + this.subtype = action.PointerType.get(subtype); this.x = 0; this.y = 0; } @@ -804,14 +817,19 @@ action.PointerParameters = class { * * @throws {InvalidArgumentError} * If |id| is already mapped to an |action.InputState| that is - * not compatible with |act.subtype|. + * not compatible with |act.type| or |pointerParams.pointerType|. */ action.processPointerAction = function processPointerAction(id, pointerParams, act) { - let subtype = act.subtype; - if (action.inputStateMap.has(id) && action.inputStateMap.get(id).subtype !== subtype) { + if (action.inputStateMap.has(id) && action.inputStateMap.get(id).type !== act.type) { + throw new InvalidArgumentError( + `Expected 'id' ${id} to be mapped to InputState whose type is ` + + `${action.inputStateMap.get(id).type}, got: ${act.type}`); + } + let pointerType = pointerParams.pointerType; + if (action.inputStateMap.has(id) && action.inputStateMap.get(id).subtype !== pointerType) { throw new InvalidArgumentError( `Expected 'id' ${id} to be mapped to InputState whose subtype is ` + - `${action.inputStateMap.get(id).subtype}, got: ${subtype}`); + `${action.inputStateMap.get(id).subtype}, got: ${pointerType}`); } act.pointerType = pointerParams.pointerType; }; diff --git a/testing/marionette/test_action.js b/testing/marionette/test_action.js index fde9c91df802..5be9df654a23 100644 --- a/testing/marionette/test_action.js +++ b/testing/marionette/test_action.js @@ -381,14 +381,23 @@ add_test(function test_processPointerActionInputStateMap() { let id = "1"; let parameters = {pointerType: "mouse"}; let a = new action.Action(id, "pointer", actionItem.type); - let wrongInputState = new action.InputState.Pointer("pause", true); + let wrongInputState = new action.InputState.Key(); + action.inputStateMap.set(id, wrongInputState); + checkErrors( + /to be mapped to InputState whose type is/, action.processPointerAction, + [id, parameters, a], + `type "pointer" with ${wrongInputState.type} in inputState`); + action.inputStateMap.clear(); + + wrongInputState = new action.InputState.Pointer("pen"); action.inputStateMap.set(id, wrongInputState); checkErrors( /to be mapped to InputState whose subtype is/, action.processPointerAction, [id, parameters, a], - `$subtype ${actionItem.type} with ${wrongInputState.subtype} in inputState`); + `subtype ${parameters.pointerType} with ${wrongInputState.subtype} in inputState`); action.inputStateMap.clear(); - let rightInputState = new action.InputState.Pointer("pointerDown", false); + + let rightInputState = new action.InputState.Pointer("mouse"); action.inputStateMap.set(id, rightInputState); action.processPointerAction(id, parameters, a); action.inputStateMap.clear(); @@ -397,7 +406,12 @@ add_test(function test_processPointerActionInputStateMap() { add_test(function test_createInputState() { for (let kind in action.InputState) { - let state = new action.InputState[kind](); + let state; + if (kind == "Pointer") { + state = new action.InputState[kind]("mouse"); + } else { + state = new action.InputState[kind](); + } ok(state); if (kind === "Null") { equal(state.type, "none"); @@ -405,6 +419,10 @@ add_test(function test_createInputState() { equal(state.type, kind.toLowerCase()); } } + Assert.throws(() => new action.InputState.Pointer(), InvalidArgumentError, + "Missing InputState.Pointer constructor arg"); + Assert.throws(() => new action.InputState.Pointer("foo"), InvalidArgumentError, + "Invalid InputState.Pointer constructor arg"); run_next_test(); });