summaryrefslogtreecommitdiffstats
path: root/dom/events/test/test_submitevent_on_form.html
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /dom/events/test/test_submitevent_on_form.html
parentInitial commit. (diff)
downloadfirefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz
firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/events/test/test_submitevent_on_form.html')
-rw-r--r--dom/events/test/test_submitevent_on_form.html67
1 files changed, 67 insertions, 0 deletions
diff --git a/dom/events/test/test_submitevent_on_form.html b/dom/events/test/test_submitevent_on_form.html
new file mode 100644
index 0000000000..01cd8f28ee
--- /dev/null
+++ b/dom/events/test/test_submitevent_on_form.html
@@ -0,0 +1,67 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+ <title>Test submit event on form</title>
+ <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+ <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
+ <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+</head>
+<body>
+ <form action="javascript:doDefault()" id="form">
+ <input name="n1" value="v1">
+ <input type="submit" value="Do Default Action">
+ </form>
+ <pre id="test">
+ <script type="application/javascript">
+SimpleTest.waitForExplicitFinish();
+SimpleTest.waitForFocus(runTests);
+
+var defaultActionCount = 0;
+
+function doDefault()
+{
+ defaultActionCount++;
+}
+
+async function runTests()
+{
+ const form = document.getElementById("form");
+ let formDataInEvent = null;
+
+ // Test if submission from submit() is deferred.
+ await SpecialPowers.pushPrefEnv({
+ set: [["dom.forms.submit.trusted_event_only", false]],
+ });
+
+ form.addEventListener("submit", function(e) {
+ form.elements[0].value = "v1";
+ form.submit();
+ form.elements[0].value = "v2";
+ }, { once: true });
+
+ form.addEventListener('formdata', e => {
+ formDataInEvent = e.formData;
+ });
+
+ form.dispatchEvent(new Event('submit'));
+ await new Promise(resolve => SimpleTest.executeSoon(resolve));
+
+ is(defaultActionCount, 1, "should only submit once");
+ is(formDataInEvent.get('n1'), 'v2', "submission from submit() should be deferred");
+
+ // Test untrusted submit event shouldn't trigger form default action.
+ defaultActionCount = 0;
+ await SpecialPowers.pushPrefEnv({
+ set: [["dom.forms.submit.trusted_event_only", true]],
+ });
+
+ form.dispatchEvent(new Event('submit'));
+ setTimeout(() => {
+ is(defaultActionCount, 0, "untrusted submit event shouldn't trigger form default action");
+ SimpleTest.finish();
+ });
+}
+ </script>
+ </pre>
+</body>
+</html>