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

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/mozapps/extensions/test/xpinstall/browser_cookies4.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,43 @@
     1.4 +// ----------------------------------------------------------------------------
     1.5 +// Test that an install that requires cookies to be sent fails when cookies
     1.6 +// are set and third party cookies are disabled and the request is to a third
     1.7 +// party.
     1.8 +// This verifies bug 462739
     1.9 +function test() {
    1.10 +  Harness.downloadFailedCallback = download_failed;
    1.11 +  Harness.installsCompletedCallback = finish_test;
    1.12 +  Harness.setup();
    1.13 +
    1.14 +  var cm = Components.classes["@mozilla.org/cookiemanager;1"]
    1.15 +                     .getService(Components.interfaces.nsICookieManager2);
    1.16 +  cm.add("example.com", "/browser/" + RELATIVE_DIR, "xpinstall", "true", false,
    1.17 +         false, true, (Date.now() / 1000) + 60);
    1.18 +
    1.19 +  var pm = Services.perms;
    1.20 +  pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION);
    1.21 +
    1.22 +  Services.prefs.setIntPref("network.cookie.cookieBehavior", 1);
    1.23 +
    1.24 +  var triggers = encodeURIComponent(JSON.stringify({
    1.25 +    "Cookie check": TESTROOT2 + "cookieRedirect.sjs?" + TESTROOT + "unsigned.xpi"
    1.26 +  }));
    1.27 +  gBrowser.selectedTab = gBrowser.addTab();
    1.28 +  gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers);
    1.29 +}
    1.30 +
    1.31 +function download_failed(install) {
    1.32 +  is(install.error, AddonManager.ERROR_NETWORK_FAILURE, "Install should fail");
    1.33 +}
    1.34 +
    1.35 +function finish_test(count) {
    1.36 +  is(count, 0, "No add-ons should have been installed");
    1.37 +  var cm = Components.classes["@mozilla.org/cookiemanager;1"]
    1.38 +                     .getService(Components.interfaces.nsICookieManager2);
    1.39 +  cm.remove("example.com", "xpinstall", "/browser/" + RELATIVE_DIR, false);
    1.40 +
    1.41 +  Services.prefs.clearUserPref("network.cookie.cookieBehavior");
    1.42 +  Services.perms.remove("example.com", "install");
    1.43 +
    1.44 +  gBrowser.removeCurrentTab();
    1.45 +  Harness.finish();
    1.46 +}

mercurial