1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/content/base/test/test_bug444546.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,160 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<html> 1.6 +<!-- 1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=444546 1.8 +--> 1.9 +<head> 1.10 + <title>Test for Bug 444546</title> 1.11 + <script type="application/javascript" src="/MochiKit/MochiKit.js"></script> 1.12 + <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> 1.13 + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> 1.14 + <style> 1.15 + .up { 1.16 + height: 14px; 1.17 + width: 1px; 1.18 + background: blue; 1.19 + font-size: 11px; 1.20 + color: white; 1.21 + } 1.22 + .down { 1.23 + height: 14px; 1.24 + width: 1px; 1.25 + background: blue; 1.26 + font-size: 11px; 1.27 + color: white; 1.28 + } 1.29 + </style> 1.30 +</head> 1.31 +<body> 1.32 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=444546">Mozilla Bug 444546</a> 1.33 +<p id="display"></p> 1.34 +<div id="content" style="display: none"> 1.35 + 1.36 +</div> 1.37 +<pre id="test"> 1.38 +<script type="application/javascript"> 1.39 + 1.40 +/** Test for Bug 444546 **/ 1.41 + 1.42 + var xhrCount = 5; 1.43 + var xhrs = new Array(); 1.44 + var uploads = new Array(); 1.45 + var maxSize = 5000000; 1.46 + var hugeString = new Array(maxSize + 1).join('a'); 1.47 + 1.48 + function updateProgress(evt) { 1.49 + ++evt.target.pcounter; 1.50 + var time = new Date().getTime(); 1.51 + // 350 - 200 = 150ms 1.52 + if ((time - evt.target.prevTime) < 150) { 1.53 + evt.target.log.parentNode.style.background = "red"; 1.54 + } 1.55 + var diff = (time - evt.target.prevTime); 1.56 + if (evt.target.min == -1 || evt.target.min > diff) { 1.57 + evt.target.min = diff; 1.58 + } 1.59 + if (evt.target.max == -1 || evt.target.max < diff) { 1.60 + evt.target.max = diff; 1.61 + } 1.62 + 1.63 + evt.target.log.textContent = diff + "ms"; 1.64 + evt.target.prevTime = time; 1.65 + if (evt.lengthComputable) { 1.66 + var loaded = (evt.loaded / evt.total); 1.67 + if (loaded < 1) { 1.68 + evt.target.log.style.width = (loaded * 400) + "px"; 1.69 + } 1.70 + } 1.71 + } 1.72 + 1.73 + function loaded(evt) { 1.74 + evt.target.log.style.width = "400px"; 1.75 + evt.target.log.style.background = "green"; 1.76 + if ("xhr" in evt.target) { 1.77 + evt.target.xhr.prevTime = new Date().getTime(); 1.78 + evt.target.xhr.startTime = evt.target.xhr.prevTime; 1.79 + } 1.80 + var total = new Date().getTime() - evt.target.startTime; 1.81 + evt.target.log.textContent = "total:" + total + "ms"; 1.82 + if (evt.target.pcounter) { 1.83 + evt.target.log.textContent += " ," + evt.target.pcounter + "pe, avg:" + 1.84 + parseInt((evt.target.prevTime - evt.target.startTime)/evt.target.pcounter) + "ms"; 1.85 + } 1.86 + if (evt.target.min != -1) { 1.87 + ok(evt.target.min >= 150, "Events fired too fast!"); 1.88 + evt.target.log.textContent += ", min:" + evt.target.min + "ms"; 1.89 + } 1.90 + if (evt.target.max != -1) { 1.91 + // Disabled for now. 1.92 + //ok(evt.target.max <= 550, "Events didn't fire fast enough!"); 1.93 + evt.target.log.textContent += ", max:" + evt.target.max + "ms"; 1.94 + } 1.95 + if ("upload" in evt.target) { 1.96 + is(evt.total, maxSize * 10, "Wrong data!"); 1.97 + --xhrCount; 1.98 + if (xhrCount == 0) { 1.99 + // This is a hack. To get more progress events, server sends the data 1.100 + // 10 times. 1.101 + SimpleTest.finish(); 1.102 + } else { 1.103 + setTimeout(start, 10); 1.104 + } 1.105 + } else { 1.106 + is(evt.total, maxSize, "Wrong data!"); 1.107 + } 1.108 + } 1.109 + 1.110 + function start() { 1.111 + var xhr = new XMLHttpRequest(); 1.112 + xhrs.push(xhr); 1.113 + uploads.push(xhr.upload); 1.114 + var container = document.createElement("tr"); 1.115 + var td1 = document.createElement("td"); 1.116 + container.appendChild(td1); 1.117 + td1.textContent = xhrs.length + "."; 1.118 + var td2 = document.createElement("td"); 1.119 + container.appendChild(td2); 1.120 + var td3 = document.createElement("td"); 1.121 + container.appendChild(td3); 1.122 + var uploadElement = document.createElement("div"); 1.123 + td2.appendChild(uploadElement); 1.124 + uploadElement.className = "up"; 1.125 + var downloadElement = document.createElement("div"); 1.126 + td3.appendChild(downloadElement); 1.127 + downloadElement.className = "down"; 1.128 + document.getElementById('tbody').appendChild(container); 1.129 + xhr.log = downloadElement; 1.130 + xhr.upload.log = uploadElement; 1.131 + xhr.onprogress = updateProgress; 1.132 + xhr.upload.onprogress = updateProgress; 1.133 + xhr.onload = loaded; 1.134 + xhr.upload.onload = loaded; 1.135 + xhr.open("POST", "bug444546.sjs"); 1.136 + xhr.upload.prevTime = new Date().getTime(); 1.137 + xhr.upload.startTime = xhr.upload.prevTime; 1.138 + xhr.upload.xhr = xhr; 1.139 + xhr.pcounter = 0; 1.140 + xhr.upload.pcounter = 0; 1.141 + xhr.min = -1; 1.142 + xhr.upload.min = -1; 1.143 + xhr.max = -1; 1.144 + xhr.upload.max = -1; 1.145 + xhr.send(hugeString); 1.146 + } 1.147 + 1.148 + SimpleTest.waitForExplicitFinish(); 1.149 + addLoadEvent(function() { setTimeout(start, 10); }); 1.150 + 1.151 +</script> 1.152 +</pre> 1.153 + <table> 1.154 + <tbody id="tbody"> 1.155 + <tr> 1.156 + <td>XHR</td> 1.157 + <td style="min-width: 410px;">upload</td> 1.158 + <td style="min-width: 410px;">download</td> 1.159 + </tr> 1.160 + </tbody> 1.161 + </table> 1.162 +</body> 1.163 +</html>