Source code

Revision control

Copy as Markdown

Other Tools

Test Info:

<!DOCTYPE html>
<meta charset="utf-8">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="./resources/targetted-form.js"></script>
<!--
The submit() in event handler should *not* get superseded in this case by the
default action submit(), because event handler here calls preventDefault().
-->
<body>
<script>
promise_test(async () => {
let form = populateForm('<input name=n1 value=v1><input type=submit>');
let iframe = form.previousSibling;
let input = form.querySelector("input[name=n1]");
let submitter = form.querySelector("input[type=submit]");
form.addEventListener('click', () => {
input.value = 'v2';
form.submit();
input.value = 'v3';
form.submit();
input.value = 'v4';
});
form.addEventListener('submit', (e) => {
e.preventDefault();
input.value = 'v5';
form.submit();
input.value = 'v6';
form.submit();
input.value = 'v7';
});
submitter.click();
await loadPromise(iframe);
assert_equals(getParamValue(iframe, "n1"), "v6");
}, 'PreventDefaulting form onsubmit should allow submit() to succeed');
promise_test(async () => {
let form = populateForm('<input type=submit><input name=n1 value=v1>');
let iframe = form.previousSibling;
let input = form['n1'];
let submitter = form.querySelector('input[type=submit]');
form.addEventListener('submit', e => {
e.preventDefault();
input.value = 'v2';
form.submit();
input.value = 'v3';
form.remove();
form.submit();
document.body.insertBefore(form, iframe.nextSibling);
input.value = 'v4';
});
submitter.click();
await loadPromise(iframe);
assert_equals(getParamValue(iframe, "n1"), "v2");
}, 'PreventDefaulting form onsubmit should allow submit() to succeed and the second submit() which is invalid should not supersede first one');
</script>
</body>