tor-browser

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

test_1331680_iframe.html (2619B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <!--
      4 https://bugzilla.mozilla.org/show_bug.cgi?id=643051
      5 -->
      6 <head>
      7  <title>Cookies set from iframe in content process</title>
      8  <script src="/tests/SimpleTest/SimpleTest.js"></script>
      9  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
     10 </head>
     11 <body>
     12 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1331680">Mozilla Bug 1331680</a>
     13 <p id="display"></p>
     14 <div id="content" style="display: none">
     15 <script type="application/javascript">
     16 SimpleTest.waitForExplicitFinish();
     17 const IFRAME_COOKIE_NAMES = ["if1", "if2_1", "if2_2"];
     18 const ID = ["if_1", "if_2", "if_3"];
     19 
     20 var gScript = SpecialPowers.loadChromeScript(SimpleTest.getTestFileURL('file_1331680.js'));
     21 
     22 /* Test iframe
     23 * 1. Create three iframes, and one of the iframe will create two cookies.
     24 * 2. Confirm the cookies can be proessed from observer.
     25 * 3. Confirm document.cookie can get cookies "if2_1" and "if2_2".
     26 * 4. Confirm the iframe whose source is "about:blank" can get parent's cookies.
     27 */
     28 function createIframe(id, src, sandbox_flags) {
     29  return new Promise(resolve => {
     30    var ifr = document.createElement("iframe");
     31    ifr.id = id;
     32    ifr.src = src;
     33    ifr.sandbox = sandbox_flags;
     34    ifr.addEventListener("load", resolve);
     35    document.body.appendChild(ifr);
     36  });
     37 };
     38 
     39 function confirmCookies(id) {
     40  is(document.cookie, "if2_1=if2_val1; if2_2=if2_val2", "Confirm the cookies can get after iframe was deleted");
     41  var new_ifr = document.getElementById(id);
     42  is(new_ifr.contentDocument.cookie, document.cookie, "Confirm the inner document.cookie = parent document.cookie");
     43  document.cookie = IFRAME_COOKIE_NAMES[1] + "=; expires=Thu, 01-Jan-1970 00:00:01 GMT";
     44  document.cookie = IFRAME_COOKIE_NAMES[2] + "=; expires=Thu, 01-Jan-1970 00:00:01 GMT";
     45  is(document.cookie, "", "Removed all cookies");
     46  SpecialPowers.clearUserPref("network.cookie.sameSite.laxByDefault");
     47  SimpleTest.finish();
     48 }
     49 
     50 addEventListener("message", function(event) {
     51  is(event.data, document.cookie, "Confirm the iframe 2 can communicate with iframe");
     52 });
     53 
     54 SpecialPowers.pushPrefEnv({
     55  // Bug 1617611: Fix all the tests broken by "cookies SameSite=lax by default"
     56  set: [["network.cookie.sameSite.laxByDefault", false]],
     57 }).then(_ => createIframe(ID[0], "file_iframe_allow_scripts.html", "allow-scripts"))
     58  .then(_ => createIframe(ID[1], "file_iframe_allow_same_origin.html", "allow-scripts allow-same-origin"))
     59  .then(_ => createIframe(ID[2], "about:blank", "allow-scripts allow-same-origin"))
     60  .then(_ => confirmCookies(ID[2]));
     61 
     62 </script>
     63 
     64 </div>
     65 <pre id="test">
     66 </pre>
     67 </body>
     68 </html>