| OLD | NEW |
| 1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
| 2 <html> | 2 <html> |
| 3 <head> | 3 <head> |
| 4 <script src="/js-test-resources/js-test-pre.js"></script> | 4 <script src="/js-test-resources/js-test-pre.js"></script> |
| 5 </head> | 5 </head> |
| 6 <body> | 6 <body> |
| 7 <script src="post-blob-content-type-tests.js"></script> | 7 <script src="post-blob-content-type-tests.js"></script> |
| 8 <script type="text/javascript"> | 8 <script type="text/javascript"> |
| 9 description("Test verifies that content MIME type is set correctly " + | 9 description("Test verifies that content MIME type is set correctly " + |
| 10 "when Blob is sent using " + | 10 "when Blob is sent using " + |
| 11 "<a href='http://www.w3.org/TR/XMLHttpRequest/#the-send-method'>
XMLHttpRequest synchronously.</a>"); | 11 "<a href='http://www.w3.org/TR/XMLHttpRequest/#the-send-method'>
XMLHttpRequest synchronously.</a>"); |
| 12 | 12 |
| 13 var xhr; | 13 var xhr; |
| 14 var expectedMimeType; | 14 var expectedMimeType; |
| 15 | 15 |
| 16 function runSyncTests() { | 16 function runSyncTests() { |
| 17 var testCount = xhrBlobTestCases.length; | 17 var testCount = xhrBlobTestCases.length; |
| 18 for (var i = 0; i < testCount; i++) { | 18 for (var i = 0; i < testCount; i++) { |
| 19 var mime = xhrBlobTestCases[i].mime; | 19 var testCase = xhrBlobTestCases[i]; |
| 20 var expectedMime = xhrBlobTestCases[i].expectedMime; | 20 var mime = testCase.mime; |
| 21 var url = xhrBlobTestCases[i].url !== undefined ? xhrBlobTestCases[i
].url + xhrBlobTestUrl : xhrBlobTestUrl; | 21 var file = testCase.file; |
| 22 url += xhrBlobTestCases[i].allowOrigin || ""; | 22 var expectedMime = testCase.expectedMime; |
| 23 if (xhrBlobTestCases[i].shouldThrow !== undefined) { | 23 var url = testCase.url !== undefined ? testCase.url + xhrBlobTestUrl
: xhrBlobTestUrl; |
| 24 url += testCase.allowOrigin || ""; |
| 25 if (testCase.shouldThrow !== undefined) { |
| 24 try { | 26 try { |
| 25 testBlobContentTypeSync(url, mime, expectedMime); | 27 testBlobContentTypeSync(url, file, mime, expectedMime); |
| 26 } catch (e) { | 28 } catch (e) { |
| 27 testPassed("Exception should be thrown.") | 29 testPassed("Exception should be thrown.") |
| 28 } | 30 } |
| 29 } else { | 31 } else { |
| 30 testBlobContentTypeSync(url, mime, expectedMime); | 32 testBlobContentTypeSync(url, file, mime, expectedMime); |
| 31 } | 33 } |
| 32 } | 34 } |
| 33 } | 35 } |
| 34 | 36 |
| 35 function testBlobContentTypeSync(url, mimeType, expectedMime) { | 37 function testBlobContentTypeSync(url, fileName, mimeType, expectedMime) { |
| 36 var blob; | 38 var blob; |
| 37 if (mimeType !== "") | 39 if (fileName) { |
| 38 blob = new Blob(["Test content"], {type: mimeType}); | 40 if (mimeType !== "") |
| 39 else | 41 blob = new File(["Test content"], fileName, {type: mimeType}); |
| 40 blob = new Blob(["Test content"]); | 42 else |
| 43 blob = new File(["Test content"], fileName); |
| 44 } else { |
| 45 if (mimeType !== "") |
| 46 blob = new Blob(["Test content"], {type: mimeType}); |
| 47 else |
| 48 blob = new Blob(["Test content"]); |
| 49 } |
| 41 | 50 |
| 42 xhr = new XMLHttpRequest(); | 51 xhr = new XMLHttpRequest(); |
| 43 xhr.open("POST", url, false); | 52 xhr.open("POST", url, false); |
| 44 xhr.send(blob); | 53 xhr.send(blob); |
| 45 if (xhr.status === 200) { | 54 if (xhr.status === 200) { |
| 46 expectedMimeType = JSON.parse(xhr.response)['content-type'] || ""; | 55 postedMimeType = JSON.parse(xhr.response)['content-type'] || ""; |
| 47 shouldBeEqualToString("expectedMimeType", expectedMime); | 56 shouldBeEqualToString("postedMimeType", expectedMime); |
| 48 } else | 57 } else |
| 49 testFailed("Unknown error"); | 58 testFailed("Unknown error"); |
| 50 | 59 |
| 51 } | 60 } |
| 52 | 61 |
| 53 runSyncTests(); | 62 runSyncTests(); |
| 54 | 63 |
| 55 </script> | 64 </script> |
| 56 </body> | 65 </body> |
| 57 </html> | 66 </html> |
| OLD | NEW |