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

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

     1 const CLASS_ID = Components.ID("{12345678-1234-1234-1234-123456789abc}");
     2 const CONTRACT_ID = "@mozilla.org/test-parameter-source;1";
     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;
    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;
    14 var gComponentRegistrar = Components.manager.QueryInterface(AM_Ci.nsIComponentRegistrar);
    15 var gCategoryManager = AM_Cc["@mozilla.org/categorymanager;1"].getService(AM_Ci.nsICategoryManager);
    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;
    23     throw Components.results.NS_ERROR_NO_INTERFACE;
    24   },
    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 };
    35 function initTest()
    36 {
    37   do_test_pending();
    38   // Setup extension manager
    39   createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9");
    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   });
    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);
    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);
    67   startupManager();
    68 }
    70 function shutdownTest()
    71 {
    72   shutdownManager();
    74   gComponentRegistrar.unregisterFactory(CLASS_ID, paramHandlerFactory);
    75   gCategoryManager.deleteCategoryEntry("extension-update-params", "CUSTOM1", false);
    76   gCategoryManager.deleteCategoryEntry("extension-update-params", "CUSTOM2", false);
    78   do_test_finished();
    79 }
    81 function run_test()
    82 {
    83   initTest();
    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       },
    92       onUpdateAvailable: function(addon, install) {
    93         do_throw("Should not have seen an available update");
    94       },
    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 }

mercurial