chromium/third_party/blink/web_tests/external/wpt/html/semantics/interactive-elements/the-dialog-element/dialog-cancel-preventDefault.html

<!DOCTYPE html>
<html>
<head>
  <title>Test cancel event with preventDefault on cancel event for dialog element</title>
  <script src="/resources/testharness.js"></script>
  <script src="/resources/testharnessreport.js"></script>
  <script src="/resources/testdriver.js"></script>
  <script src="/resources/testdriver-vendor.js"></script>
  <script src="/common/top-layer.js"></script>
  <script src="/close-watcher/resources/helpers.js"></script>
  <link rel="help" href="https://bugs.webkit.org/show_bug.cgi?id=227534">
  <link rel="help" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1322947">
</head>
<body>
<p>Test cancel event with preventDefault on cancel event for dialog element</p>
<dialog>
  <p>Hello World</p>
</dialog>
<script type=module>
  setup({ single_test: true });

  var hasCancelEventFired = false;

  const dialog = document.querySelector("dialog");

  const verify = () => {
    assert_true(hasCancelEventFired, "cancel is fired");
    done();
  };

  dialog.addEventListener("cancel", function(event) {
    hasCancelEventFired = true;
    event.preventDefault();
    step_timeout(function() {
      verify();
    }, 0)
  });

  dialog.addEventListener("close", function() {
    assert_true(false, "close event should not be fired");
  });

  dialog.showModal();

  await blessTopLayer(dialog);
  await sendCloseRequest();
</script>
</body>
</html>