diff options
| author | Vojta Jina | 2012-08-09 10:20:39 -0700 |
|---|---|---|
| committer | Igor Minar | 2012-08-10 14:53:53 -0700 |
| commit | 167aa0c29c998be33c49d33302e099b36d1ce0be (patch) | |
| tree | ef405d863f48c26ca417f251ec35a4836c1f7fc6 /test/ng/snifferSpec.js | |
| parent | 4ccd9eb88321f8554ee4dc41b7f8068ce2306765 (diff) | |
| download | angular.js-167aa0c29c998be33c49d33302e099b36d1ce0be.tar.bz2 | |
feat($sniffer): auto detect CSP mode
Chrome Canary now has CSP with apis that allow auto-detection. This change
will turn on CSP mode automatically when we detect its presence.
https://dvcs.w3.org/hg/content-security-policy/raw-file/tip/csp-specification.dev.html#script-interfaces--experimental
Diffstat (limited to 'test/ng/snifferSpec.js')
| -rw-r--r-- | test/ng/snifferSpec.js | 30 |
1 files changed, 24 insertions, 6 deletions
diff --git a/test/ng/snifferSpec.js b/test/ng/snifferSpec.js index a34a1975..8d21a23c 100644 --- a/test/ng/snifferSpec.js +++ b/test/ng/snifferSpec.js @@ -2,9 +2,10 @@ describe('$sniffer', function() { - function sniffer($window) { + function sniffer($window, $document) { $window.navigator = {}; - return new $SnifferProvider().$get[1]($window); + $document = jqLite($document || {}); + return new $SnifferProvider().$get[2]($window, $document); } describe('history', function() { @@ -20,15 +21,15 @@ describe('$sniffer', function() { describe('hashchange', function() { it('should be true if onhashchange property defined', function() { - expect(sniffer({onhashchange: true, document: {}}).hashchange).toBe(true); + expect(sniffer({onhashchange: true}, {}).hashchange).toBe(true); }); it('should be false if onhashchange property not defined', function() { - expect(sniffer({document: {}}).hashchange).toBe(false); + expect(sniffer({}, {}).hashchange).toBe(false); }); it('should be false if documentMode is 7 (IE8 comp mode)', function() { - expect(sniffer({onhashchange: true, document: {documentMode: 7}}).hashchange).toBe(false); + expect(sniffer({onhashchange: true}, {documentMode: 7}).hashchange).toBe(false); }); }); @@ -42,7 +43,7 @@ describe('$sniffer', function() { if (elm === 'div') return mockDivElement; }); - $sniffer = sniffer({document: mockDocument}); + $sniffer = sniffer({}, mockDocument); }); @@ -78,4 +79,21 @@ describe('$sniffer', function() { expect($sniffer.hasEvent('input')).toBe((msie == 9) ? false : true); }); }); + + + describe('csp', function() { + it('should be false if document.SecurityPolicy.isActive not available', function() { + expect(sniffer({}, {}).csp).toBe(false); + }); + + + it('should use document.SecurityPolicy.isActive() if available', function() { + var createDocumentWithCSP = function(csp) { + return {SecurityPolicy: {isActive: function() {return csp;}}}; + }; + + expect(sniffer({}, createDocumentWithCSP(false)).csp).toBe(false); + expect(sniffer({}, createDocumentWithCSP(true)).csp).toBe(true); + }); + }); }); |
