Bug 1335240 - actions.InputState does not record correct type for key and pointer; r?ato draft
authorMaja Frydrychowicz <mjzffr@gmail.com>
Wed, 01 Feb 2017 13:30:58 -0500
changeset 469138 a80a1e65c0b2c8745d015d66217ec22b52e45c28
parent 468295 2b11b3e60ca6342b04f4f4ac0ba979769dc98cf8
child 544100 c7d824a409d2bfdc3a0fbe0cc57c70e516bb415f
push id43622
push userbmo:mjzffr@gmail.com
push dateWed, 01 Feb 2017 18:31:57 +0000
reviewersato
bugs1335240
milestone54.0a1
Bug 1335240 - actions.InputState does not record correct type for key and pointer; r?ato MozReview-Commit-ID: 9RW0BretWU5
testing/marionette/action.js
testing/marionette/test_action.js
--- a/testing/marionette/action.js
+++ b/testing/marionette/action.js
@@ -420,17 +420,17 @@ class InputState {
 }
 
 /** Possible kinds of |InputState| for supported input sources. */
 action.InputState = {};
 
 /**
  * Input state associated with a keyboard-type device.
  */
-action.InputState.Key = class extends InputState {
+action.InputState.Key = class Key extends InputState {
   constructor() {
     super();
     this.pressed = new Set();
     this.alt = false;
     this.shift = false;
     this.ctrl = false;
     this.meta = false;
   }
@@ -493,32 +493,32 @@ action.InputState.Key = class extends In
   release(key) {
     return this.pressed.delete(key);
   }
 };
 
 /**
  * Input state not associated with a specific physical device.
  */
-action.InputState.Null = class extends InputState {
+action.InputState.Null = class Null extends InputState {
   constructor() {
     super();
     this.type = "none";
   }
 };
 
 /**
  * Input state associated with a pointer-type input device.
  *
  * @param {string} subtype
  *     Kind of pointing device: mouse, pen, touch.
  * @param {boolean} primary
  *     Whether the pointing device is primary.
  */
-action.InputState.Pointer = class extends InputState {
+action.InputState.Pointer = class Pointer extends InputState {
   constructor(subtype, primary) {
     super();
     this.pressed = new Set();
     this.subtype = subtype;
     this.primary = primary;
     this.x = 0;
     this.y = 0;
   }
--- a/testing/marionette/test_action.js
+++ b/testing/marionette/test_action.js
@@ -10,17 +10,17 @@ Cu.import("chrome://marionette/content/a
 Cu.import("chrome://marionette/content/element.js");
 Cu.import("chrome://marionette/content/error.js");
 
 action.inputStateMap = new Map();
 
 add_test(function test_createAction() {
   Assert.throws(() => new action.Action(), InvalidArgumentError,
       "Missing Action constructor args");
-  Assert.throws(() => new action.Action(1,2), InvalidArgumentError,
+  Assert.throws(() => new action.Action(1, 2), InvalidArgumentError,
       "Missing Action constructor args");
   Assert.throws(
       () => new action.Action(1, 2, "sometype"), /Expected string/, "Non-string arguments.");
   ok(new action.Action("id", "sometype", "sometype"));
 
   run_next_test();
 });
 
@@ -152,17 +152,17 @@ add_test(function test_processPointerMov
 add_test(function test_processPointerAction() {
   let actionSequence = {
     type: "pointer",
     id: "some_id",
     parameters: {
       pointerType: "touch",
       primary: false,
     },
-  }
+  };
   let actionItems = [
     {
       duration: 2000,
       type: "pause",
     },
     {
       type: "pointerMove",
       duration: 2000,
@@ -359,33 +359,46 @@ add_test(function test_processInputSourc
 });
 
 add_test(function test_processPointerActionInputStateMap() {
   let actionItem = {type: "pointerDown"};
   let id = "1";
   let parameters = {pointerType: "mouse", primary: false};
   let a = new action.Action(id, "pointer", actionItem.type);
   let wrongInputState = new action.InputState.Pointer("pause", true);
-  action.inputStateMap.set(id, wrongInputState)
+  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`);
   action.inputStateMap.clear();
   let rightInputState = new action.InputState.Pointer("pointerDown", false);
   action.inputStateMap.set(id, rightInputState);
   action.processPointerAction(id, parameters, a);
   equal(a.primary, parameters.primary);
   action.inputStateMap.clear();
   run_next_test();
 });
 
+add_test(function test_createInputState() {
+  for (let kind in action.InputState) {
+    let state = new action.InputState[kind]();
+    ok(state);
+    if (kind === "Null") {
+      equal(state.type, "none");
+    } else {
+      equal(state.type, kind.toLowerCase());
+    }
+  }
+  run_next_test();
+});
+
 add_test(function test_extractActionChainValidation() {
   for (let actions of [-1, "a", undefined, null]) {
-    let message = `actions: ${getTypeString(actions)}`
+    let message = `actions: ${getTypeString(actions)}`;
     Assert.throws(() => action.Chain.fromJson(actions),
         InvalidArgumentError, message);
     Assert.throws(() => action.Chain.fromJson(actions),
         /Expected 'actions' to be an Array/, message);
   }
   run_next_test();
 });