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 BLOCKLIST_TIMER = "blocklist-background-update-timer"; michael@0: const PREF_BLOCKLIST_URL = "extensions.blocklist.url"; michael@0: const PREF_BLOCKLIST_ENABLED = "extensions.blocklist.enabled"; michael@0: const PREF_APP_DISTRIBUTION = "distribution.id"; michael@0: const PREF_APP_DISTRIBUTION_VERSION = "distribution.version"; michael@0: const PREF_APP_UPDATE_CHANNEL = "app.update.channel"; michael@0: const PREF_GENERAL_USERAGENT_LOCALE = "general.useragent.locale"; michael@0: const CATEGORY_UPDATE_TIMER = "update-timer"; michael@0: michael@0: // Get the HTTP server. michael@0: Components.utils.import("resource://testing-common/httpd.js"); michael@0: var testserver; michael@0: var gOSVersion; michael@0: var gBlocklist; michael@0: michael@0: // This is a replacement for the timer service so we can trigger timers michael@0: var timerService = { michael@0: michael@0: hasTimer: function(id) { michael@0: var catMan = Components.classes["@mozilla.org/categorymanager;1"] michael@0: .getService(Components.interfaces.nsICategoryManager); michael@0: var entries = catMan.enumerateCategory(CATEGORY_UPDATE_TIMER); michael@0: while (entries.hasMoreElements()) { michael@0: var entry = entries.getNext().QueryInterface(Components.interfaces.nsISupportsCString).data; michael@0: var value = catMan.getCategoryEntry(CATEGORY_UPDATE_TIMER, entry); michael@0: var timerID = value.split(",")[2]; michael@0: if (id == timerID) { michael@0: return true; michael@0: } michael@0: } michael@0: return false; michael@0: }, michael@0: michael@0: fireTimer: function(id) { michael@0: gBlocklist.QueryInterface(Components.interfaces.nsITimerCallback).notify(null); michael@0: }, michael@0: michael@0: QueryInterface: function(iid) { michael@0: if (iid.equals(Components.interfaces.nsIUpdateTimerManager) michael@0: || iid.equals(Components.interfaces.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 TimerServiceFactory = { michael@0: createInstance: function (outer, iid) { michael@0: if (outer != null) michael@0: throw Components.results.NS_ERROR_NO_AGGREGATION; michael@0: return timerService.QueryInterface(iid); michael@0: } michael@0: }; michael@0: var registrar = Components.manager.QueryInterface(Components.interfaces.nsIComponentRegistrar); michael@0: registrar.registerFactory(Components.ID("{61189e7a-6b1b-44b8-ac81-f180a6105085}"), "TimerService", michael@0: "@mozilla.org/updates/timer-manager;1", TimerServiceFactory); michael@0: michael@0: function failHandler(metadata, response) { michael@0: do_throw("Should not have attempted to retrieve the blocklist when it is disabled"); michael@0: } michael@0: michael@0: function pathHandler(metadata, response) { michael@0: var ABI = "noarch-spidermonkey"; michael@0: // the blacklist service special-cases ABI for Universal binaries, michael@0: // so do the same here. michael@0: if ("@mozilla.org/xpcom/mac-utils;1" in Components.classes) { michael@0: var macutils = Components.classes["@mozilla.org/xpcom/mac-utils;1"] michael@0: .getService(Components.interfaces.nsIMacUtils); michael@0: if (macutils.isUniversalBinary) michael@0: ABI += "-u-" + macutils.architecturesInBinary; michael@0: } michael@0: do_check_eq(metadata.queryString, michael@0: "xpcshell@tests.mozilla.org&1&XPCShell&1&2007010101&" + michael@0: "XPCShell_" + ABI + "&locale&updatechannel&" + michael@0: gOSVersion + "&1.9&distribution&distribution-version"); michael@0: gBlocklist.observe(null, "quit-application", ""); michael@0: gBlocklist.observe(null, "xpcom-shutdown", ""); michael@0: testserver.stop(do_test_finished); michael@0: } michael@0: michael@0: function run_test() { michael@0: var osVersion; michael@0: var sysInfo = Components.classes["@mozilla.org/system-info;1"] michael@0: .getService(Components.interfaces.nsIPropertyBag2); michael@0: try { michael@0: osVersion = sysInfo.getProperty("name") + " " + sysInfo.getProperty("version"); michael@0: if (osVersion) { michael@0: try { michael@0: osVersion += " (" + sysInfo.getProperty("secondaryLibrary") + ")"; michael@0: } michael@0: catch (e) { michael@0: } michael@0: gOSVersion = encodeURIComponent(osVersion); michael@0: } michael@0: } michael@0: catch (e) { michael@0: } michael@0: michael@0: createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9"); michael@0: michael@0: testserver = new HttpServer(); michael@0: testserver.registerPathHandler("/1", failHandler); michael@0: testserver.registerPathHandler("/2", pathHandler); michael@0: testserver.start(-1); michael@0: gPort = testserver.identity.primaryPort; michael@0: michael@0: // Initialise the blocklist service michael@0: gBlocklist = Components.classes["@mozilla.org/extensions/blocklist;1"] michael@0: .getService(Components.interfaces.nsIBlocklistService) michael@0: .QueryInterface(Components.interfaces.nsIObserver); michael@0: gBlocklist.observe(null, "profile-after-change", ""); michael@0: michael@0: do_check_true(timerService.hasTimer(BLOCKLIST_TIMER)); michael@0: michael@0: do_test_pending(); michael@0: michael@0: // This should have no effect as the blocklist is disabled michael@0: Services.prefs.setCharPref(PREF_BLOCKLIST_URL, "http://localhost:" + gPort + "/1"); michael@0: Services.prefs.setBoolPref(PREF_BLOCKLIST_ENABLED, false); michael@0: timerService.fireTimer(BLOCKLIST_TIMER); michael@0: michael@0: // Some values have to be on the default branch to work michael@0: var defaults = Services.prefs.QueryInterface(Components.interfaces.nsIPrefService) michael@0: .getDefaultBranch(null); michael@0: defaults.setCharPref(PREF_APP_UPDATE_CHANNEL, "updatechannel"); michael@0: defaults.setCharPref(PREF_APP_DISTRIBUTION, "distribution"); michael@0: defaults.setCharPref(PREF_APP_DISTRIBUTION_VERSION, "distribution-version"); michael@0: defaults.setCharPref(PREF_GENERAL_USERAGENT_LOCALE, "locale"); michael@0: michael@0: // This should correctly escape everything michael@0: Services.prefs.setCharPref(PREF_BLOCKLIST_URL, "http://localhost:" + gPort + "/2?" + michael@0: "%APP_ID%&%APP_VERSION%&%PRODUCT%&%VERSION%&%BUILD_ID%&" + michael@0: "%BUILD_TARGET%&%LOCALE%&%CHANNEL%&" + michael@0: "%OS_VERSION%&%PLATFORM_VERSION%&%DISTRIBUTION%&%DISTRIBUTION_VERSION%"); michael@0: Services.prefs.setBoolPref(PREF_BLOCKLIST_ENABLED, true); michael@0: timerService.fireTimer(BLOCKLIST_TIMER); michael@0: }