Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1389)

Side by Side Diff: LayoutTests/http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout.js

Issue 60203010: XHR.abort(): no event dispatching in completed/non-started states. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* Test imported from Alex Vincent's XHR2 timeout tests, written for Mozilla. 1 /* Test imported from Alex Vincent's XHR2 timeout tests, written for Mozilla.
2 https://hg.mozilla.org/mozilla-central/file/tip/content/base/test/ 2 https://hg.mozilla.org/mozilla-central/file/tip/content/base/test/
3 Released into the public domain, according to 3 Released into the public domain, according to
4 https://bugzilla.mozilla.org/show_bug.cgi?id=525816#c86 4 https://bugzilla.mozilla.org/show_bug.cgi?id=525816#c86
5 */ 5 */
6 6
7 /* Notes: 7 /* Notes:
8 - All times are expressed in milliseconds in this test suite. 8 - All times are expressed in milliseconds in this test suite.
9 - Test harness code is at the end of this file. 9 - Test harness code is at the end of this file.
10 - We generate only one request at a time, to avoid overloading the HTTP 10 - We generate only one request at a time, to avoid overloading the HTTP
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 this.request = req; 186 this.request = req;
187 req.open("GET", STALLED_REQUEST_URL); 187 req.open("GET", STALLED_REQUEST_URL);
188 var me = this; 188 var me = this;
189 function handleEvent(e) { return me.handleEvent(e); }; 189 function handleEvent(e) { return me.handleEvent(e); };
190 req.onerror = handleEvent; 190 req.onerror = handleEvent;
191 req.onload = handleEvent; 191 req.onload = handleEvent;
192 req.onabort = handleEvent; 192 req.onabort = handleEvent;
193 req.ontimeout = handleEvent; 193 req.ontimeout = handleEvent;
194 194
195 req.timeout = TIME_REGULAR_TIMEOUT; 195 req.timeout = TIME_REGULAR_TIMEOUT;
196 var _this = this;
197 196
198 function abortReq() { 197 function abortReq() {
199 req.abort(); 198 if (me.request.readyState == XMLHttpRequest.DONE || me.request.readyState > XMLHttpRequest.OPENED) {
tyoshino (SeeGerritForStatus) 2013/11/07 13:38:05 maybe this should be me.request.readyState < XMLHt
sof 2013/11/07 14:34:14 Much better, that was the intent & close enough (i
199 if (me.abortDelay > TIME_REGULAR_TIMEOUT)
200 me.timeoutEventFired()
201 else
202 me.noEventsFired();
203 } else
204 req.abort();
200 } 205 }
201 206
202 if (!this.shouldAbort) { 207 if (!this.shouldAbort) {
203 self.setTimeout(function() { 208 self.setTimeout(function() {
204 try { 209 try {
205 _this.noEventsFired(); 210 me.noEventsFired();
206 } 211 }
207 catch (e) { 212 catch (e) {
208 ok(false, "Unexpected error: " + e); 213 ok(false, "Unexpected error: " + e);
209 TestCounter.testComplete(); 214 TestCounter.testComplete();
210 } 215 }
211 }, TIME_NORMAL_LOAD); 216 }, TIME_NORMAL_LOAD);
212 } 217 }
213 else { 218 else {
214 // Abort events can only be triggered on sent requests. 219 // Abort events can only be triggered on sent requests.
215 req.send(); 220 req.send();
216 if (this.abortDelay == -1) { 221 if (this.abortDelay == -1) {
217 abortReq(); 222 abortReq();
218 } 223 }
219 else { 224 else {
220 self.setTimeout(abortReq, this.abortDelay); 225 self.setTimeout(abortReq, this.abortDelay);
221 } 226 }
222 } 227 }
223 }, 228 },
224 229
225 /** 230 /**
226 * Ensure that no events fired at all, especially not our timeout event. 231 * Ensure that no events fired at all, especially not our timeout event.
227 */ 232 */
228 noEventsFired: function() { 233 noEventsFired: function() {
229 ok(!this.hasFired, "No events should fire for an unsent, unaborted request") ; 234 ok(!this.hasFired, "No events should fire for an unsent, unaborted request") ;
230 // We're done; if timeout hasn't fired by now, it never will. 235 // We're done; if timeout hasn't fired by now, it never will.
231 TestCounter.testComplete(); 236 TestCounter.testComplete();
232 }, 237 },
233 238
234 /** 239 /**
240 * Ensure that an event fired, our timeout event.
241 */
242 timeoutEventFired: function() {
243 ok(this.hasFired && this.eventFired == "timeout", "A timeout event should ha ve fired");
244 TestCounter.testComplete();
245 },
246
247 /**
235 * Get a message describing this test. 248 * Get a message describing this test.
236 * 249 *
237 * @returns {String} The test description. 250 * @returns {String} The test description.
238 */ 251 */
239 getMessage: function() { 252 getMessage: function() {
240 return "time to abort is " + this.abortDelay + ", timeout set at " + TIME_RE GULAR_TIMEOUT; 253 return "time to abort is " + this.abortDelay + ", timeout set at " + TIME_RE GULAR_TIMEOUT;
241 }, 254 },
242 255
243 /** 256 /**
244 * Check the event received, and if it's the right (and only) one we get. 257 * Check the event received, and if it's the right (and only) one we get.
245 * 258 *
246 * WebKit fires abort events even for DONE and UNSENT states, which is
247 * discussed in http://webkit.org/b/98404
248 * That's why we chose to accept secondary "abort" events in this test.
249 *
250 * @param {DOMProgressEvent} evt An event of type "load" or "timeout". 259 * @param {DOMProgressEvent} evt An event of type "load" or "timeout".
251 */ 260 */
252 handleEvent: function(evt) { 261 handleEvent: function(evt) {
253 if (this.hasFired && evt.type != "abort") { 262 if (this.hasFired) {
254 ok(false, "Only abort event should fire: " + this.getMessage()); 263 ok(false, "Only one event should fire: " + this.getMessage());
255 return; 264 return;
256 } 265 }
257 266
258 var expectedEvent = (this.abortDelay >= TIME_REGULAR_TIMEOUT && !this.hasFir ed) ? "timeout" : "abort"; 267 var expectedEvent = (this.abortDelay >= TIME_REGULAR_TIMEOUT) ? "timeout" : "abort";
259 this.hasFired = true; 268 this.hasFired = true;
269 this.eventFired = evt.type;
260 is(evt.type, expectedEvent, this.getMessage()); 270 is(evt.type, expectedEvent, this.getMessage());
261 TestCounter.testComplete(); 271 TestCounter.testComplete();
262 } 272 }
263 }; 273 };
264 274
265 var SyncRequestSettingTimeoutAfterOpen = { 275 var SyncRequestSettingTimeoutAfterOpen = {
266 startXHR: function() { 276 startXHR: function() {
267 var pass = false; 277 var pass = false;
268 var req = new XMLHttpRequest(); 278 var req = new XMLHttpRequest();
269 req.open("GET", STALLED_REQUEST_URL, false); 279 req.open("GET", STALLED_REQUEST_URL, false);
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 } 376 }
367 } 377 }
368 }; 378 };
369 379
370 self.addEventListener("message", function (event) { 380 self.addEventListener("message", function (event) {
371 if (event.data.type == "start") { 381 if (event.data.type == "start") {
372 TestRequests = TestRequestGroups[event.data.group]; 382 TestRequests = TestRequestGroups[event.data.group];
373 TestCounter.next(); 383 TestCounter.next();
374 } 384 }
375 }); 385 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698