Bug 1478979 - Disallow pageLoadStrategy to be null. r=whimboo

Capabilities matching is now done in geckodriver and Marionette
receives the negotiated set of capabilities, so there is no need
to derive default values in case the value is null.
This commit is contained in:
Andreas Tolfsen 2018-07-27 14:17:59 +01:00
Родитель 339c5c47b4
Коммит 0cedb9ad97
3 изменённых файлов: 12 добавлений и 27 удалений

Просмотреть файл

@ -464,24 +464,17 @@ class Capabilities extends Map {
for (let [k, v] of Object.entries(json)) { for (let [k, v] of Object.entries(json)) {
switch (k) { switch (k) {
case "acceptInsecureCerts": case "acceptInsecureCerts":
assert.boolean(v, assert.boolean(v, pprint`Expected ${k} to be a boolean, got ${v}`);
pprint`Expected ${k} to be a boolean, got ${v}`);
matched.set("acceptInsecureCerts", v); matched.set("acceptInsecureCerts", v);
break; break;
case "pageLoadStrategy": case "pageLoadStrategy":
if (v === null) { assert.string(v, pprint`Expected ${k} to be a string, got ${v}`);
matched.set("pageLoadStrategy", PageLoadStrategy.Normal);
} else {
assert.string(v,
pprint`Expected ${k} to be a string, got ${v}`);
if (Object.values(PageLoadStrategy).includes(v)) { if (Object.values(PageLoadStrategy).includes(v)) {
matched.set("pageLoadStrategy", v); matched.set("pageLoadStrategy", v);
} else { } else {
throw new InvalidArgumentError( throw new InvalidArgumentError("Unknown page load strategy: " + v);
"Unknown page load strategy: " + v);
}
} }
break; break;
@ -497,8 +490,7 @@ class Capabilities extends Map {
break; break;
case "unhandledPromptBehavior": case "unhandledPromptBehavior":
assert.string(v, assert.string(v, pprint`Expected ${k} to be a string, got ${v}`);
pprint`Expected ${k} to be a string, got ${v}`);
if (Object.values(UnhandledPromptBehavior).includes(v)) { if (Object.values(UnhandledPromptBehavior).includes(v)) {
matched.set("unhandledPromptBehavior", v); matched.set("unhandledPromptBehavior", v);
@ -510,20 +502,17 @@ class Capabilities extends Map {
break; break;
case "moz:accessibilityChecks": case "moz:accessibilityChecks":
assert.boolean(v, assert.boolean(v, pprint`Expected ${k} to be a boolean, got ${v}`);
pprint`Expected ${k} to be a boolean, got ${v}`);
matched.set("moz:accessibilityChecks", v); matched.set("moz:accessibilityChecks", v);
break; break;
case "moz:useNonSpecCompliantPointerOrigin": case "moz:useNonSpecCompliantPointerOrigin":
assert.boolean(v, assert.boolean(v, pprint`Expected ${k} to be a boolean, got ${v}`);
pprint`Expected ${k} to be a boolean, got ${v}`);
matched.set("moz:useNonSpecCompliantPointerOrigin", v); matched.set("moz:useNonSpecCompliantPointerOrigin", v);
break; break;
case "moz:webdriverClick": case "moz:webdriverClick":
assert.boolean(v, assert.boolean(v, pprint`Expected ${k} to be a boolean, got ${v}`);
pprint`Expected ${k} to be a boolean, got ${v}`);
matched.set("moz:webdriverClick", v); matched.set("moz:webdriverClick", v);
break; break;
} }

Просмотреть файл

@ -143,12 +143,7 @@ class TestCapabilityMatching(MarionetteTestCase):
self.marionette.start_session({"pageLoadStrategy": strategy}) self.marionette.start_session({"pageLoadStrategy": strategy})
self.assertEqual(self.marionette.session_capabilities["pageLoadStrategy"], strategy) self.assertEqual(self.marionette.session_capabilities["pageLoadStrategy"], strategy)
# A null value should be treatend as "normal" for value in ["", "EAGER", True, 42, {}, [], None]:
self.delete_session()
self.marionette.start_session({"pageLoadStrategy": None})
self.assertEqual(self.marionette.session_capabilities["pageLoadStrategy"], "normal")
for value in ["", "EAGER", True, 42, {}, []]:
print("invalid strategy {}".format(value)) print("invalid strategy {}".format(value))
with self.assertRaisesRegexp(SessionNotCreatedException, "InvalidArgumentError"): with self.assertRaisesRegexp(SessionNotCreatedException, "InvalidArgumentError"):
self.marionette.start_session({"pageLoadStrategy": value}) self.marionette.start_session({"pageLoadStrategy": value})

Просмотреть файл

@ -456,6 +456,7 @@ add_test(function test_Capabilities_fromJSON() {
equal(strategy, caps.get("pageLoadStrategy")); equal(strategy, caps.get("pageLoadStrategy"));
} }
Assert.throws(() => fromJSON({pageLoadStrategy: "foo"}), InvalidArgumentError); Assert.throws(() => fromJSON({pageLoadStrategy: "foo"}), InvalidArgumentError);
Assert.throws(() => fromJSON({pageLoadStrategy: null}), InvalidArgumentError);
let proxyConfig = {proxyType: "manual"}; let proxyConfig = {proxyType: "manual"};
caps = fromJSON({proxy: proxyConfig}); caps = fromJSON({proxy: proxyConfig});