Bug 1302707 - Make GeckoDriver#timeouts spec compatible. r=automatedtester, a=test-only
authorAndreas Tolfsen <ato@mozilla.com>
Wed, 14 Sep 2016 18:10:22 +0100
changeset 350513 65b9e6c2ebc15388b939ca00ecc1aeee89253e01
parent 350512 017b6d1f94ae3d4d1402e09821ffbeba4a23d93b
child 350514 9b2b1f7ed3861b543a24a9633db00cb8ca746fd3
push id1230
push userjlund@mozilla.com
push dateMon, 31 Oct 2016 18:13:35 +0000
treeherdermozilla-release@5e06e3766db2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersautomatedtester, test-only
bugs1302707
milestone50.0
Bug 1302707 - Make GeckoDriver#timeouts spec compatible. r=automatedtester, a=test-only MozReview-Commit-ID: 7vLVbKKuZNV
testing/marionette/driver.js
--- a/testing/marionette/driver.js
+++ b/testing/marionette/driver.js
@@ -1523,40 +1523,58 @@ GeckoDriver.prototype.switchToFrame = fu
       yield browserListening;
     }
   }
 };
 
 /**
  * Set timeout for page loading, searching, and scripts.
  *
- * @param {string} type
- *     Type of timeout.
- * @param {number} ms
- *     Timeout in milliseconds.
+ * @param {Object.<string, number>}
+ *     Dictionary of timeout types and their new value, where all timeout
+ *     types are optional.
+ *
+ * @throws {InvalidArgumentError}
+ *     If timeout type key is unknown, or the value provided with it is
+ *     not an integer.
  */
 GeckoDriver.prototype.timeouts = function(cmd, resp) {
-  let typ = cmd.parameters.type;
-  let ms = parseInt(cmd.parameters.ms);
-  if (isNaN(ms)) {
-    throw new WebDriverError("Not a Number");
+  // backwards compatibility with old API
+  // that accepted a dictionary {type: <string>, ms: <number>}
+  let timeouts = {};
+  if (typeof cmd.parameters == "object" &&
+      "type" in cmd.parameters &&
+      "ms" in cmd.parameters) {
+    logger.warn("Using deprecated data structure for setting timeouts");
+    timeouts = {[cmd.parameters.type]: parseInt(cmd.parameters.ms)};
+  } else {
+    timeouts = cmd.parameters;
   }
 
-  switch (typ) {
-    case "implicit":
-      this.setSearchTimeout(cmd, resp);
-      break;
+  for (let [typ, ms] of Object.entries(timeouts)) {
+    if (!Number.isInteger(ms)) {
+      throw new InvalidArgumentError();
+    }
+
+    switch (typ) {
+      case "implicit":
+        this.searchTimeout = ms;
+        break;
 
-    case "script":
-      this.setScriptTimeout(cmd, resp);
-      break;
+      case "script":
+        this.scriptTimeout = ms;
+        break;
 
-    default:
-      this.pageTimeout = ms;
-      break;
+      case "page load":
+        this.pageTimeout = ms;
+        break;
+
+      default:
+        throw new InvalidArgumentError();
+    }
   }
 };
 
 /** Single tap. */
 GeckoDriver.prototype.singleTap = function*(cmd, resp) {
   let {id, x, y} = cmd.parameters;
 
   switch (this.context) {