Bug 937659 - Fix deserializing of page load strategy. r=ato a=test-only
authorHenrik Skupin <mail@hskupin.info>
Wed, 19 Apr 2017 12:32:20 +0200
changeset 585359 c7475dd59d76fdccc5b3de45900d37387b6d0bbc
parent 585358 b479558ee0437038dcf55adcb982412268a95ab2
child 585360 780defc84a8934a5d7bc9d125695c6e11976bab4
push id61106
push userbmo:dkeeler@mozilla.com
push dateFri, 26 May 2017 21:26:31 +0000
reviewersato, test-only
bugs937659
milestone54.0
Bug 937659 - Fix deserializing of page load strategy. r=ato a=test-only The patch aligns the steps for deserializing the page load strategy with the webdriver specification. MozReview-Commit-ID: GnVTnhVQVkG
testing/marionette/harness/marionette_harness/tests/unit/test_capabilities.py
testing/marionette/session.js
--- a/testing/marionette/harness/marionette_harness/tests/unit/test_capabilities.py
+++ b/testing/marionette/harness/marionette_harness/tests/unit/test_capabilities.py
@@ -218,19 +218,24 @@ class TestCapabilityMatching(MarionetteT
 
     def test_page_load_strategy(self):
         for strategy in ["none", "eager", "normal"]:
             print("valid strategy {}".format(strategy))
             self.delete_session()
             self.marionette.start_session({"desiredCapabilities": {"pageLoadStrategy": strategy}})
             self.assertEqual(self.marionette.session_capabilities["pageLoadStrategy"], strategy)
 
+        # A null value should be treatend as "normal"
+        self.delete_session()
+        self.marionette.start_session({"desiredCapabilities": {"pageLoadStrategy": None}})
+        self.assertEqual(self.marionette.session_capabilities["pageLoadStrategy"], "normal")
+
         for value in ["", "EAGER", True, 42, {}, []]:
             print("invalid strategy {}".format(value))
-            with self.assertRaises(SessionNotCreatedException):
+            with self.assertRaisesRegexp(SessionNotCreatedException, "InvalidArgumentError"):
                 self.marionette.start_session({"desiredCapabilities": {"pageLoadStrategy": value}})
 
     def test_proxy_default(self):
         self.marionette.start_session()
         self.assertNotIn("proxy", self.marionette.session_capabilities)
 
     def test_proxy_desired(self):
         self.marionette.start_session({"desiredCapabilities": {"proxy": {"proxyType": "manual"}}})
--- a/testing/marionette/session.js
+++ b/testing/marionette/session.js
@@ -240,17 +240,17 @@ session.Capabilities = class extends Map
 
   set (key, value) {
     if (key === "timeouts" && !(value instanceof session.Timeouts)) {
       throw new TypeError();
     } else if (key === "proxy" && !(value instanceof session.Proxy)) {
       throw new TypeError();
     }
 
-    return super.set(key, value);  
+    return super.set(key, value);
   }
 
   toString() { return "[object session.Capabilities]"; }
 
   toJSON() {
     return marshal(this);
   }
 
@@ -352,21 +352,28 @@ session.Capabilities = class extends Map
           break;
 
         case "acceptInsecureCerts":
           assert.boolean(v);
           matched.set("acceptInsecureCerts", v);
           break;
 
         case "pageLoadStrategy":
-          if (Object.values(session.PageLoadStrategy).includes(v)) {
-            matched.set("pageLoadStrategy", v);
+          if (v === null) {
+            matched.set("pageLoadStrategy", session.PageLoadStrategy.Normal);
           } else {
-            throw new TypeError("Unknown page load strategy: " + v);
+            assert.string(v);
+
+            if (Object.values(session.PageLoadStrategy).includes(v)) {
+              matched.set("pageLoadStrategy", v);
+            } else {
+              throw new InvalidArgumentError("Unknown page load strategy: " + v);
+            }
           }
+
           break;
 
         case "proxy":
           let proxy = session.Proxy.fromJSON(v);
           matched.set("proxy", proxy);
           break;
 
         case "timeouts":