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