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.

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

mercurial