Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 <!doctype html> | |
| 2 <html> | |
| 3 <head> | |
| 4 <script src="../resources/testharness.js"></script> | |
| 5 <script src="../resources/testharnessreport.js"></script> | |
| 6 </head> | |
| 7 <body> | |
| 8 <p> Verify that a load ProgressEvent is dispatched and have the expected values. </p> | |
| 9 <div id="log"></div> | |
| 10 <script type="text/javascript"> | |
| 11 | |
| 12 var xhr; | |
| 13 var payload = "data"; | |
| 14 var expectedLength = payload.length; | |
| 15 var results = ""; | |
| 16 var expected = " loadstart readyState=DONE load"; | |
| 17 | |
| 18 function verifyProgressEvent(context, e, expected) | |
| 19 { | |
| 20 assert_true(e.lengthComputable); | |
| 21 assert_equals(e.loaded, expected, "Expected 'loaded' value for '" + context + " ' event."); | |
|
tyoshino (SeeGerritForStatus)
2013/11/25 12:35:33
+ " ' event.");
->
+ "' event.");
sof
2013/11/25 15:28:18
Done.
| |
| 22 assert_equals(e.total, expected, "Expected 'total' value for '" + context + "' event."); | |
| 23 } | |
| 24 | |
| 25 function logProgressEvent(e) { | |
| 26 results += " " + e.type; | |
| 27 } | |
| 28 | |
| 29 function logUnexpectedProgressEvent(e) { | |
| 30 results += " [unexpected ProgressEvent: " + e.type + "]"; | |
| 31 completeTest(); | |
| 32 } | |
| 33 | |
| 34 function completeTest() | |
| 35 { | |
| 36 assert_equals(results, expected, "Expected load event sequence"); | |
| 37 testOnloadEvent.done(); | |
| 38 } | |
| 39 | |
| 40 function loadHandler(e) | |
| 41 { | |
| 42 logProgressEvent(e); | |
| 43 assert_true(e instanceof ProgressEvent); | |
| 44 verifyProgressEvent("onload", e, expectedLength); | |
| 45 completeTest(); | |
| 46 } | |
| 47 | |
| 48 var testOnloadEvent = async_test("Check that 'load' events are delivered and hav e expected values."); | |
| 49 testOnloadEvent.step(function () { | |
| 50 xhr = new XMLHttpRequest(); | |
| 51 xhr.onreadystatechange = testOnloadEvent.step_func(function(e) { | |
| 52 if (xhr.readyState == xhr.DONE) | |
| 53 results += " readyState=DONE"; | |
| 54 }); | |
| 55 xhr.onloadstart = testOnloadEvent.step_func(logProgressEvent); | |
| 56 xhr.onabort = testOnloadEvent.step_func(logUnexpectedProgressEvent); | |
| 57 xhr.onerror = testOnloadEvent.step_func(logUnexpectedProgressEvent); | |
| 58 xhr.onload = testOnloadEvent.step_func(loadHandler); | |
| 59 xhr.open("POST", "resources/post-echo.php", true); | |
| 60 xhr.send(payload); | |
| 61 }); | |
| 62 </script> | |
| 63 </body> | |
| 64 </html> | |
| OLD | NEW |