4 <title>Test case for bug
40952</title>
5 <script src=
"../resources/testharness.js"></script>
6 <script src=
"../resources/testharnessreport.js"></script>
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>
12 <script type=
"text/javascript">
16 var expectedLength
= payload
.length
;
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
+ "]";
36 function completeTest()
38 assert_equals(results
, expected
, "Expected load event sequence");
39 testOnloadEndEvent
.done();
42 function loadendHandler(e
)
45 assert_true(e
instanceof ProgressEvent
);
46 verifyProgressEvent("onloadend", e
, expectedLength
);
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";
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);