gecko-dev/testing/marionette/test_session.js

437 строки
12 KiB
JavaScript
Исходник Обычный вид История

Bug 1326534 - Rewrite capabilities parsing in Marionette; r=automatedtester This patch provides a (nearly) WebDriver conforming implementation of capabilities in Marionette. The work remaining is pending further clarification in the specification. Capabilities are represented internally as a complex object provided by `session.Capabilities`. Timeouts and proxy configuration are also represented by the similar complex objects `session.Timeouts` and `session.Proxy`, respectively. The capabilities stored in `GeckoDriver#sessionCapabilities` are the result of parsing user-provided desired- and required capabilities. WebDriver now uses `firstMatch` and `alwaysMatch` primitives for capabilities, but as this is considered a wider breaking change, the move to these primitives will be done at a later stage. It’s prudent to point out that the base techniques used with the new primitives are similar to those implemented for `desiredCapabilities` and `requiredCapabilities` in this patch, and that the work needed to adapt them is considered trivial. When capabilities are presented back to the user (the so called processed capabilities), we call the `toJSON` implementation on the complex objects. `session.Capabilities#toJSON` calls the internal function `marshal` which ensures empty fields are dropped. `marshal` can be considered to be a specialisation of the standard library `JSON.stringify`, which also calls `toJSON` on entry values if they provide this function. The changeset overall also provides a much deeper level of testing of WebDriver capabilities. MozReview-Commit-ID: 97xGt3cnMys --HG-- extra : rebase_source : 98e0bde3fdfd811775d195b488cb1255f61e5772
2016-12-31 15:21:34 +03:00
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
const {utils: Cu} = Components;
Cu.import("resource://gre/modules/Preferences.jsm");
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("chrome://marionette/content/error.js");
Cu.import("chrome://marionette/content/session.js");
add_test(function test_Timeouts_ctor() {
let ts = new session.Timeouts();
equal(ts.implicit, 0);
equal(ts.pageLoad, 300000);
equal(ts.script, 30000);
run_next_test();
});
add_test(function test_Timeouts_toString() {
equal(new session.Timeouts().toString(), "[object session.Timeouts]");
run_next_test();
});
add_test(function test_Timeouts_toJSON() {
let ts = new session.Timeouts();
deepEqual(ts.toJSON(), {"implicit": 0, "pageLoad": 300000, "script": 30000});
Bug 1326534 - Rewrite capabilities parsing in Marionette; r=automatedtester This patch provides a (nearly) WebDriver conforming implementation of capabilities in Marionette. The work remaining is pending further clarification in the specification. Capabilities are represented internally as a complex object provided by `session.Capabilities`. Timeouts and proxy configuration are also represented by the similar complex objects `session.Timeouts` and `session.Proxy`, respectively. The capabilities stored in `GeckoDriver#sessionCapabilities` are the result of parsing user-provided desired- and required capabilities. WebDriver now uses `firstMatch` and `alwaysMatch` primitives for capabilities, but as this is considered a wider breaking change, the move to these primitives will be done at a later stage. It’s prudent to point out that the base techniques used with the new primitives are similar to those implemented for `desiredCapabilities` and `requiredCapabilities` in this patch, and that the work needed to adapt them is considered trivial. When capabilities are presented back to the user (the so called processed capabilities), we call the `toJSON` implementation on the complex objects. `session.Capabilities#toJSON` calls the internal function `marshal` which ensures empty fields are dropped. `marshal` can be considered to be a specialisation of the standard library `JSON.stringify`, which also calls `toJSON` on entry values if they provide this function. The changeset overall also provides a much deeper level of testing of WebDriver capabilities. MozReview-Commit-ID: 97xGt3cnMys --HG-- extra : rebase_source : 98e0bde3fdfd811775d195b488cb1255f61e5772
2016-12-31 15:21:34 +03:00
run_next_test();
});
add_test(function test_Timeouts_fromJSON() {
let json = {
implicit: 10,
pageLoad: 20,
script: 30,
Bug 1326534 - Rewrite capabilities parsing in Marionette; r=automatedtester This patch provides a (nearly) WebDriver conforming implementation of capabilities in Marionette. The work remaining is pending further clarification in the specification. Capabilities are represented internally as a complex object provided by `session.Capabilities`. Timeouts and proxy configuration are also represented by the similar complex objects `session.Timeouts` and `session.Proxy`, respectively. The capabilities stored in `GeckoDriver#sessionCapabilities` are the result of parsing user-provided desired- and required capabilities. WebDriver now uses `firstMatch` and `alwaysMatch` primitives for capabilities, but as this is considered a wider breaking change, the move to these primitives will be done at a later stage. It’s prudent to point out that the base techniques used with the new primitives are similar to those implemented for `desiredCapabilities` and `requiredCapabilities` in this patch, and that the work needed to adapt them is considered trivial. When capabilities are presented back to the user (the so called processed capabilities), we call the `toJSON` implementation on the complex objects. `session.Capabilities#toJSON` calls the internal function `marshal` which ensures empty fields are dropped. `marshal` can be considered to be a specialisation of the standard library `JSON.stringify`, which also calls `toJSON` on entry values if they provide this function. The changeset overall also provides a much deeper level of testing of WebDriver capabilities. MozReview-Commit-ID: 97xGt3cnMys --HG-- extra : rebase_source : 98e0bde3fdfd811775d195b488cb1255f61e5772
2016-12-31 15:21:34 +03:00
};
let ts = session.Timeouts.fromJSON(json);
equal(ts.implicit, json.implicit);
equal(ts.pageLoad, json.pageLoad);
equal(ts.script, json.script);
Bug 1326534 - Rewrite capabilities parsing in Marionette; r=automatedtester This patch provides a (nearly) WebDriver conforming implementation of capabilities in Marionette. The work remaining is pending further clarification in the specification. Capabilities are represented internally as a complex object provided by `session.Capabilities`. Timeouts and proxy configuration are also represented by the similar complex objects `session.Timeouts` and `session.Proxy`, respectively. The capabilities stored in `GeckoDriver#sessionCapabilities` are the result of parsing user-provided desired- and required capabilities. WebDriver now uses `firstMatch` and `alwaysMatch` primitives for capabilities, but as this is considered a wider breaking change, the move to these primitives will be done at a later stage. It’s prudent to point out that the base techniques used with the new primitives are similar to those implemented for `desiredCapabilities` and `requiredCapabilities` in this patch, and that the work needed to adapt them is considered trivial. When capabilities are presented back to the user (the so called processed capabilities), we call the `toJSON` implementation on the complex objects. `session.Capabilities#toJSON` calls the internal function `marshal` which ensures empty fields are dropped. `marshal` can be considered to be a specialisation of the standard library `JSON.stringify`, which also calls `toJSON` on entry values if they provide this function. The changeset overall also provides a much deeper level of testing of WebDriver capabilities. MozReview-Commit-ID: 97xGt3cnMys --HG-- extra : rebase_source : 98e0bde3fdfd811775d195b488cb1255f61e5772
2016-12-31 15:21:34 +03:00
run_next_test();
});
add_test(function test_Timeouts_fromJSON_unrecognised_field() {
let json = {
sessionId: "foobar",
script: 42,
};
try {
session.Timeouts.fromJSON(json);
} catch (e) {
equal(e.name, InvalidArgumentError.name);
equal(e.message, "Unrecognised timeout: sessionId");
}
run_next_test();
});
add_test(function test_Timeouts_fromJSON_invalid_type() {
try {
session.Timeouts.fromJSON({script: "foobar"});
} catch (e) {
equal(e.name, InvalidArgumentError.name);
equal(e.message, "Expected [object String] \"foobar\" to be an integer");
}
run_next_test();
});
add_test(function test_Timeouts_fromJSON_bounds() {
try {
session.Timeouts.fromJSON({script: -42});
} catch (e) {
equal(e.name, InvalidArgumentError.name);
equal(e.message, "Expected [object Number] -42 to be >= 0");
}
run_next_test();
});
Bug 1326534 - Rewrite capabilities parsing in Marionette; r=automatedtester This patch provides a (nearly) WebDriver conforming implementation of capabilities in Marionette. The work remaining is pending further clarification in the specification. Capabilities are represented internally as a complex object provided by `session.Capabilities`. Timeouts and proxy configuration are also represented by the similar complex objects `session.Timeouts` and `session.Proxy`, respectively. The capabilities stored in `GeckoDriver#sessionCapabilities` are the result of parsing user-provided desired- and required capabilities. WebDriver now uses `firstMatch` and `alwaysMatch` primitives for capabilities, but as this is considered a wider breaking change, the move to these primitives will be done at a later stage. It’s prudent to point out that the base techniques used with the new primitives are similar to those implemented for `desiredCapabilities` and `requiredCapabilities` in this patch, and that the work needed to adapt them is considered trivial. When capabilities are presented back to the user (the so called processed capabilities), we call the `toJSON` implementation on the complex objects. `session.Capabilities#toJSON` calls the internal function `marshal` which ensures empty fields are dropped. `marshal` can be considered to be a specialisation of the standard library `JSON.stringify`, which also calls `toJSON` on entry values if they provide this function. The changeset overall also provides a much deeper level of testing of WebDriver capabilities. MozReview-Commit-ID: 97xGt3cnMys --HG-- extra : rebase_source : 98e0bde3fdfd811775d195b488cb1255f61e5772
2016-12-31 15:21:34 +03:00
add_test(function test_PageLoadStrategy() {
equal(session.PageLoadStrategy.None, "none");
equal(session.PageLoadStrategy.Eager, "eager");
equal(session.PageLoadStrategy.Normal, "normal");
run_next_test();
});
add_test(function test_Proxy_ctor() {
let p = new session.Proxy();
let props = [
"proxyType",
"httpProxy",
"sslProxy",
"ftpProxy",
"socksProxy",
"socksVersion",
"proxyAutoconfigUrl",
];
for (let prop of props) {
ok(prop in p, `${prop} in ${JSON.stringify(props)}`);
equal(p[prop], null);
}
run_next_test();
});
add_test(function test_Proxy_init() {
let p = new session.Proxy();
// no changed made, and 5 (system) is default
equal(p.init(), false);
equal(Preferences.get("network.proxy.type"), 5);
// pac
p.proxyType = "pac";
p.proxyAutoconfigUrl = "http://localhost:1234";
ok(p.init());
equal(Preferences.get("network.proxy.type"), 2);
equal(Preferences.get("network.proxy.autoconfig_url"),
"http://localhost:1234");
// direct
p = new session.Proxy();
p.proxyType = "direct";
ok(p.init());
equal(Preferences.get("network.proxy.type"), 0);
Bug 1326534 - Rewrite capabilities parsing in Marionette; r=automatedtester This patch provides a (nearly) WebDriver conforming implementation of capabilities in Marionette. The work remaining is pending further clarification in the specification. Capabilities are represented internally as a complex object provided by `session.Capabilities`. Timeouts and proxy configuration are also represented by the similar complex objects `session.Timeouts` and `session.Proxy`, respectively. The capabilities stored in `GeckoDriver#sessionCapabilities` are the result of parsing user-provided desired- and required capabilities. WebDriver now uses `firstMatch` and `alwaysMatch` primitives for capabilities, but as this is considered a wider breaking change, the move to these primitives will be done at a later stage. It’s prudent to point out that the base techniques used with the new primitives are similar to those implemented for `desiredCapabilities` and `requiredCapabilities` in this patch, and that the work needed to adapt them is considered trivial. When capabilities are presented back to the user (the so called processed capabilities), we call the `toJSON` implementation on the complex objects. `session.Capabilities#toJSON` calls the internal function `marshal` which ensures empty fields are dropped. `marshal` can be considered to be a specialisation of the standard library `JSON.stringify`, which also calls `toJSON` on entry values if they provide this function. The changeset overall also provides a much deeper level of testing of WebDriver capabilities. MozReview-Commit-ID: 97xGt3cnMys --HG-- extra : rebase_source : 98e0bde3fdfd811775d195b488cb1255f61e5772
2016-12-31 15:21:34 +03:00
// autodetect
p = new session.Proxy();
p.proxyType = "autodetect";
ok(p.init());
equal(Preferences.get("network.proxy.type"), 4);
// system
p = new session.Proxy();
p.proxyType = "system";
ok(p.init());
equal(Preferences.get("network.proxy.type"), 5);
// manual
for (let proxy of ["ftp", "http", "ssl", "socks"]) {
p = new session.Proxy();
p.proxyType = "manual";
p.noProxy = ["foo", "bar"];
p[`${proxy}Proxy`] = "foo";
p[`${proxy}ProxyPort`] = 42;
if (proxy === "socks") {
p[`${proxy}Version`] = 4;
}
ok(p.init());
equal(Preferences.get("network.proxy.type"), 1);
equal(Preferences.get("network.proxy.no_proxies_on"), "foo, bar");
equal(Preferences.get(`network.proxy.${proxy}`), "foo");
equal(Preferences.get(`network.proxy.${proxy}_port`), 42);
if (proxy === "socks") {
equal(Preferences.get(`network.proxy.${proxy}_version`), 4);
}
}
Bug 1326534 - Rewrite capabilities parsing in Marionette; r=automatedtester This patch provides a (nearly) WebDriver conforming implementation of capabilities in Marionette. The work remaining is pending further clarification in the specification. Capabilities are represented internally as a complex object provided by `session.Capabilities`. Timeouts and proxy configuration are also represented by the similar complex objects `session.Timeouts` and `session.Proxy`, respectively. The capabilities stored in `GeckoDriver#sessionCapabilities` are the result of parsing user-provided desired- and required capabilities. WebDriver now uses `firstMatch` and `alwaysMatch` primitives for capabilities, but as this is considered a wider breaking change, the move to these primitives will be done at a later stage. It’s prudent to point out that the base techniques used with the new primitives are similar to those implemented for `desiredCapabilities` and `requiredCapabilities` in this patch, and that the work needed to adapt them is considered trivial. When capabilities are presented back to the user (the so called processed capabilities), we call the `toJSON` implementation on the complex objects. `session.Capabilities#toJSON` calls the internal function `marshal` which ensures empty fields are dropped. `marshal` can be considered to be a specialisation of the standard library `JSON.stringify`, which also calls `toJSON` on entry values if they provide this function. The changeset overall also provides a much deeper level of testing of WebDriver capabilities. MozReview-Commit-ID: 97xGt3cnMys --HG-- extra : rebase_source : 98e0bde3fdfd811775d195b488cb1255f61e5772
2016-12-31 15:21:34 +03:00
// empty no proxy should reset default exclustions
p = new session.Proxy();
p.proxyType = "manual";
p.noProxy = [];
ok(p.init());
equal(Preferences.get("network.proxy.no_proxies_on"), "");
Bug 1326534 - Rewrite capabilities parsing in Marionette; r=automatedtester This patch provides a (nearly) WebDriver conforming implementation of capabilities in Marionette. The work remaining is pending further clarification in the specification. Capabilities are represented internally as a complex object provided by `session.Capabilities`. Timeouts and proxy configuration are also represented by the similar complex objects `session.Timeouts` and `session.Proxy`, respectively. The capabilities stored in `GeckoDriver#sessionCapabilities` are the result of parsing user-provided desired- and required capabilities. WebDriver now uses `firstMatch` and `alwaysMatch` primitives for capabilities, but as this is considered a wider breaking change, the move to these primitives will be done at a later stage. It’s prudent to point out that the base techniques used with the new primitives are similar to those implemented for `desiredCapabilities` and `requiredCapabilities` in this patch, and that the work needed to adapt them is considered trivial. When capabilities are presented back to the user (the so called processed capabilities), we call the `toJSON` implementation on the complex objects. `session.Capabilities#toJSON` calls the internal function `marshal` which ensures empty fields are dropped. `marshal` can be considered to be a specialisation of the standard library `JSON.stringify`, which also calls `toJSON` on entry values if they provide this function. The changeset overall also provides a much deeper level of testing of WebDriver capabilities. MozReview-Commit-ID: 97xGt3cnMys --HG-- extra : rebase_source : 98e0bde3fdfd811775d195b488cb1255f61e5772
2016-12-31 15:21:34 +03:00
run_next_test();
});
add_test(function test_Proxy_toString() {
equal(new session.Proxy().toString(), "[object session.Proxy]");
run_next_test();
});
add_test(function test_Proxy_toJSON() {
let p = new session.Proxy();
deepEqual(p.toJSON(), {});
// manual
Bug 1326534 - Rewrite capabilities parsing in Marionette; r=automatedtester This patch provides a (nearly) WebDriver conforming implementation of capabilities in Marionette. The work remaining is pending further clarification in the specification. Capabilities are represented internally as a complex object provided by `session.Capabilities`. Timeouts and proxy configuration are also represented by the similar complex objects `session.Timeouts` and `session.Proxy`, respectively. The capabilities stored in `GeckoDriver#sessionCapabilities` are the result of parsing user-provided desired- and required capabilities. WebDriver now uses `firstMatch` and `alwaysMatch` primitives for capabilities, but as this is considered a wider breaking change, the move to these primitives will be done at a later stage. It’s prudent to point out that the base techniques used with the new primitives are similar to those implemented for `desiredCapabilities` and `requiredCapabilities` in this patch, and that the work needed to adapt them is considered trivial. When capabilities are presented back to the user (the so called processed capabilities), we call the `toJSON` implementation on the complex objects. `session.Capabilities#toJSON` calls the internal function `marshal` which ensures empty fields are dropped. `marshal` can be considered to be a specialisation of the standard library `JSON.stringify`, which also calls `toJSON` on entry values if they provide this function. The changeset overall also provides a much deeper level of testing of WebDriver capabilities. MozReview-Commit-ID: 97xGt3cnMys --HG-- extra : rebase_source : 98e0bde3fdfd811775d195b488cb1255f61e5772
2016-12-31 15:21:34 +03:00
p = new session.Proxy();
p.proxyType = "manual";
deepEqual(p.toJSON(), {proxyType: "manual"});
for (let proxy of ["ftpProxy", "httpProxy", "sslProxy", "socksProxy"]) {
let expected = {proxyType: "manual"}
let manual = new session.Proxy();
manual.proxyType = "manual";
if (proxy == "socksProxy") {
manual.socksVersion = 5;
expected.socksVersion = 5;
}
// without port
manual[proxy] = "foo";
expected[proxy] = "foo"
deepEqual(manual.toJSON(), expected);
// with port
manual[proxy] = "foo";
manual[`${proxy}Port`] = 0;
expected[proxy] = "foo:0";
deepEqual(manual.toJSON(), expected);
manual[`${proxy}Port`] = 42;
expected[proxy] = "foo:42"
deepEqual(manual.toJSON(), expected);
}
Bug 1326534 - Rewrite capabilities parsing in Marionette; r=automatedtester This patch provides a (nearly) WebDriver conforming implementation of capabilities in Marionette. The work remaining is pending further clarification in the specification. Capabilities are represented internally as a complex object provided by `session.Capabilities`. Timeouts and proxy configuration are also represented by the similar complex objects `session.Timeouts` and `session.Proxy`, respectively. The capabilities stored in `GeckoDriver#sessionCapabilities` are the result of parsing user-provided desired- and required capabilities. WebDriver now uses `firstMatch` and `alwaysMatch` primitives for capabilities, but as this is considered a wider breaking change, the move to these primitives will be done at a later stage. It’s prudent to point out that the base techniques used with the new primitives are similar to those implemented for `desiredCapabilities` and `requiredCapabilities` in this patch, and that the work needed to adapt them is considered trivial. When capabilities are presented back to the user (the so called processed capabilities), we call the `toJSON` implementation on the complex objects. `session.Capabilities#toJSON` calls the internal function `marshal` which ensures empty fields are dropped. `marshal` can be considered to be a specialisation of the standard library `JSON.stringify`, which also calls `toJSON` on entry values if they provide this function. The changeset overall also provides a much deeper level of testing of WebDriver capabilities. MozReview-Commit-ID: 97xGt3cnMys --HG-- extra : rebase_source : 98e0bde3fdfd811775d195b488cb1255f61e5772
2016-12-31 15:21:34 +03:00
run_next_test();
});
add_test(function test_Proxy_fromJSON() {
deepEqual({}, session.Proxy.fromJSON(undefined).toJSON());
deepEqual({}, session.Proxy.fromJSON(null).toJSON());
for (let typ of [true, 42, "foo", []]) {
Assert.throws(() => session.Proxy.fromJSON(typ), InvalidArgumentError);
}
// must contain a valid proxyType
Bug 1326534 - Rewrite capabilities parsing in Marionette; r=automatedtester This patch provides a (nearly) WebDriver conforming implementation of capabilities in Marionette. The work remaining is pending further clarification in the specification. Capabilities are represented internally as a complex object provided by `session.Capabilities`. Timeouts and proxy configuration are also represented by the similar complex objects `session.Timeouts` and `session.Proxy`, respectively. The capabilities stored in `GeckoDriver#sessionCapabilities` are the result of parsing user-provided desired- and required capabilities. WebDriver now uses `firstMatch` and `alwaysMatch` primitives for capabilities, but as this is considered a wider breaking change, the move to these primitives will be done at a later stage. It’s prudent to point out that the base techniques used with the new primitives are similar to those implemented for `desiredCapabilities` and `requiredCapabilities` in this patch, and that the work needed to adapt them is considered trivial. When capabilities are presented back to the user (the so called processed capabilities), we call the `toJSON` implementation on the complex objects. `session.Capabilities#toJSON` calls the internal function `marshal` which ensures empty fields are dropped. `marshal` can be considered to be a specialisation of the standard library `JSON.stringify`, which also calls `toJSON` on entry values if they provide this function. The changeset overall also provides a much deeper level of testing of WebDriver capabilities. MozReview-Commit-ID: 97xGt3cnMys --HG-- extra : rebase_source : 98e0bde3fdfd811775d195b488cb1255f61e5772
2016-12-31 15:21:34 +03:00
Assert.throws(() => session.Proxy.fromJSON({}), InvalidArgumentError);
Assert.throws(() => session.Proxy.fromJSON({proxyType: "foo"}),
InvalidArgumentError);
Bug 1326534 - Rewrite capabilities parsing in Marionette; r=automatedtester This patch provides a (nearly) WebDriver conforming implementation of capabilities in Marionette. The work remaining is pending further clarification in the specification. Capabilities are represented internally as a complex object provided by `session.Capabilities`. Timeouts and proxy configuration are also represented by the similar complex objects `session.Timeouts` and `session.Proxy`, respectively. The capabilities stored in `GeckoDriver#sessionCapabilities` are the result of parsing user-provided desired- and required capabilities. WebDriver now uses `firstMatch` and `alwaysMatch` primitives for capabilities, but as this is considered a wider breaking change, the move to these primitives will be done at a later stage. It’s prudent to point out that the base techniques used with the new primitives are similar to those implemented for `desiredCapabilities` and `requiredCapabilities` in this patch, and that the work needed to adapt them is considered trivial. When capabilities are presented back to the user (the so called processed capabilities), we call the `toJSON` implementation on the complex objects. `session.Capabilities#toJSON` calls the internal function `marshal` which ensures empty fields are dropped. `marshal` can be considered to be a specialisation of the standard library `JSON.stringify`, which also calls `toJSON` on entry values if they provide this function. The changeset overall also provides a much deeper level of testing of WebDriver capabilities. MozReview-Commit-ID: 97xGt3cnMys --HG-- extra : rebase_source : 98e0bde3fdfd811775d195b488cb1255f61e5772
2016-12-31 15:21:34 +03:00
// manual
session.Proxy.fromJSON({proxyType: "manual"});
for (let proxy of ["httpProxy", "sslProxy", "ftpProxy", "socksProxy"]) {
let manual = {proxyType: "manual"};
// invalid hosts
for (let host of [true, 42, [], {}, null, "http://foo",
"foo:-1", "foo:65536", "foo/test", "foo#42", "foo?foo=bar",
"2001:db8::1"]) {
manual[proxy] = host;
Bug 1326534 - Rewrite capabilities parsing in Marionette; r=automatedtester This patch provides a (nearly) WebDriver conforming implementation of capabilities in Marionette. The work remaining is pending further clarification in the specification. Capabilities are represented internally as a complex object provided by `session.Capabilities`. Timeouts and proxy configuration are also represented by the similar complex objects `session.Timeouts` and `session.Proxy`, respectively. The capabilities stored in `GeckoDriver#sessionCapabilities` are the result of parsing user-provided desired- and required capabilities. WebDriver now uses `firstMatch` and `alwaysMatch` primitives for capabilities, but as this is considered a wider breaking change, the move to these primitives will be done at a later stage. It’s prudent to point out that the base techniques used with the new primitives are similar to those implemented for `desiredCapabilities` and `requiredCapabilities` in this patch, and that the work needed to adapt them is considered trivial. When capabilities are presented back to the user (the so called processed capabilities), we call the `toJSON` implementation on the complex objects. `session.Capabilities#toJSON` calls the internal function `marshal` which ensures empty fields are dropped. `marshal` can be considered to be a specialisation of the standard library `JSON.stringify`, which also calls `toJSON` on entry values if they provide this function. The changeset overall also provides a much deeper level of testing of WebDriver capabilities. MozReview-Commit-ID: 97xGt3cnMys --HG-- extra : rebase_source : 98e0bde3fdfd811775d195b488cb1255f61e5772
2016-12-31 15:21:34 +03:00
Assert.throws(() => session.Proxy.fromJSON(manual),
InvalidArgumentError);
}
let expected = {"proxyType": "manual"};
if (proxy == "socksProxy") {
manual.socksVersion = 5;
expected.socksVersion = 5;
}
Bug 1326534 - Rewrite capabilities parsing in Marionette; r=automatedtester This patch provides a (nearly) WebDriver conforming implementation of capabilities in Marionette. The work remaining is pending further clarification in the specification. Capabilities are represented internally as a complex object provided by `session.Capabilities`. Timeouts and proxy configuration are also represented by the similar complex objects `session.Timeouts` and `session.Proxy`, respectively. The capabilities stored in `GeckoDriver#sessionCapabilities` are the result of parsing user-provided desired- and required capabilities. WebDriver now uses `firstMatch` and `alwaysMatch` primitives for capabilities, but as this is considered a wider breaking change, the move to these primitives will be done at a later stage. It’s prudent to point out that the base techniques used with the new primitives are similar to those implemented for `desiredCapabilities` and `requiredCapabilities` in this patch, and that the work needed to adapt them is considered trivial. When capabilities are presented back to the user (the so called processed capabilities), we call the `toJSON` implementation on the complex objects. `session.Capabilities#toJSON` calls the internal function `marshal` which ensures empty fields are dropped. `marshal` can be considered to be a specialisation of the standard library `JSON.stringify`, which also calls `toJSON` on entry values if they provide this function. The changeset overall also provides a much deeper level of testing of WebDriver capabilities. MozReview-Commit-ID: 97xGt3cnMys --HG-- extra : rebase_source : 98e0bde3fdfd811775d195b488cb1255f61e5772
2016-12-31 15:21:34 +03:00
// valid proxy hosts with port
for (let host of ["foo:1", "foo:80", "foo:443", "foo:65535",
"127.0.0.1:42", "[2001:db8::1]:42"]) {
manual[proxy] = host;
expected[proxy] = host;
deepEqual(expected, session.Proxy.fromJSON(manual).toJSON());
Bug 1326534 - Rewrite capabilities parsing in Marionette; r=automatedtester This patch provides a (nearly) WebDriver conforming implementation of capabilities in Marionette. The work remaining is pending further clarification in the specification. Capabilities are represented internally as a complex object provided by `session.Capabilities`. Timeouts and proxy configuration are also represented by the similar complex objects `session.Timeouts` and `session.Proxy`, respectively. The capabilities stored in `GeckoDriver#sessionCapabilities` are the result of parsing user-provided desired- and required capabilities. WebDriver now uses `firstMatch` and `alwaysMatch` primitives for capabilities, but as this is considered a wider breaking change, the move to these primitives will be done at a later stage. It’s prudent to point out that the base techniques used with the new primitives are similar to those implemented for `desiredCapabilities` and `requiredCapabilities` in this patch, and that the work needed to adapt them is considered trivial. When capabilities are presented back to the user (the so called processed capabilities), we call the `toJSON` implementation on the complex objects. `session.Capabilities#toJSON` calls the internal function `marshal` which ensures empty fields are dropped. `marshal` can be considered to be a specialisation of the standard library `JSON.stringify`, which also calls `toJSON` on entry values if they provide this function. The changeset overall also provides a much deeper level of testing of WebDriver capabilities. MozReview-Commit-ID: 97xGt3cnMys --HG-- extra : rebase_source : 98e0bde3fdfd811775d195b488cb1255f61e5772
2016-12-31 15:21:34 +03:00
}
// Without a port the default port of the scheme is used
for (let host of ["foo", "foo:"]) {
manual[proxy] = host;
Bug 1326534 - Rewrite capabilities parsing in Marionette; r=automatedtester This patch provides a (nearly) WebDriver conforming implementation of capabilities in Marionette. The work remaining is pending further clarification in the specification. Capabilities are represented internally as a complex object provided by `session.Capabilities`. Timeouts and proxy configuration are also represented by the similar complex objects `session.Timeouts` and `session.Proxy`, respectively. The capabilities stored in `GeckoDriver#sessionCapabilities` are the result of parsing user-provided desired- and required capabilities. WebDriver now uses `firstMatch` and `alwaysMatch` primitives for capabilities, but as this is considered a wider breaking change, the move to these primitives will be done at a later stage. It’s prudent to point out that the base techniques used with the new primitives are similar to those implemented for `desiredCapabilities` and `requiredCapabilities` in this patch, and that the work needed to adapt them is considered trivial. When capabilities are presented back to the user (the so called processed capabilities), we call the `toJSON` implementation on the complex objects. `session.Capabilities#toJSON` calls the internal function `marshal` which ensures empty fields are dropped. `marshal` can be considered to be a specialisation of the standard library `JSON.stringify`, which also calls `toJSON` on entry values if they provide this function. The changeset overall also provides a much deeper level of testing of WebDriver capabilities. MozReview-Commit-ID: 97xGt3cnMys --HG-- extra : rebase_source : 98e0bde3fdfd811775d195b488cb1255f61e5772
2016-12-31 15:21:34 +03:00
// For socks no default port is available
if (proxy === "socksProxy") {
expected[proxy] = `foo`;
} else {
let default_ports = {"ftpProxy": 21, "httpProxy": 80,
"sslProxy": 443};
Bug 1326534 - Rewrite capabilities parsing in Marionette; r=automatedtester This patch provides a (nearly) WebDriver conforming implementation of capabilities in Marionette. The work remaining is pending further clarification in the specification. Capabilities are represented internally as a complex object provided by `session.Capabilities`. Timeouts and proxy configuration are also represented by the similar complex objects `session.Timeouts` and `session.Proxy`, respectively. The capabilities stored in `GeckoDriver#sessionCapabilities` are the result of parsing user-provided desired- and required capabilities. WebDriver now uses `firstMatch` and `alwaysMatch` primitives for capabilities, but as this is considered a wider breaking change, the move to these primitives will be done at a later stage. It’s prudent to point out that the base techniques used with the new primitives are similar to those implemented for `desiredCapabilities` and `requiredCapabilities` in this patch, and that the work needed to adapt them is considered trivial. When capabilities are presented back to the user (the so called processed capabilities), we call the `toJSON` implementation on the complex objects. `session.Capabilities#toJSON` calls the internal function `marshal` which ensures empty fields are dropped. `marshal` can be considered to be a specialisation of the standard library `JSON.stringify`, which also calls `toJSON` on entry values if they provide this function. The changeset overall also provides a much deeper level of testing of WebDriver capabilities. MozReview-Commit-ID: 97xGt3cnMys --HG-- extra : rebase_source : 98e0bde3fdfd811775d195b488cb1255f61e5772
2016-12-31 15:21:34 +03:00
expected[proxy] = `foo:${default_ports[proxy]}`;
}
deepEqual(expected, session.Proxy.fromJSON(manual).toJSON());
Bug 1326534 - Rewrite capabilities parsing in Marionette; r=automatedtester This patch provides a (nearly) WebDriver conforming implementation of capabilities in Marionette. The work remaining is pending further clarification in the specification. Capabilities are represented internally as a complex object provided by `session.Capabilities`. Timeouts and proxy configuration are also represented by the similar complex objects `session.Timeouts` and `session.Proxy`, respectively. The capabilities stored in `GeckoDriver#sessionCapabilities` are the result of parsing user-provided desired- and required capabilities. WebDriver now uses `firstMatch` and `alwaysMatch` primitives for capabilities, but as this is considered a wider breaking change, the move to these primitives will be done at a later stage. It’s prudent to point out that the base techniques used with the new primitives are similar to those implemented for `desiredCapabilities` and `requiredCapabilities` in this patch, and that the work needed to adapt them is considered trivial. When capabilities are presented back to the user (the so called processed capabilities), we call the `toJSON` implementation on the complex objects. `session.Capabilities#toJSON` calls the internal function `marshal` which ensures empty fields are dropped. `marshal` can be considered to be a specialisation of the standard library `JSON.stringify`, which also calls `toJSON` on entry values if they provide this function. The changeset overall also provides a much deeper level of testing of WebDriver capabilities. MozReview-Commit-ID: 97xGt3cnMys --HG-- extra : rebase_source : 98e0bde3fdfd811775d195b488cb1255f61e5772
2016-12-31 15:21:34 +03:00
}
}
// missing required socks version
Bug 1326534 - Rewrite capabilities parsing in Marionette; r=automatedtester This patch provides a (nearly) WebDriver conforming implementation of capabilities in Marionette. The work remaining is pending further clarification in the specification. Capabilities are represented internally as a complex object provided by `session.Capabilities`. Timeouts and proxy configuration are also represented by the similar complex objects `session.Timeouts` and `session.Proxy`, respectively. The capabilities stored in `GeckoDriver#sessionCapabilities` are the result of parsing user-provided desired- and required capabilities. WebDriver now uses `firstMatch` and `alwaysMatch` primitives for capabilities, but as this is considered a wider breaking change, the move to these primitives will be done at a later stage. It’s prudent to point out that the base techniques used with the new primitives are similar to those implemented for `desiredCapabilities` and `requiredCapabilities` in this patch, and that the work needed to adapt them is considered trivial. When capabilities are presented back to the user (the so called processed capabilities), we call the `toJSON` implementation on the complex objects. `session.Capabilities#toJSON` calls the internal function `marshal` which ensures empty fields are dropped. `marshal` can be considered to be a specialisation of the standard library `JSON.stringify`, which also calls `toJSON` on entry values if they provide this function. The changeset overall also provides a much deeper level of testing of WebDriver capabilities. MozReview-Commit-ID: 97xGt3cnMys --HG-- extra : rebase_source : 98e0bde3fdfd811775d195b488cb1255f61e5772
2016-12-31 15:21:34 +03:00
Assert.throws(() => session.Proxy.fromJSON(
{proxyType: "manual", socksProxy: "foo:1234"}),
Bug 1326534 - Rewrite capabilities parsing in Marionette; r=automatedtester This patch provides a (nearly) WebDriver conforming implementation of capabilities in Marionette. The work remaining is pending further clarification in the specification. Capabilities are represented internally as a complex object provided by `session.Capabilities`. Timeouts and proxy configuration are also represented by the similar complex objects `session.Timeouts` and `session.Proxy`, respectively. The capabilities stored in `GeckoDriver#sessionCapabilities` are the result of parsing user-provided desired- and required capabilities. WebDriver now uses `firstMatch` and `alwaysMatch` primitives for capabilities, but as this is considered a wider breaking change, the move to these primitives will be done at a later stage. It’s prudent to point out that the base techniques used with the new primitives are similar to those implemented for `desiredCapabilities` and `requiredCapabilities` in this patch, and that the work needed to adapt them is considered trivial. When capabilities are presented back to the user (the so called processed capabilities), we call the `toJSON` implementation on the complex objects. `session.Capabilities#toJSON` calls the internal function `marshal` which ensures empty fields are dropped. `marshal` can be considered to be a specialisation of the standard library `JSON.stringify`, which also calls `toJSON` on entry values if they provide this function. The changeset overall also provides a much deeper level of testing of WebDriver capabilities. MozReview-Commit-ID: 97xGt3cnMys --HG-- extra : rebase_source : 98e0bde3fdfd811775d195b488cb1255f61e5772
2016-12-31 15:21:34 +03:00
InvalidArgumentError);
// invalid noProxy
for (let noProxy of [true, 42, {}, null, "foo",
[true], [42], [{}], [null]]) {
Assert.throws(() => session.Proxy.fromJSON(
{proxyType: "manual", noProxy: noProxy}),
InvalidArgumentError);
}
// valid noProxy
for (let noProxy of [[], ["foo"], ["foo", "bar"]]) {
let manual = {proxyType: "manual", "noProxy": noProxy}
deepEqual(manual, session.Proxy.fromJSON(manual).toJSON());
}
Bug 1326534 - Rewrite capabilities parsing in Marionette; r=automatedtester This patch provides a (nearly) WebDriver conforming implementation of capabilities in Marionette. The work remaining is pending further clarification in the specification. Capabilities are represented internally as a complex object provided by `session.Capabilities`. Timeouts and proxy configuration are also represented by the similar complex objects `session.Timeouts` and `session.Proxy`, respectively. The capabilities stored in `GeckoDriver#sessionCapabilities` are the result of parsing user-provided desired- and required capabilities. WebDriver now uses `firstMatch` and `alwaysMatch` primitives for capabilities, but as this is considered a wider breaking change, the move to these primitives will be done at a later stage. It’s prudent to point out that the base techniques used with the new primitives are similar to those implemented for `desiredCapabilities` and `requiredCapabilities` in this patch, and that the work needed to adapt them is considered trivial. When capabilities are presented back to the user (the so called processed capabilities), we call the `toJSON` implementation on the complex objects. `session.Capabilities#toJSON` calls the internal function `marshal` which ensures empty fields are dropped. `marshal` can be considered to be a specialisation of the standard library `JSON.stringify`, which also calls `toJSON` on entry values if they provide this function. The changeset overall also provides a much deeper level of testing of WebDriver capabilities. MozReview-Commit-ID: 97xGt3cnMys --HG-- extra : rebase_source : 98e0bde3fdfd811775d195b488cb1255f61e5772
2016-12-31 15:21:34 +03:00
run_next_test();
});
add_test(function test_Capabilities_ctor() {
let caps = new session.Capabilities();
ok(caps.has("browserName"));
ok(caps.has("browserVersion"));
ok(caps.has("platformName"));
ok(caps.has("platformVersion"));
equal(session.PageLoadStrategy.Normal, caps.get("pageLoadStrategy"));
equal(false, caps.get("acceptInsecureCerts"));
ok(caps.get("timeouts") instanceof session.Timeouts);
ok(caps.get("proxy") instanceof session.Proxy);
ok(caps.has("rotatable"));
equal(false, caps.get("moz:accessibilityChecks"));
Bug 1326534 - Rewrite capabilities parsing in Marionette; r=automatedtester This patch provides a (nearly) WebDriver conforming implementation of capabilities in Marionette. The work remaining is pending further clarification in the specification. Capabilities are represented internally as a complex object provided by `session.Capabilities`. Timeouts and proxy configuration are also represented by the similar complex objects `session.Timeouts` and `session.Proxy`, respectively. The capabilities stored in `GeckoDriver#sessionCapabilities` are the result of parsing user-provided desired- and required capabilities. WebDriver now uses `firstMatch` and `alwaysMatch` primitives for capabilities, but as this is considered a wider breaking change, the move to these primitives will be done at a later stage. It’s prudent to point out that the base techniques used with the new primitives are similar to those implemented for `desiredCapabilities` and `requiredCapabilities` in this patch, and that the work needed to adapt them is considered trivial. When capabilities are presented back to the user (the so called processed capabilities), we call the `toJSON` implementation on the complex objects. `session.Capabilities#toJSON` calls the internal function `marshal` which ensures empty fields are dropped. `marshal` can be considered to be a specialisation of the standard library `JSON.stringify`, which also calls `toJSON` on entry values if they provide this function. The changeset overall also provides a much deeper level of testing of WebDriver capabilities. MozReview-Commit-ID: 97xGt3cnMys --HG-- extra : rebase_source : 98e0bde3fdfd811775d195b488cb1255f61e5772
2016-12-31 15:21:34 +03:00
ok(caps.has("moz:processID"));
ok(caps.has("moz:profile"));
equal(false, caps.get("moz:webdriverClick"));
Bug 1326534 - Rewrite capabilities parsing in Marionette; r=automatedtester This patch provides a (nearly) WebDriver conforming implementation of capabilities in Marionette. The work remaining is pending further clarification in the specification. Capabilities are represented internally as a complex object provided by `session.Capabilities`. Timeouts and proxy configuration are also represented by the similar complex objects `session.Timeouts` and `session.Proxy`, respectively. The capabilities stored in `GeckoDriver#sessionCapabilities` are the result of parsing user-provided desired- and required capabilities. WebDriver now uses `firstMatch` and `alwaysMatch` primitives for capabilities, but as this is considered a wider breaking change, the move to these primitives will be done at a later stage. It’s prudent to point out that the base techniques used with the new primitives are similar to those implemented for `desiredCapabilities` and `requiredCapabilities` in this patch, and that the work needed to adapt them is considered trivial. When capabilities are presented back to the user (the so called processed capabilities), we call the `toJSON` implementation on the complex objects. `session.Capabilities#toJSON` calls the internal function `marshal` which ensures empty fields are dropped. `marshal` can be considered to be a specialisation of the standard library `JSON.stringify`, which also calls `toJSON` on entry values if they provide this function. The changeset overall also provides a much deeper level of testing of WebDriver capabilities. MozReview-Commit-ID: 97xGt3cnMys --HG-- extra : rebase_source : 98e0bde3fdfd811775d195b488cb1255f61e5772
2016-12-31 15:21:34 +03:00
run_next_test();
});
add_test(function test_Capabilities_toString() {
equal("[object session.Capabilities]", new session.Capabilities().toString());
run_next_test();
});
add_test(function test_Capabilities_toJSON() {
let caps = new session.Capabilities();
let json = caps.toJSON();
equal(caps.get("browserName"), json.browserName);
equal(caps.get("browserVersion"), json.browserVersion);
equal(caps.get("platformName"), json.platformName);
equal(caps.get("platformVersion"), json.platformVersion);
equal(caps.get("pageLoadStrategy"), json.pageLoadStrategy);
equal(caps.get("acceptInsecureCerts"), json.acceptInsecureCerts);
deepEqual(caps.get("timeouts").toJSON(), json.timeouts);
equal(undefined, json.proxy);
equal(caps.get("rotatable"), json.rotatable);
equal(caps.get("moz:accessibilityChecks"), json["moz:accessibilityChecks"]);
Bug 1326534 - Rewrite capabilities parsing in Marionette; r=automatedtester This patch provides a (nearly) WebDriver conforming implementation of capabilities in Marionette. The work remaining is pending further clarification in the specification. Capabilities are represented internally as a complex object provided by `session.Capabilities`. Timeouts and proxy configuration are also represented by the similar complex objects `session.Timeouts` and `session.Proxy`, respectively. The capabilities stored in `GeckoDriver#sessionCapabilities` are the result of parsing user-provided desired- and required capabilities. WebDriver now uses `firstMatch` and `alwaysMatch` primitives for capabilities, but as this is considered a wider breaking change, the move to these primitives will be done at a later stage. It’s prudent to point out that the base techniques used with the new primitives are similar to those implemented for `desiredCapabilities` and `requiredCapabilities` in this patch, and that the work needed to adapt them is considered trivial. When capabilities are presented back to the user (the so called processed capabilities), we call the `toJSON` implementation on the complex objects. `session.Capabilities#toJSON` calls the internal function `marshal` which ensures empty fields are dropped. `marshal` can be considered to be a specialisation of the standard library `JSON.stringify`, which also calls `toJSON` on entry values if they provide this function. The changeset overall also provides a much deeper level of testing of WebDriver capabilities. MozReview-Commit-ID: 97xGt3cnMys --HG-- extra : rebase_source : 98e0bde3fdfd811775d195b488cb1255f61e5772
2016-12-31 15:21:34 +03:00
equal(caps.get("moz:processID"), json["moz:processID"]);
equal(caps.get("moz:profile"), json["moz:profile"]);
equal(caps.get("moz:webdriverClick"), json["moz:webdriverClick"]);
Bug 1326534 - Rewrite capabilities parsing in Marionette; r=automatedtester This patch provides a (nearly) WebDriver conforming implementation of capabilities in Marionette. The work remaining is pending further clarification in the specification. Capabilities are represented internally as a complex object provided by `session.Capabilities`. Timeouts and proxy configuration are also represented by the similar complex objects `session.Timeouts` and `session.Proxy`, respectively. The capabilities stored in `GeckoDriver#sessionCapabilities` are the result of parsing user-provided desired- and required capabilities. WebDriver now uses `firstMatch` and `alwaysMatch` primitives for capabilities, but as this is considered a wider breaking change, the move to these primitives will be done at a later stage. It’s prudent to point out that the base techniques used with the new primitives are similar to those implemented for `desiredCapabilities` and `requiredCapabilities` in this patch, and that the work needed to adapt them is considered trivial. When capabilities are presented back to the user (the so called processed capabilities), we call the `toJSON` implementation on the complex objects. `session.Capabilities#toJSON` calls the internal function `marshal` which ensures empty fields are dropped. `marshal` can be considered to be a specialisation of the standard library `JSON.stringify`, which also calls `toJSON` on entry values if they provide this function. The changeset overall also provides a much deeper level of testing of WebDriver capabilities. MozReview-Commit-ID: 97xGt3cnMys --HG-- extra : rebase_source : 98e0bde3fdfd811775d195b488cb1255f61e5772
2016-12-31 15:21:34 +03:00
run_next_test();
});
add_test(function test_Capabilities_fromJSON() {
const {fromJSON} = session.Capabilities;
// plain
for (let typ of [{}, null, undefined]) {
ok(fromJSON(typ).has("browserName"));
Bug 1326534 - Rewrite capabilities parsing in Marionette; r=automatedtester This patch provides a (nearly) WebDriver conforming implementation of capabilities in Marionette. The work remaining is pending further clarification in the specification. Capabilities are represented internally as a complex object provided by `session.Capabilities`. Timeouts and proxy configuration are also represented by the similar complex objects `session.Timeouts` and `session.Proxy`, respectively. The capabilities stored in `GeckoDriver#sessionCapabilities` are the result of parsing user-provided desired- and required capabilities. WebDriver now uses `firstMatch` and `alwaysMatch` primitives for capabilities, but as this is considered a wider breaking change, the move to these primitives will be done at a later stage. It’s prudent to point out that the base techniques used with the new primitives are similar to those implemented for `desiredCapabilities` and `requiredCapabilities` in this patch, and that the work needed to adapt them is considered trivial. When capabilities are presented back to the user (the so called processed capabilities), we call the `toJSON` implementation on the complex objects. `session.Capabilities#toJSON` calls the internal function `marshal` which ensures empty fields are dropped. `marshal` can be considered to be a specialisation of the standard library `JSON.stringify`, which also calls `toJSON` on entry values if they provide this function. The changeset overall also provides a much deeper level of testing of WebDriver capabilities. MozReview-Commit-ID: 97xGt3cnMys --HG-- extra : rebase_source : 98e0bde3fdfd811775d195b488cb1255f61e5772
2016-12-31 15:21:34 +03:00
}
for (let typ of [true, 42, "foo", []]) {
Assert.throws(() => fromJSON(typ), InvalidArgumentError);
Bug 1326534 - Rewrite capabilities parsing in Marionette; r=automatedtester This patch provides a (nearly) WebDriver conforming implementation of capabilities in Marionette. The work remaining is pending further clarification in the specification. Capabilities are represented internally as a complex object provided by `session.Capabilities`. Timeouts and proxy configuration are also represented by the similar complex objects `session.Timeouts` and `session.Proxy`, respectively. The capabilities stored in `GeckoDriver#sessionCapabilities` are the result of parsing user-provided desired- and required capabilities. WebDriver now uses `firstMatch` and `alwaysMatch` primitives for capabilities, but as this is considered a wider breaking change, the move to these primitives will be done at a later stage. It’s prudent to point out that the base techniques used with the new primitives are similar to those implemented for `desiredCapabilities` and `requiredCapabilities` in this patch, and that the work needed to adapt them is considered trivial. When capabilities are presented back to the user (the so called processed capabilities), we call the `toJSON` implementation on the complex objects. `session.Capabilities#toJSON` calls the internal function `marshal` which ensures empty fields are dropped. `marshal` can be considered to be a specialisation of the standard library `JSON.stringify`, which also calls `toJSON` on entry values if they provide this function. The changeset overall also provides a much deeper level of testing of WebDriver capabilities. MozReview-Commit-ID: 97xGt3cnMys --HG-- extra : rebase_source : 98e0bde3fdfd811775d195b488cb1255f61e5772
2016-12-31 15:21:34 +03:00
}
// matching
let caps = new session.Capabilities();
caps = fromJSON({acceptInsecureCerts: true});
equal(true, caps.get("acceptInsecureCerts"));
caps = fromJSON({acceptInsecureCerts: false});
equal(false, caps.get("acceptInsecureCerts"));
Assert.throws(() => fromJSON({acceptInsecureCerts: "foo"}));
for (let strategy of Object.values(session.PageLoadStrategy)) {
caps = fromJSON({pageLoadStrategy: strategy});
equal(strategy, caps.get("pageLoadStrategy"));
}
Assert.throws(() => fromJSON({pageLoadStrategy: "foo"}));
let proxyConfig = {proxyType: "manual"};
caps = fromJSON({proxy: proxyConfig});
equal("manual", caps.get("proxy").proxyType);
let timeoutsConfig = {implicit: 123};
caps = fromJSON({timeouts: timeoutsConfig});
equal(123, caps.get("timeouts").implicit);
equal(false, caps.get("moz:webdriverClick"));
caps = fromJSON({"moz:webdriverClick": true});
equal(true, caps.get("moz:webdriverClick"));
Assert.throws(() => fromJSON({"moz:webdriverClick": "foo"}));
Assert.throws(() => fromJSON({"moz:webdriverClick": 1}));
Bug 1326534 - Rewrite capabilities parsing in Marionette; r=automatedtester This patch provides a (nearly) WebDriver conforming implementation of capabilities in Marionette. The work remaining is pending further clarification in the specification. Capabilities are represented internally as a complex object provided by `session.Capabilities`. Timeouts and proxy configuration are also represented by the similar complex objects `session.Timeouts` and `session.Proxy`, respectively. The capabilities stored in `GeckoDriver#sessionCapabilities` are the result of parsing user-provided desired- and required capabilities. WebDriver now uses `firstMatch` and `alwaysMatch` primitives for capabilities, but as this is considered a wider breaking change, the move to these primitives will be done at a later stage. It’s prudent to point out that the base techniques used with the new primitives are similar to those implemented for `desiredCapabilities` and `requiredCapabilities` in this patch, and that the work needed to adapt them is considered trivial. When capabilities are presented back to the user (the so called processed capabilities), we call the `toJSON` implementation on the complex objects. `session.Capabilities#toJSON` calls the internal function `marshal` which ensures empty fields are dropped. `marshal` can be considered to be a specialisation of the standard library `JSON.stringify`, which also calls `toJSON` on entry values if they provide this function. The changeset overall also provides a much deeper level of testing of WebDriver capabilities. MozReview-Commit-ID: 97xGt3cnMys --HG-- extra : rebase_source : 98e0bde3fdfd811775d195b488cb1255f61e5772
2016-12-31 15:21:34 +03:00
caps = fromJSON({"moz:accessibilityChecks": true});
equal(true, caps.get("moz:accessibilityChecks"));
caps = fromJSON({"moz:accessibilityChecks": false});
equal(false, caps.get("moz:accessibilityChecks"));
Assert.throws(() => fromJSON({"moz:accessibilityChecks": "foo"}));
run_next_test();
});
// use session.Proxy.toJSON to test marshal
add_test(function test_marshal() {
let proxy = new session.Proxy();
// drop empty fields
deepEqual({}, proxy.toJSON());
proxy.proxyType = "manual";
deepEqual({proxyType: "manual"}, proxy.toJSON());
proxy.proxyType = null;
deepEqual({}, proxy.toJSON());
proxy.proxyType = undefined;
deepEqual({}, proxy.toJSON());
// iterate over object literals
proxy.proxyType = {foo: "bar"};
deepEqual({proxyType: {foo: "bar"}}, proxy.toJSON());
// iterate over complex object that implement toJSON
proxy.proxyType = new session.Proxy();
deepEqual({}, proxy.toJSON());
proxy.proxyType.proxyType = "manual";
deepEqual({proxyType: {proxyType: "manual"}}, proxy.toJSON());
// drop objects with no entries
proxy.proxyType = {foo: {}};
deepEqual({}, proxy.toJSON());
proxy.proxyType = {foo: new session.Proxy()};
deepEqual({}, proxy.toJSON());
run_next_test();
});