-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
html: Add tests for SubmitEvent interface (#19562)
Specification PR: whatwg/html#4984
- Loading branch information
1 parent
7b222c0
commit 61c2804
Showing
4 changed files
with
136 additions
and
0 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
html/semantics/forms/form-submission-0/SubmitEvent.window.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#the-submitevent-interface | ||
|
||
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'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
html/semantics/forms/form-submission-0/implicit-submission.optional.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters