-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
LibWeb: Update FormData constructor to reflect the spec
- Loading branch information
1 parent
5c03258
commit 9524330
Showing
5 changed files
with
143 additions
and
6 deletions.
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
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
15 changes: 15 additions & 0 deletions
15
Tests/LibWeb/Text/expected/wpt-import/xhr/formdata/constructor-submitter.txt
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,15 @@ | ||
Harness status: OK | ||
|
||
Found 9 tests | ||
|
||
6 Pass | ||
3 Fail | ||
Pass FormData construction should allow a null submitter | ||
Pass FormData construction should allow an undefined form and an undefined submitter | ||
Pass FormData construction should allow an undefined form and a null submitter | ||
Pass FormData construction should throw a TypeError if a non-null submitter is not a submit button | ||
Pass FormData construction should throw a 'NotFoundError' DOMException if a non-null submitter is not owned by the form | ||
Fail The constructed FormData object should contain an in-tree-order entry for a named submit button submitter | ||
Pass The constructed FormData object should not contain an entry for an unnamed submit button submitter | ||
Fail The constructed FormData object should contain in-tree-order entries for an activated Image Button submitter | ||
Fail The constructed FormData object should contain in-tree-order entries for an unactivated Image Button submitter |
100 changes: 100 additions & 0 deletions
100
Tests/LibWeb/Text/input/wpt-import/xhr/formdata/constructor-submitter.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,100 @@ | ||
<!DOCTYPE html> | ||
<meta charset='utf-8'> | ||
<link rel='help' href='https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#constructing-the-form-data-set'> | ||
<link ref='help' href='https://xhr.spec.whatwg.org/#dom-formdata'> | ||
<script src='../../resources/testharness.js'></script> | ||
<script src='../../resources/testharnessreport.js'></script> | ||
|
||
<button name=outerNamed value=GO form='myform'></button> | ||
<form id='myform' onsubmit='return false'> | ||
<input name=n1 value=v1> | ||
<button name=named value=GO></button> | ||
<button id=unnamed value=unnamed></button> | ||
<button form="another" name=unassociated value=unassociated></button> | ||
<input type=image name=namedImage src='/media/1x1-green.png'></button> | ||
<input type=image id=unnamedImage src='/media/1x1-green.png'></button> | ||
<input type=image name=unactivatedImage src='/media/1x1-green.png'></button> | ||
<input name=n3 value=v3> | ||
</form> | ||
|
||
<form id='another'> | ||
<button name=unassociated2 value=unassociated></button> | ||
</form> | ||
|
||
<script> | ||
function assertFormDataEntries(formData, expectedEntries) { | ||
const expectedEntryNames = expectedEntries.map((entry) => entry[0]); | ||
const actualEntries = [...formData.entries()]; | ||
const actualEntryNames = actualEntries.map((entry) => entry[0]); | ||
assert_array_equals(actualEntryNames, expectedEntryNames); | ||
for (let i = 0; i < actualEntries.length; i++) { | ||
assert_array_equals(actualEntries[i], expectedEntries[i]); | ||
} | ||
} | ||
|
||
const form = document.querySelector('#myform'); | ||
|
||
test(() => { | ||
assertFormDataEntries( | ||
new FormData(form, null), | ||
[['n1', 'v1'], ['n3', 'v3']] | ||
); | ||
}, 'FormData construction should allow a null submitter'); // the use case here is so web developers can avoid null checks, e.g. `new FormData(e.target, e.submitter)` | ||
|
||
test(() => { | ||
assertFormDataEntries(new FormData(undefined, undefined), []); | ||
}, 'FormData construction should allow an undefined form and an undefined submitter'); | ||
|
||
test(() => { | ||
assertFormDataEntries(new FormData(undefined, null), []); | ||
}, 'FormData construction should allow an undefined form and a null submitter'); | ||
|
||
test(() => { | ||
assert_throws_js(TypeError, () => new FormData(form, document.querySelector('[name=n1]'))); | ||
}, 'FormData construction should throw a TypeError if a non-null submitter is not a submit button'); | ||
|
||
test(() => { | ||
assert_throws_dom('NotFoundError', () => new FormData(form, document.querySelector('[name=unassociated]'))); | ||
assert_throws_dom('NotFoundError', () => new FormData(form, document.querySelector('[name=unassociated2]'))); | ||
}, "FormData construction should throw a 'NotFoundError' DOMException if a non-null submitter is not owned by the form"); | ||
|
||
test(() => { | ||
assertFormDataEntries( | ||
new FormData(form, document.querySelector('[name=named]')), | ||
[['n1', 'v1'], ['named', 'GO'], ['n3', 'v3']] | ||
); | ||
assertFormDataEntries( | ||
new FormData(form, document.querySelector('[name=outerNamed]')), | ||
[['outerNamed', 'GO'], ['n1', 'v1'], ['n3', 'v3']] | ||
); | ||
}, 'The constructed FormData object should contain an in-tree-order entry for a named submit button submitter'); | ||
|
||
test(() => { | ||
assertFormDataEntries( | ||
new FormData(form, document.querySelector('#unnamed')), | ||
[['n1', 'v1'], ['n3', 'v3']] | ||
); | ||
}, 'The constructed FormData object should not contain an entry for an unnamed submit button submitter'); | ||
|
||
test(() => { | ||
const submitter1 = document.querySelector('[name=namedImage]'); | ||
submitter1.click(); | ||
const submitter2 = document.querySelector('#unnamedImage'); | ||
submitter2.click(); | ||
assertFormDataEntries( | ||
new FormData(form, submitter1), | ||
[['n1', 'v1'], ['namedImage.x', '0'], ['namedImage.y', '0'], ['n3', 'v3']] | ||
); | ||
assertFormDataEntries( | ||
new FormData(form, submitter2), | ||
[['n1', 'v1'], ['x', '0'], ['y', '0'], ['n3', 'v3']] | ||
); | ||
}, 'The constructed FormData object should contain in-tree-order entries for an activated Image Button submitter'); | ||
|
||
test(() => { | ||
assertFormDataEntries( | ||
new FormData(form, document.querySelector('[name=unactivatedImage]')), | ||
[['n1', 'v1'], ['unactivatedImage.x', '0'], ['unactivatedImage.y', '0'], ['n3', 'v3']] | ||
); | ||
}, 'The constructed FormData object should contain in-tree-order entries for an unactivated Image Button submitter'); | ||
</script> |