|
1 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
2 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
4 |
|
5 "use strict" |
|
6 |
|
7 const { LoaderWithHookedConsole } = require("sdk/test/loader"); |
|
8 |
|
9 exports["test LoaderWithHookedConsole"] = function (assert) { |
|
10 let count = 0; |
|
11 function onMessage(type, message) { |
|
12 switch (count++) { |
|
13 case 0: |
|
14 assert.equal(type, "log", "got log type"); |
|
15 assert.equal(message, "1st", "got log msg"); |
|
16 break; |
|
17 case 1: |
|
18 assert.equal(type, "error", "got error type"); |
|
19 assert.equal(message, "2nd", "got error msg"); |
|
20 break; |
|
21 case 2: |
|
22 assert.equal(type, "warn", "got warn type"); |
|
23 assert.equal(message, "3rd", "got warn msg"); |
|
24 break; |
|
25 case 3: |
|
26 assert.equal(type, "info", "got info type"); |
|
27 assert.equal(message, "4th", "got info msg"); |
|
28 break; |
|
29 case 4: |
|
30 assert.equal(type, "debug", "got debug type"); |
|
31 assert.equal(message, "5th", "got debug msg"); |
|
32 break; |
|
33 case 5: |
|
34 assert.equal(type, "exception", "got exception type"); |
|
35 assert.equal(message, "6th", "got exception msg"); |
|
36 break; |
|
37 default: |
|
38 assert.fail("Got unexception message: " + i); |
|
39 } |
|
40 } |
|
41 |
|
42 let { loader, messages } = LoaderWithHookedConsole(module, onMessage); |
|
43 let console = loader.globals.console; |
|
44 console.log("1st"); |
|
45 console.error("2nd"); |
|
46 console.warn("3rd"); |
|
47 console.info("4th"); |
|
48 console.debug("5th"); |
|
49 console.exception("6th"); |
|
50 assert.equal(messages.length, 6, "Got all console messages"); |
|
51 assert.deepEqual(messages[0], {type: "log", msg: "1st", innerID: null}, "Got log"); |
|
52 assert.deepEqual(messages[1], {type: "error", msg: "2nd", innerID: null}, "Got error"); |
|
53 assert.deepEqual(messages[2], {type: "warn", msg: "3rd", innerID: null}, "Got warn"); |
|
54 assert.deepEqual(messages[3], {type: "info", msg: "4th", innerID: null}, "Got info"); |
|
55 assert.deepEqual(messages[4], {type: "debug", msg: "5th", innerID: null}, "Got debug"); |
|
56 assert.deepEqual(messages[5], {type: "exception", msg: "6th", innerID: null}, "Got exception"); |
|
57 assert.equal(count, 6, "Called for all messages"); |
|
58 }; |
|
59 |
|
60 require("sdk/test").run(exports); |