Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 <!DOCTYPE html> | |
| 2 | |
| 3 <script src="/js-test-resources/js-test.js"></script> | |
| 4 <script> | |
| 5 description("Test verifies that FormData is sent correctly when using " + | |
| 6 "<a href='http://www.w3.org/TR/XMLHttpRequest/#the-send-method'>XM LHttpRequest asynchronously.</a>"); | |
| 7 | |
| 8 var xhrFormDataTestUrl = '/xmlhttprequest/resources/multipart-post-echo.php'; | |
| 9 var xhrFormDataTestCases = [{ | |
| 10 data: { string: 'string value' }, | |
| 11 result: "string=string value" | |
| 12 }, { | |
| 13 data: { bareBlob: new Blob(['blob-value']) }, | |
| 14 result: 'bareBlob=blob:application/octet-stream:blob-value' | |
| 15 }, { | |
| 16 data: { mimeBlob: new Blob(['blob-value'], { type: 'text/html' }) }, | |
| 17 result: 'mimeBlob=blob:text/html:blob-value' | |
| 18 }, { | |
| 19 data: { | |
| 20 namedBlob: { | |
| 21 value: new Blob(['blob-value']), | |
| 22 fileName: 'blob-file.txt' | |
| 23 } | |
| 24 }, | |
| 25 result: 'namedBlob=blob-file.txt:application/octet-stream:blob-value' | |
| 26 }, { | |
| 27 data: { bareFile: new File(['file-value'], 'file-name.txt') }, | |
| 28 result: 'bareFile=file-name.txt:application/octet-stream:file-value' | |
| 29 }, { | |
| 30 data: { | |
| 31 mimeFile: new File(['file-value'], 'file-name.html', { type: 'text/htm l' }) | |
| 32 }, | |
| 33 result: 'mimeFile=file-name.html:text/html:file-value' | |
| 34 }, { | |
| 35 data: { | |
| 36 renamedFile: { | |
| 37 value: new File(['file-value'], 'file-name.html', { type: 'text/ht ml' }), | |
| 38 fileName: 'file-name-override.html' | |
| 39 } | |
| 40 }, | |
| 41 result: 'renamedFile=file-name-override.html:text/html:file-value' | |
| 42 }]; | |
| 43 | |
| 44 var xhr; | |
| 45 var expectedMimeType; | |
| 46 window.jsTestIsAsync = true; | |
| 47 var asyncTestCase = 0; | |
| 48 | |
| 49 function runNextAsyncTest() { | |
| 50 asyncTestCase++; | |
| 51 runAsyncTests(); | |
| 52 } | |
| 53 | |
| 54 function reportResult(e) { | |
| 55 var testCase = xhrFormDataTestCases[asyncTestCase]; | |
| 56 if (xhr.status === 200) { | |
| 57 echoResult = xhr.response; | |
| 58 shouldBeEqualToString("echoResult", testCase.result); | |
| 59 } else { | |
| 60 testFailed("Unknown error"); | |
| 61 } | |
| 62 | |
| 63 runNextAsyncTest(); | |
| 64 } | |
| 65 | |
| 66 function runAsyncTests() { | |
| 67 if (asyncTestCase >= xhrFormDataTestCases.length) { | |
| 68 finishJSTest(); | |
| 69 return; | |
| 70 } else { | |
|
kinuko
2013/11/14 05:41:06
nit: no need of else as we return in the former ca
pwnall-personal
2013/11/14 14:31:19
Done.
| |
| 71 var testCase = xhrFormDataTestCases[asyncTestCase]; | |
| 72 var formData = new FormData(); | |
| 73 for (var fieldName in testCase.data) { | |
| 74 fieldValue = testCase.data[fieldName]; | |
| 75 if (fieldValue.constructor === Object) { | |
| 76 formData.append(fieldName, fieldValue.value, fieldValue.fileNa me); | |
| 77 } else { | |
| 78 formData.append(fieldName, fieldValue); | |
|
kinuko
2013/11/14 05:41:06
nit: indent looks off?
pwnall-personal
2013/11/14 14:31:19
Done.
I also removed the brackets, since both bran
| |
| 79 } | |
| 80 } | |
| 81 | |
| 82 xhr = new XMLHttpRequest(); | |
| 83 xhr.onloadend = reportResult; | |
| 84 xhr.open("POST", xhrFormDataTestUrl, true); | |
| 85 xhr.send(formData); | |
| 86 } | |
| 87 } | |
| 88 | |
| 89 runAsyncTests(); | |
| 90 | |
| 91 </script> | |
| OLD | NEW |