Bug 1341415 - Require action sequences to have an id. r=ato, a=test-only
authorMaja Frydrychowicz <mjzffr@gmail.com>
Tue, 21 Feb 2017 15:08:09 -0500
changeset 378680 92be498fbb00642cdddacda6e4d7cbc0b4e699cf
parent 378679 94916848475de408e4d91a5a002e6e969e6cbcfe
child 378681 a09f50f513b876153ccab49775478daba3cc6863
push id1419
push userjlund@mozilla.com
push dateMon, 10 Apr 2017 20:44:07 +0000
treeherdermozilla-release@5e6801b73ef6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersato, test-only
bugs1341415
milestone53.0a2
Bug 1341415 - Require action sequences to have an id. r=ato, a=test-only 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],
@@ -455,17 +443,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 = [