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: const PREF_MATCH_OS_LOCALE = "intl.locale.matchOS"; michael@0: const PREF_SELECTED_LOCALE = "general.useragent.locale"; michael@0: michael@0: // Disables security checking our updates which haven't been signed michael@0: Services.prefs.setBoolPref("extensions.checkUpdateSecurity", false); michael@0: michael@0: const Ci = Components.interfaces; michael@0: const Cu = Components.utils; michael@0: michael@0: Cu.import("resource://testing-common/httpd.js"); michael@0: michael@0: // This is the data we expect to see sent as part of the update url. michael@0: var EXPECTED = [ michael@0: { michael@0: id: "bug335238_1@tests.mozilla.org", michael@0: version: "1.3.4", michael@0: maxAppVersion: "5", michael@0: status: "userEnabled", michael@0: appId: "xpcshell@tests.mozilla.org", michael@0: appVersion: "1", michael@0: appOs: "XPCShell", michael@0: appAbi: "noarch-spidermonkey", michael@0: locale: "en-US", michael@0: reqVersion: "2" michael@0: }, michael@0: { michael@0: id: "bug335238_2@tests.mozilla.org", michael@0: version: "28at", michael@0: maxAppVersion: "7", michael@0: status: "userDisabled", michael@0: appId: "xpcshell@tests.mozilla.org", michael@0: appVersion: "1", michael@0: appOs: "XPCShell", michael@0: appAbi: "noarch-spidermonkey", michael@0: locale: "en-US", michael@0: reqVersion: "2" michael@0: }, michael@0: { michael@0: id: "bug335238_3@tests.mozilla.org", michael@0: version: "58", michael@0: maxAppVersion: "*", michael@0: status: "userDisabled,softblocked", michael@0: appId: "xpcshell@tests.mozilla.org", michael@0: appVersion: "1", michael@0: appOs: "XPCShell", michael@0: appAbi: "noarch-spidermonkey", michael@0: locale: "en-US", michael@0: reqVersion: "2" michael@0: }, michael@0: { michael@0: id: "bug335238_4@tests.mozilla.org", michael@0: version: "4", michael@0: maxAppVersion: "2+", michael@0: status: "userEnabled,blocklisted", michael@0: appId: "xpcshell@tests.mozilla.org", michael@0: appVersion: "1", michael@0: appOs: "XPCShell", michael@0: appAbi: "noarch-spidermonkey", michael@0: locale: "en-US", michael@0: reqVersion: "2" michael@0: } michael@0: ]; michael@0: michael@0: var ADDONS = [ michael@0: {id: "bug335238_1@tests.mozilla.org", michael@0: addon: "test_bug335238_1"}, michael@0: {id: "bug335238_2@tests.mozilla.org", michael@0: addon: "test_bug335238_2"}, michael@0: {id: "bug335238_3@tests.mozilla.org", michael@0: addon: "test_bug335238_3"}, michael@0: {id: "bug335238_4@tests.mozilla.org", michael@0: addon: "test_bug335238_4"} michael@0: ]; michael@0: michael@0: // This is a replacement for the blocklist service michael@0: var BlocklistService = { michael@0: getAddonBlocklistState: function(aAddon, aAppVersion, aToolkitVersion) { michael@0: if (aAddon.id == "bug335238_3@tests.mozilla.org") michael@0: return Ci.nsIBlocklistService.STATE_SOFTBLOCKED; michael@0: if (aAddon.id == "bug335238_4@tests.mozilla.org") michael@0: return Ci.nsIBlocklistService.STATE_BLOCKED; michael@0: return Ci.nsIBlocklistService.STATE_NOT_BLOCKED; michael@0: }, michael@0: michael@0: getPluginBlocklistState: function(aPlugin, aVersion, aAppVersion, aToolkitVersion) { michael@0: return Ci.nsIBlocklistService.STATE_NOT_BLOCKED; michael@0: }, michael@0: michael@0: isAddonBlocklisted: function(aAddon, aAppVersion, aToolkitVersion) { michael@0: return this.getAddonBlocklistState(aAddon, aAppVersion, aToolkitVersion) == michael@0: Ci.nsIBlocklistService.STATE_BLOCKED; michael@0: }, michael@0: michael@0: QueryInterface: function(iid) { michael@0: if (iid.equals(Ci.nsIBlocklistService) michael@0: || iid.equals(Ci.nsISupports)) michael@0: return this; michael@0: michael@0: throw Components.results.NS_ERROR_NO_INTERFACE; michael@0: } michael@0: }; michael@0: michael@0: var BlocklistServiceFactory = { michael@0: createInstance: function (outer, iid) { michael@0: if (outer != null) michael@0: throw Components.results.NS_ERROR_NO_AGGREGATION; michael@0: return BlocklistService.QueryInterface(iid); michael@0: } michael@0: }; michael@0: var registrar = Components.manager.QueryInterface(Ci.nsIComponentRegistrar); michael@0: registrar.registerFactory(Components.ID("{61189e7a-6b1b-44b8-ac81-f180a6105085}"), "BlocklistService", michael@0: "@mozilla.org/extensions/blocklist;1", BlocklistServiceFactory); michael@0: michael@0: var server; michael@0: michael@0: var updateListener = { michael@0: pendingCount: 0, michael@0: michael@0: onUpdateAvailable: function(aAddon) { michael@0: do_throw("Should not have seen an update for " + aAddon.id); michael@0: }, michael@0: michael@0: onUpdateFinished: function() { michael@0: if (--this.pendingCount == 0) michael@0: server.stop(do_test_finished); michael@0: } michael@0: } michael@0: michael@0: var requestHandler = { michael@0: handle: function(metadata, response) michael@0: { michael@0: var expected = EXPECTED[metadata.path.substring(1)]; michael@0: var params = metadata.queryString.split("&"); michael@0: do_check_eq(params.length, 10); michael@0: for (var k in params) { michael@0: var pair = params[k].split("="); michael@0: var name = decodeURIComponent(pair[0]); michael@0: var value = decodeURIComponent(pair[1]); michael@0: do_check_eq(expected[name], value); michael@0: } michael@0: response.setStatusLine(metadata.httpVersion, 404, "Not Found"); michael@0: } michael@0: } michael@0: michael@0: function run_test() { michael@0: do_test_pending(); michael@0: createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9"); michael@0: michael@0: server = new HttpServer(); michael@0: server.registerPathHandler("/0", requestHandler); michael@0: server.registerPathHandler("/1", requestHandler); michael@0: server.registerPathHandler("/2", requestHandler); michael@0: server.registerPathHandler("/3", requestHandler); michael@0: server.start(4444); michael@0: michael@0: Services.prefs.setBoolPref(PREF_MATCH_OS_LOCALE, false); michael@0: Services.prefs.setCharPref(PREF_SELECTED_LOCALE, "en-US"); michael@0: michael@0: startupManager(); michael@0: installAllFiles([do_get_addon(a.addon) for each (a in ADDONS)], function() { michael@0: michael@0: restartManager(); michael@0: AddonManager.getAddonByID(ADDONS[1].id, callback_soon(function(addon) { michael@0: do_check_true(!(!addon)); michael@0: addon.userDisabled = true; michael@0: restartManager(); michael@0: michael@0: AddonManager.getAddonsByIDs([a.id for each (a in ADDONS)], function(installedItems) { michael@0: installedItems.forEach(function(item) { michael@0: updateListener.pendingCount++; michael@0: item.findUpdates(updateListener, AddonManager.UPDATE_WHEN_USER_REQUESTED); michael@0: }); michael@0: }); michael@0: })); michael@0: }); michael@0: }