Bug 1335240 - actions.InputState does not record correct type for key and pointer. r=ato, a=test-only
authorMaja Frydrychowicz <mjzffr@gmail.com>
Wed, 01 Feb 2017 13:30:58 -0500
changeset 376503 5f7f4b00b19f159d491ab717480efe60cfe6e429
parent 376502 d68639a64412962018e2d516035038216d602f4d
child 376504 f3257085d3c4be6c83eb616d29f70b816638983e
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
bugs1335240
milestone53.0a2
Bug 1335240 - actions.InputState does not record correct type for key and pointer. r=ato, a=test-only 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,
@@ -347,33 +347,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();
 });