OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Content settings API test | 5 // Content settings API test |
6 // Run with browser_tests --gtest_filter=ExtensionApiTest.ContentSettings | 6 // Run with browser_tests --gtest_filter=ExtensionApiTest.ContentSettings |
7 | 7 |
8 var cs = chrome.contentSettings; | 8 var cs = chrome.contentSettings; |
9 var default_content_settings = { | 9 var default_content_settings = { |
10 "cookies": "session_only", | 10 "cookies": "session_only", |
(...skipping 12 matching lines...) Expand all Loading... |
23 }; | 23 }; |
24 | 24 |
25 var settings = { | 25 var settings = { |
26 "cookies": "block", | 26 "cookies": "block", |
27 "images": "allow", | 27 "images": "allow", |
28 "javascript": "block", | 28 "javascript": "block", |
29 "plugins": "detect_important_content", | 29 "plugins": "detect_important_content", |
30 "popups": "allow", | 30 "popups": "allow", |
31 "location": "block", | 31 "location": "block", |
32 "notifications": "block", | 32 "notifications": "block", |
33 "fullscreen": "allow", | 33 "fullscreen": "block", // Should be ignored. |
34 "mouselock": "block", | 34 "mouselock": "block", // Should be ignored. |
35 "microphone": "block", | 35 "microphone": "block", |
36 "camera": "block", | 36 "camera": "block", |
37 "unsandboxedPlugins": "block", | 37 "unsandboxedPlugins": "block", |
38 "automaticDownloads": "block" | 38 "automaticDownloads": "block" |
39 }; | 39 }; |
40 | 40 |
| 41 // List of settings that are expected to return different values than were |
| 42 // written, due to deprecation. For example, "fullscreen" is set to "block" but |
| 43 // we expect this to be ignored, and so read back as "allow". Any setting |
| 44 // omitted from this list is expected to read back whatever was written. |
| 45 var deprecatedSettingsExpectations = { |
| 46 // Due to deprecation, these should be "allow", regardless of the setting. |
| 47 "fullscreen": "allow", |
| 48 "mouselock": "allow" |
| 49 }; |
| 50 |
41 Object.prototype.forEach = function(f) { | 51 Object.prototype.forEach = function(f) { |
42 var k; | 52 var k; |
43 for (k in this) { | 53 for (k in this) { |
44 if (this.hasOwnProperty(k)) | 54 if (this.hasOwnProperty(k)) |
45 f(k, this[k]); | 55 f(k, this[k]); |
46 } | 56 } |
47 }; | 57 }; |
48 | 58 |
49 function expect(expected, message) { | 59 function expect(expected, message) { |
50 return chrome.test.callbackPass(function(value) { | 60 return chrome.test.callbackPass(function(value) { |
(...skipping 22 matching lines...) Expand all Loading... |
73 settings.forEach(function(type, setting) { | 83 settings.forEach(function(type, setting) { |
74 cs[type].set({ | 84 cs[type].set({ |
75 'primaryPattern': 'http://*.google.com/*', | 85 'primaryPattern': 'http://*.google.com/*', |
76 'secondaryPattern': 'http://*.google.com/*', | 86 'secondaryPattern': 'http://*.google.com/*', |
77 'setting': setting | 87 'setting': setting |
78 }, chrome.test.callbackPass()); | 88 }, chrome.test.callbackPass()); |
79 }); | 89 }); |
80 }, | 90 }, |
81 function getContentSettings() { | 91 function getContentSettings() { |
82 settings.forEach(function(type, setting) { | 92 settings.forEach(function(type, setting) { |
| 93 setting = deprecatedSettingsExpectations[type] || setting; |
83 var message = "Setting for " + type + " should be " + setting; | 94 var message = "Setting for " + type + " should be " + setting; |
84 cs[type].get({ | 95 cs[type].get({ |
85 'primaryUrl': 'http://www.google.com', | 96 'primaryUrl': 'http://www.google.com', |
86 'secondaryUrl': 'http://www.google.com' | 97 'secondaryUrl': 'http://www.google.com' |
87 }, expect({'setting':setting}, message)); | 98 }, expect({'setting':setting}, message)); |
88 }); | 99 }); |
89 }, | 100 }, |
90 function invalidSettings() { | 101 function invalidSettings() { |
91 cs.cookies.get({ | 102 cs.cookies.get({ |
92 'primaryUrl': 'moo' | 103 'primaryUrl': 'moo' |
93 }, chrome.test.callbackFail("The URL \"moo\" is invalid.")); | 104 }, chrome.test.callbackFail("The URL \"moo\" is invalid.")); |
94 cs.plugins.set({ | 105 cs.plugins.set({ |
95 'primaryPattern': 'http://example.com/*', | 106 'primaryPattern': 'http://example.com/*', |
96 'secondaryPattern': 'http://example.com/path', | 107 'secondaryPattern': 'http://example.com/path', |
97 'setting': 'block' | 108 'setting': 'block' |
98 }, chrome.test.callbackFail("Specific paths are not allowed.")); | 109 }, chrome.test.callbackFail("Specific paths are not allowed.")); |
99 cs.javascript.set({ | 110 cs.javascript.set({ |
100 'primaryPattern': 'http://example.com/*', | 111 'primaryPattern': 'http://example.com/*', |
101 'secondaryPattern': 'file:///home/hansmoleman/*', | 112 'secondaryPattern': 'file:///home/hansmoleman/*', |
102 'setting': 'allow' | 113 'setting': 'allow' |
103 }, chrome.test.callbackFail( | 114 }, chrome.test.callbackFail( |
104 "Path wildcards in file URL patterns are not allowed.")); | 115 "Path wildcards in file URL patterns are not allowed.")); |
105 } | 116 } |
106 ]); | 117 ]); |
OLD | NEW |