|
1 <!DOCTYPE HTML> |
|
2 <html> |
|
3 <!-- |
|
4 https://bugzilla.mozilla.org/show_bug.cgi?id=782342 |
|
5 --> |
|
6 <head> |
|
7 <title>Test for bug 782342 - blob: protocol no Content-Length header</title> |
|
8 |
|
9 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
|
10 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> |
|
11 |
|
12 </head> |
|
13 |
|
14 <body> |
|
15 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=782342">Mozilla Bug 782342 - blob: protocol no Content-Length header</a> |
|
16 <p id="display"> |
|
17 <input id="fileList" type="file"></input> |
|
18 </p> |
|
19 |
|
20 <script type="text/javascript;version=1.7"> |
|
21 SimpleTest.waitForExplicitFinish(); |
|
22 |
|
23 var url = "file_bug782342.txt"; |
|
24 var xhr = new XMLHttpRequest(); |
|
25 xhr.open("GET", url, true); |
|
26 xhr.responseType = "blob"; |
|
27 |
|
28 function checkHeaders(xhr) { |
|
29 var headers = xhr.getAllResponseHeaders(); |
|
30 dump(headers + "\n"); |
|
31 var p = headers.split("\n"); |
|
32 |
|
33 var contentType = false; |
|
34 var contentLength = false; |
|
35 |
|
36 for (var i = 0; i < p.length; ++i) { |
|
37 var header = p[i].split(':')[0]; |
|
38 if (header.toLowerCase() == 'content-type') |
|
39 contentType = true; |
|
40 else if (header.toLowerCase() == 'content-length') |
|
41 contentLength = true; |
|
42 } |
|
43 |
|
44 ok(contentLength == true, "Content-length is part of the headers!"); |
|
45 ok(contentType == true, "Content-type is part of the headers!"); |
|
46 |
|
47 var ct = xhr.getResponseHeader('content-type'); |
|
48 ok(ct.length > 0, 'Get Response Header - content type: ' + ct); |
|
49 var cl = xhr.getResponseHeader('content-length'); |
|
50 ok(cl.length > 0, 'Get Response Header - content length: ' + cl); |
|
51 } |
|
52 |
|
53 xhr.addEventListener("load", function () { |
|
54 ok(xhr.status === 200, "Status 200!"); |
|
55 if (xhr.status === 200) { |
|
56 var blob = xhr.response; |
|
57 ok(blob, "Blob is: " + blob); |
|
58 var blobUrl = window.URL.createObjectURL(blob); |
|
59 ok(blobUrl, "Blob URL is: " + blobUrl); |
|
60 checkHeaders(xhr); |
|
61 |
|
62 var xhrBlob = new XMLHttpRequest(); |
|
63 xhrBlob.open("GET", blobUrl, true); |
|
64 xhrBlob.responseType = "blob"; |
|
65 |
|
66 xhrBlob.addEventListener("load", function () { |
|
67 var blob2 = xhr.response; |
|
68 ok(blob2, "Blob is: " + blob2); |
|
69 var blob2Url = window.URL.createObjectURL(blob); |
|
70 ok(blob2Url, "Blob URL is: " + blob2Url); |
|
71 checkHeaders(xhrBlob); |
|
72 |
|
73 ok(blob2.size == blob.size, "Blob sizes are: " + blob2.size + " - " + blob.size); |
|
74 ok(blob2.type == blob.type, "Blob types are: " + blob2.type + " - " + blob.type); |
|
75 |
|
76 SimpleTest.finish(); |
|
77 }, false); |
|
78 xhrBlob.send(); |
|
79 } |
|
80 }, false); |
|
81 xhr.send(); |
|
82 </script> |
|
83 </body> |
|
84 |
|
85 </html> |