OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include <memory> | 5 #include <memory> |
6 #include <string> | 6 #include <string> |
7 | 7 |
8 #include "base/auto_reset.h" | 8 #include "base/auto_reset.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 | 92 |
93 // Wrapper to query GetWebsiteSetting(), and only return the source. | 93 // Wrapper to query GetWebsiteSetting(), and only return the source. |
94 content_settings::SettingSource GetSettingSourceForURL( | 94 content_settings::SettingSource GetSettingSourceForURL( |
95 const std::string& url_str) { | 95 const std::string& url_str) { |
96 GURL url(url_str); | 96 GURL url(url_str); |
97 content_settings::SettingInfo setting_info; | 97 content_settings::SettingInfo setting_info; |
98 std::unique_ptr<base::Value> result = | 98 std::unique_ptr<base::Value> result = |
99 host_content_settings_map_->GetWebsiteSetting( | 99 host_content_settings_map_->GetWebsiteSetting( |
100 url, url, content_type_, std::string(), &setting_info); | 100 url, url, content_type_, std::string(), &setting_info); |
101 return setting_info.source; | 101 return setting_info.source; |
102 }; | 102 } |
103 | 103 |
104 private: | 104 private: |
105 syncable_prefs::TestingPrefServiceSyncable* prefs_; | 105 syncable_prefs::TestingPrefServiceSyncable* prefs_; |
106 HostContentSettingsMap* host_content_settings_map_; | 106 HostContentSettingsMap* host_content_settings_map_; |
107 ContentSettingsType content_type_; | 107 ContentSettingsType content_type_; |
108 const char* policy_default_setting_; | 108 const char* policy_default_setting_; |
109 | 109 |
110 DISALLOW_COPY_AND_ASSIGN(TesterForType); | 110 DISALLOW_COPY_AND_ASSIGN(TesterForType); |
111 }; | 111 }; |
112 | 112 |
113 TEST_F(HostContentSettingsMapTest, DefaultValues) { | 113 TEST_F(HostContentSettingsMapTest, DefaultValues) { |
114 TestingProfile profile; | 114 TestingProfile profile; |
115 HostContentSettingsMap* host_content_settings_map = | 115 HostContentSettingsMap* host_content_settings_map = |
116 HostContentSettingsMapFactory::GetForProfile(&profile); | 116 HostContentSettingsMapFactory::GetForProfile(&profile); |
117 | 117 |
118 // Check setting defaults. | 118 // Check setting defaults. |
119 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 119 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
120 host_content_settings_map->GetDefaultContentSetting( | 120 host_content_settings_map->GetDefaultContentSetting( |
121 CONTENT_SETTINGS_TYPE_JAVASCRIPT, NULL)); | 121 CONTENT_SETTINGS_TYPE_JAVASCRIPT, NULL)); |
122 host_content_settings_map->SetDefaultContentSetting( | 122 host_content_settings_map->SetDefaultContentSetting( |
123 CONTENT_SETTINGS_TYPE_IMAGES, CONTENT_SETTING_BLOCK); | 123 CONTENT_SETTINGS_TYPE_JAVASCRIPT, CONTENT_SETTING_BLOCK); |
124 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 124 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
125 host_content_settings_map->GetDefaultContentSetting( | 125 host_content_settings_map->GetDefaultContentSetting( |
126 CONTENT_SETTINGS_TYPE_IMAGES, NULL)); | 126 CONTENT_SETTINGS_TYPE_JAVASCRIPT, NULL)); |
127 EXPECT_EQ(CONTENT_SETTING_ALLOW, host_content_settings_map->GetContentSetting( | 127 EXPECT_EQ( |
128 GURL(chrome::kChromeUINewTabURL), | 128 CONTENT_SETTING_ALLOW, |
129 GURL(chrome::kChromeUINewTabURL), | 129 host_content_settings_map->GetContentSetting( |
130 CONTENT_SETTINGS_TYPE_IMAGES, | 130 GURL(chrome::kChromeUINewTabURL), GURL(chrome::kChromeUINewTabURL), |
131 std::string())); | 131 CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string())); |
132 | 132 |
133 #if defined(ENABLE_PLUGINS) | 133 #if defined(ENABLE_PLUGINS) |
134 host_content_settings_map->SetDefaultContentSetting( | 134 host_content_settings_map->SetDefaultContentSetting( |
135 CONTENT_SETTINGS_TYPE_PLUGINS, CONTENT_SETTING_ALLOW); | 135 CONTENT_SETTINGS_TYPE_PLUGINS, CONTENT_SETTING_ALLOW); |
136 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 136 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
137 host_content_settings_map->GetDefaultContentSetting( | 137 host_content_settings_map->GetDefaultContentSetting( |
138 CONTENT_SETTINGS_TYPE_PLUGINS, NULL)); | 138 CONTENT_SETTINGS_TYPE_PLUGINS, NULL)); |
139 host_content_settings_map->SetDefaultContentSetting( | 139 host_content_settings_map->SetDefaultContentSetting( |
140 CONTENT_SETTINGS_TYPE_PLUGINS, CONTENT_SETTING_BLOCK); | 140 CONTENT_SETTINGS_TYPE_PLUGINS, CONTENT_SETTING_BLOCK); |
141 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 141 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
(...skipping 18 matching lines...) Expand all Loading... |
160 | 160 |
161 TEST_F(HostContentSettingsMapTest, IndividualSettings) { | 161 TEST_F(HostContentSettingsMapTest, IndividualSettings) { |
162 TestingProfile profile; | 162 TestingProfile profile; |
163 HostContentSettingsMap* host_content_settings_map = | 163 HostContentSettingsMap* host_content_settings_map = |
164 HostContentSettingsMapFactory::GetForProfile(&profile); | 164 HostContentSettingsMapFactory::GetForProfile(&profile); |
165 | 165 |
166 // Check returning individual settings. | 166 // Check returning individual settings. |
167 GURL host("http://example.com/"); | 167 GURL host("http://example.com/"); |
168 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 168 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
169 host_content_settings_map->GetContentSetting( | 169 host_content_settings_map->GetContentSetting( |
170 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); | 170 host, host, CONTENT_SETTINGS_TYPE_COOKIES, std::string())); |
171 host_content_settings_map->SetContentSettingDefaultScope( | 171 host_content_settings_map->SetContentSettingDefaultScope( |
172 host, GURL(), CONTENT_SETTINGS_TYPE_IMAGES, std::string(), | 172 host, GURL(), CONTENT_SETTINGS_TYPE_COOKIES, std::string(), |
173 CONTENT_SETTING_DEFAULT); | 173 CONTENT_SETTING_DEFAULT); |
174 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 174 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
175 host_content_settings_map->GetContentSetting( | 175 host_content_settings_map->GetContentSetting( |
176 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); | 176 host, host, CONTENT_SETTINGS_TYPE_COOKIES, std::string())); |
177 host_content_settings_map->SetContentSettingDefaultScope( | 177 host_content_settings_map->SetContentSettingDefaultScope( |
178 host, GURL(), CONTENT_SETTINGS_TYPE_IMAGES, std::string(), | 178 host, GURL(), CONTENT_SETTINGS_TYPE_COOKIES, std::string(), |
179 CONTENT_SETTING_BLOCK); | 179 CONTENT_SETTING_BLOCK); |
180 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 180 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
181 host_content_settings_map->GetContentSetting( | 181 host_content_settings_map->GetContentSetting( |
182 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); | 182 host, host, CONTENT_SETTINGS_TYPE_COOKIES, std::string())); |
183 #if defined(ENABLE_PLUGINS) | 183 #if defined(ENABLE_PLUGINS) |
184 EXPECT_EQ(CONTENT_SETTING_DETECT_IMPORTANT_CONTENT, | 184 EXPECT_EQ(CONTENT_SETTING_DETECT_IMPORTANT_CONTENT, |
185 host_content_settings_map->GetContentSetting( | 185 host_content_settings_map->GetContentSetting( |
186 host, host, CONTENT_SETTINGS_TYPE_PLUGINS, std::string())); | 186 host, host, CONTENT_SETTINGS_TYPE_PLUGINS, std::string())); |
187 #endif | 187 #endif |
188 | 188 |
189 // Check returning all settings for a host. | 189 // Check returning all settings for a host. |
190 host_content_settings_map->SetContentSettingDefaultScope( | 190 host_content_settings_map->SetContentSettingDefaultScope( |
191 host, GURL(), CONTENT_SETTINGS_TYPE_IMAGES, std::string(), | |
192 CONTENT_SETTING_DEFAULT); | |
193 EXPECT_EQ(CONTENT_SETTING_ALLOW, | |
194 host_content_settings_map->GetContentSetting( | |
195 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); | |
196 host_content_settings_map->SetContentSettingDefaultScope( | |
197 host, GURL(), CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string(), | 191 host, GURL(), CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string(), |
198 CONTENT_SETTING_BLOCK); | 192 CONTENT_SETTING_BLOCK); |
199 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 193 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
200 host_content_settings_map->GetContentSetting( | 194 host_content_settings_map->GetContentSetting( |
201 host, host, CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string())); | 195 host, host, CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string())); |
202 #if defined(ENABLE_PLUGINS) | 196 #if defined(ENABLE_PLUGINS) |
203 host_content_settings_map->SetContentSettingDefaultScope( | 197 host_content_settings_map->SetContentSettingDefaultScope( |
204 host, GURL(), CONTENT_SETTINGS_TYPE_PLUGINS, std::string(), | 198 host, GURL(), CONTENT_SETTINGS_TYPE_PLUGINS, std::string(), |
205 CONTENT_SETTING_ALLOW); | 199 CONTENT_SETTING_ALLOW); |
206 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 200 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
207 host_content_settings_map->GetContentSetting( | 201 host_content_settings_map->GetContentSetting( |
208 host, host, CONTENT_SETTINGS_TYPE_PLUGINS, std::string())); | 202 host, host, CONTENT_SETTINGS_TYPE_PLUGINS, std::string())); |
209 #endif | 203 #endif |
210 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 204 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
211 host_content_settings_map->GetContentSetting( | 205 host_content_settings_map->GetContentSetting( |
212 host, host, CONTENT_SETTINGS_TYPE_POPUPS, std::string())); | 206 host, host, CONTENT_SETTINGS_TYPE_POPUPS, std::string())); |
213 EXPECT_EQ(CONTENT_SETTING_ASK, | 207 EXPECT_EQ(CONTENT_SETTING_ASK, |
214 host_content_settings_map->GetContentSetting( | 208 host_content_settings_map->GetContentSetting( |
215 host, host, CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); | 209 host, host, CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); |
216 EXPECT_EQ( | 210 EXPECT_EQ( |
217 CONTENT_SETTING_ASK, | 211 CONTENT_SETTING_ASK, |
218 host_content_settings_map->GetContentSetting( | 212 host_content_settings_map->GetContentSetting( |
219 host, host, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string())); | 213 host, host, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string())); |
220 EXPECT_EQ(CONTENT_SETTING_ASK, | 214 EXPECT_EQ(CONTENT_SETTING_ASK, |
221 host_content_settings_map->GetContentSetting( | 215 host_content_settings_map->GetContentSetting( |
222 host, host, CONTENT_SETTINGS_TYPE_FULLSCREEN, std::string())); | 216 host, host, CONTENT_SETTINGS_TYPE_FULLSCREEN, std::string())); |
223 EXPECT_EQ(CONTENT_SETTING_ASK, | |
224 host_content_settings_map->GetContentSetting( | |
225 host, host, CONTENT_SETTINGS_TYPE_MOUSELOCK, std::string())); | |
226 | 217 |
227 host_content_settings_map->SetContentSettingDefaultScope( | 218 host_content_settings_map->SetContentSettingDefaultScope( |
228 host, GURL(), CONTENT_SETTINGS_TYPE_KEYGEN, std::string(), | 219 host, GURL(), CONTENT_SETTINGS_TYPE_KEYGEN, std::string(), |
229 CONTENT_SETTING_ALLOW); | 220 CONTENT_SETTING_ALLOW); |
230 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 221 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
231 host_content_settings_map->GetContentSetting( | 222 host_content_settings_map->GetContentSetting( |
232 host, host, CONTENT_SETTINGS_TYPE_KEYGEN, std::string())); | 223 host, host, CONTENT_SETTINGS_TYPE_KEYGEN, std::string())); |
233 | 224 |
234 host_content_settings_map->SetContentSettingDefaultScope( | 225 host_content_settings_map->SetContentSettingDefaultScope( |
235 host, GURL(), CONTENT_SETTINGS_TYPE_AUTOPLAY, std::string(), | 226 host, GURL(), CONTENT_SETTINGS_TYPE_AUTOPLAY, std::string(), |
236 CONTENT_SETTING_BLOCK); | 227 CONTENT_SETTING_BLOCK); |
237 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 228 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
238 host_content_settings_map->GetContentSetting( | 229 host_content_settings_map->GetContentSetting( |
239 host, host, CONTENT_SETTINGS_TYPE_AUTOPLAY, std::string())); | 230 host, host, CONTENT_SETTINGS_TYPE_AUTOPLAY, std::string())); |
240 | 231 |
241 // Check returning all hosts for a setting. | 232 // Check returning all hosts for a setting. |
242 GURL host2("http://example.org/"); | 233 GURL host2("http://example.org/"); |
243 host_content_settings_map->SetContentSettingDefaultScope( | 234 host_content_settings_map->SetContentSettingDefaultScope( |
244 host2, GURL(), CONTENT_SETTINGS_TYPE_IMAGES, std::string(), | 235 host2, GURL(), CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string(), |
245 CONTENT_SETTING_BLOCK); | 236 CONTENT_SETTING_BLOCK); |
246 #if defined(ENABLE_PLUGINS) | 237 #if defined(ENABLE_PLUGINS) |
247 host_content_settings_map->SetContentSettingDefaultScope( | 238 host_content_settings_map->SetContentSettingDefaultScope( |
248 host2, GURL(), CONTENT_SETTINGS_TYPE_PLUGINS, std::string(), | 239 host2, GURL(), CONTENT_SETTINGS_TYPE_PLUGINS, std::string(), |
249 CONTENT_SETTING_BLOCK); | 240 CONTENT_SETTING_BLOCK); |
250 #endif | 241 #endif |
251 ContentSettingsForOneType host_settings; | 242 ContentSettingsForOneType host_settings; |
252 host_content_settings_map->GetSettingsForOneType( | 243 host_content_settings_map->GetSettingsForOneType( |
253 CONTENT_SETTINGS_TYPE_IMAGES, std::string(), &host_settings); | 244 CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string(), &host_settings); |
254 // |host_settings| contains the default setting and an exception. | 245 // |host_settings| contains the default setting and 2 exception. |
255 EXPECT_EQ(2U, host_settings.size()); | 246 EXPECT_EQ(3U, host_settings.size()); |
256 #if defined(ENABLE_PLUGINS) | 247 #if defined(ENABLE_PLUGINS) |
257 host_content_settings_map->GetSettingsForOneType( | 248 host_content_settings_map->GetSettingsForOneType( |
258 CONTENT_SETTINGS_TYPE_PLUGINS, std::string(), &host_settings); | 249 CONTENT_SETTINGS_TYPE_PLUGINS, std::string(), &host_settings); |
259 // |host_settings| contains the default setting and 2 exceptions. | 250 // |host_settings| contains the default setting and 2 exceptions. |
260 EXPECT_EQ(3U, host_settings.size()); | 251 EXPECT_EQ(3U, host_settings.size()); |
261 #endif | 252 #endif |
262 host_content_settings_map->GetSettingsForOneType( | 253 host_content_settings_map->GetSettingsForOneType( |
263 CONTENT_SETTINGS_TYPE_POPUPS, std::string(), &host_settings); | 254 CONTENT_SETTINGS_TYPE_POPUPS, std::string(), &host_settings); |
264 // |host_settings| contains only the default setting. | 255 // |host_settings| contains only the default setting. |
265 EXPECT_EQ(1U, host_settings.size()); | 256 EXPECT_EQ(1U, host_settings.size()); |
266 } | 257 } |
267 | 258 |
268 TEST_F(HostContentSettingsMapTest, Clear) { | 259 TEST_F(HostContentSettingsMapTest, Clear) { |
269 TestingProfile profile; | 260 TestingProfile profile; |
270 HostContentSettingsMap* host_content_settings_map = | 261 HostContentSettingsMap* host_content_settings_map = |
271 HostContentSettingsMapFactory::GetForProfile(&profile); | 262 HostContentSettingsMapFactory::GetForProfile(&profile); |
272 | 263 |
273 // Check clearing one type. | 264 // Check clearing one type. |
274 GURL host("http://example.org/"); | 265 GURL host("http://example.org/"); |
275 GURL host2("http://example.net/"); | 266 GURL host2("http://example.net/"); |
276 host_content_settings_map->SetContentSettingDefaultScope( | 267 host_content_settings_map->SetContentSettingDefaultScope( |
277 host2, GURL(), CONTENT_SETTINGS_TYPE_IMAGES, std::string(), | 268 host2, GURL(), CONTENT_SETTINGS_TYPE_COOKIES, std::string(), |
278 CONTENT_SETTING_BLOCK); | 269 CONTENT_SETTING_BLOCK); |
279 host_content_settings_map->SetContentSettingDefaultScope( | 270 host_content_settings_map->SetContentSettingDefaultScope( |
280 host, GURL(), CONTENT_SETTINGS_TYPE_IMAGES, std::string(), | 271 host, GURL(), CONTENT_SETTINGS_TYPE_COOKIES, std::string(), |
281 CONTENT_SETTING_BLOCK); | 272 CONTENT_SETTING_BLOCK); |
282 #if defined(ENABLE_PLUGINS) | 273 #if defined(ENABLE_PLUGINS) |
283 host_content_settings_map->SetContentSettingDefaultScope( | 274 host_content_settings_map->SetContentSettingDefaultScope( |
284 host, GURL(), CONTENT_SETTINGS_TYPE_PLUGINS, std::string(), | 275 host, GURL(), CONTENT_SETTINGS_TYPE_PLUGINS, std::string(), |
285 CONTENT_SETTING_BLOCK); | 276 CONTENT_SETTING_BLOCK); |
286 #endif | 277 #endif |
287 host_content_settings_map->SetContentSettingDefaultScope( | 278 host_content_settings_map->SetContentSettingDefaultScope( |
288 host2, GURL(), CONTENT_SETTINGS_TYPE_IMAGES, std::string(), | 279 host2, GURL(), CONTENT_SETTINGS_TYPE_COOKIES, std::string(), |
289 CONTENT_SETTING_BLOCK); | 280 CONTENT_SETTING_BLOCK); |
290 host_content_settings_map->ClearSettingsForOneType( | 281 host_content_settings_map->ClearSettingsForOneType( |
291 CONTENT_SETTINGS_TYPE_IMAGES); | 282 CONTENT_SETTINGS_TYPE_COOKIES); |
292 ContentSettingsForOneType host_settings; | 283 ContentSettingsForOneType host_settings; |
293 host_content_settings_map->GetSettingsForOneType( | 284 host_content_settings_map->GetSettingsForOneType( |
294 CONTENT_SETTINGS_TYPE_IMAGES, std::string(), &host_settings); | 285 CONTENT_SETTINGS_TYPE_COOKIES, std::string(), &host_settings); |
295 // |host_settings| contains only the default setting. | 286 // |host_settings| contains only the default setting. |
296 EXPECT_EQ(1U, host_settings.size()); | 287 EXPECT_EQ(1U, host_settings.size()); |
297 #if defined(ENABLE_PLUGINS) | 288 #if defined(ENABLE_PLUGINS) |
298 host_content_settings_map->GetSettingsForOneType( | 289 host_content_settings_map->GetSettingsForOneType( |
299 CONTENT_SETTINGS_TYPE_PLUGINS, std::string(), &host_settings); | 290 CONTENT_SETTINGS_TYPE_PLUGINS, std::string(), &host_settings); |
300 // |host_settings| contains the default setting and an exception. | 291 // |host_settings| contains the default setting and an exception. |
301 EXPECT_EQ(2U, host_settings.size()); | 292 EXPECT_EQ(2U, host_settings.size()); |
302 #endif | 293 #endif |
303 } | 294 } |
304 | 295 |
305 TEST_F(HostContentSettingsMapTest, Patterns) { | 296 TEST_F(HostContentSettingsMapTest, Patterns) { |
306 TestingProfile profile; | 297 TestingProfile profile; |
307 HostContentSettingsMap* host_content_settings_map = | 298 HostContentSettingsMap* host_content_settings_map = |
308 HostContentSettingsMapFactory::GetForProfile(&profile); | 299 HostContentSettingsMapFactory::GetForProfile(&profile); |
309 | 300 |
310 GURL host1("http://example.com/"); | 301 GURL host1("http://example.com/"); |
311 GURL host2("http://www.example.com/"); | 302 GURL host2("http://www.example.com/"); |
312 GURL host3("http://example.org/"); | 303 GURL host3("http://example.org/"); |
313 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 304 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
314 host_content_settings_map->GetContentSetting( | 305 host_content_settings_map->GetContentSetting( |
315 host1, host1, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); | 306 host1, host1, CONTENT_SETTINGS_TYPE_COOKIES, std::string())); |
316 host_content_settings_map->SetContentSettingDefaultScope( | 307 host_content_settings_map->SetContentSettingDefaultScope( |
317 host1, GURL(), CONTENT_SETTINGS_TYPE_IMAGES, std::string(), | 308 host1, GURL(), CONTENT_SETTINGS_TYPE_COOKIES, std::string(), |
318 CONTENT_SETTING_BLOCK); | 309 CONTENT_SETTING_BLOCK); |
319 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 310 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
320 host_content_settings_map->GetContentSetting( | 311 host_content_settings_map->GetContentSetting( |
321 host1, host1, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); | 312 host1, host1, CONTENT_SETTINGS_TYPE_COOKIES, std::string())); |
322 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 313 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
323 host_content_settings_map->GetContentSetting( | 314 host_content_settings_map->GetContentSetting( |
324 host2, host2, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); | 315 host2, host2, CONTENT_SETTINGS_TYPE_COOKIES, std::string())); |
325 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 316 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
326 host_content_settings_map->GetContentSetting( | 317 host_content_settings_map->GetContentSetting( |
327 host3, host3, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); | 318 host3, host3, CONTENT_SETTINGS_TYPE_COOKIES, std::string())); |
328 host_content_settings_map->SetContentSettingDefaultScope( | 319 host_content_settings_map->SetContentSettingDefaultScope( |
329 host3, GURL(), CONTENT_SETTINGS_TYPE_IMAGES, std::string(), | 320 host3, GURL(), CONTENT_SETTINGS_TYPE_COOKIES, std::string(), |
330 CONTENT_SETTING_BLOCK); | 321 CONTENT_SETTING_BLOCK); |
331 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 322 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
332 host_content_settings_map->GetContentSetting( | 323 host_content_settings_map->GetContentSetting( |
333 host3, host3, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); | 324 host3, host3, CONTENT_SETTINGS_TYPE_COOKIES, std::string())); |
334 } | 325 } |
335 | 326 |
336 TEST_F(HostContentSettingsMapTest, Observer) { | 327 TEST_F(HostContentSettingsMapTest, Observer) { |
337 TestingProfile profile; | 328 TestingProfile profile; |
338 HostContentSettingsMap* host_content_settings_map = | 329 HostContentSettingsMap* host_content_settings_map = |
339 HostContentSettingsMapFactory::GetForProfile(&profile); | 330 HostContentSettingsMapFactory::GetForProfile(&profile); |
340 MockSettingsObserver observer(host_content_settings_map); | 331 MockSettingsObserver observer(host_content_settings_map); |
341 | 332 |
342 GURL host("http://example.com/"); | 333 GURL host("http://example.com/"); |
343 ContentSettingsPattern primary_pattern = | 334 ContentSettingsPattern primary_pattern = |
344 ContentSettingsPattern::FromString("[*.]example.com"); | 335 ContentSettingsPattern::FromString("[*.]example.com"); |
345 ContentSettingsPattern secondary_pattern = | 336 ContentSettingsPattern secondary_pattern = |
346 ContentSettingsPattern::Wildcard(); | 337 ContentSettingsPattern::Wildcard(); |
347 EXPECT_CALL(observer, | 338 EXPECT_CALL(observer, OnContentSettingsChanged(host_content_settings_map, |
348 OnContentSettingsChanged(host_content_settings_map, | 339 CONTENT_SETTINGS_TYPE_COOKIES, |
349 CONTENT_SETTINGS_TYPE_IMAGES, | 340 false, primary_pattern, |
350 false, | 341 secondary_pattern, false)); |
351 primary_pattern, | |
352 secondary_pattern, | |
353 false)); | |
354 host_content_settings_map->SetContentSettingDefaultScope( | 342 host_content_settings_map->SetContentSettingDefaultScope( |
355 host, GURL(), CONTENT_SETTINGS_TYPE_IMAGES, std::string(), | 343 host, GURL(), CONTENT_SETTINGS_TYPE_COOKIES, std::string(), |
356 CONTENT_SETTING_ALLOW); | 344 CONTENT_SETTING_ALLOW); |
357 ::testing::Mock::VerifyAndClearExpectations(&observer); | 345 ::testing::Mock::VerifyAndClearExpectations(&observer); |
358 | 346 |
359 EXPECT_CALL(observer, | 347 EXPECT_CALL(observer, OnContentSettingsChanged(host_content_settings_map, |
360 OnContentSettingsChanged(host_content_settings_map, | 348 CONTENT_SETTINGS_TYPE_COOKIES, |
361 CONTENT_SETTINGS_TYPE_IMAGES, false, | 349 false, _, _, true)); |
362 _, _, true)); | |
363 host_content_settings_map->ClearSettingsForOneType( | 350 host_content_settings_map->ClearSettingsForOneType( |
364 CONTENT_SETTINGS_TYPE_IMAGES); | 351 CONTENT_SETTINGS_TYPE_COOKIES); |
365 ::testing::Mock::VerifyAndClearExpectations(&observer); | 352 ::testing::Mock::VerifyAndClearExpectations(&observer); |
366 | 353 |
367 EXPECT_CALL(observer, | 354 EXPECT_CALL(observer, OnContentSettingsChanged(host_content_settings_map, |
368 OnContentSettingsChanged(host_content_settings_map, | 355 CONTENT_SETTINGS_TYPE_COOKIES, |
369 CONTENT_SETTINGS_TYPE_IMAGES, false, | 356 false, _, _, true)); |
370 _, _, true)); | |
371 host_content_settings_map->SetDefaultContentSetting( | 357 host_content_settings_map->SetDefaultContentSetting( |
372 CONTENT_SETTINGS_TYPE_IMAGES, CONTENT_SETTING_BLOCK); | 358 CONTENT_SETTINGS_TYPE_COOKIES, CONTENT_SETTING_BLOCK); |
373 } | 359 } |
374 | 360 |
375 TEST_F(HostContentSettingsMapTest, ObserveDefaultPref) { | 361 TEST_F(HostContentSettingsMapTest, ObserveDefaultPref) { |
376 TestingProfile profile; | 362 TestingProfile profile; |
377 HostContentSettingsMap* host_content_settings_map = | 363 HostContentSettingsMap* host_content_settings_map = |
378 HostContentSettingsMapFactory::GetForProfile(&profile); | 364 HostContentSettingsMapFactory::GetForProfile(&profile); |
379 | 365 |
380 PrefService* prefs = profile.GetPrefs(); | 366 PrefService* prefs = profile.GetPrefs(); |
381 GURL host("http://example.com"); | 367 GURL host("http://example.com"); |
382 | 368 |
383 host_content_settings_map->SetDefaultContentSetting( | 369 host_content_settings_map->SetDefaultContentSetting( |
384 CONTENT_SETTINGS_TYPE_IMAGES, CONTENT_SETTING_BLOCK); | 370 CONTENT_SETTINGS_TYPE_COOKIES, CONTENT_SETTING_BLOCK); |
385 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 371 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
386 host_content_settings_map->GetContentSetting( | 372 host_content_settings_map->GetContentSetting( |
387 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); | 373 host, host, CONTENT_SETTINGS_TYPE_COOKIES, std::string())); |
388 | 374 |
389 const content_settings::WebsiteSettingsInfo* info = | 375 const content_settings::WebsiteSettingsInfo* info = |
390 content_settings::WebsiteSettingsRegistry::GetInstance()->Get( | 376 content_settings::WebsiteSettingsRegistry::GetInstance()->Get( |
391 CONTENT_SETTINGS_TYPE_IMAGES); | 377 CONTENT_SETTINGS_TYPE_COOKIES); |
392 // Clearing the backing pref should also clear the internal cache. | 378 // Clearing the backing pref should also clear the internal cache. |
393 prefs->ClearPref(info->default_value_pref_name()); | 379 prefs->ClearPref(info->default_value_pref_name()); |
394 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 380 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
395 host_content_settings_map->GetContentSetting( | 381 host_content_settings_map->GetContentSetting( |
396 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); | 382 host, host, CONTENT_SETTINGS_TYPE_COOKIES, std::string())); |
397 | 383 |
398 // Reseting the pref to its previous value should update the cache. | 384 // Reseting the pref to its previous value should update the cache. |
399 prefs->SetInteger(info->default_value_pref_name(), CONTENT_SETTING_BLOCK); | 385 prefs->SetInteger(info->default_value_pref_name(), CONTENT_SETTING_BLOCK); |
400 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 386 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
401 host_content_settings_map->GetContentSetting( | 387 host_content_settings_map->GetContentSetting( |
402 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); | 388 host, host, CONTENT_SETTINGS_TYPE_COOKIES, std::string())); |
403 } | 389 } |
404 | 390 |
405 TEST_F(HostContentSettingsMapTest, ObserveExceptionPref) { | 391 TEST_F(HostContentSettingsMapTest, ObserveExceptionPref) { |
406 TestingProfile profile; | 392 TestingProfile profile; |
407 HostContentSettingsMap* host_content_settings_map = | 393 HostContentSettingsMap* host_content_settings_map = |
408 HostContentSettingsMapFactory::GetForProfile(&profile); | 394 HostContentSettingsMapFactory::GetForProfile(&profile); |
409 | 395 |
410 PrefService* prefs = profile.GetPrefs(); | 396 PrefService* prefs = profile.GetPrefs(); |
411 | 397 |
412 // Make a copy of the default pref value so we can reset it later. | 398 // Make a copy of the default pref value so we can reset it later. |
413 std::unique_ptr<base::Value> default_value( | 399 std::unique_ptr<base::Value> default_value( |
414 prefs->FindPreference(GetPrefName(CONTENT_SETTINGS_TYPE_IMAGES)) | 400 prefs->FindPreference(GetPrefName(CONTENT_SETTINGS_TYPE_COOKIES)) |
415 ->GetValue() | 401 ->GetValue() |
416 ->DeepCopy()); | 402 ->DeepCopy()); |
417 | 403 |
418 GURL host("http://example.com"); | 404 GURL host("http://example.com"); |
419 | 405 |
420 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 406 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
421 host_content_settings_map->GetContentSetting( | 407 host_content_settings_map->GetContentSetting( |
422 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); | 408 host, host, CONTENT_SETTINGS_TYPE_COOKIES, std::string())); |
423 | 409 |
424 host_content_settings_map->SetContentSettingDefaultScope( | 410 host_content_settings_map->SetContentSettingDefaultScope( |
425 host, GURL(), CONTENT_SETTINGS_TYPE_IMAGES, std::string(), | 411 host, GURL(), CONTENT_SETTINGS_TYPE_COOKIES, std::string(), |
426 CONTENT_SETTING_BLOCK); | 412 CONTENT_SETTING_BLOCK); |
427 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 413 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
428 host_content_settings_map->GetContentSetting( | 414 host_content_settings_map->GetContentSetting( |
429 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); | 415 host, host, CONTENT_SETTINGS_TYPE_COOKIES, std::string())); |
430 | 416 |
431 // Make a copy of the pref's new value so we can reset it later. | 417 // Make a copy of the pref's new value so we can reset it later. |
432 std::unique_ptr<base::Value> new_value( | 418 std::unique_ptr<base::Value> new_value( |
433 prefs->FindPreference(GetPrefName(CONTENT_SETTINGS_TYPE_IMAGES)) | 419 prefs->FindPreference(GetPrefName(CONTENT_SETTINGS_TYPE_COOKIES)) |
434 ->GetValue() | 420 ->GetValue() |
435 ->DeepCopy()); | 421 ->DeepCopy()); |
436 | 422 |
437 // Clearing the backing pref should also clear the internal cache. | 423 // Clearing the backing pref should also clear the internal cache. |
438 prefs->Set(GetPrefName(CONTENT_SETTINGS_TYPE_IMAGES), *default_value); | 424 prefs->Set(GetPrefName(CONTENT_SETTINGS_TYPE_COOKIES), *default_value); |
439 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 425 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
440 host_content_settings_map->GetContentSetting( | 426 host_content_settings_map->GetContentSetting( |
441 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); | 427 host, host, CONTENT_SETTINGS_TYPE_COOKIES, std::string())); |
442 | 428 |
443 // Reseting the pref to its previous value should update the cache. | 429 // Reseting the pref to its previous value should update the cache. |
444 prefs->Set(GetPrefName(CONTENT_SETTINGS_TYPE_IMAGES), *new_value); | 430 prefs->Set(GetPrefName(CONTENT_SETTINGS_TYPE_COOKIES), *new_value); |
445 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 431 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
446 host_content_settings_map->GetContentSetting( | 432 host_content_settings_map->GetContentSetting( |
447 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); | 433 host, host, CONTENT_SETTINGS_TYPE_COOKIES, std::string())); |
448 } | 434 } |
449 | 435 |
450 TEST_F(HostContentSettingsMapTest, HostTrimEndingDotCheck) { | 436 TEST_F(HostContentSettingsMapTest, HostTrimEndingDotCheck) { |
451 TestingProfile profile; | 437 TestingProfile profile; |
452 HostContentSettingsMap* host_content_settings_map = | 438 HostContentSettingsMap* host_content_settings_map = |
453 HostContentSettingsMapFactory::GetForProfile(&profile); | 439 HostContentSettingsMapFactory::GetForProfile(&profile); |
454 content_settings::CookieSettings* cookie_settings = | 440 content_settings::CookieSettings* cookie_settings = |
455 CookieSettingsFactory::GetForProfile(&profile).get(); | 441 CookieSettingsFactory::GetForProfile(&profile).get(); |
456 | 442 |
457 GURL host_ending_with_dot("http://example.com./"); | 443 GURL host_ending_with_dot("http://example.com./"); |
458 | 444 |
459 EXPECT_EQ(CONTENT_SETTING_ALLOW, | |
460 host_content_settings_map->GetContentSetting( | |
461 host_ending_with_dot, | |
462 host_ending_with_dot, | |
463 CONTENT_SETTINGS_TYPE_IMAGES, | |
464 std::string())); | |
465 host_content_settings_map->SetContentSettingDefaultScope( | |
466 host_ending_with_dot, GURL(), CONTENT_SETTINGS_TYPE_IMAGES, std::string(), | |
467 CONTENT_SETTING_DEFAULT); | |
468 EXPECT_EQ( | |
469 CONTENT_SETTING_ALLOW, | |
470 host_content_settings_map->GetContentSetting(host_ending_with_dot, | |
471 host_ending_with_dot, | |
472 CONTENT_SETTINGS_TYPE_IMAGES, | |
473 std::string())); | |
474 host_content_settings_map->SetContentSettingDefaultScope( | |
475 host_ending_with_dot, GURL(), CONTENT_SETTINGS_TYPE_IMAGES, std::string(), | |
476 CONTENT_SETTING_BLOCK); | |
477 EXPECT_EQ( | |
478 CONTENT_SETTING_BLOCK, | |
479 host_content_settings_map->GetContentSetting(host_ending_with_dot, | |
480 host_ending_with_dot, | |
481 CONTENT_SETTINGS_TYPE_IMAGES, | |
482 std::string())); | |
483 | |
484 EXPECT_TRUE(cookie_settings->IsSettingCookieAllowed( | 445 EXPECT_TRUE(cookie_settings->IsSettingCookieAllowed( |
485 host_ending_with_dot, host_ending_with_dot)); | 446 host_ending_with_dot, host_ending_with_dot)); |
486 host_content_settings_map->SetContentSettingDefaultScope( | 447 host_content_settings_map->SetContentSettingDefaultScope( |
487 host_ending_with_dot, GURL(), CONTENT_SETTINGS_TYPE_COOKIES, | 448 host_ending_with_dot, GURL(), CONTENT_SETTINGS_TYPE_COOKIES, |
488 std::string(), CONTENT_SETTING_DEFAULT); | 449 std::string(), CONTENT_SETTING_DEFAULT); |
489 EXPECT_TRUE(cookie_settings->IsSettingCookieAllowed( | 450 EXPECT_TRUE(cookie_settings->IsSettingCookieAllowed( |
490 host_ending_with_dot, host_ending_with_dot)); | 451 host_ending_with_dot, host_ending_with_dot)); |
491 host_content_settings_map->SetContentSettingDefaultScope( | 452 host_content_settings_map->SetContentSettingDefaultScope( |
492 host_ending_with_dot, GURL(), CONTENT_SETTINGS_TYPE_COOKIES, | 453 host_ending_with_dot, GURL(), CONTENT_SETTINGS_TYPE_COOKIES, |
493 std::string(), CONTENT_SETTING_BLOCK); | 454 std::string(), CONTENT_SETTING_BLOCK); |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
613 TEST_F(HostContentSettingsMapTest, NestedSettings) { | 574 TEST_F(HostContentSettingsMapTest, NestedSettings) { |
614 TestingProfile profile; | 575 TestingProfile profile; |
615 HostContentSettingsMap* host_content_settings_map = | 576 HostContentSettingsMap* host_content_settings_map = |
616 HostContentSettingsMapFactory::GetForProfile(&profile); | 577 HostContentSettingsMapFactory::GetForProfile(&profile); |
617 | 578 |
618 GURL host("http://a.b.example.com/"); | 579 GURL host("http://a.b.example.com/"); |
619 GURL host1("http://example.com/"); | 580 GURL host1("http://example.com/"); |
620 GURL host2("http://b.example.com/"); | 581 GURL host2("http://b.example.com/"); |
621 | 582 |
622 host_content_settings_map->SetContentSettingDefaultScope( | 583 host_content_settings_map->SetContentSettingDefaultScope( |
623 host1, GURL(), CONTENT_SETTINGS_TYPE_IMAGES, std::string(), | 584 host1, GURL(), CONTENT_SETTINGS_TYPE_POPUPS, std::string(), |
624 CONTENT_SETTING_BLOCK); | 585 CONTENT_SETTING_BLOCK); |
625 | 586 |
626 host_content_settings_map->SetContentSettingDefaultScope( | 587 host_content_settings_map->SetContentSettingDefaultScope( |
627 host2, GURL(), CONTENT_SETTINGS_TYPE_COOKIES, std::string(), | 588 host2, GURL(), CONTENT_SETTINGS_TYPE_COOKIES, std::string(), |
628 CONTENT_SETTING_BLOCK); | 589 CONTENT_SETTING_BLOCK); |
629 | 590 |
630 host_content_settings_map->SetContentSettingDefaultScope( | 591 host_content_settings_map->SetContentSettingDefaultScope( |
631 host, GURL(), CONTENT_SETTINGS_TYPE_PLUGINS, std::string(), | 592 host, GURL(), CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS, std::string(), |
632 CONTENT_SETTING_BLOCK); | 593 CONTENT_SETTING_BLOCK); |
633 host_content_settings_map->SetDefaultContentSetting( | 594 host_content_settings_map->SetDefaultContentSetting( |
634 CONTENT_SETTINGS_TYPE_JAVASCRIPT, CONTENT_SETTING_BLOCK); | 595 CONTENT_SETTINGS_TYPE_JAVASCRIPT, CONTENT_SETTING_BLOCK); |
635 | 596 |
636 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 597 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
637 host_content_settings_map->GetContentSetting( | 598 host_content_settings_map->GetContentSetting( |
638 host, host, CONTENT_SETTINGS_TYPE_COOKIES, std::string())); | 599 host, host, CONTENT_SETTINGS_TYPE_COOKIES, std::string())); |
639 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 600 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
640 host_content_settings_map->GetContentSetting( | 601 host_content_settings_map->GetContentSetting( |
641 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); | 602 host, host, CONTENT_SETTINGS_TYPE_POPUPS, std::string())); |
642 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 603 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
643 host_content_settings_map->GetContentSetting( | 604 host_content_settings_map->GetContentSetting( |
644 host, host, CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string())); | 605 host, host, CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string())); |
645 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 606 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
646 host_content_settings_map->GetContentSetting( | 607 host_content_settings_map->GetContentSetting( |
647 host, host, CONTENT_SETTINGS_TYPE_PLUGINS, std::string())); | 608 host, host, CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS, |
648 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 609 std::string())); |
649 host_content_settings_map->GetContentSetting( | |
650 host, host, CONTENT_SETTINGS_TYPE_POPUPS, std::string())); | |
651 EXPECT_EQ(CONTENT_SETTING_ASK, | 610 EXPECT_EQ(CONTENT_SETTING_ASK, |
652 host_content_settings_map->GetContentSetting( | 611 host_content_settings_map->GetContentSetting( |
653 host, host, CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); | 612 host, host, CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); |
654 EXPECT_EQ( | 613 EXPECT_EQ( |
655 CONTENT_SETTING_ASK, | 614 CONTENT_SETTING_ASK, |
656 host_content_settings_map->GetContentSetting( | 615 host_content_settings_map->GetContentSetting( |
657 host, host, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string())); | 616 host, host, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string())); |
658 EXPECT_EQ(CONTENT_SETTING_ASK, | 617 EXPECT_EQ(CONTENT_SETTING_ASK, |
659 host_content_settings_map->GetContentSetting( | 618 host_content_settings_map->GetContentSetting( |
660 host, host, CONTENT_SETTINGS_TYPE_FULLSCREEN, std::string())); | 619 host, host, CONTENT_SETTINGS_TYPE_FULLSCREEN, std::string())); |
| 620 #if !defined(OS_ANDROID) |
661 EXPECT_EQ(CONTENT_SETTING_ASK, | 621 EXPECT_EQ(CONTENT_SETTING_ASK, |
662 host_content_settings_map->GetContentSetting( | 622 host_content_settings_map->GetContentSetting( |
663 host, host, CONTENT_SETTINGS_TYPE_MOUSELOCK, std::string())); | 623 host, host, CONTENT_SETTINGS_TYPE_MOUSELOCK, std::string())); |
| 624 #endif |
664 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 625 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
665 host_content_settings_map->GetContentSetting( | 626 host_content_settings_map->GetContentSetting( |
666 host, host, CONTENT_SETTINGS_TYPE_KEYGEN, std::string())); | 627 host, host, CONTENT_SETTINGS_TYPE_KEYGEN, std::string())); |
667 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 628 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
668 host_content_settings_map->GetContentSetting( | 629 host_content_settings_map->GetContentSetting( |
669 host, host, CONTENT_SETTINGS_TYPE_AUTOPLAY, std::string())); | 630 host, host, CONTENT_SETTINGS_TYPE_AUTOPLAY, std::string())); |
670 } | 631 } |
671 | 632 |
672 TEST_F(HostContentSettingsMapTest, OffTheRecord) { | 633 TEST_F(HostContentSettingsMapTest, OffTheRecord) { |
673 TestingProfile profile; | 634 TestingProfile profile; |
674 Profile* otr_profile = profile.GetOffTheRecordProfile(); | 635 Profile* otr_profile = profile.GetOffTheRecordProfile(); |
675 HostContentSettingsMap* host_content_settings_map = | 636 HostContentSettingsMap* host_content_settings_map = |
676 HostContentSettingsMapFactory::GetForProfile(&profile); | 637 HostContentSettingsMapFactory::GetForProfile(&profile); |
677 HostContentSettingsMap* otr_map = | 638 HostContentSettingsMap* otr_map = |
678 HostContentSettingsMapFactory::GetForProfile(otr_profile); | 639 HostContentSettingsMapFactory::GetForProfile(otr_profile); |
679 | 640 |
680 GURL host("http://example.com/"); | 641 GURL host("http://example.com/"); |
681 | 642 |
682 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 643 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
683 host_content_settings_map->GetContentSetting( | 644 host_content_settings_map->GetContentSetting( |
684 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); | 645 host, host, CONTENT_SETTINGS_TYPE_COOKIES, std::string())); |
685 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 646 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
686 otr_map->GetContentSetting( | 647 otr_map->GetContentSetting( |
687 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); | 648 host, host, CONTENT_SETTINGS_TYPE_COOKIES, std::string())); |
688 | 649 |
689 // Changing content settings on the main map should also affect the | 650 // Changing content settings on the main map should also affect the |
690 // incognito map. | 651 // incognito map. |
691 host_content_settings_map->SetContentSettingDefaultScope( | 652 host_content_settings_map->SetContentSettingDefaultScope( |
692 host, GURL(), CONTENT_SETTINGS_TYPE_IMAGES, std::string(), | 653 host, GURL(), CONTENT_SETTINGS_TYPE_COOKIES, std::string(), |
693 CONTENT_SETTING_BLOCK); | 654 CONTENT_SETTING_BLOCK); |
694 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 655 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
695 host_content_settings_map->GetContentSetting( | 656 host_content_settings_map->GetContentSetting( |
696 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); | 657 host, host, CONTENT_SETTINGS_TYPE_COOKIES, std::string())); |
697 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 658 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
698 otr_map->GetContentSetting( | 659 otr_map->GetContentSetting( |
699 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); | 660 host, host, CONTENT_SETTINGS_TYPE_COOKIES, std::string())); |
700 | 661 |
701 // Changing content settings on the incognito map should NOT affect the | 662 // Changing content settings on the incognito map should NOT affect the |
702 // main map. | 663 // main map. |
703 otr_map->SetContentSettingDefaultScope(host, GURL(), | 664 otr_map->SetContentSettingDefaultScope(host, GURL(), |
704 CONTENT_SETTINGS_TYPE_IMAGES, | 665 CONTENT_SETTINGS_TYPE_COOKIES, |
705 std::string(), CONTENT_SETTING_ALLOW); | 666 std::string(), CONTENT_SETTING_ALLOW); |
706 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 667 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
707 host_content_settings_map->GetContentSetting( | 668 host_content_settings_map->GetContentSetting( |
708 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); | 669 host, host, CONTENT_SETTINGS_TYPE_COOKIES, std::string())); |
709 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 670 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
710 otr_map->GetContentSetting( | 671 otr_map->GetContentSetting( |
711 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); | 672 host, host, CONTENT_SETTINGS_TYPE_COOKIES, std::string())); |
712 } | 673 } |
713 | 674 |
714 TEST_F(HostContentSettingsMapTest, OffTheRecordPartialInheritPref) { | 675 TEST_F(HostContentSettingsMapTest, OffTheRecordPartialInheritPref) { |
715 // Permissions marked INHERIT_IN_INCOGNITO_EXCEPT_ALLOW in | 676 // Permissions marked INHERIT_IN_INCOGNITO_EXCEPT_ALLOW in |
716 // ContentSettingsRegistry (e.g. push & notifications) only inherit BLOCK | 677 // ContentSettingsRegistry (e.g. push & notifications) only inherit BLOCK |
717 // settings from regular to incognito. | 678 // settings from regular to incognito. |
718 TestingProfile profile; | 679 TestingProfile profile; |
719 Profile* otr_profile = profile.GetOffTheRecordProfile(); | 680 Profile* otr_profile = profile.GetOffTheRecordProfile(); |
720 HostContentSettingsMap* host_content_settings_map = | 681 HostContentSettingsMap* host_content_settings_map = |
721 HostContentSettingsMapFactory::GetForProfile(&profile); | 682 HostContentSettingsMapFactory::GetForProfile(&profile); |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
902 | 863 |
903 // For a single Unicode encoded pattern, check if it gets converted to punycode | 864 // For a single Unicode encoded pattern, check if it gets converted to punycode |
904 // and old pattern gets deleted. | 865 // and old pattern gets deleted. |
905 TEST_F(HostContentSettingsMapTest, CanonicalizeExceptionsUnicodeOnly) { | 866 TEST_F(HostContentSettingsMapTest, CanonicalizeExceptionsUnicodeOnly) { |
906 TestingProfile profile; | 867 TestingProfile profile; |
907 PrefService* prefs = profile.GetPrefs(); | 868 PrefService* prefs = profile.GetPrefs(); |
908 | 869 |
909 // Set utf-8 data. | 870 // Set utf-8 data. |
910 { | 871 { |
911 DictionaryPrefUpdate update(prefs, | 872 DictionaryPrefUpdate update(prefs, |
912 GetPrefName(CONTENT_SETTINGS_TYPE_PLUGINS)); | 873 GetPrefName(CONTENT_SETTINGS_TYPE_COOKIES)); |
913 base::DictionaryValue* all_settings_dictionary = update.Get(); | 874 base::DictionaryValue* all_settings_dictionary = update.Get(); |
914 ASSERT_TRUE(NULL != all_settings_dictionary); | 875 ASSERT_TRUE(NULL != all_settings_dictionary); |
915 | 876 |
916 base::DictionaryValue* dummy_payload = new base::DictionaryValue; | 877 base::DictionaryValue* dummy_payload = new base::DictionaryValue; |
917 dummy_payload->SetInteger("setting", CONTENT_SETTING_ALLOW); | 878 dummy_payload->SetInteger("setting", CONTENT_SETTING_ALLOW); |
918 all_settings_dictionary->SetWithoutPathExpansion("[*.]\xC4\x87ira.com,*", | 879 all_settings_dictionary->SetWithoutPathExpansion("[*.]\xC4\x87ira.com,*", |
919 dummy_payload); | 880 dummy_payload); |
920 } | 881 } |
921 | 882 |
922 HostContentSettingsMapFactory::GetForProfile(&profile); | 883 HostContentSettingsMapFactory::GetForProfile(&profile); |
923 | 884 |
924 const base::DictionaryValue* all_settings_dictionary = | 885 const base::DictionaryValue* all_settings_dictionary = |
925 prefs->GetDictionary(GetPrefName(CONTENT_SETTINGS_TYPE_PLUGINS)); | 886 prefs->GetDictionary(GetPrefName(CONTENT_SETTINGS_TYPE_COOKIES)); |
926 const base::DictionaryValue* result = NULL; | 887 const base::DictionaryValue* result = NULL; |
927 EXPECT_FALSE(all_settings_dictionary->GetDictionaryWithoutPathExpansion( | 888 EXPECT_FALSE(all_settings_dictionary->GetDictionaryWithoutPathExpansion( |
928 "[*.]\xC4\x87ira.com,*", &result)); | 889 "[*.]\xC4\x87ira.com,*", &result)); |
929 EXPECT_TRUE(all_settings_dictionary->GetDictionaryWithoutPathExpansion( | 890 EXPECT_TRUE(all_settings_dictionary->GetDictionaryWithoutPathExpansion( |
930 "[*.]xn--ira-ppa.com,*", &result)); | 891 "[*.]xn--ira-ppa.com,*", &result)); |
931 } | 892 } |
932 | 893 |
933 // If both Unicode and its punycode pattern exist, make sure we don't touch the | 894 // If both Unicode and its punycode pattern exist, make sure we don't touch the |
934 // settings for the punycode, and that Unicode pattern gets deleted. | 895 // settings for the punycode, and that Unicode pattern gets deleted. |
935 TEST_F(HostContentSettingsMapTest, CanonicalizeExceptionsUnicodeAndPunycode) { | 896 TEST_F(HostContentSettingsMapTest, CanonicalizeExceptionsUnicodeAndPunycode) { |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
976 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 937 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
977 host_content_settings_map->GetDefaultContentSetting( | 938 host_content_settings_map->GetDefaultContentSetting( |
978 CONTENT_SETTINGS_TYPE_JAVASCRIPT, NULL)); | 939 CONTENT_SETTINGS_TYPE_JAVASCRIPT, NULL)); |
979 | 940 |
980 // Remove managed-default-content-settings-preferences. | 941 // Remove managed-default-content-settings-preferences. |
981 prefs->RemoveManagedPref(prefs::kManagedDefaultJavaScriptSetting); | 942 prefs->RemoveManagedPref(prefs::kManagedDefaultJavaScriptSetting); |
982 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 943 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
983 host_content_settings_map->GetDefaultContentSetting( | 944 host_content_settings_map->GetDefaultContentSetting( |
984 CONTENT_SETTINGS_TYPE_JAVASCRIPT, NULL)); | 945 CONTENT_SETTINGS_TYPE_JAVASCRIPT, NULL)); |
985 | 946 |
| 947 #if defined(ENABLE_PLUGINS) |
986 // Set preference to manage the default-content-setting for Plugins. | 948 // Set preference to manage the default-content-setting for Plugins. |
987 prefs->SetManagedPref(prefs::kManagedDefaultPluginsSetting, | 949 prefs->SetManagedPref(prefs::kManagedDefaultPluginsSetting, |
988 new base::FundamentalValue(CONTENT_SETTING_BLOCK)); | 950 new base::FundamentalValue(CONTENT_SETTING_BLOCK)); |
989 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 951 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
990 host_content_settings_map->GetDefaultContentSetting( | 952 host_content_settings_map->GetDefaultContentSetting( |
991 CONTENT_SETTINGS_TYPE_PLUGINS, NULL)); | 953 CONTENT_SETTINGS_TYPE_PLUGINS, NULL)); |
992 | 954 |
993 #if defined(ENABLE_PLUGINS) | |
994 // Remove the preference to manage the default-content-setting for Plugins. | 955 // Remove the preference to manage the default-content-setting for Plugins. |
995 prefs->RemoveManagedPref(prefs::kManagedDefaultPluginsSetting); | 956 prefs->RemoveManagedPref(prefs::kManagedDefaultPluginsSetting); |
996 EXPECT_EQ(CONTENT_SETTING_DETECT_IMPORTANT_CONTENT, | 957 EXPECT_EQ(CONTENT_SETTING_DETECT_IMPORTANT_CONTENT, |
997 host_content_settings_map->GetDefaultContentSetting( | 958 host_content_settings_map->GetDefaultContentSetting( |
998 CONTENT_SETTINGS_TYPE_PLUGINS, NULL)); | 959 CONTENT_SETTINGS_TYPE_PLUGINS, NULL)); |
999 #endif | 960 #endif |
1000 | 961 |
1001 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 962 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
1002 host_content_settings_map->GetDefaultContentSetting( | 963 host_content_settings_map->GetDefaultContentSetting( |
1003 CONTENT_SETTINGS_TYPE_KEYGEN, NULL)); | 964 CONTENT_SETTINGS_TYPE_KEYGEN, NULL)); |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1122 // If a setting for a default-content-setting-type is set while the type is | 1083 // If a setting for a default-content-setting-type is set while the type is |
1123 // managed, then the new setting should be preserved and used after the | 1084 // managed, then the new setting should be preserved and used after the |
1124 // default-content-setting-type is not managed anymore. | 1085 // default-content-setting-type is not managed anymore. |
1125 TEST_F(HostContentSettingsMapTest, SettingDefaultContentSettingsWhenManaged) { | 1086 TEST_F(HostContentSettingsMapTest, SettingDefaultContentSettingsWhenManaged) { |
1126 TestingProfile profile; | 1087 TestingProfile profile; |
1127 HostContentSettingsMap* host_content_settings_map = | 1088 HostContentSettingsMap* host_content_settings_map = |
1128 HostContentSettingsMapFactory::GetForProfile(&profile); | 1089 HostContentSettingsMapFactory::GetForProfile(&profile); |
1129 syncable_prefs::TestingPrefServiceSyncable* prefs = | 1090 syncable_prefs::TestingPrefServiceSyncable* prefs = |
1130 profile.GetTestingPrefService(); | 1091 profile.GetTestingPrefService(); |
1131 | 1092 |
1132 prefs->SetManagedPref(prefs::kManagedDefaultPluginsSetting, | 1093 prefs->SetManagedPref(prefs::kManagedDefaultCookiesSetting, |
1133 new base::FundamentalValue(CONTENT_SETTING_ALLOW)); | 1094 new base::FundamentalValue(CONTENT_SETTING_ALLOW)); |
1134 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 1095 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
1135 host_content_settings_map->GetDefaultContentSetting( | 1096 host_content_settings_map->GetDefaultContentSetting( |
1136 CONTENT_SETTINGS_TYPE_PLUGINS, NULL)); | 1097 CONTENT_SETTINGS_TYPE_COOKIES, NULL)); |
1137 | 1098 |
1138 host_content_settings_map->SetDefaultContentSetting( | 1099 host_content_settings_map->SetDefaultContentSetting( |
1139 CONTENT_SETTINGS_TYPE_PLUGINS, CONTENT_SETTING_BLOCK); | 1100 CONTENT_SETTINGS_TYPE_COOKIES, CONTENT_SETTING_BLOCK); |
1140 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 1101 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
1141 host_content_settings_map->GetDefaultContentSetting( | 1102 host_content_settings_map->GetDefaultContentSetting( |
1142 CONTENT_SETTINGS_TYPE_PLUGINS, NULL)); | 1103 CONTENT_SETTINGS_TYPE_COOKIES, NULL)); |
1143 | 1104 |
1144 prefs->RemoveManagedPref(prefs::kManagedDefaultPluginsSetting); | 1105 prefs->RemoveManagedPref(prefs::kManagedDefaultCookiesSetting); |
1145 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 1106 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
1146 host_content_settings_map->GetDefaultContentSetting( | 1107 host_content_settings_map->GetDefaultContentSetting( |
1147 CONTENT_SETTINGS_TYPE_PLUGINS, NULL)); | 1108 CONTENT_SETTINGS_TYPE_COOKIES, NULL)); |
1148 } | 1109 } |
1149 | 1110 |
1150 TEST_F(HostContentSettingsMapTest, GetContentSetting) { | 1111 TEST_F(HostContentSettingsMapTest, GetContentSetting) { |
1151 TestingProfile profile; | 1112 TestingProfile profile; |
1152 HostContentSettingsMap* host_content_settings_map = | 1113 HostContentSettingsMap* host_content_settings_map = |
1153 HostContentSettingsMapFactory::GetForProfile(&profile); | 1114 HostContentSettingsMapFactory::GetForProfile(&profile); |
1154 | 1115 |
1155 GURL host("http://example.com/"); | 1116 GURL host("http://example.com/"); |
1156 GURL embedder("chrome://foo"); | 1117 GURL embedder("chrome://foo"); |
1157 host_content_settings_map->SetContentSettingDefaultScope( | 1118 host_content_settings_map->SetContentSettingDefaultScope( |
1158 host, GURL(), CONTENT_SETTINGS_TYPE_IMAGES, std::string(), | 1119 host, GURL(), CONTENT_SETTINGS_TYPE_COOKIES, std::string(), |
1159 CONTENT_SETTING_BLOCK); | 1120 CONTENT_SETTING_BLOCK); |
1160 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 1121 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
1161 host_content_settings_map->GetContentSetting( | 1122 host_content_settings_map->GetContentSetting( |
1162 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); | 1123 host, host, CONTENT_SETTINGS_TYPE_COOKIES, std::string())); |
1163 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 1124 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
1164 host_content_settings_map->GetContentSetting( | 1125 host_content_settings_map->GetContentSetting( |
1165 embedder, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); | 1126 embedder, host, CONTENT_SETTINGS_TYPE_COOKIES, std::string())); |
1166 } | 1127 } |
1167 | 1128 |
1168 TEST_F(HostContentSettingsMapTest, IsDefaultSettingAllowedForType) { | 1129 TEST_F(HostContentSettingsMapTest, IsDefaultSettingAllowedForType) { |
1169 EXPECT_FALSE(HostContentSettingsMap::IsDefaultSettingAllowedForType( | 1130 EXPECT_FALSE(HostContentSettingsMap::IsDefaultSettingAllowedForType( |
1170 CONTENT_SETTING_ALLOW, CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC)); | 1131 CONTENT_SETTING_ALLOW, CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC)); |
1171 EXPECT_FALSE(HostContentSettingsMap::IsDefaultSettingAllowedForType( | 1132 EXPECT_FALSE(HostContentSettingsMap::IsDefaultSettingAllowedForType( |
1172 CONTENT_SETTING_ALLOW, CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA)); | 1133 CONTENT_SETTING_ALLOW, CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA)); |
1173 } | 1134 } |
1174 | 1135 |
1175 TEST_F(HostContentSettingsMapTest, AddContentSettingsObserver) { | 1136 TEST_F(HostContentSettingsMapTest, AddContentSettingsObserver) { |
1176 TestingProfile profile; | 1137 TestingProfile profile; |
1177 HostContentSettingsMap* host_content_settings_map = | 1138 HostContentSettingsMap* host_content_settings_map = |
1178 HostContentSettingsMapFactory::GetForProfile(&profile); | 1139 HostContentSettingsMapFactory::GetForProfile(&profile); |
1179 content_settings::MockObserver mock_observer; | 1140 content_settings::MockObserver mock_observer; |
1180 | 1141 |
1181 GURL host("http://example.com/"); | 1142 GURL host("http://example.com/"); |
1182 ContentSettingsPattern pattern = | 1143 ContentSettingsPattern pattern = |
1183 ContentSettingsPattern::FromString("[*.]example.com"); | 1144 ContentSettingsPattern::FromString("[*.]example.com"); |
1184 EXPECT_CALL(mock_observer, | 1145 EXPECT_CALL(mock_observer, OnContentSettingChanged( |
1185 OnContentSettingChanged(pattern, | 1146 pattern, ContentSettingsPattern::Wildcard(), |
1186 ContentSettingsPattern::Wildcard(), | 1147 CONTENT_SETTINGS_TYPE_COOKIES, "")); |
1187 CONTENT_SETTINGS_TYPE_IMAGES, | |
1188 "")); | |
1189 | 1148 |
1190 host_content_settings_map->AddObserver(&mock_observer); | 1149 host_content_settings_map->AddObserver(&mock_observer); |
1191 | 1150 |
1192 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 1151 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
1193 host_content_settings_map->GetContentSetting( | 1152 host_content_settings_map->GetContentSetting( |
1194 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); | 1153 host, host, CONTENT_SETTINGS_TYPE_COOKIES, std::string())); |
1195 host_content_settings_map->SetContentSettingDefaultScope( | 1154 host_content_settings_map->SetContentSettingDefaultScope( |
1196 host, GURL(), CONTENT_SETTINGS_TYPE_IMAGES, std::string(), | 1155 host, GURL(), CONTENT_SETTINGS_TYPE_COOKIES, std::string(), |
1197 CONTENT_SETTING_DEFAULT); | 1156 CONTENT_SETTING_DEFAULT); |
1198 } | 1157 } |
1199 | 1158 |
1200 TEST_F(HostContentSettingsMapTest, GuestProfile) { | 1159 TEST_F(HostContentSettingsMapTest, GuestProfile) { |
1201 TestingProfile profile; | 1160 TestingProfile profile; |
1202 profile.SetGuestSession(true); | 1161 profile.SetGuestSession(true); |
1203 HostContentSettingsMap* host_content_settings_map = | 1162 HostContentSettingsMap* host_content_settings_map = |
1204 HostContentSettingsMapFactory::GetForProfile(&profile); | 1163 HostContentSettingsMapFactory::GetForProfile(&profile); |
1205 | 1164 |
1206 GURL host("http://example.com/"); | 1165 GURL host("http://example.com/"); |
1207 ContentSettingsPattern pattern = | 1166 ContentSettingsPattern pattern = |
1208 ContentSettingsPattern::FromString("[*.]example.com"); | 1167 ContentSettingsPattern::FromString("[*.]example.com"); |
1209 | 1168 |
1210 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 1169 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
1211 host_content_settings_map->GetContentSetting( | 1170 host_content_settings_map->GetContentSetting( |
1212 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); | 1171 host, host, CONTENT_SETTINGS_TYPE_COOKIES, std::string())); |
1213 | 1172 |
1214 // Changing content settings should not result in any prefs being stored | 1173 // Changing content settings should not result in any prefs being stored |
1215 // however the value should be set in memory. | 1174 // however the value should be set in memory. |
1216 host_content_settings_map->SetContentSettingDefaultScope( | 1175 host_content_settings_map->SetContentSettingDefaultScope( |
1217 host, GURL(), CONTENT_SETTINGS_TYPE_IMAGES, std::string(), | 1176 host, GURL(), CONTENT_SETTINGS_TYPE_COOKIES, std::string(), |
1218 CONTENT_SETTING_BLOCK); | 1177 CONTENT_SETTING_BLOCK); |
1219 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 1178 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
1220 host_content_settings_map->GetContentSetting( | 1179 host_content_settings_map->GetContentSetting( |
1221 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); | 1180 host, host, CONTENT_SETTINGS_TYPE_COOKIES, std::string())); |
1222 | 1181 |
1223 const base::DictionaryValue* all_settings_dictionary = | 1182 const base::DictionaryValue* all_settings_dictionary = |
1224 profile.GetPrefs()->GetDictionary( | 1183 profile.GetPrefs()->GetDictionary( |
1225 GetPrefName(CONTENT_SETTINGS_TYPE_IMAGES)); | 1184 GetPrefName(CONTENT_SETTINGS_TYPE_COOKIES)); |
1226 EXPECT_TRUE(all_settings_dictionary->empty()); | 1185 EXPECT_TRUE(all_settings_dictionary->empty()); |
1227 } | 1186 } |
1228 | 1187 |
1229 // Default settings should not be modifiable for the guest profile (there is no | 1188 // Default settings should not be modifiable for the guest profile (there is no |
1230 // UI to do this). | 1189 // UI to do this). |
1231 TEST_F(HostContentSettingsMapTest, GuestProfileDefaultSetting) { | 1190 TEST_F(HostContentSettingsMapTest, GuestProfileDefaultSetting) { |
1232 TestingProfile profile; | 1191 TestingProfile profile; |
1233 profile.SetGuestSession(true); | 1192 profile.SetGuestSession(true); |
1234 HostContentSettingsMap* host_content_settings_map = | 1193 HostContentSettingsMap* host_content_settings_map = |
1235 HostContentSettingsMapFactory::GetForProfile(&profile); | 1194 HostContentSettingsMapFactory::GetForProfile(&profile); |
1236 | 1195 |
1237 GURL host("http://example.com/"); | 1196 GURL host("http://example.com/"); |
1238 | 1197 |
1239 // There are no custom rules, so this should be the default. | 1198 // There are no custom rules, so this should be the default. |
1240 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 1199 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
1241 host_content_settings_map->GetContentSetting( | 1200 host_content_settings_map->GetContentSetting( |
1242 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); | 1201 host, host, CONTENT_SETTINGS_TYPE_COOKIES, std::string())); |
1243 | 1202 |
1244 host_content_settings_map->SetDefaultContentSetting( | 1203 host_content_settings_map->SetDefaultContentSetting( |
1245 CONTENT_SETTINGS_TYPE_IMAGES, CONTENT_SETTING_BLOCK); | 1204 CONTENT_SETTINGS_TYPE_COOKIES, CONTENT_SETTING_BLOCK); |
1246 | 1205 |
1247 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 1206 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
1248 host_content_settings_map->GetContentSetting( | 1207 host_content_settings_map->GetContentSetting( |
1249 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); | 1208 host, host, CONTENT_SETTINGS_TYPE_COOKIES, std::string())); |
1250 } | 1209 } |
1251 | 1210 |
1252 // We used to incorrectly store content settings in prefs for the guest profile. | 1211 // We used to incorrectly store content settings in prefs for the guest profile. |
1253 // We need to ensure these get deleted appropriately. | 1212 // We need to ensure these get deleted appropriately. |
1254 TEST_F(HostContentSettingsMapTest, GuestProfileMigration) { | 1213 TEST_F(HostContentSettingsMapTest, GuestProfileMigration) { |
1255 TestingProfile profile; | 1214 TestingProfile profile; |
1256 profile.SetGuestSession(true); | 1215 profile.SetGuestSession(true); |
1257 | 1216 |
1258 // Set a pref manually in the guest profile. | 1217 // Set a pref manually in the guest profile. |
1259 std::unique_ptr<base::Value> value = | 1218 std::unique_ptr<base::Value> value = |
1260 base::JSONReader::Read("{\"[*.]\\xC4\\x87ira.com,*\":{\"setting\":1}}"); | 1219 base::JSONReader::Read("{\"[*.]\\xC4\\x87ira.com,*\":{\"setting\":1}}"); |
1261 profile.GetPrefs()->Set(GetPrefName(CONTENT_SETTINGS_TYPE_IMAGES), *value); | 1220 profile.GetPrefs()->Set(GetPrefName(CONTENT_SETTINGS_TYPE_COOKIES), *value); |
1262 | 1221 |
1263 // Test that during construction all the prefs get cleared. | 1222 // Test that during construction all the prefs get cleared. |
1264 HostContentSettingsMapFactory::GetForProfile(&profile); | 1223 HostContentSettingsMapFactory::GetForProfile(&profile); |
1265 | 1224 |
1266 const base::DictionaryValue* all_settings_dictionary = | 1225 const base::DictionaryValue* all_settings_dictionary = |
1267 profile.GetPrefs()->GetDictionary( | 1226 profile.GetPrefs()->GetDictionary( |
1268 GetPrefName(CONTENT_SETTINGS_TYPE_IMAGES)); | 1227 GetPrefName(CONTENT_SETTINGS_TYPE_COOKIES)); |
1269 EXPECT_TRUE(all_settings_dictionary->empty()); | 1228 EXPECT_TRUE(all_settings_dictionary->empty()); |
1270 } | 1229 } |
1271 | 1230 |
1272 TEST_F(HostContentSettingsMapTest, MigrateKeygenSettings) { | 1231 TEST_F(HostContentSettingsMapTest, MigrateKeygenSettings) { |
1273 TestingProfile profile; | 1232 TestingProfile profile; |
1274 HostContentSettingsMap* host_content_settings_map = | 1233 HostContentSettingsMap* host_content_settings_map = |
1275 HostContentSettingsMapFactory::GetForProfile(&profile); | 1234 HostContentSettingsMapFactory::GetForProfile(&profile); |
1276 | 1235 |
1277 // Set old formatted settings. | 1236 // Set old formatted settings. |
1278 GURL host("http://example.com/"); | 1237 GURL host("http://example.com/"); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1330 base::DictionaryValue test_value; | 1289 base::DictionaryValue test_value; |
1331 test_value.SetString("test", "value"); | 1290 test_value.SetString("test", "value"); |
1332 host_content_settings_map->SetWebsiteSettingDefaultScope( | 1291 host_content_settings_map->SetWebsiteSettingDefaultScope( |
1333 unsupported_url, unsupported_url, CONTENT_SETTINGS_TYPE_APP_BANNER, | 1292 unsupported_url, unsupported_url, CONTENT_SETTINGS_TYPE_APP_BANNER, |
1334 std::string(), base::WrapUnique(test_value.DeepCopy())); | 1293 std::string(), base::WrapUnique(test_value.DeepCopy())); |
1335 EXPECT_EQ(nullptr, | 1294 EXPECT_EQ(nullptr, |
1336 host_content_settings_map->GetWebsiteSetting( | 1295 host_content_settings_map->GetWebsiteSetting( |
1337 unsupported_url, unsupported_url, | 1296 unsupported_url, unsupported_url, |
1338 CONTENT_SETTINGS_TYPE_APP_BANNER, std::string(), nullptr)); | 1297 CONTENT_SETTINGS_TYPE_APP_BANNER, std::string(), nullptr)); |
1339 } | 1298 } |
OLD | NEW |