@@ -799,11 +799,10 @@ describe('angular', function() {
799
799
var originalFunction ;
800
800
801
801
beforeEach ( function ( ) {
802
- originalFunction = window . Function ;
802
+ spyOn ( window , ' Function' ) ;
803
803
} ) ;
804
804
805
805
afterEach ( function ( ) {
806
- window . Function = originalFunction ;
807
806
delete csp . rules ;
808
807
} ) ;
809
808
@@ -814,40 +813,49 @@ describe('angular', function() {
814
813
815
814
816
815
it ( 'should return true for noUnsafeEval if eval causes a CSP security policy error' , function ( ) {
817
- window . Function = function ( ) { throw new Error ( 'CSP test' ) ; } ;
816
+ window . Function . andCallFake ( function ( ) { throw new Error ( 'CSP test' ) ; } ) ;
818
817
expect ( csp ( ) ) . toEqual ( { noUnsafeEval : true , noInlineStyle : false } ) ;
818
+ expect ( window . Function ) . toHaveBeenCalledWith ( '' ) ;
819
819
} ) ;
820
820
821
821
822
822
it ( 'should return true for all rules when CSP is enabled manually via empty `ng-csp` attribute' , function ( ) {
823
823
var spy = mockCspElement ( 'ng-csp' ) ;
824
824
expect ( csp ( ) ) . toEqual ( { noUnsafeEval : true , noInlineStyle : true } ) ;
825
825
expect ( spy ) . toHaveBeenCalledWith ( '[ng-csp]' ) ;
826
+ expect ( window . Function ) . not . toHaveBeenCalled ( ) ;
826
827
} ) ;
827
828
828
829
829
830
it ( 'should return true when CSP is enabled manually via [data-ng-csp]' , function ( ) {
830
831
var spy = mockCspElement ( 'data-ng-csp' ) ;
831
832
expect ( csp ( ) ) . toEqual ( { noUnsafeEval : true , noInlineStyle : true } ) ;
832
- expect ( document . querySelector ) . toHaveBeenCalledWith ( '[data-ng-csp]' ) ;
833
+ expect ( spy ) . toHaveBeenCalledWith ( '[data-ng-csp]' ) ;
834
+ expect ( window . Function ) . not . toHaveBeenCalled ( ) ;
833
835
} ) ;
834
836
835
837
836
838
it ( 'should return true for noUnsafeEval if it is specified in the `ng-csp` attribute value' , function ( ) {
837
839
var spy = mockCspElement ( 'ng-csp' , 'no-unsafe-eval' ) ;
838
840
expect ( csp ( ) ) . toEqual ( { noUnsafeEval : true , noInlineStyle : false } ) ;
841
+ expect ( spy ) . toHaveBeenCalledWith ( '[ng-csp]' ) ;
842
+ expect ( window . Function ) . not . toHaveBeenCalled ( ) ;
839
843
} ) ;
840
844
841
845
842
846
it ( 'should return true for noInlineStyle if it is specified in the `ng-csp` attribute value' , function ( ) {
843
847
var spy = mockCspElement ( 'ng-csp' , 'no-inline-style' ) ;
844
848
expect ( csp ( ) ) . toEqual ( { noUnsafeEval : false , noInlineStyle : true } ) ;
849
+ expect ( spy ) . toHaveBeenCalledWith ( '[ng-csp]' ) ;
850
+ expect ( window . Function ) . not . toHaveBeenCalled ( ) ;
845
851
} ) ;
846
852
847
853
848
854
it ( 'should return true for all styles if they are all specified in the `ng-csp` attribute value' , function ( ) {
849
855
var spy = mockCspElement ( 'ng-csp' , 'no-inline-style;no-unsafe-eval' ) ;
850
856
expect ( csp ( ) ) . toEqual ( { noUnsafeEval : true , noInlineStyle : true } ) ;
857
+ expect ( spy ) . toHaveBeenCalledWith ( '[ng-csp]' ) ;
858
+ expect ( window . Function ) . not . toHaveBeenCalled ( ) ;
851
859
} ) ;
852
860
} ) ;
853
861
0 commit comments