append-formelement.html (2161B)
1 <!doctype html> 2 <meta charset="utf-8"> 3 <title>FormData.append (with form element) 4 </title> 5 <link rel="help" href="https://xhr.spec.whatwg.org/#dom-formdata-append"> 6 <script src="/resources/testharness.js"></script> 7 <script src="/resources/testharnessreport.js"></script> 8 <div id="log"></div> 9 <form id="form"></form> 10 <script> 11 test(function() { 12 var fd = new FormData(document.getElementById("form")); 13 fd.append('key', 'value1'); 14 assert_equals(fd.get('key'), "value1"); 15 }, 'testFormDataAppendToForm1'); 16 test(function() { 17 var fd = new FormData(document.getElementById("form")); 18 fd.append('key', 'value2'); 19 fd.append('key', 'value1'); 20 assert_equals(fd.get('key'), "value2"); 21 }, 'testFormDataAppendToForm2'); 22 test(function() { 23 var fd = new FormData(document.getElementById("form")); 24 fd.append('key', undefined); 25 assert_equals(fd.get('key'), "undefined"); 26 }, 'testFormDataAppendToFormUndefined1'); 27 test(function() { 28 var fd = new FormData(document.getElementById("form")); 29 fd.append('key', undefined); 30 fd.append('key', 'value1'); 31 assert_equals(fd.get('key'), "undefined"); 32 }, 'testFormDataAppendToFormUndefined2'); 33 test(function() { 34 var fd = new FormData(document.getElementById("form")); 35 fd.append('key', null); 36 assert_equals(fd.get('key'), "null"); 37 }, 'testFormDataAppendToFormNull1'); 38 test(function() { 39 var fd = new FormData(document.getElementById("form")); 40 fd.append('key', null); 41 fd.append('key', 'value1'); 42 assert_equals(fd.get('key'), "null"); 43 }, 'testFormDataAppendToFormNull2'); 44 test(function() { 45 var fd = new FormData(document.getElementById("form")); 46 assert_throws_js(TypeError, () => {fd.append('name', "string", 'filename')}); 47 }, 'testFormDataAppendToFormString'); 48 test(function() { 49 var fd = new FormData(document.getElementById("form")); 50 assert_throws_js(TypeError, () => {fd.append('name', new URLSearchParams(), 'filename')}); 51 }, 'testFormDataAppendToFormWrongPlatformObject'); 52 </script>