aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorVojta Jina2012-08-09 10:20:39 -0700
committerIgor Minar2012-08-10 14:53:53 -0700
commit167aa0c29c998be33c49d33302e099b36d1ce0be (patch)
treeef405d863f48c26ca417f251ec35a4836c1f7fc6 /test
parent4ccd9eb88321f8554ee4dc41b7f8068ce2306765 (diff)
downloadangular.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')
-rw-r--r--test/ng/logSpec.js2
-rw-r--r--test/ng/snifferSpec.js30
2 files changed, 25 insertions, 7 deletions
diff --git a/test/ng/logSpec.js b/test/ng/logSpec.js
index ce5c4f11..8b872bb1 100644
--- a/test/ng/logSpec.js
+++ b/test/ng/logSpec.js
@@ -6,7 +6,7 @@ describe('$log', function() {
beforeEach(module(function($provide){
- $window = {navigator: {}};
+ $window = {navigator: {}, document: {}};
logger = '';
log = function() { logger+= 'log;'; };
warn = function() { logger+= 'warn;'; };
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);
+ });
+ });
});