tor-browser

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

test_window_close.html (3073B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <head>
      4  <meta charset="utf-8">
      5  <title>test window.close()</title>
      6  <script src="/tests/SimpleTest/SimpleTest.js"></script>
      7  <link rel="stylesheet" href="/tests/SimpleTest/test.css"/>
      8  <script>
      9    SimpleTest.waitForExplicitFinish();
     10    var b = SpecialPowers.wrap(BroadcastChannel).unpartitionedTestingChannel("windowclose");
     11 
     12    const link = "link";
     13    const windowopen = "window.open()";
     14    var tests = [
     15        {
     16        type: windowopen,
     17        noopener: true,
     18        shouldCloseWithoutHistory: true,
     19        shouldCloseWithHistory: true
     20      },
     21      {
     22        type: windowopen,
     23        noopener: false,
     24        shouldCloseWithoutHistory: true,
     25        shouldCloseWithHistory: true
     26      },
     27      {
     28        type: link,
     29        noopener: true,
     30        shouldCloseWithoutHistory: true,
     31        shouldCloseWithHistory: true
     32      },
     33      {
     34        type: link,
     35        noopener: false,
     36        shouldCloseWithoutHistory: true,
     37        shouldCloseWithHistory: true
     38      }
     39    ];
     40 
     41    var loadTypes = ["withouthistory", "withhistory"];
     42 
     43    async function start() {
     44      // If Fission is disabled, the pref is no-op.
     45      await SpecialPowers.pushPrefEnv({set: [["fission.bfcacheInParent", true]]});
     46 
     47      for (let test of tests) {
     48        await SpecialPowers.pushPrefEnv({ set: [["dom.allow_scripts_to_close_windows", false]]});
     49        if (test.type == windowopen) {
     50          for (let loadType of loadTypes) {
     51            var features = test.noopener ? "noopener" : "";
     52            window.open("file_window_close.html?" + loadType, "", features);
     53            await new Promise(function(r) {
     54              b.onmessage = function(e) {
     55                var expectedClose = loadType == "withouthistory" ?
     56                  test.shouldCloseWithoutHistory : test.shouldCloseWithHistory;
     57                is(e.data, expectedClose ? "closed" : "blocked",
     58                   "Expected close on " + loadType + ": " + expectedClose);
     59                r();
     60              }
     61            });
     62          }
     63        } else if (test.type == link) {
     64          var rel = test.noopener ? "rel='noopener'" : "";
     65          for (let loadType of loadTypes) {
     66            document.getElementById("content").innerHTML =
     67              "<a href='file_window_close.html?" +  loadType + "'" +
     68                " target='foo' " + rel + "'>link</a>";
     69            var p = new Promise(function(r) {
     70              b.onmessage = function(e) {
     71                var expectedClose = loadType == "withouthistory" ?
     72                  test.shouldCloseWithoutHistory : test.shouldCloseWithHistory;
     73                is(e.data, expectedClose ? "closed" : "blocked",
     74                   "Expected close on " + loadType + ": " + expectedClose);
     75                r();
     76              }
     77            });
     78            document.getElementById("content").firstChild.click();
     79            await p;
     80          }
     81        }
     82      }
     83      SimpleTest.finish();
     84    }
     85 
     86  </script>
     87 </head>
     88 <body onload="setTimeout(start)">
     89 <p id="display"></p>
     90 <div id="content"></div>
     91 <pre id="test"></pre>
     92 </body>
     93 </html>