<!DOCTYPE html>
<html>
<head>
  <title>window.open from a window being closed</title>
  <script src="/tests/SimpleTest/SimpleTest.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
  <h1>window.open from a window being closed</h1>
<script>
add_task(async function() {
  const RELS = ["", "#noopener", "#opener"];
  const FEATURES = [
    "",
    "noopener",
    "width=300",
    "width=300,noopener",
  ];

  let resolver;
  let channel = new BroadcastChannel("test");
  channel.onmessage = function(e) {
    info("message from broadcastchannel: " + e.data);
    if (e.data == "load") {
      resolver();
    }
  };

  for (let rel of RELS) {
    for (let feature of FEATURES) {
      info(`running test: rel=${rel}, feature=${feature}`);

      let loadPromise = new Promise(r => { resolver = r; });
      window.open("file_window_close_and_open.html" + rel, "_blank", feature);
      await loadPromise;
      ok(true, "popup opened successfully - closing...");
      channel.postMessage("close");
    }
  }
});
</script>
</body>
</html>
