michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. michael@0: */ michael@0: michael@0: let addonIDs = ["test_bug393285_1@tests.mozilla.org", michael@0: "test_bug393285_2@tests.mozilla.org", michael@0: "test_bug393285_3a@tests.mozilla.org", michael@0: "test_bug393285_4@tests.mozilla.org"]; michael@0: michael@0: const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components; michael@0: michael@0: const URI_EXTENSION_BLOCKLIST_DIALOG = "chrome://mozapps/content/extensions/blocklist.xul"; michael@0: michael@0: Cu.import("resource://testing-common/httpd.js"); michael@0: var testserver = new HttpServer(); michael@0: testserver.start(-1); michael@0: gPort = testserver.identity.primaryPort; michael@0: michael@0: // register static files with server and interpolate port numbers in them michael@0: mapFile("/data/test_bug393285.xml", testserver); michael@0: michael@0: const profileDir = gProfD.clone(); michael@0: profileDir.append("extensions"); michael@0: michael@0: // A window watcher to deal with the blocklist UI dialog. michael@0: var WindowWatcher = { michael@0: openWindow: function(parent, url, name, features, arguments) { michael@0: // Should be called to list the newly blocklisted items michael@0: do_check_eq(url, URI_EXTENSION_BLOCKLIST_DIALOG); michael@0: michael@0: // Simulate auto-disabling any softblocks michael@0: var list = arguments.wrappedJSObject.list; michael@0: list.forEach(function(aItem) { michael@0: if (!aItem.blocked) michael@0: aItem.disable = true; michael@0: }); michael@0: michael@0: //run the code after the blocklist is closed michael@0: Services.obs.notifyObservers(null, "addon-blocklist-closed", null); michael@0: michael@0: }, michael@0: michael@0: QueryInterface: function(iid) { michael@0: if (iid.equals(Ci.nsIWindowWatcher) michael@0: || iid.equals(Ci.nsISupports)) michael@0: return this; michael@0: michael@0: throw Cr.NS_ERROR_NO_INTERFACE; michael@0: } michael@0: }; michael@0: michael@0: var WindowWatcherFactory = { michael@0: createInstance: function createInstance(outer, iid) { michael@0: if (outer != null) michael@0: throw Cr.NS_ERROR_NO_AGGREGATION; michael@0: return WindowWatcher.QueryInterface(iid); michael@0: } michael@0: }; michael@0: michael@0: var registrar = Components.manager.QueryInterface(Ci.nsIComponentRegistrar); michael@0: registrar.registerFactory(Components.ID("{1dfeb90a-2193-45d5-9cb8-864928b2af55}"), michael@0: "Fake Window Watcher", michael@0: "@mozilla.org/embedcomp/window-watcher;1", michael@0: WindowWatcherFactory); michael@0: michael@0: michael@0: function load_blocklist(aFile, aCallback) { michael@0: Services.obs.addObserver(function() { michael@0: Services.obs.removeObserver(arguments.callee, "blocklist-updated"); michael@0: michael@0: do_execute_soon(aCallback); michael@0: }, "blocklist-updated", false); michael@0: michael@0: Services.prefs.setCharPref("extensions.blocklist.url", "http://localhost:" + michael@0: gPort + "/data/" + aFile); michael@0: var blocklist = Cc["@mozilla.org/extensions/blocklist;1"]. michael@0: getService(Ci.nsITimerCallback); michael@0: blocklist.notify(null); michael@0: } michael@0: michael@0: michael@0: function end_test() { michael@0: testserver.stop(do_test_finished); michael@0: } michael@0: michael@0: function run_test() { michael@0: do_test_pending(); michael@0: michael@0: createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9"); michael@0: michael@0: writeInstallRDFForExtension({ michael@0: id: "test_bug393285_1@tests.mozilla.org", michael@0: name: "extension 1", michael@0: version: "1.0", michael@0: targetApplications: [{ michael@0: id: "xpcshell@tests.mozilla.org", michael@0: minVersion: "1", michael@0: maxVersion: "3" michael@0: }] michael@0: }, profileDir); michael@0: michael@0: michael@0: writeInstallRDFForExtension({ michael@0: id: "test_bug393285_2@tests.mozilla.org", michael@0: name: "extension 2", michael@0: version: "1.0", michael@0: targetApplications: [{ michael@0: id: "xpcshell@tests.mozilla.org", michael@0: minVersion: "1", michael@0: maxVersion: "3" michael@0: }] michael@0: }, profileDir); michael@0: michael@0: writeInstallRDFForExtension({ michael@0: id: "test_bug393285_3a@tests.mozilla.org", michael@0: name: "extension 3a", michael@0: version: "1.0", michael@0: targetApplications: [{ michael@0: id: "xpcshell@tests.mozilla.org", michael@0: minVersion: "1", michael@0: maxVersion: "3" michael@0: }] michael@0: }, profileDir); michael@0: michael@0: writeInstallRDFForExtension({ michael@0: id: "test_bug393285_4@tests.mozilla.org", michael@0: name: "extension 4", michael@0: version: "1.0", michael@0: targetApplications: [{ michael@0: id: "xpcshell@tests.mozilla.org", michael@0: minVersion: "1", michael@0: maxVersion: "3" michael@0: }] michael@0: }, profileDir); michael@0: michael@0: startupManager(); michael@0: michael@0: AddonManager.getAddonsByIDs(addonIDs, function(addons) { michael@0: for (addon of addons) { michael@0: do_check_eq(addon.blocklistState, Ci.nsIBlocklistService.STATE_NOT_BLOCKED); michael@0: } michael@0: run_test_1(); michael@0: }); michael@0: } michael@0: michael@0: function run_test_1() { michael@0: load_blocklist("test_bug393285.xml", function() { michael@0: restartManager(); michael@0: michael@0: var blocklist = Cc["@mozilla.org/extensions/blocklist;1"] michael@0: .getService(Ci.nsIBlocklistService); michael@0: michael@0: AddonManager.getAddonsByIDs(addonIDs, michael@0: function([a1, a2, a3, a4]) { michael@0: // No info in blocklist, shouldn't be blocked michael@0: do_check_false(blocklist.isAddonBlocklisted(a1, null, null)); michael@0: michael@0: // All these should be blocklisted for the current app. michael@0: do_check_true(blocklist.isAddonBlocklisted(a2, null, null)); michael@0: do_check_true(blocklist.isAddonBlocklisted(a3, null, null)); michael@0: do_check_true(blocklist.isAddonBlocklisted(a4, null, null)); michael@0: michael@0: end_test(); michael@0: }); michael@0: }); michael@0: }