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