test_bug523771.html (4162B)
1 <!DOCTYPE HTML> 2 <html> 3 <!-- 4 https://bugzilla.mozilla.org/show_bug.cgi?id=523771 5 --> 6 <head> 7 <title>Test for Bug 523771</title> 8 <script src="/tests/SimpleTest/SimpleTest.js"></script> 9 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> 10 </head> 11 <body> 12 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=523771">Mozilla Bug 523771</a> 13 <p id="display"></p> 14 <iframe name="target_iframe" id="target_iframe"></iframe> 15 <form action="form_submit_server.sjs" target="target_iframe" id="form" 16 method="POST" enctype="multipart/form-data"> 17 <input id=singleFile name=singleFile type=file> 18 <input id=multiFile name=multiFile type=file multiple> 19 </form> 20 <pre id="test"> 21 <script class="testbody" type="text/javascript"> 22 23 singleFileInput = document.getElementById('singleFile'); 24 multiFileInput = document.getElementById('multiFile'); 25 var input1File = { name: "523771_file1", type: "", body: "file1 contents"}; 26 var input2Files = 27 [{ name: "523771_file2", type: "", body: "second file contents" }, 28 { name: "523771_file3.txt", type: "text/plain", body: "123456" }, 29 { name: "523771_file4.html", type: "text/html", body: "<html>content</html>" } 30 ]; 31 32 SimpleTest.waitForExplicitFinish(); 33 34 function setFileInputs () { 35 var f = createFileWithData(input1File.name, input1File.body, input1File.type); 36 SpecialPowers.wrap(singleFileInput).mozSetFileArray([f]); 37 38 var input2FileNames = []; 39 for (file of input2Files) { 40 f = createFileWithData(file.name, file.body, file.type); 41 input2FileNames.push(f); 42 } 43 SpecialPowers.wrap(multiFileInput).mozSetFileArray(input2FileNames); 44 } 45 46 function createFileWithData(fileName, fileData, fileType) { 47 return new File([fileData], fileName, { type: fileType }); 48 } 49 50 function cleanupFiles() { 51 singleFileInput.value = ""; 52 multiFileInput.value = ""; 53 } 54 55 is(singleFileInput.files.length, 0, "single-file .files.length"); // bug 524421 56 is(multiFileInput.files.length, 0, "multi-file .files.length"); // bug 524421 57 58 setFileInputs(); 59 60 is(singleFileInput.multiple, false, "single-file input .multiple"); 61 is(multiFileInput.multiple, true, "multi-file input .multiple"); 62 is(singleFileInput.value, 'C:\\fakepath\\' + input1File.name, "single-file input .value"); 63 is(multiFileInput.value, 'C:\\fakepath\\' + input2Files[0].name, "multi-file input .value"); 64 is(singleFileInput.files[0].name, input1File.name, "single-file input .files[n].name"); 65 is(singleFileInput.files[0].size, input1File.body.length, "single-file input .files[n].size"); 66 is(singleFileInput.files[0].type, input1File.type, "single-file input .files[n].type"); 67 for(i = 0; i < input2Files.length; ++i) { 68 is(multiFileInput.files[i].name, input2Files[i].name, "multi-file input .files[n].name"); 69 is(multiFileInput.files[i].size, input2Files[i].body.length, "multi-file input .files[n].size"); 70 is(multiFileInput.files[i].type, input2Files[i].type, "multi-file input .files[n].type"); 71 } 72 73 document.getElementById('form').submit(); 74 iframe = document.getElementById('target_iframe'); 75 iframe.onload = function() { 76 response = JSON.parse(iframe.contentDocument.documentElement.textContent); 77 is(response[0].headers["Content-Disposition"], 78 "form-data; name=\"singleFile\"; filename=\"" + input1File.name + 79 "\"", 80 "singleFile Content-Disposition"); 81 is(response[0].headers["Content-Type"], input1File.type || "application/octet-stream", 82 "singleFile Content-Type"); 83 is(response[0].body, input1File.body, "singleFile body"); 84 85 for(i = 0; i < input2Files.length; ++i) { 86 is(response[i + 1].headers["Content-Disposition"], 87 "form-data; name=\"multiFile\"; filename=\"" + input2Files[i].name + 88 "\"", 89 "multiFile Content-Disposition"); 90 is(response[i + 1].headers["Content-Type"], input2Files[i].type || "application/octet-stream", 91 "multiFile Content-Type"); 92 is(response[i + 1].body, input2Files[i].body, "multiFile body"); 93 } 94 95 cleanupFiles(); 96 97 is(singleFileInput.files.length, 0, "single-file .files.length"); // bug 524421 98 is(multiFileInput.files.length, 0, "multi-file .files.length"); // bug 524421 99 100 SimpleTest.finish(); 101 } 102 103 </script> 104 </pre> 105 </body> 106 </html>