summaryrefslogtreecommitdiffstats
path: root/dom/html/test/dialog/test_dialog_keydown_preventDefault.html
blob: 8a9e1ecadc9fed86aa1905d44d5273429278fa07 (plain)
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
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=1322947
-->
<head>
  <title>Test for Bug 1322947</title>
  <script src="/tests/SimpleTest/SimpleTest.js"></script>
  <script src="/tests/SimpleTest/EventUtils.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body onload="SimpleTest.waitForFocus(runTest)">
  <a target="_blank"
    href="https://bugzilla.mozilla.org/show_bug.cgi?id=1322947">Test cancel event with preventDefault on keydown event for dialog element</a>
<p id="display"></p>
<dialog>
  <p>Hello World</p>
</dialog>
<pre id="test">
<script type="application/javascript">

SimpleTest.waitForExplicitFinish();

var hasCancelEventFired = false;

function runTest() {
  const dialog = document.querySelector("dialog");

  const verify = () => {
    ok(!hasCancelEventFired, "cancel should not be fired");
    ok(hasKeydownEventFired, "document level keydown event should be fired");
    done();
  }

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

  document.addEventListener("keydown", function(event) {
    hasKeydownEventFired = true;
    event.preventDefault();
    setTimeout(function() {
      verify();
    }, 0);
  });
  dialog.showModal();
  synthesizeKey("VK_ESCAPE", {}, window);
}

function done() {
  SimpleTest.finish();
}
</script>
</pre>
</body>
</html>