OLD | NEW |
1 <script> | 1 <script> |
2 // Content settings API test | 2 // Content settings API test |
3 // Run with browser_tests --gtest_filter=ExtensionApiTest.ContentSettings | 3 // Run with browser_tests --gtest_filter=ExtensionApiTest.ContentSettings |
4 | 4 |
5 var cs = chrome.experimental.contentSettings; | 5 var cs = chrome.experimental.contentSettings; |
6 var default_content_settings = { | 6 var default_content_settings = { |
7 "cookies": "session_only", | 7 "cookies": "session_only", |
8 "images": "allow", | 8 "images": "allow", |
9 "javascript": "block", | 9 "javascript": "block", |
10 "plugins": "allow", | 10 "plugins": "allow", |
11 "popups": "block", | 11 "popups": "block", |
12 // TODO(bauerb) | 12 // TODO(bauerb) |
13 // "geolocation": "ask", | 13 // "geolocation": "ask", |
14 "notifications": "ask" | 14 "notifications": "ask" |
15 }; | 15 }; |
16 | 16 |
17 var settings = { | 17 var settings = { |
18 "cookies": "block", | 18 "cookies": "block", |
19 "images": "allow", | 19 "images": "allow", |
20 "javascript": "block", | 20 "javascript": "block", |
21 "plugins": "block", | 21 "plugins": "block", |
22 "popups": "allow", | 22 "popups": "allow", |
23 // "geolocation": "block", | 23 // "geolocation": "block", |
24 "notifications": "block" | 24 "notifications": "block" |
25 }; | 25 }; |
26 | 26 |
27 Object.prototype.forEach = function(f) { | 27 Object.prototype.forEach = function(f) { |
28 for (key in this) { | 28 var k; |
29 if (this.hasOwnProperty(key)) | 29 for (k in this) { |
30 f(key, this[key]); | 30 if (this.hasOwnProperty(k)) |
| 31 f(k, this[k]); |
31 } | 32 } |
32 } | 33 }; |
33 | |
34 | 34 |
35 function expect(expected, message) { | 35 function expect(expected, message) { |
36 return chrome.test.callbackPass(function(value) { | 36 return chrome.test.callbackPass(function(value) { |
37 chrome.test.assertEq(expected, value, message); | 37 chrome.test.assertEq(expected, value, message); |
38 }); | 38 }); |
39 } | 39 } |
| 40 |
| 41 function expectFalse(message) { |
| 42 return expect({ |
| 43 "value": false, |
| 44 "levelOfControl": "controllable_by_this_extension" |
| 45 }, message); |
| 46 } |
| 47 |
40 chrome.test.runTests([ | 48 chrome.test.runTests([ |
41 function getThirdPartyCookiesAllowed() { | |
42 cs.global.thirdPartyCookiesAllowed.get( | |
43 {}, | |
44 expect({ 'value': false, | |
45 'levelOfControl': "controllable_by_this_extension" }, | |
46 "third-party cookies should be blocked")); | |
47 }, | |
48 function getReferrersEnabled() { | |
49 cs.global.referrersEnabled.get( | |
50 {}, | |
51 expect({ 'value': false, | |
52 'levelOfControl': "controllable_by_this_extension" }, | |
53 "referrers should be disabled")); | |
54 }, | |
55 function setThirdPartyCookiesAllowed() { | |
56 cs.global.thirdPartyCookiesAllowed.set( | |
57 {'value': true}, | |
58 chrome.test.callbackPass()); | |
59 }, | |
60 function setReferrersEnabled() { | |
61 cs.global.referrersEnabled.set( | |
62 {'value': true}, | |
63 chrome.test.callbackPass()); | |
64 }, | |
65 function setDefaultContentSettings() { | 49 function setDefaultContentSettings() { |
66 default_content_settings.forEach(function(type, setting) { | 50 default_content_settings.forEach(function(type, setting) { |
67 cs[type].set({ | 51 cs[type].set({ |
68 'primaryPattern': '<all_urls>', | 52 'primaryPattern': '<all_urls>', |
69 'secondaryPattern': '<all_urls>', | 53 'secondaryPattern': '<all_urls>', |
70 'setting': setting | 54 'setting': setting |
71 }, chrome.test.callbackPass()); | 55 }, chrome.test.callbackPass()); |
72 }); | 56 }); |
73 }, | 57 }, |
74 function setContentSettings() { | 58 function setContentSettings() { |
75 settings.forEach(function(type, setting) { | 59 settings.forEach(function(type, setting) { |
76 cs[type].set({ | 60 cs[type].set({ |
77 'primaryPattern': 'http://*.google.com/*', | 61 'primaryPattern': 'http://*.google.com/*', |
78 'secondaryPattern': 'http://*.google.com/*', | 62 'secondaryPattern': 'http://*.google.com/*', |
79 'setting': setting | 63 'setting': setting |
80 }, chrome.test.callbackPass()); | 64 }, chrome.test.callbackPass()); |
81 }); | 65 }); |
82 }, | 66 }, |
83 function getContentSettings() { | 67 function getContentSettings() { |
84 settings.forEach(function(type, setting) { | 68 settings.forEach(function(type, setting) { |
85 var message = "Setting for " + type + " should be " + setting; | 69 var message = "Setting for " + type + " should be " + setting; |
86 cs[type].get({ | 70 cs[type].get({ |
87 'primaryUrl': 'http://www.google.com', | 71 'primaryUrl': 'http://www.google.com', |
88 'secondaryUrl': 'http://www.google.com' | 72 'secondaryUrl': 'http://www.google.com' |
89 }, expect({'setting':setting}, message)); | 73 }, expect({'setting':setting}, message)); |
90 }); | 74 }); |
91 }, | 75 }, |
92 function invalidSettings() { | 76 function invalidSettings() { |
93 cs.cookies.get({ | 77 cs.cookies.get({ |
94 'primaryUrl': 'moo', | 78 'primaryUrl': 'moo' |
95 }, chrome.test.callbackFail("The URL \"moo\" is invalid.")); | 79 }, chrome.test.callbackFail("The URL \"moo\" is invalid.")); |
96 cs.plugins.set({ | 80 cs.plugins.set({ |
97 'primaryPattern': 'http://example.com/*', | 81 'primaryPattern': 'http://example.com/*', |
98 'secondaryPattern': 'http://example.com/path', | 82 'secondaryPattern': 'http://example.com/path', |
99 'setting': 'block' | 83 'setting': 'block' |
100 }, chrome.test.callbackFail("Specific paths are not allowed.")); | 84 }, chrome.test.callbackFail("Specific paths are not allowed.")); |
101 cs.javascript.set({ | 85 cs.javascript.set({ |
102 'primaryPattern': 'http://example.com/*', | 86 'primaryPattern': 'http://example.com/*', |
103 'secondaryPattern': 'file:///home/hansmoleman/*', | 87 'secondaryPattern': 'file:///home/hansmoleman/*', |
104 'setting': 'allow' | 88 'setting': 'allow' |
105 }, chrome.test.callbackFail("Path wildcards in file URL patterns are not all
owed.")); | 89 }, chrome.test.callbackFail("Path wildcards in file URL patterns are not all
owed.")); |
106 } | 90 } |
107 ]); | 91 ]); |
108 </script> | 92 </script> |
OLD | NEW |