@@ -39,7 +39,17 @@ describe('$httpBackend', function() {
39
39
fakeDocument = {
40
40
$$scripts : [ ] ,
41
41
createElement : jasmine . createSpy ( 'createElement' ) . andCallFake ( function ( ) {
42
- return { } ;
42
+ // msie8 depends on modifying readyState for testing. This property is readonly,
43
+ // so it requires a fake object. For other browsers, we do need to make use of
44
+ // event listener registration/deregistration, so these stubs are needed.
45
+ if ( msie <= 8 ) return {
46
+ attachEvent : noop ,
47
+ detachEvent : noop ,
48
+ addEventListener : noop ,
49
+ removeEventListener : noop
50
+ } ;
51
+ // Return a proper script element...
52
+ return document . createElement ( arguments [ 0 ] ) ;
43
53
} ) ,
44
54
body : {
45
55
appendChild : jasmine . createSpy ( 'body.appendChild' ) . andCallFake ( function ( script ) {
@@ -356,7 +366,7 @@ describe('$httpBackend', function() {
356
366
script . readyState = 'complete' ;
357
367
script . onreadystatechange ( ) ;
358
368
} else {
359
- script . onload ( ) ;
369
+ browserTrigger ( script , "load" ) ;
360
370
}
361
371
362
372
expect ( callback ) . toHaveBeenCalledOnce ( ) ;
@@ -372,20 +382,19 @@ describe('$httpBackend', function() {
372
382
callbackId = script . src . match ( SCRIPT_URL ) [ 2 ] ;
373
383
374
384
callbacks [ callbackId ] ( 'some-data' ) ;
375
-
376
385
if ( script . onreadystatechange ) {
377
386
script . readyState = 'complete' ;
378
387
script . onreadystatechange ( ) ;
379
388
} else {
380
- script . onload ( ) ;
389
+ browserTrigger ( script , "load" ) ;
381
390
}
382
391
383
392
expect ( callbacks [ callbackId ] ) . toBe ( angular . noop ) ;
384
393
expect ( fakeDocument . body . removeChild ) . toHaveBeenCalledOnceWith ( script ) ;
385
394
} ) ;
386
395
387
396
388
- if ( msie <= 8 ) {
397
+ if ( msie <= 8 ) {
389
398
390
399
it ( 'should attach onreadystatechange handler to the script object' , function ( ) {
391
400
$backend ( 'JSONP' , 'http://example.org/path?cb=JSON_CALLBACK' , null , noop ) ;
@@ -400,42 +409,9 @@ describe('$httpBackend', function() {
400
409
expect ( script . onreadystatechange ) . toBe ( null ) ;
401
410
} ) ;
402
411
403
- } else {
404
-
405
- it ( 'should attach onload and onerror handlers to the script object' , function ( ) {
406
- $backend ( 'JSONP' , 'http://example.org/path?cb=JSON_CALLBACK' , null , noop ) ;
407
-
408
- expect ( fakeDocument . $$scripts [ 0 ] . onload ) . toEqual ( jasmine . any ( Function ) ) ;
409
- expect ( fakeDocument . $$scripts [ 0 ] . onerror ) . toEqual ( jasmine . any ( Function ) ) ;
410
-
411
- var script = fakeDocument . $$scripts [ 0 ] ;
412
- script . onload ( ) ;
413
-
414
- expect ( script . onload ) . toBe ( null ) ;
415
- expect ( script . onerror ) . toBe ( null ) ;
416
- } ) ;
417
412
418
413
}
419
414
420
- it ( 'should call callback with status -2 when script fails to load' , function ( ) {
421
- callback . andCallFake ( function ( status , response ) {
422
- expect ( status ) . toBe ( - 2 ) ;
423
- expect ( response ) . toBeUndefined ( ) ;
424
- } ) ;
425
-
426
- $backend ( 'JSONP' , 'http://example.org/path?cb=JSON_CALLBACK' , null , callback ) ;
427
- expect ( fakeDocument . $$scripts . length ) . toBe ( 1 ) ;
428
-
429
- var script = fakeDocument . $$scripts . shift ( ) ;
430
- if ( script . onreadystatechange ) {
431
- script . readyState = 'complete' ;
432
- script . onreadystatechange ( ) ;
433
- } else {
434
- script . onload ( ) ;
435
- }
436
- expect ( callback ) . toHaveBeenCalledOnce ( ) ;
437
- } ) ;
438
-
439
415
440
416
it ( 'should set url to current location if not specified or empty string' , function ( ) {
441
417
$backend ( 'JSONP' , undefined , null , callback ) ;
0 commit comments