@@ -222,6 +222,7 @@ describe('Zone', function() {
222222 } ) ;
223223
224224 zone . run ( ( ) => { document . dispatchEvent ( scrollEvent ) ; } ) ;
225+ ( document as any ) . removeAllListeners ( 'scroll' ) ;
225226 } ) ;
226227
227228 it ( 'should be able to clear on handler added before load zone.js' , function ( ) {
@@ -799,6 +800,7 @@ describe('Zone', function() {
799800
800801 button . dispatchEvent ( clickEvent ) ;
801802 expect ( logs ) . toEqual ( [ ] ) ;
803+ ( document as any ) . removeAllListeners ( 'click' ) ;
802804 } ) ;
803805 } ) ) ;
804806
@@ -1035,6 +1037,42 @@ describe('Zone', function() {
10351037 button . removeEventListener ( 'click' , listener ) ;
10361038 } ) ) ;
10371039
1040+ describe ( 'passiveEvents' , ( ) => {
1041+ let logs : string [ ] = [ ] ;
1042+ const listener = ( e : Event ) => {
1043+ logs . push ( e . defaultPrevented ? 'defaultPrevented' : 'default will run' ) ;
1044+ e . preventDefault ( ) ;
1045+ logs . push ( e . defaultPrevented ? 'defaultPrevented' : 'default will run' ) ;
1046+ } ;
1047+ const testPassive = function ( eventName : string , expectedPassiveLog : string , options : any ) {
1048+ ( button as any ) . addEventListener ( eventName , listener , options ) ;
1049+ const evt = document . createEvent ( 'Event' ) ;
1050+ evt . initEvent ( eventName , true , true ) ;
1051+ button . dispatchEvent ( evt ) ;
1052+ expect ( logs ) . toEqual ( [ 'default will run' , expectedPassiveLog ] ) ;
1053+ ( button as any ) . removeAllListeners ( eventName ) ;
1054+ } ;
1055+ beforeEach ( ( ) => { logs = [ ] ; } ) ;
1056+ it ( 'should be passive with global variable defined' ,
1057+ ( ) => { testPassive ( 'touchstart' , 'default will run' , { passive : true } ) ; } ) ;
1058+ it ( 'should not be passive without global variable defined' ,
1059+ ( ) => { testPassive ( 'touchend' , 'defaultPrevented' , undefined ) ; } ) ;
1060+ it ( 'should be passive with global variable defined even without passive options' ,
1061+ ( ) => { testPassive ( 'touchstart' , 'default will run' , undefined ) ; } ) ;
1062+ it ( 'should be passive with global variable defined even without passive options and with capture' ,
1063+ ( ) => { testPassive ( 'touchstart' , 'default will run' , { capture : true } ) ; } ) ;
1064+ it ( 'should be passive with global variable defined with capture option' ,
1065+ ( ) => { testPassive ( 'touchstart' , 'default will run' , true ) ; } ) ;
1066+ it ( 'should not be passive with global variable defined with passive false option' ,
1067+ ( ) => { testPassive ( 'touchstart' , 'defaultPrevented' , { passive : false } ) ; } ) ;
1068+ it ( 'should be passive with global variable defined and also blacklisted' , ( ) => {
1069+ ( document as any ) . removeAllListeners ( 'scroll' ) ;
1070+ testPassive ( 'scroll' , 'default will run' , undefined ) ;
1071+ } ) ;
1072+ it ( 'should not be passive without global variable defined and also blacklisted' ,
1073+ ( ) => { testPassive ( 'wheel' , 'defaultPrevented' , undefined ) ; } ) ;
1074+ } ) ;
1075+
10381076 it ( 'should support Event.stopImmediatePropagation' ,
10391077 ifEnvSupports ( supportEventListenerOptions , function ( ) {
10401078 const hookSpy = jasmine . createSpy ( 'hook' ) ;
0 commit comments