2007-08-15 00:49:12 -07:00
|
|
|
const CLASS_ID = Components.ID("{12345678-1234-1234-1234-123456789abc}");
|
|
|
|
const CONTRACT_ID = "@mozilla.org/test-parameter-source;1";
|
|
|
|
|
2010-10-26 10:47:31 -07:00
|
|
|
var gTestURL = "http://127.0.0.1:4444/update.rdf?itemID=%ITEM_ID%&custom1=%CUSTOM1%&custom2=%CUSTOM2%";
|
|
|
|
var gExpectedQuery = "itemID=test@mozilla.org&custom1=custom_parameter_1&custom2=custom_parameter_2";
|
2007-08-15 00:49:12 -07:00
|
|
|
var gSeenExpectedURL = false;
|
|
|
|
|
2010-10-26 10:47:31 -07:00
|
|
|
var gComponentRegistrar = Components.manager.QueryInterface(AM_Ci.nsIComponentRegistrar);
|
|
|
|
var gCategoryManager = AM_Cc["@mozilla.org/categorymanager;1"].getService(AM_Ci.nsICategoryManager);
|
|
|
|
|
|
|
|
// Get the HTTP server.
|
|
|
|
do_load_httpd_js();
|
|
|
|
var testserver;
|
2007-08-15 00:49:12 -07:00
|
|
|
|
|
|
|
// Factory for our parameter handler
|
|
|
|
var paramHandlerFactory = {
|
|
|
|
QueryInterface: function(iid) {
|
2010-10-26 10:47:31 -07:00
|
|
|
if (iid.equals(AM_Ci.nsIFactory) || iid.equals(AM_Ci.nsISupports))
|
2007-08-15 00:49:12 -07:00
|
|
|
return this;
|
|
|
|
|
|
|
|
throw Components.results.NS_ERROR_NO_INTERFACE;
|
|
|
|
},
|
|
|
|
|
|
|
|
createInstance: function(outer, iid) {
|
2010-10-26 10:47:31 -07:00
|
|
|
var bag = AM_Cc["@mozilla.org/hash-property-bag;1"].
|
|
|
|
createInstance(AM_Ci.nsIWritablePropertyBag);
|
2007-08-15 00:49:12 -07:00
|
|
|
bag.setProperty("CUSTOM1", "custom_parameter_1");
|
|
|
|
bag.setProperty("CUSTOM2", "custom_parameter_2");
|
|
|
|
return bag.QueryInterface(iid);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
function initTest()
|
|
|
|
{
|
2010-04-28 11:49:56 -07:00
|
|
|
do_test_pending();
|
2007-08-15 00:49:12 -07:00
|
|
|
// Setup extension manager
|
2007-08-29 01:16:15 -07:00
|
|
|
createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9");
|
2007-08-15 00:49:12 -07:00
|
|
|
|
2010-10-26 10:47:31 -07:00
|
|
|
// Create and configure the HTTP server.
|
|
|
|
testserver = new nsHttpServer();
|
|
|
|
testserver.registerPathHandler("/update.rdf", function(aRequest, aResponse) {
|
|
|
|
gSeenExpectedURL = aRequest.queryString == gExpectedQuery;
|
|
|
|
aResponse.setStatusLine(null, 404, "Not Found");
|
|
|
|
});
|
|
|
|
testserver.start(4444);
|
|
|
|
|
2007-08-15 00:49:12 -07:00
|
|
|
// Register our parameter handlers
|
|
|
|
gComponentRegistrar.registerFactory(CLASS_ID, "Test component", CONTRACT_ID, paramHandlerFactory);
|
|
|
|
gCategoryManager.addCategoryEntry("extension-update-params", "CUSTOM1", CONTRACT_ID, false, false);
|
|
|
|
gCategoryManager.addCategoryEntry("extension-update-params", "CUSTOM2", CONTRACT_ID, false, false);
|
|
|
|
|
2010-04-28 11:49:56 -07:00
|
|
|
// Install a test extension into the profile
|
|
|
|
let dir = gProfD.clone();
|
|
|
|
dir.append("extensions");
|
2010-09-10 15:54:37 -07:00
|
|
|
writeInstallRDFForExtension({
|
2010-04-28 11:49:56 -07:00
|
|
|
id: "test@mozilla.org",
|
|
|
|
version: "1.0",
|
|
|
|
name: "Test extension",
|
|
|
|
updateURL: gTestURL,
|
|
|
|
targetApplications: [{
|
|
|
|
id: "xpcshell@tests.mozilla.org",
|
|
|
|
minVersion: "1",
|
|
|
|
maxVersion: "1"
|
|
|
|
}],
|
|
|
|
}, dir);
|
|
|
|
|
|
|
|
startupManager();
|
2007-08-15 00:49:12 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function shutdownTest()
|
|
|
|
{
|
2010-04-28 11:49:56 -07:00
|
|
|
shutdownManager();
|
2007-08-15 00:49:12 -07:00
|
|
|
|
|
|
|
gComponentRegistrar.unregisterFactory(CLASS_ID, paramHandlerFactory);
|
|
|
|
gCategoryManager.deleteCategoryEntry("extension-update-params", "CUSTOM1", false);
|
|
|
|
gCategoryManager.deleteCategoryEntry("extension-update-params", "CUSTOM2", false);
|
|
|
|
|
2010-04-28 11:49:56 -07:00
|
|
|
do_test_finished();
|
2007-08-15 00:49:12 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function run_test()
|
|
|
|
{
|
|
|
|
initTest();
|
|
|
|
|
2010-04-26 10:49:19 -07:00
|
|
|
AddonManager.getAddonByID("test@mozilla.org", function(item) {
|
2010-04-28 11:49:56 -07:00
|
|
|
// Initiate update
|
|
|
|
item.findUpdates({
|
2010-06-10 11:11:16 -07:00
|
|
|
onCompatibilityUpdateAvailable: function(addon) {
|
|
|
|
do_throw("Should not have seen a compatibility update");
|
2010-04-28 11:49:56 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
onUpdateAvailable: function(addon, install) {
|
2010-06-10 11:11:16 -07:00
|
|
|
do_throw("Should not have seen an available update");
|
2010-04-28 11:49:56 -07:00
|
|
|
},
|
|
|
|
|
2010-06-10 11:11:16 -07:00
|
|
|
onUpdateFinished: function(addon, error) {
|
|
|
|
do_check_eq(error, AddonManager.UPDATE_STATUS_DOWNLOAD_ERROR);
|
2010-04-28 11:49:56 -07:00
|
|
|
do_check_true(gSeenExpectedURL);
|
|
|
|
shutdownTest();
|
|
|
|
}
|
|
|
|
}, AddonManager.UPDATE_WHEN_USER_REQUESTED);
|
|
|
|
});
|
2007-08-15 00:49:12 -07:00
|
|
|
}
|