gecko-dev/testing/marionette/capabilities.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

687 строки
18 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";
Bug 1514594: Part 3 - Change ChromeUtils.import API. *** Bug 1514594: Part 3a - Change ChromeUtils.import to return an exports object; not pollute global. r=mccr8 This changes the behavior of ChromeUtils.import() to return an exports object, rather than a module global, in all cases except when `null` is passed as a second argument, and changes the default behavior not to pollute the global scope with the module's exports. Thus, the following code written for the old model: ChromeUtils.import("resource://gre/modules/Services.jsm"); is approximately the same as the following, in the new model: var {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm"); Since the two behaviors are mutually incompatible, this patch will land with a scripted rewrite to update all existing callers to use the new model rather than the old. *** Bug 1514594: Part 3b - Mass rewrite all JS code to use the new ChromeUtils.import API. rs=Gijs This was done using the followng script: https://bitbucket.org/kmaglione/m-c-rewrites/src/tip/processors/cu-import-exports.jsm *** Bug 1514594: Part 3c - Update ESLint plugin for ChromeUtils.import API changes. r=Standard8 Differential Revision: https://phabricator.services.mozilla.com/D16747 *** Bug 1514594: Part 3d - Remove/fix hundreds of duplicate imports from sync tests. r=Gijs Differential Revision: https://phabricator.services.mozilla.com/D16748 *** Bug 1514594: Part 3e - Remove no-op ChromeUtils.import() calls. r=Gijs Differential Revision: https://phabricator.services.mozilla.com/D16749 *** Bug 1514594: Part 3f.1 - Cleanup various test corner cases after mass rewrite. r=Gijs *** Bug 1514594: Part 3f.2 - Cleanup various non-test corner cases after mass rewrite. r=Gijs Differential Revision: https://phabricator.services.mozilla.com/D16750 --HG-- extra : rebase_source : 359574ee3064c90f33bf36c2ebe3159a24cc8895 extra : histedit_source : b93c8f42808b1599f9122d7842d2c0b3e656a594%2C64a3a4e3359dc889e2ab2b49461bab9e27fc10a7
2019-01-17 21:18:31 +03:00
const { Preferences } = ChromeUtils.import(
"resource://gre/modules/Preferences.jsm"
);
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
const { XPCOMUtils } = ChromeUtils.import(
"resource://gre/modules/XPCOMUtils.jsm"
);
Bug 1514594: Part 3 - Change ChromeUtils.import API. *** Bug 1514594: Part 3a - Change ChromeUtils.import to return an exports object; not pollute global. r=mccr8 This changes the behavior of ChromeUtils.import() to return an exports object, rather than a module global, in all cases except when `null` is passed as a second argument, and changes the default behavior not to pollute the global scope with the module's exports. Thus, the following code written for the old model: ChromeUtils.import("resource://gre/modules/Services.jsm"); is approximately the same as the following, in the new model: var {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm"); Since the two behaviors are mutually incompatible, this patch will land with a scripted rewrite to update all existing callers to use the new model rather than the old. *** Bug 1514594: Part 3b - Mass rewrite all JS code to use the new ChromeUtils.import API. rs=Gijs This was done using the followng script: https://bitbucket.org/kmaglione/m-c-rewrites/src/tip/processors/cu-import-exports.jsm *** Bug 1514594: Part 3c - Update ESLint plugin for ChromeUtils.import API changes. r=Standard8 Differential Revision: https://phabricator.services.mozilla.com/D16747 *** Bug 1514594: Part 3d - Remove/fix hundreds of duplicate imports from sync tests. r=Gijs Differential Revision: https://phabricator.services.mozilla.com/D16748 *** Bug 1514594: Part 3e - Remove no-op ChromeUtils.import() calls. r=Gijs Differential Revision: https://phabricator.services.mozilla.com/D16749 *** Bug 1514594: Part 3f.1 - Cleanup various test corner cases after mass rewrite. r=Gijs *** Bug 1514594: Part 3f.2 - Cleanup various non-test corner cases after mass rewrite. r=Gijs Differential Revision: https://phabricator.services.mozilla.com/D16750 --HG-- extra : rebase_source : 359574ee3064c90f33bf36c2ebe3159a24cc8895 extra : histedit_source : b93c8f42808b1599f9122d7842d2c0b3e656a594%2C64a3a4e3359dc889e2ab2b49461bab9e27fc10a7
2019-01-17 21:18:31 +03:00
const { assert } = ChromeUtils.import("chrome://marionette/content/assert.js");
const { InvalidArgumentError } = ChromeUtils.import(
"chrome://marionette/content/error.js"
);
const { pprint } = ChromeUtils.import("chrome://marionette/content/format.js");
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
XPCOMUtils.defineLazyGlobalGetters(this, ["URL"]);
this.EXPORTED_SYMBOLS = [
"Capabilities",
"PageLoadStrategy",
"Proxy",
"Timeouts",
"UnhandledPromptBehavior",
];
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
// Enable testing this module, as Services.appinfo.* is not available
// in xpcshell tests.
const appinfo = { name: "<missing>", version: "<missing>" };
try {
appinfo.name = Services.appinfo.name.toLowerCase();
} catch (e) {}
try {
appinfo.version = Services.appinfo.version;
} catch (e) {}
/** Representation of WebDriver session timeouts. */
class Timeouts {
constructor() {
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
// disabled
this.implicit = 0;
// five mintues
this.pageLoad = 300000;
// 30 seconds
this.script = 30000;
}
toString() {
return "[object Timeouts]";
}
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
/** Marshals timeout durations to a JSON Object. */
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
return {
implicit: this.implicit,
pageLoad: this.pageLoad,
script: this.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
};
}
static fromJSON(json) {
assert.object(
json,
pprint`Expected "timeouts" to be an object, got ${json}`
);
let t = new Timeouts();
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 [type, ms] of Object.entries(json)) {
switch (type) {
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
case "implicit":
t.implicit = assert.positiveInteger(
ms,
pprint`Expected ${type} to be a positive integer, got ${ms}`
);
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
break;
case "script":
if (ms !== null) {
assert.positiveInteger(
ms,
pprint`Expected ${type} to be a positive integer, got ${ms}`
);
}
t.script = ms;
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
break;
case "pageLoad":
t.pageLoad = assert.positiveInteger(
ms,
pprint`Expected ${type} to be a positive integer, got ${ms}`
);
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
break;
default:
throw new InvalidArgumentError("Unrecognised timeout: " + type);
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
}
}
return t;
}
}
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
/**
* Enum of page loading strategies.
*
* @enum
*/
const PageLoadStrategy = {
/** No page load strategy. Navigation will return immediately. */
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
None: "none",
/**
* Eager, causing navigation to complete when the document reaches
* the <code>interactive</code> ready state.
*/
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
Eager: "eager",
/**
* Normal, causing navigation to return when the document reaches the
* <code>complete</code> ready state.
*/
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
Normal: "normal",
};
/** Proxy configuration object representation. */
class Proxy {
/** @class */
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
constructor() {
this.proxyType = null;
this.ftpProxy = null;
this.ftpProxyPort = null;
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.httpProxy = null;
this.httpProxyPort = null;
this.noProxy = null;
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.sslProxy = null;
this.sslProxyPort = null;
this.socksProxy = null;
this.socksProxyPort = null;
this.socksVersion = null;
this.proxyAutoconfigUrl = null;
}
/**
* Sets Firefox proxy settings.
*
* @return {boolean}
* True if proxy settings were updated as a result of calling this
* function, or false indicating that this function acted as
* a no-op.
*/
init() {
switch (this.proxyType) {
case "autodetect":
Preferences.set("network.proxy.type", 4);
return true;
case "direct":
Preferences.set("network.proxy.type", 0);
return true;
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
case "manual":
Preferences.set("network.proxy.type", 1);
if (this.ftpProxy) {
Preferences.set("network.proxy.ftp", this.ftpProxy);
if (Number.isInteger(this.ftpProxyPort)) {
Preferences.set("network.proxy.ftp_port", this.ftpProxyPort);
}
}
if (this.httpProxy) {
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
Preferences.set("network.proxy.http", this.httpProxy);
if (Number.isInteger(this.httpProxyPort)) {
Preferences.set("network.proxy.http_port", this.httpProxyPort);
}
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
}
if (this.sslProxy) {
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
Preferences.set("network.proxy.ssl", this.sslProxy);
if (Number.isInteger(this.sslProxyPort)) {
Preferences.set("network.proxy.ssl_port", this.sslProxyPort);
}
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
}
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
if (this.socksProxy) {
Preferences.set("network.proxy.socks", this.socksProxy);
if (Number.isInteger(this.socksProxyPort)) {
Preferences.set("network.proxy.socks_port", this.socksProxyPort);
}
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
if (this.socksVersion) {
Preferences.set("network.proxy.socks_version", this.socksVersion);
}
}
if (this.noProxy) {
Preferences.set(
"network.proxy.no_proxies_on",
this.noProxy.join(", ")
);
}
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
return true;
case "pac":
Preferences.set("network.proxy.type", 2);
Preferences.set(
"network.proxy.autoconfig_url",
this.proxyAutoconfigUrl
);
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
return true;
case "system":
Preferences.set("network.proxy.type", 5);
return true;
default:
return false;
}
}
/**
* @param {Object.<string, ?>} json
* JSON Object to unmarshal.
*
* @throws {InvalidArgumentError}
* When proxy configuration is invalid.
*/
static fromJSON(json) {
function stripBracketsFromIpv6Hostname(hostname) {
return hostname.includes(":")
? hostname.replace(/[\[\]]/g, "")
: hostname;
}
// Parse hostname and optional port from host
function fromHost(scheme, host) {
assert.string(
host,
pprint`Expected proxy "host" to be a string, got ${host}`
);
if (host.includes("://")) {
throw new InvalidArgumentError(`${host} contains a scheme`);
}
let url;
try {
// To parse the host a scheme has to be added temporarily.
// If the returned value for the port is an empty string it
// could mean no port or the default port for this scheme was
// specified. In such a case parse again with a different
// scheme to ensure we filter out the default port.
url = new URL("http://" + host);
if (url.port == "") {
url = new URL("https://" + host);
}
} catch (e) {
throw new InvalidArgumentError(e.message);
}
let hostname = stripBracketsFromIpv6Hostname(url.hostname);
// If the port hasn't been set, use the default port of
// the selected scheme (except for socks which doesn't have one).
let port = parseInt(url.port);
if (!Number.isInteger(port)) {
if (scheme === "socks") {
port = null;
} else {
port = Services.io.getProtocolHandler(scheme).defaultPort;
}
}
if (
url.username != "" ||
url.password != "" ||
url.pathname != "/" ||
url.search != "" ||
url.hash != ""
) {
throw new InvalidArgumentError(
`${host} was not of the form host[:port]`
);
}
return [hostname, port];
}
let p = new Proxy();
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
if (typeof json == "undefined" || json === null) {
return p;
}
assert.object(json, pprint`Expected "proxy" to be an object, got ${json}`);
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.in(
"proxyType",
json,
pprint`Expected "proxyType" in "proxy" object, got ${json}`
);
p.proxyType = assert.string(
json.proxyType,
pprint`Expected "proxyType" to be a string, got ${json.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
switch (p.proxyType) {
case "autodetect":
case "direct":
case "system":
break;
case "pac":
p.proxyAutoconfigUrl = assert.string(
json.proxyAutoconfigUrl,
`Expected "proxyAutoconfigUrl" to be a string, ` +
pprint`got ${json.proxyAutoconfigUrl}`
);
break;
case "manual":
if (typeof json.ftpProxy != "undefined") {
[p.ftpProxy, p.ftpProxyPort] = fromHost("ftp", json.ftpProxy);
}
if (typeof json.httpProxy != "undefined") {
[p.httpProxy, p.httpProxyPort] = fromHost("http", json.httpProxy);
}
if (typeof json.sslProxy != "undefined") {
[p.sslProxy, p.sslProxyPort] = fromHost("https", json.sslProxy);
}
if (typeof json.socksProxy != "undefined") {
[p.socksProxy, p.socksProxyPort] = fromHost("socks", json.socksProxy);
p.socksVersion = assert.positiveInteger(
json.socksVersion,
pprint`Expected "socksVersion" to be a positive integer, got ${json.socksVersion}`
);
}
if (typeof json.noProxy != "undefined") {
let entries = assert.array(
json.noProxy,
pprint`Expected "noProxy" to be an array, got ${json.noProxy}`
);
p.noProxy = entries.map(entry => {
assert.string(
entry,
pprint`Expected "noProxy" entry to be a string, got ${entry}`
);
return stripBracketsFromIpv6Hostname(entry);
});
}
break;
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
default:
throw new InvalidArgumentError(`Invalid type of proxy: ${p.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
}
return p;
}
/**
* @return {Object.<string, (number|string)>}
* JSON serialisation of proxy object.
*/
toJSON() {
function addBracketsToIpv6Hostname(hostname) {
return hostname.includes(":") ? `[${hostname}]` : hostname;
}
function toHost(hostname, port) {
if (!hostname) {
return null;
}
// Add brackets around IPv6 addresses
hostname = addBracketsToIpv6Hostname(hostname);
if (port != null) {
return `${hostname}:${port}`;
}
return hostname;
}
let excludes = this.noProxy;
if (excludes) {
excludes = excludes.map(addBracketsToIpv6Hostname);
}
return marshal({
proxyType: this.proxyType,
ftpProxy: toHost(this.ftpProxy, this.ftpProxyPort),
httpProxy: toHost(this.httpProxy, this.httpProxyPort),
noProxy: excludes,
sslProxy: toHost(this.sslProxy, this.sslProxyPort),
socksProxy: toHost(this.socksProxy, this.socksProxyPort),
socksVersion: this.socksVersion,
proxyAutoconfigUrl: this.proxyAutoconfigUrl,
});
}
toString() {
return "[object Proxy]";
}
}
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
/**
* Enum of unhandled prompt behavior.
*
* @enum
*/
const UnhandledPromptBehavior = {
/** All simple dialogs encountered should be accepted. */
Accept: "accept",
/**
* All simple dialogs encountered should be accepted, and an error
* returned that the dialog was handled.
*/
AcceptAndNotify: "accept and notify",
/** All simple dialogs encountered should be dismissed. */
Dismiss: "dismiss",
/**
* All simple dialogs encountered should be dismissed, and an error
* returned that the dialog was handled.
*/
DismissAndNotify: "dismiss and notify",
/** All simple dialogs encountered should be left to the user to handle. */
Ignore: "ignore",
};
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
/** WebDriver session capabilities representation. */
class Capabilities extends Map {
/** @class */
constructor() {
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
super([
// webdriver
["browserName", getWebDriverBrowserName()],
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
["browserVersion", appinfo.version],
["platformName", getWebDriverPlatformName()],
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
["platformVersion", Services.sysinfo.getProperty("version")],
["acceptInsecureCerts", false],
["pageLoadStrategy", PageLoadStrategy.Normal],
["proxy", new Proxy()],
["setWindowRect", appinfo.name == "firefox"],
["timeouts", new Timeouts()],
["strictFileInteractability", false],
["unhandledPromptBehavior", UnhandledPromptBehavior.DismissAndNotify],
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
// features
["rotatable", appinfo.name == "B2G"],
// proprietary
["moz:accessibilityChecks", false],
["moz:buildID", Services.appinfo.appBuildID],
[
"moz:headless",
Cc["@mozilla.org/gfx/info;1"].getService(Ci.nsIGfxInfo).isHeadless,
],
["moz:processID", Services.appinfo.processID],
["moz:profile", maybeProfile()],
[
"moz:shutdownTimeout",
Services.prefs.getIntPref("toolkit.asyncshutdown.crash_timeout"),
],
["moz:useNonSpecCompliantPointerOrigin", false],
["moz:webdriverClick", true],
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
]);
}
/**
* @param {string} key
* Capability key.
* @param {(string|number|boolean)} value
* JSON-safe capability value.
*/
set(key, value) {
if (key === "timeouts" && !(value instanceof Timeouts)) {
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
throw new TypeError();
} else if (key === "proxy" && !(value instanceof Proxy)) {
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
throw new TypeError();
}
return super.set(key, value);
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
}
toString() {
return "[object Capabilities]";
}
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
/**
* JSON serialisation of capabilities object.
*
* @return {Object.<string, ?>}
*/
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
toJSON() {
let marshalled = marshal(this);
marshalled.timeouts = super.get("timeouts");
return marshalled;
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
}
/**
* Unmarshal a JSON object representation of WebDriver capabilities.
*
* @param {Object.<string, *>=} json
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
* WebDriver capabilities.
*
* @return {Capabilities}
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
* Internal representation of WebDriver capabilities.
*/
static fromJSON(json) {
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
if (typeof json == "undefined" || json === null) {
json = {};
}
assert.object(
json,
pprint`Expected "capabilities" to be an object, got ${json}"`
);
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
return Capabilities.match_(json);
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
}
// Matches capabilities as described by WebDriver.
static match_(json = {}) {
let matched = new Capabilities();
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 [k, v] of Object.entries(json)) {
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
switch (k) {
case "acceptInsecureCerts":
assert.boolean(v, pprint`Expected ${k} to be a boolean, got ${v}`);
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
break;
case "pageLoadStrategy":
assert.string(v, pprint`Expected ${k} to be a string, got ${v}`);
if (!Object.values(PageLoadStrategy).includes(v)) {
throw new InvalidArgumentError("Unknown page load strategy: " + v);
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
}
break;
case "proxy":
v = Proxy.fromJSON(v);
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
break;
case "setWindowRect":
assert.boolean(v, pprint`Expected ${k} to be boolean, got ${v}`);
if (appinfo.name == "firefox" && !v) {
throw new InvalidArgumentError("setWindowRect cannot be disabled");
} else if (appinfo.name != "firefox" && v) {
throw new InvalidArgumentError(
"setWindowRect is only supported in Firefox desktop"
);
}
break;
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
case "timeouts":
v = Timeouts.fromJSON(v);
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
break;
case "strictFileInteractability":
v = assert.boolean(v);
break;
case "unhandledPromptBehavior":
assert.string(v, pprint`Expected ${k} to be a string, got ${v}`);
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 boolean, got ${v}`);
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
break;
case "moz:useNonSpecCompliantPointerOrigin":
assert.boolean(v, pprint`Expected ${k} to be boolean, got ${v}`);
break;
case "moz:webdriverClick":
assert.boolean(v, pprint`Expected ${k} to be boolean, got ${v}`);
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
break;
}
matched.set(k, v);
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
}
return matched;
}
}
this.Capabilities = Capabilities;
this.PageLoadStrategy = PageLoadStrategy;
this.Proxy = Proxy;
this.Timeouts = Timeouts;
this.UnhandledPromptBehavior = UnhandledPromptBehavior;
function getWebDriverBrowserName() {
// Similar to chromedriver which reports "chrome" as browser name for all
// WebView apps, we will report "firefox" for all GeckoView apps.
if (Services.androidBridge) {
return "firefox";
}
return appinfo.name;
}
function getWebDriverPlatformName() {
let name = Services.sysinfo.getProperty("name");
if (Services.androidBridge) {
return "android";
}
switch (name) {
case "Windows_NT":
return "windows";
case "Darwin":
return "mac";
default:
return name.toLowerCase();
}
}
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
// Specialisation of |JSON.stringify| that produces JSON-safe object
// literals, dropping empty objects and entries which values are undefined
// or null. Objects are allowed to produce their own JSON representations
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
// by implementing a |toJSON| function.
function marshal(obj) {
let rv = Object.create(null);
function* iter(mapOrObject) {
if (mapOrObject instanceof Map) {
for (const [k, v] of mapOrObject) {
yield [k, v];
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
}
} else {
for (const k of Object.keys(mapOrObject)) {
yield [k, mapOrObject[k]];
}
}
}
for (let [k, v] of iter(obj)) {
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
// Skip empty values when serialising to JSON.
if (typeof v == "undefined" || v === null) {
continue;
}
// Recursively marshal objects that are able to produce their own
// JSON representation.
if (typeof v.toJSON == "function") {
v = marshal(v.toJSON());
// Or do the same for object literals.
} else if (isObject(v)) {
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
v = marshal(v);
}
// And finally drop (possibly marshaled) objects which have no
// entries.
if (!isObjectEmpty(v)) {
rv[k] = v;
}
}
return rv;
}
function isObject(obj) {
return Object.prototype.toString.call(obj) == "[object Object]";
}
function isObjectEmpty(obj) {
return isObject(obj) && Object.keys(obj).length === 0;
}
// Services.dirsvc is not accessible from content frame scripts,
// but we should not panic about that.
function maybeProfile() {
try {
return Services.dirsvc.get("ProfD", Ci.nsIFile).path;
} catch (e) {
return "<protected>";
}
}