tor-browser

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

test_same_site_cookies_toplevel_set_cookie.html (1847B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <head>
      4  <title>Bug 1454242: Setting samesite cookie should not rely on CookieCommons::IsSameSiteForeign</title>
      5  <script src="/tests/SimpleTest/SimpleTest.js"></script>
      6  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
      7 </head>
      8 <body>
      9 <img id="cookieImage">
     10 <iframe id="testframe"></iframe>
     11 
     12 <script class="testbody" type="text/javascript">
     13 
     14 /*
     15 * Description of the test:
     16 * 1) We load a window from example.com which loads a window from mochi.test
     17 *    which then sets a same-site cookie for mochi.test.
     18 * 2) We load an iframe from mochi.test.
     19 * 3) We observe that the cookie within (1) was allowed to be set and
     20 *    is available for mochi.test.
     21 */
     22 
     23 SimpleTest.waitForExplicitFinish();
     24 
     25 const SAME_ORIGIN = "http://mochi.test:8888/"
     26 const CROSS_ORIGIN = "http://example.com/";
     27 const PATH = "tests/dom/security/test/general/file_same_site_cookies_toplevel_set_cookie.sjs";
     28 
     29 let testWin = null;
     30 
     31 window.addEventListener("message", receiveMessage);
     32 function receiveMessage(event) {
     33  // once the second window (which sets the cookie) loaded, we get a notification
     34  // that the test setup is correct and we can now try to query the same-site cookie
     35  if (event.data.value === "testSetupComplete") {
     36    ok(true, "cookie setup worked");
     37    let testframe = document.getElementById("testframe");
     38    testframe.src = SAME_ORIGIN + PATH + "?checkCookie";
     39    return;
     40  }
     41 
     42  // thie second message is the cookie value from verifying the
     43  // cookie has been set correctly.
     44  is(event.data.value, "myKey=laxSameSiteCookie",
     45     "setting same-site cookie on cross origin top-level page");
     46 
     47  window.removeEventListener("message", receiveMessage);
     48  testWin.close();
     49  SimpleTest.finish();
     50 }
     51 
     52 // fire up the test
     53 testWin = window.open(CROSS_ORIGIN + PATH + "?loadWin");
     54 
     55 </script>
     56 </body>
     57 </html>