Bug 1470659 - Simplify Marionette capability parsing. r=whimboo
authorAndreas Tolfsen <ato@sny.no>
Sat, 21 Jul 2018 18:29:39 +0100
changeset 429700 39954f25c48e32f2393d3a4550bd3a85f117d37f
parent 429699 b9b178105f1bd1d794e53c2fb128bd9e505f8f32
child 429701 203d1449aa592dfa527ed6e7a79d07dcaad8018f
push id34372
push usernerli@mozilla.com
push dateThu, 02 Aug 2018 08:55:28 +0000
treeherdermozilla-central@bd79b07f57a3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerswhimboo
bugs1470659
milestone63.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1470659 - Simplify Marionette capability parsing. r=whimboo Change the switch-statement to only do assertions, and replace the v variable with any parsed values before writing it to the matched set of capabilities in one location.
testing/marionette/capabilities.js
--- a/testing/marionette/capabilities.js
+++ b/testing/marionette/capabilities.js
@@ -460,67 +460,55 @@ class Capabilities extends Map {
   // Matches capabilities as described by WebDriver.
   static match_(json = {}) {
     let matched = new Capabilities();
 
     for (let [k, v] of Object.entries(json)) {
       switch (k) {
         case "acceptInsecureCerts":
           assert.boolean(v, pprint`Expected ${k} to be a boolean, got ${v}`);
-          matched.set("acceptInsecureCerts", v);
           break;
 
         case "pageLoadStrategy":
           assert.string(v, pprint`Expected ${k} to be a string, got ${v}`);
-
-          if (Object.values(PageLoadStrategy).includes(v)) {
-            matched.set("pageLoadStrategy", v);
-          } else {
+          if (!Object.values(PageLoadStrategy).includes(v)) {
             throw new InvalidArgumentError("Unknown page load strategy: " + v);
           }
-
           break;
 
         case "proxy":
-          let proxy = Proxy.fromJSON(v);
-          matched.set("proxy", proxy);
+          v = Proxy.fromJSON(v);
           break;
 
         case "timeouts":
-          let timeouts = Timeouts.fromJSON(v);
-          matched.set("timeouts", timeouts);
+          v = Timeouts.fromJSON(v);
           break;
 
         case "unhandledPromptBehavior":
           assert.string(v, pprint`Expected ${k} to be a string, got ${v}`);
-
-          if (Object.values(UnhandledPromptBehavior).includes(v)) {
-            matched.set("unhandledPromptBehavior", v);
-          } else {
+          if (!Object.values(UnhandledPromptBehavior).includes(v)) {
             throw new InvalidArgumentError(
                 `Unknown unhandled prompt behavior: ${v}`);
           }
-
           break;
 
         case "moz:accessibilityChecks":
-          assert.boolean(v, pprint`Expected ${k} to be a boolean, got ${v}`);
-          matched.set("moz:accessibilityChecks", v);
+          assert.boolean(v, pprint`Expected ${k} to be boolean, got ${v}`);
           break;
 
         case "moz:useNonSpecCompliantPointerOrigin":
-          assert.boolean(v, pprint`Expected ${k} to be a boolean, got ${v}`);
-          matched.set("moz:useNonSpecCompliantPointerOrigin", v);
+          assert.boolean(v, pprint`Expected ${k} to be boolean, got ${v}`);
           break;
 
         case "moz:webdriverClick":
-          assert.boolean(v, pprint`Expected ${k} to be a boolean, got ${v}`);
-          matched.set("moz:webdriverClick", v);
+          assert.boolean(v, pprint`Expected ${k} to be boolean, got ${v}`);
           break;
       }
+
+      matched.set(k, v);
     }
 
     return matched;
   }
 }
 
 this.Capabilities = Capabilities;
 this.PageLoadStrategy = PageLoadStrategy;