content/base/test/test_bug782342.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/content/base/test/test_bug782342.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,85 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<html>
     1.6 +<!--
     1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=782342
     1.8 +-->
     1.9 +<head>
    1.10 +  <title>Test for bug 782342 - blob: protocol no Content-Length header</title>
    1.11 +
    1.12 +  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
    1.13 +  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
    1.14 +
    1.15 +</head>
    1.16 +
    1.17 +<body>
    1.18 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=782342">Mozilla Bug 782342 - blob: protocol no Content-Length header</a>
    1.19 +<p id="display">
    1.20 +  <input id="fileList" type="file"></input>
    1.21 +</p>
    1.22 +
    1.23 +<script type="text/javascript;version=1.7">
    1.24 +SimpleTest.waitForExplicitFinish();
    1.25 +
    1.26 +var url = "file_bug782342.txt";
    1.27 +var xhr = new XMLHttpRequest();
    1.28 +xhr.open("GET", url, true);
    1.29 +xhr.responseType = "blob";
    1.30 +
    1.31 +function checkHeaders(xhr) {
    1.32 +  var headers = xhr.getAllResponseHeaders();
    1.33 +  dump(headers + "\n");
    1.34 +  var p = headers.split("\n");
    1.35 +
    1.36 +  var contentType = false;
    1.37 +  var contentLength = false;
    1.38 +
    1.39 +  for (var i = 0; i < p.length; ++i) {
    1.40 +    var header = p[i].split(':')[0];
    1.41 +    if (header.toLowerCase() == 'content-type')
    1.42 +      contentType = true;
    1.43 +    else if (header.toLowerCase() == 'content-length')
    1.44 +      contentLength = true;
    1.45 +  }
    1.46 +
    1.47 +  ok(contentLength == true, "Content-length is part of the headers!");
    1.48 +  ok(contentType == true, "Content-type is part of the headers!");
    1.49 +
    1.50 +  var ct = xhr.getResponseHeader('content-type');
    1.51 +  ok(ct.length > 0, 'Get Response Header - content type: ' + ct);
    1.52 +  var cl = xhr.getResponseHeader('content-length');
    1.53 +  ok(cl.length > 0, 'Get Response Header - content length: ' + cl);
    1.54 +}
    1.55 +
    1.56 +xhr.addEventListener("load", function () {
    1.57 +  ok(xhr.status === 200, "Status 200!");
    1.58 +  if (xhr.status === 200) {
    1.59 +    var blob = xhr.response;
    1.60 +    ok(blob, "Blob is: " + blob);
    1.61 +    var blobUrl = window.URL.createObjectURL(blob);
    1.62 +    ok(blobUrl, "Blob URL is: " + blobUrl);
    1.63 +    checkHeaders(xhr);
    1.64 +
    1.65 +    var xhrBlob = new XMLHttpRequest();
    1.66 +    xhrBlob.open("GET", blobUrl, true);
    1.67 +    xhrBlob.responseType = "blob";
    1.68 +
    1.69 +    xhrBlob.addEventListener("load", function () {
    1.70 +      var blob2 = xhr.response;
    1.71 +      ok(blob2, "Blob is: " + blob2);
    1.72 +      var blob2Url = window.URL.createObjectURL(blob);
    1.73 +      ok(blob2Url, "Blob URL is: " + blob2Url);
    1.74 +      checkHeaders(xhrBlob);
    1.75 +
    1.76 +      ok(blob2.size == blob.size, "Blob sizes are: " + blob2.size + " - " + blob.size);
    1.77 +      ok(blob2.type == blob.type, "Blob types are: " + blob2.type + " - " + blob.type);
    1.78 +
    1.79 +      SimpleTest.finish();
    1.80 +    }, false);
    1.81 +    xhrBlob.send();
    1.82 +  }
    1.83 +}, false);
    1.84 +xhr.send();
    1.85 +</script>
    1.86 +</body>
    1.87 +
    1.88 +</html>

mercurial