toolkit/mozapps/extensions/test/xpinstall/browser_cookies4.js

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 // ----------------------------------------------------------------------------
     2 // Test that an install that requires cookies to be sent fails when cookies
     3 // are set and third party cookies are disabled and the request is to a third
     4 // party.
     5 // This verifies bug 462739
     6 function test() {
     7   Harness.downloadFailedCallback = download_failed;
     8   Harness.installsCompletedCallback = finish_test;
     9   Harness.setup();
    11   var cm = Components.classes["@mozilla.org/cookiemanager;1"]
    12                      .getService(Components.interfaces.nsICookieManager2);
    13   cm.add("example.com", "/browser/" + RELATIVE_DIR, "xpinstall", "true", false,
    14          false, true, (Date.now() / 1000) + 60);
    16   var pm = Services.perms;
    17   pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION);
    19   Services.prefs.setIntPref("network.cookie.cookieBehavior", 1);
    21   var triggers = encodeURIComponent(JSON.stringify({
    22     "Cookie check": TESTROOT2 + "cookieRedirect.sjs?" + TESTROOT + "unsigned.xpi"
    23   }));
    24   gBrowser.selectedTab = gBrowser.addTab();
    25   gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers);
    26 }
    28 function download_failed(install) {
    29   is(install.error, AddonManager.ERROR_NETWORK_FAILURE, "Install should fail");
    30 }
    32 function finish_test(count) {
    33   is(count, 0, "No add-ons should have been installed");
    34   var cm = Components.classes["@mozilla.org/cookiemanager;1"]
    35                      .getService(Components.interfaces.nsICookieManager2);
    36   cm.remove("example.com", "xpinstall", "/browser/" + RELATIVE_DIR, false);
    38   Services.prefs.clearUserPref("network.cookie.cookieBehavior");
    39   Services.perms.remove("example.com", "install");
    41   gBrowser.removeCurrentTab();
    42   Harness.finish();
    43 }

mercurial