dom/tests/mochitest/localstorage/test_localStorageCookieSettings.html
author Ehsan Akhgari <ehsan@mozilla.com>
Thu, 25 Oct 2018 13:35:24 +0000
changeset 491334 578d395f555ee3d71cacb239f5f84ce897b313cb
parent 486566 afc8f32e6742473811406ee117475a6cdd679e2e
child 491342 5e471c480b8a6ba4939a6c159d86a687a24bb5d8
permissions -rw-r--r--
Bug 1501286 - Part 4: Remove the browser.contentblocking.ui.enabled pref from several tests which now set it needlessly r=johannh Depends on D9521 Differential Revision: https://phabricator.services.mozilla.com/D9522

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>localStorage cookies settings test</title>

<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="text/javascript" src="interOriginTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />

</head>
<body>
<iframe></iframe>

<script type="text/javascript">

SimpleTest.waitForExplicitFinish();

// Set cookies behavior to "always reject".
SpecialPowers.pushPrefEnv({"set": [
  ["browser.contentblocking.enabled", true],
  ["network.cookie.cookieBehavior", 2],
]}, test1);

function test1() {
  try {
    localStorage.setItem("contentkey", "test-value");
    ok(false, "Setting localStorageItem should throw a security exception");
  }
  catch(ex) {
    is(ex.name, "SecurityError");
  }

  // Set cookies behavior to "reject 3rd party"
  SpecialPowers.pushPrefEnv({"set": [["network.cookie.cookieBehavior", 1]],
                             "clear": [["network.cookie.lifetimePolicy"]]},
                            test3);
}

function test3() {
  try {
    localStorage.setItem("contentkey", "test-value");
    ok(true, "Setting localStorageItem should not throw a security exception");
  }
  catch(ex) {
    ok(false, "Setting localStorageItem should not throw a security exception");
  }

  var fileTest = (location.protocol + "//example.com" + location.pathname)
                 .replace("test_l", "frameL");

  var myframe = document.querySelector("iframe");
  myframe.src = fileTest;
}

// Called by interOriginTest.js
function doNextTest() {
  SimpleTest.finish();
}

</script>
</body>
</html>