Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / http / tests / xmlhttprequest / onloadend-event-after-load.html
blobbf97ab0d053754583572c7f2e7f8f10a929fd823
1 <!doctype html>
2 <html>
3 <head>
4 <title>Test case for bug 40952</title>
5 <script src="../resources/testharness.js"></script>
6 <script src="../resources/testharnessreport.js"></script>
7 </head>
8 <body>
9 <p> Test case for <a href="https://bugs.webkit.org/show_bug.cgi?id=40952"> bug 40952</a>: Onloadend event is not supported in XMLHttpRequest</p>
10 <p> Verify that a loadend ProgressEvent is dispatched after the load ProgressEvent when an async request completes normally.</p>
11 <div id="log"></div>
12 <script type="text/javascript">
14 var xhr;
15 var payload = "data";
16 var expectedLength = payload.length;
17 var results = "";
18 var expected = " loadstart readyState=DONE load loadend";
20 function verifyProgressEvent(context, e, expected)
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.");
27 function logProgressEvent(e) {
28 results += " " + e.type;
31 function logUnexpectedProgressEvent(e) {
32 results += " [unexpected ProgressEvent: " + e.type + "]";
33 completeTest();
36 function completeTest()
38 assert_equals(results, expected, "Expected load event sequence");
39 testOnloadEndEvent.done();
42 function loadendHandler(e)
44 logProgressEvent(e);
45 assert_true(e instanceof ProgressEvent);
46 verifyProgressEvent("onloadend", e, expectedLength);
47 completeTest();
50 var testOnloadEndEvent = async_test("Check that 'loadend' events are delivered and have expected values.");
51 testOnloadEndEvent.step(function () {
52 xhr = new XMLHttpRequest();
53 xhr.onreadystatechange = testOnloadEndEvent.step_func(function(e) {
54 if (xhr.readyState == xhr.DONE)
55 results += " readyState=DONE";
56 });
57 xhr.onloadstart = testOnloadEndEvent.step_func(logProgressEvent);
58 xhr.onabort = testOnloadEndEvent.step_func(logUnexpectedProgressEvent);
59 xhr.onerror = testOnloadEndEvent.step_func(logUnexpectedProgressEvent);
60 xhr.onload = testOnloadEndEvent.step_func(logProgressEvent);
61 xhr.onloadend = testOnloadEndEvent.step_func(loadendHandler);
62 xhr.open("POST", "resources/post-echo.php", true);
63 xhr.send(payload);
64 });
65 </script>
66 </body>
67 </html>