mirror of
https://github.com/servo/servo.git
synced 2025-08-12 17:05:33 +01:00
Refactor FormData code to match updated spec
Use Atoms instead of Strings as keys
This commit is contained in:
parent
61314f5253
commit
7001583047
14 changed files with 469 additions and 89 deletions
|
@ -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>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue