dom/indexedDB/test/test_third_party.html
author Ciure Andrei <aciure@mozilla.com>
Thu, 07 Mar 2019 17:54:18 +0200
changeset 462908 ca64604d4b781aa8191144e97b660ae3b09fae6e
parent 462865 fb90d51ba85396becf96418b9ead270055130c11
child 463124 98ff0248c6079b9518e2b96d19bacb5402a21bda
permissions -rw-r--r--
Backed out 16 changesets (bug 1525245) for perma failing test_document_cookie.html CLOSED TREE Backed out changeset 3fd27215698f (bug 1525245) Backed out changeset d9a9e8e77873 (bug 1525245) Backed out changeset 0e6f7be92e3f (bug 1525245) Backed out changeset 6790802e2fa5 (bug 1525245) Backed out changeset a5a9e01116ed (bug 1525245) Backed out changeset 66e19a0c38dd (bug 1525245) Backed out changeset fb90d51ba853 (bug 1525245) Backed out changeset 4772db3625b3 (bug 1525245) Backed out changeset 9affaf0cb998 (bug 1525245) Backed out changeset a91b7ebe8bdd (bug 1525245) Backed out changeset c2a13a7480e1 (bug 1525245) Backed out changeset abe4482fa137 (bug 1525245) Backed out changeset b3920c0bcf84 (bug 1525245) Backed out changeset 0821b81f2724 (bug 1525245) Backed out changeset 70bed2ad7899 (bug 1525245) Backed out changeset 5f72ba232cc8 (bug 1525245)

<!--
  Any copyright is dedicated to the Public Domain.
  http://creativecommons.org/publicdomain/zero/1.0/
-->
<html>
<head>
  <title>Indexed Database Test</title>

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

  <script type="text/javascript">
    const BEHAVIOR_ACCEPT = 0;
    const BEHAVIOR_REJECTFOREIGN = 1;
    const BEHAVIOR_REJECT = 2;
    const BEHAVIOR_LIMITFOREIGN = 3;

    const testData = [
      { host: "http://" + window.location.host, cookieBehavior: BEHAVIOR_ACCEPT, expectedResult: true },
      { host: "http://example.com", cookieBehavior: BEHAVIOR_ACCEPT, expectedResult: true },
      { host: "http://sub1.test2.example.org:8000", cookieBehavior: BEHAVIOR_ACCEPT, expectedResult: true },
      { host: "http://" + window.location.host, cookieBehavior: BEHAVIOR_ACCEPT, expectedResult: true },

      { host: "http://" + window.location.host, cookieBehavior: BEHAVIOR_REJECT, expectedResult: false },
      { host: "http://example.com", cookieBehavior: BEHAVIOR_REJECT, expectedResult: false },
      { host: "http://sub1.test2.example.org:8000", cookieBehavior: BEHAVIOR_REJECT, expectedResult: false },
      { host: "http://" + window.location.host, cookieBehavior: BEHAVIOR_REJECT, expectedResult: false },

      { host: "http://" + window.location.host, cookieBehavior: BEHAVIOR_REJECTFOREIGN, expectedResult: true },
      { host: "http://example.com", cookieBehavior: BEHAVIOR_REJECTFOREIGN, expectedResult: false },
      { host: "http://sub1.test2.example.org:8000", cookieBehavior: BEHAVIOR_REJECTFOREIGN, expectedResult: false },
      { host: "http://" + window.location.host, cookieBehavior: BEHAVIOR_REJECTFOREIGN, expectedResult: true },

      { host: "http://" + window.location.host, cookieBehavior: BEHAVIOR_LIMITFOREIGN, expectedResult: true },
      { host: "http://example.com", cookieBehavior: BEHAVIOR_LIMITFOREIGN, expectedResult: false },
      { host: "http://sub1.test2.example.org:8000", cookieBehavior: BEHAVIOR_LIMITFOREIGN, expectedResult: false },
      { host: "http://" + window.location.host, cookieBehavior: BEHAVIOR_LIMITFOREIGN, expectedResult: true },
    ];

    const iframe1Path =
      window.location.pathname.replace("test_third_party.html",
                                       "third_party_iframe1.html");
    const iframe2URL =
      "http://" + window.location.host +
      window.location.pathname.replace("test_third_party.html",
                                       "third_party_iframe2.html");

    let testIndex = 0;
    let testRunning = false;

    function iframeLoaded() {
      let message = { source: "parent", href: iframe2URL };
      let iframe = document.getElementById("iframe1");
      iframe.contentWindow.postMessage(message.toSource(), "*");
    }

    function setiframe() {
      let iframe = document.getElementById("iframe1");

      if (!testRunning) {
        testRunning = true;
        iframe.addEventListener("load", iframeLoaded);
      }
      SpecialPowers.pushPrefEnv({
        "set": [
          ["network.cookie.cookieBehavior", testData[testIndex].cookieBehavior],
        ],
      }, () => {
        iframe.src = testData[testIndex].host + iframe1Path;
      });
      // SpecialPowers.setIntPref("network.cookie.cookieBehavior", testData[testIndex].cookieBehavior);
    }

    function messageListener(event) {
      // eslint-disable-next-line no-eval
      let message = eval(event.data);

      is(message.source, "iframe", "Good source");
      is(message.result, testData[testIndex].expectedResult, "Good result");

      if (testIndex < testData.length - 1) {
        testIndex++;
        setiframe();
        return;
      }

      SimpleTest.finish();
    }

    function runTest() {
      SimpleTest.waitForExplicitFinish();

      SpecialPowers.addPermission("indexedDB", true, document);

      window.addEventListener("message", messageListener);
      setiframe();
    }
  </script>

</head>

<body onload="runTest();">
  <iframe id="iframe1"></iframe>
</body>

</html>