<!doctype html>
<html>
  <head>
    <title>Auxiliary Browsing Contexts: window.opener, multiple</title>
    <script src="/resources/testharness.js"></script>
    <script src="/resources/testharnessreport.js"></script>
    <script src="/common/PrefixedLocalStorage.js"></script>
  </head>
  <body>
    <div id="log"></div>
    <script>
    var prefixedLocalStorage;
    setup (() => prefixedLocalStorage = new PrefixedLocalStorageTest());
    async_test(t => {
      t.add_cleanup (() => prefixedLocalStorage.cleanup());
      var a       = document.createElement('a');
      a.href      = prefixedLocalStorage.url('resources/multiple-opener.html');
      a.target    = 'multipleOpener';
      window.name = 'topOpener';
      document.body.appendChild(a);
      window.addEventListener('message', t.step_func_done(e => {
        var aux1 = e.data.aux1; // First opened context
        var aux2 = e.data.aux2; // Context opened by first-opened context
        assert_equals(aux1.name, 'multipleOpener');
        assert_equals(aux1.openerName, window.name);
        assert_equals(aux1.isTop, true);
        assert_equals(aux2.name, 'multipleOpenee');
        assert_equals(aux2.openerName, aux1.name);
        assert_equals(aux2.isTop, true);
      }));
      a.click();
    }, 'An auxiliary browsing context should be able to open another auxiliary browsing context');
    </script>
  </body>
</html>
