1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/mozapps/extensions/test/xpcshell/test_bug406118.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,167 @@ 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 +let addonIDs = ["test_bug393285_1@tests.mozilla.org", 1.10 + "test_bug393285_2@tests.mozilla.org", 1.11 + "test_bug393285_3a@tests.mozilla.org", 1.12 + "test_bug393285_4@tests.mozilla.org"]; 1.13 + 1.14 +const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components; 1.15 + 1.16 +const URI_EXTENSION_BLOCKLIST_DIALOG = "chrome://mozapps/content/extensions/blocklist.xul"; 1.17 + 1.18 +Cu.import("resource://testing-common/httpd.js"); 1.19 +var testserver = new HttpServer(); 1.20 +testserver.start(-1); 1.21 +gPort = testserver.identity.primaryPort; 1.22 + 1.23 +// register static files with server and interpolate port numbers in them 1.24 +mapFile("/data/test_bug393285.xml", testserver); 1.25 + 1.26 +const profileDir = gProfD.clone(); 1.27 +profileDir.append("extensions"); 1.28 + 1.29 +// A window watcher to deal with the blocklist UI dialog. 1.30 +var WindowWatcher = { 1.31 + openWindow: function(parent, url, name, features, arguments) { 1.32 + // Should be called to list the newly blocklisted items 1.33 + do_check_eq(url, URI_EXTENSION_BLOCKLIST_DIALOG); 1.34 + 1.35 + // Simulate auto-disabling any softblocks 1.36 + var list = arguments.wrappedJSObject.list; 1.37 + list.forEach(function(aItem) { 1.38 + if (!aItem.blocked) 1.39 + aItem.disable = true; 1.40 + }); 1.41 + 1.42 + //run the code after the blocklist is closed 1.43 + Services.obs.notifyObservers(null, "addon-blocklist-closed", null); 1.44 + 1.45 + }, 1.46 + 1.47 + QueryInterface: function(iid) { 1.48 + if (iid.equals(Ci.nsIWindowWatcher) 1.49 + || iid.equals(Ci.nsISupports)) 1.50 + return this; 1.51 + 1.52 + throw Cr.NS_ERROR_NO_INTERFACE; 1.53 + } 1.54 +}; 1.55 + 1.56 +var WindowWatcherFactory = { 1.57 + createInstance: function createInstance(outer, iid) { 1.58 + if (outer != null) 1.59 + throw Cr.NS_ERROR_NO_AGGREGATION; 1.60 + return WindowWatcher.QueryInterface(iid); 1.61 + } 1.62 +}; 1.63 + 1.64 +var registrar = Components.manager.QueryInterface(Ci.nsIComponentRegistrar); 1.65 +registrar.registerFactory(Components.ID("{1dfeb90a-2193-45d5-9cb8-864928b2af55}"), 1.66 + "Fake Window Watcher", 1.67 + "@mozilla.org/embedcomp/window-watcher;1", 1.68 + WindowWatcherFactory); 1.69 + 1.70 + 1.71 +function load_blocklist(aFile, aCallback) { 1.72 + Services.obs.addObserver(function() { 1.73 + Services.obs.removeObserver(arguments.callee, "blocklist-updated"); 1.74 + 1.75 + do_execute_soon(aCallback); 1.76 + }, "blocklist-updated", false); 1.77 + 1.78 + Services.prefs.setCharPref("extensions.blocklist.url", "http://localhost:" + 1.79 + gPort + "/data/" + aFile); 1.80 + var blocklist = Cc["@mozilla.org/extensions/blocklist;1"]. 1.81 + getService(Ci.nsITimerCallback); 1.82 + blocklist.notify(null); 1.83 +} 1.84 + 1.85 + 1.86 +function end_test() { 1.87 + testserver.stop(do_test_finished); 1.88 +} 1.89 + 1.90 +function run_test() { 1.91 + do_test_pending(); 1.92 + 1.93 + createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9"); 1.94 + 1.95 + writeInstallRDFForExtension({ 1.96 + id: "test_bug393285_1@tests.mozilla.org", 1.97 + name: "extension 1", 1.98 + version: "1.0", 1.99 + targetApplications: [{ 1.100 + id: "xpcshell@tests.mozilla.org", 1.101 + minVersion: "1", 1.102 + maxVersion: "3" 1.103 + }] 1.104 + }, profileDir); 1.105 + 1.106 + 1.107 + writeInstallRDFForExtension({ 1.108 + id: "test_bug393285_2@tests.mozilla.org", 1.109 + name: "extension 2", 1.110 + version: "1.0", 1.111 + targetApplications: [{ 1.112 + id: "xpcshell@tests.mozilla.org", 1.113 + minVersion: "1", 1.114 + maxVersion: "3" 1.115 + }] 1.116 + }, profileDir); 1.117 + 1.118 + writeInstallRDFForExtension({ 1.119 + id: "test_bug393285_3a@tests.mozilla.org", 1.120 + name: "extension 3a", 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_4@tests.mozilla.org", 1.131 + name: "extension 4", 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 + startupManager(); 1.141 + 1.142 + AddonManager.getAddonsByIDs(addonIDs, function(addons) { 1.143 + for (addon of addons) { 1.144 + do_check_eq(addon.blocklistState, Ci.nsIBlocklistService.STATE_NOT_BLOCKED); 1.145 + } 1.146 + run_test_1(); 1.147 + }); 1.148 +} 1.149 + 1.150 +function run_test_1() { 1.151 + load_blocklist("test_bug393285.xml", function() { 1.152 + restartManager(); 1.153 + 1.154 + var blocklist = Cc["@mozilla.org/extensions/blocklist;1"] 1.155 + .getService(Ci.nsIBlocklistService); 1.156 + 1.157 + AddonManager.getAddonsByIDs(addonIDs, 1.158 + function([a1, a2, a3, a4]) { 1.159 + // No info in blocklist, shouldn't be blocked 1.160 + do_check_false(blocklist.isAddonBlocklisted(a1, null, null)); 1.161 + 1.162 + // All these should be blocklisted for the current app. 1.163 + do_check_true(blocklist.isAddonBlocklisted(a2, null, null)); 1.164 + do_check_true(blocklist.isAddonBlocklisted(a3, null, null)); 1.165 + do_check_true(blocklist.isAddonBlocklisted(a4, null, null)); 1.166 + 1.167 + end_test(); 1.168 + }); 1.169 + }); 1.170 +}