tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_cookie_fetch.html (2548B)


      1 <!--
      2  Any copyright is dedicated to the Public Domain.
      3  http://creativecommons.org/publicdomain/zero/1.0/
      4 -->
      5 <!DOCTYPE HTML>
      6 <html>
      7 <head>
      8  <title>Bug 1331680 - test access to cookies in the documents synthesized from service worker responses</title>
      9  <script src="/tests/SimpleTest/SimpleTest.js"></script>
     10  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
     11 </head>
     12 <body>
     13 <p id="display"></p>
     14 <div id="content" style="display: none">
     15 <iframe></iframe>
     16 </div>
     17 <pre id="test"></pre>
     18 <script class="testbody" type="text/javascript">
     19 
     20  var iframe;
     21  function runTest() {
     22    iframe = document.querySelector("iframe");
     23    iframe.src = "https://example.com/tests/dom/serviceworkers/test/fetch/cookie/register.html";
     24    window.onmessage = function(e) {
     25      if (e.data.status == "ok") {
     26        ok(e.data.result, e.data.message);
     27      } else if (e.data.status == "registrationdone") {
     28        // Remove the iframe and recreate a new one to ensure that any traces
     29        // of the cookies have been removed from the child process.
     30        iframe.remove();
     31        iframe = document.createElement("iframe");
     32        document.getElementById("content").appendChild(iframe);
     33 
     34        iframe.src = "https://example.com/tests/dom/serviceworkers/test/fetch/cookie/synth.html";
     35      } else if (e.data.status == "done") {
     36        // Note, we can't do an exact is() comparison here since other
     37        // tests can leave cookies on the domain.
     38        ok(e.data.cookie.includes("foo=bar"),
     39           "The synthesized document has access to its cookies");
     40 
     41        iframe.src = "https://example.com/tests/dom/serviceworkers/test/fetch/cookie/unregister.html";
     42      } else if (e.data.status == "unregistrationdone") {
     43        window.onmessage = null;
     44        ok(true, "Test finished successfully");
     45        SpecialPowers.clearUserPref("network.cookie.sameSite.laxByDefault");
     46        SimpleTest.finish();
     47      }
     48    };
     49  }
     50 
     51  SimpleTest.waitForExplicitFinish();
     52  onload = function() {
     53    SpecialPowers.pushPrefEnv({"set": [
     54      ["dom.serviceWorkers.exemptFromPerDomainMax", true],
     55      ["dom.serviceWorkers.enabled", true],
     56      ["dom.serviceWorkers.testing.enabled", true],
     57      // Bug 1617611: Fix all the tests broken by "cookies SameSite=lax by default"
     58      ["network.cookie.sameSite.laxByDefault", false],
     59      // Bug 1874001: Fix all the tests broken by 3pc blocking by default in TCP.
     60      ["network.cookie.cookieBehavior.optInPartitioning", false],
     61    ]}, runTest);
     62  };
     63 </script>
     64 </pre>
     65 </body>
     66 </html>