Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 <!doctype html> | |
| 1 <html> | 2 <html> |
| 2 <head> | 3 <head> |
| 3 <title>Test case for bug 40952</title> | 4 <title>Test case for bug 40952</title> |
| 5 <script src="../resources/testharness.js"></script> | |
| 6 <script src="../resources/testharnessreport.js"></script> | |
| 4 </head> | 7 </head> |
| 5 <body> | 8 <body> |
| 6 <p> Test case for <a href="https://bugs.webkit.org/show_bug.cgi?id=40952"> bug 4 0952</a>: Onloadend event is not supported in XMLHttpRequest</p> | 9 <p> Test case for <a href="https://bugs.webkit.org/show_bug.cgi?id=40952"> bug 4 0952</a>: Onloadend event is not supported in XMLHttpRequest</p> |
| 7 <p> Verify that a loadend ProgressEvent is dispatched after the load ProgressEve nt when an async upload request completes normally.</p> | 10 <p> Verify that a loadend ProgressEvent is dispatched after the load ProgressEve nt when an async upload request completes normally.</p> |
| 8 <p>PASS should appear below:</p> | 11 <div id="log"></div> |
| 9 <p id=console></p> | |
| 10 <script type="text/javascript"> | 12 <script type="text/javascript"> |
| 11 if (window.testRunner) { | 13 |
| 12 testRunner.dumpAsText(); | 14 var xhr; |
| 13 testRunner.waitUntilDone(); | 15 var payload = "data"; |
| 16 var expectedLength = payload.length; | |
| 17 var results = ""; | |
| 18 var expected = " loadstart load loadend"; | |
| 19 | |
| 20 function verifyProgressEvent(context, e, expected) | |
| 21 { | |
| 22 assert_true(e.lengthComputable); | |
| 23 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.
| |
| 24 assert_equals(e.total, expected, "Expected 'total' value for '" + context + "' event."); | |
| 25 } | |
| 26 | |
| 27 function logProgressEvent(e) { | |
| 28 results += " " + e.type; | |
| 14 } | 29 } |
| 15 | 30 |
| 16 function log(message) | 31 function log(message) |
| 17 { | 32 { |
| 18 var consoleElt = document.getElementById("console"); | 33 var consoleElt = document.getElementById("console"); |
| 19 consoleElt.appendChild(document.createTextNode(message)); | 34 consoleElt.appendChild(document.createTextNode(message)); |
| 20 } | 35 } |
|
tyoshino (SeeGerritForStatus)
2013/11/25 12:35:33
no longer necessary
sof
2013/11/25 15:28:18
Gone.
| |
| 21 | |
| 22 var xhr = new XMLHttpRequest(); | |
| 23 var results = ""; | |
| 24 var expected = " loadstart load loadend"; | |
| 25 | |
| 26 function logProgressEvent(e) { | |
| 27 results += " " + e.type; | |
| 28 } | |
| 29 | |
| 30 function logUnexpectedProgressEvent(e) { | 36 function logUnexpectedProgressEvent(e) { |
| 31 results += " [unexpected ProgressEvent: " + e.type + "]"; | 37 results += " [unexpected ProgressEvent: " + e.type + "]"; |
| 32 completeTest(); | 38 completeTest(); |
| 33 } | 39 } |
| 34 | 40 |
| 41 function loadendHandler(e) | |
| 42 { | |
| 43 logProgressEvent(e); | |
| 44 assert_true(e instanceof ProgressEvent); | |
| 45 verifyProgressEvent("onload", e, expectedLength); | |
|
tyoshino (SeeGerritForStatus)
2013/11/25 12:35:33
"onload" -> "onloadend" or just "loadend"
sof
2013/11/25 15:28:18
Done.
| |
| 46 completeTest(); | |
| 47 } | |
| 48 | |
| 35 function completeTest() | 49 function completeTest() |
| 36 { | 50 { |
| 37 log(results == expected ? "PASS" : "FAILED results : '" + results + "', expe cted : '" + expected + "'"); | 51 assert_equals(results, expected, "Expected load event sequence"); |
| 38 if (window.testRunner) | 52 testUploadOnloadEndEvent.done(); |
| 39 testRunner.notifyDone(); | |
| 40 } | 53 } |
| 41 | 54 |
| 42 function test() | 55 var testUploadOnloadEndEvent = async_test("Check that upload 'loadend' events ar e delivered and have expected values."); |
| 43 { | 56 testUploadOnloadEndEvent.step(function () { |
| 44 xhr.onreadystatechange = function(e) { | 57 xhr = new XMLHttpRequest(); |
| 45 if (xhr.readyState == xhr.DONE) | 58 xhr.upload.onloadstart = testUploadOnloadEndEvent.step_func(logProgressEvent ); |
| 46 completeTest(); | 59 xhr.upload.onabort = testUploadOnloadEndEvent.step_func(logUnexpectedProgres sEvent); |
| 47 } | 60 xhr.upload.onerror = testUploadOnloadEndEvent.step_func(logUnexpectedProgres sEvent); |
| 48 xhr.upload.onloadstart = logProgressEvent; | 61 xhr.upload.onload = testUploadOnloadEndEvent.step_func(logProgressEvent); |
| 49 xhr.upload.onabort = logUnexpectedProgressEvent; | 62 xhr.upload.onloadend = testUploadOnloadEndEvent.step_func(loadendHandler); |
| 50 xhr.upload.onerror = logUnexpectedProgressEvent; | 63 xhr.open("POST", "resources/post-echo.php", true); |
| 51 xhr.upload.onload = logProgressEvent; | 64 xhr.send(payload); |
| 52 xhr.upload.onloadend = logProgressEvent; | 65 }); |
| 53 | |
| 54 xhr.open("POST", "resources/post-echo.cgi", true); | |
| 55 xhr.send("data"); | |
| 56 } | |
| 57 | |
| 58 test(); | |
| 59 | |
| 60 </script> | 66 </script> |
| 61 </body> | 67 </body> |
| 68 </html> | |
| OLD | NEW |