|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 * http://creativecommons.org/publicdomain/zero/1.0/ |
|
3 */ |
|
4 |
|
5 Components.utils.import("resource://testing-common/httpd.js"); |
|
6 var gServer = new HttpServer(); |
|
7 gServer.start(-1); |
|
8 |
|
9 const PREF_GETADDONS_CACHE_ENABLED = "extensions.getAddons.cache.enabled"; |
|
10 |
|
11 const PORT = gServer.identity.primaryPort; |
|
12 const BASE_URL = "http://localhost:" + PORT; |
|
13 const DEFAULT_URL = "about:blank"; |
|
14 |
|
15 var addon = { |
|
16 id: "addon@tests.mozilla.org", |
|
17 version: "1.0", |
|
18 name: "Test", |
|
19 targetApplications: [{ |
|
20 id: "xpcshell@tests.mozilla.org", |
|
21 minVersion: "1", |
|
22 maxVersion: "1" |
|
23 }] |
|
24 }; |
|
25 |
|
26 const profileDir = gProfD.clone(); |
|
27 profileDir.append("extensions"); |
|
28 |
|
29 function backgroundUpdate(aCallback) { |
|
30 Services.obs.addObserver(function() { |
|
31 Services.obs.removeObserver(arguments.callee, "addons-background-update-complete"); |
|
32 aCallback(); |
|
33 }, "addons-background-update-complete", false); |
|
34 |
|
35 AddonManagerPrivate.backgroundUpdateCheck(); |
|
36 } |
|
37 |
|
38 function run_test() { |
|
39 do_test_pending(); |
|
40 |
|
41 mapUrlToFile("/cache.xml", do_get_file("data/test_sourceURI.xml"), gServer); |
|
42 Services.prefs.setCharPref(PREF_GETADDONS_BYIDS, BASE_URL + "/cache.xml"); |
|
43 Services.prefs.setCharPref(PREF_GETADDONS_BYIDS_PERFORMANCE, BASE_URL + "/cache.xml"); |
|
44 Services.prefs.setBoolPref(PREF_GETADDONS_CACHE_ENABLED, true); |
|
45 |
|
46 createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1"); |
|
47 writeInstallRDFForExtension(addon, profileDir); |
|
48 startupManager(); |
|
49 |
|
50 AddonManager.getAddonByID("addon@tests.mozilla.org", function(a) { |
|
51 do_check_neq(a, null); |
|
52 do_check_eq(a.sourceURI, null); |
|
53 |
|
54 backgroundUpdate(function() { |
|
55 restartManager(); |
|
56 |
|
57 AddonManager.getAddonByID("addon@tests.mozilla.org", function(a) { |
|
58 do_check_neq(a, null); |
|
59 do_check_neq(a.sourceURI, null); |
|
60 do_check_eq(a.sourceURI.spec, "http://www.example.com/testaddon.xpi"); |
|
61 |
|
62 do_test_finished(); |
|
63 }); |
|
64 }); |
|
65 }); |
|
66 } |