2
2
3
3
describe ( '$sniffer' , function ( ) {
4
4
5
- function sniffer ( $window ) {
5
+ function sniffer ( $window , $document ) {
6
6
$window . navigator = { } ;
7
- return new $SnifferProvider ( ) . $get [ 1 ] ( $window ) ;
7
+ $document = jqLite ( $document || { } ) ;
8
+ return new $SnifferProvider ( ) . $get [ 2 ] ( $window , $document ) ;
8
9
}
9
10
10
11
describe ( 'history' , function ( ) {
@@ -20,15 +21,15 @@ describe('$sniffer', function() {
20
21
21
22
describe ( 'hashchange' , function ( ) {
22
23
it ( 'should be true if onhashchange property defined' , function ( ) {
23
- expect ( sniffer ( { onhashchange : true , document : { } } ) . hashchange ) . toBe ( true ) ;
24
+ expect ( sniffer ( { onhashchange : true } , { } ) . hashchange ) . toBe ( true ) ;
24
25
} ) ;
25
26
26
27
it ( 'should be false if onhashchange property not defined' , function ( ) {
27
- expect ( sniffer ( { document : { } } ) . hashchange ) . toBe ( false ) ;
28
+ expect ( sniffer ( { } , { } ) . hashchange ) . toBe ( false ) ;
28
29
} ) ;
29
30
30
31
it ( 'should be false if documentMode is 7 (IE8 comp mode)' , function ( ) {
31
- expect ( sniffer ( { onhashchange : true , document : { documentMode : 7 } } ) . hashchange ) . toBe ( false ) ;
32
+ expect ( sniffer ( { onhashchange : true } , { documentMode : 7 } ) . hashchange ) . toBe ( false ) ;
32
33
} ) ;
33
34
} ) ;
34
35
@@ -42,7 +43,7 @@ describe('$sniffer', function() {
42
43
if ( elm === 'div' ) return mockDivElement ;
43
44
} ) ;
44
45
45
- $sniffer = sniffer ( { document : mockDocument } ) ;
46
+ $sniffer = sniffer ( { } , mockDocument ) ;
46
47
} ) ;
47
48
48
49
@@ -78,4 +79,21 @@ describe('$sniffer', function() {
78
79
expect ( $sniffer . hasEvent ( 'input' ) ) . toBe ( ( msie == 9 ) ? false : true ) ;
79
80
} ) ;
80
81
} ) ;
82
+
83
+
84
+ describe ( 'csp' , function ( ) {
85
+ it ( 'should be false if document.SecurityPolicy.isActive not available' , function ( ) {
86
+ expect ( sniffer ( { } , { } ) . csp ) . toBe ( false ) ;
87
+ } ) ;
88
+
89
+
90
+ it ( 'should use document.SecurityPolicy.isActive() if available' , function ( ) {
91
+ var createDocumentWithCSP = function ( csp ) {
92
+ return { SecurityPolicy : { isActive : function ( ) { return csp ; } } } ;
93
+ } ;
94
+
95
+ expect ( sniffer ( { } , createDocumentWithCSP ( false ) ) . csp ) . toBe ( false ) ;
96
+ expect ( sniffer ( { } , createDocumentWithCSP ( true ) ) . csp ) . toBe ( true ) ;
97
+ } ) ;
98
+ } ) ;
81
99
} ) ;
0 commit comments