tor-browser

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

test_1421324.html (2204B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <!--
      4 -->
      5 <head>
      6  <title>Cookie changes from XHR requests are observed in content processes.</title>
      7  <script src="/tests/SimpleTest/SimpleTest.js"></script>
      8  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
      9 
     10 <script type="text/javascript">
     11 SimpleTest.waitForExplicitFinish();
     12 
     13 function createXHR(url) {
     14  return new Promise(function (resolve, reject) {
     15    var xhr = new XMLHttpRequest();
     16    xhr.open("GET", url, true); // async request
     17    xhr.onload = function () {
     18      if (this.status >= 200 && this.status < 300) {
     19        resolve(xhr.response);
     20      } else {
     21        reject({
     22          status: this.status,
     23          statusText: xhr.statusText
     24        });
     25      }
     26    };
     27    xhr.onerror = function () {
     28      reject({
     29        status: this.status,
     30        statusText: xhr.statusText
     31      });
     32    };
     33    xhr.send();
     34  });
     35 }
     36 
     37 
     38 SpecialPowers.pushPrefEnv({
     39  // Bug 1617611: Fix all the tests broken by "cookies SameSite=lax by default"
     40  set: [["network.cookie.sameSite.laxByDefault", false]],
     41 })
     42 
     43 // 1. Create one XHR to set a non-http-only cookie (testXHR1)
     44 .then(_ => createXHR('reset_cookie_xhr.sjs?set_cookie'))
     45 
     46 // 2. Check the visibility of that cookie
     47 .then(_ => is(document.cookie, "testXHR1=xhr_val1", "Confirm the cookie"))
     48 
     49 // 3. Create a second cookie via document.cookie (testXHR2) and check the
     50 //    visibility of those 2 cookies
     51 .then(_ => {
     52  document.cookie = "testXHR2=xhr_val2; path=/";
     53  is(document.cookie, "testXHR1=xhr_val1; testXHR2=xhr_val2", "Confirm the two cookies");
     54 })
     55 
     56 // 4. Create one XHR to modify the first cookie and make it http-only
     57 .then(_ => createXHR('reset_cookie_xhr.sjs?modify_cookie'))
     58 
     59 // 5. Child process only can get the testXHR1 cookie.
     60 .then(_ => {
     61  is(document.cookie, "testXHR2=xhr_val2", "Confirm the first cookie is gone");
     62 })
     63 
     64 // 6. Try to override the first cookie.
     65 .then(_ => {
     66  document.cookie = "testXHR1=xhr_val3; path=/";
     67  is(document.cookie, "testXHR2=xhr_val2", "Still one cookie");
     68 })
     69 
     70 // 7. Cleanup && Shutdown
     71 .finally(_ => {
     72  document.cookie = "testXHR2=; path=/; expires=Thu, 01-Jan-1970 00:00:01 GMT";
     73  SimpleTest.finish();
     74 });
     75 
     76 </script>
     77 </head>
     78 <body>
     79 </body>
     80 </html>