4 <title>XMLHttpRequest: abort() while sending data
</title>
5 <script src=
"../resources/testharness.js"></script>
6 <script src=
"../resources/testharnessreport.js"></script>
9 Correct progress event sequencing on abort(),
<a href=
"http://crbug.com/315488">bug
315488</a>.
11 // Based on http://w3c-test.org/web-platform-tests/master/XMLHttpRequest/abort-during-upload.htm
22 function recordEvent(e
) {
23 var kind
= e
.target
instanceof XMLHttpRequest
? 'load' : 'upload';
24 result
.push(kind
, e
.type
);
27 var abortAfterSendLoadend
= async_test("Progress event delivery on abort(), post-send() (async)");
28 abortAfterSendLoadend
.step(function() {
29 var xhr
= new XMLHttpRequest();
30 xhr
.open("POST", "resources/delay.php?iteration=1&delay=1000");
31 xhr
.onprogress
= recordEvent
;
32 xhr
.onabort
= recordEvent
;
33 xhr
.onloadend
= abortAfterSendLoadend
.step_func(function (e
) {
35 assert_equals(xhr
.readyState
, XMLHttpRequest
.DONE
);
36 assert_array_equals(result
, expected
);
37 // Runs after abort()'s transition of readyState to UNSENT.
38 setTimeout(abortAfterSendLoadend
.step_func(function () {
39 assert_equals(xhr
.readyState
, XMLHttpRequest
.UNSENT
);
40 abortAfterSendLoadend
.done();
43 xhr
.upload
.onprogress
= recordEvent
;
44 xhr
.upload
.onabort
= recordEvent
;
45 xhr
.upload
.onloadend
= recordEvent
;
52 function recordEventSync(e
) {
53 var kind
= e
.target
instanceof XMLHttpRequest
? 'load' : 'upload';
54 resultSync
.push(kind
, e
.type
);
56 var abortAfterSendSync
= async_test("Progress event delivery on abort(), post-send() (sync)");
57 abortAfterSendSync
.step(function() {
58 var xhr
= new XMLHttpRequest();
59 xhr
.open("POST", "resources/delay.php?iteration=1&delay=10");
60 xhr
.onreadystatechange = function () {
61 if (xhr
.readyState
> XMLHttpRequest
.OPENED
&& xhr
.readyState
!= XMLHttpRequest
.DONE
)
64 xhr
.onprogress
= recordEventSync
;
65 xhr
.onabort
= recordEventSync
;
66 xhr
.onloadend
= abortAfterSendSync
.step_func(function (e
) {
68 assert_equals(xhr
.readyState
, XMLHttpRequest
.DONE
);
69 assert_array_equals(resultSync
, expected
);
70 // Runs after abort()'s transition of readyState to UNSENT.
71 setTimeout(abortAfterSendSync
.step_func(function () {
72 assert_equals(xhr
.readyState
, XMLHttpRequest
.UNSENT
);
73 abortAfterSendSync
.done();
76 xhr
.upload
.onprogress
= recordEventSync
;
77 xhr
.upload
.onabort
= recordEventSync
;
78 xhr
.upload
.onloadend
= recordEventSync
;