Backed out changeset 2450366cf7ca (bug 1891629) for causing win msix mochitest failures
[gecko.git] / dom / base / test / test_bug444546.html
blob4fec1754e03b4a32253c0b1a864de816eddf87f1
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 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;
19 .down {
20 height: 14px;
21 width: 1px;
22 background: blue;
23 font-size: 11px;
24 color: white;
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";
52 var diff = (time - evt.target.prevTime);
53 if (evt.target.min == -1 || evt.target.min > diff) {
54 evt.target.min = diff;
56 if (evt.target.max == -1 || evt.target.max < diff) {
57 evt.target.max = diff;
60 evt.target.log.textContent = diff + "ms";
61 evt.target.prevTime = time;
62 if (evt.lengthComputable) {
63 var fractionLoaded = (evt.loaded / evt.total);
64 if (fractionLoaded < 1) {
65 evt.target.log.style.width = (fractionLoaded * 400) + "px";
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;
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";
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";
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";
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);
102 } else {
103 is(evt.total, maxSize, "Wrong data!");
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);
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>