toolkit/mozapps/extensions/test/xpcshell/test_bug384052.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/mozapps/extensions/test/xpcshell/test_bug384052.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,103 @@
     1.4 +const CLASS_ID = Components.ID("{12345678-1234-1234-1234-123456789abc}");
     1.5 +const CONTRACT_ID = "@mozilla.org/test-parameter-source;1";
     1.6 +
     1.7 +// Get and create the HTTP server.
     1.8 +Components.utils.import("resource://testing-common/httpd.js");
     1.9 +var testserver = new HttpServer();
    1.10 +testserver.start(-1);
    1.11 +gPort = testserver.identity.primaryPort;
    1.12 +
    1.13 +var gTestURL = "http://127.0.0.1:" + gPort + "/update.rdf?itemID=%ITEM_ID%&custom1=%CUSTOM1%&custom2=%CUSTOM2%";
    1.14 +var gExpectedQuery = "itemID=test@mozilla.org&custom1=custom_parameter_1&custom2=custom_parameter_2";
    1.15 +var gSeenExpectedURL = false;
    1.16 +
    1.17 +var gComponentRegistrar = Components.manager.QueryInterface(AM_Ci.nsIComponentRegistrar);
    1.18 +var gCategoryManager = AM_Cc["@mozilla.org/categorymanager;1"].getService(AM_Ci.nsICategoryManager);
    1.19 +
    1.20 +// Factory for our parameter handler
    1.21 +var paramHandlerFactory = {
    1.22 +  QueryInterface: function(iid) {
    1.23 +    if (iid.equals(AM_Ci.nsIFactory) || iid.equals(AM_Ci.nsISupports))
    1.24 +      return this;
    1.25 +
    1.26 +    throw Components.results.NS_ERROR_NO_INTERFACE;
    1.27 +  },
    1.28 +
    1.29 +  createInstance: function(outer, iid) {
    1.30 +    var bag = AM_Cc["@mozilla.org/hash-property-bag;1"].
    1.31 +              createInstance(AM_Ci.nsIWritablePropertyBag);
    1.32 +    bag.setProperty("CUSTOM1", "custom_parameter_1");
    1.33 +    bag.setProperty("CUSTOM2", "custom_parameter_2");
    1.34 +    return bag.QueryInterface(iid);
    1.35 +  }
    1.36 +};
    1.37 +
    1.38 +function initTest()
    1.39 +{
    1.40 +  do_test_pending();
    1.41 +  // Setup extension manager
    1.42 +  createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9");
    1.43 +
    1.44 +  // Configure the HTTP server.
    1.45 +  testserver.registerPathHandler("/update.rdf", function(aRequest, aResponse) {
    1.46 +    gSeenExpectedURL = aRequest.queryString == gExpectedQuery;
    1.47 +    aResponse.setStatusLine(null, 404, "Not Found");
    1.48 +  });
    1.49 +
    1.50 +  // Register our parameter handlers
    1.51 +  gComponentRegistrar.registerFactory(CLASS_ID, "Test component", CONTRACT_ID, paramHandlerFactory);
    1.52 +  gCategoryManager.addCategoryEntry("extension-update-params", "CUSTOM1", CONTRACT_ID, false, false);
    1.53 +  gCategoryManager.addCategoryEntry("extension-update-params", "CUSTOM2", CONTRACT_ID, false, false);
    1.54 +
    1.55 +  // Install a test extension into the profile
    1.56 +  let dir = gProfD.clone();
    1.57 +  dir.append("extensions");
    1.58 +  writeInstallRDFForExtension({
    1.59 +    id: "test@mozilla.org",
    1.60 +    version: "1.0",
    1.61 +    name: "Test extension",
    1.62 +    updateURL: gTestURL,
    1.63 +    targetApplications: [{
    1.64 +      id: "xpcshell@tests.mozilla.org",
    1.65 +      minVersion: "1",
    1.66 +      maxVersion: "1"
    1.67 +    }],
    1.68 +  }, dir);
    1.69 +
    1.70 +  startupManager();
    1.71 +}
    1.72 +
    1.73 +function shutdownTest()
    1.74 +{
    1.75 +  shutdownManager();
    1.76 +
    1.77 +  gComponentRegistrar.unregisterFactory(CLASS_ID, paramHandlerFactory);
    1.78 +  gCategoryManager.deleteCategoryEntry("extension-update-params", "CUSTOM1", false);
    1.79 +  gCategoryManager.deleteCategoryEntry("extension-update-params", "CUSTOM2", false);
    1.80 +
    1.81 +  do_test_finished();
    1.82 +}
    1.83 +
    1.84 +function run_test()
    1.85 +{
    1.86 +  initTest();
    1.87 +
    1.88 +  AddonManager.getAddonByID("test@mozilla.org", function(item) {
    1.89 +    // Initiate update
    1.90 +    item.findUpdates({
    1.91 +      onCompatibilityUpdateAvailable: function(addon) {
    1.92 +        do_throw("Should not have seen a compatibility update");
    1.93 +      },
    1.94 +
    1.95 +      onUpdateAvailable: function(addon, install) {
    1.96 +        do_throw("Should not have seen an available update");
    1.97 +      },
    1.98 +
    1.99 +      onUpdateFinished: function(addon, error) {
   1.100 +        do_check_eq(error, AddonManager.UPDATE_STATUS_DOWNLOAD_ERROR);
   1.101 +        do_check_true(gSeenExpectedURL);
   1.102 +        do_execute_soon(shutdownTest);
   1.103 +      }
   1.104 +    }, AddonManager.UPDATE_WHEN_USER_REQUESTED);
   1.105 +  });
   1.106 +}

mercurial