content/base/test/test_bug782342.html

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial