4 <script src=
"../resources/testharness.js"></script>
5 <script src=
"../resources/testharnessreport.js"></script>
6 <script type=
"text/javascript">
8 // Interval prepared to wait until deciding if 'abort' has been delivered (or not.)
9 var TIME_DELAY_ABORT_DELIVERY
= 200;
13 var xhr
= new XMLHttpRequest
;
14 xhr
.onreadystatechange
= this.step_func(function() {
15 assert_unreached("Received readystatechange event unexpectedly: readyState=" + xhr
.readyState
)
17 xhr
.onabort
= this.step_func(function () {
18 assert_unreached("Unexpected 'abort' event in state UNSENT.");
21 assert_equals(xhr
.readyState
, xhr
.UNSENT
, "xhr.readyState after abort() call");
22 }, "Test onreadystatechange + onabort invocation when abort()-ed in UNSENT state.");
26 var xhr
= new XMLHttpRequest
;
28 xhr
.onreadystatechange
= this.step_func(function() {
29 seenStates
.push(xhr
.readyState
);
31 switch (xhr
.readyState
) {
36 case xhr
.HEADERS_RECEIVED
:
40 assert_unreached("Unexpected readyState: " + xhr
.readyState
);
44 xhr
.onabort
= this.step_func(function () {
45 assert_unreached("Unexpected 'abort' event in state OPENED.");
47 xhr
.open("GET", "resources/test.ogv", true);
49 assert_equals(xhr
.readyState
, xhr
.UNSENT
, "xhr.readyState after abort() call");
50 assert_array_equals(seenStates
, [xhr
.OPENED
]);
51 }, "Test onreadystatechange + onabort invocation when abort()-ed in OPENED state.");
53 var abortAfterSendTest
= async_test("Test onreadystatechange + onabort invocation when abort()-ed right after calling send().");
54 abortAfterSendTest
.step(function()
56 var xhr
= new XMLHttpRequest
;
58 xhr
.onreadystatechange
= this.step_func(function() {
59 seenStates
.push(xhr
.readyState
);
61 switch (xhr
.readyState
) {
67 case xhr
.HEADERS_RECEIVED
:
70 assert_unreached("Unexpected readyState: " + xhr
.readyState
);
74 var abortFired
= false;
75 xhr
.onabort = function () {
78 xhr
.open("GET", "resources/test.ogv", true);
81 assert_equals(xhr
.readyState
, xhr
.UNSENT
, "xhr.readyState after abort() call");
82 assert_array_equals(seenStates
, [xhr
.OPENED
, xhr
.DONE
]);
83 setTimeout(abortAfterSendTest
.step_func(function () {
84 assert_true(abortFired
, "Expected 'abort' event to have fired in sent request.");
85 abortAfterSendTest
.done();
86 }), TIME_DELAY_ABORT_DELIVERY
);
89 var abortInHeadersReceivedTest
= async_test("Test onreadystatechange + onabort invocation when abort()-ed in HEADERS_RECEIVED state.");
90 abortInHeadersReceivedTest
.step(function()
92 var xhr
= new XMLHttpRequest
;
94 xhr
.onreadystatechange
= abortInHeadersReceivedTest
.step_func(function() {
95 seenStates
.push(xhr
.readyState
);
97 switch (xhr
.readyState
) {
102 case xhr
.HEADERS_RECEIVED
:
104 assert_equals(xhr
.readyState
, xhr
.UNSENT
, "xhr.readyState after abort() call");
105 assert_array_equals(seenStates
, [xhr
.OPENED
, xhr
.HEADERS_RECEIVED
, xhr
.DONE
]);
106 setTimeout(abortInHeadersReceivedTest
.step_func(function() {
107 assert_true(abortFired
, "Expected 'abort' event to have fired in HEADERS_RECEIVED state.");
108 abortInHeadersReceivedTest
.done();
109 }), TIME_DELAY_ABORT_DELIVERY
);
115 assert_unreached("Unexpected readyState: " + xhr
.readyState
)
119 var abortFired
= false;
120 xhr
.onabort = function () {
123 xhr
.open("GET", "resources/test.ogv", true);
127 var abortInLoadingTest
= async_test("Test onreadystatechange + onabort invocation when abort()-ed in LOADING state.");
128 abortInLoadingTest
.step(function()
130 var xhr
= new XMLHttpRequest
;
132 xhr
.onreadystatechange
= abortInLoadingTest
.step_func(function() {
133 seenStates
.push(xhr
.readyState
);
135 switch (xhr
.readyState
) {
137 case xhr
.HEADERS_RECEIVED
:
143 assert_equals(xhr
.readyState
, xhr
.UNSENT
, "xhr.readyState after abort() call");
144 assert_array_equals(seenStates
, [xhr
.OPENED
, xhr
.HEADERS_RECEIVED
, xhr
.LOADING
, xhr
.DONE
]);
145 setTimeout(abortInLoadingTest
.step_func(function() {
146 assert_true(abortFired
, "Expected 'abort' event to have fired in LOADING state.");
147 abortInLoadingTest
.done();
148 }), TIME_DELAY_ABORT_DELIVERY
);
153 assert_unreached("Unexpected readyState: " + xhr
.readyState
)
157 var abortFired
= false;
158 xhr
.onabort = function () {
161 xhr
.open("GET", "resources/test.ogv", true);
165 var abortInDoneTest
= async_test("Test onreadystatechange + onabort invocation when abort()-ed in DONE state.");
166 abortInDoneTest
.step(function()
168 var xhr
= new XMLHttpRequest
;
170 xhr
.onreadystatechange
= abortInDoneTest
.step_func(function() {
171 seenStates
.push(xhr
.readyState
);
173 switch (xhr
.readyState
) {
175 case xhr
.HEADERS_RECEIVED
:
181 assert_equals(xhr
.readyState
, xhr
.UNSENT
, "xhr.readyState after abort() call");
182 assert_array_equals(seenStates
, [xhr
.OPENED
, xhr
.HEADERS_RECEIVED
, xhr
.LOADING
, xhr
.DONE
]);
184 setTimeout(abortInDoneTest
.step_func(function() {
185 abortInDoneTest
.done();
186 }), TIME_DELAY_ABORT_DELIVERY
);
191 assert_unreached("Unexpected readyState: " + xhr
.readyState
)
195 xhr
.onabort
= abortInDoneTest
.step_func(function () {
196 assert_unreached("abort() should not cause the abort event to fire");
198 xhr
.open("GET", "resources/test.ogv", true);