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 {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components; |
michael@0 | 7 | |
michael@0 | 8 | const URI_EXTENSION_BLOCKLIST_DIALOG = "chrome://mozapps/content/extensions/blocklist.xul"; |
michael@0 | 9 | |
michael@0 | 10 | Cu.import("resource://testing-common/httpd.js"); |
michael@0 | 11 | var testserver = new HttpServer(); |
michael@0 | 12 | testserver.start(-1); |
michael@0 | 13 | gPort = testserver.identity.primaryPort; |
michael@0 | 14 | |
michael@0 | 15 | // register static files with server and interpolate port numbers in them |
michael@0 | 16 | mapFile("/data/test_bug393285.xml", testserver); |
michael@0 | 17 | |
michael@0 | 18 | const profileDir = gProfD.clone(); |
michael@0 | 19 | profileDir.append("extensions"); |
michael@0 | 20 | |
michael@0 | 21 | let addonIDs = ["test_bug393285_1@tests.mozilla.org", |
michael@0 | 22 | "test_bug393285_2@tests.mozilla.org", |
michael@0 | 23 | "test_bug393285_3a@tests.mozilla.org", |
michael@0 | 24 | "test_bug393285_3b@tests.mozilla.org", |
michael@0 | 25 | "test_bug393285_4@tests.mozilla.org", |
michael@0 | 26 | "test_bug393285_5@tests.mozilla.org", |
michael@0 | 27 | "test_bug393285_6@tests.mozilla.org", |
michael@0 | 28 | "test_bug393285_7@tests.mozilla.org", |
michael@0 | 29 | "test_bug393285_8@tests.mozilla.org", |
michael@0 | 30 | "test_bug393285_9@tests.mozilla.org", |
michael@0 | 31 | "test_bug393285_10@tests.mozilla.org", |
michael@0 | 32 | "test_bug393285_11@tests.mozilla.org", |
michael@0 | 33 | "test_bug393285_12@tests.mozilla.org", |
michael@0 | 34 | "test_bug393285_13@tests.mozilla.org", |
michael@0 | 35 | "test_bug393285_14@tests.mozilla.org"]; |
michael@0 | 36 | |
michael@0 | 37 | // A window watcher to deal with the blocklist UI dialog. |
michael@0 | 38 | var WindowWatcher = { |
michael@0 | 39 | openWindow: function(parent, url, name, features, arguments) { |
michael@0 | 40 | // Should be called to list the newly blocklisted items |
michael@0 | 41 | do_check_eq(url, URI_EXTENSION_BLOCKLIST_DIALOG); |
michael@0 | 42 | |
michael@0 | 43 | // Simulate auto-disabling any softblocks |
michael@0 | 44 | var list = arguments.wrappedJSObject.list; |
michael@0 | 45 | list.forEach(function(aItem) { |
michael@0 | 46 | if (!aItem.blocked) |
michael@0 | 47 | aItem.disable = true; |
michael@0 | 48 | }); |
michael@0 | 49 | |
michael@0 | 50 | //run the code after the blocklist is closed |
michael@0 | 51 | Services.obs.notifyObservers(null, "addon-blocklist-closed", null); |
michael@0 | 52 | |
michael@0 | 53 | }, |
michael@0 | 54 | |
michael@0 | 55 | QueryInterface: function(iid) { |
michael@0 | 56 | if (iid.equals(Ci.nsIWindowWatcher) |
michael@0 | 57 | || iid.equals(Ci.nsISupports)) |
michael@0 | 58 | return this; |
michael@0 | 59 | |
michael@0 | 60 | throw Cr.NS_ERROR_NO_INTERFACE; |
michael@0 | 61 | } |
michael@0 | 62 | }; |
michael@0 | 63 | |
michael@0 | 64 | var WindowWatcherFactory = { |
michael@0 | 65 | createInstance: function createInstance(outer, iid) { |
michael@0 | 66 | if (outer != null) |
michael@0 | 67 | throw Cr.NS_ERROR_NO_AGGREGATION; |
michael@0 | 68 | return WindowWatcher.QueryInterface(iid); |
michael@0 | 69 | } |
michael@0 | 70 | }; |
michael@0 | 71 | |
michael@0 | 72 | var registrar = Components.manager.QueryInterface(Ci.nsIComponentRegistrar); |
michael@0 | 73 | registrar.registerFactory(Components.ID("{1dfeb90a-2193-45d5-9cb8-864928b2af55}"), |
michael@0 | 74 | "Fake Window Watcher", |
michael@0 | 75 | "@mozilla.org/embedcomp/window-watcher;1", |
michael@0 | 76 | WindowWatcherFactory); |
michael@0 | 77 | |
michael@0 | 78 | |
michael@0 | 79 | function load_blocklist(aFile, aCallback) { |
michael@0 | 80 | Services.obs.addObserver(function() { |
michael@0 | 81 | Services.obs.removeObserver(arguments.callee, "blocklist-updated"); |
michael@0 | 82 | |
michael@0 | 83 | do_execute_soon(aCallback); |
michael@0 | 84 | }, "blocklist-updated", false); |
michael@0 | 85 | |
michael@0 | 86 | Services.prefs.setCharPref("extensions.blocklist.url", "http://localhost:" + |
michael@0 | 87 | gPort + "/data/" + aFile); |
michael@0 | 88 | var blocklist = Cc["@mozilla.org/extensions/blocklist;1"]. |
michael@0 | 89 | getService(Ci.nsITimerCallback); |
michael@0 | 90 | blocklist.notify(null); |
michael@0 | 91 | } |
michael@0 | 92 | |
michael@0 | 93 | |
michael@0 | 94 | function end_test() { |
michael@0 | 95 | testserver.stop(do_test_finished); |
michael@0 | 96 | } |
michael@0 | 97 | |
michael@0 | 98 | function run_test() { |
michael@0 | 99 | do_test_pending(); |
michael@0 | 100 | |
michael@0 | 101 | createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9"); |
michael@0 | 102 | |
michael@0 | 103 | writeInstallRDFForExtension({ |
michael@0 | 104 | id: "test_bug393285_1@tests.mozilla.org", |
michael@0 | 105 | name: "extension 1", |
michael@0 | 106 | version: "1.0", |
michael@0 | 107 | targetApplications: [{ |
michael@0 | 108 | id: "xpcshell@tests.mozilla.org", |
michael@0 | 109 | minVersion: "1", |
michael@0 | 110 | maxVersion: "3" |
michael@0 | 111 | }] |
michael@0 | 112 | }, profileDir); |
michael@0 | 113 | |
michael@0 | 114 | |
michael@0 | 115 | writeInstallRDFForExtension({ |
michael@0 | 116 | id: "test_bug393285_2@tests.mozilla.org", |
michael@0 | 117 | name: "extension 2", |
michael@0 | 118 | version: "1.0", |
michael@0 | 119 | targetApplications: [{ |
michael@0 | 120 | id: "xpcshell@tests.mozilla.org", |
michael@0 | 121 | minVersion: "1", |
michael@0 | 122 | maxVersion: "3" |
michael@0 | 123 | }] |
michael@0 | 124 | }, profileDir); |
michael@0 | 125 | |
michael@0 | 126 | writeInstallRDFForExtension({ |
michael@0 | 127 | id: "test_bug393285_3a@tests.mozilla.org", |
michael@0 | 128 | name: "extension 3a", |
michael@0 | 129 | version: "1.0", |
michael@0 | 130 | targetApplications: [{ |
michael@0 | 131 | id: "xpcshell@tests.mozilla.org", |
michael@0 | 132 | minVersion: "1", |
michael@0 | 133 | maxVersion: "3" |
michael@0 | 134 | }] |
michael@0 | 135 | }, profileDir); |
michael@0 | 136 | |
michael@0 | 137 | writeInstallRDFForExtension({ |
michael@0 | 138 | id: "test_bug393285_3b@tests.mozilla.org", |
michael@0 | 139 | name: "extension 3b", |
michael@0 | 140 | version: "2.0", |
michael@0 | 141 | targetApplications: [{ |
michael@0 | 142 | id: "xpcshell@tests.mozilla.org", |
michael@0 | 143 | minVersion: "1", |
michael@0 | 144 | maxVersion: "3" |
michael@0 | 145 | }] |
michael@0 | 146 | }, profileDir); |
michael@0 | 147 | |
michael@0 | 148 | writeInstallRDFForExtension({ |
michael@0 | 149 | id: "test_bug393285_4@tests.mozilla.org", |
michael@0 | 150 | name: "extension 4", |
michael@0 | 151 | version: "1.0", |
michael@0 | 152 | targetApplications: [{ |
michael@0 | 153 | id: "xpcshell@tests.mozilla.org", |
michael@0 | 154 | minVersion: "1", |
michael@0 | 155 | maxVersion: "3" |
michael@0 | 156 | }] |
michael@0 | 157 | }, profileDir); |
michael@0 | 158 | |
michael@0 | 159 | writeInstallRDFForExtension({ |
michael@0 | 160 | id: "test_bug393285_5@tests.mozilla.org", |
michael@0 | 161 | name: "extension 5", |
michael@0 | 162 | version: "1.0", |
michael@0 | 163 | targetApplications: [{ |
michael@0 | 164 | id: "xpcshell@tests.mozilla.org", |
michael@0 | 165 | minVersion: "1", |
michael@0 | 166 | maxVersion: "3" |
michael@0 | 167 | }] |
michael@0 | 168 | }, profileDir); |
michael@0 | 169 | |
michael@0 | 170 | writeInstallRDFForExtension({ |
michael@0 | 171 | id: "test_bug393285_6@tests.mozilla.org", |
michael@0 | 172 | name: "extension 6", |
michael@0 | 173 | version: "1.0", |
michael@0 | 174 | targetApplications: [{ |
michael@0 | 175 | id: "xpcshell@tests.mozilla.org", |
michael@0 | 176 | minVersion: "1", |
michael@0 | 177 | maxVersion: "3" |
michael@0 | 178 | }] |
michael@0 | 179 | }, profileDir); |
michael@0 | 180 | |
michael@0 | 181 | writeInstallRDFForExtension({ |
michael@0 | 182 | id: "test_bug393285_7@tests.mozilla.org", |
michael@0 | 183 | name: "extension 7", |
michael@0 | 184 | version: "1.0", |
michael@0 | 185 | targetApplications: [{ |
michael@0 | 186 | id: "xpcshell@tests.mozilla.org", |
michael@0 | 187 | minVersion: "1", |
michael@0 | 188 | maxVersion: "3" |
michael@0 | 189 | }] |
michael@0 | 190 | }, profileDir); |
michael@0 | 191 | |
michael@0 | 192 | writeInstallRDFForExtension({ |
michael@0 | 193 | id: "test_bug393285_8@tests.mozilla.org", |
michael@0 | 194 | name: "extension 8", |
michael@0 | 195 | version: "1.0", |
michael@0 | 196 | targetApplications: [{ |
michael@0 | 197 | id: "xpcshell@tests.mozilla.org", |
michael@0 | 198 | minVersion: "1", |
michael@0 | 199 | maxVersion: "3" |
michael@0 | 200 | }] |
michael@0 | 201 | }, profileDir); |
michael@0 | 202 | |
michael@0 | 203 | writeInstallRDFForExtension({ |
michael@0 | 204 | id: "test_bug393285_9@tests.mozilla.org", |
michael@0 | 205 | name: "extension 9", |
michael@0 | 206 | version: "1.0", |
michael@0 | 207 | targetApplications: [{ |
michael@0 | 208 | id: "xpcshell@tests.mozilla.org", |
michael@0 | 209 | minVersion: "1", |
michael@0 | 210 | maxVersion: "3" |
michael@0 | 211 | }] |
michael@0 | 212 | }, profileDir); |
michael@0 | 213 | |
michael@0 | 214 | writeInstallRDFForExtension({ |
michael@0 | 215 | id: "test_bug393285_10@tests.mozilla.org", |
michael@0 | 216 | name: "extension 10", |
michael@0 | 217 | version: "1.0", |
michael@0 | 218 | targetApplications: [{ |
michael@0 | 219 | id: "xpcshell@tests.mozilla.org", |
michael@0 | 220 | minVersion: "1", |
michael@0 | 221 | maxVersion: "3" |
michael@0 | 222 | }] |
michael@0 | 223 | }, profileDir); |
michael@0 | 224 | |
michael@0 | 225 | writeInstallRDFForExtension({ |
michael@0 | 226 | id: "test_bug393285_11@tests.mozilla.org", |
michael@0 | 227 | name: "extension 11", |
michael@0 | 228 | version: "1.0", |
michael@0 | 229 | targetApplications: [{ |
michael@0 | 230 | id: "xpcshell@tests.mozilla.org", |
michael@0 | 231 | minVersion: "1", |
michael@0 | 232 | maxVersion: "3" |
michael@0 | 233 | }] |
michael@0 | 234 | }, profileDir); |
michael@0 | 235 | |
michael@0 | 236 | writeInstallRDFForExtension({ |
michael@0 | 237 | id: "test_bug393285_12@tests.mozilla.org", |
michael@0 | 238 | name: "extension 12", |
michael@0 | 239 | version: "1.0", |
michael@0 | 240 | targetApplications: [{ |
michael@0 | 241 | id: "xpcshell@tests.mozilla.org", |
michael@0 | 242 | minVersion: "1", |
michael@0 | 243 | maxVersion: "3" |
michael@0 | 244 | }] |
michael@0 | 245 | }, profileDir); |
michael@0 | 246 | |
michael@0 | 247 | writeInstallRDFForExtension({ |
michael@0 | 248 | id: "test_bug393285_13@tests.mozilla.org", |
michael@0 | 249 | name: "extension 13", |
michael@0 | 250 | version: "1.0", |
michael@0 | 251 | targetApplications: [{ |
michael@0 | 252 | id: "xpcshell@tests.mozilla.org", |
michael@0 | 253 | minVersion: "1", |
michael@0 | 254 | maxVersion: "3" |
michael@0 | 255 | }] |
michael@0 | 256 | }, profileDir); |
michael@0 | 257 | |
michael@0 | 258 | writeInstallRDFForExtension({ |
michael@0 | 259 | id: "test_bug393285_14@tests.mozilla.org", |
michael@0 | 260 | name: "extension 14", |
michael@0 | 261 | version: "1.0", |
michael@0 | 262 | targetApplications: [{ |
michael@0 | 263 | id: "xpcshell@tests.mozilla.org", |
michael@0 | 264 | minVersion: "1", |
michael@0 | 265 | maxVersion: "3" |
michael@0 | 266 | }] |
michael@0 | 267 | }, profileDir); |
michael@0 | 268 | |
michael@0 | 269 | startupManager(); |
michael@0 | 270 | |
michael@0 | 271 | AddonManager.getAddonsByIDs(addonIDs, function(addons) { |
michael@0 | 272 | for (addon of addons) { |
michael@0 | 273 | do_check_eq(addon.blocklistState, Ci.nsIBlocklistService.STATE_NOT_BLOCKED); |
michael@0 | 274 | } |
michael@0 | 275 | run_test_1(); |
michael@0 | 276 | }); |
michael@0 | 277 | } |
michael@0 | 278 | |
michael@0 | 279 | function run_test_1() { |
michael@0 | 280 | load_blocklist("test_bug393285.xml", function() { |
michael@0 | 281 | restartManager(); |
michael@0 | 282 | |
michael@0 | 283 | var blocklist = Cc["@mozilla.org/extensions/blocklist;1"] |
michael@0 | 284 | .getService(Ci.nsIBlocklistService); |
michael@0 | 285 | |
michael@0 | 286 | AddonManager.getAddonsByIDs(addonIDs, |
michael@0 | 287 | function([a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, |
michael@0 | 288 | a11, a12, a13, a14, a15]) { |
michael@0 | 289 | // No info in blocklist, shouldn't be blocked |
michael@0 | 290 | do_check_false(blocklist.isAddonBlocklisted(a1, "1", "1.9")); |
michael@0 | 291 | |
michael@0 | 292 | // Should always be blocked |
michael@0 | 293 | do_check_true(blocklist.isAddonBlocklisted(a2, "1", "1.9")); |
michael@0 | 294 | |
michael@0 | 295 | // Only version 1 should be blocked |
michael@0 | 296 | do_check_true(blocklist.isAddonBlocklisted(a3, "1", "1.9")); |
michael@0 | 297 | do_check_false(blocklist.isAddonBlocklisted(a4, "1", "1.9")); |
michael@0 | 298 | |
michael@0 | 299 | // Should be blocked for app version 1 |
michael@0 | 300 | do_check_true(blocklist.isAddonBlocklisted(a5, "1", "1.9")); |
michael@0 | 301 | do_check_false(blocklist.isAddonBlocklisted(a5, "2", "1.9")); |
michael@0 | 302 | |
michael@0 | 303 | // Not blocklisted because we are a different OS |
michael@0 | 304 | do_check_false(blocklist.isAddonBlocklisted(a6, "2", "1.9")); |
michael@0 | 305 | |
michael@0 | 306 | // Blocklisted based on OS |
michael@0 | 307 | do_check_true(blocklist.isAddonBlocklisted(a7, "2", "1.9")); |
michael@0 | 308 | do_check_true(blocklist.isAddonBlocklisted(a8, "2", "1.9")); |
michael@0 | 309 | |
michael@0 | 310 | // Not blocklisted because we are a different ABI |
michael@0 | 311 | do_check_false(blocklist.isAddonBlocklisted(a9, "2", "1.9")); |
michael@0 | 312 | |
michael@0 | 313 | // Blocklisted based on ABI |
michael@0 | 314 | do_check_true(blocklist.isAddonBlocklisted(a10, "2", "1.9")); |
michael@0 | 315 | do_check_true(blocklist.isAddonBlocklisted(a11, "2", "1.9")); |
michael@0 | 316 | |
michael@0 | 317 | // Doesnt match both os and abi so not blocked |
michael@0 | 318 | do_check_false(blocklist.isAddonBlocklisted(a12, "2", "1.9")); |
michael@0 | 319 | do_check_false(blocklist.isAddonBlocklisted(a13, "2", "1.9")); |
michael@0 | 320 | do_check_false(blocklist.isAddonBlocklisted(a14, "2", "1.9")); |
michael@0 | 321 | |
michael@0 | 322 | // Matches both os and abi so blocked |
michael@0 | 323 | do_check_true(blocklist.isAddonBlocklisted(a15, "2", "1.9")); |
michael@0 | 324 | end_test(); |
michael@0 | 325 | }); |
michael@0 | 326 | }); |
michael@0 | 327 | } |