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 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | Cu.import("resource://gre/modules/Promise.jsm"); |
michael@0 | 6 | |
michael@0 | 7 | let cs = Cc["@mozilla.org/consoleservice;1"]. |
michael@0 | 8 | getService(Ci.nsIConsoleService); |
michael@0 | 9 | let ps = Cc["@mozilla.org/preferences-service;1"]. |
michael@0 | 10 | getService(Ci.nsIPrefService); |
michael@0 | 11 | |
michael@0 | 12 | function makeBuffer(length) { |
michael@0 | 13 | return new Array(length + 1).join('x'); |
michael@0 | 14 | } |
michael@0 | 15 | |
michael@0 | 16 | /** |
michael@0 | 17 | * @resolves |true| if execution proceeded without warning, |
michael@0 | 18 | * |false| if there was a warning. |
michael@0 | 19 | */ |
michael@0 | 20 | function checkWarning(pref, buffer) { |
michael@0 | 21 | let deferred = Promise.defer(); |
michael@0 | 22 | let complete = false; |
michael@0 | 23 | let listener = { |
michael@0 | 24 | observe: function(event) { |
michael@0 | 25 | let message = event.message; |
michael@0 | 26 | if (!(message.startsWith("Warning: attempting to write") |
michael@0 | 27 | && message.contains(pref))) { |
michael@0 | 28 | return; |
michael@0 | 29 | } |
michael@0 | 30 | if (complete) { |
michael@0 | 31 | return; |
michael@0 | 32 | } |
michael@0 | 33 | complete = true; |
michael@0 | 34 | do_print("Warning while setting " + pref); |
michael@0 | 35 | cs.unregisterListener(listener); |
michael@0 | 36 | deferred.resolve(true); |
michael@0 | 37 | } |
michael@0 | 38 | }; |
michael@0 | 39 | do_timeout(1000, function() { |
michael@0 | 40 | if (complete) { |
michael@0 | 41 | return; |
michael@0 | 42 | } |
michael@0 | 43 | complete = true; |
michael@0 | 44 | do_print("No warning while setting " + pref); |
michael@0 | 45 | cs.unregisterListener(listener); |
michael@0 | 46 | deferred.resolve(false); |
michael@0 | 47 | }); |
michael@0 | 48 | cs.registerListener(listener); |
michael@0 | 49 | ps.setCharPref(pref, buffer); |
michael@0 | 50 | return deferred.promise; |
michael@0 | 51 | } |
michael@0 | 52 | |
michael@0 | 53 | function run_test() { |
michael@0 | 54 | run_next_test(); |
michael@0 | 55 | } |
michael@0 | 56 | |
michael@0 | 57 | add_task(function() { |
michael@0 | 58 | // Simple change, shouldn't cause a warning |
michael@0 | 59 | do_print("Checking that a simple change doesn't cause a warning"); |
michael@0 | 60 | let buf = makeBuffer(100); |
michael@0 | 61 | let warned = yield checkWarning("string.accept", buf); |
michael@0 | 62 | do_check_false(warned); |
michael@0 | 63 | |
michael@0 | 64 | // Large change, should cause a warning |
michael@0 | 65 | do_print("Checking that a large change causes a warning"); |
michael@0 | 66 | buf = makeBuffer(32 * 1024); |
michael@0 | 67 | warned = yield checkWarning("string.warn", buf); |
michael@0 | 68 | do_check_true(warned); |
michael@0 | 69 | }); |