1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/mozapps/extensions/test/xpcshell/test_bug393285.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,327 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. 1.7 + */ 1.8 + 1.9 +const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components; 1.10 + 1.11 +const URI_EXTENSION_BLOCKLIST_DIALOG = "chrome://mozapps/content/extensions/blocklist.xul"; 1.12 + 1.13 +Cu.import("resource://testing-common/httpd.js"); 1.14 +var testserver = new HttpServer(); 1.15 +testserver.start(-1); 1.16 +gPort = testserver.identity.primaryPort; 1.17 + 1.18 +// register static files with server and interpolate port numbers in them 1.19 +mapFile("/data/test_bug393285.xml", testserver); 1.20 + 1.21 +const profileDir = gProfD.clone(); 1.22 +profileDir.append("extensions"); 1.23 + 1.24 +let addonIDs = ["test_bug393285_1@tests.mozilla.org", 1.25 + "test_bug393285_2@tests.mozilla.org", 1.26 + "test_bug393285_3a@tests.mozilla.org", 1.27 + "test_bug393285_3b@tests.mozilla.org", 1.28 + "test_bug393285_4@tests.mozilla.org", 1.29 + "test_bug393285_5@tests.mozilla.org", 1.30 + "test_bug393285_6@tests.mozilla.org", 1.31 + "test_bug393285_7@tests.mozilla.org", 1.32 + "test_bug393285_8@tests.mozilla.org", 1.33 + "test_bug393285_9@tests.mozilla.org", 1.34 + "test_bug393285_10@tests.mozilla.org", 1.35 + "test_bug393285_11@tests.mozilla.org", 1.36 + "test_bug393285_12@tests.mozilla.org", 1.37 + "test_bug393285_13@tests.mozilla.org", 1.38 + "test_bug393285_14@tests.mozilla.org"]; 1.39 + 1.40 +// A window watcher to deal with the blocklist UI dialog. 1.41 +var WindowWatcher = { 1.42 + openWindow: function(parent, url, name, features, arguments) { 1.43 + // Should be called to list the newly blocklisted items 1.44 + do_check_eq(url, URI_EXTENSION_BLOCKLIST_DIALOG); 1.45 + 1.46 + // Simulate auto-disabling any softblocks 1.47 + var list = arguments.wrappedJSObject.list; 1.48 + list.forEach(function(aItem) { 1.49 + if (!aItem.blocked) 1.50 + aItem.disable = true; 1.51 + }); 1.52 + 1.53 + //run the code after the blocklist is closed 1.54 + Services.obs.notifyObservers(null, "addon-blocklist-closed", null); 1.55 + 1.56 + }, 1.57 + 1.58 + QueryInterface: function(iid) { 1.59 + if (iid.equals(Ci.nsIWindowWatcher) 1.60 + || iid.equals(Ci.nsISupports)) 1.61 + return this; 1.62 + 1.63 + throw Cr.NS_ERROR_NO_INTERFACE; 1.64 + } 1.65 +}; 1.66 + 1.67 +var WindowWatcherFactory = { 1.68 + createInstance: function createInstance(outer, iid) { 1.69 + if (outer != null) 1.70 + throw Cr.NS_ERROR_NO_AGGREGATION; 1.71 + return WindowWatcher.QueryInterface(iid); 1.72 + } 1.73 +}; 1.74 + 1.75 +var registrar = Components.manager.QueryInterface(Ci.nsIComponentRegistrar); 1.76 +registrar.registerFactory(Components.ID("{1dfeb90a-2193-45d5-9cb8-864928b2af55}"), 1.77 + "Fake Window Watcher", 1.78 + "@mozilla.org/embedcomp/window-watcher;1", 1.79 + WindowWatcherFactory); 1.80 + 1.81 + 1.82 +function load_blocklist(aFile, aCallback) { 1.83 + Services.obs.addObserver(function() { 1.84 + Services.obs.removeObserver(arguments.callee, "blocklist-updated"); 1.85 + 1.86 + do_execute_soon(aCallback); 1.87 + }, "blocklist-updated", false); 1.88 + 1.89 + Services.prefs.setCharPref("extensions.blocklist.url", "http://localhost:" + 1.90 + gPort + "/data/" + aFile); 1.91 + var blocklist = Cc["@mozilla.org/extensions/blocklist;1"]. 1.92 + getService(Ci.nsITimerCallback); 1.93 + blocklist.notify(null); 1.94 +} 1.95 + 1.96 + 1.97 +function end_test() { 1.98 + testserver.stop(do_test_finished); 1.99 +} 1.100 + 1.101 +function run_test() { 1.102 + do_test_pending(); 1.103 + 1.104 + createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9"); 1.105 + 1.106 + writeInstallRDFForExtension({ 1.107 + id: "test_bug393285_1@tests.mozilla.org", 1.108 + name: "extension 1", 1.109 + version: "1.0", 1.110 + targetApplications: [{ 1.111 + id: "xpcshell@tests.mozilla.org", 1.112 + minVersion: "1", 1.113 + maxVersion: "3" 1.114 + }] 1.115 + }, profileDir); 1.116 + 1.117 + 1.118 + writeInstallRDFForExtension({ 1.119 + id: "test_bug393285_2@tests.mozilla.org", 1.120 + name: "extension 2", 1.121 + version: "1.0", 1.122 + targetApplications: [{ 1.123 + id: "xpcshell@tests.mozilla.org", 1.124 + minVersion: "1", 1.125 + maxVersion: "3" 1.126 + }] 1.127 + }, profileDir); 1.128 + 1.129 + writeInstallRDFForExtension({ 1.130 + id: "test_bug393285_3a@tests.mozilla.org", 1.131 + name: "extension 3a", 1.132 + version: "1.0", 1.133 + targetApplications: [{ 1.134 + id: "xpcshell@tests.mozilla.org", 1.135 + minVersion: "1", 1.136 + maxVersion: "3" 1.137 + }] 1.138 + }, profileDir); 1.139 + 1.140 + writeInstallRDFForExtension({ 1.141 + id: "test_bug393285_3b@tests.mozilla.org", 1.142 + name: "extension 3b", 1.143 + version: "2.0", 1.144 + targetApplications: [{ 1.145 + id: "xpcshell@tests.mozilla.org", 1.146 + minVersion: "1", 1.147 + maxVersion: "3" 1.148 + }] 1.149 + }, profileDir); 1.150 + 1.151 + writeInstallRDFForExtension({ 1.152 + id: "test_bug393285_4@tests.mozilla.org", 1.153 + name: "extension 4", 1.154 + version: "1.0", 1.155 + targetApplications: [{ 1.156 + id: "xpcshell@tests.mozilla.org", 1.157 + minVersion: "1", 1.158 + maxVersion: "3" 1.159 + }] 1.160 + }, profileDir); 1.161 + 1.162 + writeInstallRDFForExtension({ 1.163 + id: "test_bug393285_5@tests.mozilla.org", 1.164 + name: "extension 5", 1.165 + version: "1.0", 1.166 + targetApplications: [{ 1.167 + id: "xpcshell@tests.mozilla.org", 1.168 + minVersion: "1", 1.169 + maxVersion: "3" 1.170 + }] 1.171 + }, profileDir); 1.172 + 1.173 + writeInstallRDFForExtension({ 1.174 + id: "test_bug393285_6@tests.mozilla.org", 1.175 + name: "extension 6", 1.176 + version: "1.0", 1.177 + targetApplications: [{ 1.178 + id: "xpcshell@tests.mozilla.org", 1.179 + minVersion: "1", 1.180 + maxVersion: "3" 1.181 + }] 1.182 + }, profileDir); 1.183 + 1.184 + writeInstallRDFForExtension({ 1.185 + id: "test_bug393285_7@tests.mozilla.org", 1.186 + name: "extension 7", 1.187 + version: "1.0", 1.188 + targetApplications: [{ 1.189 + id: "xpcshell@tests.mozilla.org", 1.190 + minVersion: "1", 1.191 + maxVersion: "3" 1.192 + }] 1.193 + }, profileDir); 1.194 + 1.195 + writeInstallRDFForExtension({ 1.196 + id: "test_bug393285_8@tests.mozilla.org", 1.197 + name: "extension 8", 1.198 + version: "1.0", 1.199 + targetApplications: [{ 1.200 + id: "xpcshell@tests.mozilla.org", 1.201 + minVersion: "1", 1.202 + maxVersion: "3" 1.203 + }] 1.204 + }, profileDir); 1.205 + 1.206 + writeInstallRDFForExtension({ 1.207 + id: "test_bug393285_9@tests.mozilla.org", 1.208 + name: "extension 9", 1.209 + version: "1.0", 1.210 + targetApplications: [{ 1.211 + id: "xpcshell@tests.mozilla.org", 1.212 + minVersion: "1", 1.213 + maxVersion: "3" 1.214 + }] 1.215 + }, profileDir); 1.216 + 1.217 + writeInstallRDFForExtension({ 1.218 + id: "test_bug393285_10@tests.mozilla.org", 1.219 + name: "extension 10", 1.220 + version: "1.0", 1.221 + targetApplications: [{ 1.222 + id: "xpcshell@tests.mozilla.org", 1.223 + minVersion: "1", 1.224 + maxVersion: "3" 1.225 + }] 1.226 + }, profileDir); 1.227 + 1.228 + writeInstallRDFForExtension({ 1.229 + id: "test_bug393285_11@tests.mozilla.org", 1.230 + name: "extension 11", 1.231 + version: "1.0", 1.232 + targetApplications: [{ 1.233 + id: "xpcshell@tests.mozilla.org", 1.234 + minVersion: "1", 1.235 + maxVersion: "3" 1.236 + }] 1.237 + }, profileDir); 1.238 + 1.239 + writeInstallRDFForExtension({ 1.240 + id: "test_bug393285_12@tests.mozilla.org", 1.241 + name: "extension 12", 1.242 + version: "1.0", 1.243 + targetApplications: [{ 1.244 + id: "xpcshell@tests.mozilla.org", 1.245 + minVersion: "1", 1.246 + maxVersion: "3" 1.247 + }] 1.248 + }, profileDir); 1.249 + 1.250 + writeInstallRDFForExtension({ 1.251 + id: "test_bug393285_13@tests.mozilla.org", 1.252 + name: "extension 13", 1.253 + version: "1.0", 1.254 + targetApplications: [{ 1.255 + id: "xpcshell@tests.mozilla.org", 1.256 + minVersion: "1", 1.257 + maxVersion: "3" 1.258 + }] 1.259 + }, profileDir); 1.260 + 1.261 + writeInstallRDFForExtension({ 1.262 + id: "test_bug393285_14@tests.mozilla.org", 1.263 + name: "extension 14", 1.264 + version: "1.0", 1.265 + targetApplications: [{ 1.266 + id: "xpcshell@tests.mozilla.org", 1.267 + minVersion: "1", 1.268 + maxVersion: "3" 1.269 + }] 1.270 + }, profileDir); 1.271 + 1.272 + startupManager(); 1.273 + 1.274 + AddonManager.getAddonsByIDs(addonIDs, function(addons) { 1.275 + for (addon of addons) { 1.276 + do_check_eq(addon.blocklistState, Ci.nsIBlocklistService.STATE_NOT_BLOCKED); 1.277 + } 1.278 + run_test_1(); 1.279 + }); 1.280 +} 1.281 + 1.282 +function run_test_1() { 1.283 + load_blocklist("test_bug393285.xml", function() { 1.284 + restartManager(); 1.285 + 1.286 + var blocklist = Cc["@mozilla.org/extensions/blocklist;1"] 1.287 + .getService(Ci.nsIBlocklistService); 1.288 + 1.289 + AddonManager.getAddonsByIDs(addonIDs, 1.290 + function([a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, 1.291 + a11, a12, a13, a14, a15]) { 1.292 + // No info in blocklist, shouldn't be blocked 1.293 + do_check_false(blocklist.isAddonBlocklisted(a1, "1", "1.9")); 1.294 + 1.295 + // Should always be blocked 1.296 + do_check_true(blocklist.isAddonBlocklisted(a2, "1", "1.9")); 1.297 + 1.298 + // Only version 1 should be blocked 1.299 + do_check_true(blocklist.isAddonBlocklisted(a3, "1", "1.9")); 1.300 + do_check_false(blocklist.isAddonBlocklisted(a4, "1", "1.9")); 1.301 + 1.302 + // Should be blocked for app version 1 1.303 + do_check_true(blocklist.isAddonBlocklisted(a5, "1", "1.9")); 1.304 + do_check_false(blocklist.isAddonBlocklisted(a5, "2", "1.9")); 1.305 + 1.306 + // Not blocklisted because we are a different OS 1.307 + do_check_false(blocklist.isAddonBlocklisted(a6, "2", "1.9")); 1.308 + 1.309 + // Blocklisted based on OS 1.310 + do_check_true(blocklist.isAddonBlocklisted(a7, "2", "1.9")); 1.311 + do_check_true(blocklist.isAddonBlocklisted(a8, "2", "1.9")); 1.312 + 1.313 + // Not blocklisted because we are a different ABI 1.314 + do_check_false(blocklist.isAddonBlocklisted(a9, "2", "1.9")); 1.315 + 1.316 + // Blocklisted based on ABI 1.317 + do_check_true(blocklist.isAddonBlocklisted(a10, "2", "1.9")); 1.318 + do_check_true(blocklist.isAddonBlocklisted(a11, "2", "1.9")); 1.319 + 1.320 + // Doesnt match both os and abi so not blocked 1.321 + do_check_false(blocklist.isAddonBlocklisted(a12, "2", "1.9")); 1.322 + do_check_false(blocklist.isAddonBlocklisted(a13, "2", "1.9")); 1.323 + do_check_false(blocklist.isAddonBlocklisted(a14, "2", "1.9")); 1.324 + 1.325 + // Matches both os and abi so blocked 1.326 + do_check_true(blocklist.isAddonBlocklisted(a15, "2", "1.9")); 1.327 + end_test(); 1.328 + }); 1.329 + }); 1.330 +}