OLD | NEW |
---|---|
(Empty) | |
1 <!doctype html> | |
2 <html> | |
3 <head> | |
4 <title>XMLHttpRequest: abort() while sending data</title> | |
5 <script src="../resources/testharness.js"></script> | |
6 <script src="../resources/testharnessreport.js"></script> | |
7 </head> | |
8 <body> | |
9 Correct progress event sequencing on abort(), <a href="http://crbug.com/315488"> bug 315488</a>. | |
10 <script> | |
11 // Based on http://w3c-test.org/web-platform-tests/master/XMLHttpRequest/abort-d uring-upload.htm | |
12 | |
13 var expected = [ | |
14 'upload', 'progress', | |
15 'upload', 'abort', | |
16 'upload', 'loadend', | |
17 'load', 'progress', | |
18 'load', 'abort', | |
19 'load', 'loadend']; | |
20 | |
21 var result = []; | |
22 function recordEvent(e) { | |
23 var kind = e.target instanceof XMLHttpRequest ? 'load' : 'upload'; | |
24 result.push(kind, e.type); | |
25 } | |
26 | |
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) { | |
34 recordEvent(e); | |
35 assert_equals(xhr.readyState, XMLHttpRequest.DONE); | |
36 assert_array_equals(result, expected); | |
37 setTimeout(abortAfterSendLoadend.step_func(function () { | |
38 assert_equals(xhr.readyState, XMLHttpRequest.UNSENT); | |
39 abortAfterSendLoadend.done(); | |
40 }), 100); | |
tyoshino (SeeGerritForStatus)
2013/11/19 16:57:38
does this need to be 100?
sof
2013/11/19 18:57:03
No, just being wary of introducing test flakiness.
| |
41 }); | |
42 xhr.upload.onprogress = recordEvent; | |
43 xhr.upload.onabort = recordEvent; | |
44 xhr.upload.onloadend = recordEvent; | |
45 | |
46 xhr.send(); | |
47 xhr.abort(); | |
48 }); | |
49 | |
50 var resultSync = []; | |
51 function recordEventSync(e) { | |
52 var kind = e.target instanceof XMLHttpRequest ? 'load' : 'upload'; | |
53 resultSync.push(kind, e.type); | |
54 } | |
55 var abortAfterSendSync = async_test("Progress event delivery on abort(), post-se nd() (sync)"); | |
56 abortAfterSendSync.step(function() { | |
57 var xhr = new XMLHttpRequest(); | |
58 xhr.open("POST", "resources/delay.php?iteration=1&delay=10"); | |
59 xhr.onreadystatechange = function () { | |
60 if (xhr.readyState > XMLHttpRequest.OPENED && xhr.readyState != XMLHttpR equest.DONE) | |
61 xhr.abort(); | |
62 }; | |
63 xhr.onprogress = recordEventSync; | |
64 xhr.onabort = recordEventSync; | |
65 xhr.onloadend = abortAfterSendSync.step_func(function (e) { | |
66 recordEventSync(e); | |
67 assert_equals(xhr.readyState, XMLHttpRequest.DONE); | |
68 assert_array_equals(resultSync, expected); | |
69 setTimeout(abortAfterSendSync.step_func(function () { | |
70 assert_equals(xhr.readyState, XMLHttpRequest.UNSENT); | |
71 abortAfterSendSync.done(); | |
72 }), 100); | |
tyoshino (SeeGerritForStatus)
2013/11/19 16:57:38
ditto
| |
73 }); | |
74 xhr.upload.onprogress = recordEventSync; | |
75 xhr.upload.onabort = recordEventSync; | |
76 xhr.upload.onloadend = recordEventSync; | |
77 xhr.send(); | |
78 }); | |
79 </script> | |
80 </body> | |
81 </html> | |
OLD | NEW |