diff options
Diffstat (limited to 'dom/html/test/dialog')
7 files changed, 342 insertions, 0 deletions
diff --git a/dom/html/test/dialog/mochitest.ini b/dom/html/test/dialog/mochitest.ini new file mode 100644 index 0000000000..c9d4d55529 --- /dev/null +++ b/dom/html/test/dialog/mochitest.ini @@ -0,0 +1,9 @@ +[DEFAULT] +prefs = + dom.dialog_element.enabled=true +[test_cancelDialogByEscape.html] +[test_dialog_cancel_with_select.html] +[test_dialog_cancel_events.html] +[test_dialog_cancel_preventDefault.html] +[test_dialog_keydown_preventDefault.html] +[test_bug1648877_dialog_fullscreen_denied.html] diff --git a/dom/html/test/dialog/test_bug1648877_dialog_fullscreen_denied.html b/dom/html/test/dialog/test_bug1648877_dialog_fullscreen_denied.html new file mode 100644 index 0000000000..906c7dd53e --- /dev/null +++ b/dom/html/test/dialog/test_bug1648877_dialog_fullscreen_denied.html @@ -0,0 +1,52 @@ +<!DOCTYPE HTML> +<html> +<!-- +https://bugzilla.mozilla.org/show_bug.cgi?id=1648877 +--> +<head> + <title>Test for Bug 1648877</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> + <a target="_blank" + href="https://bugzilla.mozilla.org/show_bug.cgi?id=1648877">Requesting + fullscreen a dialog element should be denied</a> +<p id="display"></p> +<dialog> +</dialog> +<div style="width: 30px; height:30px" </div> + +<pre id="test"> +<script type="application/javascript"> +SimpleTest.waitForExplicitFinish(); + +function runTest() { + document.addEventListener("fullscreenchange", () => { + ok(false, "Should never receive " + + "a fullscreenchange event in the main window."); + }); + + document.addEventListener('fullscreenerror', (event) => { + ok(!document.fullscreenElement, + "Should not grant request if the element is dialog"); + SimpleTest.finish(); + }); + + const div = document.querySelector("div"); + + div.addEventListener("click", function() { + const dialog = document.querySelector("dialog"); + dialog.requestFullscreen(); + }); + + synthesizeMouseAtCenter(div, {}); +} + +SimpleTest.waitForFocus(runTest); + +</script> +</pre> +</body> +</html> 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> + diff --git a/dom/html/test/dialog/test_dialog_cancel_events.html b/dom/html/test/dialog/test_dialog_cancel_events.html new file mode 100644 index 0000000000..c7b9d25b91 --- /dev/null +++ b/dom/html/test/dialog/test_dialog_cancel_events.html @@ -0,0 +1,57 @@ +<!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="runTest()"> + <a target="_blank" + href="https://bugzilla.mozilla.org/show_bug.cgi?id=1322947">Test cancel event + is fired when the dialog is closed by user interaction</a> +<p id="display"></p> +<dialog> + <p>Hello World</p> +</dialog> +<pre id="test"> +<script type="application/javascript"> +SimpleTest.waitForExplicitFinish(); + +var hasCancelEventFired = false; +var hasCloseEventFired = false; + +function runTest() { + const dialog = document.querySelector("dialog"); + + dialog.addEventListener("cancel", function(event) { + ok(true, "cancel event is fired"); + ok(event.cancelable, "cancel event should be cancelable"); + ok(!hasCancelEventFired, "cancel event should only be fired once"); + ok(!hasCloseEventFired, "close event should be fired after cancel event"); + hasCancelEventFired = true; + }); + + dialog.addEventListener("close", function() { + ok(true, "close event is fired"); + ok(!hasCloseEventFired, "close event should only be fired once"); + ok(hasCancelEventFired, "cancel event should be fired before close event"); + hasCloseEventFired = true; + done(); + }); + + dialog.showModal(); + synthesizeKey("VK_ESCAPE", {}, window); +} + +function done() { + SimpleTest.finish(); +} +</script> +</pre> +</body> +</html> + diff --git a/dom/html/test/dialog/test_dialog_cancel_preventDefault.html b/dom/html/test/dialog/test_dialog_cancel_preventDefault.html new file mode 100644 index 0000000000..3cc4dd0eee --- /dev/null +++ b/dom/html/test/dialog/test_dialog_cancel_preventDefault.html @@ -0,0 +1,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 cancel 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 is fired"); + done(); + } + + dialog.addEventListener("cancel", function(event) { + hasCancelEventFired = true; + event.preventDefault(); + setTimeout(function() { + verify(); + }, 0) + }); + + dialog.addEventListener("close", function() { + ok(false, "close event should not be fired"); + }); + + dialog.showModal(); + synthesizeKey("VK_ESCAPE", {}, window); +} + +function done() { + SimpleTest.finish(); +} +</script> +</pre> +</body> +</html> diff --git a/dom/html/test/dialog/test_dialog_cancel_with_select.html b/dom/html/test/dialog/test_dialog_cancel_with_select.html new file mode 100644 index 0000000000..924ffcf1ca --- /dev/null +++ b/dom/html/test/dialog/test_dialog_cancel_with_select.html @@ -0,0 +1,48 @@ +<!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"> + <select> + <option value="one">one</option> + <option value="two">two</option> + </select> +</dialog> + +<pre id="test"> +<script type="application/javascript"> +SimpleTest.waitForExplicitFinish(); + +function runTest() { + const dialog = document.getElementById("dialog"); + const select = document.querySelector("select"); + + dialog.addEventListener("close", function() { + ok(dialog.close, "dialog with select is closed"); + done(); + }); + dialog.showModal(); + ok(select == document.activeElement, "select element should be focused"); + + synthesizeKey("VK_ESCAPE", {}, window); +} + +function done() { + SimpleTest.finish(); +} +</script> +</pre> +</body> +</html> + diff --git a/dom/html/test/dialog/test_dialog_keydown_preventDefault.html b/dom/html/test/dialog/test_dialog_keydown_preventDefault.html new file mode 100644 index 0000000000..8a9e1ecadc --- /dev/null +++ b/dom/html/test/dialog/test_dialog_keydown_preventDefault.html @@ -0,0 +1,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> |