-
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, xhr: Add tests for 'formdata' event (#14637)
Specification PR: whatwg/html#4239
- Loading branch information
1 parent
3655845
commit c547389
Showing
7 changed files
with
179 additions
and
1 deletion.
There are no files selected for viewing
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
21 changes: 21 additions & 0 deletions
21
html/semantics/forms/form-submission-0/FormDataEvent.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,21 @@ | ||
// https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#the-formdataevent-interface | ||
|
||
test(() => { | ||
let fd = new FormData(); | ||
let typeError = new TypeError(); | ||
assert_throws(typeError, () => { new FormDataEvent() }, '0 arguments'); | ||
assert_throws(typeError, () => { new FormDataEvent('foo') }, '1 argument'); | ||
assert_throws(typeError, () => { new FormDataEvent(fd, fd) }, '2 invalid arguments'); | ||
assert_throws(typeError, () => { new FormDataEvent('foo', null) }, 'Null dictionary'); | ||
assert_throws(typeError, () => { new FormDataEvent('foo', undefined) }, 'Undefined dictionary'); | ||
assert_throws(typeError, () => { new FormDataEvent('foo', { formData: null }) }, 'Null formData'); | ||
assert_throws(typeError, () => { new FormDataEvent('foo', { formData: undefined }) }, 'Undefined formData'); | ||
assert_throws(typeError, () => { new FormDataEvent('foo', { formData: 'bar' }) }, 'Wrong type of formData'); | ||
}, 'Failing FormDataEvent constructor'); | ||
|
||
test(() => { | ||
let fd = new FormData(); | ||
let event = new FormDataEvent('bar', { formData: fd, bubbles: true }); | ||
assert_equals(event.formData, fd); | ||
assert_true(event.bubbles); | ||
}, 'Successful FormDataEvent constructor'); |
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/form-submission-algorithm.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/multipage/form-control-infrastructure.html#form-submission-algorithm"> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script src="./resources/targetted-form.js"></script> | ||
<body> | ||
<script> | ||
test(() => { | ||
let form = populateForm('<input name=n10 value=v10>'); | ||
let counter = 0; | ||
form.addEventListener('formdata', e => { | ||
++counter; | ||
form.submit(); | ||
}); | ||
form.submit(); | ||
assert_equals(counter, 1); | ||
new FormData(form); | ||
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(() => { | ||
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(() => { | ||
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(); | ||
}); | ||
</script> | ||
</body> |
13 changes: 13 additions & 0 deletions
13
html/semantics/forms/form-submission-0/resources/targetted-form.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,13 @@ | ||
let frameCounter = 0; | ||
|
||
function populateForm(optionalContentHtml) { | ||
if (!optionalContentHtml) | ||
optionalContentHtml = ''; | ||
document.body.insertAdjacentHTML( | ||
'afterbegin', | ||
`<iframe name="form-test-target-${frameCounter}"></iframe>` + | ||
`<form action="/common/blank.html" target="` + | ||
`form-test-target-${frameCounter}">${optionalContentHtml}</form>`); | ||
++frameCounter; | ||
return document.body.firstChild.nextSibling; | ||
} |
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
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