Add tick duration argument to testdriver Action

We want to allow the users to define the duration for every tick, so we
add an argument to Action class which will be a duration for all
ticks. If there is a tick which need a different duration, we can call
addTick or pause to pass a different value.

Bug: 606367
Change-Id: I7e5d88557f5f4a4c63dbf85985c30881aee9f739
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1762836
Reviewed-by: Navid Zolghadr <nzolghadr@chromium.org>
Commit-Queue: Lan Wei <lanwei@chromium.org>
Cr-Commit-Position: refs/heads/master@{#691186}
diff --git a/resources/testdriver-actions.js b/resources/testdriver-actions.js
index 43d8b1d..b53b3b0 100644
--- a/resources/testdriver-actions.js
+++ b/resources/testdriver-actions.js
@@ -3,8 +3,10 @@
 
   /**
    * Builder for creating a sequence of actions
+   * The default tick duration is set to 32ms, which is 2 frame time based on
+   * 60Hz display.
    */
-  function Actions() {
+  function Actions(defaultTickDuration=32) {
     this.sourceTypes = new Map([["key", KeySource],
                                 ["pointer", PointerSource],
                                 ["none", GeneralSource]]);
@@ -19,6 +21,7 @@
     }
     this.createSource("none");
     this.tickIdx = 0;
+    this.defaultTickDuration = defaultTickDuration;
   }
 
   Actions.prototype = {
@@ -40,7 +43,7 @@
       let actions = [];
       for (let [sourceType, sourceName] of this.sourceOrder) {
         let source = this.sources.get(sourceType).get(sourceName);
-        let serialized = source.serialize(this.tickIdx + 1);
+        let serialized = source.serialize(this.tickIdx + 1, this.defaultTickDuration);
         if (serialized) {
           serialized.id = sourceName;
           actions.push(serialized);
@@ -278,17 +281,14 @@
   }
 
   GeneralSource.prototype = {
-    serialize: function(tickCount) {
-      if (!this.actions.size) {
-        return undefined;
-      }
+    serialize: function(tickCount, defaultTickDuration) {
       let actions = [];
       let data = {"type": "none", "actions": actions};
       for (let i=0; i<tickCount; i++) {
         if (this.actions.has(i)) {
           actions.push(this.actions.get(i));
         } else {
-          actions.push({"type": "pause"});
+          actions.push({"type": "pause", duration: defaultTickDuration});
         }
       }
       return data;