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 | Components.utils.import("resource://gre/modules/XPCOMUtils.jsm"); |
michael@0 | 2 | |
michael@0 | 3 | const Cc = Components.classes; |
michael@0 | 4 | const Ci = Components.interfaces; |
michael@0 | 5 | |
michael@0 | 6 | function info(s) { |
michael@0 | 7 | dump("TEST-INFO | test_compmgr_warnings.js | " + s + "\n"); |
michael@0 | 8 | } |
michael@0 | 9 | |
michael@0 | 10 | var gMessagesExpected = [ |
michael@0 | 11 | { line: 2, message: /Malformed CID/, found: false }, |
michael@0 | 12 | { line: 6, message: /re-register/, found: false }, |
michael@0 | 13 | { line: 9, message: /Could not/, found: false }, |
michael@0 | 14 | { line: 2, message: /binary component twice/, found: false }, |
michael@0 | 15 | { line: 3, message: /binary component twice/, found: false }, |
michael@0 | 16 | ]; |
michael@0 | 17 | |
michael@0 | 18 | const kConsoleListener = { |
michael@0 | 19 | QueryInterface: XPCOMUtils.generateQI([Ci.nsIConsoleListener]), |
michael@0 | 20 | |
michael@0 | 21 | observe: function listener_observe(message) { |
michael@0 | 22 | if (!(message instanceof Ci.nsIScriptError)) { |
michael@0 | 23 | info("Not a script error: " + message.message); |
michael@0 | 24 | return; |
michael@0 | 25 | } |
michael@0 | 26 | |
michael@0 | 27 | info("Script error... " + message.sourceName + ":" + message.lineNumber + ": " + message.errorMessage); |
michael@0 | 28 | for each (let expected in gMessagesExpected) { |
michael@0 | 29 | if (message.lineNumber != expected.line) |
michael@0 | 30 | continue; |
michael@0 | 31 | |
michael@0 | 32 | if (!expected.message.test(message.errorMessage)) |
michael@0 | 33 | continue; |
michael@0 | 34 | |
michael@0 | 35 | info("Found expected message: " + expected.message); |
michael@0 | 36 | do_check_false(expected.found); |
michael@0 | 37 | |
michael@0 | 38 | expected.found = true; |
michael@0 | 39 | } |
michael@0 | 40 | } |
michael@0 | 41 | }; |
michael@0 | 42 | |
michael@0 | 43 | function run_deferred_event(fn) { |
michael@0 | 44 | do_test_pending(); |
michael@0 | 45 | Components.classes["@mozilla.org/thread-manager;1"]. |
michael@0 | 46 | getService(Ci.nsIThreadManager).mainThread.dispatch(function() { |
michael@0 | 47 | fn(); |
michael@0 | 48 | do_test_finished(); |
michael@0 | 49 | }, 0); |
michael@0 | 50 | } |
michael@0 | 51 | |
michael@0 | 52 | function run_test() |
michael@0 | 53 | { |
michael@0 | 54 | let cs = Components.classes["@mozilla.org/consoleservice;1"]. |
michael@0 | 55 | getService(Ci.nsIConsoleService); |
michael@0 | 56 | cs.registerListener(kConsoleListener); |
michael@0 | 57 | |
michael@0 | 58 | var manifest = do_get_file('compmgr_warnings.manifest'); |
michael@0 | 59 | Components.manager.QueryInterface(Ci.nsIComponentRegistrar). |
michael@0 | 60 | autoRegister(manifest); |
michael@0 | 61 | manifest = do_get_file('testcomponent.manifest'); |
michael@0 | 62 | Components.manager.autoRegister(manifest); |
michael@0 | 63 | |
michael@0 | 64 | run_deferred_event(function() { |
michael@0 | 65 | cs.unregisterListener(kConsoleListener); |
michael@0 | 66 | |
michael@0 | 67 | for each (let expected in gMessagesExpected) { |
michael@0 | 68 | info("checking " + expected.message); |
michael@0 | 69 | do_check_true(expected.found); |
michael@0 | 70 | } |
michael@0 | 71 | }); |
michael@0 | 72 | } |