michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: * http://creativecommons.org/publicdomain/zero/1.0/ michael@0: */ michael@0: michael@0: Components.utils.import("resource://testing-common/httpd.js"); michael@0: var gServer = new HttpServer(); michael@0: gServer.start(-1); michael@0: michael@0: const PREF_GETADDONS_CACHE_ENABLED = "extensions.getAddons.cache.enabled"; michael@0: michael@0: const PORT = gServer.identity.primaryPort; michael@0: const BASE_URL = "http://localhost:" + PORT; michael@0: const DEFAULT_URL = "about:blank"; michael@0: michael@0: var addon = { michael@0: id: "addon@tests.mozilla.org", michael@0: version: "1.0", michael@0: name: "Test", michael@0: targetApplications: [{ michael@0: id: "xpcshell@tests.mozilla.org", michael@0: minVersion: "1", michael@0: maxVersion: "1" michael@0: }] michael@0: }; michael@0: michael@0: const profileDir = gProfD.clone(); michael@0: profileDir.append("extensions"); michael@0: michael@0: function backgroundUpdate(aCallback) { michael@0: Services.obs.addObserver(function() { michael@0: Services.obs.removeObserver(arguments.callee, "addons-background-update-complete"); michael@0: aCallback(); michael@0: }, "addons-background-update-complete", false); michael@0: michael@0: AddonManagerPrivate.backgroundUpdateCheck(); michael@0: } michael@0: michael@0: function run_test() { michael@0: do_test_pending(); michael@0: michael@0: mapUrlToFile("/cache.xml", do_get_file("data/test_sourceURI.xml"), gServer); michael@0: Services.prefs.setCharPref(PREF_GETADDONS_BYIDS, BASE_URL + "/cache.xml"); michael@0: Services.prefs.setCharPref(PREF_GETADDONS_BYIDS_PERFORMANCE, BASE_URL + "/cache.xml"); michael@0: Services.prefs.setBoolPref(PREF_GETADDONS_CACHE_ENABLED, true); michael@0: michael@0: createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1"); michael@0: writeInstallRDFForExtension(addon, profileDir); michael@0: startupManager(); michael@0: michael@0: AddonManager.getAddonByID("addon@tests.mozilla.org", function(a) { michael@0: do_check_neq(a, null); michael@0: do_check_eq(a.sourceURI, null); michael@0: michael@0: backgroundUpdate(function() { michael@0: restartManager(); michael@0: michael@0: AddonManager.getAddonByID("addon@tests.mozilla.org", function(a) { michael@0: do_check_neq(a, null); michael@0: do_check_neq(a.sourceURI, null); michael@0: do_check_eq(a.sourceURI.spec, "http://www.example.com/testaddon.xpi"); michael@0: michael@0: do_test_finished(); michael@0: }); michael@0: }); michael@0: }); michael@0: }