test_bug1250148.html (2089B)
1 <!DOCTYPE HTML> 2 <html> 3 <!-- 4 https://bugzilla.mozilla.org/show_bug.cgi?id=1250148 5 --> 6 <head> 7 <meta charset="utf-8"> 8 <title>Test for Bug 1250148 - FormData and HTML submission compatibility</title> 9 <script src="/tests/SimpleTest/SimpleTest.js"></script> 10 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> 11 </head> 12 <body> 13 <form id="form" enctype="multipart/form-data"><input type="file" name="test" /></form> 14 <script type="application/javascript"> 15 16 SimpleTest.waitForExplicitFinish(); 17 18 var f = document.getElementById('form'); 19 var fd = new FormData(f); 20 var get = fd.get("test"); 21 ok(get instanceof File, "We want a File object."); 22 is(get.name, "", "We want a File with an empty name."); 23 is( 24 get.type, 25 "application/octet-stream", 26 "We want a File with type application/octet-stream." 27 ); 28 is(get.size, 0, "We want a File with an empty body."); 29 30 var getAll = fd.getAll("test"); 31 ok(Array.isArray(getAll), "We want an array with 1 empty File."); 32 is(getAll.length, 1, "We want an array with 1 empty File."); 33 is( 34 getAll[0], 35 get, 36 "We want the File returned from getAll to be that returned from get." 37 ); 38 39 var xhr = new XMLHttpRequest(); 40 xhr.open("POST", "file_bug1250148.sjs", true); 41 xhr.onload = function() { 42 var obj = JSON.parse(xhr.responseText); 43 44 ok(Array.isArray(obj), "XHR response is an array."); 45 is(obj.length, 1, "XHR response array contains 1 result."); 46 47 ok("headers" in obj[0], "XHR response has an header value"); 48 49 ok("Content-Disposition" in obj[0].headers, "XHR response.headers array has a Content-Desposition value"); 50 is(obj[0].headers["Content-Disposition"], "form-data; name=\"test\"; filename=\"\"", "Correct Content-Disposition"); 51 52 ok("Content-Type" in obj[0].headers, "XHR response.headers array has a Content-Type value"); 53 is(obj[0].headers["Content-Type"], "application/octet-stream", "Correct Content-Type"); 54 55 ok("body" in obj[0], "XHR response has a body value"); 56 is(obj[0].body, "", "Correct body value"); 57 58 SimpleTest.finish(); 59 } 60 xhr.send(fd); 61 62 </script> 63 </body> 64 </html>