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 var globalFixtures = { | |
28 "alternateErrorPagesEnabled": "Alternate error pages should be disabled.", | |
29 "autofillEnabled": "Autofill should be disabled.", | |
30 "clearSiteDataOnExit": "Clearing site data should be disabled.", | |
31 "hyperlinkAuditingEnabled": "<a ping> should be disabled.", | |
32 "instantEnabled": "Instant should be disabled.", | |
33 "networkPredictionEnabled": "Network prediction should be disabled.", | |
34 "referrersEnabled": "Referrers should be disabled.", | |
35 "safeBrowsingEnabled": "Safe browsing should be disabled.", | |
36 "searchSuggestEnabled": "Suggest should be disabled.", | |
37 "thirdPartyCookiesAllowed": "Third party cookies should be blocked.", | |
38 "translateEnabled": "Translate should be disabled." | |
39 }; | |
40 | |
27 Object.prototype.forEach = function(f) { | 41 Object.prototype.forEach = function(f) { |
28 for (key in this) { | 42 var k; |
29 if (this.hasOwnProperty(key)) | 43 for (k in this) { |
30 f(key, this[key]); | 44 if (this.hasOwnProperty(k)) |
45 f(k, this[k]); | |
31 } | 46 } |
32 } | 47 }; |
33 | 48 |
34 | 49 |
35 function expect(expected, message) { | 50 function expect(expected, message) { |
36 return chrome.test.callbackPass(function(value) { | 51 return chrome.test.callbackPass(function(value) { |
37 chrome.test.assertEq(expected, value, message); | 52 chrome.test.assertEq(expected, value, message); |
38 }); | 53 }); |
39 } | 54 } |
55 | |
56 function expectFalse(message) { | |
57 return expect({ | |
58 "value": false, | |
59 "levelOfControl": "controllable_by_this_extension" | |
60 }, message); | |
61 } | |
62 | |
40 chrome.test.runTests([ | 63 chrome.test.runTests([ |
41 function getThirdPartyCookiesAllowed() { | 64 function getGlobals() { |
42 cs.global.thirdPartyCookiesAllowed.get( | 65 globalFixtures.forEach(function (pref, message) { |
43 {}, | 66 cs.global[pref].get({}, expectFalse(message)); |
Bernhard Bauer
2011/07/27 11:41:34
These prefs are not in global anymore.
Mike West
2011/07/27 11:48:01
Lots of ContentSettings tests are broken in this C
| |
44 expect({ 'value': false, | 67 }); |
45 'levelOfControl': "controllable_by_this_extension" }, | |
46 "third-party cookies should be blocked")); | |
47 }, | 68 }, |
48 function getReferrersEnabled() { | 69 function setGlobals() { |
49 cs.global.referrersEnabled.get( | 70 globalFixtures.forEach(function (pref) { |
50 {}, | 71 cs.global[pref].set({'value': true}, chrome.test.callbackPass()); |
51 expect({ 'value': false, | 72 }); |
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 }, | 73 }, |
65 function setDefaultContentSettings() { | 74 function setDefaultContentSettings() { |
66 default_content_settings.forEach(function(type, setting) { | 75 default_content_settings.forEach(function(type, setting) { |
67 cs[type].set({ | 76 cs[type].set({ |
68 'primaryPattern': '<all_urls>', | 77 'primaryPattern': '<all_urls>', |
69 'secondaryPattern': '<all_urls>', | 78 'secondaryPattern': '<all_urls>', |
70 'setting': setting | 79 'setting': setting |
71 }, chrome.test.callbackPass()); | 80 }, chrome.test.callbackPass()); |
72 }); | 81 }); |
73 }, | 82 }, |
(...skipping 10 matching lines...) Expand all Loading... | |
84 settings.forEach(function(type, setting) { | 93 settings.forEach(function(type, setting) { |
85 var message = "Setting for " + type + " should be " + setting; | 94 var message = "Setting for " + type + " should be " + setting; |
86 cs[type].get({ | 95 cs[type].get({ |
87 'primaryUrl': 'http://www.google.com', | 96 'primaryUrl': 'http://www.google.com', |
88 'secondaryUrl': 'http://www.google.com' | 97 'secondaryUrl': 'http://www.google.com' |
89 }, expect({'setting':setting}, message)); | 98 }, expect({'setting':setting}, message)); |
90 }); | 99 }); |
91 }, | 100 }, |
92 function invalidSettings() { | 101 function invalidSettings() { |
93 cs.cookies.get({ | 102 cs.cookies.get({ |
94 'primaryUrl': 'moo', | 103 'primaryUrl': 'moo' |
95 }, chrome.test.callbackFail("The URL \"moo\" is invalid.")); | 104 }, chrome.test.callbackFail("The URL \"moo\" is invalid.")); |
96 cs.plugins.set({ | 105 cs.plugins.set({ |
97 'primaryPattern': 'http://example.com/*', | 106 'primaryPattern': 'http://example.com/*', |
98 'secondaryPattern': 'http://example.com/path', | 107 'secondaryPattern': 'http://example.com/path', |
99 'setting': 'block' | 108 'setting': 'block' |
100 }, chrome.test.callbackFail("Specific paths are not allowed.")); | 109 }, chrome.test.callbackFail("Specific paths are not allowed.")); |
101 cs.javascript.set({ | 110 cs.javascript.set({ |
102 'primaryPattern': 'http://example.com/*', | 111 'primaryPattern': 'http://example.com/*', |
103 'secondaryPattern': 'file:///home/hansmoleman/*', | 112 'secondaryPattern': 'file:///home/hansmoleman/*', |
104 'setting': 'allow' | 113 'setting': 'allow' |
105 }, chrome.test.callbackFail("Path wildcards in file URL patterns are not all owed.")); | 114 }, chrome.test.callbackFail("Path wildcards in file URL patterns are not all owed.")); |
106 } | 115 } |
107 ]); | 116 ]); |
108 </script> | 117 </script> |
OLD | NEW |