Skip to content

Commit

Permalink
Bug 1557370 [wpt PR 16811] - html: Add a testcase for submit event re…
Browse files Browse the repository at this point in the history
…entrancy protection, a=testonly

Automatic update from web-platform-tests
html: Add a testcase for submit event reentrancy protection (#16811)

Specification change: whatwg/html#4621

--

wp5At-commits: 7ffd31b4eb23f0d99d5333ae2056b8c6896f463b
wpt-pr: 16811
  • Loading branch information
tkent-google authored and jgraham committed Jun 19, 2019
1 parent 5022688 commit 7cb2187
Showing 1 changed file with 35 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,53 @@
assert_equals(counter, 2);
}, 'If constructing entry list flag of form is true, then return');

let test10 = async_test('Cannot navigate (after constructing the entry list)');
test10.step(() => {

test(() => {
let form = populateForm('<input required><input type=submit><button type=submit></button>');
let submitter1 = form.querySelector('input[type=submit]');
let submitter2 = form.querySelector('button[type=submit]');
let invalid = form.querySelector('[required]');
let counter = 0;
invalid.oninvalid = () => {
++counter;
// Needs to click different one because click() has reentrancy protection.
submitter2.click();
};
submitter1.click();
assert_equals(counter, 1);
}, "If form's firing submission events is true, then return; 'invalid' event");

async_test(t => {
let form = populateForm('<input type=submit name=n value=i><button type=submit name=n value=b>');
let submitter1 = form.querySelector('input[type=submit]');
let submitter2 = form.querySelector('button[type=submit]');
let iframe = form.previousSibling;
form.onsubmit = () => {
// Needs to click different one because click() has reentrancy protection.
submitter2.click();
};
submitter1.click();
// We actually submit the form in order to check which 'click()' submits it.
iframe.onload = t.step_func_done(() => {
assert_not_equals(iframe.contentWindow.location.search.indexOf('n=i'), -1);
});
}, "If form's firing submission events is true, then return; 'submit' event");

async_test(t => {
let form = populateForm('<input name=n1 value=v1>');
form.onformdata = (e) => { e.target.remove(); };
let wasLoaded = false;
let iframe = form.previousSibling;
// Request to load '/common/dummy.xhtml', and immediately submit the form to
// the same frame. If the form submission is aborted, the first request
// will be completed.
iframe.onload = test10.step_func_done(() => {
iframe.onload = t.step_func_done(() => {
wasLoaded = true;
assert_true(iframe.contentWindow.location.search.indexOf('n1=v1') == -1);
});
iframe.src = '/common/dummy.xhtml';
assert_false(wasLoaded, 'Make sure the first loading is ongoing.');
form.submit();
});
}, 'Cannot navigate (after constructing the entry list)');
</script>
</body>

0 comments on commit 7cb2187

Please sign in to comment.