michael@0: const CLASS_ID = Components.ID("{12345678-1234-1234-1234-123456789abc}"); michael@0: const CONTRACT_ID = "@mozilla.org/test-parameter-source;1"; michael@0: michael@0: // Get and create the HTTP server. michael@0: Components.utils.import("resource://testing-common/httpd.js"); michael@0: var testserver = new HttpServer(); michael@0: testserver.start(-1); michael@0: gPort = testserver.identity.primaryPort; michael@0: michael@0: var gTestURL = "http://127.0.0.1:" + gPort + "/update.rdf?itemID=%ITEM_ID%&custom1=%CUSTOM1%&custom2=%CUSTOM2%"; michael@0: var gExpectedQuery = "itemID=test@mozilla.org&custom1=custom_parameter_1&custom2=custom_parameter_2"; michael@0: var gSeenExpectedURL = false; michael@0: michael@0: var gComponentRegistrar = Components.manager.QueryInterface(AM_Ci.nsIComponentRegistrar); michael@0: var gCategoryManager = AM_Cc["@mozilla.org/categorymanager;1"].getService(AM_Ci.nsICategoryManager); michael@0: michael@0: // Factory for our parameter handler michael@0: var paramHandlerFactory = { michael@0: QueryInterface: function(iid) { michael@0: if (iid.equals(AM_Ci.nsIFactory) || iid.equals(AM_Ci.nsISupports)) michael@0: return this; michael@0: michael@0: throw Components.results.NS_ERROR_NO_INTERFACE; michael@0: }, michael@0: michael@0: createInstance: function(outer, iid) { michael@0: var bag = AM_Cc["@mozilla.org/hash-property-bag;1"]. michael@0: createInstance(AM_Ci.nsIWritablePropertyBag); michael@0: bag.setProperty("CUSTOM1", "custom_parameter_1"); michael@0: bag.setProperty("CUSTOM2", "custom_parameter_2"); michael@0: return bag.QueryInterface(iid); michael@0: } michael@0: }; michael@0: michael@0: function initTest() michael@0: { michael@0: do_test_pending(); michael@0: // Setup extension manager michael@0: createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9"); michael@0: michael@0: // Configure the HTTP server. michael@0: testserver.registerPathHandler("/update.rdf", function(aRequest, aResponse) { michael@0: gSeenExpectedURL = aRequest.queryString == gExpectedQuery; michael@0: aResponse.setStatusLine(null, 404, "Not Found"); michael@0: }); michael@0: michael@0: // Register our parameter handlers michael@0: gComponentRegistrar.registerFactory(CLASS_ID, "Test component", CONTRACT_ID, paramHandlerFactory); michael@0: gCategoryManager.addCategoryEntry("extension-update-params", "CUSTOM1", CONTRACT_ID, false, false); michael@0: gCategoryManager.addCategoryEntry("extension-update-params", "CUSTOM2", CONTRACT_ID, false, false); michael@0: michael@0: // Install a test extension into the profile michael@0: let dir = gProfD.clone(); michael@0: dir.append("extensions"); michael@0: writeInstallRDFForExtension({ michael@0: id: "test@mozilla.org", michael@0: version: "1.0", michael@0: name: "Test extension", michael@0: updateURL: gTestURL, michael@0: targetApplications: [{ michael@0: id: "xpcshell@tests.mozilla.org", michael@0: minVersion: "1", michael@0: maxVersion: "1" michael@0: }], michael@0: }, dir); michael@0: michael@0: startupManager(); michael@0: } michael@0: michael@0: function shutdownTest() michael@0: { michael@0: shutdownManager(); michael@0: michael@0: gComponentRegistrar.unregisterFactory(CLASS_ID, paramHandlerFactory); michael@0: gCategoryManager.deleteCategoryEntry("extension-update-params", "CUSTOM1", false); michael@0: gCategoryManager.deleteCategoryEntry("extension-update-params", "CUSTOM2", false); michael@0: michael@0: do_test_finished(); michael@0: } michael@0: michael@0: function run_test() michael@0: { michael@0: initTest(); michael@0: michael@0: AddonManager.getAddonByID("test@mozilla.org", function(item) { michael@0: // Initiate update michael@0: item.findUpdates({ michael@0: onCompatibilityUpdateAvailable: function(addon) { michael@0: do_throw("Should not have seen a compatibility update"); michael@0: }, michael@0: michael@0: onUpdateAvailable: function(addon, install) { michael@0: do_throw("Should not have seen an available update"); michael@0: }, michael@0: michael@0: onUpdateFinished: function(addon, error) { michael@0: do_check_eq(error, AddonManager.UPDATE_STATUS_DOWNLOAD_ERROR); michael@0: do_check_true(gSeenExpectedURL); michael@0: do_execute_soon(shutdownTest); michael@0: } michael@0: }, AddonManager.UPDATE_WHEN_USER_REQUESTED); michael@0: }); michael@0: }