toolkit/components/antitracking/test/browser/localStorage.html
author Andrea Marchesini <amarchesini@mozilla.com>
Mon, 19 Nov 2018 23:56:04 +0100
changeset 503558 ff115c0a1586797a1bbf4dbe472d34726986585d
parent 503526 88af3329ee16b19450f0c4638d4fb39019cdf928
child 503528 401763b97e54cd99c6a5ad2a617379da011a57e5
permissions -rw-r--r--
Bug 1505571 - Tests of localStorage access immediatelly after a user-interaction, r=ehsan

<h1>Here a tracker!</h1>
<script>

if (window.opener) {
  SpecialPowers.wrap(document).userInteractionForTesting();
  localStorage.foo = "opener" + Math.random();
  window.close();
}

if (parent) {
  window.onmessage = e => {
    if (e.data == "test") {
      let status;
      try {
        localStorage.foo = "value" + Math.random();
        status = true;
      } catch (e) {
        status = false;
      }

      parent.postMessage({type: "test", status }, "*");
      return;
    }

    if (e.data == "open") {
      window.open("localStorage.html");
    }
  };

  window.addEventListener("storage", e => {
    let fromOpener = localStorage.foo.startsWith("opener");

    let status;
    try {
      localStorage.foo = "value" + Math.random();
      status = true;
    } catch (e) {
      status = false;
    }

    parent.postMessage({type: "test", status: status && fromOpener }, "*");
  });
}

</script>