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 // If omitted, expected to be the same as |settings|. | |
42 var expectations = { | |
Devlin
2016/09/26 20:30:37
I would add a bit more context here, and rename th
Matt Giuca
2016/09/27 01:18:33
Done.
| |
43 // Due to deprecation, these should be "allow", regardless of the setting. | |
44 "fullscreen": "allow", | |
Devlin
2016/09/26 20:30:37
prefer single quotes in js
Matt Giuca
2016/09/27 01:18:33
I think it's appropriate to stay consistent with t
| |
45 "mouselock": "allow" | |
46 }; | |
47 | |
41 Object.prototype.forEach = function(f) { | 48 Object.prototype.forEach = function(f) { |
42 var k; | 49 var k; |
43 for (k in this) { | 50 for (k in this) { |
44 if (this.hasOwnProperty(k)) | 51 if (this.hasOwnProperty(k)) |
45 f(k, this[k]); | 52 f(k, this[k]); |
46 } | 53 } |
47 }; | 54 }; |
48 | 55 |
49 function expect(expected, message) { | 56 function expect(expected, message) { |
50 return chrome.test.callbackPass(function(value) { | 57 return chrome.test.callbackPass(function(value) { |
(...skipping 22 matching lines...) Expand all Loading... | |
73 settings.forEach(function(type, setting) { | 80 settings.forEach(function(type, setting) { |
74 cs[type].set({ | 81 cs[type].set({ |
75 'primaryPattern': 'http://*.google.com/*', | 82 'primaryPattern': 'http://*.google.com/*', |
76 'secondaryPattern': 'http://*.google.com/*', | 83 'secondaryPattern': 'http://*.google.com/*', |
77 'setting': setting | 84 'setting': setting |
78 }, chrome.test.callbackPass()); | 85 }, chrome.test.callbackPass()); |
79 }); | 86 }); |
80 }, | 87 }, |
81 function getContentSettings() { | 88 function getContentSettings() { |
82 settings.forEach(function(type, setting) { | 89 settings.forEach(function(type, setting) { |
90 setting = expectations[type] || setting; | |
83 var message = "Setting for " + type + " should be " + setting; | 91 var message = "Setting for " + type + " should be " + setting; |
84 cs[type].get({ | 92 cs[type].get({ |
85 'primaryUrl': 'http://www.google.com', | 93 'primaryUrl': 'http://www.google.com', |
86 'secondaryUrl': 'http://www.google.com' | 94 'secondaryUrl': 'http://www.google.com' |
87 }, expect({'setting':setting}, message)); | 95 }, expect({'setting':setting}, message)); |
88 }); | 96 }); |
89 }, | 97 }, |
90 function invalidSettings() { | 98 function invalidSettings() { |
91 cs.cookies.get({ | 99 cs.cookies.get({ |
92 'primaryUrl': 'moo' | 100 'primaryUrl': 'moo' |
93 }, chrome.test.callbackFail("The URL \"moo\" is invalid.")); | 101 }, chrome.test.callbackFail("The URL \"moo\" is invalid.")); |
94 cs.plugins.set({ | 102 cs.plugins.set({ |
95 'primaryPattern': 'http://example.com/*', | 103 'primaryPattern': 'http://example.com/*', |
96 'secondaryPattern': 'http://example.com/path', | 104 'secondaryPattern': 'http://example.com/path', |
97 'setting': 'block' | 105 'setting': 'block' |
98 }, chrome.test.callbackFail("Specific paths are not allowed.")); | 106 }, chrome.test.callbackFail("Specific paths are not allowed.")); |
99 cs.javascript.set({ | 107 cs.javascript.set({ |
100 'primaryPattern': 'http://example.com/*', | 108 'primaryPattern': 'http://example.com/*', |
101 'secondaryPattern': 'file:///home/hansmoleman/*', | 109 'secondaryPattern': 'file:///home/hansmoleman/*', |
102 'setting': 'allow' | 110 'setting': 'allow' |
103 }, chrome.test.callbackFail( | 111 }, chrome.test.callbackFail( |
104 "Path wildcards in file URL patterns are not allowed.")); | 112 "Path wildcards in file URL patterns are not allowed.")); |
105 } | 113 } |
106 ]); | 114 ]); |
OLD | NEW |