|
1 const CLASS_ID = Components.ID("{12345678-1234-1234-1234-123456789abc}"); |
|
2 const CONTRACT_ID = "@mozilla.org/test-parameter-source;1"; |
|
3 |
|
4 // Get and create the HTTP server. |
|
5 Components.utils.import("resource://testing-common/httpd.js"); |
|
6 var testserver = new HttpServer(); |
|
7 testserver.start(-1); |
|
8 gPort = testserver.identity.primaryPort; |
|
9 |
|
10 var gTestURL = "http://127.0.0.1:" + gPort + "/update.rdf?itemID=%ITEM_ID%&custom1=%CUSTOM1%&custom2=%CUSTOM2%"; |
|
11 var gExpectedQuery = "itemID=test@mozilla.org&custom1=custom_parameter_1&custom2=custom_parameter_2"; |
|
12 var gSeenExpectedURL = false; |
|
13 |
|
14 var gComponentRegistrar = Components.manager.QueryInterface(AM_Ci.nsIComponentRegistrar); |
|
15 var gCategoryManager = AM_Cc["@mozilla.org/categorymanager;1"].getService(AM_Ci.nsICategoryManager); |
|
16 |
|
17 // Factory for our parameter handler |
|
18 var paramHandlerFactory = { |
|
19 QueryInterface: function(iid) { |
|
20 if (iid.equals(AM_Ci.nsIFactory) || iid.equals(AM_Ci.nsISupports)) |
|
21 return this; |
|
22 |
|
23 throw Components.results.NS_ERROR_NO_INTERFACE; |
|
24 }, |
|
25 |
|
26 createInstance: function(outer, iid) { |
|
27 var bag = AM_Cc["@mozilla.org/hash-property-bag;1"]. |
|
28 createInstance(AM_Ci.nsIWritablePropertyBag); |
|
29 bag.setProperty("CUSTOM1", "custom_parameter_1"); |
|
30 bag.setProperty("CUSTOM2", "custom_parameter_2"); |
|
31 return bag.QueryInterface(iid); |
|
32 } |
|
33 }; |
|
34 |
|
35 function initTest() |
|
36 { |
|
37 do_test_pending(); |
|
38 // Setup extension manager |
|
39 createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9"); |
|
40 |
|
41 // Configure the HTTP server. |
|
42 testserver.registerPathHandler("/update.rdf", function(aRequest, aResponse) { |
|
43 gSeenExpectedURL = aRequest.queryString == gExpectedQuery; |
|
44 aResponse.setStatusLine(null, 404, "Not Found"); |
|
45 }); |
|
46 |
|
47 // Register our parameter handlers |
|
48 gComponentRegistrar.registerFactory(CLASS_ID, "Test component", CONTRACT_ID, paramHandlerFactory); |
|
49 gCategoryManager.addCategoryEntry("extension-update-params", "CUSTOM1", CONTRACT_ID, false, false); |
|
50 gCategoryManager.addCategoryEntry("extension-update-params", "CUSTOM2", CONTRACT_ID, false, false); |
|
51 |
|
52 // Install a test extension into the profile |
|
53 let dir = gProfD.clone(); |
|
54 dir.append("extensions"); |
|
55 writeInstallRDFForExtension({ |
|
56 id: "test@mozilla.org", |
|
57 version: "1.0", |
|
58 name: "Test extension", |
|
59 updateURL: gTestURL, |
|
60 targetApplications: [{ |
|
61 id: "xpcshell@tests.mozilla.org", |
|
62 minVersion: "1", |
|
63 maxVersion: "1" |
|
64 }], |
|
65 }, dir); |
|
66 |
|
67 startupManager(); |
|
68 } |
|
69 |
|
70 function shutdownTest() |
|
71 { |
|
72 shutdownManager(); |
|
73 |
|
74 gComponentRegistrar.unregisterFactory(CLASS_ID, paramHandlerFactory); |
|
75 gCategoryManager.deleteCategoryEntry("extension-update-params", "CUSTOM1", false); |
|
76 gCategoryManager.deleteCategoryEntry("extension-update-params", "CUSTOM2", false); |
|
77 |
|
78 do_test_finished(); |
|
79 } |
|
80 |
|
81 function run_test() |
|
82 { |
|
83 initTest(); |
|
84 |
|
85 AddonManager.getAddonByID("test@mozilla.org", function(item) { |
|
86 // Initiate update |
|
87 item.findUpdates({ |
|
88 onCompatibilityUpdateAvailable: function(addon) { |
|
89 do_throw("Should not have seen a compatibility update"); |
|
90 }, |
|
91 |
|
92 onUpdateAvailable: function(addon, install) { |
|
93 do_throw("Should not have seen an available update"); |
|
94 }, |
|
95 |
|
96 onUpdateFinished: function(addon, error) { |
|
97 do_check_eq(error, AddonManager.UPDATE_STATUS_DOWNLOAD_ERROR); |
|
98 do_check_true(gSeenExpectedURL); |
|
99 do_execute_soon(shutdownTest); |
|
100 } |
|
101 }, AddonManager.UPDATE_WHEN_USER_REQUESTED); |
|
102 }); |
|
103 } |