2016-02-29 21:52:30 +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";
|
|
|
|
|
2020-09-08 21:19:32 +03:00
|
|
|
const EXPORTED_SYMBOLS = ["evaluate", "sandbox", "Sandboxes"];
|
|
|
|
|
2019-01-17 21:18:31 +03:00
|
|
|
const { clearTimeout, setTimeout } = ChromeUtils.import(
|
|
|
|
"resource://gre/modules/Timer.jsm"
|
|
|
|
);
|
|
|
|
const { XPCOMUtils } = ChromeUtils.import(
|
|
|
|
"resource://gre/modules/XPCOMUtils.jsm"
|
2019-07-05 12:01:24 +03:00
|
|
|
);
|
|
|
|
|
2020-09-08 21:22:43 +03:00
|
|
|
XPCOMUtils.defineLazyModuleGetters(this, {
|
|
|
|
assert: "chrome://marionette/content/assert.js",
|
|
|
|
element: "chrome://marionette/content/element.js",
|
|
|
|
error: "chrome://marionette/content/error.js",
|
|
|
|
Log: "chrome://marionette/content/log.js",
|
|
|
|
WebElement: "chrome://marionette/content/element.js",
|
|
|
|
});
|
Bug 1123506 - Evaluate scripts in content with lasting side-effects; r=automatedtester
In order to achieve WebDriver parity, Marionette needs the ability to
evaluate scripts in content space with lasting side-effects. This means
that state modifications should affect behaviour and state of the browsing
context, and such transgress the boundaries of the sandbox.
This patch brings a new script evaluation module that is shared between
code in chrome- and content space. This brings the number of unique
script evaluation implementations in Marionette down from six to one.
evaluate.sandbox provides the main entry-point for execution. It is
compatible with existing Marionette uses of Execute Script and Execute
Async Script commands in Mozilla clients, but also provides a new stateful
sandbox for evaluation that should have lasting side-effects.
It is not expected that Mozilla clients, such as testing/marionette/client
and the Node.js client in Gaia, should have to change as a consequence
of this change.
A substantial change to the script's runtime environment is that many
globals that previously existed are now only exposed whenever needed.
This means for example that Simple Test harness functionality (waitFor,
ok, isnot, is, &c.) is only available when using a sandbox augmented
with a Simple Test harness adapter.
Conversely, this patch does not expose marionetteScriptFinished as a
callback to asynchronous scripts for sandboxes which sandboxName parameter
is undefined, because this is what determines if the script should be
evaluated under WebDriver conformance constraints. In all other cases
where sandboxName _is_ defined, the traditional marionetteScriptFinished
et al. runtime environment is preserved.
MozReview-Commit-ID: 8FZ6rNVImuC
2016-02-26 17:36:39 +03:00
|
|
|
|
2020-09-16 14:51:36 +03:00
|
|
|
XPCOMUtils.defineLazyGetter(this, "logger", () => Log.get());
|
2016-02-29 21:52:30 +03:00
|
|
|
|
Bug 1123506 - Evaluate scripts in content with lasting side-effects; r=automatedtester
In order to achieve WebDriver parity, Marionette needs the ability to
evaluate scripts in content space with lasting side-effects. This means
that state modifications should affect behaviour and state of the browsing
context, and such transgress the boundaries of the sandbox.
This patch brings a new script evaluation module that is shared between
code in chrome- and content space. This brings the number of unique
script evaluation implementations in Marionette down from six to one.
evaluate.sandbox provides the main entry-point for execution. It is
compatible with existing Marionette uses of Execute Script and Execute
Async Script commands in Mozilla clients, but also provides a new stateful
sandbox for evaluation that should have lasting side-effects.
It is not expected that Mozilla clients, such as testing/marionette/client
and the Node.js client in Gaia, should have to change as a consequence
of this change.
A substantial change to the script's runtime environment is that many
globals that previously existed are now only exposed whenever needed.
This means for example that Simple Test harness functionality (waitFor,
ok, isnot, is, &c.) is only available when using a sandbox augmented
with a Simple Test harness adapter.
Conversely, this patch does not expose marionetteScriptFinished as a
callback to asynchronous scripts for sandboxes which sandboxName parameter
is undefined, because this is what determines if the script should be
evaluated under WebDriver conformance constraints. In all other cases
where sandboxName _is_ defined, the traditional marionetteScriptFinished
et al. runtime environment is preserved.
MozReview-Commit-ID: 8FZ6rNVImuC
2016-02-26 17:36:39 +03:00
|
|
|
const ARGUMENTS = "__webDriverArguments";
|
|
|
|
const CALLBACK = "__webDriverCallback";
|
|
|
|
const COMPLETE = "__webDriverComplete";
|
|
|
|
const DEFAULT_TIMEOUT = 10000; // ms
|
|
|
|
const FINISH = "finish";
|
2016-02-29 21:52:30 +03:00
|
|
|
|
2017-07-26 15:11:53 +03:00
|
|
|
/** @namespace */
|
2016-02-29 21:52:30 +03:00
|
|
|
this.evaluate = {};
|
|
|
|
|
Bug 1123506 - Evaluate scripts in content with lasting side-effects; r=automatedtester
In order to achieve WebDriver parity, Marionette needs the ability to
evaluate scripts in content space with lasting side-effects. This means
that state modifications should affect behaviour and state of the browsing
context, and such transgress the boundaries of the sandbox.
This patch brings a new script evaluation module that is shared between
code in chrome- and content space. This brings the number of unique
script evaluation implementations in Marionette down from six to one.
evaluate.sandbox provides the main entry-point for execution. It is
compatible with existing Marionette uses of Execute Script and Execute
Async Script commands in Mozilla clients, but also provides a new stateful
sandbox for evaluation that should have lasting side-effects.
It is not expected that Mozilla clients, such as testing/marionette/client
and the Node.js client in Gaia, should have to change as a consequence
of this change.
A substantial change to the script's runtime environment is that many
globals that previously existed are now only exposed whenever needed.
This means for example that Simple Test harness functionality (waitFor,
ok, isnot, is, &c.) is only available when using a sandbox augmented
with a Simple Test harness adapter.
Conversely, this patch does not expose marionetteScriptFinished as a
callback to asynchronous scripts for sandboxes which sandboxName parameter
is undefined, because this is what determines if the script should be
evaluated under WebDriver conformance constraints. In all other cases
where sandboxName _is_ defined, the traditional marionetteScriptFinished
et al. runtime environment is preserved.
MozReview-Commit-ID: 8FZ6rNVImuC
2016-02-26 17:36:39 +03:00
|
|
|
/**
|
|
|
|
* Evaluate a script in given sandbox.
|
|
|
|
*
|
2018-04-08 20:03:29 +03:00
|
|
|
* The the provided `script` will be wrapped in an anonymous function
|
|
|
|
* with the `args` argument applied.
|
Bug 1123506 - Evaluate scripts in content with lasting side-effects; r=automatedtester
In order to achieve WebDriver parity, Marionette needs the ability to
evaluate scripts in content space with lasting side-effects. This means
that state modifications should affect behaviour and state of the browsing
context, and such transgress the boundaries of the sandbox.
This patch brings a new script evaluation module that is shared between
code in chrome- and content space. This brings the number of unique
script evaluation implementations in Marionette down from six to one.
evaluate.sandbox provides the main entry-point for execution. It is
compatible with existing Marionette uses of Execute Script and Execute
Async Script commands in Mozilla clients, but also provides a new stateful
sandbox for evaluation that should have lasting side-effects.
It is not expected that Mozilla clients, such as testing/marionette/client
and the Node.js client in Gaia, should have to change as a consequence
of this change.
A substantial change to the script's runtime environment is that many
globals that previously existed are now only exposed whenever needed.
This means for example that Simple Test harness functionality (waitFor,
ok, isnot, is, &c.) is only available when using a sandbox augmented
with a Simple Test harness adapter.
Conversely, this patch does not expose marionetteScriptFinished as a
callback to asynchronous scripts for sandboxes which sandboxName parameter
is undefined, because this is what determines if the script should be
evaluated under WebDriver conformance constraints. In all other cases
where sandboxName _is_ defined, the traditional marionetteScriptFinished
et al. runtime environment is preserved.
MozReview-Commit-ID: 8FZ6rNVImuC
2016-02-26 17:36:39 +03:00
|
|
|
*
|
2018-04-08 20:03:29 +03:00
|
|
|
* The arguments provided by the `args<` argument are exposed
|
|
|
|
* through the `arguments` object available in the script context,
|
|
|
|
* and if the script is executed asynchronously with the `async`
|
|
|
|
* option, an additional last argument that is synonymous to the
|
2018-07-08 07:52:49 +03:00
|
|
|
* name `resolve` is appended, and can be accessed
|
2018-04-08 20:03:29 +03:00
|
|
|
* through `arguments[arguments.length - 1]`.
|
Bug 1123506 - Evaluate scripts in content with lasting side-effects; r=automatedtester
In order to achieve WebDriver parity, Marionette needs the ability to
evaluate scripts in content space with lasting side-effects. This means
that state modifications should affect behaviour and state of the browsing
context, and such transgress the boundaries of the sandbox.
This patch brings a new script evaluation module that is shared between
code in chrome- and content space. This brings the number of unique
script evaluation implementations in Marionette down from six to one.
evaluate.sandbox provides the main entry-point for execution. It is
compatible with existing Marionette uses of Execute Script and Execute
Async Script commands in Mozilla clients, but also provides a new stateful
sandbox for evaluation that should have lasting side-effects.
It is not expected that Mozilla clients, such as testing/marionette/client
and the Node.js client in Gaia, should have to change as a consequence
of this change.
A substantial change to the script's runtime environment is that many
globals that previously existed are now only exposed whenever needed.
This means for example that Simple Test harness functionality (waitFor,
ok, isnot, is, &c.) is only available when using a sandbox augmented
with a Simple Test harness adapter.
Conversely, this patch does not expose marionetteScriptFinished as a
callback to asynchronous scripts for sandboxes which sandboxName parameter
is undefined, because this is what determines if the script should be
evaluated under WebDriver conformance constraints. In all other cases
where sandboxName _is_ defined, the traditional marionetteScriptFinished
et al. runtime environment is preserved.
MozReview-Commit-ID: 8FZ6rNVImuC
2016-02-26 17:36:39 +03:00
|
|
|
*
|
2018-04-08 20:03:29 +03:00
|
|
|
* The `timeout` option specifies the duration for how long the
|
|
|
|
* script should be allowed to run before it is interrupted and aborted.
|
2017-07-26 15:11:53 +03:00
|
|
|
* An interrupted script will cause a {@link ScriptTimeoutError} to occur.
|
Bug 1123506 - Evaluate scripts in content with lasting side-effects; r=automatedtester
In order to achieve WebDriver parity, Marionette needs the ability to
evaluate scripts in content space with lasting side-effects. This means
that state modifications should affect behaviour and state of the browsing
context, and such transgress the boundaries of the sandbox.
This patch brings a new script evaluation module that is shared between
code in chrome- and content space. This brings the number of unique
script evaluation implementations in Marionette down from six to one.
evaluate.sandbox provides the main entry-point for execution. It is
compatible with existing Marionette uses of Execute Script and Execute
Async Script commands in Mozilla clients, but also provides a new stateful
sandbox for evaluation that should have lasting side-effects.
It is not expected that Mozilla clients, such as testing/marionette/client
and the Node.js client in Gaia, should have to change as a consequence
of this change.
A substantial change to the script's runtime environment is that many
globals that previously existed are now only exposed whenever needed.
This means for example that Simple Test harness functionality (waitFor,
ok, isnot, is, &c.) is only available when using a sandbox augmented
with a Simple Test harness adapter.
Conversely, this patch does not expose marionetteScriptFinished as a
callback to asynchronous scripts for sandboxes which sandboxName parameter
is undefined, because this is what determines if the script should be
evaluated under WebDriver conformance constraints. In all other cases
where sandboxName _is_ defined, the traditional marionetteScriptFinished
et al. runtime environment is preserved.
MozReview-Commit-ID: 8FZ6rNVImuC
2016-02-26 17:36:39 +03:00
|
|
|
*
|
2018-04-08 20:03:29 +03:00
|
|
|
* The `async` option indicates that the script will not return
|
2018-07-08 07:52:49 +03:00
|
|
|
* until the `resolve` callback is invoked,
|
2018-04-08 20:03:29 +03:00
|
|
|
* which is analogous to the last argument of the `arguments` object.
|
Bug 1123506 - Evaluate scripts in content with lasting side-effects; r=automatedtester
In order to achieve WebDriver parity, Marionette needs the ability to
evaluate scripts in content space with lasting side-effects. This means
that state modifications should affect behaviour and state of the browsing
context, and such transgress the boundaries of the sandbox.
This patch brings a new script evaluation module that is shared between
code in chrome- and content space. This brings the number of unique
script evaluation implementations in Marionette down from six to one.
evaluate.sandbox provides the main entry-point for execution. It is
compatible with existing Marionette uses of Execute Script and Execute
Async Script commands in Mozilla clients, but also provides a new stateful
sandbox for evaluation that should have lasting side-effects.
It is not expected that Mozilla clients, such as testing/marionette/client
and the Node.js client in Gaia, should have to change as a consequence
of this change.
A substantial change to the script's runtime environment is that many
globals that previously existed are now only exposed whenever needed.
This means for example that Simple Test harness functionality (waitFor,
ok, isnot, is, &c.) is only available when using a sandbox augmented
with a Simple Test harness adapter.
Conversely, this patch does not expose marionetteScriptFinished as a
callback to asynchronous scripts for sandboxes which sandboxName parameter
is undefined, because this is what determines if the script should be
evaluated under WebDriver conformance constraints. In all other cases
where sandboxName _is_ defined, the traditional marionetteScriptFinished
et al. runtime environment is preserved.
MozReview-Commit-ID: 8FZ6rNVImuC
2016-02-26 17:36:39 +03:00
|
|
|
*
|
2018-04-08 20:03:29 +03:00
|
|
|
* The `file` option is used in error messages to provide information
|
|
|
|
* on the origin script file in the local end.
|
Bug 1123506 - Evaluate scripts in content with lasting side-effects; r=automatedtester
In order to achieve WebDriver parity, Marionette needs the ability to
evaluate scripts in content space with lasting side-effects. This means
that state modifications should affect behaviour and state of the browsing
context, and such transgress the boundaries of the sandbox.
This patch brings a new script evaluation module that is shared between
code in chrome- and content space. This brings the number of unique
script evaluation implementations in Marionette down from six to one.
evaluate.sandbox provides the main entry-point for execution. It is
compatible with existing Marionette uses of Execute Script and Execute
Async Script commands in Mozilla clients, but also provides a new stateful
sandbox for evaluation that should have lasting side-effects.
It is not expected that Mozilla clients, such as testing/marionette/client
and the Node.js client in Gaia, should have to change as a consequence
of this change.
A substantial change to the script's runtime environment is that many
globals that previously existed are now only exposed whenever needed.
This means for example that Simple Test harness functionality (waitFor,
ok, isnot, is, &c.) is only available when using a sandbox augmented
with a Simple Test harness adapter.
Conversely, this patch does not expose marionetteScriptFinished as a
callback to asynchronous scripts for sandboxes which sandboxName parameter
is undefined, because this is what determines if the script should be
evaluated under WebDriver conformance constraints. In all other cases
where sandboxName _is_ defined, the traditional marionetteScriptFinished
et al. runtime environment is preserved.
MozReview-Commit-ID: 8FZ6rNVImuC
2016-02-26 17:36:39 +03:00
|
|
|
*
|
2018-04-08 20:03:29 +03:00
|
|
|
* The `line` option is used in error messages, along with `filename`,
|
|
|
|
* to provide the line number in the origin script file on the local end.
|
Bug 1123506 - Evaluate scripts in content with lasting side-effects; r=automatedtester
In order to achieve WebDriver parity, Marionette needs the ability to
evaluate scripts in content space with lasting side-effects. This means
that state modifications should affect behaviour and state of the browsing
context, and such transgress the boundaries of the sandbox.
This patch brings a new script evaluation module that is shared between
code in chrome- and content space. This brings the number of unique
script evaluation implementations in Marionette down from six to one.
evaluate.sandbox provides the main entry-point for execution. It is
compatible with existing Marionette uses of Execute Script and Execute
Async Script commands in Mozilla clients, but also provides a new stateful
sandbox for evaluation that should have lasting side-effects.
It is not expected that Mozilla clients, such as testing/marionette/client
and the Node.js client in Gaia, should have to change as a consequence
of this change.
A substantial change to the script's runtime environment is that many
globals that previously existed are now only exposed whenever needed.
This means for example that Simple Test harness functionality (waitFor,
ok, isnot, is, &c.) is only available when using a sandbox augmented
with a Simple Test harness adapter.
Conversely, this patch does not expose marionetteScriptFinished as a
callback to asynchronous scripts for sandboxes which sandboxName parameter
is undefined, because this is what determines if the script should be
evaluated under WebDriver conformance constraints. In all other cases
where sandboxName _is_ defined, the traditional marionetteScriptFinished
et al. runtime environment is preserved.
MozReview-Commit-ID: 8FZ6rNVImuC
2016-02-26 17:36:39 +03:00
|
|
|
*
|
2017-07-26 15:11:53 +03:00
|
|
|
* @param {nsISandbox} sb
|
|
|
|
* Sandbox the script will be evaluted in.
|
2017-06-30 02:40:24 +03:00
|
|
|
* @param {string} script
|
2017-07-26 15:11:53 +03:00
|
|
|
* Script to evaluate.
|
Bug 1123506 - Evaluate scripts in content with lasting side-effects; r=automatedtester
In order to achieve WebDriver parity, Marionette needs the ability to
evaluate scripts in content space with lasting side-effects. This means
that state modifications should affect behaviour and state of the browsing
context, and such transgress the boundaries of the sandbox.
This patch brings a new script evaluation module that is shared between
code in chrome- and content space. This brings the number of unique
script evaluation implementations in Marionette down from six to one.
evaluate.sandbox provides the main entry-point for execution. It is
compatible with existing Marionette uses of Execute Script and Execute
Async Script commands in Mozilla clients, but also provides a new stateful
sandbox for evaluation that should have lasting side-effects.
It is not expected that Mozilla clients, such as testing/marionette/client
and the Node.js client in Gaia, should have to change as a consequence
of this change.
A substantial change to the script's runtime environment is that many
globals that previously existed are now only exposed whenever needed.
This means for example that Simple Test harness functionality (waitFor,
ok, isnot, is, &c.) is only available when using a sandbox augmented
with a Simple Test harness adapter.
Conversely, this patch does not expose marionetteScriptFinished as a
callback to asynchronous scripts for sandboxes which sandboxName parameter
is undefined, because this is what determines if the script should be
evaluated under WebDriver conformance constraints. In all other cases
where sandboxName _is_ defined, the traditional marionetteScriptFinished
et al. runtime environment is preserved.
MozReview-Commit-ID: 8FZ6rNVImuC
2016-02-26 17:36:39 +03:00
|
|
|
* @param {Array.<?>=} args
|
|
|
|
* A sequence of arguments to call the script with.
|
2017-07-26 15:11:53 +03:00
|
|
|
* @param {boolean=} [async=false] async
|
|
|
|
* Indicates if the script should return immediately or wait for
|
|
|
|
* the callback to be invoked before returning.
|
|
|
|
* @param {string=} [file="dummy file"] file
|
|
|
|
* File location of the program in the client.
|
|
|
|
* @param {number=} [line=0] line
|
|
|
|
* Line number of th eprogram in the client.
|
|
|
|
* @param {number=} [timeout=DEFAULT_TIMEOUT] timeout
|
|
|
|
* Duration in milliseconds before interrupting the script.
|
Bug 1123506 - Evaluate scripts in content with lasting side-effects; r=automatedtester
In order to achieve WebDriver parity, Marionette needs the ability to
evaluate scripts in content space with lasting side-effects. This means
that state modifications should affect behaviour and state of the browsing
context, and such transgress the boundaries of the sandbox.
This patch brings a new script evaluation module that is shared between
code in chrome- and content space. This brings the number of unique
script evaluation implementations in Marionette down from six to one.
evaluate.sandbox provides the main entry-point for execution. It is
compatible with existing Marionette uses of Execute Script and Execute
Async Script commands in Mozilla clients, but also provides a new stateful
sandbox for evaluation that should have lasting side-effects.
It is not expected that Mozilla clients, such as testing/marionette/client
and the Node.js client in Gaia, should have to change as a consequence
of this change.
A substantial change to the script's runtime environment is that many
globals that previously existed are now only exposed whenever needed.
This means for example that Simple Test harness functionality (waitFor,
ok, isnot, is, &c.) is only available when using a sandbox augmented
with a Simple Test harness adapter.
Conversely, this patch does not expose marionetteScriptFinished as a
callback to asynchronous scripts for sandboxes which sandboxName parameter
is undefined, because this is what determines if the script should be
evaluated under WebDriver conformance constraints. In all other cases
where sandboxName _is_ defined, the traditional marionetteScriptFinished
et al. runtime environment is preserved.
MozReview-Commit-ID: 8FZ6rNVImuC
2016-02-26 17:36:39 +03:00
|
|
|
*
|
|
|
|
* @return {Promise}
|
|
|
|
* A promise that when resolved will give you the return value from
|
|
|
|
* the script. Note that the return value requires serialisation before
|
|
|
|
* it can be sent to the client.
|
|
|
|
*
|
2017-06-30 02:40:24 +03:00
|
|
|
* @throws {JavaScriptError}
|
2017-07-26 15:11:53 +03:00
|
|
|
* If an {@link Error} was thrown whilst evaluating the script.
|
2017-06-30 02:40:24 +03:00
|
|
|
* @throws {ScriptTimeoutError}
|
Bug 1123506 - Evaluate scripts in content with lasting side-effects; r=automatedtester
In order to achieve WebDriver parity, Marionette needs the ability to
evaluate scripts in content space with lasting side-effects. This means
that state modifications should affect behaviour and state of the browsing
context, and such transgress the boundaries of the sandbox.
This patch brings a new script evaluation module that is shared between
code in chrome- and content space. This brings the number of unique
script evaluation implementations in Marionette down from six to one.
evaluate.sandbox provides the main entry-point for execution. It is
compatible with existing Marionette uses of Execute Script and Execute
Async Script commands in Mozilla clients, but also provides a new stateful
sandbox for evaluation that should have lasting side-effects.
It is not expected that Mozilla clients, such as testing/marionette/client
and the Node.js client in Gaia, should have to change as a consequence
of this change.
A substantial change to the script's runtime environment is that many
globals that previously existed are now only exposed whenever needed.
This means for example that Simple Test harness functionality (waitFor,
ok, isnot, is, &c.) is only available when using a sandbox augmented
with a Simple Test harness adapter.
Conversely, this patch does not expose marionetteScriptFinished as a
callback to asynchronous scripts for sandboxes which sandboxName parameter
is undefined, because this is what determines if the script should be
evaluated under WebDriver conformance constraints. In all other cases
where sandboxName _is_ defined, the traditional marionetteScriptFinished
et al. runtime environment is preserved.
MozReview-Commit-ID: 8FZ6rNVImuC
2016-02-26 17:36:39 +03:00
|
|
|
* If the script was interrupted due to script timeout.
|
|
|
|
*/
|
2017-07-26 15:11:53 +03:00
|
|
|
evaluate.sandbox = function(
|
|
|
|
sb,
|
|
|
|
script,
|
|
|
|
args = [],
|
|
|
|
{
|
|
|
|
async = false,
|
|
|
|
file = "dummy file",
|
|
|
|
line = 0,
|
|
|
|
timeout = DEFAULT_TIMEOUT,
|
|
|
|
} = {}
|
|
|
|
) {
|
2019-02-14 16:39:19 +03:00
|
|
|
let unloadHandler;
|
2019-07-29 11:48:50 +03:00
|
|
|
let marionetteSandbox = sandbox.create(sb.window);
|
|
|
|
|
2019-02-14 16:39:19 +03:00
|
|
|
// timeout handler
|
|
|
|
let scriptTimeoutID, timeoutPromise;
|
|
|
|
if (timeout !== null) {
|
|
|
|
timeoutPromise = new Promise((resolve, reject) => {
|
|
|
|
scriptTimeoutID = setTimeout(() => {
|
2020-08-26 11:42:14 +03:00
|
|
|
reject(new error.ScriptTimeoutError(`Timed out after ${timeout} ms`));
|
2019-02-14 16:39:19 +03:00
|
|
|
}, timeout);
|
|
|
|
});
|
|
|
|
}
|
Bug 1123506 - Evaluate scripts in content with lasting side-effects; r=automatedtester
In order to achieve WebDriver parity, Marionette needs the ability to
evaluate scripts in content space with lasting side-effects. This means
that state modifications should affect behaviour and state of the browsing
context, and such transgress the boundaries of the sandbox.
This patch brings a new script evaluation module that is shared between
code in chrome- and content space. This brings the number of unique
script evaluation implementations in Marionette down from six to one.
evaluate.sandbox provides the main entry-point for execution. It is
compatible with existing Marionette uses of Execute Script and Execute
Async Script commands in Mozilla clients, but also provides a new stateful
sandbox for evaluation that should have lasting side-effects.
It is not expected that Mozilla clients, such as testing/marionette/client
and the Node.js client in Gaia, should have to change as a consequence
of this change.
A substantial change to the script's runtime environment is that many
globals that previously existed are now only exposed whenever needed.
This means for example that Simple Test harness functionality (waitFor,
ok, isnot, is, &c.) is only available when using a sandbox augmented
with a Simple Test harness adapter.
Conversely, this patch does not expose marionetteScriptFinished as a
callback to asynchronous scripts for sandboxes which sandboxName parameter
is undefined, because this is what determines if the script should be
evaluated under WebDriver conformance constraints. In all other cases
where sandboxName _is_ defined, the traditional marionetteScriptFinished
et al. runtime environment is preserved.
MozReview-Commit-ID: 8FZ6rNVImuC
2016-02-26 17:36:39 +03:00
|
|
|
|
|
|
|
let promise = new Promise((resolve, reject) => {
|
2016-08-04 20:20:18 +03:00
|
|
|
let src = "";
|
Bug 1123506 - Evaluate scripts in content with lasting side-effects; r=automatedtester
In order to achieve WebDriver parity, Marionette needs the ability to
evaluate scripts in content space with lasting side-effects. This means
that state modifications should affect behaviour and state of the browsing
context, and such transgress the boundaries of the sandbox.
This patch brings a new script evaluation module that is shared between
code in chrome- and content space. This brings the number of unique
script evaluation implementations in Marionette down from six to one.
evaluate.sandbox provides the main entry-point for execution. It is
compatible with existing Marionette uses of Execute Script and Execute
Async Script commands in Mozilla clients, but also provides a new stateful
sandbox for evaluation that should have lasting side-effects.
It is not expected that Mozilla clients, such as testing/marionette/client
and the Node.js client in Gaia, should have to change as a consequence
of this change.
A substantial change to the script's runtime environment is that many
globals that previously existed are now only exposed whenever needed.
This means for example that Simple Test harness functionality (waitFor,
ok, isnot, is, &c.) is only available when using a sandbox augmented
with a Simple Test harness adapter.
Conversely, this patch does not expose marionetteScriptFinished as a
callback to asynchronous scripts for sandboxes which sandboxName parameter
is undefined, because this is what determines if the script should be
evaluated under WebDriver conformance constraints. In all other cases
where sandboxName _is_ defined, the traditional marionetteScriptFinished
et al. runtime environment is preserved.
MozReview-Commit-ID: 8FZ6rNVImuC
2016-02-26 17:36:39 +03:00
|
|
|
sb[COMPLETE] = resolve;
|
2018-04-08 20:03:29 +03:00
|
|
|
sb[ARGUMENTS] = sandbox.cloneInto(args, sb);
|
|
|
|
|
|
|
|
// callback function made private
|
|
|
|
// so that introspection is possible
|
|
|
|
// on the arguments object
|
|
|
|
if (async) {
|
|
|
|
sb[CALLBACK] = sb[COMPLETE];
|
|
|
|
src += `${ARGUMENTS}.push(rv => ${CALLBACK}(rv));`;
|
|
|
|
}
|
|
|
|
|
2018-08-01 17:48:02 +03:00
|
|
|
src += `(function() {
|
|
|
|
${script}
|
|
|
|
}).apply(null, ${ARGUMENTS})`;
|
2018-04-08 20:03:29 +03:00
|
|
|
|
2019-02-14 16:39:19 +03:00
|
|
|
unloadHandler = sandbox.cloneInto(
|
2020-08-26 11:42:14 +03:00
|
|
|
() => reject(new error.JavaScriptError("Document was unloaded")),
|
2019-07-29 11:48:50 +03:00
|
|
|
marionetteSandbox
|
2019-02-14 16:39:19 +03:00
|
|
|
);
|
2019-07-29 11:48:50 +03:00
|
|
|
marionetteSandbox.window.addEventListener("unload", unloadHandler);
|
Bug 1123506 - Evaluate scripts in content with lasting side-effects; r=automatedtester
In order to achieve WebDriver parity, Marionette needs the ability to
evaluate scripts in content space with lasting side-effects. This means
that state modifications should affect behaviour and state of the browsing
context, and such transgress the boundaries of the sandbox.
This patch brings a new script evaluation module that is shared between
code in chrome- and content space. This brings the number of unique
script evaluation implementations in Marionette down from six to one.
evaluate.sandbox provides the main entry-point for execution. It is
compatible with existing Marionette uses of Execute Script and Execute
Async Script commands in Mozilla clients, but also provides a new stateful
sandbox for evaluation that should have lasting side-effects.
It is not expected that Mozilla clients, such as testing/marionette/client
and the Node.js client in Gaia, should have to change as a consequence
of this change.
A substantial change to the script's runtime environment is that many
globals that previously existed are now only exposed whenever needed.
This means for example that Simple Test harness functionality (waitFor,
ok, isnot, is, &c.) is only available when using a sandbox augmented
with a Simple Test harness adapter.
Conversely, this patch does not expose marionetteScriptFinished as a
callback to asynchronous scripts for sandboxes which sandboxName parameter
is undefined, because this is what determines if the script should be
evaluated under WebDriver conformance constraints. In all other cases
where sandboxName _is_ defined, the traditional marionetteScriptFinished
et al. runtime environment is preserved.
MozReview-Commit-ID: 8FZ6rNVImuC
2016-02-26 17:36:39 +03:00
|
|
|
|
2019-02-14 16:39:19 +03:00
|
|
|
let promises = [
|
2019-12-02 20:27:18 +03:00
|
|
|
Cu.evalInSandbox(
|
|
|
|
src,
|
|
|
|
sb,
|
|
|
|
"1.8",
|
|
|
|
file,
|
|
|
|
line,
|
|
|
|
/* enforceFilenameRestrictions */ false
|
|
|
|
),
|
2019-02-14 16:39:19 +03:00
|
|
|
timeoutPromise,
|
|
|
|
];
|
|
|
|
|
|
|
|
// Wait for the immediate result of calling evalInSandbox, or a timeout.
|
|
|
|
// Only resolve the promise if the scriptPromise was resolved and is not
|
|
|
|
// async, because the latter has to call resolve() itself.
|
|
|
|
Promise.race(promises).then(
|
|
|
|
value => {
|
|
|
|
if (!async) {
|
|
|
|
resolve(value);
|
2019-07-05 12:01:24 +03:00
|
|
|
}
|
|
|
|
},
|
|
|
|
err => {
|
2019-02-14 16:39:19 +03:00
|
|
|
reject(err);
|
|
|
|
}
|
|
|
|
);
|
Bug 1123506 - Evaluate scripts in content with lasting side-effects; r=automatedtester
In order to achieve WebDriver parity, Marionette needs the ability to
evaluate scripts in content space with lasting side-effects. This means
that state modifications should affect behaviour and state of the browsing
context, and such transgress the boundaries of the sandbox.
This patch brings a new script evaluation module that is shared between
code in chrome- and content space. This brings the number of unique
script evaluation implementations in Marionette down from six to one.
evaluate.sandbox provides the main entry-point for execution. It is
compatible with existing Marionette uses of Execute Script and Execute
Async Script commands in Mozilla clients, but also provides a new stateful
sandbox for evaluation that should have lasting side-effects.
It is not expected that Mozilla clients, such as testing/marionette/client
and the Node.js client in Gaia, should have to change as a consequence
of this change.
A substantial change to the script's runtime environment is that many
globals that previously existed are now only exposed whenever needed.
This means for example that Simple Test harness functionality (waitFor,
ok, isnot, is, &c.) is only available when using a sandbox augmented
with a Simple Test harness adapter.
Conversely, this patch does not expose marionetteScriptFinished as a
callback to asynchronous scripts for sandboxes which sandboxName parameter
is undefined, because this is what determines if the script should be
evaluated under WebDriver conformance constraints. In all other cases
where sandboxName _is_ defined, the traditional marionetteScriptFinished
et al. runtime environment is preserved.
MozReview-Commit-ID: 8FZ6rNVImuC
2016-02-26 17:36:39 +03:00
|
|
|
});
|
|
|
|
|
2019-02-14 16:39:19 +03:00
|
|
|
// This block is mainly for async scripts, which escape the inner promise
|
|
|
|
// when calling resolve() on their own. The timeout promise will be re-used
|
|
|
|
// to break out after the initially setup timeout.
|
|
|
|
return Promise.race([promise, timeoutPromise])
|
|
|
|
.catch(err => {
|
|
|
|
// Only raise valid errors for both the sync and async scripts.
|
2020-08-26 11:42:14 +03:00
|
|
|
if (err instanceof error.ScriptTimeoutError) {
|
2019-02-14 16:39:19 +03:00
|
|
|
throw err;
|
|
|
|
}
|
2020-08-26 11:42:14 +03:00
|
|
|
throw new error.JavaScriptError(err);
|
2019-02-14 16:38:41 +03:00
|
|
|
})
|
|
|
|
.finally(() => {
|
2016-11-25 20:01:16 +03:00
|
|
|
clearTimeout(scriptTimeoutID);
|
2019-07-29 11:48:50 +03:00
|
|
|
marionetteSandbox.window.removeEventListener("unload", unloadHandler);
|
Bug 1123506 - Evaluate scripts in content with lasting side-effects; r=automatedtester
In order to achieve WebDriver parity, Marionette needs the ability to
evaluate scripts in content space with lasting side-effects. This means
that state modifications should affect behaviour and state of the browsing
context, and such transgress the boundaries of the sandbox.
This patch brings a new script evaluation module that is shared between
code in chrome- and content space. This brings the number of unique
script evaluation implementations in Marionette down from six to one.
evaluate.sandbox provides the main entry-point for execution. It is
compatible with existing Marionette uses of Execute Script and Execute
Async Script commands in Mozilla clients, but also provides a new stateful
sandbox for evaluation that should have lasting side-effects.
It is not expected that Mozilla clients, such as testing/marionette/client
and the Node.js client in Gaia, should have to change as a consequence
of this change.
A substantial change to the script's runtime environment is that many
globals that previously existed are now only exposed whenever needed.
This means for example that Simple Test harness functionality (waitFor,
ok, isnot, is, &c.) is only available when using a sandbox augmented
with a Simple Test harness adapter.
Conversely, this patch does not expose marionetteScriptFinished as a
callback to asynchronous scripts for sandboxes which sandboxName parameter
is undefined, because this is what determines if the script should be
evaluated under WebDriver conformance constraints. In all other cases
where sandboxName _is_ defined, the traditional marionetteScriptFinished
et al. runtime environment is preserved.
MozReview-Commit-ID: 8FZ6rNVImuC
2016-02-26 17:36:39 +03:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2017-05-08 19:05:20 +03:00
|
|
|
/**
|
2021-02-14 17:09:22 +03:00
|
|
|
* Convert any web elements in arbitrary objects to a ContentDOMReference by
|
|
|
|
* looking them up in the seen element reference store. For ElementIdentifiers a
|
|
|
|
* new entry in the seen element reference store gets added when running in the
|
2020-10-02 00:13:43 +03:00
|
|
|
* parent process, otherwise ContentDOMReference is used to retrieve the DOM
|
|
|
|
* node.
|
2017-05-08 19:05:20 +03:00
|
|
|
*
|
2017-07-26 15:11:53 +03:00
|
|
|
* @param {Object} obj
|
2020-10-02 00:13:43 +03:00
|
|
|
* Arbitrary object containing web elements or ElementIdentifiers.
|
2021-02-14 17:09:22 +03:00
|
|
|
* @param {element.ReferenceStore=} seenEls
|
2020-10-02 00:13:43 +03:00
|
|
|
* Known element store to look up web elements from. If `seenEls` is an
|
2021-02-14 17:09:22 +03:00
|
|
|
* instance of `element.ReferenceStore`, return WebElement. If `seenEls` is
|
2020-10-02 00:13:43 +03:00
|
|
|
* `undefined` the Element from the ContentDOMReference cache is returned
|
|
|
|
* when executed in the child process, in the parent process the WebElement
|
|
|
|
* is passed-through.
|
2018-09-18 15:51:21 +03:00
|
|
|
* @param {WindowProxy=} win
|
2018-07-06 18:36:19 +03:00
|
|
|
* Current browsing context, if `seenEls` is provided.
|
2017-05-08 19:05:20 +03:00
|
|
|
*
|
2017-07-26 15:11:53 +03:00
|
|
|
* @return {Object}
|
2018-07-06 18:36:19 +03:00
|
|
|
* Same object as provided by `obj` with the web elements
|
2017-07-26 15:11:53 +03:00
|
|
|
* replaced by DOM elements.
|
2017-10-05 19:55:31 +03:00
|
|
|
*
|
|
|
|
* @throws {NoSuchElementError}
|
2021-02-14 17:09:22 +03:00
|
|
|
* If `seenEls` is an `element.ReferenceStore` and the web element reference
|
|
|
|
* has not been seen before.
|
2017-10-05 19:55:31 +03:00
|
|
|
* @throws {StaleElementReferenceError}
|
2021-02-14 17:09:22 +03:00
|
|
|
* If `seenEls` is an `element.ReferenceStore` and the element has gone
|
|
|
|
* stale, indicating it is no longer attached to the DOM, or its node
|
|
|
|
* document is no longer the active document.
|
2017-05-08 19:05:20 +03:00
|
|
|
*/
|
2018-09-18 15:51:21 +03:00
|
|
|
evaluate.fromJSON = function(obj, seenEls = undefined, win = undefined) {
|
2017-05-08 19:05:20 +03:00
|
|
|
switch (typeof obj) {
|
|
|
|
case "boolean":
|
|
|
|
case "number":
|
|
|
|
case "string":
|
2017-06-30 02:40:24 +03:00
|
|
|
default:
|
2017-05-08 19:05:20 +03:00
|
|
|
return obj;
|
|
|
|
|
|
|
|
case "object":
|
|
|
|
if (obj === null) {
|
|
|
|
return obj;
|
|
|
|
|
|
|
|
// arrays
|
2017-06-30 02:40:24 +03:00
|
|
|
} else if (Array.isArray(obj)) {
|
2018-09-18 15:51:21 +03:00
|
|
|
return obj.map(e => evaluate.fromJSON(e, seenEls, win));
|
2017-05-08 19:05:20 +03:00
|
|
|
|
2020-10-02 00:13:43 +03:00
|
|
|
// ElementIdentifier and ReferenceStore (used by JSWindowActor)
|
|
|
|
} else if (WebElement.isReference(obj.webElRef)) {
|
|
|
|
if (seenEls instanceof element.ReferenceStore) {
|
|
|
|
// Parent: Store web element reference in the cache
|
|
|
|
return seenEls.add(obj);
|
|
|
|
} else if (!seenEls) {
|
|
|
|
// Child: Resolve ElementIdentifier by using ContentDOMReference
|
2020-10-27 19:55:29 +03:00
|
|
|
return element.resolveElement(obj, win);
|
2020-10-02 00:13:43 +03:00
|
|
|
}
|
|
|
|
throw new TypeError("seenEls is not an instance of ReferenceStore");
|
2017-05-08 19:05:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// arbitrary objects
|
2017-06-30 02:40:24 +03:00
|
|
|
let rv = {};
|
|
|
|
for (let prop in obj) {
|
2018-09-18 15:51:21 +03:00
|
|
|
rv[prop] = evaluate.fromJSON(obj[prop], seenEls, win);
|
2017-05-08 19:05:20 +03:00
|
|
|
}
|
2017-06-30 02:40:24 +03:00
|
|
|
return rv;
|
2017-05-08 19:05:20 +03:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2017-11-24 21:21:17 +03:00
|
|
|
* Marshal arbitrary objects to JSON-safe primitives that can be
|
2020-09-24 14:59:48 +03:00
|
|
|
* transported over the Marionette protocol or across processes.
|
2017-05-08 19:05:20 +03:00
|
|
|
*
|
2017-11-24 21:21:17 +03:00
|
|
|
* The marshaling rules are as follows:
|
|
|
|
*
|
2018-07-06 18:36:19 +03:00
|
|
|
* - Primitives are returned as is.
|
2017-11-24 21:21:17 +03:00
|
|
|
*
|
2018-07-06 18:36:19 +03:00
|
|
|
* - Collections, such as `Array<`, `NodeList`, `HTMLCollection`
|
|
|
|
* et al. are expanded to arrays and then recursed.
|
2017-11-24 21:21:17 +03:00
|
|
|
*
|
2021-02-14 17:09:22 +03:00
|
|
|
* - Elements that are not known web elements are added to the
|
|
|
|
* ContentDOMReference registry. Once known, the elements'
|
2020-10-02 00:13:43 +03:00
|
|
|
* associated web element representation is returned.
|
2017-11-24 21:21:17 +03:00
|
|
|
*
|
2020-09-24 14:59:48 +03:00
|
|
|
* - WebElements are transformed to the corresponding ElementIdentifier
|
|
|
|
* for use in the content process, if an `element.ReferenceStore` is provided.
|
|
|
|
*
|
2018-07-06 18:36:19 +03:00
|
|
|
* - Objects with custom JSON representations, i.e. if they have
|
|
|
|
* a callable `toJSON` function, are returned verbatim. This means
|
|
|
|
* their internal integrity _are not_ checked. Be careful.
|
2017-11-24 21:21:17 +03:00
|
|
|
*
|
2018-07-06 18:36:19 +03:00
|
|
|
* - Other arbitrary objects are first tested for cyclic references
|
|
|
|
* and then recursed into.
|
2017-05-08 19:05:20 +03:00
|
|
|
*
|
2017-07-26 15:11:53 +03:00
|
|
|
* @param {Object} obj
|
2017-05-08 19:05:20 +03:00
|
|
|
* Object to be marshaled.
|
2020-09-24 14:59:48 +03:00
|
|
|
*
|
2021-02-14 17:09:22 +03:00
|
|
|
* @param {element.ReferenceStore=} seenEls
|
2017-05-08 19:05:20 +03:00
|
|
|
* Element store to use for lookup of web element references.
|
|
|
|
*
|
2017-07-26 15:11:53 +03:00
|
|
|
* @return {Object}
|
2018-07-06 18:36:19 +03:00
|
|
|
* Same object as provided by `obj` with the elements
|
2017-07-26 15:11:53 +03:00
|
|
|
* replaced by web elements.
|
2017-11-24 21:21:17 +03:00
|
|
|
*
|
|
|
|
* @throws {JavaScriptError}
|
|
|
|
* If an object contains cyclic references.
|
2017-05-08 19:05:20 +03:00
|
|
|
*/
|
2017-06-30 02:40:24 +03:00
|
|
|
evaluate.toJSON = function(obj, seenEls) {
|
2017-05-08 20:57:09 +03:00
|
|
|
const t = Object.prototype.toString.call(obj);
|
2017-05-08 19:05:20 +03:00
|
|
|
|
|
|
|
// null
|
|
|
|
if (t == "[object Undefined]" || t == "[object Null]") {
|
|
|
|
return null;
|
|
|
|
|
2017-10-31 22:57:40 +03:00
|
|
|
// primitives
|
2017-06-30 02:40:24 +03:00
|
|
|
} else if (
|
|
|
|
t == "[object Boolean]" ||
|
|
|
|
t == "[object Number]" ||
|
|
|
|
t == "[object String]"
|
|
|
|
) {
|
2017-05-08 19:05:20 +03:00
|
|
|
return obj;
|
|
|
|
|
|
|
|
// Array, NodeList, HTMLCollection, et al.
|
2017-06-30 02:40:24 +03:00
|
|
|
} else if (element.isCollection(obj)) {
|
2017-11-24 21:21:17 +03:00
|
|
|
assert.acyclic(obj);
|
2017-05-08 19:05:20 +03:00
|
|
|
return [...obj].map(el => evaluate.toJSON(el, seenEls));
|
|
|
|
|
2017-10-05 19:55:52 +03:00
|
|
|
// WebElement
|
|
|
|
} else if (WebElement.isReference(obj)) {
|
2020-10-02 00:13:43 +03:00
|
|
|
// Parent: Convert to ElementIdentifier for use in child actor
|
2021-02-14 17:09:22 +03:00
|
|
|
return seenEls.get(WebElement.fromJSON(obj));
|
2017-10-05 19:55:52 +03:00
|
|
|
|
2020-10-02 00:13:43 +03:00
|
|
|
// ElementIdentifier
|
|
|
|
} else if (WebElement.isReference(obj.webElRef)) {
|
|
|
|
// Parent: Pass-through ElementIdentifiers to the child
|
2021-02-14 17:09:22 +03:00
|
|
|
return obj;
|
2020-10-02 00:13:43 +03:00
|
|
|
|
2017-11-24 21:21:17 +03:00
|
|
|
// Element (HTMLElement, SVGElement, XULElement, et al.)
|
2017-10-17 16:53:42 +03:00
|
|
|
} else if (element.isElement(obj)) {
|
2020-10-02 00:13:43 +03:00
|
|
|
// Parent
|
|
|
|
if (seenEls instanceof element.ReferenceStore) {
|
|
|
|
throw new TypeError(`ReferenceStore can't be used with Element`);
|
|
|
|
}
|
|
|
|
|
|
|
|
// If no storage has been specified assume we are in a child process.
|
|
|
|
// Evaluation of code will take place in mutable sandboxes, which are
|
|
|
|
// created to waive xrays by default. As such DOM nodes have to be unwaived
|
|
|
|
// before accessing the ownerGlobal is possible, which is needed by
|
|
|
|
// ContentDOMReference.
|
|
|
|
return element.getElementId(Cu.unwaiveXrays(obj));
|
2017-05-08 19:05:20 +03:00
|
|
|
|
2017-05-08 20:57:09 +03:00
|
|
|
// custom JSON representation
|
2017-07-25 21:15:41 +03:00
|
|
|
} else if (typeof obj.toJSON == "function") {
|
2017-05-08 20:57:09 +03:00
|
|
|
let unsafeJSON = obj.toJSON();
|
|
|
|
return evaluate.toJSON(unsafeJSON, seenEls);
|
|
|
|
}
|
|
|
|
|
2017-05-08 19:05:20 +03:00
|
|
|
// arbitrary objects + files
|
2017-06-28 21:22:29 +03:00
|
|
|
let rv = {};
|
|
|
|
for (let prop in obj) {
|
2017-11-24 21:21:17 +03:00
|
|
|
assert.acyclic(obj[prop]);
|
|
|
|
|
2017-06-28 21:22:29 +03:00
|
|
|
try {
|
|
|
|
rv[prop] = evaluate.toJSON(obj[prop], seenEls);
|
|
|
|
} catch (e) {
|
|
|
|
if (e.result == Cr.NS_ERROR_NOT_IMPLEMENTED) {
|
2020-09-08 21:28:44 +03:00
|
|
|
logger.debug(`Skipping ${prop}: ${e.message}`);
|
2017-06-28 21:22:29 +03:00
|
|
|
} else {
|
|
|
|
throw e;
|
2017-05-08 19:05:20 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-06-30 02:40:24 +03:00
|
|
|
return rv;
|
2017-05-08 19:05:20 +03:00
|
|
|
};
|
|
|
|
|
2018-07-06 20:35:21 +03:00
|
|
|
/**
|
|
|
|
* Tests if an arbitrary object is cyclic.
|
|
|
|
*
|
2018-07-06 22:08:37 +03:00
|
|
|
* Element prototypes are by definition acyclic, even when they
|
|
|
|
* contain cyclic references. This is because `evaluate.toJSON`
|
|
|
|
* ensures they are marshaled as web elements.
|
|
|
|
*
|
|
|
|
* @param {*} value
|
2018-07-06 20:35:21 +03:00
|
|
|
* Object to test for cyclical references.
|
|
|
|
*
|
|
|
|
* @return {boolean}
|
|
|
|
* True if object is cyclic, false otherwise.
|
|
|
|
*/
|
2018-07-25 20:42:07 +03:00
|
|
|
evaluate.isCyclic = function(value, stack = []) {
|
2018-07-06 22:08:37 +03:00
|
|
|
let t = Object.prototype.toString.call(value);
|
|
|
|
|
|
|
|
// null
|
|
|
|
if (t == "[object Undefined]" || t == "[object Null]") {
|
2018-07-06 20:35:21 +03:00
|
|
|
return false;
|
2018-07-06 22:08:37 +03:00
|
|
|
|
|
|
|
// primitives
|
|
|
|
} else if (
|
|
|
|
t == "[object Boolean]" ||
|
|
|
|
t == "[object Number]" ||
|
|
|
|
t == "[object String]"
|
|
|
|
) {
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// HTMLElement, SVGElement, XULElement, et al.
|
|
|
|
} else if (element.isElement(value)) {
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Array, NodeList, HTMLCollection, et al.
|
|
|
|
} else if (element.isCollection(value)) {
|
|
|
|
if (stack.includes(value)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
stack.push(value);
|
|
|
|
|
|
|
|
for (let i = 0; i < value.length; i++) {
|
2018-07-25 20:42:07 +03:00
|
|
|
if (evaluate.isCyclic(value[i], stack)) {
|
2018-07-06 22:08:37 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
stack.pop();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// arbitrary objects
|
|
|
|
if (stack.includes(value)) {
|
2018-07-06 20:35:21 +03:00
|
|
|
return true;
|
|
|
|
}
|
2018-07-06 22:08:37 +03:00
|
|
|
stack.push(value);
|
|
|
|
|
|
|
|
for (let prop in value) {
|
2018-07-25 20:42:07 +03:00
|
|
|
if (evaluate.isCyclic(value[prop], stack)) {
|
2018-07-06 22:08:37 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
stack.pop();
|
|
|
|
return false;
|
2018-07-25 20:42:07 +03:00
|
|
|
};
|
2018-07-06 20:35:21 +03:00
|
|
|
|
2017-07-03 10:38:21 +03:00
|
|
|
/**
|
2018-07-06 18:36:19 +03:00
|
|
|
* `Cu.isDeadWrapper` does not return true for a dead sandbox that
|
|
|
|
* was assosciated with and extension popup. This provides a way to
|
|
|
|
* still test for a dead object.
|
2017-07-03 10:38:21 +03:00
|
|
|
*
|
2017-07-26 15:11:53 +03:00
|
|
|
* @param {Object} obj
|
2017-07-03 10:38:21 +03:00
|
|
|
* A potentially dead object.
|
|
|
|
* @param {string} prop
|
|
|
|
* Name of a property on the object.
|
|
|
|
*
|
|
|
|
* @returns {boolean}
|
2017-07-26 15:11:53 +03:00
|
|
|
* True if <var>obj</var> is dead, false otherwise.
|
2017-07-03 10:38:21 +03:00
|
|
|
*/
|
|
|
|
evaluate.isDead = function(obj, prop) {
|
|
|
|
try {
|
|
|
|
obj[prop];
|
|
|
|
} catch (e) {
|
|
|
|
if (e.message.includes("dead object")) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
Bug 1123506 - Evaluate scripts in content with lasting side-effects; r=automatedtester
In order to achieve WebDriver parity, Marionette needs the ability to
evaluate scripts in content space with lasting side-effects. This means
that state modifications should affect behaviour and state of the browsing
context, and such transgress the boundaries of the sandbox.
This patch brings a new script evaluation module that is shared between
code in chrome- and content space. This brings the number of unique
script evaluation implementations in Marionette down from six to one.
evaluate.sandbox provides the main entry-point for execution. It is
compatible with existing Marionette uses of Execute Script and Execute
Async Script commands in Mozilla clients, but also provides a new stateful
sandbox for evaluation that should have lasting side-effects.
It is not expected that Mozilla clients, such as testing/marionette/client
and the Node.js client in Gaia, should have to change as a consequence
of this change.
A substantial change to the script's runtime environment is that many
globals that previously existed are now only exposed whenever needed.
This means for example that Simple Test harness functionality (waitFor,
ok, isnot, is, &c.) is only available when using a sandbox augmented
with a Simple Test harness adapter.
Conversely, this patch does not expose marionetteScriptFinished as a
callback to asynchronous scripts for sandboxes which sandboxName parameter
is undefined, because this is what determines if the script should be
evaluated under WebDriver conformance constraints. In all other cases
where sandboxName _is_ defined, the traditional marionetteScriptFinished
et al. runtime environment is preserved.
MozReview-Commit-ID: 8FZ6rNVImuC
2016-02-26 17:36:39 +03:00
|
|
|
this.sandbox = {};
|
|
|
|
|
2016-12-11 05:15:53 +03:00
|
|
|
/**
|
|
|
|
* Provides a safe way to take an object defined in a privileged scope and
|
|
|
|
* create a structured clone of it in a less-privileged scope. It returns
|
|
|
|
* a reference to the clone.
|
|
|
|
*
|
2018-07-06 18:36:19 +03:00
|
|
|
* Unlike for {@link Components.utils.cloneInto}, `obj` may contain
|
|
|
|
* functions and DOM elements.
|
2016-12-11 05:15:53 +03:00
|
|
|
*/
|
2017-06-30 02:40:24 +03:00
|
|
|
sandbox.cloneInto = function(obj, sb) {
|
2016-12-11 05:15:53 +03:00
|
|
|
return Cu.cloneInto(obj, sb, { cloneFunctions: true, wrapReflectors: true });
|
|
|
|
};
|
|
|
|
|
Bug 1123506 - Evaluate scripts in content with lasting side-effects; r=automatedtester
In order to achieve WebDriver parity, Marionette needs the ability to
evaluate scripts in content space with lasting side-effects. This means
that state modifications should affect behaviour and state of the browsing
context, and such transgress the boundaries of the sandbox.
This patch brings a new script evaluation module that is shared between
code in chrome- and content space. This brings the number of unique
script evaluation implementations in Marionette down from six to one.
evaluate.sandbox provides the main entry-point for execution. It is
compatible with existing Marionette uses of Execute Script and Execute
Async Script commands in Mozilla clients, but also provides a new stateful
sandbox for evaluation that should have lasting side-effects.
It is not expected that Mozilla clients, such as testing/marionette/client
and the Node.js client in Gaia, should have to change as a consequence
of this change.
A substantial change to the script's runtime environment is that many
globals that previously existed are now only exposed whenever needed.
This means for example that Simple Test harness functionality (waitFor,
ok, isnot, is, &c.) is only available when using a sandbox augmented
with a Simple Test harness adapter.
Conversely, this patch does not expose marionetteScriptFinished as a
callback to asynchronous scripts for sandboxes which sandboxName parameter
is undefined, because this is what determines if the script should be
evaluated under WebDriver conformance constraints. In all other cases
where sandboxName _is_ defined, the traditional marionetteScriptFinished
et al. runtime environment is preserved.
MozReview-Commit-ID: 8FZ6rNVImuC
2016-02-26 17:36:39 +03:00
|
|
|
/**
|
2018-07-06 18:36:19 +03:00
|
|
|
* Augment given sandbox by an adapter that has an `exports` map
|
|
|
|
* property, or a normal map, of function names and function references.
|
Bug 1123506 - Evaluate scripts in content with lasting side-effects; r=automatedtester
In order to achieve WebDriver parity, Marionette needs the ability to
evaluate scripts in content space with lasting side-effects. This means
that state modifications should affect behaviour and state of the browsing
context, and such transgress the boundaries of the sandbox.
This patch brings a new script evaluation module that is shared between
code in chrome- and content space. This brings the number of unique
script evaluation implementations in Marionette down from six to one.
evaluate.sandbox provides the main entry-point for execution. It is
compatible with existing Marionette uses of Execute Script and Execute
Async Script commands in Mozilla clients, but also provides a new stateful
sandbox for evaluation that should have lasting side-effects.
It is not expected that Mozilla clients, such as testing/marionette/client
and the Node.js client in Gaia, should have to change as a consequence
of this change.
A substantial change to the script's runtime environment is that many
globals that previously existed are now only exposed whenever needed.
This means for example that Simple Test harness functionality (waitFor,
ok, isnot, is, &c.) is only available when using a sandbox augmented
with a Simple Test harness adapter.
Conversely, this patch does not expose marionetteScriptFinished as a
callback to asynchronous scripts for sandboxes which sandboxName parameter
is undefined, because this is what determines if the script should be
evaluated under WebDriver conformance constraints. In all other cases
where sandboxName _is_ defined, the traditional marionetteScriptFinished
et al. runtime environment is preserved.
MozReview-Commit-ID: 8FZ6rNVImuC
2016-02-26 17:36:39 +03:00
|
|
|
*
|
2017-06-30 02:40:24 +03:00
|
|
|
* @param {Sandbox} sb
|
Bug 1123506 - Evaluate scripts in content with lasting side-effects; r=automatedtester
In order to achieve WebDriver parity, Marionette needs the ability to
evaluate scripts in content space with lasting side-effects. This means
that state modifications should affect behaviour and state of the browsing
context, and such transgress the boundaries of the sandbox.
This patch brings a new script evaluation module that is shared between
code in chrome- and content space. This brings the number of unique
script evaluation implementations in Marionette down from six to one.
evaluate.sandbox provides the main entry-point for execution. It is
compatible with existing Marionette uses of Execute Script and Execute
Async Script commands in Mozilla clients, but also provides a new stateful
sandbox for evaluation that should have lasting side-effects.
It is not expected that Mozilla clients, such as testing/marionette/client
and the Node.js client in Gaia, should have to change as a consequence
of this change.
A substantial change to the script's runtime environment is that many
globals that previously existed are now only exposed whenever needed.
This means for example that Simple Test harness functionality (waitFor,
ok, isnot, is, &c.) is only available when using a sandbox augmented
with a Simple Test harness adapter.
Conversely, this patch does not expose marionetteScriptFinished as a
callback to asynchronous scripts for sandboxes which sandboxName parameter
is undefined, because this is what determines if the script should be
evaluated under WebDriver conformance constraints. In all other cases
where sandboxName _is_ defined, the traditional marionetteScriptFinished
et al. runtime environment is preserved.
MozReview-Commit-ID: 8FZ6rNVImuC
2016-02-26 17:36:39 +03:00
|
|
|
* The sandbox to augment.
|
|
|
|
* @param {Object} adapter
|
2018-07-06 18:36:19 +03:00
|
|
|
* Object that holds an `exports` property, or a map, of function
|
|
|
|
* names and function references.
|
Bug 1123506 - Evaluate scripts in content with lasting side-effects; r=automatedtester
In order to achieve WebDriver parity, Marionette needs the ability to
evaluate scripts in content space with lasting side-effects. This means
that state modifications should affect behaviour and state of the browsing
context, and such transgress the boundaries of the sandbox.
This patch brings a new script evaluation module that is shared between
code in chrome- and content space. This brings the number of unique
script evaluation implementations in Marionette down from six to one.
evaluate.sandbox provides the main entry-point for execution. It is
compatible with existing Marionette uses of Execute Script and Execute
Async Script commands in Mozilla clients, but also provides a new stateful
sandbox for evaluation that should have lasting side-effects.
It is not expected that Mozilla clients, such as testing/marionette/client
and the Node.js client in Gaia, should have to change as a consequence
of this change.
A substantial change to the script's runtime environment is that many
globals that previously existed are now only exposed whenever needed.
This means for example that Simple Test harness functionality (waitFor,
ok, isnot, is, &c.) is only available when using a sandbox augmented
with a Simple Test harness adapter.
Conversely, this patch does not expose marionetteScriptFinished as a
callback to asynchronous scripts for sandboxes which sandboxName parameter
is undefined, because this is what determines if the script should be
evaluated under WebDriver conformance constraints. In all other cases
where sandboxName _is_ defined, the traditional marionetteScriptFinished
et al. runtime environment is preserved.
MozReview-Commit-ID: 8FZ6rNVImuC
2016-02-26 17:36:39 +03:00
|
|
|
*
|
|
|
|
* @return {Sandbox}
|
|
|
|
* The augmented sandbox.
|
|
|
|
*/
|
2017-06-30 02:40:24 +03:00
|
|
|
sandbox.augment = function(sb, adapter) {
|
Bug 1123506 - Evaluate scripts in content with lasting side-effects; r=automatedtester
In order to achieve WebDriver parity, Marionette needs the ability to
evaluate scripts in content space with lasting side-effects. This means
that state modifications should affect behaviour and state of the browsing
context, and such transgress the boundaries of the sandbox.
This patch brings a new script evaluation module that is shared between
code in chrome- and content space. This brings the number of unique
script evaluation implementations in Marionette down from six to one.
evaluate.sandbox provides the main entry-point for execution. It is
compatible with existing Marionette uses of Execute Script and Execute
Async Script commands in Mozilla clients, but also provides a new stateful
sandbox for evaluation that should have lasting side-effects.
It is not expected that Mozilla clients, such as testing/marionette/client
and the Node.js client in Gaia, should have to change as a consequence
of this change.
A substantial change to the script's runtime environment is that many
globals that previously existed are now only exposed whenever needed.
This means for example that Simple Test harness functionality (waitFor,
ok, isnot, is, &c.) is only available when using a sandbox augmented
with a Simple Test harness adapter.
Conversely, this patch does not expose marionetteScriptFinished as a
callback to asynchronous scripts for sandboxes which sandboxName parameter
is undefined, because this is what determines if the script should be
evaluated under WebDriver conformance constraints. In all other cases
where sandboxName _is_ defined, the traditional marionetteScriptFinished
et al. runtime environment is preserved.
MozReview-Commit-ID: 8FZ6rNVImuC
2016-02-26 17:36:39 +03:00
|
|
|
function* entries(obj) {
|
2017-06-30 02:40:24 +03:00
|
|
|
for (let key of Object.keys(obj)) {
|
|
|
|
yield [key, obj[key]];
|
|
|
|
}
|
Bug 1123506 - Evaluate scripts in content with lasting side-effects; r=automatedtester
In order to achieve WebDriver parity, Marionette needs the ability to
evaluate scripts in content space with lasting side-effects. This means
that state modifications should affect behaviour and state of the browsing
context, and such transgress the boundaries of the sandbox.
This patch brings a new script evaluation module that is shared between
code in chrome- and content space. This brings the number of unique
script evaluation implementations in Marionette down from six to one.
evaluate.sandbox provides the main entry-point for execution. It is
compatible with existing Marionette uses of Execute Script and Execute
Async Script commands in Mozilla clients, but also provides a new stateful
sandbox for evaluation that should have lasting side-effects.
It is not expected that Mozilla clients, such as testing/marionette/client
and the Node.js client in Gaia, should have to change as a consequence
of this change.
A substantial change to the script's runtime environment is that many
globals that previously existed are now only exposed whenever needed.
This means for example that Simple Test harness functionality (waitFor,
ok, isnot, is, &c.) is only available when using a sandbox augmented
with a Simple Test harness adapter.
Conversely, this patch does not expose marionetteScriptFinished as a
callback to asynchronous scripts for sandboxes which sandboxName parameter
is undefined, because this is what determines if the script should be
evaluated under WebDriver conformance constraints. In all other cases
where sandboxName _is_ defined, the traditional marionetteScriptFinished
et al. runtime environment is preserved.
MozReview-Commit-ID: 8FZ6rNVImuC
2016-02-26 17:36:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
let funcs = adapter.exports || entries(adapter);
|
|
|
|
for (let [name, func] of funcs) {
|
|
|
|
sb[name] = func;
|
|
|
|
}
|
|
|
|
|
|
|
|
return sb;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a sandbox.
|
|
|
|
*
|
2018-09-18 15:51:21 +03:00
|
|
|
* @param {Window} win
|
Bug 1123506 - Evaluate scripts in content with lasting side-effects; r=automatedtester
In order to achieve WebDriver parity, Marionette needs the ability to
evaluate scripts in content space with lasting side-effects. This means
that state modifications should affect behaviour and state of the browsing
context, and such transgress the boundaries of the sandbox.
This patch brings a new script evaluation module that is shared between
code in chrome- and content space. This brings the number of unique
script evaluation implementations in Marionette down from six to one.
evaluate.sandbox provides the main entry-point for execution. It is
compatible with existing Marionette uses of Execute Script and Execute
Async Script commands in Mozilla clients, but also provides a new stateful
sandbox for evaluation that should have lasting side-effects.
It is not expected that Mozilla clients, such as testing/marionette/client
and the Node.js client in Gaia, should have to change as a consequence
of this change.
A substantial change to the script's runtime environment is that many
globals that previously existed are now only exposed whenever needed.
This means for example that Simple Test harness functionality (waitFor,
ok, isnot, is, &c.) is only available when using a sandbox augmented
with a Simple Test harness adapter.
Conversely, this patch does not expose marionetteScriptFinished as a
callback to asynchronous scripts for sandboxes which sandboxName parameter
is undefined, because this is what determines if the script should be
evaluated under WebDriver conformance constraints. In all other cases
where sandboxName _is_ defined, the traditional marionetteScriptFinished
et al. runtime environment is preserved.
MozReview-Commit-ID: 8FZ6rNVImuC
2016-02-26 17:36:39 +03:00
|
|
|
* The DOM Window object.
|
|
|
|
* @param {nsIPrincipal=} principal
|
|
|
|
* An optional, custom principal to prefer over the Window. Useful if
|
|
|
|
* you need elevated security permissions.
|
|
|
|
*
|
|
|
|
* @return {Sandbox}
|
|
|
|
* The created sandbox.
|
|
|
|
*/
|
2018-09-18 15:51:21 +03:00
|
|
|
sandbox.create = function(win, principal = null, opts = {}) {
|
|
|
|
let p = principal || win;
|
Bug 1123506 - Evaluate scripts in content with lasting side-effects; r=automatedtester
In order to achieve WebDriver parity, Marionette needs the ability to
evaluate scripts in content space with lasting side-effects. This means
that state modifications should affect behaviour and state of the browsing
context, and such transgress the boundaries of the sandbox.
This patch brings a new script evaluation module that is shared between
code in chrome- and content space. This brings the number of unique
script evaluation implementations in Marionette down from six to one.
evaluate.sandbox provides the main entry-point for execution. It is
compatible with existing Marionette uses of Execute Script and Execute
Async Script commands in Mozilla clients, but also provides a new stateful
sandbox for evaluation that should have lasting side-effects.
It is not expected that Mozilla clients, such as testing/marionette/client
and the Node.js client in Gaia, should have to change as a consequence
of this change.
A substantial change to the script's runtime environment is that many
globals that previously existed are now only exposed whenever needed.
This means for example that Simple Test harness functionality (waitFor,
ok, isnot, is, &c.) is only available when using a sandbox augmented
with a Simple Test harness adapter.
Conversely, this patch does not expose marionetteScriptFinished as a
callback to asynchronous scripts for sandboxes which sandboxName parameter
is undefined, because this is what determines if the script should be
evaluated under WebDriver conformance constraints. In all other cases
where sandboxName _is_ defined, the traditional marionetteScriptFinished
et al. runtime environment is preserved.
MozReview-Commit-ID: 8FZ6rNVImuC
2016-02-26 17:36:39 +03:00
|
|
|
opts = Object.assign(
|
|
|
|
{
|
2018-09-18 15:51:21 +03:00
|
|
|
sameZoneAs: win,
|
|
|
|
sandboxPrototype: win,
|
Bug 1123506 - Evaluate scripts in content with lasting side-effects; r=automatedtester
In order to achieve WebDriver parity, Marionette needs the ability to
evaluate scripts in content space with lasting side-effects. This means
that state modifications should affect behaviour and state of the browsing
context, and such transgress the boundaries of the sandbox.
This patch brings a new script evaluation module that is shared between
code in chrome- and content space. This brings the number of unique
script evaluation implementations in Marionette down from six to one.
evaluate.sandbox provides the main entry-point for execution. It is
compatible with existing Marionette uses of Execute Script and Execute
Async Script commands in Mozilla clients, but also provides a new stateful
sandbox for evaluation that should have lasting side-effects.
It is not expected that Mozilla clients, such as testing/marionette/client
and the Node.js client in Gaia, should have to change as a consequence
of this change.
A substantial change to the script's runtime environment is that many
globals that previously existed are now only exposed whenever needed.
This means for example that Simple Test harness functionality (waitFor,
ok, isnot, is, &c.) is only available when using a sandbox augmented
with a Simple Test harness adapter.
Conversely, this patch does not expose marionetteScriptFinished as a
callback to asynchronous scripts for sandboxes which sandboxName parameter
is undefined, because this is what determines if the script should be
evaluated under WebDriver conformance constraints. In all other cases
where sandboxName _is_ defined, the traditional marionetteScriptFinished
et al. runtime environment is preserved.
MozReview-Commit-ID: 8FZ6rNVImuC
2016-02-26 17:36:39 +03:00
|
|
|
wantComponents: true,
|
|
|
|
wantXrays: true,
|
2018-12-21 00:15:11 +03:00
|
|
|
wantGlobalProperties: ["ChromeUtils"],
|
Bug 1123506 - Evaluate scripts in content with lasting side-effects; r=automatedtester
In order to achieve WebDriver parity, Marionette needs the ability to
evaluate scripts in content space with lasting side-effects. This means
that state modifications should affect behaviour and state of the browsing
context, and such transgress the boundaries of the sandbox.
This patch brings a new script evaluation module that is shared between
code in chrome- and content space. This brings the number of unique
script evaluation implementations in Marionette down from six to one.
evaluate.sandbox provides the main entry-point for execution. It is
compatible with existing Marionette uses of Execute Script and Execute
Async Script commands in Mozilla clients, but also provides a new stateful
sandbox for evaluation that should have lasting side-effects.
It is not expected that Mozilla clients, such as testing/marionette/client
and the Node.js client in Gaia, should have to change as a consequence
of this change.
A substantial change to the script's runtime environment is that many
globals that previously existed are now only exposed whenever needed.
This means for example that Simple Test harness functionality (waitFor,
ok, isnot, is, &c.) is only available when using a sandbox augmented
with a Simple Test harness adapter.
Conversely, this patch does not expose marionetteScriptFinished as a
callback to asynchronous scripts for sandboxes which sandboxName parameter
is undefined, because this is what determines if the script should be
evaluated under WebDriver conformance constraints. In all other cases
where sandboxName _is_ defined, the traditional marionetteScriptFinished
et al. runtime environment is preserved.
MozReview-Commit-ID: 8FZ6rNVImuC
2016-02-26 17:36:39 +03:00
|
|
|
},
|
|
|
|
opts
|
|
|
|
);
|
|
|
|
return new Cu.Sandbox(p, opts);
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a mutable sandbox, where changes to the global scope
|
|
|
|
* will have lasting side-effects.
|
|
|
|
*
|
2018-09-18 15:51:21 +03:00
|
|
|
* @param {Window} win
|
Bug 1123506 - Evaluate scripts in content with lasting side-effects; r=automatedtester
In order to achieve WebDriver parity, Marionette needs the ability to
evaluate scripts in content space with lasting side-effects. This means
that state modifications should affect behaviour and state of the browsing
context, and such transgress the boundaries of the sandbox.
This patch brings a new script evaluation module that is shared between
code in chrome- and content space. This brings the number of unique
script evaluation implementations in Marionette down from six to one.
evaluate.sandbox provides the main entry-point for execution. It is
compatible with existing Marionette uses of Execute Script and Execute
Async Script commands in Mozilla clients, but also provides a new stateful
sandbox for evaluation that should have lasting side-effects.
It is not expected that Mozilla clients, such as testing/marionette/client
and the Node.js client in Gaia, should have to change as a consequence
of this change.
A substantial change to the script's runtime environment is that many
globals that previously existed are now only exposed whenever needed.
This means for example that Simple Test harness functionality (waitFor,
ok, isnot, is, &c.) is only available when using a sandbox augmented
with a Simple Test harness adapter.
Conversely, this patch does not expose marionetteScriptFinished as a
callback to asynchronous scripts for sandboxes which sandboxName parameter
is undefined, because this is what determines if the script should be
evaluated under WebDriver conformance constraints. In all other cases
where sandboxName _is_ defined, the traditional marionetteScriptFinished
et al. runtime environment is preserved.
MozReview-Commit-ID: 8FZ6rNVImuC
2016-02-26 17:36:39 +03:00
|
|
|
* The DOM Window object.
|
|
|
|
*
|
|
|
|
* @return {Sandbox}
|
|
|
|
* The created sandbox.
|
|
|
|
*/
|
2018-09-18 15:51:21 +03:00
|
|
|
sandbox.createMutable = function(win) {
|
Bug 1123506 - Evaluate scripts in content with lasting side-effects; r=automatedtester
In order to achieve WebDriver parity, Marionette needs the ability to
evaluate scripts in content space with lasting side-effects. This means
that state modifications should affect behaviour and state of the browsing
context, and such transgress the boundaries of the sandbox.
This patch brings a new script evaluation module that is shared between
code in chrome- and content space. This brings the number of unique
script evaluation implementations in Marionette down from six to one.
evaluate.sandbox provides the main entry-point for execution. It is
compatible with existing Marionette uses of Execute Script and Execute
Async Script commands in Mozilla clients, but also provides a new stateful
sandbox for evaluation that should have lasting side-effects.
It is not expected that Mozilla clients, such as testing/marionette/client
and the Node.js client in Gaia, should have to change as a consequence
of this change.
A substantial change to the script's runtime environment is that many
globals that previously existed are now only exposed whenever needed.
This means for example that Simple Test harness functionality (waitFor,
ok, isnot, is, &c.) is only available when using a sandbox augmented
with a Simple Test harness adapter.
Conversely, this patch does not expose marionetteScriptFinished as a
callback to asynchronous scripts for sandboxes which sandboxName parameter
is undefined, because this is what determines if the script should be
evaluated under WebDriver conformance constraints. In all other cases
where sandboxName _is_ defined, the traditional marionetteScriptFinished
et al. runtime environment is preserved.
MozReview-Commit-ID: 8FZ6rNVImuC
2016-02-26 17:36:39 +03:00
|
|
|
let opts = {
|
|
|
|
wantComponents: false,
|
|
|
|
wantXrays: false,
|
|
|
|
};
|
2018-09-15 01:38:55 +03:00
|
|
|
// Note: We waive Xrays here to match potentially-accidental old behavior.
|
2018-09-18 15:51:21 +03:00
|
|
|
return Cu.waiveXrays(sandbox.create(win, null, opts));
|
Bug 1123506 - Evaluate scripts in content with lasting side-effects; r=automatedtester
In order to achieve WebDriver parity, Marionette needs the ability to
evaluate scripts in content space with lasting side-effects. This means
that state modifications should affect behaviour and state of the browsing
context, and such transgress the boundaries of the sandbox.
This patch brings a new script evaluation module that is shared between
code in chrome- and content space. This brings the number of unique
script evaluation implementations in Marionette down from six to one.
evaluate.sandbox provides the main entry-point for execution. It is
compatible with existing Marionette uses of Execute Script and Execute
Async Script commands in Mozilla clients, but also provides a new stateful
sandbox for evaluation that should have lasting side-effects.
It is not expected that Mozilla clients, such as testing/marionette/client
and the Node.js client in Gaia, should have to change as a consequence
of this change.
A substantial change to the script's runtime environment is that many
globals that previously existed are now only exposed whenever needed.
This means for example that Simple Test harness functionality (waitFor,
ok, isnot, is, &c.) is only available when using a sandbox augmented
with a Simple Test harness adapter.
Conversely, this patch does not expose marionetteScriptFinished as a
callback to asynchronous scripts for sandboxes which sandboxName parameter
is undefined, because this is what determines if the script should be
evaluated under WebDriver conformance constraints. In all other cases
where sandboxName _is_ defined, the traditional marionetteScriptFinished
et al. runtime environment is preserved.
MozReview-Commit-ID: 8FZ6rNVImuC
2016-02-26 17:36:39 +03:00
|
|
|
};
|
|
|
|
|
2018-09-18 15:51:21 +03:00
|
|
|
sandbox.createSystemPrincipal = function(win) {
|
Bug 1123506 - Evaluate scripts in content with lasting side-effects; r=automatedtester
In order to achieve WebDriver parity, Marionette needs the ability to
evaluate scripts in content space with lasting side-effects. This means
that state modifications should affect behaviour and state of the browsing
context, and such transgress the boundaries of the sandbox.
This patch brings a new script evaluation module that is shared between
code in chrome- and content space. This brings the number of unique
script evaluation implementations in Marionette down from six to one.
evaluate.sandbox provides the main entry-point for execution. It is
compatible with existing Marionette uses of Execute Script and Execute
Async Script commands in Mozilla clients, but also provides a new stateful
sandbox for evaluation that should have lasting side-effects.
It is not expected that Mozilla clients, such as testing/marionette/client
and the Node.js client in Gaia, should have to change as a consequence
of this change.
A substantial change to the script's runtime environment is that many
globals that previously existed are now only exposed whenever needed.
This means for example that Simple Test harness functionality (waitFor,
ok, isnot, is, &c.) is only available when using a sandbox augmented
with a Simple Test harness adapter.
Conversely, this patch does not expose marionetteScriptFinished as a
callback to asynchronous scripts for sandboxes which sandboxName parameter
is undefined, because this is what determines if the script should be
evaluated under WebDriver conformance constraints. In all other cases
where sandboxName _is_ defined, the traditional marionetteScriptFinished
et al. runtime environment is preserved.
MozReview-Commit-ID: 8FZ6rNVImuC
2016-02-26 17:36:39 +03:00
|
|
|
let principal = Cc["@mozilla.org/systemprincipal;1"].createInstance(
|
|
|
|
Ci.nsIPrincipal
|
|
|
|
);
|
2018-09-18 15:51:21 +03:00
|
|
|
return sandbox.create(win, principal);
|
Bug 1123506 - Evaluate scripts in content with lasting side-effects; r=automatedtester
In order to achieve WebDriver parity, Marionette needs the ability to
evaluate scripts in content space with lasting side-effects. This means
that state modifications should affect behaviour and state of the browsing
context, and such transgress the boundaries of the sandbox.
This patch brings a new script evaluation module that is shared between
code in chrome- and content space. This brings the number of unique
script evaluation implementations in Marionette down from six to one.
evaluate.sandbox provides the main entry-point for execution. It is
compatible with existing Marionette uses of Execute Script and Execute
Async Script commands in Mozilla clients, but also provides a new stateful
sandbox for evaluation that should have lasting side-effects.
It is not expected that Mozilla clients, such as testing/marionette/client
and the Node.js client in Gaia, should have to change as a consequence
of this change.
A substantial change to the script's runtime environment is that many
globals that previously existed are now only exposed whenever needed.
This means for example that Simple Test harness functionality (waitFor,
ok, isnot, is, &c.) is only available when using a sandbox augmented
with a Simple Test harness adapter.
Conversely, this patch does not expose marionetteScriptFinished as a
callback to asynchronous scripts for sandboxes which sandboxName parameter
is undefined, because this is what determines if the script should be
evaluated under WebDriver conformance constraints. In all other cases
where sandboxName _is_ defined, the traditional marionetteScriptFinished
et al. runtime environment is preserved.
MozReview-Commit-ID: 8FZ6rNVImuC
2016-02-26 17:36:39 +03:00
|
|
|
};
|
|
|
|
|
2018-09-18 15:51:21 +03:00
|
|
|
sandbox.createSimpleTest = function(win, harness) {
|
|
|
|
let sb = sandbox.create(win);
|
Bug 1123506 - Evaluate scripts in content with lasting side-effects; r=automatedtester
In order to achieve WebDriver parity, Marionette needs the ability to
evaluate scripts in content space with lasting side-effects. This means
that state modifications should affect behaviour and state of the browsing
context, and such transgress the boundaries of the sandbox.
This patch brings a new script evaluation module that is shared between
code in chrome- and content space. This brings the number of unique
script evaluation implementations in Marionette down from six to one.
evaluate.sandbox provides the main entry-point for execution. It is
compatible with existing Marionette uses of Execute Script and Execute
Async Script commands in Mozilla clients, but also provides a new stateful
sandbox for evaluation that should have lasting side-effects.
It is not expected that Mozilla clients, such as testing/marionette/client
and the Node.js client in Gaia, should have to change as a consequence
of this change.
A substantial change to the script's runtime environment is that many
globals that previously existed are now only exposed whenever needed.
This means for example that Simple Test harness functionality (waitFor,
ok, isnot, is, &c.) is only available when using a sandbox augmented
with a Simple Test harness adapter.
Conversely, this patch does not expose marionetteScriptFinished as a
callback to asynchronous scripts for sandboxes which sandboxName parameter
is undefined, because this is what determines if the script should be
evaluated under WebDriver conformance constraints. In all other cases
where sandboxName _is_ defined, the traditional marionetteScriptFinished
et al. runtime environment is preserved.
MozReview-Commit-ID: 8FZ6rNVImuC
2016-02-26 17:36:39 +03:00
|
|
|
sb = sandbox.augment(sb, harness);
|
|
|
|
sb[FINISH] = () => sb[COMPLETE](harness.generate_results());
|
|
|
|
return sb;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sandbox storage. When the user requests a sandbox by a specific name,
|
|
|
|
* if one exists in the storage this will be used as long as its window
|
|
|
|
* reference is still valid.
|
2017-07-26 15:11:53 +03:00
|
|
|
*
|
|
|
|
* @memberof evaluate
|
Bug 1123506 - Evaluate scripts in content with lasting side-effects; r=automatedtester
In order to achieve WebDriver parity, Marionette needs the ability to
evaluate scripts in content space with lasting side-effects. This means
that state modifications should affect behaviour and state of the browsing
context, and such transgress the boundaries of the sandbox.
This patch brings a new script evaluation module that is shared between
code in chrome- and content space. This brings the number of unique
script evaluation implementations in Marionette down from six to one.
evaluate.sandbox provides the main entry-point for execution. It is
compatible with existing Marionette uses of Execute Script and Execute
Async Script commands in Mozilla clients, but also provides a new stateful
sandbox for evaluation that should have lasting side-effects.
It is not expected that Mozilla clients, such as testing/marionette/client
and the Node.js client in Gaia, should have to change as a consequence
of this change.
A substantial change to the script's runtime environment is that many
globals that previously existed are now only exposed whenever needed.
This means for example that Simple Test harness functionality (waitFor,
ok, isnot, is, &c.) is only available when using a sandbox augmented
with a Simple Test harness adapter.
Conversely, this patch does not expose marionetteScriptFinished as a
callback to asynchronous scripts for sandboxes which sandboxName parameter
is undefined, because this is what determines if the script should be
evaluated under WebDriver conformance constraints. In all other cases
where sandboxName _is_ defined, the traditional marionetteScriptFinished
et al. runtime environment is preserved.
MozReview-Commit-ID: 8FZ6rNVImuC
2016-02-26 17:36:39 +03:00
|
|
|
*/
|
|
|
|
this.Sandboxes = class {
|
|
|
|
/**
|
|
|
|
* @param {function(): Window} windowFn
|
|
|
|
* A function that returns the references to the current Window
|
|
|
|
* object.
|
|
|
|
*/
|
|
|
|
constructor(windowFn) {
|
|
|
|
this.windowFn_ = windowFn;
|
|
|
|
this.boxes_ = new Map();
|
|
|
|
}
|
|
|
|
|
|
|
|
get window_() {
|
|
|
|
return this.windowFn_();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Factory function for getting a sandbox by name, or failing that,
|
|
|
|
* creating a new one.
|
|
|
|
*
|
|
|
|
* If the sandbox' window does not match the provided window, a new one
|
|
|
|
* will be created.
|
|
|
|
*
|
|
|
|
* @param {string} name
|
|
|
|
* The name of the sandbox to get or create.
|
2017-07-26 15:11:53 +03:00
|
|
|
* @param {boolean=} [fresh=false] fresh
|
Bug 1123506 - Evaluate scripts in content with lasting side-effects; r=automatedtester
In order to achieve WebDriver parity, Marionette needs the ability to
evaluate scripts in content space with lasting side-effects. This means
that state modifications should affect behaviour and state of the browsing
context, and such transgress the boundaries of the sandbox.
This patch brings a new script evaluation module that is shared between
code in chrome- and content space. This brings the number of unique
script evaluation implementations in Marionette down from six to one.
evaluate.sandbox provides the main entry-point for execution. It is
compatible with existing Marionette uses of Execute Script and Execute
Async Script commands in Mozilla clients, but also provides a new stateful
sandbox for evaluation that should have lasting side-effects.
It is not expected that Mozilla clients, such as testing/marionette/client
and the Node.js client in Gaia, should have to change as a consequence
of this change.
A substantial change to the script's runtime environment is that many
globals that previously existed are now only exposed whenever needed.
This means for example that Simple Test harness functionality (waitFor,
ok, isnot, is, &c.) is only available when using a sandbox augmented
with a Simple Test harness adapter.
Conversely, this patch does not expose marionetteScriptFinished as a
callback to asynchronous scripts for sandboxes which sandboxName parameter
is undefined, because this is what determines if the script should be
evaluated under WebDriver conformance constraints. In all other cases
where sandboxName _is_ defined, the traditional marionetteScriptFinished
et al. runtime environment is preserved.
MozReview-Commit-ID: 8FZ6rNVImuC
2016-02-26 17:36:39 +03:00
|
|
|
* Remove old sandbox by name first, if it exists.
|
|
|
|
*
|
|
|
|
* @return {Sandbox}
|
|
|
|
* A used or fresh sandbox.
|
|
|
|
*/
|
|
|
|
get(name = "default", fresh = false) {
|
|
|
|
let sb = this.boxes_.get(name);
|
|
|
|
if (sb) {
|
2017-07-03 10:38:21 +03:00
|
|
|
if (fresh || evaluate.isDead(sb, "window") || sb.window != this.window_) {
|
Bug 1123506 - Evaluate scripts in content with lasting side-effects; r=automatedtester
In order to achieve WebDriver parity, Marionette needs the ability to
evaluate scripts in content space with lasting side-effects. This means
that state modifications should affect behaviour and state of the browsing
context, and such transgress the boundaries of the sandbox.
This patch brings a new script evaluation module that is shared between
code in chrome- and content space. This brings the number of unique
script evaluation implementations in Marionette down from six to one.
evaluate.sandbox provides the main entry-point for execution. It is
compatible with existing Marionette uses of Execute Script and Execute
Async Script commands in Mozilla clients, but also provides a new stateful
sandbox for evaluation that should have lasting side-effects.
It is not expected that Mozilla clients, such as testing/marionette/client
and the Node.js client in Gaia, should have to change as a consequence
of this change.
A substantial change to the script's runtime environment is that many
globals that previously existed are now only exposed whenever needed.
This means for example that Simple Test harness functionality (waitFor,
ok, isnot, is, &c.) is only available when using a sandbox augmented
with a Simple Test harness adapter.
Conversely, this patch does not expose marionetteScriptFinished as a
callback to asynchronous scripts for sandboxes which sandboxName parameter
is undefined, because this is what determines if the script should be
evaluated under WebDriver conformance constraints. In all other cases
where sandboxName _is_ defined, the traditional marionetteScriptFinished
et al. runtime environment is preserved.
MozReview-Commit-ID: 8FZ6rNVImuC
2016-02-26 17:36:39 +03:00
|
|
|
this.boxes_.delete(name);
|
|
|
|
return this.get(name, false);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (name == "system") {
|
|
|
|
sb = sandbox.createSystemPrincipal(this.window_);
|
|
|
|
} else {
|
|
|
|
sb = sandbox.create(this.window_);
|
|
|
|
}
|
|
|
|
this.boxes_.set(name, sb);
|
|
|
|
}
|
|
|
|
return sb;
|
|
|
|
}
|
|
|
|
|
2017-07-26 15:11:53 +03:00
|
|
|
/** Clears cache of sandboxes. */
|
Bug 1123506 - Evaluate scripts in content with lasting side-effects; r=automatedtester
In order to achieve WebDriver parity, Marionette needs the ability to
evaluate scripts in content space with lasting side-effects. This means
that state modifications should affect behaviour and state of the browsing
context, and such transgress the boundaries of the sandbox.
This patch brings a new script evaluation module that is shared between
code in chrome- and content space. This brings the number of unique
script evaluation implementations in Marionette down from six to one.
evaluate.sandbox provides the main entry-point for execution. It is
compatible with existing Marionette uses of Execute Script and Execute
Async Script commands in Mozilla clients, but also provides a new stateful
sandbox for evaluation that should have lasting side-effects.
It is not expected that Mozilla clients, such as testing/marionette/client
and the Node.js client in Gaia, should have to change as a consequence
of this change.
A substantial change to the script's runtime environment is that many
globals that previously existed are now only exposed whenever needed.
This means for example that Simple Test harness functionality (waitFor,
ok, isnot, is, &c.) is only available when using a sandbox augmented
with a Simple Test harness adapter.
Conversely, this patch does not expose marionetteScriptFinished as a
callback to asynchronous scripts for sandboxes which sandboxName parameter
is undefined, because this is what determines if the script should be
evaluated under WebDriver conformance constraints. In all other cases
where sandboxName _is_ defined, the traditional marionetteScriptFinished
et al. runtime environment is preserved.
MozReview-Commit-ID: 8FZ6rNVImuC
2016-02-26 17:36:39 +03:00
|
|
|
clear() {
|
|
|
|
this.boxes_.clear();
|
|
|
|
}
|
|
|
|
};
|