-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #9049 - KiChjang:form-data-refactor, r=eefriedman
Refactor FormData code to match updated spec <!-- Reviewable:start --> [<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/9049) <!-- Reviewable:end -->
- Loading branch information
Showing
14 changed files
with
467 additions
and
87 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[formdata-delete.htm] | ||
type:testharness | ||
[testFormDataDeleteFromFormNonExistentKey] | ||
expected: FAIL | ||
[testFormDataDeleteFromFormOtherKey] | ||
expected: FAIL | ||
|
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 @@ | ||
[formdata-get.htm] | ||
type: testharness | ||
[testFormDataGetFromForm] | ||
expected: FAIL | ||
[testFormDataGetAllFromForm] | ||
expected: FAIL |
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,5 @@ | ||
[formdata-has.htm] | ||
type: testharness | ||
[testFormDataHasFromForm] | ||
expected: FAIL | ||
|
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,7 @@ | ||
[formdata-set.htm] | ||
type: testharness | ||
[Passing a String object to FormData.set should work] | ||
expected: FAIL | ||
[testFormDataSetEmptyBlob] | ||
expected: FAIL | ||
|
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
114 changes: 90 additions & 24 deletions
114
tests/wpt/web-platform-tests/XMLHttpRequest/FormData-append.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 |
---|---|---|
@@ -1,28 +1,94 @@ | ||
<!doctype html> | ||
<meta charset=utf-8> | ||
<meta charset="utf-8"> | ||
<title>FormData.append</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> | ||
<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" /> | ||
<script> | ||
function test_formdata(creator, verifier, description) { | ||
async_test(description).step(function() { | ||
var fd = creator(); | ||
var xhr = new XMLHttpRequest(); | ||
xhr.onload = this.step_func(function() { | ||
verifier(xhr.responseText); | ||
this.done(); | ||
}); | ||
xhr.open("POST", "resources/upload.py"); | ||
xhr.send(fd); | ||
}) | ||
} | ||
test_formdata(function() { | ||
var fd = new FormData(); | ||
fd.append("name", new String("value")); | ||
return fd; | ||
}, function(data) { | ||
assert_equals(data, "name=value,\n"); | ||
}, "Passing a String object to FormData.append should work."); | ||
function test_formdata(creator, verifier, description) { | ||
async_test(description).step(function() { | ||
var fd = creator(); | ||
var xhr = new XMLHttpRequest(); | ||
xhr.onload = this.step_func(function() { | ||
verifier(xhr.responseText); | ||
this.done(); | ||
}); | ||
xhr.open("POST", "resources/upload.py"); | ||
xhr.send(fd); | ||
}); | ||
} | ||
|
||
test_formdata(function() { | ||
var fd = new FormData(); | ||
fd.append("name", new String("value")); | ||
return fd; | ||
}, function(data) { | ||
assert_equals(data, "name=value,\n"); | ||
}, "Passing a String object to FormData.append should work."); | ||
|
||
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 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() { | ||
assert_object_equals(create_formdata(['key', new Blob(), 'blank.txt']).get('key'), | ||
new File(new Blob(), 'blank.txt')); | ||
}, 'testFormDataAppendEmptyBlob'); | ||
|
||
function create_formdata() { | ||
var fd = new FormData(); | ||
for (var i = 0; i < arguments.length; i++) { | ||
fd.append.apply(fd, arguments[i]); | ||
}; | ||
return fd; | ||
} | ||
</script> |
Oops, something went wrong.