From 5f8de423f190bbb79a62f804151bc24824fa32d8 Mon Sep 17 00:00:00 2001 From: "Matt A. Tobin" Date: Fri, 2 Feb 2018 04:16:08 -0500 Subject: Add m-esr52 at 52.6.0 --- testing/marionette/logging.js | 75 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 testing/marionette/logging.js (limited to 'testing/marionette/logging.js') 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.>} 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.>} + * 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); + } + } +}; -- cgit v1.2.3