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 = { |
| 7 "cookies": "session_only", |
| 8 "images": "allow", |
| 9 "javascript": "block", |
| 10 "plugins": "allow", |
| 11 "popups": "block", |
| 12 // TODO(bauerb) |
| 13 // "geolocation": "ask", |
| 14 "notifications": "ask" |
| 15 }; |
| 16 |
| 17 var settings = { |
| 18 "cookies": "block", |
| 19 "images": "allow", |
| 20 "javascript": "block", |
| 21 "plugins": "block", |
| 22 "popups": "allow", |
| 23 // "geolocation": "block", |
| 24 "notifications": "block" |
| 25 }; |
| 26 |
| 27 Object.prototype.forEach = function(f) { |
| 28 for (key in this) { |
| 29 if (this.hasOwnProperty(key)) |
| 30 f(key, this[key]); |
| 31 } |
| 32 } |
| 33 |
| 34 |
6 function expect(expected, message) { | 35 function expect(expected, message) { |
7 return chrome.test.callbackPass(function(value) { | 36 return chrome.test.callbackPass(function(value) { |
8 chrome.test.assertEq(expected, value, message); | 37 chrome.test.assertEq(expected, value, message); |
9 }); | 38 }); |
10 } | 39 } |
11 chrome.test.runTests([ | 40 chrome.test.runTests([ |
12 function getThirdPartyCookiesAllowed() { | 41 function getThirdPartyCookiesAllowed() { |
13 cs.global.thirdPartyCookiesAllowed.get( | 42 cs.global.thirdPartyCookiesAllowed.get( |
14 {}, | 43 {}, |
15 expect({ 'value': false, | 44 expect({ 'value': false, |
16 'levelOfControl': "controllable_by_this_extension" }, | 45 'levelOfControl': "controllable_by_this_extension" }, |
17 "third-party cookies should be blocked")); | 46 "third-party cookies should be blocked")); |
18 }, | 47 }, |
19 function getReferrersEnabled() { | 48 function getReferrersEnabled() { |
20 cs.global.referrersEnabled.get( | 49 cs.global.referrersEnabled.get( |
21 {}, | 50 {}, |
22 expect({ 'value': false, | 51 expect({ 'value': false, |
23 'levelOfControl': "controllable_by_this_extension" }, | 52 'levelOfControl': "controllable_by_this_extension" }, |
24 "referrers should be disabled")); | 53 "referrers should be disabled")); |
25 }, | 54 }, |
26 function setThirdPartyCookiesAllowed() { | 55 function setThirdPartyCookiesAllowed() { |
27 cs.global.thirdPartyCookiesAllowed.set( | 56 cs.global.thirdPartyCookiesAllowed.set( |
28 {'value': true}, | 57 {'value': true}, |
29 chrome.test.callbackPass()); | 58 chrome.test.callbackPass()); |
30 }, | 59 }, |
31 function setReferrersEnabled() { | 60 function setReferrersEnabled() { |
32 cs.global.referrersEnabled.set( | 61 cs.global.referrersEnabled.set( |
33 {'value': true}, | 62 {'value': true}, |
34 chrome.test.callbackPass()); | 63 chrome.test.callbackPass()); |
| 64 }, |
| 65 function setDefaultContentSettings() { |
| 66 default_content_settings.forEach(function(type, setting) { |
| 67 cs[type].set({ |
| 68 'topLevelPattern': {'pattern': '*'}, |
| 69 'embeddedPattern': {'pattern': '*'}, |
| 70 'setting': setting |
| 71 }, chrome.test.callbackPass()); |
| 72 }); |
| 73 }, |
| 74 function setContentSettings() { |
| 75 settings.forEach(function(type, setting) { |
| 76 cs[type].set({ |
| 77 'topLevelPattern': {'pattern': '[*.]google.com'}, |
| 78 'embeddedPattern': {'pattern': '[*.]google.com'}, |
| 79 'setting': setting |
| 80 }, chrome.test.callbackPass()); |
| 81 }); |
| 82 }, |
| 83 function getContentSettings() { |
| 84 settings.forEach(function(type, setting) { |
| 85 var message = "Setting for " + type + " should be " + setting; |
| 86 cs[type].get({ |
| 87 'topLevelUrl': 'http://www.google.com', |
| 88 'embeddedUrl': 'http://www.google.com' |
| 89 }, expect({'setting':setting}, message)); |
| 90 }); |
| 91 }, |
| 92 function invalidSettings() { |
| 93 cs.cookies.get({ |
| 94 'topLevelUrl': '', |
| 95 'embeddedUrl': 'moo' |
| 96 }, chrome.test.callbackFail("The URL \"moo\" is invalid.")); |
35 } | 97 } |
36 ]); | 98 ]); |
37 </script> | 99 </script> |
OLD | NEW |