-
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.
This commit restrucutres xhr/formdata tests that do not require a form element to be .any.js tests, and thus runnable outside the browser, and in workers (like in Deno). This commit only moves tests around (no changes or removals), with the exception of the "Passing a String object to FormData.set should work" and "Passing a String object to FormData.append should work." tests because the tests are exact replicas of the "formdata with string" test in xhr/formdata.html. Because of that they have been removed.
- Loading branch information
1 parent
15874bf
commit e45a9f9
Showing
18 changed files
with
277 additions
and
358 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<!doctype html> | ||
<meta charset="utf-8"> | ||
<title>FormData.append (with form element) | ||
</title> | ||
<link rel="help" href="https://xhr.spec.whatwg.org/#dom-formdata-append"> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<div id="log"></div> | ||
<form id="form"></form> | ||
<script> | ||
test(function() { | ||
var fd = new FormData(document.getElementById("form")); | ||
fd.append('key', 'value1'); | ||
assert_equals(fd.get('key'), "value1"); | ||
}, 'testFormDataAppendToForm1'); | ||
test(function() { | ||
var fd = new FormData(document.getElementById("form")); | ||
fd.append('key', 'value2'); | ||
fd.append('key', 'value1'); | ||
assert_equals(fd.get('key'), "value2"); | ||
}, 'testFormDataAppendToForm2'); | ||
test(function() { | ||
var fd = new FormData(document.getElementById("form")); | ||
fd.append('key', undefined); | ||
assert_equals(fd.get('key'), "undefined"); | ||
}, 'testFormDataAppendToFormUndefined1'); | ||
test(function() { | ||
var fd = new FormData(document.getElementById("form")); | ||
fd.append('key', undefined); | ||
fd.append('key', 'value1'); | ||
assert_equals(fd.get('key'), "undefined"); | ||
}, 'testFormDataAppendToFormUndefined2'); | ||
test(function() { | ||
var fd = new FormData(document.getElementById("form")); | ||
fd.append('key', null); | ||
assert_equals(fd.get('key'), "null"); | ||
}, 'testFormDataAppendToFormNull1'); | ||
test(function() { | ||
var fd = new FormData(document.getElementById("form")); | ||
fd.append('key', null); | ||
fd.append('key', 'value1'); | ||
assert_equals(fd.get('key'), "null"); | ||
}, 'testFormDataAppendToFormNull2'); | ||
test(function() { | ||
var fd = new FormData(document.getElementById("form")); | ||
assert_throws_js(TypeError, () => {fd.append('name', "string", 'filename')}); | ||
}, 'testFormDataAppendToFormString'); | ||
test(function() { | ||
var fd = new FormData(document.getElementById("form")); | ||
assert_throws_js(TypeError, () => {fd.append('name', new URLSearchParams(), 'filename')}); | ||
}, 'testFormDataAppendToFormWrongPlatformObject'); | ||
</script> |
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,37 @@ | ||
// META: title=FormData.append | ||
|
||
test(function() { | ||
assert_equals(create_formdata(['key', 'value1']).get('key'), "value1"); | ||
}, 'testFormDataAppend1'); | ||
test(function() { | ||
assert_equals(create_formdata(['key', 'value2'], ['key', 'value1']).get('key'), "value2"); | ||
}, 'testFormDataAppend2'); | ||
test(function() { | ||
assert_equals(create_formdata(['key', undefined]).get('key'), "undefined"); | ||
}, 'testFormDataAppendUndefined1'); | ||
test(function() { | ||
assert_equals(create_formdata(['key', undefined], ['key', 'value1']).get('key'), "undefined"); | ||
}, 'testFormDataAppendUndefined2'); | ||
test(function() { | ||
assert_equals(create_formdata(['key', null]).get('key'), "null"); | ||
}, 'testFormDataAppendNull1'); | ||
test(function() { | ||
assert_equals(create_formdata(['key', null], ['key', 'value1']).get('key'), "null"); | ||
}, 'testFormDataAppendNull2'); | ||
test(function() { | ||
var before = new Date(new Date().getTime() - 2000); // two seconds ago, in case there's clock drift | ||
var fd = create_formdata(['key', new Blob(), 'blank.txt']).get('key'); | ||
assert_equals(fd.name, "blank.txt"); | ||
assert_equals(fd.type, ""); | ||
assert_equals(fd.size, 0); | ||
assert_greater_than_equal(fd.lastModified, before); | ||
assert_less_than_equal(fd.lastModified, new Date()); | ||
}, 'testFormDataAppendEmptyBlob'); | ||
|
||
function create_formdata() { | ||
var fd = new FormData(); | ||
for (var i = 0; i < arguments.length; i++) { | ||
fd.append.apply(fd, arguments[i]); | ||
}; | ||
return fd; | ||
} |
2 changes: 1 addition & 1 deletion
2
xhr/formdata-constructor.html → xhr/formdata/constructor-formelement.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
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,6 @@ | ||
// META: title=FormData: constructor | ||
|
||
test(() => { | ||
assert_throws_js(TypeError, () => { new FormData(null); }); | ||
assert_throws_js(TypeError, () => { new FormData("string"); }); | ||
}, "Constructors should throw a type error"); |
Oops, something went wrong.