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 | |
michael@0 | 6 | const BLOCKLIST_TIMER = "blocklist-background-update-timer"; |
michael@0 | 7 | const PREF_BLOCKLIST_URL = "extensions.blocklist.url"; |
michael@0 | 8 | const PREF_BLOCKLIST_ENABLED = "extensions.blocklist.enabled"; |
michael@0 | 9 | const PREF_APP_DISTRIBUTION = "distribution.id"; |
michael@0 | 10 | const PREF_APP_DISTRIBUTION_VERSION = "distribution.version"; |
michael@0 | 11 | const PREF_APP_UPDATE_CHANNEL = "app.update.channel"; |
michael@0 | 12 | const PREF_GENERAL_USERAGENT_LOCALE = "general.useragent.locale"; |
michael@0 | 13 | const CATEGORY_UPDATE_TIMER = "update-timer"; |
michael@0 | 14 | |
michael@0 | 15 | // Get the HTTP server. |
michael@0 | 16 | Components.utils.import("resource://testing-common/httpd.js"); |
michael@0 | 17 | var testserver; |
michael@0 | 18 | var gOSVersion; |
michael@0 | 19 | var gBlocklist; |
michael@0 | 20 | |
michael@0 | 21 | // This is a replacement for the timer service so we can trigger timers |
michael@0 | 22 | var timerService = { |
michael@0 | 23 | |
michael@0 | 24 | hasTimer: function(id) { |
michael@0 | 25 | var catMan = Components.classes["@mozilla.org/categorymanager;1"] |
michael@0 | 26 | .getService(Components.interfaces.nsICategoryManager); |
michael@0 | 27 | var entries = catMan.enumerateCategory(CATEGORY_UPDATE_TIMER); |
michael@0 | 28 | while (entries.hasMoreElements()) { |
michael@0 | 29 | var entry = entries.getNext().QueryInterface(Components.interfaces.nsISupportsCString).data; |
michael@0 | 30 | var value = catMan.getCategoryEntry(CATEGORY_UPDATE_TIMER, entry); |
michael@0 | 31 | var timerID = value.split(",")[2]; |
michael@0 | 32 | if (id == timerID) { |
michael@0 | 33 | return true; |
michael@0 | 34 | } |
michael@0 | 35 | } |
michael@0 | 36 | return false; |
michael@0 | 37 | }, |
michael@0 | 38 | |
michael@0 | 39 | fireTimer: function(id) { |
michael@0 | 40 | gBlocklist.QueryInterface(Components.interfaces.nsITimerCallback).notify(null); |
michael@0 | 41 | }, |
michael@0 | 42 | |
michael@0 | 43 | QueryInterface: function(iid) { |
michael@0 | 44 | if (iid.equals(Components.interfaces.nsIUpdateTimerManager) |
michael@0 | 45 | || iid.equals(Components.interfaces.nsISupports)) |
michael@0 | 46 | return this; |
michael@0 | 47 | |
michael@0 | 48 | throw Components.results.NS_ERROR_NO_INTERFACE; |
michael@0 | 49 | } |
michael@0 | 50 | }; |
michael@0 | 51 | |
michael@0 | 52 | var TimerServiceFactory = { |
michael@0 | 53 | createInstance: function (outer, iid) { |
michael@0 | 54 | if (outer != null) |
michael@0 | 55 | throw Components.results.NS_ERROR_NO_AGGREGATION; |
michael@0 | 56 | return timerService.QueryInterface(iid); |
michael@0 | 57 | } |
michael@0 | 58 | }; |
michael@0 | 59 | var registrar = Components.manager.QueryInterface(Components.interfaces.nsIComponentRegistrar); |
michael@0 | 60 | registrar.registerFactory(Components.ID("{61189e7a-6b1b-44b8-ac81-f180a6105085}"), "TimerService", |
michael@0 | 61 | "@mozilla.org/updates/timer-manager;1", TimerServiceFactory); |
michael@0 | 62 | |
michael@0 | 63 | function failHandler(metadata, response) { |
michael@0 | 64 | do_throw("Should not have attempted to retrieve the blocklist when it is disabled"); |
michael@0 | 65 | } |
michael@0 | 66 | |
michael@0 | 67 | function pathHandler(metadata, response) { |
michael@0 | 68 | var ABI = "noarch-spidermonkey"; |
michael@0 | 69 | // the blacklist service special-cases ABI for Universal binaries, |
michael@0 | 70 | // so do the same here. |
michael@0 | 71 | if ("@mozilla.org/xpcom/mac-utils;1" in Components.classes) { |
michael@0 | 72 | var macutils = Components.classes["@mozilla.org/xpcom/mac-utils;1"] |
michael@0 | 73 | .getService(Components.interfaces.nsIMacUtils); |
michael@0 | 74 | if (macutils.isUniversalBinary) |
michael@0 | 75 | ABI += "-u-" + macutils.architecturesInBinary; |
michael@0 | 76 | } |
michael@0 | 77 | do_check_eq(metadata.queryString, |
michael@0 | 78 | "xpcshell@tests.mozilla.org&1&XPCShell&1&2007010101&" + |
michael@0 | 79 | "XPCShell_" + ABI + "&locale&updatechannel&" + |
michael@0 | 80 | gOSVersion + "&1.9&distribution&distribution-version"); |
michael@0 | 81 | gBlocklist.observe(null, "quit-application", ""); |
michael@0 | 82 | gBlocklist.observe(null, "xpcom-shutdown", ""); |
michael@0 | 83 | testserver.stop(do_test_finished); |
michael@0 | 84 | } |
michael@0 | 85 | |
michael@0 | 86 | function run_test() { |
michael@0 | 87 | var osVersion; |
michael@0 | 88 | var sysInfo = Components.classes["@mozilla.org/system-info;1"] |
michael@0 | 89 | .getService(Components.interfaces.nsIPropertyBag2); |
michael@0 | 90 | try { |
michael@0 | 91 | osVersion = sysInfo.getProperty("name") + " " + sysInfo.getProperty("version"); |
michael@0 | 92 | if (osVersion) { |
michael@0 | 93 | try { |
michael@0 | 94 | osVersion += " (" + sysInfo.getProperty("secondaryLibrary") + ")"; |
michael@0 | 95 | } |
michael@0 | 96 | catch (e) { |
michael@0 | 97 | } |
michael@0 | 98 | gOSVersion = encodeURIComponent(osVersion); |
michael@0 | 99 | } |
michael@0 | 100 | } |
michael@0 | 101 | catch (e) { |
michael@0 | 102 | } |
michael@0 | 103 | |
michael@0 | 104 | createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9"); |
michael@0 | 105 | |
michael@0 | 106 | testserver = new HttpServer(); |
michael@0 | 107 | testserver.registerPathHandler("/1", failHandler); |
michael@0 | 108 | testserver.registerPathHandler("/2", pathHandler); |
michael@0 | 109 | testserver.start(-1); |
michael@0 | 110 | gPort = testserver.identity.primaryPort; |
michael@0 | 111 | |
michael@0 | 112 | // Initialise the blocklist service |
michael@0 | 113 | gBlocklist = Components.classes["@mozilla.org/extensions/blocklist;1"] |
michael@0 | 114 | .getService(Components.interfaces.nsIBlocklistService) |
michael@0 | 115 | .QueryInterface(Components.interfaces.nsIObserver); |
michael@0 | 116 | gBlocklist.observe(null, "profile-after-change", ""); |
michael@0 | 117 | |
michael@0 | 118 | do_check_true(timerService.hasTimer(BLOCKLIST_TIMER)); |
michael@0 | 119 | |
michael@0 | 120 | do_test_pending(); |
michael@0 | 121 | |
michael@0 | 122 | // This should have no effect as the blocklist is disabled |
michael@0 | 123 | Services.prefs.setCharPref(PREF_BLOCKLIST_URL, "http://localhost:" + gPort + "/1"); |
michael@0 | 124 | Services.prefs.setBoolPref(PREF_BLOCKLIST_ENABLED, false); |
michael@0 | 125 | timerService.fireTimer(BLOCKLIST_TIMER); |
michael@0 | 126 | |
michael@0 | 127 | // Some values have to be on the default branch to work |
michael@0 | 128 | var defaults = Services.prefs.QueryInterface(Components.interfaces.nsIPrefService) |
michael@0 | 129 | .getDefaultBranch(null); |
michael@0 | 130 | defaults.setCharPref(PREF_APP_UPDATE_CHANNEL, "updatechannel"); |
michael@0 | 131 | defaults.setCharPref(PREF_APP_DISTRIBUTION, "distribution"); |
michael@0 | 132 | defaults.setCharPref(PREF_APP_DISTRIBUTION_VERSION, "distribution-version"); |
michael@0 | 133 | defaults.setCharPref(PREF_GENERAL_USERAGENT_LOCALE, "locale"); |
michael@0 | 134 | |
michael@0 | 135 | // This should correctly escape everything |
michael@0 | 136 | Services.prefs.setCharPref(PREF_BLOCKLIST_URL, "http://localhost:" + gPort + "/2?" + |
michael@0 | 137 | "%APP_ID%&%APP_VERSION%&%PRODUCT%&%VERSION%&%BUILD_ID%&" + |
michael@0 | 138 | "%BUILD_TARGET%&%LOCALE%&%CHANNEL%&" + |
michael@0 | 139 | "%OS_VERSION%&%PLATFORM_VERSION%&%DISTRIBUTION%&%DISTRIBUTION_VERSION%"); |
michael@0 | 140 | Services.prefs.setBoolPref(PREF_BLOCKLIST_ENABLED, true); |
michael@0 | 141 | timerService.fireTimer(BLOCKLIST_TIMER); |
michael@0 | 142 | } |