Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
1 "use strict";
3 Components.utils.import("resource://gre/modules/osfile.jsm");
4 Components.utils.import("resource://gre/modules/Services.jsm");
6 /**
7 * Tests logging by passing OS.Shared.LOG both an object with its own
8 * toString method, and one with the default.
9 */
10 function run_test() {
11 do_test_pending();
12 let messageCount = 0;
14 do_print("Test starting");
16 // Create a console listener.
17 let consoleListener = {
18 observe: function (aMessage) {
19 //Ignore unexpected messages.
20 if (!(aMessage instanceof Components.interfaces.nsIConsoleMessage)) {
21 return;
22 }
23 // This is required, as printing to the |Services.console|
24 // while in the observe function causes an exception.
25 do_execute_soon(function() {
26 do_print("Observing message " + aMessage.message);
27 if (aMessage.message.indexOf("TEST OS") < 0) {
28 return;
29 }
31 ++messageCount;
32 if(messageCount == 1) {
33 do_check_eq(aMessage.message, "TEST OS {\"name\":\"test\"}\n");
34 }
35 if(messageCount == 2) {
36 do_check_eq(aMessage.message, "TEST OS name is test\n");
37 toggleConsoleListener(false);
38 do_test_finished();
39 }
40 });
41 }
42 };
44 // Set/Unset the console listener.
45 function toggleConsoleListener (pref) {
46 do_print("Setting console listener: " + pref);
47 Services.prefs.setBoolPref("toolkit.osfile.log", pref);
48 Services.prefs.setBoolPref("toolkit.osfile.log.redirect", pref);
49 Services.console[pref ? "registerListener" : "unregisterListener"](
50 consoleListener);
51 }
53 toggleConsoleListener(true);
55 let objectDefault = {name: "test"};
56 let CustomToString = function() {
57 this.name = "test";
58 };
59 CustomToString.prototype.toString = function() {
60 return "name is " + this.name;
61 };
62 let objectCustom = new CustomToString();
64 do_print(OS.Shared.LOG.toSource());
66 do_print("Logging 1");
67 OS.Shared.LOG(objectDefault);
69 do_print("Logging 2");
70 OS.Shared.LOG(objectCustom);
71 // Once both messages are observed OS.Shared.DEBUG, and OS.Shared.TEST
72 // are reset to false.
73 }