@@ -390,6 +390,56 @@ o.spec("xhr", function() {
390390 o ( xhr . getRequestHeader ( "Accept" ) ) . equals ( "application/json, text/*" )
391391 }
392392 } )
393+ o ( "doesn't fail on abort" , function ( done ) {
394+ var s = new Date
395+ mock . $defineRoutes ( {
396+ "GET /item" : function ( ) {
397+ return { status : 200 , responseText : JSON . stringify ( { a : 1 } ) }
398+ }
399+ } )
400+
401+ var failed = false
402+ var resolved = false
403+ function handleAbort ( xhr ) {
404+ var onreadystatechange = xhr . onreadystatechange // probably not set yet
405+ var testonreadystatechange = function ( ) {
406+ onreadystatechange . call ( xhr )
407+ setTimeout ( function ( ) { // allow promises to (not) resolve first
408+ o ( failed ) . equals ( false )
409+ o ( resolved ) . equals ( false )
410+ done ( )
411+ } , 0 )
412+ }
413+ Object . defineProperty ( xhr , 'onreadystatechange' , {
414+ set : function ( val ) { onreadystatechange = val }
415+ , get : function ( ) { return testonreadystatechange }
416+ } )
417+ xhr . abort ( )
418+ }
419+ xhr ( { method : "GET" , url : "/item" , config : handleAbort } ) . catch ( function ( ) {
420+ failed = true
421+ } )
422+ . then ( function ( ) {
423+ resolved = true
424+ } )
425+ } )
426+ o ( "doesn't fail on file:// status 0" , function ( done ) {
427+ var s = new Date
428+ mock . $defineRoutes ( {
429+ "GET /item" : function ( ) {
430+ return { status : 0 , responseText : JSON . stringify ( { a : 1 } ) }
431+ }
432+ } )
433+ var failed = false
434+ xhr ( { method : "GET" , url : "file:///item" } ) . catch ( function ( ) {
435+ failed = true
436+ } ) . then ( function ( data ) {
437+ o ( failed ) . equals ( false )
438+ o ( data ) . deepEquals ( { a : 1 } )
439+ } ) . then ( function ( ) {
440+ done ( )
441+ } )
442+ } )
393443 /*o("data maintains after interpolate", function() {
394444 mock.$defineRoutes({
395445 "PUT /items/:x": function() {
@@ -463,5 +513,15 @@ o.spec("xhr", function() {
463513 } )
464514 } )
465515 } )
516+ o ( "rejects on cors-like error" , function ( done ) {
517+ mock . $defineRoutes ( {
518+ "GET /item" : function ( request ) {
519+ return { status : 0 }
520+ }
521+ } )
522+ xhr ( { method : "GET" , url : "/item" } ) . catch ( function ( e ) {
523+ o ( e instanceof Error ) . equals ( true )
524+ } ) . then ( done )
525+ } )
466526 } )
467527} )
0 commit comments