Bug 1341415 - Require action sequences to have an id; r?ato draft
authorMaja Frydrychowicz <mjzffr@gmail.com>
Tue, 21 Feb 2017 15:08:09 -0500
changeset 487584 f8d62ab07979c7d864efd7aa2c8a4f00474e3cc8
parent 487583 c7b015c488cfb2afbcff295a9639acd85df332f8
child 546485 3fe32dd085c50c3e5db493202986c9fdb15fb7dc
push id46254
push userbmo:mjzffr@gmail.com
push dateTue, 21 Feb 2017 20:08:47 +0000
reviewersato
bugs1341415
milestone54.0a1
Bug 1341415 - Require action sequences to have an id; r?ato MozReview-Commit-ID: DjjhIdDJ8HI
testing/marionette/action.js
testing/marionette/test_action.js
--- a/testing/marionette/action.js
+++ b/testing/marionette/action.js
@@ -708,21 +708,18 @@ action.Sequence = class extends Array {
    *     If |actionSequence.id| is not a string or it's aleady mapped
    *     to an |action.InputState} incompatible with |actionSequence.type|.
    *     If |actionSequence.actions| is not an Array.
    */
   static fromJson(actionSequence) {
     // used here only to validate 'type' and InputState type
     let inputSourceState = InputState.fromJson(actionSequence);
     let id = actionSequence.id;
-    if (typeof id == "undefined") {
-      actionSequence.id = id = element.generateUUID();
-    } else if (typeof id != "string") {
-      throw new InvalidArgumentError(`Expected 'id' to be a string, got: ${id}`);
-    }
+    assert.defined(id, "Expected 'id' to be defined");
+    assert.string(id, error.pprint`Expected 'id' to be a string, got: ${id}`);
     let actionItems = actionSequence.actions;
     if (!Array.isArray(actionItems)) {
       throw new InvalidArgumentError(
           `Expected 'actionSequence.actions' to be an Array, got: ${actionSequence.actions}`);
     }
 
     if (action.inputStateMap.has(id) && !action.inputStateMap.get(id).is(inputSourceState)) {
       throw new InvalidArgumentError(
--- a/testing/marionette/test_action.js
+++ b/testing/marionette/test_action.js
@@ -254,16 +254,20 @@ add_test(function test_processInputSourc
       regex, action.Sequence.fromJson, [actionSequence], message);
   check(`actionSequence.type: ${actionSequence.type}`, /Unknown action type/);
 
   actionSequence.type = "none";
   actionSequence.id = -1;
   check(`actionSequence.id: ${getTypeString(actionSequence.id)}`,
       /Expected 'id' to be a string/);
 
+  actionSequence.id = undefined;
+  check(`actionSequence.id: ${getTypeString(actionSequence.id)}`,
+      /Expected 'id' to be defined/);
+
   actionSequence.id = "some_id";
   actionSequence.actions = -1;
   check(`actionSequence.actions: ${getTypeString(actionSequence.actions)}`,
       /Expected 'actionSequence.actions' to be an Array/);
 
   run_next_test();
 });
 
@@ -315,32 +319,16 @@ add_test(function test_processInputSourc
       actionSequence.id, actionSequence.type, actionItem.type);
   expectedAction.value = actionItem.value;
   let actions = action.Sequence.fromJson(actionSequence);
   equal(actions.length, 1);
   deepEqual(actions[0], expectedAction);
   run_next_test();
 });
 
-add_test(function test_processInputSourceActionSequenceGenerateID() {
-  let actionItems = [
-    {
-      type: "pause",
-      duration: 5000,
-    },
-  ];
-  let actionSequence = {
-    type: "key",
-    actions: actionItems,
-  };
-  let actions = action.Sequence.fromJson(actionSequence);
-  equal(typeof actions[0].id, "string");
-  ok(actions[0].id.match(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i));
-  run_next_test();
-});
 
 add_test(function test_processInputSourceActionSequenceInputStateMap() {
   let id = "1";
   let actionItem = {type: "pause", duration: 5000};
   let actionSequence = {
     type: "key",
     id: id,
     actions: [actionItem],
@@ -468,17 +456,18 @@ add_test(function test_extractActionChai
   equal(2, actionsByTick[0].length);
   equal(2, actionsByTick[1].length);
   equal(1, actionsByTick[2].length);
   let expectedAction = new action.Action(keyActionSequence.id, "key", keyActionItems[2].type);
   expectedAction.value = keyActionItems[2].value;
   deepEqual(actionsByTick[2][0], expectedAction);
 
   // one empty action sequence
-  actionsByTick = action.Chain.fromJson([keyActionSequence, {type: "none", actions: []}]);
+  actionsByTick = action.Chain.fromJson(
+      [keyActionSequence, {type: "none", id: "some", actions: []}]);
   equal(keyActionItems.length, actionsByTick.length);
   equal(1, actionsByTick[0].length);
   run_next_test();
 });
 
 add_test(function test_computeTickDuration() {
   let expected = 8000;
   let tickActions = [