diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /testing/marionette/logging.js | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip |
Add m-esr52 at 52.6.0
Diffstat (limited to 'testing/marionette/logging.js')
-rw-r--r-- | testing/marionette/logging.js | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/testing/marionette/logging.js b/testing/marionette/logging.js new file mode 100644 index 000000000..d77adfb0c --- /dev/null +++ b/testing/marionette/logging.js @@ -0,0 +1,75 @@ +/* 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); + } + } +}; |