content/base/test/test_bug444546.html

Thu, 15 Jan 2015 21:03:48 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 21:03:48 +0100
branch
TOR_BUG_9701
changeset 11
deefc01c0e14
permissions
-rw-r--r--

Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)

     1 <!DOCTYPE HTML>
     2 <html>
     3 <!--
     4 https://bugzilla.mozilla.org/show_bug.cgi?id=444546
     5 -->
     6 <head>
     7   <title>Test for Bug 444546</title>
     8   <script type="application/javascript" src="/MochiKit/MochiKit.js"></script>
     9   <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
    10   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
    11    <style>
    12      .up {
    13        height: 14px;
    14        width: 1px;
    15        background: blue;
    16        font-size: 11px;
    17        color: white;
    18      }
    19      .down {
    20        height: 14px;
    21        width: 1px;
    22        background: blue;
    23        font-size: 11px;
    24        color: white;
    25      }
    26    </style>
    27 </head>
    28 <body>
    29 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=444546">Mozilla Bug 444546</a>
    30 <p id="display"></p>
    31 <div id="content" style="display: none">
    33 </div>
    34 <pre id="test">
    35 <script type="application/javascript">
    37 /** Test for Bug 444546 **/
    39   var xhrCount = 5;
    40   var xhrs = new Array();
    41   var uploads = new Array();
    42   var maxSize = 5000000;
    43   var hugeString = new Array(maxSize + 1).join('a');
    45   function updateProgress(evt) {
    46     ++evt.target.pcounter;
    47     var time = new Date().getTime();
    48     // 350 - 200 = 150ms
    49     if ((time - evt.target.prevTime) < 150) {
    50       evt.target.log.parentNode.style.background = "red";
    51     }
    52     var diff = (time - evt.target.prevTime);
    53     if (evt.target.min == -1 || evt.target.min > diff) {
    54       evt.target.min = diff;
    55     }
    56     if (evt.target.max == -1 || evt.target.max < diff) {
    57       evt.target.max = diff;
    58     }
    60     evt.target.log.textContent = diff + "ms";
    61     evt.target.prevTime = time;
    62     if (evt.lengthComputable) {
    63       var loaded = (evt.loaded / evt.total);
    64       if (loaded < 1) {
    65         evt.target.log.style.width = (loaded * 400) + "px";
    66       }
    67     }
    68   }
    70   function loaded(evt) {
    71     evt.target.log.style.width = "400px";
    72     evt.target.log.style.background = "green";
    73     if ("xhr" in evt.target) {
    74       evt.target.xhr.prevTime = new Date().getTime();
    75       evt.target.xhr.startTime = evt.target.xhr.prevTime;
    76     }
    77     var total = new Date().getTime() - evt.target.startTime;
    78     evt.target.log.textContent = "total:" + total + "ms";
    79     if (evt.target.pcounter) {
    80       evt.target.log.textContent += " ," + evt.target.pcounter + "pe, avg:" +
    81         parseInt((evt.target.prevTime - evt.target.startTime)/evt.target.pcounter) + "ms";
    82     }
    83     if (evt.target.min != -1) {
    84       ok(evt.target.min >= 150, "Events fired too fast!");
    85       evt.target.log.textContent += ", min:" + evt.target.min + "ms";
    86     }
    87     if (evt.target.max != -1) {
    88       // Disabled for now.
    89       //ok(evt.target.max <= 550, "Events didn't fire fast enough!");
    90       evt.target.log.textContent += ", max:" + evt.target.max + "ms";
    91     }
    92     if ("upload" in evt.target) {
    93       is(evt.total, maxSize * 10, "Wrong data!");
    94       --xhrCount;
    95       if (xhrCount == 0) {
    96         // This is a hack. To get more progress events, server sends the data
    97         // 10 times.
    98         SimpleTest.finish();
    99       } else {
   100         setTimeout(start, 10);
   101       }
   102     } else {
   103       is(evt.total, maxSize, "Wrong data!");
   104     }
   105   }
   107   function start() {
   108     var xhr = new XMLHttpRequest();
   109     xhrs.push(xhr);
   110     uploads.push(xhr.upload);
   111     var container = document.createElement("tr");
   112     var td1 = document.createElement("td");
   113     container.appendChild(td1);
   114     td1.textContent = xhrs.length + ".";
   115     var td2 = document.createElement("td");
   116     container.appendChild(td2);
   117     var td3 = document.createElement("td");
   118     container.appendChild(td3);
   119     var uploadElement = document.createElement("div");
   120     td2.appendChild(uploadElement);
   121     uploadElement.className = "up";
   122     var downloadElement = document.createElement("div");
   123     td3.appendChild(downloadElement);
   124     downloadElement.className = "down";
   125     document.getElementById('tbody').appendChild(container);
   126     xhr.log = downloadElement;
   127     xhr.upload.log = uploadElement;
   128     xhr.onprogress = updateProgress;
   129     xhr.upload.onprogress = updateProgress;
   130     xhr.onload = loaded;
   131     xhr.upload.onload = loaded;
   132     xhr.open("POST", "bug444546.sjs");
   133     xhr.upload.prevTime = new Date().getTime();
   134     xhr.upload.startTime = xhr.upload.prevTime;
   135     xhr.upload.xhr = xhr;
   136     xhr.pcounter = 0;
   137     xhr.upload.pcounter = 0;
   138     xhr.min = -1;
   139     xhr.upload.min = -1;
   140     xhr.max = -1;
   141     xhr.upload.max = -1;
   142     xhr.send(hugeString);
   143   }
   145   SimpleTest.waitForExplicitFinish();
   146   addLoadEvent(function() { setTimeout(start, 10); });
   148 </script>
   149 </pre>
   150   <table>
   151     <tbody id="tbody">
   152       <tr>
   153         <td>XHR</td>
   154         <td style="min-width: 410px;">upload</td>
   155         <td style="min-width: 410px;">download</td>
   156       </tr>
   157     </tbody>
   158   </table>
   159 </body>
   160 </html>

mercurial