This repository was archived by the owner on Feb 26, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +83
-0
lines changed Expand file tree Collapse file tree 2 files changed +83
-0
lines changed Original file line number Diff line number Diff line change @@ -324,6 +324,56 @@ describe('Zone.patch', function () {
324
324
325
325
} ) ;
326
326
327
+ describe ( 'XMLHttpRequest' , function ( ) {
328
+
329
+ it ( 'should work with onreadystatechange' , function ( ) {
330
+ var flag = false ,
331
+ hasParent ;
332
+
333
+ runs ( function ( ) {
334
+ var req = new XMLHttpRequest ( ) ;
335
+ req . onreadystatechange = function ( ) {
336
+ hasParent = ! ! window . zone . parent ;
337
+ flag = true ;
338
+ } ;
339
+ req . open ( 'get' , '/' , true ) ;
340
+ req . send ( ) ;
341
+ } ) ;
342
+
343
+ waitsFor ( function ( ) {
344
+ return flag ;
345
+ } , 'HTTP request to resolve' , 100 ) ;
346
+
347
+ runs ( function ( ) {
348
+ expect ( hasParent ) . toBe ( true ) ;
349
+ } ) ;
350
+ } ) ;
351
+
352
+ it ( 'should work with onprogress' , function ( ) {
353
+ var flag = false ,
354
+ hasParent ;
355
+
356
+ runs ( function ( ) {
357
+ var req = new XMLHttpRequest ( ) ;
358
+ req . onprogress = function ( ) {
359
+ hasParent = ! ! window . zone . parent ;
360
+ flag = true ;
361
+ } ;
362
+ req . open ( 'get' , '/' , true ) ;
363
+ req . send ( ) ;
364
+ } ) ;
365
+
366
+ waitsFor ( function ( ) {
367
+ return flag ;
368
+ } , 'HTTP request to resolve' , 100 ) ;
369
+
370
+ runs ( function ( ) {
371
+ expect ( hasParent ) . toBe ( true ) ;
372
+ } ) ;
373
+ } ) ;
374
+ } ) ;
375
+
376
+
327
377
describe ( 'hooks' , function ( ) {
328
378
329
379
beforeEach ( function ( ) {
Original file line number Diff line number Diff line change @@ -250,6 +250,7 @@ Zone.patch = function patch () {
250
250
Zone . patchViaPropertyDescriptor ( ) ;
251
251
} else {
252
252
Zone . patchViaCapturingAllTheEvents ( ) ;
253
+ Zone . patchClass ( 'XMLHttpRequest' ) ;
253
254
}
254
255
255
256
// patch promises
@@ -304,6 +305,38 @@ Zone.patchViaCapturingAllTheEvents = function () {
304
305
} ) ;
305
306
} ;
306
307
308
+ // TODO: wrap some native API
309
+ Zone . patchClass = function ( className ) {
310
+ var OriginalClass = window [ className ] ;
311
+ window [ className ] = function ( ) {
312
+ this . _o = new OriginalClass ( ) ;
313
+ } ;
314
+
315
+ var instance = ( new OriginalClass ( ) ) ;
316
+
317
+ var prop ;
318
+ for ( prop in instance ) {
319
+ ( function ( prop ) {
320
+ if ( typeof instance [ prop ] === 'function' ) {
321
+ window [ className ] . prototype [ prop ] = function ( ) {
322
+ return this . _o [ prop ] . apply ( this . _o , arguments ) ;
323
+ } ;
324
+ } else {
325
+ Object . defineProperty ( window [ className ] . prototype , prop , {
326
+ set : function ( fn ) {
327
+ if ( typeof fn === 'function' ) {
328
+ this . _o [ prop ] = zone . bind ( fn ) ;
329
+ }
330
+ } ,
331
+ get : function ( ) {
332
+ return this . _o [ prop ] ;
333
+ }
334
+ } ) ;
335
+ }
336
+ } ( prop ) ) ;
337
+ } ;
338
+ } ;
339
+
307
340
Zone . eventNames = 'copy cut paste abort blur focus canplay canplaythrough change click contextmenu dblclick drag dragend dragenter dragleave dragover dragstart drop durationchange emptied ended input invalid keydown keypress keyup load loadeddata loadedmetadata loadstart mousedown mouseenter mouseleave mousemove mouseout mouseover mouseup pause play playing progress ratechange reset scroll seeked seeking select show stalled submit suspend timeupdate volumechange waiting mozfullscreenchange mozfullscreenerror mozpointerlockchange mozpointerlockerror error' . split ( ' ' ) ;
308
341
309
342
Zone . init = function init ( ) {
You can’t perform that action at this time.
0 commit comments