chromium/third_party/blink/web_tests/http/tests/loading/resources/onbeforeunload-detach-iframe.html

<a href="onbeforeunload-detach-iframe.html?done" id="link">link</a>
<script>
if (window.location.href.indexOf("?") === -1) {
  window.addEventListener("beforeunload", function() {
    console.log('iframe: onbeforeunload');
    var doneFunction = window.top.iframeDone;
    var iframe = window.top.document.querySelector('iframe');
    iframe.parentNode.removeChild(iframe);
    doneFunction();
  }, false);

  console.log('iframe: clicking');
  var a = document.querySelector("#link");
  var evt = new MouseEvent("click");
  a.dispatchEvent(evt);
}
</script>