OLD | NEW |
1 <HTML> | 1 <!doctype 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 request completes normally.</p> | 10 <p> Verify that a loadend ProgressEvent is dispatched after the load ProgressEve
nt when an async 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 readyState=DONE load loadend"; | 18 var expected = " loadstart readyState=DONE 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(); |
33 } | 34 } |
34 | 35 |
35 function completeTest() | 36 function completeTest() |
36 { | 37 { |
37 log(results == expected ? "PASS" : "FAILED results : '" + results + "', expe
cted : '" + expected + "'"); | 38 assert_equals(results, expected, "Expected load event sequence"); |
38 if (window.testRunner) | 39 testOnloadEndEvent.done(); |
39 testRunner.notifyDone(); | |
40 } | 40 } |
41 | 41 |
42 function test() | 42 function loadendHandler(e) |
43 { | 43 { |
44 xhr.onreadystatechange = function(e) { | 44 logProgressEvent(e); |
| 45 assert_true(e instanceof ProgressEvent); |
| 46 verifyProgressEvent("onloadend", e, expectedLength); |
| 47 completeTest(); |
| 48 } |
| 49 |
| 50 var testOnloadEndEvent = async_test("Check that 'loadend' events are delivered a
nd have expected values."); |
| 51 testOnloadEndEvent.step(function () { |
| 52 xhr = new XMLHttpRequest(); |
| 53 xhr.onreadystatechange = testOnloadEndEvent.step_func(function(e) { |
45 if (xhr.readyState == xhr.DONE) | 54 if (xhr.readyState == xhr.DONE) |
46 results += " readyState=DONE"; | 55 results += " readyState=DONE"; |
47 } | 56 }); |
48 xhr.onloadstart = logProgressEvent; | 57 xhr.onloadstart = testOnloadEndEvent.step_func(logProgressEvent); |
49 xhr.onabort = logUnexpectedProgressEvent; | 58 xhr.onabort = testOnloadEndEvent.step_func(logUnexpectedProgressEvent); |
50 xhr.onerror = logUnexpectedProgressEvent; | 59 xhr.onerror = testOnloadEndEvent.step_func(logUnexpectedProgressEvent); |
51 xhr.onload = logProgressEvent; | 60 xhr.onload = testOnloadEndEvent.step_func(logProgressEvent); |
52 xhr.onloadend = function(e) { | 61 xhr.onloadend = testOnloadEndEvent.step_func(loadendHandler); |
53 logProgressEvent(e); | 62 xhr.open("POST", "resources/post-echo.php", true); |
54 completeTest(); | 63 xhr.send(payload); |
55 } | 64 }); |
56 | |
57 xhr.open("GET", "resources/get.txt", true); | |
58 xhr.send(); | |
59 } | |
60 | |
61 test(); | |
62 | |
63 </script> | 65 </script> |
64 </body> | 66 </body> |
| 67 </html> |
OLD | NEW |