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