| OLD | NEW |
| (Empty) |
| 1 <html> | |
| 2 <head> | |
| 3 <title> Test case for bug 18655 </title> | |
| 4 </head> | |
| 5 <body> | |
| 6 <p> Test case for Bug <a href="https://bugs.webkit.org/show_bug.cgi?id=18655">18
655</a>: [XHR] onProgress event | |
| 7 needs to be dispatched according to what the specification states </p> | |
| 8 <p> This test verify that we "dispatch a progress event called progress about | |
| 9 every 50ms or for every byte received, whichever is least frequent".</p> | |
| 10 <p> You should see a sequence of 5 PASSED. </p> | |
| 11 <p id="console"></p> | |
| 12 | |
| 13 <script type="text/javascript"> | |
| 14 if (window.testRunner) { | |
| 15 testRunner.dumpAsText(); | |
| 16 testRunner.waitUntilDone(); | |
| 17 } | |
| 18 | |
| 19 function log(message) | |
| 20 { | |
| 21 document.getElementById("console").appendChild(document.createTextNode(messa
ge)); | |
| 22 document.getElementById("console").appendChild(document.createElement("br"))
; | |
| 23 } | |
| 24 | |
| 25 var testsCompleted = 0; | |
| 26 | |
| 27 function test(iteration, delay, compare, testDescription) | |
| 28 { | |
| 29 var count = 0; | |
| 30 var sawReadyStateDONE = false; | |
| 31 function onProgress(e) { | |
| 32 ++count; | |
| 33 if (sawReadyStateDONE) | |
| 34 log("FAILED: saw 'progress' event after readystate 'DONE' event for
" + testDescription); | |
| 35 } | |
| 36 | |
| 37 function onReadyState(e) { | |
| 38 if (this.readyState == 4) { | |
| 39 sawReadyStateDONE = true; | |
| 40 var passed = compare(count, iteration); | |
| 41 log(passed ? "PASSED" : "FAILED (count was " + count + ") for " + te
stDescription); | |
| 42 ++testsCompleted; | |
| 43 if (testsCompleted == 5) { | |
| 44 if (window.testRunner) | |
| 45 testRunner.notifyDone(); | |
| 46 } | |
| 47 } | |
| 48 } | |
| 49 | |
| 50 var req = new XMLHttpRequest(); | |
| 51 req.onprogress = onProgress; | |
| 52 req.onreadystatechange = onReadyState; | |
| 53 req.open("GET", "resources/download-with-delay.php?iteration=" + iteration +
"&delay=" + delay, true); | |
| 54 req.send(null); | |
| 55 } | |
| 56 | |
| 57 try { | |
| 58 // Number of chunks to send, delay between chunks | |
| 59 var strictTests = [ 2, 80, | |
| 60 1, 1000, | |
| 61 2, 50 ]; | |
| 62 function compareStrict(count, iteration) | |
| 63 { | |
| 64 return count == iteration; | |
| 65 } | |
| 66 | |
| 67 var i = 0; | |
| 68 while (strictTests.length) { | |
| 69 var iteration = strictTests.shift(); | |
| 70 var delay = strictTests.shift(); | |
| 71 test(iteration, delay, compareStrict, "strict test " + ++i); | |
| 72 } | |
| 73 | |
| 74 // Number of chunks to send, delay between chunks | |
| 75 var throttledTests = [ 5, 20, | |
| 76 6, 30 ]; | |
| 77 function compareThrottled(count, iteration) | |
| 78 { | |
| 79 return count < iteration; | |
| 80 } | |
| 81 | |
| 82 i = 0; | |
| 83 while(throttledTests.length) { | |
| 84 var iteration = throttledTests.shift(); | |
| 85 var delay = throttledTests.shift(); | |
| 86 test(iteration, delay, compareThrottled, "throttled test " + ++i); | |
| 87 } | |
| 88 } catch(e) { | |
| 89 log("FAILED: exception raised: " + e.message); | |
| 90 } | |
| 91 </script> | |
| 92 </body> | |
| 93 </html> | |
| OLD | NEW |