michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: "use strict" michael@0: michael@0: const { LoaderWithHookedConsole } = require("sdk/test/loader"); michael@0: michael@0: exports["test LoaderWithHookedConsole"] = function (assert) { michael@0: let count = 0; michael@0: function onMessage(type, message) { michael@0: switch (count++) { michael@0: case 0: michael@0: assert.equal(type, "log", "got log type"); michael@0: assert.equal(message, "1st", "got log msg"); michael@0: break; michael@0: case 1: michael@0: assert.equal(type, "error", "got error type"); michael@0: assert.equal(message, "2nd", "got error msg"); michael@0: break; michael@0: case 2: michael@0: assert.equal(type, "warn", "got warn type"); michael@0: assert.equal(message, "3rd", "got warn msg"); michael@0: break; michael@0: case 3: michael@0: assert.equal(type, "info", "got info type"); michael@0: assert.equal(message, "4th", "got info msg"); michael@0: break; michael@0: case 4: michael@0: assert.equal(type, "debug", "got debug type"); michael@0: assert.equal(message, "5th", "got debug msg"); michael@0: break; michael@0: case 5: michael@0: assert.equal(type, "exception", "got exception type"); michael@0: assert.equal(message, "6th", "got exception msg"); michael@0: break; michael@0: default: michael@0: assert.fail("Got unexception message: " + i); michael@0: } michael@0: } michael@0: michael@0: let { loader, messages } = LoaderWithHookedConsole(module, onMessage); michael@0: let console = loader.globals.console; michael@0: console.log("1st"); michael@0: console.error("2nd"); michael@0: console.warn("3rd"); michael@0: console.info("4th"); michael@0: console.debug("5th"); michael@0: console.exception("6th"); michael@0: assert.equal(messages.length, 6, "Got all console messages"); michael@0: assert.deepEqual(messages[0], {type: "log", msg: "1st", innerID: null}, "Got log"); michael@0: assert.deepEqual(messages[1], {type: "error", msg: "2nd", innerID: null}, "Got error"); michael@0: assert.deepEqual(messages[2], {type: "warn", msg: "3rd", innerID: null}, "Got warn"); michael@0: assert.deepEqual(messages[3], {type: "info", msg: "4th", innerID: null}, "Got info"); michael@0: assert.deepEqual(messages[4], {type: "debug", msg: "5th", innerID: null}, "Got debug"); michael@0: assert.deepEqual(messages[5], {type: "exception", msg: "6th", innerID: null}, "Got exception"); michael@0: assert.equal(count, 6, "Called for all messages"); michael@0: }; michael@0: michael@0: require("sdk/test").run(exports);