Bug 937659 - Fix deserializing of page load strategy.
The patch aligns the steps for deserializing the page load strategy with
the webdriver specification.
MozReview-Commit-ID: GnVTnhVQVkG
--- 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":