tor-browser

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

htmlanchorelement_noopener.html (3126B)


      1 <!doctype html>
      2 <meta charset=utf-8>
      3 <title>Test behavior of rel="noopener" links</title>
      4 <script src=/resources/testharness.js></script>
      5 <script src=/resources/testharnessreport.js></script>
      6 <iframe name="oursubframe"></iframe>
      7 <a href="support/noopener-target-2.html" rel="noopener" target="ourpopup"></a>
      8 <a href="support/noopener-target-2.html" rel="noopener" target="oursubframe"></a>
      9 <script>
     10 var tests = [];
     11 // First test the special targets
     12 function target1Loaded(win) {
     13  // Find the relevant test
     14  var test = tests.find((t) => t.openedWindow == win);
     15  test.step(function() {
     16    assert_equals(win.opener, window);
     17    win.close();
     18    test.done();
     19  });
     20 }
     21 /**
     22 * Test that <a rel="noopener"> targeted at one of _self, _parent, _top does the
     23 * load in the appropriate existing browsing context instead of opening a new
     24 * one.  The test is run in a separate popup window we open and which we can
     25 * navigate without causing the test harness going into conniptions.
     26 */
     27 for (var target of ["self", "parent", "top"]) {
     28  var t = async_test("Check that rel=noopener with target=_" + target + " does a normal load");
     29  tests.push(t);
     30  t.openedWindow = window.open("support/noopener-popup.html");
     31  t.targetName = target;
     32  t.openedWindow.onload = t.step_func(function() {
     33    this.openedWindow.findLink(this.targetName).click();
     34  });
     35 }
     36 
     37 /**
     38 * And now check that a noopener load targeted at something other than one of
     39 * the three special targets above is still able to reuse existing things with the
     40 * given name.  We do this in two ways.  First, by opening a window named
     41 * "ourpopup" and then doing a load via <a rel="noopener" target="ourpopup"> and
     42 * verifying that the load happens in a window with a null opener, etc, while
     43 * the opener of the thing we opened is not modified.  And second, by targeting
     44 * <a rel="noopener"> at a name that an existing subframe has, and ensuring that
     45 * this subframe is not navigated.
     46 */
     47 var t1 = async_test("Check that targeting of rel=noopener with a given name reuses an existing window with that name");
     48 var w;
     49 t1.add_cleanup(function() { w.close(); });
     50 var channel = new BroadcastChannel("ourpopup");
     51 channel.onmessage = t1.step_func_done(function(e) {
     52  var data = e.data;
     53  assert_true(data.hasOpener);
     54  assert_false(data.hasParent);
     55  assert_equals(data.name, "ourpopup");
     56  assert_equals(w.opener, window);
     57  assert_not_equals(w.location.href, "about:blank");
     58 });
     59 t1.step(function() {
     60  w = window.open("", "ourpopup");
     61  assert_equals(w.opener, window);
     62  document.querySelectorAll("a")[0].click();
     63 });
     64 
     65 var t2 = async_test("Check that targeting of rel=noopener with a given name reuses an existing subframe with that name");
     66 var channel = new BroadcastChannel("oursubframe");
     67 channel.onmessage = t2.step_func_done(function(e) {
     68  var data = e.data;
     69  assert_false(data.hasOpener);
     70  assert_true(data.hasParent);
     71  assert_equals(data.name, "oursubframe");
     72  assert_not_equals(document.querySelector("iframe").contentWindow.location.href,
     73                    "about:blank");
     74 });
     75 t2.step(function() {
     76  document.querySelectorAll("a")[1].click();
     77 });
     78 </script>