Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(302)

Side by Side Diff: chrome/browser/content_settings/host_content_settings_map_unittest.cc

Issue 1686343002: Change HostContentSettingsMap::SetContentSetting to use GURLs instead of patterns (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add migrate method Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "base/auto_reset.h" 5 #include "base/auto_reset.h"
6 #include "base/command_line.h" 6 #include "base/command_line.h"
7 #include "base/json/json_reader.h" 7 #include "base/json/json_reader.h"
8 #include "base/json/json_writer.h" 8 #include "base/json/json_writer.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "chrome/browser/content_settings/content_settings_mock_observer.h" 10 #include "chrome/browser/content_settings/content_settings_mock_observer.h"
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 HostContentSettingsMap* host_content_settings_map = 100 HostContentSettingsMap* host_content_settings_map =
101 HostContentSettingsMapFactory::GetForProfile(&profile); 101 HostContentSettingsMapFactory::GetForProfile(&profile);
102 102
103 // Check returning individual settings. 103 // Check returning individual settings.
104 GURL host("http://example.com/"); 104 GURL host("http://example.com/");
105 ContentSettingsPattern pattern = 105 ContentSettingsPattern pattern =
106 ContentSettingsPattern::FromString("[*.]example.com"); 106 ContentSettingsPattern::FromString("[*.]example.com");
107 EXPECT_EQ(CONTENT_SETTING_ALLOW, 107 EXPECT_EQ(CONTENT_SETTING_ALLOW,
108 host_content_settings_map->GetContentSetting( 108 host_content_settings_map->GetContentSetting(
109 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); 109 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
110 host_content_settings_map->SetContentSetting( 110 host_content_settings_map->SetContentSettingCustomScope(
raymes 2016/03/01 06:17:31 Can we use the default scope in some of these case
lshang 2016/03/02 04:02:28 Done.
111 pattern, 111 pattern, ContentSettingsPattern::Wildcard(), CONTENT_SETTINGS_TYPE_IMAGES,
112 ContentSettingsPattern::Wildcard(), 112 std::string(), CONTENT_SETTING_DEFAULT);
113 CONTENT_SETTINGS_TYPE_IMAGES,
114 std::string(),
115 CONTENT_SETTING_DEFAULT);
116 EXPECT_EQ(CONTENT_SETTING_ALLOW, 113 EXPECT_EQ(CONTENT_SETTING_ALLOW,
117 host_content_settings_map->GetContentSetting( 114 host_content_settings_map->GetContentSetting(
118 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); 115 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
119 host_content_settings_map->SetContentSetting( 116 host_content_settings_map->SetContentSettingCustomScope(
120 pattern, 117 pattern, ContentSettingsPattern::Wildcard(), CONTENT_SETTINGS_TYPE_IMAGES,
121 ContentSettingsPattern::Wildcard(), 118 std::string(), CONTENT_SETTING_BLOCK);
122 CONTENT_SETTINGS_TYPE_IMAGES,
123 std::string(),
124 CONTENT_SETTING_BLOCK);
125 EXPECT_EQ(CONTENT_SETTING_BLOCK, 119 EXPECT_EQ(CONTENT_SETTING_BLOCK,
126 host_content_settings_map->GetContentSetting( 120 host_content_settings_map->GetContentSetting(
127 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); 121 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
128 #if defined(ENABLE_PLUGINS) 122 #if defined(ENABLE_PLUGINS)
129 EXPECT_EQ(CONTENT_SETTING_DETECT_IMPORTANT_CONTENT, 123 EXPECT_EQ(CONTENT_SETTING_DETECT_IMPORTANT_CONTENT,
130 host_content_settings_map->GetContentSetting( 124 host_content_settings_map->GetContentSetting(
131 host, host, CONTENT_SETTINGS_TYPE_PLUGINS, std::string())); 125 host, host, CONTENT_SETTINGS_TYPE_PLUGINS, std::string()));
132 #endif 126 #endif
133 127
134 // Check returning all settings for a host. 128 // Check returning all settings for a host.
135 host_content_settings_map->SetContentSetting( 129 host_content_settings_map->SetContentSettingCustomScope(
136 pattern, 130 pattern, ContentSettingsPattern::Wildcard(), CONTENT_SETTINGS_TYPE_IMAGES,
137 ContentSettingsPattern::Wildcard(), 131 std::string(), CONTENT_SETTING_DEFAULT);
138 CONTENT_SETTINGS_TYPE_IMAGES,
139 std::string(),
140 CONTENT_SETTING_DEFAULT);
141 EXPECT_EQ(CONTENT_SETTING_ALLOW, 132 EXPECT_EQ(CONTENT_SETTING_ALLOW,
142 host_content_settings_map->GetContentSetting( 133 host_content_settings_map->GetContentSetting(
143 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); 134 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
144 host_content_settings_map->SetContentSetting( 135 host_content_settings_map->SetContentSettingCustomScope(
145 pattern, 136 pattern, ContentSettingsPattern::Wildcard(),
146 ContentSettingsPattern::Wildcard(), 137 CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string(), CONTENT_SETTING_BLOCK);
147 CONTENT_SETTINGS_TYPE_JAVASCRIPT,
148 std::string(),
149 CONTENT_SETTING_BLOCK);
150 EXPECT_EQ(CONTENT_SETTING_BLOCK, 138 EXPECT_EQ(CONTENT_SETTING_BLOCK,
151 host_content_settings_map->GetContentSetting( 139 host_content_settings_map->GetContentSetting(
152 host, host, CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string())); 140 host, host, CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string()));
153 #if defined(ENABLE_PLUGINS) 141 #if defined(ENABLE_PLUGINS)
154 host_content_settings_map->SetContentSetting( 142 host_content_settings_map->SetContentSettingCustomScope(
155 pattern, 143 pattern, ContentSettingsPattern::Wildcard(),
156 ContentSettingsPattern::Wildcard(), 144 CONTENT_SETTINGS_TYPE_PLUGINS, std::string(), CONTENT_SETTING_ALLOW);
157 CONTENT_SETTINGS_TYPE_PLUGINS,
158 std::string(),
159 CONTENT_SETTING_ALLOW);
160 EXPECT_EQ(CONTENT_SETTING_ALLOW, 145 EXPECT_EQ(CONTENT_SETTING_ALLOW,
161 host_content_settings_map->GetContentSetting( 146 host_content_settings_map->GetContentSetting(
162 host, host, CONTENT_SETTINGS_TYPE_PLUGINS, std::string())); 147 host, host, CONTENT_SETTINGS_TYPE_PLUGINS, std::string()));
163 #endif 148 #endif
164 EXPECT_EQ(CONTENT_SETTING_BLOCK, 149 EXPECT_EQ(CONTENT_SETTING_BLOCK,
165 host_content_settings_map->GetContentSetting( 150 host_content_settings_map->GetContentSetting(
166 host, host, CONTENT_SETTINGS_TYPE_POPUPS, std::string())); 151 host, host, CONTENT_SETTINGS_TYPE_POPUPS, std::string()));
167 EXPECT_EQ(CONTENT_SETTING_ASK, 152 EXPECT_EQ(CONTENT_SETTING_ASK,
168 host_content_settings_map->GetContentSetting( 153 host_content_settings_map->GetContentSetting(
169 host, host, CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); 154 host, host, CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string()));
170 EXPECT_EQ( 155 EXPECT_EQ(
171 CONTENT_SETTING_ASK, 156 CONTENT_SETTING_ASK,
172 host_content_settings_map->GetContentSetting( 157 host_content_settings_map->GetContentSetting(
173 host, host, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string())); 158 host, host, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string()));
174 EXPECT_EQ(CONTENT_SETTING_ASK, 159 EXPECT_EQ(CONTENT_SETTING_ASK,
175 host_content_settings_map->GetContentSetting( 160 host_content_settings_map->GetContentSetting(
176 host, host, CONTENT_SETTINGS_TYPE_FULLSCREEN, std::string())); 161 host, host, CONTENT_SETTINGS_TYPE_FULLSCREEN, std::string()));
177 EXPECT_EQ(CONTENT_SETTING_ASK, 162 EXPECT_EQ(CONTENT_SETTING_ASK,
178 host_content_settings_map->GetContentSetting( 163 host_content_settings_map->GetContentSetting(
179 host, host, CONTENT_SETTINGS_TYPE_MOUSELOCK, std::string())); 164 host, host, CONTENT_SETTINGS_TYPE_MOUSELOCK, std::string()));
180 host_content_settings_map->SetContentSetting( 165 host_content_settings_map->SetContentSettingCustomScope(
181 pattern, ContentSettingsPattern::Wildcard(), CONTENT_SETTINGS_TYPE_KEYGEN, 166 pattern, ContentSettingsPattern::Wildcard(), CONTENT_SETTINGS_TYPE_KEYGEN,
182 std::string(), CONTENT_SETTING_ALLOW); 167 std::string(), CONTENT_SETTING_ALLOW);
183 EXPECT_EQ(CONTENT_SETTING_ALLOW, 168 EXPECT_EQ(CONTENT_SETTING_ALLOW,
184 host_content_settings_map->GetContentSetting( 169 host_content_settings_map->GetContentSetting(
185 host, host, CONTENT_SETTINGS_TYPE_KEYGEN, std::string())); 170 host, host, CONTENT_SETTINGS_TYPE_KEYGEN, std::string()));
186 171
187 // Check returning all hosts for a setting. 172 // Check returning all hosts for a setting.
188 ContentSettingsPattern pattern2 = 173 ContentSettingsPattern pattern2 =
189 ContentSettingsPattern::FromString("[*.]example.org"); 174 ContentSettingsPattern::FromString("[*.]example.org");
190 host_content_settings_map->SetContentSetting( 175 host_content_settings_map->SetContentSettingCustomScope(
191 pattern2, 176 pattern2, ContentSettingsPattern::Wildcard(),
192 ContentSettingsPattern::Wildcard(), 177 CONTENT_SETTINGS_TYPE_IMAGES, std::string(), CONTENT_SETTING_BLOCK);
193 CONTENT_SETTINGS_TYPE_IMAGES,
194 std::string(),
195 CONTENT_SETTING_BLOCK);
196 #if defined(ENABLE_PLUGINS) 178 #if defined(ENABLE_PLUGINS)
197 host_content_settings_map->SetContentSetting( 179 host_content_settings_map->SetContentSettingCustomScope(
198 pattern2, 180 pattern2, ContentSettingsPattern::Wildcard(),
199 ContentSettingsPattern::Wildcard(), 181 CONTENT_SETTINGS_TYPE_PLUGINS, std::string(), CONTENT_SETTING_BLOCK);
200 CONTENT_SETTINGS_TYPE_PLUGINS,
201 std::string(),
202 CONTENT_SETTING_BLOCK);
203 #endif 182 #endif
204 ContentSettingsForOneType host_settings; 183 ContentSettingsForOneType host_settings;
205 host_content_settings_map->GetSettingsForOneType( 184 host_content_settings_map->GetSettingsForOneType(
206 CONTENT_SETTINGS_TYPE_IMAGES, std::string(), &host_settings); 185 CONTENT_SETTINGS_TYPE_IMAGES, std::string(), &host_settings);
207 // |host_settings| contains the default setting and an exception. 186 // |host_settings| contains the default setting and an exception.
208 EXPECT_EQ(2U, host_settings.size()); 187 EXPECT_EQ(2U, host_settings.size());
209 #if defined(ENABLE_PLUGINS) 188 #if defined(ENABLE_PLUGINS)
210 host_content_settings_map->GetSettingsForOneType( 189 host_content_settings_map->GetSettingsForOneType(
211 CONTENT_SETTINGS_TYPE_PLUGINS, std::string(), &host_settings); 190 CONTENT_SETTINGS_TYPE_PLUGINS, std::string(), &host_settings);
212 // |host_settings| contains the default setting and 2 exceptions. 191 // |host_settings| contains the default setting and 2 exceptions.
213 EXPECT_EQ(3U, host_settings.size()); 192 EXPECT_EQ(3U, host_settings.size());
214 #endif 193 #endif
215 host_content_settings_map->GetSettingsForOneType( 194 host_content_settings_map->GetSettingsForOneType(
216 CONTENT_SETTINGS_TYPE_POPUPS, std::string(), &host_settings); 195 CONTENT_SETTINGS_TYPE_POPUPS, std::string(), &host_settings);
217 // |host_settings| contains only the default setting. 196 // |host_settings| contains only the default setting.
218 EXPECT_EQ(1U, host_settings.size()); 197 EXPECT_EQ(1U, host_settings.size());
219 } 198 }
220 199
221 TEST_F(HostContentSettingsMapTest, Clear) { 200 TEST_F(HostContentSettingsMapTest, Clear) {
222 TestingProfile profile; 201 TestingProfile profile;
223 HostContentSettingsMap* host_content_settings_map = 202 HostContentSettingsMap* host_content_settings_map =
224 HostContentSettingsMapFactory::GetForProfile(&profile); 203 HostContentSettingsMapFactory::GetForProfile(&profile);
225 204
226 // Check clearing one type. 205 // Check clearing one type.
227 ContentSettingsPattern pattern = 206 ContentSettingsPattern pattern =
228 ContentSettingsPattern::FromString("[*.]example.org"); 207 ContentSettingsPattern::FromString("[*.]example.org");
229 ContentSettingsPattern pattern2 = 208 ContentSettingsPattern pattern2 =
230 ContentSettingsPattern::FromString("[*.]example.net"); 209 ContentSettingsPattern::FromString("[*.]example.net");
231 host_content_settings_map->SetContentSetting( 210 host_content_settings_map->SetContentSettingCustomScope(
232 pattern2, 211 pattern2, ContentSettingsPattern::Wildcard(),
233 ContentSettingsPattern::Wildcard(), 212 CONTENT_SETTINGS_TYPE_IMAGES, std::string(), CONTENT_SETTING_BLOCK);
234 CONTENT_SETTINGS_TYPE_IMAGES, 213 host_content_settings_map->SetContentSettingCustomScope(
235 std::string(), 214 pattern, ContentSettingsPattern::Wildcard(), CONTENT_SETTINGS_TYPE_IMAGES,
236 CONTENT_SETTING_BLOCK); 215 std::string(), CONTENT_SETTING_BLOCK);
237 host_content_settings_map->SetContentSetting(
238 pattern,
239 ContentSettingsPattern::Wildcard(),
240 CONTENT_SETTINGS_TYPE_IMAGES,
241 std::string(),
242 CONTENT_SETTING_BLOCK);
243 #if defined(ENABLE_PLUGINS) 216 #if defined(ENABLE_PLUGINS)
244 host_content_settings_map->SetContentSetting( 217 host_content_settings_map->SetContentSettingCustomScope(
245 pattern, 218 pattern, ContentSettingsPattern::Wildcard(),
246 ContentSettingsPattern::Wildcard(), 219 CONTENT_SETTINGS_TYPE_PLUGINS, std::string(), CONTENT_SETTING_BLOCK);
247 CONTENT_SETTINGS_TYPE_PLUGINS,
248 std::string(),
249 CONTENT_SETTING_BLOCK);
250 #endif 220 #endif
251 host_content_settings_map->SetContentSetting( 221 host_content_settings_map->SetContentSettingCustomScope(
252 pattern2, 222 pattern2, ContentSettingsPattern::Wildcard(),
253 ContentSettingsPattern::Wildcard(), 223 CONTENT_SETTINGS_TYPE_IMAGES, std::string(), CONTENT_SETTING_BLOCK);
254 CONTENT_SETTINGS_TYPE_IMAGES,
255 std::string(),
256 CONTENT_SETTING_BLOCK);
257 host_content_settings_map->ClearSettingsForOneType( 224 host_content_settings_map->ClearSettingsForOneType(
258 CONTENT_SETTINGS_TYPE_IMAGES); 225 CONTENT_SETTINGS_TYPE_IMAGES);
259 ContentSettingsForOneType host_settings; 226 ContentSettingsForOneType host_settings;
260 host_content_settings_map->GetSettingsForOneType( 227 host_content_settings_map->GetSettingsForOneType(
261 CONTENT_SETTINGS_TYPE_IMAGES, std::string(), &host_settings); 228 CONTENT_SETTINGS_TYPE_IMAGES, std::string(), &host_settings);
262 // |host_settings| contains only the default setting. 229 // |host_settings| contains only the default setting.
263 EXPECT_EQ(1U, host_settings.size()); 230 EXPECT_EQ(1U, host_settings.size());
264 #if defined(ENABLE_PLUGINS) 231 #if defined(ENABLE_PLUGINS)
265 host_content_settings_map->GetSettingsForOneType( 232 host_content_settings_map->GetSettingsForOneType(
266 CONTENT_SETTINGS_TYPE_PLUGINS, std::string(), &host_settings); 233 CONTENT_SETTINGS_TYPE_PLUGINS, std::string(), &host_settings);
(...skipping 10 matching lines...) Expand all
277 GURL host1("http://example.com/"); 244 GURL host1("http://example.com/");
278 GURL host2("http://www.example.com/"); 245 GURL host2("http://www.example.com/");
279 GURL host3("http://example.org/"); 246 GURL host3("http://example.org/");
280 ContentSettingsPattern pattern1 = 247 ContentSettingsPattern pattern1 =
281 ContentSettingsPattern::FromString("[*.]example.com"); 248 ContentSettingsPattern::FromString("[*.]example.com");
282 ContentSettingsPattern pattern2 = 249 ContentSettingsPattern pattern2 =
283 ContentSettingsPattern::FromString("example.org"); 250 ContentSettingsPattern::FromString("example.org");
284 EXPECT_EQ(CONTENT_SETTING_ALLOW, 251 EXPECT_EQ(CONTENT_SETTING_ALLOW,
285 host_content_settings_map->GetContentSetting( 252 host_content_settings_map->GetContentSetting(
286 host1, host1, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); 253 host1, host1, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
287 host_content_settings_map->SetContentSetting( 254 host_content_settings_map->SetContentSettingCustomScope(
288 pattern1, 255 pattern1, ContentSettingsPattern::Wildcard(),
289 ContentSettingsPattern::Wildcard(), 256 CONTENT_SETTINGS_TYPE_IMAGES, std::string(), CONTENT_SETTING_BLOCK);
290 CONTENT_SETTINGS_TYPE_IMAGES,
291 std::string(),
292 CONTENT_SETTING_BLOCK);
293 EXPECT_EQ(CONTENT_SETTING_BLOCK, 257 EXPECT_EQ(CONTENT_SETTING_BLOCK,
294 host_content_settings_map->GetContentSetting( 258 host_content_settings_map->GetContentSetting(
295 host1, host1, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); 259 host1, host1, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
296 EXPECT_EQ(CONTENT_SETTING_BLOCK, 260 EXPECT_EQ(CONTENT_SETTING_BLOCK,
297 host_content_settings_map->GetContentSetting( 261 host_content_settings_map->GetContentSetting(
298 host2, host2, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); 262 host2, host2, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
299 EXPECT_EQ(CONTENT_SETTING_ALLOW, 263 EXPECT_EQ(CONTENT_SETTING_ALLOW,
300 host_content_settings_map->GetContentSetting( 264 host_content_settings_map->GetContentSetting(
301 host3, host3, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); 265 host3, host3, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
302 host_content_settings_map->SetContentSetting( 266 host_content_settings_map->SetContentSettingCustomScope(
303 pattern2, 267 pattern2, ContentSettingsPattern::Wildcard(),
304 ContentSettingsPattern::Wildcard(), 268 CONTENT_SETTINGS_TYPE_IMAGES, std::string(), CONTENT_SETTING_BLOCK);
305 CONTENT_SETTINGS_TYPE_IMAGES,
306 std::string(),
307 CONTENT_SETTING_BLOCK);
308 EXPECT_EQ(CONTENT_SETTING_BLOCK, 269 EXPECT_EQ(CONTENT_SETTING_BLOCK,
309 host_content_settings_map->GetContentSetting( 270 host_content_settings_map->GetContentSetting(
310 host3, host3, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); 271 host3, host3, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
311 } 272 }
312 273
313 TEST_F(HostContentSettingsMapTest, Observer) { 274 TEST_F(HostContentSettingsMapTest, Observer) {
314 TestingProfile profile; 275 TestingProfile profile;
315 HostContentSettingsMap* host_content_settings_map = 276 HostContentSettingsMap* host_content_settings_map =
316 HostContentSettingsMapFactory::GetForProfile(&profile); 277 HostContentSettingsMapFactory::GetForProfile(&profile);
317 MockSettingsObserver observer(host_content_settings_map); 278 MockSettingsObserver observer(host_content_settings_map);
318 279
319 ContentSettingsPattern primary_pattern = 280 ContentSettingsPattern primary_pattern =
320 ContentSettingsPattern::FromString("[*.]example.com"); 281 ContentSettingsPattern::FromString("[*.]example.com");
321 ContentSettingsPattern secondary_pattern = 282 ContentSettingsPattern secondary_pattern =
322 ContentSettingsPattern::Wildcard(); 283 ContentSettingsPattern::Wildcard();
323 EXPECT_CALL(observer, 284 EXPECT_CALL(observer,
324 OnContentSettingsChanged(host_content_settings_map, 285 OnContentSettingsChanged(host_content_settings_map,
325 CONTENT_SETTINGS_TYPE_IMAGES, 286 CONTENT_SETTINGS_TYPE_IMAGES,
326 false, 287 false,
327 primary_pattern, 288 primary_pattern,
328 secondary_pattern, 289 secondary_pattern,
329 false)); 290 false));
330 host_content_settings_map->SetContentSetting( 291 host_content_settings_map->SetContentSettingCustomScope(
331 primary_pattern, 292 primary_pattern, secondary_pattern, CONTENT_SETTINGS_TYPE_IMAGES,
332 secondary_pattern, 293 std::string(), CONTENT_SETTING_ALLOW);
333 CONTENT_SETTINGS_TYPE_IMAGES,
334 std::string(),
335 CONTENT_SETTING_ALLOW);
336 ::testing::Mock::VerifyAndClearExpectations(&observer); 294 ::testing::Mock::VerifyAndClearExpectations(&observer);
337 295
338 EXPECT_CALL(observer, 296 EXPECT_CALL(observer,
339 OnContentSettingsChanged(host_content_settings_map, 297 OnContentSettingsChanged(host_content_settings_map,
340 CONTENT_SETTINGS_TYPE_IMAGES, false, 298 CONTENT_SETTINGS_TYPE_IMAGES, false,
341 _, _, true)); 299 _, _, true));
342 host_content_settings_map->ClearSettingsForOneType( 300 host_content_settings_map->ClearSettingsForOneType(
343 CONTENT_SETTINGS_TYPE_IMAGES); 301 CONTENT_SETTINGS_TYPE_IMAGES);
344 ::testing::Mock::VerifyAndClearExpectations(&observer); 302 ::testing::Mock::VerifyAndClearExpectations(&observer);
345 303
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
395 ->DeepCopy()); 353 ->DeepCopy());
396 354
397 ContentSettingsPattern pattern = 355 ContentSettingsPattern pattern =
398 ContentSettingsPattern::FromString("[*.]example.com"); 356 ContentSettingsPattern::FromString("[*.]example.com");
399 GURL host("http://example.com"); 357 GURL host("http://example.com");
400 358
401 EXPECT_EQ(CONTENT_SETTING_ALLOW, 359 EXPECT_EQ(CONTENT_SETTING_ALLOW,
402 host_content_settings_map->GetContentSetting( 360 host_content_settings_map->GetContentSetting(
403 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); 361 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
404 362
405 host_content_settings_map->SetContentSetting( 363 host_content_settings_map->SetContentSettingCustomScope(
406 pattern, 364 pattern, ContentSettingsPattern::Wildcard(), CONTENT_SETTINGS_TYPE_IMAGES,
407 ContentSettingsPattern::Wildcard(), 365 std::string(), CONTENT_SETTING_BLOCK);
408 CONTENT_SETTINGS_TYPE_IMAGES,
409 std::string(),
410 CONTENT_SETTING_BLOCK);
411 EXPECT_EQ(CONTENT_SETTING_BLOCK, 366 EXPECT_EQ(CONTENT_SETTING_BLOCK,
412 host_content_settings_map->GetContentSetting( 367 host_content_settings_map->GetContentSetting(
413 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); 368 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
414 369
415 // Make a copy of the pref's new value so we can reset it later. 370 // Make a copy of the pref's new value so we can reset it later.
416 scoped_ptr<base::Value> new_value( 371 scoped_ptr<base::Value> new_value(
417 prefs->FindPreference(GetPrefName(CONTENT_SETTINGS_TYPE_IMAGES)) 372 prefs->FindPreference(GetPrefName(CONTENT_SETTINGS_TYPE_IMAGES))
418 ->GetValue() 373 ->GetValue()
419 ->DeepCopy()); 374 ->DeepCopy());
420 375
(...skipping 20 matching lines...) Expand all
441 ContentSettingsPattern pattern = 396 ContentSettingsPattern pattern =
442 ContentSettingsPattern::FromString("[*.]example.com"); 397 ContentSettingsPattern::FromString("[*.]example.com");
443 GURL host_ending_with_dot("http://example.com./"); 398 GURL host_ending_with_dot("http://example.com./");
444 399
445 EXPECT_EQ(CONTENT_SETTING_ALLOW, 400 EXPECT_EQ(CONTENT_SETTING_ALLOW,
446 host_content_settings_map->GetContentSetting( 401 host_content_settings_map->GetContentSetting(
447 host_ending_with_dot, 402 host_ending_with_dot,
448 host_ending_with_dot, 403 host_ending_with_dot,
449 CONTENT_SETTINGS_TYPE_IMAGES, 404 CONTENT_SETTINGS_TYPE_IMAGES,
450 std::string())); 405 std::string()));
451 host_content_settings_map->SetContentSetting( 406 host_content_settings_map->SetContentSettingCustomScope(
452 pattern, 407 pattern, ContentSettingsPattern::Wildcard(), CONTENT_SETTINGS_TYPE_IMAGES,
453 ContentSettingsPattern::Wildcard(), 408 std::string(), CONTENT_SETTING_DEFAULT);
454 CONTENT_SETTINGS_TYPE_IMAGES,
455 std::string(),
456 CONTENT_SETTING_DEFAULT);
457 EXPECT_EQ( 409 EXPECT_EQ(
458 CONTENT_SETTING_ALLOW, 410 CONTENT_SETTING_ALLOW,
459 host_content_settings_map->GetContentSetting(host_ending_with_dot, 411 host_content_settings_map->GetContentSetting(host_ending_with_dot,
460 host_ending_with_dot, 412 host_ending_with_dot,
461 CONTENT_SETTINGS_TYPE_IMAGES, 413 CONTENT_SETTINGS_TYPE_IMAGES,
462 std::string())); 414 std::string()));
463 host_content_settings_map->SetContentSetting( 415 host_content_settings_map->SetContentSettingCustomScope(
464 pattern, 416 pattern, ContentSettingsPattern::Wildcard(), CONTENT_SETTINGS_TYPE_IMAGES,
465 ContentSettingsPattern::Wildcard(), 417 std::string(), CONTENT_SETTING_BLOCK);
466 CONTENT_SETTINGS_TYPE_IMAGES,
467 std::string(),
468 CONTENT_SETTING_BLOCK);
469 EXPECT_EQ( 418 EXPECT_EQ(
470 CONTENT_SETTING_BLOCK, 419 CONTENT_SETTING_BLOCK,
471 host_content_settings_map->GetContentSetting(host_ending_with_dot, 420 host_content_settings_map->GetContentSetting(host_ending_with_dot,
472 host_ending_with_dot, 421 host_ending_with_dot,
473 CONTENT_SETTINGS_TYPE_IMAGES, 422 CONTENT_SETTINGS_TYPE_IMAGES,
474 std::string())); 423 std::string()));
475 424
476 EXPECT_TRUE(cookie_settings->IsSettingCookieAllowed( 425 EXPECT_TRUE(cookie_settings->IsSettingCookieAllowed(
477 host_ending_with_dot, host_ending_with_dot)); 426 host_ending_with_dot, host_ending_with_dot));
478 host_content_settings_map->SetContentSetting( 427 host_content_settings_map->SetContentSettingCustomScope(
479 pattern, 428 pattern, ContentSettingsPattern::Wildcard(),
480 ContentSettingsPattern::Wildcard(), 429 CONTENT_SETTINGS_TYPE_COOKIES, std::string(), CONTENT_SETTING_DEFAULT);
481 CONTENT_SETTINGS_TYPE_COOKIES,
482 std::string(),
483 CONTENT_SETTING_DEFAULT);
484 EXPECT_TRUE(cookie_settings->IsSettingCookieAllowed( 430 EXPECT_TRUE(cookie_settings->IsSettingCookieAllowed(
485 host_ending_with_dot, host_ending_with_dot)); 431 host_ending_with_dot, host_ending_with_dot));
486 host_content_settings_map->SetContentSetting( 432 host_content_settings_map->SetContentSettingCustomScope(
487 pattern, 433 pattern, ContentSettingsPattern::Wildcard(),
488 ContentSettingsPattern::Wildcard(), 434 CONTENT_SETTINGS_TYPE_COOKIES, std::string(), CONTENT_SETTING_BLOCK);
489 CONTENT_SETTINGS_TYPE_COOKIES,
490 std::string(),
491 CONTENT_SETTING_BLOCK);
492 EXPECT_FALSE(cookie_settings->IsSettingCookieAllowed( 435 EXPECT_FALSE(cookie_settings->IsSettingCookieAllowed(
493 host_ending_with_dot, host_ending_with_dot)); 436 host_ending_with_dot, host_ending_with_dot));
494 437
495 EXPECT_EQ(CONTENT_SETTING_ALLOW, 438 EXPECT_EQ(CONTENT_SETTING_ALLOW,
496 host_content_settings_map->GetContentSetting( 439 host_content_settings_map->GetContentSetting(
497 host_ending_with_dot, 440 host_ending_with_dot,
498 host_ending_with_dot, 441 host_ending_with_dot,
499 CONTENT_SETTINGS_TYPE_JAVASCRIPT, 442 CONTENT_SETTINGS_TYPE_JAVASCRIPT,
500 std::string())); 443 std::string()));
501 host_content_settings_map->SetContentSetting( 444 host_content_settings_map->SetContentSettingCustomScope(
502 pattern, 445 pattern, ContentSettingsPattern::Wildcard(),
503 ContentSettingsPattern::Wildcard(), 446 CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string(), CONTENT_SETTING_DEFAULT);
504 CONTENT_SETTINGS_TYPE_JAVASCRIPT,
505 std::string(),
506 CONTENT_SETTING_DEFAULT);
507 EXPECT_EQ(CONTENT_SETTING_ALLOW, 447 EXPECT_EQ(CONTENT_SETTING_ALLOW,
508 host_content_settings_map->GetContentSetting( 448 host_content_settings_map->GetContentSetting(
509 host_ending_with_dot, 449 host_ending_with_dot,
510 host_ending_with_dot, 450 host_ending_with_dot,
511 CONTENT_SETTINGS_TYPE_JAVASCRIPT, 451 CONTENT_SETTINGS_TYPE_JAVASCRIPT,
512 std::string())); 452 std::string()));
513 host_content_settings_map->SetContentSetting( 453 host_content_settings_map->SetContentSettingCustomScope(
514 pattern, 454 pattern, ContentSettingsPattern::Wildcard(),
515 ContentSettingsPattern::Wildcard(), 455 CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string(), CONTENT_SETTING_BLOCK);
516 CONTENT_SETTINGS_TYPE_JAVASCRIPT,
517 std::string(),
518 CONTENT_SETTING_BLOCK);
519 EXPECT_EQ(CONTENT_SETTING_BLOCK, 456 EXPECT_EQ(CONTENT_SETTING_BLOCK,
520 host_content_settings_map->GetContentSetting( 457 host_content_settings_map->GetContentSetting(
521 host_ending_with_dot, 458 host_ending_with_dot,
522 host_ending_with_dot, 459 host_ending_with_dot,
523 CONTENT_SETTINGS_TYPE_JAVASCRIPT, 460 CONTENT_SETTINGS_TYPE_JAVASCRIPT,
524 std::string())); 461 std::string()));
525 462
526 #if defined(ENABLE_PLUGINS) 463 #if defined(ENABLE_PLUGINS)
527 EXPECT_EQ(CONTENT_SETTING_DETECT_IMPORTANT_CONTENT, 464 EXPECT_EQ(CONTENT_SETTING_DETECT_IMPORTANT_CONTENT,
528 host_content_settings_map->GetContentSetting( 465 host_content_settings_map->GetContentSetting(
529 host_ending_with_dot, 466 host_ending_with_dot,
530 host_ending_with_dot, 467 host_ending_with_dot,
531 CONTENT_SETTINGS_TYPE_PLUGINS, 468 CONTENT_SETTINGS_TYPE_PLUGINS,
532 std::string())); 469 std::string()));
533 host_content_settings_map->SetContentSetting( 470 host_content_settings_map->SetContentSettingCustomScope(
534 pattern, 471 pattern, ContentSettingsPattern::Wildcard(),
535 ContentSettingsPattern::Wildcard(), 472 CONTENT_SETTINGS_TYPE_PLUGINS, std::string(), CONTENT_SETTING_DEFAULT);
536 CONTENT_SETTINGS_TYPE_PLUGINS,
537 std::string(),
538 CONTENT_SETTING_DEFAULT);
539 EXPECT_EQ(CONTENT_SETTING_DETECT_IMPORTANT_CONTENT, 473 EXPECT_EQ(CONTENT_SETTING_DETECT_IMPORTANT_CONTENT,
540 host_content_settings_map->GetContentSetting( 474 host_content_settings_map->GetContentSetting(
541 host_ending_with_dot, 475 host_ending_with_dot,
542 host_ending_with_dot, 476 host_ending_with_dot,
543 CONTENT_SETTINGS_TYPE_PLUGINS, 477 CONTENT_SETTINGS_TYPE_PLUGINS,
544 std::string())); 478 std::string()));
545 host_content_settings_map->SetContentSetting( 479 host_content_settings_map->SetContentSettingCustomScope(
546 pattern, 480 pattern, ContentSettingsPattern::Wildcard(),
547 ContentSettingsPattern::Wildcard(), 481 CONTENT_SETTINGS_TYPE_PLUGINS, std::string(), CONTENT_SETTING_BLOCK);
548 CONTENT_SETTINGS_TYPE_PLUGINS,
549 std::string(),
550 CONTENT_SETTING_BLOCK);
551 EXPECT_EQ(CONTENT_SETTING_BLOCK, 482 EXPECT_EQ(CONTENT_SETTING_BLOCK,
552 host_content_settings_map->GetContentSetting( 483 host_content_settings_map->GetContentSetting(
553 host_ending_with_dot, 484 host_ending_with_dot,
554 host_ending_with_dot, 485 host_ending_with_dot,
555 CONTENT_SETTINGS_TYPE_PLUGINS, 486 CONTENT_SETTINGS_TYPE_PLUGINS,
556 std::string())); 487 std::string()));
557 #endif 488 #endif
558 489
559 EXPECT_EQ( 490 EXPECT_EQ(
560 CONTENT_SETTING_BLOCK, 491 CONTENT_SETTING_BLOCK,
561 host_content_settings_map->GetContentSetting(host_ending_with_dot, 492 host_content_settings_map->GetContentSetting(host_ending_with_dot,
562 host_ending_with_dot, 493 host_ending_with_dot,
563 CONTENT_SETTINGS_TYPE_POPUPS, 494 CONTENT_SETTINGS_TYPE_POPUPS,
564 std::string())); 495 std::string()));
565 host_content_settings_map->SetContentSetting( 496 host_content_settings_map->SetContentSettingCustomScope(
566 pattern, 497 pattern, ContentSettingsPattern::Wildcard(), CONTENT_SETTINGS_TYPE_POPUPS,
567 ContentSettingsPattern::Wildcard(), 498 std::string(), CONTENT_SETTING_DEFAULT);
568 CONTENT_SETTINGS_TYPE_POPUPS,
569 std::string(),
570 CONTENT_SETTING_DEFAULT);
571 EXPECT_EQ( 499 EXPECT_EQ(
572 CONTENT_SETTING_BLOCK, 500 CONTENT_SETTING_BLOCK,
573 host_content_settings_map->GetContentSetting(host_ending_with_dot, 501 host_content_settings_map->GetContentSetting(host_ending_with_dot,
574 host_ending_with_dot, 502 host_ending_with_dot,
575 CONTENT_SETTINGS_TYPE_POPUPS, 503 CONTENT_SETTINGS_TYPE_POPUPS,
576 std::string())); 504 std::string()));
577 host_content_settings_map->SetContentSetting( 505 host_content_settings_map->SetContentSettingCustomScope(
578 pattern, 506 pattern, ContentSettingsPattern::Wildcard(), CONTENT_SETTINGS_TYPE_POPUPS,
579 ContentSettingsPattern::Wildcard(), 507 std::string(), CONTENT_SETTING_ALLOW);
580 CONTENT_SETTINGS_TYPE_POPUPS,
581 std::string(),
582 CONTENT_SETTING_ALLOW);
583 EXPECT_EQ( 508 EXPECT_EQ(
584 CONTENT_SETTING_ALLOW, 509 CONTENT_SETTING_ALLOW,
585 host_content_settings_map->GetContentSetting(host_ending_with_dot, 510 host_content_settings_map->GetContentSetting(host_ending_with_dot,
586 host_ending_with_dot, 511 host_ending_with_dot,
587 CONTENT_SETTINGS_TYPE_POPUPS, 512 CONTENT_SETTINGS_TYPE_POPUPS,
588 std::string())); 513 std::string()));
589 514
590 EXPECT_EQ(CONTENT_SETTING_BLOCK, 515 EXPECT_EQ(CONTENT_SETTING_BLOCK,
591 host_content_settings_map->GetContentSetting( 516 host_content_settings_map->GetContentSetting(
592 host_ending_with_dot, host_ending_with_dot, 517 host_ending_with_dot, host_ending_with_dot,
593 CONTENT_SETTINGS_TYPE_KEYGEN, std::string())); 518 CONTENT_SETTINGS_TYPE_KEYGEN, std::string()));
594 host_content_settings_map->SetContentSetting( 519 host_content_settings_map->SetContentSettingCustomScope(
595 pattern, ContentSettingsPattern::Wildcard(), CONTENT_SETTINGS_TYPE_KEYGEN, 520 pattern, ContentSettingsPattern::Wildcard(), CONTENT_SETTINGS_TYPE_KEYGEN,
596 std::string(), CONTENT_SETTING_ALLOW); 521 std::string(), CONTENT_SETTING_ALLOW);
597 EXPECT_EQ(CONTENT_SETTING_ALLOW, 522 EXPECT_EQ(CONTENT_SETTING_ALLOW,
598 host_content_settings_map->GetContentSetting( 523 host_content_settings_map->GetContentSetting(
599 host_ending_with_dot, host_ending_with_dot, 524 host_ending_with_dot, host_ending_with_dot,
600 CONTENT_SETTINGS_TYPE_KEYGEN, std::string())); 525 CONTENT_SETTINGS_TYPE_KEYGEN, std::string()));
601 host_content_settings_map->SetContentSetting( 526 host_content_settings_map->SetContentSettingCustomScope(
602 pattern, ContentSettingsPattern::Wildcard(), CONTENT_SETTINGS_TYPE_KEYGEN, 527 pattern, ContentSettingsPattern::Wildcard(), CONTENT_SETTINGS_TYPE_KEYGEN,
603 std::string(), CONTENT_SETTING_DEFAULT); 528 std::string(), CONTENT_SETTING_DEFAULT);
604 EXPECT_EQ(CONTENT_SETTING_BLOCK, 529 EXPECT_EQ(CONTENT_SETTING_BLOCK,
605 host_content_settings_map->GetContentSetting( 530 host_content_settings_map->GetContentSetting(
606 host_ending_with_dot, host_ending_with_dot, 531 host_ending_with_dot, host_ending_with_dot,
607 CONTENT_SETTINGS_TYPE_KEYGEN, std::string())); 532 CONTENT_SETTINGS_TYPE_KEYGEN, std::string()));
608 } 533 }
609 534
610 TEST_F(HostContentSettingsMapTest, NestedSettings) { 535 TEST_F(HostContentSettingsMapTest, NestedSettings) {
611 TestingProfile profile; 536 TestingProfile profile;
612 HostContentSettingsMap* host_content_settings_map = 537 HostContentSettingsMap* host_content_settings_map =
613 HostContentSettingsMapFactory::GetForProfile(&profile); 538 HostContentSettingsMapFactory::GetForProfile(&profile);
614 539
615 GURL host("http://a.b.example.com/"); 540 GURL host("http://a.b.example.com/");
616 ContentSettingsPattern pattern1 = 541 ContentSettingsPattern pattern1 =
617 ContentSettingsPattern::FromString("[*.]example.com"); 542 ContentSettingsPattern::FromString("[*.]example.com");
618 ContentSettingsPattern pattern2 = 543 ContentSettingsPattern pattern2 =
619 ContentSettingsPattern::FromString("[*.]b.example.com"); 544 ContentSettingsPattern::FromString("[*.]b.example.com");
620 ContentSettingsPattern pattern3 = 545 ContentSettingsPattern pattern3 =
621 ContentSettingsPattern::FromString("a.b.example.com"); 546 ContentSettingsPattern::FromString("a.b.example.com");
622 547
623 host_content_settings_map->SetContentSetting( 548 host_content_settings_map->SetContentSettingCustomScope(
624 pattern1, 549 pattern1, ContentSettingsPattern::Wildcard(),
625 ContentSettingsPattern::Wildcard(), 550 CONTENT_SETTINGS_TYPE_IMAGES, std::string(), CONTENT_SETTING_BLOCK);
626 CONTENT_SETTINGS_TYPE_IMAGES,
627 std::string(),
628 CONTENT_SETTING_BLOCK);
629 551
630 host_content_settings_map->SetContentSetting( 552 host_content_settings_map->SetContentSettingCustomScope(
631 pattern2, 553 pattern2, ContentSettingsPattern::Wildcard(),
632 ContentSettingsPattern::Wildcard(), 554 CONTENT_SETTINGS_TYPE_COOKIES, std::string(), CONTENT_SETTING_BLOCK);
633 CONTENT_SETTINGS_TYPE_COOKIES,
634 std::string(),
635 CONTENT_SETTING_BLOCK);
636 555
637 host_content_settings_map->SetContentSetting( 556 host_content_settings_map->SetContentSettingCustomScope(
638 pattern3, 557 pattern3, ContentSettingsPattern::Wildcard(),
639 ContentSettingsPattern::Wildcard(), 558 CONTENT_SETTINGS_TYPE_PLUGINS, std::string(), CONTENT_SETTING_BLOCK);
640 CONTENT_SETTINGS_TYPE_PLUGINS,
641 std::string(),
642 CONTENT_SETTING_BLOCK);
643 host_content_settings_map->SetDefaultContentSetting( 559 host_content_settings_map->SetDefaultContentSetting(
644 CONTENT_SETTINGS_TYPE_JAVASCRIPT, CONTENT_SETTING_BLOCK); 560 CONTENT_SETTINGS_TYPE_JAVASCRIPT, CONTENT_SETTING_BLOCK);
645 561
646 EXPECT_EQ(CONTENT_SETTING_BLOCK, 562 EXPECT_EQ(CONTENT_SETTING_BLOCK,
647 host_content_settings_map->GetContentSetting( 563 host_content_settings_map->GetContentSetting(
648 host, host, CONTENT_SETTINGS_TYPE_COOKIES, std::string())); 564 host, host, CONTENT_SETTINGS_TYPE_COOKIES, std::string()));
649 EXPECT_EQ(CONTENT_SETTING_BLOCK, 565 EXPECT_EQ(CONTENT_SETTING_BLOCK,
650 host_content_settings_map->GetContentSetting( 566 host_content_settings_map->GetContentSetting(
651 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); 567 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
652 EXPECT_EQ(CONTENT_SETTING_BLOCK, 568 EXPECT_EQ(CONTENT_SETTING_BLOCK,
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
690 606
691 EXPECT_EQ(CONTENT_SETTING_ALLOW, 607 EXPECT_EQ(CONTENT_SETTING_ALLOW,
692 host_content_settings_map->GetContentSetting( 608 host_content_settings_map->GetContentSetting(
693 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); 609 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
694 EXPECT_EQ(CONTENT_SETTING_ALLOW, 610 EXPECT_EQ(CONTENT_SETTING_ALLOW,
695 otr_map->GetContentSetting( 611 otr_map->GetContentSetting(
696 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); 612 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
697 613
698 // Changing content settings on the main map should also affect the 614 // Changing content settings on the main map should also affect the
699 // incognito map. 615 // incognito map.
700 host_content_settings_map->SetContentSetting( 616 host_content_settings_map->SetContentSettingCustomScope(
701 pattern, 617 pattern, ContentSettingsPattern::Wildcard(), CONTENT_SETTINGS_TYPE_IMAGES,
702 ContentSettingsPattern::Wildcard(), 618 std::string(), CONTENT_SETTING_BLOCK);
703 CONTENT_SETTINGS_TYPE_IMAGES,
704 std::string(),
705 CONTENT_SETTING_BLOCK);
706 EXPECT_EQ(CONTENT_SETTING_BLOCK, 619 EXPECT_EQ(CONTENT_SETTING_BLOCK,
707 host_content_settings_map->GetContentSetting( 620 host_content_settings_map->GetContentSetting(
708 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); 621 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
709 EXPECT_EQ(CONTENT_SETTING_BLOCK, 622 EXPECT_EQ(CONTENT_SETTING_BLOCK,
710 otr_map->GetContentSetting( 623 otr_map->GetContentSetting(
711 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); 624 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
712 625
713 // Changing content settings on the incognito map should NOT affect the 626 // Changing content settings on the incognito map should NOT affect the
714 // main map. 627 // main map.
715 otr_map->SetContentSetting(pattern, 628 otr_map->SetContentSettingCustomScope(
716 ContentSettingsPattern::Wildcard(), 629 pattern, ContentSettingsPattern::Wildcard(), CONTENT_SETTINGS_TYPE_IMAGES,
717 CONTENT_SETTINGS_TYPE_IMAGES, 630 std::string(), CONTENT_SETTING_ALLOW);
718 std::string(),
719 CONTENT_SETTING_ALLOW);
720 EXPECT_EQ(CONTENT_SETTING_BLOCK, 631 EXPECT_EQ(CONTENT_SETTING_BLOCK,
721 host_content_settings_map->GetContentSetting( 632 host_content_settings_map->GetContentSetting(
722 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); 633 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
723 EXPECT_EQ(CONTENT_SETTING_ALLOW, 634 EXPECT_EQ(CONTENT_SETTING_ALLOW,
724 otr_map->GetContentSetting( 635 otr_map->GetContentSetting(
725 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); 636 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
726 } 637 }
727 638
728 TEST_F(HostContentSettingsMapTest, OffTheRecordPartialInheritPref) { 639 TEST_F(HostContentSettingsMapTest, OffTheRecordPartialInheritPref) {
729 // Permissions marked INHERIT_IN_INCOGNITO_EXCEPT_ALLOW in 640 // Permissions marked INHERIT_IN_INCOGNITO_EXCEPT_ALLOW in
730 // ContentSettingsRegistry (e.g. push & notifications) only inherit BLOCK 641 // ContentSettingsRegistry (e.g. push & notifications) only inherit BLOCK
731 // settings from regular to incognito. 642 // settings from regular to incognito.
732 TestingProfile profile; 643 TestingProfile profile;
733 Profile* otr_profile = profile.GetOffTheRecordProfile(); 644 Profile* otr_profile = profile.GetOffTheRecordProfile();
734 HostContentSettingsMap* host_content_settings_map = 645 HostContentSettingsMap* host_content_settings_map =
735 HostContentSettingsMapFactory::GetForProfile(&profile); 646 HostContentSettingsMapFactory::GetForProfile(&profile);
736 HostContentSettingsMap* otr_map = 647 HostContentSettingsMap* otr_map =
737 HostContentSettingsMapFactory::GetForProfile(otr_profile); 648 HostContentSettingsMapFactory::GetForProfile(otr_profile);
738 649
739 GURL host("http://example.com/"); 650 GURL host("http://example.com/");
740 ContentSettingsPattern pattern =
741 ContentSettingsPattern::FromURLNoWildcard(host);
742 651
743 EXPECT_EQ( 652 EXPECT_EQ(
744 CONTENT_SETTING_ASK, 653 CONTENT_SETTING_ASK,
745 host_content_settings_map->GetContentSetting( 654 host_content_settings_map->GetContentSetting(
746 host, host, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string())); 655 host, host, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string()));
747 EXPECT_EQ( 656 EXPECT_EQ(
748 CONTENT_SETTING_ASK, 657 CONTENT_SETTING_ASK,
749 otr_map->GetContentSetting( 658 otr_map->GetContentSetting(
750 host, host, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string())); 659 host, host, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string()));
751 660
752 // BLOCK should be inherited from the main map to the incognito map. 661 // BLOCK should be inherited from the main map to the incognito map.
753 host_content_settings_map->SetContentSetting( 662 host_content_settings_map->SetContentSettingDefaultScope(
754 pattern, 663 host, GURL(), CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string(),
755 ContentSettingsPattern::Wildcard(),
756 CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
757 std::string(),
758 CONTENT_SETTING_BLOCK); 664 CONTENT_SETTING_BLOCK);
759 EXPECT_EQ( 665 EXPECT_EQ(
760 CONTENT_SETTING_BLOCK, 666 CONTENT_SETTING_BLOCK,
761 host_content_settings_map->GetContentSetting( 667 host_content_settings_map->GetContentSetting(
762 host, host, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string())); 668 host, host, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string()));
763 EXPECT_EQ( 669 EXPECT_EQ(
764 CONTENT_SETTING_BLOCK, 670 CONTENT_SETTING_BLOCK,
765 otr_map->GetContentSetting( 671 otr_map->GetContentSetting(
766 host, host, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string())); 672 host, host, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string()));
767 673
768 // ALLOW should not be inherited from the main map to the incognito map (but 674 // ALLOW should not be inherited from the main map to the incognito map (but
769 // it still overwrites the BLOCK, hence incognito reverts to ASK). 675 // it still overwrites the BLOCK, hence incognito reverts to ASK).
770 host_content_settings_map->SetContentSetting( 676 host_content_settings_map->SetContentSettingDefaultScope(
771 pattern, 677 host, GURL(), CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string(),
772 ContentSettingsPattern::Wildcard(),
773 CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
774 std::string(),
775 CONTENT_SETTING_ALLOW); 678 CONTENT_SETTING_ALLOW);
776 EXPECT_EQ( 679 EXPECT_EQ(
777 CONTENT_SETTING_ALLOW, 680 CONTENT_SETTING_ALLOW,
778 host_content_settings_map->GetContentSetting( 681 host_content_settings_map->GetContentSetting(
779 host, host, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string())); 682 host, host, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string()));
780 EXPECT_EQ( 683 EXPECT_EQ(
781 CONTENT_SETTING_ASK, 684 CONTENT_SETTING_ASK,
782 otr_map->GetContentSetting( 685 otr_map->GetContentSetting(
783 host, host, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string())); 686 host, host, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string()));
784 } 687 }
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
1007 GetNonDefaultContentSettingsIfTypeManaged) { 910 GetNonDefaultContentSettingsIfTypeManaged) {
1008 TestingProfile profile; 911 TestingProfile profile;
1009 HostContentSettingsMap* host_content_settings_map = 912 HostContentSettingsMap* host_content_settings_map =
1010 HostContentSettingsMapFactory::GetForProfile(&profile); 913 HostContentSettingsMapFactory::GetForProfile(&profile);
1011 syncable_prefs::TestingPrefServiceSyncable* prefs = 914 syncable_prefs::TestingPrefServiceSyncable* prefs =
1012 profile.GetTestingPrefService(); 915 profile.GetTestingPrefService();
1013 916
1014 // Set pattern for JavaScript setting. 917 // Set pattern for JavaScript setting.
1015 ContentSettingsPattern pattern = 918 ContentSettingsPattern pattern =
1016 ContentSettingsPattern::FromString("[*.]example.com"); 919 ContentSettingsPattern::FromString("[*.]example.com");
1017 host_content_settings_map->SetContentSetting( 920 host_content_settings_map->SetContentSettingCustomScope(
1018 pattern, 921 pattern, ContentSettingsPattern::Wildcard(),
1019 ContentSettingsPattern::Wildcard(), 922 CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string(), CONTENT_SETTING_BLOCK);
1020 CONTENT_SETTINGS_TYPE_JAVASCRIPT,
1021 std::string(),
1022 CONTENT_SETTING_BLOCK);
1023 923
1024 EXPECT_EQ(CONTENT_SETTING_ALLOW, 924 EXPECT_EQ(CONTENT_SETTING_ALLOW,
1025 host_content_settings_map->GetDefaultContentSetting( 925 host_content_settings_map->GetDefaultContentSetting(
1026 CONTENT_SETTINGS_TYPE_JAVASCRIPT, NULL)); 926 CONTENT_SETTINGS_TYPE_JAVASCRIPT, NULL));
1027 927
1028 GURL host("http://example.com/"); 928 GURL host("http://example.com/");
1029 EXPECT_EQ(CONTENT_SETTING_BLOCK, 929 EXPECT_EQ(CONTENT_SETTING_BLOCK,
1030 host_content_settings_map->GetContentSetting( 930 host_content_settings_map->GetContentSetting(
1031 host, host, CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string())); 931 host, host, CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string()));
1032 932
(...skipping 16 matching lines...) Expand all
1049 profile.GetTestingPrefService(); 949 profile.GetTestingPrefService();
1050 950
1051 // Block all JavaScript. 951 // Block all JavaScript.
1052 host_content_settings_map->SetDefaultContentSetting( 952 host_content_settings_map->SetDefaultContentSetting(
1053 CONTENT_SETTINGS_TYPE_JAVASCRIPT, CONTENT_SETTING_BLOCK); 953 CONTENT_SETTINGS_TYPE_JAVASCRIPT, CONTENT_SETTING_BLOCK);
1054 954
1055 // Set an exception to allow "[*.]example.com" 955 // Set an exception to allow "[*.]example.com"
1056 ContentSettingsPattern pattern = 956 ContentSettingsPattern pattern =
1057 ContentSettingsPattern::FromString("[*.]example.com"); 957 ContentSettingsPattern::FromString("[*.]example.com");
1058 958
1059 host_content_settings_map->SetContentSetting( 959 host_content_settings_map->SetContentSettingCustomScope(
1060 pattern, 960 pattern, ContentSettingsPattern::Wildcard(),
1061 ContentSettingsPattern::Wildcard(), 961 CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string(), CONTENT_SETTING_ALLOW);
1062 CONTENT_SETTINGS_TYPE_JAVASCRIPT,
1063 std::string(),
1064 CONTENT_SETTING_ALLOW);
1065 962
1066 EXPECT_EQ(CONTENT_SETTING_BLOCK, 963 EXPECT_EQ(CONTENT_SETTING_BLOCK,
1067 host_content_settings_map->GetDefaultContentSetting( 964 host_content_settings_map->GetDefaultContentSetting(
1068 CONTENT_SETTINGS_TYPE_JAVASCRIPT, NULL)); 965 CONTENT_SETTINGS_TYPE_JAVASCRIPT, NULL));
1069 GURL host("http://example.com/"); 966 GURL host("http://example.com/");
1070 EXPECT_EQ(CONTENT_SETTING_ALLOW, 967 EXPECT_EQ(CONTENT_SETTING_ALLOW,
1071 host_content_settings_map->GetContentSetting( 968 host_content_settings_map->GetContentSetting(
1072 host, host, CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string())); 969 host, host, CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string()));
1073 970
1074 // Set managed-default-content-settings-preferences. 971 // Set managed-default-content-settings-preferences.
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
1145 1042
1146 TEST_F(HostContentSettingsMapTest, GetContentSetting) { 1043 TEST_F(HostContentSettingsMapTest, GetContentSetting) {
1147 TestingProfile profile; 1044 TestingProfile profile;
1148 HostContentSettingsMap* host_content_settings_map = 1045 HostContentSettingsMap* host_content_settings_map =
1149 HostContentSettingsMapFactory::GetForProfile(&profile); 1046 HostContentSettingsMapFactory::GetForProfile(&profile);
1150 1047
1151 GURL host("http://example.com/"); 1048 GURL host("http://example.com/");
1152 GURL embedder("chrome://foo"); 1049 GURL embedder("chrome://foo");
1153 ContentSettingsPattern pattern = 1050 ContentSettingsPattern pattern =
1154 ContentSettingsPattern::FromString("[*.]example.com"); 1051 ContentSettingsPattern::FromString("[*.]example.com");
1155 host_content_settings_map->SetContentSetting( 1052 host_content_settings_map->SetContentSettingCustomScope(
1156 pattern, 1053 pattern, ContentSettingsPattern::Wildcard(), CONTENT_SETTINGS_TYPE_IMAGES,
1157 ContentSettingsPattern::Wildcard(), 1054 std::string(), CONTENT_SETTING_BLOCK);
1158 CONTENT_SETTINGS_TYPE_IMAGES,
1159 std::string(),
1160 CONTENT_SETTING_BLOCK);
1161 EXPECT_EQ(CONTENT_SETTING_BLOCK, 1055 EXPECT_EQ(CONTENT_SETTING_BLOCK,
1162 host_content_settings_map->GetContentSetting( 1056 host_content_settings_map->GetContentSetting(
1163 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); 1057 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
1164 EXPECT_EQ(CONTENT_SETTING_ALLOW, 1058 EXPECT_EQ(CONTENT_SETTING_ALLOW,
1165 host_content_settings_map->GetContentSetting( 1059 host_content_settings_map->GetContentSetting(
1166 embedder, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); 1060 embedder, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
1167 } 1061 }
1168 1062
1169 TEST_F(HostContentSettingsMapTest, IsDefaultSettingAllowedForType) { 1063 TEST_F(HostContentSettingsMapTest, IsDefaultSettingAllowedForType) {
1170 EXPECT_FALSE(HostContentSettingsMap::IsDefaultSettingAllowedForType( 1064 EXPECT_FALSE(HostContentSettingsMap::IsDefaultSettingAllowedForType(
(...skipping 15 matching lines...) Expand all
1186 OnContentSettingChanged(pattern, 1080 OnContentSettingChanged(pattern,
1187 ContentSettingsPattern::Wildcard(), 1081 ContentSettingsPattern::Wildcard(),
1188 CONTENT_SETTINGS_TYPE_IMAGES, 1082 CONTENT_SETTINGS_TYPE_IMAGES,
1189 "")); 1083 ""));
1190 1084
1191 host_content_settings_map->AddObserver(&mock_observer); 1085 host_content_settings_map->AddObserver(&mock_observer);
1192 1086
1193 EXPECT_EQ(CONTENT_SETTING_ALLOW, 1087 EXPECT_EQ(CONTENT_SETTING_ALLOW,
1194 host_content_settings_map->GetContentSetting( 1088 host_content_settings_map->GetContentSetting(
1195 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); 1089 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
1196 host_content_settings_map->SetContentSetting( 1090 host_content_settings_map->SetContentSettingCustomScope(
1197 pattern, 1091 pattern, ContentSettingsPattern::Wildcard(), CONTENT_SETTINGS_TYPE_IMAGES,
1198 ContentSettingsPattern::Wildcard(), 1092 std::string(), CONTENT_SETTING_DEFAULT);
1199 CONTENT_SETTINGS_TYPE_IMAGES,
1200 std::string(),
1201 CONTENT_SETTING_DEFAULT);
1202 } 1093 }
1203 1094
1204 TEST_F(HostContentSettingsMapTest, GuestProfile) { 1095 TEST_F(HostContentSettingsMapTest, GuestProfile) {
1205 TestingProfile profile; 1096 TestingProfile profile;
1206 profile.SetGuestSession(true); 1097 profile.SetGuestSession(true);
1207 HostContentSettingsMap* host_content_settings_map = 1098 HostContentSettingsMap* host_content_settings_map =
1208 HostContentSettingsMapFactory::GetForProfile(&profile); 1099 HostContentSettingsMapFactory::GetForProfile(&profile);
1209 1100
1210 GURL host("http://example.com/"); 1101 GURL host("http://example.com/");
1211 ContentSettingsPattern pattern = 1102 ContentSettingsPattern pattern =
1212 ContentSettingsPattern::FromString("[*.]example.com"); 1103 ContentSettingsPattern::FromString("[*.]example.com");
1213 1104
1214 EXPECT_EQ(CONTENT_SETTING_ALLOW, 1105 EXPECT_EQ(CONTENT_SETTING_ALLOW,
1215 host_content_settings_map->GetContentSetting( 1106 host_content_settings_map->GetContentSetting(
1216 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); 1107 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
1217 1108
1218 // Changing content settings should not result in any prefs being stored 1109 // Changing content settings should not result in any prefs being stored
1219 // however the value should be set in memory. 1110 // however the value should be set in memory.
1220 host_content_settings_map->SetContentSetting( 1111 host_content_settings_map->SetContentSettingCustomScope(
1221 pattern, ContentSettingsPattern::Wildcard(), CONTENT_SETTINGS_TYPE_IMAGES, 1112 pattern, ContentSettingsPattern::Wildcard(), CONTENT_SETTINGS_TYPE_IMAGES,
1222 std::string(), CONTENT_SETTING_BLOCK); 1113 std::string(), CONTENT_SETTING_BLOCK);
1223 EXPECT_EQ(CONTENT_SETTING_BLOCK, 1114 EXPECT_EQ(CONTENT_SETTING_BLOCK,
1224 host_content_settings_map->GetContentSetting( 1115 host_content_settings_map->GetContentSetting(
1225 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); 1116 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
1226 1117
1227 const base::DictionaryValue* all_settings_dictionary = 1118 const base::DictionaryValue* all_settings_dictionary =
1228 profile.GetPrefs()->GetDictionary( 1119 profile.GetPrefs()->GetDictionary(
1229 GetPrefName(CONTENT_SETTINGS_TYPE_IMAGES)); 1120 GetPrefName(CONTENT_SETTINGS_TYPE_IMAGES));
1230 EXPECT_TRUE(all_settings_dictionary->empty()); 1121 EXPECT_TRUE(all_settings_dictionary->empty());
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1265 profile.GetPrefs()->Set(GetPrefName(CONTENT_SETTINGS_TYPE_IMAGES), *value); 1156 profile.GetPrefs()->Set(GetPrefName(CONTENT_SETTINGS_TYPE_IMAGES), *value);
1266 1157
1267 // Test that during construction all the prefs get cleared. 1158 // Test that during construction all the prefs get cleared.
1268 HostContentSettingsMapFactory::GetForProfile(&profile); 1159 HostContentSettingsMapFactory::GetForProfile(&profile);
1269 1160
1270 const base::DictionaryValue* all_settings_dictionary = 1161 const base::DictionaryValue* all_settings_dictionary =
1271 profile.GetPrefs()->GetDictionary( 1162 profile.GetPrefs()->GetDictionary(
1272 GetPrefName(CONTENT_SETTINGS_TYPE_IMAGES)); 1163 GetPrefName(CONTENT_SETTINGS_TYPE_IMAGES));
1273 EXPECT_TRUE(all_settings_dictionary->empty()); 1164 EXPECT_TRUE(all_settings_dictionary->empty());
1274 } 1165 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698