1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16
   17
   18
   19
   20
   21
   22
   23
   24
   25
   26
   27
   28
   29
   30
   31
   32
   33
   34
   35
   36
   37
   38
   39
   40
   41
   42
   43
   44
   45
   46
   47
   48
   49
   50
   51
   52
   53
   54
   55
   56
   57
   58
   59
   60
   61
   62
   63
   64
   65
   66
   67
   68
   69
   70
   71
   72
   73
   74
   75
   76
   77
   78
   79
   80
   81
   82
   83
   84
   85
   86
   87
   88
   89
   90
   91
   92
   93
   94
   95
   96
   97
   98
   99
  100
  101
  102
  103
  104
  105
  106
  107
  108
  109
  110
  111
  112
  113
  114
  115
  116
  117
  118
  119
  120
  121
  122
  123
  124
  125
  126
  127
  128
  129
  130
  131
  132
  133
  134
  135
  136
  137
  138
  139
  140
  141
  142
  143
  144
  145
  146
  147
  148
  149
  150
  151
  152
  153
  154
  155
  156
  157
  158
  159
  160
  161
  162
  163

content / test / data / click-noreferrer-links.html [blame]

<html>

 <head><title>Click noreferrer links</title>
 <script>
  function setOriginForLinks(baseUrl) {
    var links = [
        'noref_and_tblank_link',
        'noopener_and_tblank_link',
        'tblank_link',
        'noref_link',
        'noopener_link'
    ];
    links.forEach(function(linkId) {
      link = document.getElementById(linkId);
      link.href = baseUrl + link.pathname.substr(1);
    });
  }
  function simulateClick(target) {
    var evt = document.createEvent("MouseEvents");
    evt.initMouseEvent("click", true, true, window,
                       0, 0, 0, 0, 0, false, false,
                       false, false, 0, null);

    return target.dispatchEvent(evt);
  }

  function clickNoRefTargetBlankLink() {
    return simulateClick(document.getElementById("noref_and_tblank_link"));
  }

  function clickNoOpenerTargetBlankLink() {
    return simulateClick(document.getElementById("noopener_and_tblank_link"));
  }

  function clickSameSiteNoRefTargetedLink() {
    return simulateClick(
        document.getElementById("samesite_noref_and_targeted_link"));
  }

  function clickSameSiteNoOpenerTargetedLink() {
    return simulateClick(
        document.getElementById("samesite_noopener_and_targeted_link"));
  }

  function clickSameSiteTargetedLink() {
    return simulateClick(document.getElementById("samesite_targeted_link"));
  }

  function clickSameSiteTargetBlankLink() {
    return simulateClick(document.getElementById("samesite_tblank_link"));
  }

  function clickTargetBlankLink() {
    return simulateClick(document.getElementById("tblank_link"));
  }

  function clickNoRefLink() {
    return simulateClick(document.getElementById("noref_link"));
  }

  function clickNoOpenerLink() {
    return simulateClick(document.getElementById("noopener_link"));
  }

  function clickBlankTargetedLink() {
    return simulateClick(document.getElementById("blank_targeted_link"));
  }

  function testScriptAccessToWindow() {
    // Grab a reference to the existing foo window and access its location.
    try {
      var w = window.open("", "foo");
      var url = w.location.href;
      return url != undefined;
    } catch (e) {
      return false;
    }
  }

  function testCloseWindow() {
    // Grab a reference to the existing foo window and close it.
    var w = window.open("", "foo");
    w.close();
    return true;
  }

  // Listen to incoming messages and reply to them.
  var receivedMessages = 0;
  window.addEventListener("message", messageReceived, false);
  function messageReceived(event) {
    receivedMessages++;
    event.source.postMessage(event.data, "*");
  }

  // Send a message which contains a message port.
  var mc;
  function postWithPortToFoo() {
    mc = new MessageChannel();
    mc.port1.onmessage = portMessageReceived;
    mc.port1.start();
    var w = window.open("", "foo");
    w.postMessage({message: "msg-with-port", port: mc.port2}, "*", [mc.port2]);
    return true;
  }

  var receivedMessagesViaPort = 0;
  function portMessageReceived(event) {
    receivedMessagesViaPort++;
    // Change the title to generate a notification.
    document.title = event.data;
  }

  var last_opened_window = undefined;
  function saveWindowReference() {
    // Grab a reference to the existing foo window into a global variable
    // for later testing.
    last_opened_window = window.open("", "foo");
  }
  function getLastOpenedWindowLocation() {
    return last_opened_window.location.href;
  }

  function openWindowWithTargetAndFeatures(path, target, features) {
    var w = window.open(path, target, features);
    return w !== null;
  }
 </script>
 </head>

<a href="title2.html" id="samesite_noref_and_targeted_link"
   rel="noreferrer" target="foo">
  same-site rel=noreferrer and target=foo</a><br>
<a href="title2.html" id="samesite_noopener_and_targeted_link"
   rel="noopener" target="foo">
  same-site rel=noopener and target=foo</a><br>
<a href="navigate_opener.html" id="samesite_targeted_link" target="foo">
  same-site target=foo</a><br>
<a href="title2.html" id="samesite_tblank_link" rel="opener" target="_blank">
  same-site rel=opener target=_blank</a><br>
<a href="about:blank" id="blank_targeted_link" target="foo">
  blank_targeted_link=foo</a><br>

<!-- The following set of links have to be fixed at runtime with the proper
  scheme://host:port/ string, since the port is randomly generated. The
  setOriginForLinks method is provided for facilitating the replacement and
  should be called by each browser test utilizing these links. -->
<a href="http://REPLACE/title2.html"
   id="noref_and_tblank_link" rel="noreferrer" target="_blank">
  rel=noreferrer and target=_blank</a><br>
<a href="http://REPLACE/title2.html"
   id="noopener_and_tblank_link" rel="noopener" target="_blank">
  rel=noopener and target=_blank</a><br>
<a href="http://REPLACE/title2.html" id="tblank_link"
   rel="opener" target="_blank">rel=opener target=_blank</a><br>
<a href="http://REPLACE/title2.html" id="noref_link"
   rel="noreferrer">rel=noreferrer</a><br>
<a href="http://REPLACE/title2.html" id="noopener_link"
   rel="noopener">rel=opener</a><br>


<iframe id="frame1" src="frame_tree/1-1.html"></iframe>

</html>