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) { | |
12 testRunner.dumpAsText(); | |
13 testRunner.waitUntilDone(); | |
14 } | |
15 | 13 |
16 function log(message) | 14 var xhr; |
17 { | 15 var payload = "data"; |
18 var consoleElt = document.getElementById("console"); | 16 var expectedLength = payload.length; |
19 consoleElt.appendChild(document.createTextNode(message)); | |
20 } | |
21 | |
22 var xhr = new XMLHttpRequest(); | |
23 var results = ""; | 17 var results = ""; |
24 var expected = " loadstart load loadend"; | 18 var expected = " loadstart load loadend"; |
25 | 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."); |
| 24 assert_equals(e.total, expected, "Expected 'total' value for '" + context +
"' event."); |
| 25 } |
| 26 |
26 function logProgressEvent(e) { | 27 function logProgressEvent(e) { |
27 results += " " + e.type; | 28 results += " " + e.type; |
28 } | 29 } |
29 | 30 |
30 function logUnexpectedProgressEvent(e) { | 31 function logUnexpectedProgressEvent(e) { |
31 results += " [unexpected ProgressEvent: " + e.type + "]"; | 32 results += " [unexpected ProgressEvent: " + e.type + "]"; |
32 completeTest(); | 33 completeTest(); |
| 34 } |
| 35 |
| 36 function loadendHandler(e) |
| 37 { |
| 38 logProgressEvent(e); |
| 39 assert_true(e instanceof ProgressEvent); |
| 40 verifyProgressEvent("onloadend", e, expectedLength); |
| 41 completeTest(); |
33 } | 42 } |
34 | 43 |
35 function completeTest() | 44 function completeTest() |
36 { | 45 { |
37 log(results == expected ? "PASS" : "FAILED results : '" + results + "', expe
cted : '" + expected + "'"); | 46 assert_equals(results, expected, "Expected load event sequence"); |
38 if (window.testRunner) | 47 testUploadOnloadEndEvent.done(); |
39 testRunner.notifyDone(); | |
40 } | 48 } |
41 | 49 |
42 function test() | 50 var testUploadOnloadEndEvent = async_test("Check that upload 'loadend' events ar
e delivered and have expected values."); |
43 { | 51 testUploadOnloadEndEvent.step(function () { |
44 xhr.onreadystatechange = function(e) { | 52 xhr = new XMLHttpRequest(); |
45 if (xhr.readyState == xhr.DONE) | 53 xhr.upload.onloadstart = testUploadOnloadEndEvent.step_func(logProgressEvent
); |
46 completeTest(); | 54 xhr.upload.onabort = testUploadOnloadEndEvent.step_func(logUnexpectedProgres
sEvent); |
47 } | 55 xhr.upload.onerror = testUploadOnloadEndEvent.step_func(logUnexpectedProgres
sEvent); |
48 xhr.upload.onloadstart = logProgressEvent; | 56 xhr.upload.onload = testUploadOnloadEndEvent.step_func(logProgressEvent); |
49 xhr.upload.onabort = logUnexpectedProgressEvent; | 57 xhr.upload.onloadend = testUploadOnloadEndEvent.step_func(loadendHandler); |
50 xhr.upload.onerror = logUnexpectedProgressEvent; | 58 xhr.open("POST", "resources/post-echo.php", true); |
51 xhr.upload.onload = logProgressEvent; | 59 xhr.send(payload); |
52 xhr.upload.onloadend = logProgressEvent; | 60 }); |
53 | |
54 xhr.open("POST", "resources/post-echo.cgi", true); | |
55 xhr.send("data"); | |
56 } | |
57 | |
58 test(); | |
59 | |
60 </script> | 61 </script> |
61 </body> | 62 </body> |
| 63 </html> |
OLD | NEW |