gecko-dev/testing/marionette/logging.js
Andreas Tolfsen 1d15796afc 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-05-09 16:08:17 +01:00

76 lines
1.7 KiB
JavaScript

/* 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";
this.EXPORTED_SYMBOLS = ["logging"];
this.logging = {};
/** Simple logger that is used in Simple Test harness tests. */
logging.ContentLogger = class {
constructor() {
this.logs_ = [];
}
/**
* Append a log entry.
*
* @param {string} message
* Log entry message.
* @param {string=} level
* Severity of entry. Defaults to "INFO".
*/
log(message, level = "INFO") {
let now = (new Date()).toString();
this.logs_.push([level, message, now]);
}
/**
* Append array of log entries.
*
* @param {Array.<Array<string, string, string>>} messages
* List of log entries, that are of the form severity, message,
* and date.
*/
addAll(messages) {
for (let message of messages) {
this.logs_.push(message);
}
}
/**
* Gets current log entries and clears the cache.
*
* @return {Array.<Array<string, string, string>>}
* Log entries of the form severity, message, and date.
*/
get() {
let logs = this.logs_;
this.logs_ = [];
return logs;
}
};
/**
* Adapts an instance of ContentLogger for use in a sandbox. Is consumed
* by sandbox.augment.
*/
logging.Adapter = class {
constructor(logger = null) {
this.logger = logger;
}
get exports() {
return new Map([["log", this.log.bind(this)]]);
}
log(message, level = "INFO") {
dump(`MARIONETTE LOG: ${level}: ${message}\n`);
if (this.logger) {
this.logger.log(message, level);
}
}
};