summaryrefslogtreecommitdiffstats
path: root/dom/html/test/dialog/test_cancelDialogByEscape.html
diff options
context:
space:
mode:
Diffstat (limited to 'dom/html/test/dialog/test_cancelDialogByEscape.html')
-rw-r--r--dom/html/test/dialog/test_cancelDialogByEscape.html64
1 files changed, 64 insertions, 0 deletions
diff --git a/dom/html/test/dialog/test_cancelDialogByEscape.html b/dom/html/test/dialog/test_cancelDialogByEscape.html
new file mode 100644
index 0000000000..d0c8d80385
--- /dev/null
+++ b/dom/html/test/dialog/test_cancelDialogByEscape.html
@@ -0,0 +1,64 @@
+<!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 dialog modal is closed by escape key</a>
+<p id="display"></p>
+<dialog id="dialog">
+ <p>Hello World</p>
+</dialog>
+
+<dialog id="dialogWithAutofocus">
+ <input autofocus/>
+</dialog>
+
+<pre id="test">
+<script type="application/javascript">
+SimpleTest.waitForExplicitFinish();
+
+/* Make sure we still cancel the dialog even if the input element is focused */
+function runTestCancelWhenInputFocused() {
+ const dialog = document.getElementById("dialogWithAutofocus");
+ const input = document.querySelector("input");
+
+ dialog.addEventListener("close", function() {
+ ok(dialog.close, "dialog with input autofocused is closed");
+ done();
+ });
+ dialog.showModal();
+ ok(input == document.activeElement, "input element should be focused");
+
+ synthesizeKey("VK_ESCAPE", {}, window);
+}
+
+function runTest() {
+ const dialog = document.getElementById("dialog");
+
+ dialog.addEventListener("close", function() {
+ ok(dialog.close, "dialog closed");
+ setTimeout(function(){
+ runTestCancelWhenInputFocused();
+ }, 0);
+ });
+
+ dialog.showModal();
+ synthesizeKey("VK_ESCAPE", {}, window);
+}
+
+function done() {
+ SimpleTest.finish();
+}
+</script>
+</pre>
+</body>
+</html>
+