Skip to content

Commit

Permalink
Bug 1586978 [wpt PR 19562] - html: Add tests for SubmitEvent interfac…
Browse files Browse the repository at this point in the history
…e, a=testonly

Automatic update from web-platform-tests
html: Add tests for SubmitEvent interface (#19562)

Specification PR: whatwg/html#4984

--

wpt-commits: 61c2804bf27a7abc1b8bc406627f6bf3b3344f14
wpt-pr: 19562

Differential Revision: https://phabricator.services.mozilla.com/D53600

UltraBlame original commit: 8e52d11e8347d0a5573b9c349fa15722ef7448b1
  • Loading branch information
marco-c committed Nov 21, 2019
1 parent 32792a5 commit 8a9df1a
Show file tree
Hide file tree
Showing 4 changed files with 136 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@


test(() => {
let button = document.createElement('button');
let typeError = new TypeError();
assert_throws(typeError, () => { new SubmitEvent() }, '0 arguments');
assert_throws(typeError, () => { new SubmitEvent('bar', button) }, '1 invalid arguments');
assert_throws(typeError, () => { new SubmitEvent(button, button) }, '2 invalid arguments');
assert_throws(typeError, () => { new SubmitEvent('foo', null) }, 'Null dictionary');
assert_throws(typeError, () => { new SubmitEvent('foo', undefined) }, 'Undefined dictionary');
assert_throws(typeError, () => { new SubmitEvent('foo', { submitter: null }) }, 'Null submitter');
assert_throws(typeError, () => { new SubmitEvent('foo', { submitter: undefined }) }, 'Undefined submitter');
assert_throws(typeError, () => { new SubmitEvent('foo', { submitter: 'bar' }) }, 'Wrong type of submitter');
}, 'Failing SubmitEvent constructor');

test(() => {
let button = document.createElement('button');
let event = new SubmitEvent('bar', { submitter: button, bubbles: true });
assert_equals(event.submitter, button);
assert_true(event.bubbles);
}, 'Successful SubmitEvent constructor');

test(() => {
let event = new SubmitEvent('bar', { submitter: null});
assert_equals(event.submitter, null);
}, 'Successful SubmitEvent constructor; null submitter');

test(() => {
let event = new SubmitEvent('baz', {});
assert_equals(event.submitter, null);
}, 'Successful SubmitEvent constructor; empty dictionary');

test(() => {
let event = new SubmitEvent('baz');
assert_equals(event.submitter, null);
}, 'Successful SubmitEvent constructor; missing dictionary');
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,60 @@
});
}, "If form's firing submission events is true, then return; 'submit' event");

promise_test(async () => {
let form = populateForm('<button type=submit></button><input name=n1 value=submit type=submit>');
let iframe = form.previousSibling;
let submitter = form.querySelector('input[type=submit]');
let event;
form.addEventListener('submit', e => { event = e; });
submitter.click();
await loadPromise(iframe);
assert_true(event.bubbles);
assert_true(event.cancelable);
assert_equals(event.submitter, submitter);
assert_true(event instanceof SubmitEvent);
}, 'firing an event named submit; clicking a submit button');

promise_test(async () => {
let form = populateForm('');
let iframe = form.previousSibling;
let event;
form.addEventListener('submit', e => { event = e; });
form.requestSubmit();
await loadPromise(iframe);
assert_true(event.bubbles);
assert_true(event.cancelable);
assert_equals(event.submitter, null);
assert_true(event instanceof SubmitEvent);
}, 'firing an event named submit; form.requestSubmit()');

promise_test(async () => {
let form = populateForm('');
let iframe = form.previousSibling;
let event;
form.addEventListener('submit', e => { event = e; });
form.requestSubmit(null);
await loadPromise(iframe);
assert_true(event.bubbles);
assert_true(event.cancelable);
assert_equals(event.submitter, null);
assert_true(event instanceof SubmitEvent);
}, 'firing an event named submit; form.requestSubmit(null)');

promise_test(async () => {
let form = populateForm('<input type=submit><button type=submit></button>');
let iframe = form.previousSibling;
let submitter = form.querySelector('button');
let event;
form.addEventListener('submit', e => { event = e; });
form.requestSubmit(submitter);
await loadPromise(iframe);
assert_true(event.bubbles);
assert_true(event.cancelable);
assert_equals(event.submitter, submitter);
assert_true(event instanceof SubmitEvent);
}, 'firing an event named submit; form.requestSubmit(submitter)');

async_test(t => {
let form = populateForm('<input name=n1 value=v1>');
form.onformdata = (e) => { e.target.remove(); };
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<!DOCTYPE html>
<link rel="help" href="https://html.spec.whatwg.org/C/#implicit-submission">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
<script src="./resources/targetted-form.js"></script>
<body>
<script>
// This test file is "optional" because triggering implicit submission by
// "Enter" key is not standardized.

const ENTER = '\uE007';

promise_test(async () => {
let form = populateForm('<input name=text value=abc><input name=submiButton type=submit>');
let event;
form.text.focus();
form.addEventListener('submit', e => { event = e; });
await test_driver.send_keys(form.text, ENTER);
assert_true(event.bubbles);
assert_true(event.cancelable);
assert_equals(event.submitter, form.submitButton);
assert_true(event instanceof SubmitEvent);
}, 'Submit event with a submit button');

promise_test(async () => {
let form = populateForm('<input name=text value=abc>');
let event;
form.text.focus();
form.addEventListener('submit', e => { event = e; });
await test_driver.send_keys(form.text, ENTER);
assert_true(event.bubbles);
assert_true(event.cancelable);
assert_equals(event.submitter, null);
assert_true(event instanceof SubmitEvent);
}, 'Submit event with no submit button');
</script>
</body>
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,10 @@ function submitPromise(form, iframe) {
form.submit();
});
}

function loadPromise(iframe) {
return new Promise((resolve, reject) => {
iframe.onload = resolve;
iframe.onerror = () => reject(new Error('iframe onerror fired'));
});
}

0 comments on commit 8a9df1a

Please sign in to comment.