-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement FormData constructor's submitter argument
This was recently added to the standard in whatwg/xhr#366.
- Loading branch information
Showing
6 changed files
with
85 additions
and
9 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
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
38 changes: 38 additions & 0 deletions
38
test/web-platform-tests/to-upstream/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,38 @@ | ||
<!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> | ||
|
||
<form> | ||
<input type=image src='/media/1x1-green.png'></button> | ||
</form> | ||
|
||
<script> | ||
"use strict"; | ||
test(() => { | ||
const form = document.querySelector("form"); | ||
const submitter = form.querySelector("input[type=image]"); | ||
|
||
let formData; | ||
form.addEventListener("submit", e => { | ||
e.preventDefault(); | ||
formData = new FormData(form, submitter); | ||
}); | ||
|
||
// use the DOMRect to construct a coordinate relative to the button, that way we get predictable values regardless of | ||
// layout support | ||
const domRect = submitter.getBoundingClientRect(); | ||
submitter.dispatchEvent( | ||
new MouseEvent("click", { | ||
clientX: Math.round(domRect.x) + 1, | ||
clientY: Math.round(domRect.y) + 2 | ||
}) | ||
); | ||
|
||
assert_equals(formData?.get("x"), "1"); | ||
assert_equals(formData?.get("y"), "2"); | ||
|
||
}, "The constructed FormData object should contain correct entries for Image Button submitter's dispatched coordinate"); | ||
</script> |