|
1 /* vim:set ts=2 sw=2 sts=2 et: */ |
|
2 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
3 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
5 |
|
6 const TEST_URI = "data:text/html;charset=utf-8,<p>Web Console test for notifications"; |
|
7 |
|
8 function test() { |
|
9 observer.init(); |
|
10 addTab(TEST_URI); |
|
11 browser.addEventListener("load", onLoad, true); |
|
12 } |
|
13 |
|
14 function webConsoleCreated(aID) |
|
15 { |
|
16 Services.obs.removeObserver(observer, "web-console-created"); |
|
17 ok(HUDService.getHudReferenceById(aID), "We have a hud reference"); |
|
18 content.wrappedJSObject.console.log("adding a log message"); |
|
19 } |
|
20 |
|
21 function webConsoleDestroyed(aID) |
|
22 { |
|
23 Services.obs.removeObserver(observer, "web-console-destroyed"); |
|
24 ok(!HUDService.getHudReferenceById(aID), "We do not have a hud reference"); |
|
25 executeSoon(finishTest); |
|
26 } |
|
27 |
|
28 function webConsoleMessage(aID, aNodeID) |
|
29 { |
|
30 Services.obs.removeObserver(observer, "web-console-message-created"); |
|
31 ok(aID, "we have a console ID"); |
|
32 is(typeof aNodeID, "string", "message node id is a string"); |
|
33 executeSoon(closeConsole); |
|
34 } |
|
35 |
|
36 let observer = { |
|
37 |
|
38 QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver]), |
|
39 |
|
40 observe: function observe(aSubject, aTopic, aData) |
|
41 { |
|
42 aSubject = aSubject.QueryInterface(Ci.nsISupportsString); |
|
43 |
|
44 switch(aTopic) { |
|
45 case "web-console-created": |
|
46 webConsoleCreated(aSubject.data); |
|
47 break; |
|
48 case "web-console-destroyed": |
|
49 webConsoleDestroyed(aSubject.data); |
|
50 break; |
|
51 case "web-console-message-created": |
|
52 webConsoleMessage(aSubject, aData); |
|
53 break; |
|
54 default: |
|
55 break; |
|
56 } |
|
57 }, |
|
58 |
|
59 init: function init() |
|
60 { |
|
61 Services.obs.addObserver(this, "web-console-created", false); |
|
62 Services.obs.addObserver(this, "web-console-destroyed", false); |
|
63 Services.obs.addObserver(this, "web-console-message-created", false); |
|
64 } |
|
65 }; |
|
66 |
|
67 function onLoad() { |
|
68 browser.removeEventListener("load", onLoad, true); |
|
69 openConsole(); |
|
70 } |