tor-browser

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

window_bug1171215.html (2417B)


      1 <!DOCTYPE html>
      2 <html>
      3 <!--
      4 https://bugzilla.mozilla.org/show_bug.cgi?id=1022869
      5 -->
      6 <head>
      7  <meta charset="utf-8">
      8  <title>Test for Bug 1022869</title>
      9  <iframe src="about:blank"></iframe>
     10  <script type="text/javascript">
     11 
     12  function finish() {
     13    opener.postMessage({type: "finish" });
     14  }
     15 
     16  function info(msg) {
     17    opener.postMessage({type: "info", msg });
     18  }
     19 
     20  function ok(a, msg) {
     21    opener.postMessage({type: "test", test: !!a, msg });
     22  }
     23 
     24  function is(a, b, msg) {
     25    ok(a === b, msg);
     26  }
     27 
     28  var f = document.getElementsByTagName("iframe")[0];
     29 
     30  /** Test for Bug 1022869 */
     31  function startTest() {
     32    // Set a cookie in example.org so we can test that we can't read it in
     33    // third-party cases.
     34    f.contentWindow.location =
     35        "http://example.org/tests/dom/tests/mochitest/bugs/file_prime_cookie.html";
     36    waitForLoad().then(continueTest).catch((e) => { ok(false, `Got exception: ${e}`) });
     37  }
     38 
     39  function waitForLoad() {
     40    return new Promise((resolve) => {
     41      window.addEventListener("message", function(msg) {
     42        info(`got message ${msg.data}`);
     43        resolve(msg.data);
     44      }, {once: true});
     45    });
     46  }
     47 
     48  async function continueTest() {
     49    var sameOrigin = "http://mochi.test:8888";
     50    var thirdParty = "http://example.org";
     51    var page = "tests/dom/tests/mochitest/bugs/file_cookieOutputter.html"
     52    var redirect = "tests/dom/tests/mochitest/bugs/file_redirector.sjs";
     53 
     54    function createRedirect(firstOrigin, secondOrigin) {
     55      return `${firstOrigin}/${redirect}?${secondOrigin}/${page}`;
     56    }
     57 
     58    info("starting test");
     59 
     60    // Same origin to same origin.
     61    f.contentWindow.location = createRedirect(sameOrigin, sameOrigin);
     62    let cookie = await waitForLoad();
     63    is(cookie, "a=b", "got the cookie");
     64 
     65    // Cross origin to cross origin.
     66    f.contentWindow.location = createRedirect(thirdParty, thirdParty);
     67    cookie = await waitForLoad();
     68    is(cookie, "", "no third-party cookies");
     69 
     70    // Same origin to cross origin.
     71    f.contentWindow.location = createRedirect(sameOrigin, thirdParty);
     72    cookie = await waitForLoad();
     73    is(cookie, "", "no third-party cookies");
     74 
     75    // Cross origin to same origin
     76    f.contentWindow.location = createRedirect(thirdParty, sameOrigin);
     77    cookie = await waitForLoad();
     78    is(cookie, "a=b", "got the cookie");
     79 
     80    finish();
     81  }
     82  </script>
     83 </head>
     84 <body onload="startTest()">
     85 </body>
     86 </html>