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 PREF_MATCH_OS_LOCALE = "intl.locale.matchOS"; |
michael@0 | 7 | const PREF_SELECTED_LOCALE = "general.useragent.locale"; |
michael@0 | 8 | |
michael@0 | 9 | // Disables security checking our updates which haven't been signed |
michael@0 | 10 | Services.prefs.setBoolPref("extensions.checkUpdateSecurity", false); |
michael@0 | 11 | |
michael@0 | 12 | const Ci = Components.interfaces; |
michael@0 | 13 | const Cu = Components.utils; |
michael@0 | 14 | |
michael@0 | 15 | Cu.import("resource://testing-common/httpd.js"); |
michael@0 | 16 | |
michael@0 | 17 | // This is the data we expect to see sent as part of the update url. |
michael@0 | 18 | var EXPECTED = [ |
michael@0 | 19 | { |
michael@0 | 20 | id: "bug335238_1@tests.mozilla.org", |
michael@0 | 21 | version: "1.3.4", |
michael@0 | 22 | maxAppVersion: "5", |
michael@0 | 23 | status: "userEnabled", |
michael@0 | 24 | appId: "xpcshell@tests.mozilla.org", |
michael@0 | 25 | appVersion: "1", |
michael@0 | 26 | appOs: "XPCShell", |
michael@0 | 27 | appAbi: "noarch-spidermonkey", |
michael@0 | 28 | locale: "en-US", |
michael@0 | 29 | reqVersion: "2" |
michael@0 | 30 | }, |
michael@0 | 31 | { |
michael@0 | 32 | id: "bug335238_2@tests.mozilla.org", |
michael@0 | 33 | version: "28at", |
michael@0 | 34 | maxAppVersion: "7", |
michael@0 | 35 | status: "userDisabled", |
michael@0 | 36 | appId: "xpcshell@tests.mozilla.org", |
michael@0 | 37 | appVersion: "1", |
michael@0 | 38 | appOs: "XPCShell", |
michael@0 | 39 | appAbi: "noarch-spidermonkey", |
michael@0 | 40 | locale: "en-US", |
michael@0 | 41 | reqVersion: "2" |
michael@0 | 42 | }, |
michael@0 | 43 | { |
michael@0 | 44 | id: "bug335238_3@tests.mozilla.org", |
michael@0 | 45 | version: "58", |
michael@0 | 46 | maxAppVersion: "*", |
michael@0 | 47 | status: "userDisabled,softblocked", |
michael@0 | 48 | appId: "xpcshell@tests.mozilla.org", |
michael@0 | 49 | appVersion: "1", |
michael@0 | 50 | appOs: "XPCShell", |
michael@0 | 51 | appAbi: "noarch-spidermonkey", |
michael@0 | 52 | locale: "en-US", |
michael@0 | 53 | reqVersion: "2" |
michael@0 | 54 | }, |
michael@0 | 55 | { |
michael@0 | 56 | id: "bug335238_4@tests.mozilla.org", |
michael@0 | 57 | version: "4", |
michael@0 | 58 | maxAppVersion: "2+", |
michael@0 | 59 | status: "userEnabled,blocklisted", |
michael@0 | 60 | appId: "xpcshell@tests.mozilla.org", |
michael@0 | 61 | appVersion: "1", |
michael@0 | 62 | appOs: "XPCShell", |
michael@0 | 63 | appAbi: "noarch-spidermonkey", |
michael@0 | 64 | locale: "en-US", |
michael@0 | 65 | reqVersion: "2" |
michael@0 | 66 | } |
michael@0 | 67 | ]; |
michael@0 | 68 | |
michael@0 | 69 | var ADDONS = [ |
michael@0 | 70 | {id: "bug335238_1@tests.mozilla.org", |
michael@0 | 71 | addon: "test_bug335238_1"}, |
michael@0 | 72 | {id: "bug335238_2@tests.mozilla.org", |
michael@0 | 73 | addon: "test_bug335238_2"}, |
michael@0 | 74 | {id: "bug335238_3@tests.mozilla.org", |
michael@0 | 75 | addon: "test_bug335238_3"}, |
michael@0 | 76 | {id: "bug335238_4@tests.mozilla.org", |
michael@0 | 77 | addon: "test_bug335238_4"} |
michael@0 | 78 | ]; |
michael@0 | 79 | |
michael@0 | 80 | // This is a replacement for the blocklist service |
michael@0 | 81 | var BlocklistService = { |
michael@0 | 82 | getAddonBlocklistState: function(aAddon, aAppVersion, aToolkitVersion) { |
michael@0 | 83 | if (aAddon.id == "bug335238_3@tests.mozilla.org") |
michael@0 | 84 | return Ci.nsIBlocklistService.STATE_SOFTBLOCKED; |
michael@0 | 85 | if (aAddon.id == "bug335238_4@tests.mozilla.org") |
michael@0 | 86 | return Ci.nsIBlocklistService.STATE_BLOCKED; |
michael@0 | 87 | return Ci.nsIBlocklistService.STATE_NOT_BLOCKED; |
michael@0 | 88 | }, |
michael@0 | 89 | |
michael@0 | 90 | getPluginBlocklistState: function(aPlugin, aVersion, aAppVersion, aToolkitVersion) { |
michael@0 | 91 | return Ci.nsIBlocklistService.STATE_NOT_BLOCKED; |
michael@0 | 92 | }, |
michael@0 | 93 | |
michael@0 | 94 | isAddonBlocklisted: function(aAddon, aAppVersion, aToolkitVersion) { |
michael@0 | 95 | return this.getAddonBlocklistState(aAddon, aAppVersion, aToolkitVersion) == |
michael@0 | 96 | Ci.nsIBlocklistService.STATE_BLOCKED; |
michael@0 | 97 | }, |
michael@0 | 98 | |
michael@0 | 99 | QueryInterface: function(iid) { |
michael@0 | 100 | if (iid.equals(Ci.nsIBlocklistService) |
michael@0 | 101 | || iid.equals(Ci.nsISupports)) |
michael@0 | 102 | return this; |
michael@0 | 103 | |
michael@0 | 104 | throw Components.results.NS_ERROR_NO_INTERFACE; |
michael@0 | 105 | } |
michael@0 | 106 | }; |
michael@0 | 107 | |
michael@0 | 108 | var BlocklistServiceFactory = { |
michael@0 | 109 | createInstance: function (outer, iid) { |
michael@0 | 110 | if (outer != null) |
michael@0 | 111 | throw Components.results.NS_ERROR_NO_AGGREGATION; |
michael@0 | 112 | return BlocklistService.QueryInterface(iid); |
michael@0 | 113 | } |
michael@0 | 114 | }; |
michael@0 | 115 | var registrar = Components.manager.QueryInterface(Ci.nsIComponentRegistrar); |
michael@0 | 116 | registrar.registerFactory(Components.ID("{61189e7a-6b1b-44b8-ac81-f180a6105085}"), "BlocklistService", |
michael@0 | 117 | "@mozilla.org/extensions/blocklist;1", BlocklistServiceFactory); |
michael@0 | 118 | |
michael@0 | 119 | var server; |
michael@0 | 120 | |
michael@0 | 121 | var updateListener = { |
michael@0 | 122 | pendingCount: 0, |
michael@0 | 123 | |
michael@0 | 124 | onUpdateAvailable: function(aAddon) { |
michael@0 | 125 | do_throw("Should not have seen an update for " + aAddon.id); |
michael@0 | 126 | }, |
michael@0 | 127 | |
michael@0 | 128 | onUpdateFinished: function() { |
michael@0 | 129 | if (--this.pendingCount == 0) |
michael@0 | 130 | server.stop(do_test_finished); |
michael@0 | 131 | } |
michael@0 | 132 | } |
michael@0 | 133 | |
michael@0 | 134 | var requestHandler = { |
michael@0 | 135 | handle: function(metadata, response) |
michael@0 | 136 | { |
michael@0 | 137 | var expected = EXPECTED[metadata.path.substring(1)]; |
michael@0 | 138 | var params = metadata.queryString.split("&"); |
michael@0 | 139 | do_check_eq(params.length, 10); |
michael@0 | 140 | for (var k in params) { |
michael@0 | 141 | var pair = params[k].split("="); |
michael@0 | 142 | var name = decodeURIComponent(pair[0]); |
michael@0 | 143 | var value = decodeURIComponent(pair[1]); |
michael@0 | 144 | do_check_eq(expected[name], value); |
michael@0 | 145 | } |
michael@0 | 146 | response.setStatusLine(metadata.httpVersion, 404, "Not Found"); |
michael@0 | 147 | } |
michael@0 | 148 | } |
michael@0 | 149 | |
michael@0 | 150 | function run_test() { |
michael@0 | 151 | do_test_pending(); |
michael@0 | 152 | createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9"); |
michael@0 | 153 | |
michael@0 | 154 | server = new HttpServer(); |
michael@0 | 155 | server.registerPathHandler("/0", requestHandler); |
michael@0 | 156 | server.registerPathHandler("/1", requestHandler); |
michael@0 | 157 | server.registerPathHandler("/2", requestHandler); |
michael@0 | 158 | server.registerPathHandler("/3", requestHandler); |
michael@0 | 159 | server.start(4444); |
michael@0 | 160 | |
michael@0 | 161 | Services.prefs.setBoolPref(PREF_MATCH_OS_LOCALE, false); |
michael@0 | 162 | Services.prefs.setCharPref(PREF_SELECTED_LOCALE, "en-US"); |
michael@0 | 163 | |
michael@0 | 164 | startupManager(); |
michael@0 | 165 | installAllFiles([do_get_addon(a.addon) for each (a in ADDONS)], function() { |
michael@0 | 166 | |
michael@0 | 167 | restartManager(); |
michael@0 | 168 | AddonManager.getAddonByID(ADDONS[1].id, callback_soon(function(addon) { |
michael@0 | 169 | do_check_true(!(!addon)); |
michael@0 | 170 | addon.userDisabled = true; |
michael@0 | 171 | restartManager(); |
michael@0 | 172 | |
michael@0 | 173 | AddonManager.getAddonsByIDs([a.id for each (a in ADDONS)], function(installedItems) { |
michael@0 | 174 | installedItems.forEach(function(item) { |
michael@0 | 175 | updateListener.pendingCount++; |
michael@0 | 176 | item.findUpdates(updateListener, AddonManager.UPDATE_WHEN_USER_REQUESTED); |
michael@0 | 177 | }); |
michael@0 | 178 | }); |
michael@0 | 179 | })); |
michael@0 | 180 | }); |
michael@0 | 181 | } |