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

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

Issue 2812113004: Write last_modified date to Content Settings in the PrefProvider (Closed)
Patch Set: rebase Created 3 years, 7 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 "components/content_settings/core/browser/content_settings_pref_provide r.h" 5 #include "components/content_settings/core/browser/content_settings_pref_provide r.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/auto_reset.h" 9 #include "base/auto_reset.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "base/memory/ptr_util.h" 12 #include "base/memory/ptr_util.h"
13 #include "base/message_loop/message_loop.h" 13 #include "base/message_loop/message_loop.h"
14 #include "base/test/test_timeouts.h"
14 #include "base/threading/platform_thread.h" 15 #include "base/threading/platform_thread.h"
15 #include "base/values.h" 16 #include "base/values.h"
16 #include "chrome/browser/content_settings/content_settings_mock_observer.h" 17 #include "chrome/browser/content_settings/content_settings_mock_observer.h"
17 #include "chrome/browser/prefs/browser_prefs.h" 18 #include "chrome/browser/prefs/browser_prefs.h"
18 #include "chrome/common/chrome_switches.h" 19 #include "chrome/common/chrome_switches.h"
19 #include "chrome/common/pref_names.h" 20 #include "chrome/common/pref_names.h"
20 #include "chrome/common/url_constants.h" 21 #include "chrome/common/url_constants.h"
21 #include "chrome/test/base/testing_profile.h" 22 #include "chrome/test/base/testing_profile.h"
22 #include "components/content_settings/core/browser/content_settings_pref.h" 23 #include "components/content_settings/core/browser/content_settings_pref.h"
23 #include "components/content_settings/core/browser/content_settings_registry.h" 24 #include "components/content_settings/core/browser/content_settings_registry.h"
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 // Ensure all content settings are initialized. 108 // Ensure all content settings are initialized.
108 ContentSettingsRegistry::GetInstance(); 109 ContentSettingsRegistry::GetInstance();
109 } 110 }
110 111
111 private: 112 private:
112 content::TestBrowserThreadBundle thread_bundle_; 113 content::TestBrowserThreadBundle thread_bundle_;
113 }; 114 };
114 115
115 TEST_F(PrefProviderTest, Observer) { 116 TEST_F(PrefProviderTest, Observer) {
116 TestingProfile profile; 117 TestingProfile profile;
117 PrefProvider pref_content_settings_provider(profile.GetPrefs(), false); 118 PrefProvider pref_content_settings_provider(profile.GetPrefs(),
119 false /* incognito */,
120 true /* store_last_modified */);
118 121
119 ContentSettingsPattern pattern = 122 ContentSettingsPattern pattern =
120 ContentSettingsPattern::FromString("[*.]example.com"); 123 ContentSettingsPattern::FromString("[*.]example.com");
121 MockObserver mock_observer; 124 MockObserver mock_observer;
122 EXPECT_CALL(mock_observer, OnContentSettingChanged( 125 EXPECT_CALL(mock_observer, OnContentSettingChanged(
123 pattern, ContentSettingsPattern::Wildcard(), 126 pattern, ContentSettingsPattern::Wildcard(),
124 CONTENT_SETTINGS_TYPE_COOKIES, "")); 127 CONTENT_SETTINGS_TYPE_COOKIES, ""));
125 128
126 pref_content_settings_provider.AddObserver(&mock_observer); 129 pref_content_settings_provider.AddObserver(&mock_observer);
127 130
(...skipping 27 matching lines...) Expand all
155 data_for_pattern->SetInteger("setting", CONTENT_SETTING_ALLOW); 158 data_for_pattern->SetInteger("setting", CONTENT_SETTING_ALLOW);
156 pref_data.SetWithoutPathExpansion(kPattern, std::move(data_for_pattern)); 159 pref_data.SetWithoutPathExpansion(kPattern, std::move(data_for_pattern));
157 prefs->Set(kFullscreenPrefPath, pref_data); 160 prefs->Set(kFullscreenPrefPath, pref_data);
158 #if !defined(OS_ANDROID) 161 #if !defined(OS_ANDROID)
159 prefs->Set(kMouselockPrefPath, pref_data); 162 prefs->Set(kMouselockPrefPath, pref_data);
160 #endif 163 #endif
161 prefs->Set(kGeolocationPrefPath, pref_data); 164 prefs->Set(kGeolocationPrefPath, pref_data);
162 165
163 // Instantiate a new PrefProvider here, because we want to test the 166 // Instantiate a new PrefProvider here, because we want to test the
164 // constructor's behavior after setting the above. 167 // constructor's behavior after setting the above.
165 PrefProvider provider(prefs, false); 168 PrefProvider provider(prefs, false /* incognito */,
169 true /* store_last_modified */);
166 provider.ShutdownOnUIThread(); 170 provider.ShutdownOnUIThread();
167 171
168 // Check that fullscreen and mouselock have been deleted. 172 // Check that fullscreen and mouselock have been deleted.
169 EXPECT_FALSE(prefs->HasPrefPath(kFullscreenPrefPath)); 173 EXPECT_FALSE(prefs->HasPrefPath(kFullscreenPrefPath));
170 #if !defined(OS_ANDROID) 174 #if !defined(OS_ANDROID)
171 EXPECT_FALSE(prefs->HasPrefPath(kMouselockPrefPath)); 175 EXPECT_FALSE(prefs->HasPrefPath(kMouselockPrefPath));
172 #endif 176 #endif
173 EXPECT_TRUE(prefs->HasPrefPath(kGeolocationPrefPath)); 177 EXPECT_TRUE(prefs->HasPrefPath(kGeolocationPrefPath));
174 GURL primary_url("http://example.com/"); 178 GURL primary_url("http://example.com/");
175 EXPECT_EQ(CONTENT_SETTING_ALLOW, 179 EXPECT_EQ(CONTENT_SETTING_ALLOW,
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 217
214 auto mic_pattern_data = base::MakeUnique<base::DictionaryValue>(); 218 auto mic_pattern_data = base::MakeUnique<base::DictionaryValue>();
215 mic_pattern_data->SetInteger("setting", CONTENT_SETTING_ALLOW); 219 mic_pattern_data->SetInteger("setting", CONTENT_SETTING_ALLOW);
216 mic_pattern_data->SetDouble(kObsoleteLastUsed, 1480000000.0); 220 mic_pattern_data->SetDouble(kObsoleteLastUsed, 1480000000.0);
217 base::DictionaryValue mic_pref_data; 221 base::DictionaryValue mic_pref_data;
218 mic_pref_data.SetWithoutPathExpansion(kPattern, std::move(mic_pattern_data)); 222 mic_pref_data.SetWithoutPathExpansion(kPattern, std::move(mic_pattern_data));
219 prefs->Set(kMicPrefPath, mic_pref_data); 223 prefs->Set(kMicPrefPath, mic_pref_data);
220 224
221 // Instantiate a new PrefProvider here, because we want to test the 225 // Instantiate a new PrefProvider here, because we want to test the
222 // constructor's behavior after setting the above. 226 // constructor's behavior after setting the above.
223 PrefProvider provider(prefs, false); 227 PrefProvider provider(prefs, false /* incognito */,
228 true /* store_last_modified */);
224 229
225 // Check that last_used data has been deleted. 230 // Check that last_used data has been deleted.
226 EXPECT_TRUE(prefs->GetDictionary(kGeolocationPrefPath)->empty()); 231 EXPECT_TRUE(prefs->GetDictionary(kGeolocationPrefPath)->empty());
227 auto* mic_prefs = prefs->GetDictionary(kMicPrefPath); 232 auto* mic_prefs = prefs->GetDictionary(kMicPrefPath);
228 const base::DictionaryValue* mic_result_pattern_data; 233 const base::DictionaryValue* mic_result_pattern_data;
229 ASSERT_TRUE(mic_prefs->GetDictionaryWithoutPathExpansion( 234 ASSERT_TRUE(mic_prefs->GetDictionaryWithoutPathExpansion(
230 kPattern, &mic_result_pattern_data)); 235 kPattern, &mic_result_pattern_data));
231 EXPECT_EQ(static_cast<size_t>(1), mic_result_pattern_data->size()); 236 EXPECT_EQ(static_cast<size_t>(1), mic_result_pattern_data->size());
232 int mic_result_setting; 237 int mic_result_setting;
233 EXPECT_TRUE( 238 EXPECT_TRUE(
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 chrome::RegisterUserProfilePrefs(otr_registry.get()); 271 chrome::RegisterUserProfilePrefs(otr_registry.get());
267 272
268 TestingProfile::Builder profile_builder; 273 TestingProfile::Builder profile_builder;
269 profile_builder.SetPrefService(base::WrapUnique(regular_prefs)); 274 profile_builder.SetPrefService(base::WrapUnique(regular_prefs));
270 std::unique_ptr<TestingProfile> profile = profile_builder.Build(); 275 std::unique_ptr<TestingProfile> profile = profile_builder.Build();
271 276
272 TestingProfile::Builder otr_profile_builder; 277 TestingProfile::Builder otr_profile_builder;
273 otr_profile_builder.SetPrefService(base::WrapUnique(otr_prefs)); 278 otr_profile_builder.SetPrefService(base::WrapUnique(otr_prefs));
274 otr_profile_builder.BuildIncognito(profile.get()); 279 otr_profile_builder.BuildIncognito(profile.get());
275 280
276 PrefProvider pref_content_settings_provider(regular_prefs, false); 281 PrefProvider pref_content_settings_provider(
277 PrefProvider pref_content_settings_provider_incognito(otr_prefs, true); 282 regular_prefs, false /* incognito */, true /* store_last_modified */);
283 PrefProvider pref_content_settings_provider_incognito(
284 otr_prefs, true /* incognito */, true /* store_last_modified */);
278 ContentSettingsPattern pattern = 285 ContentSettingsPattern pattern =
279 ContentSettingsPattern::FromString("[*.]example.com"); 286 ContentSettingsPattern::FromString("[*.]example.com");
280 pref_content_settings_provider.SetWebsiteSetting( 287 pref_content_settings_provider.SetWebsiteSetting(
281 pattern, pattern, CONTENT_SETTINGS_TYPE_COOKIES, std::string(), 288 pattern, pattern, CONTENT_SETTINGS_TYPE_COOKIES, std::string(),
282 new base::Value(CONTENT_SETTING_ALLOW)); 289 new base::Value(CONTENT_SETTING_ALLOW));
283 290
284 GURL host("http://example.com/"); 291 GURL host("http://example.com/");
285 // The value should of course be visible in the regular PrefProvider. 292 // The value should of course be visible in the regular PrefProvider.
286 EXPECT_EQ(CONTENT_SETTING_ALLOW, 293 EXPECT_EQ(CONTENT_SETTING_ALLOW,
287 TestUtils::GetContentSetting(&pref_content_settings_provider, host, 294 TestUtils::GetContentSetting(&pref_content_settings_provider, host,
288 host, CONTENT_SETTINGS_TYPE_COOKIES, 295 host, CONTENT_SETTINGS_TYPE_COOKIES,
289 std::string(), false)); 296 std::string(), false));
290 // And also in the OTR version. 297 // And also in the OTR version.
291 EXPECT_EQ(CONTENT_SETTING_ALLOW, 298 EXPECT_EQ(CONTENT_SETTING_ALLOW,
292 TestUtils::GetContentSetting( 299 TestUtils::GetContentSetting(
293 &pref_content_settings_provider_incognito, host, host, 300 &pref_content_settings_provider_incognito, host, host,
294 CONTENT_SETTINGS_TYPE_COOKIES, std::string(), false)); 301 CONTENT_SETTINGS_TYPE_COOKIES, std::string(), false));
295 const WebsiteSettingsInfo* info = WebsiteSettingsRegistry::GetInstance()->Get( 302 const WebsiteSettingsInfo* info = WebsiteSettingsRegistry::GetInstance()->Get(
296 CONTENT_SETTINGS_TYPE_COOKIES); 303 CONTENT_SETTINGS_TYPE_COOKIES);
297 // But the value should not be overridden in the OTR user prefs accidentally. 304 // But the value should not be overridden in the OTR user prefs accidentally.
298 EXPECT_FALSE(otr_user_prefs->IsSetInOverlay(info->pref_name())); 305 EXPECT_FALSE(otr_user_prefs->IsSetInOverlay(info->pref_name()));
299 306
300 pref_content_settings_provider.ShutdownOnUIThread(); 307 pref_content_settings_provider.ShutdownOnUIThread();
301 pref_content_settings_provider_incognito.ShutdownOnUIThread(); 308 pref_content_settings_provider_incognito.ShutdownOnUIThread();
302 } 309 }
303 310
304 TEST_F(PrefProviderTest, GetContentSettingsValue) { 311 TEST_F(PrefProviderTest, GetContentSettingsValue) {
305 TestingProfile testing_profile; 312 TestingProfile testing_profile;
306 PrefProvider provider(testing_profile.GetPrefs(), false); 313 PrefProvider provider(testing_profile.GetPrefs(), false /* incognito */,
314 true /* store_last_modified */);
307 315
308 GURL primary_url("http://example.com/"); 316 GURL primary_url("http://example.com/");
309 ContentSettingsPattern primary_pattern = 317 ContentSettingsPattern primary_pattern =
310 ContentSettingsPattern::FromString("[*.]example.com"); 318 ContentSettingsPattern::FromString("[*.]example.com");
311 319
312 EXPECT_EQ(CONTENT_SETTING_DEFAULT, 320 EXPECT_EQ(CONTENT_SETTING_DEFAULT,
313 TestUtils::GetContentSetting(&provider, primary_url, primary_url, 321 TestUtils::GetContentSetting(&provider, primary_url, primary_url,
314 CONTENT_SETTINGS_TYPE_COOKIES, 322 CONTENT_SETTINGS_TYPE_COOKIES,
315 std::string(), false)); 323 std::string(), false));
316 324
(...skipping 20 matching lines...) Expand all
337 NULL); 345 NULL);
338 EXPECT_EQ(NULL, TestUtils::GetContentSettingValue( 346 EXPECT_EQ(NULL, TestUtils::GetContentSettingValue(
339 &provider, primary_url, primary_url, 347 &provider, primary_url, primary_url,
340 CONTENT_SETTINGS_TYPE_COOKIES, std::string(), false)); 348 CONTENT_SETTINGS_TYPE_COOKIES, std::string(), false));
341 provider.ShutdownOnUIThread(); 349 provider.ShutdownOnUIThread();
342 } 350 }
343 351
344 TEST_F(PrefProviderTest, Patterns) { 352 TEST_F(PrefProviderTest, Patterns) {
345 TestingProfile testing_profile; 353 TestingProfile testing_profile;
346 PrefProvider pref_content_settings_provider(testing_profile.GetPrefs(), 354 PrefProvider pref_content_settings_provider(testing_profile.GetPrefs(),
347 false); 355 false /* incognito */,
356 true /* store_last_modified */);
348 357
349 GURL host1("http://example.com/"); 358 GURL host1("http://example.com/");
350 GURL host2("http://www.example.com/"); 359 GURL host2("http://www.example.com/");
351 GURL host3("http://example.org/"); 360 GURL host3("http://example.org/");
352 GURL host4("file:///tmp/test.html"); 361 GURL host4("file:///tmp/test.html");
353 ContentSettingsPattern pattern1 = 362 ContentSettingsPattern pattern1 =
354 ContentSettingsPattern::FromString("[*.]example.com"); 363 ContentSettingsPattern::FromString("[*.]example.com");
355 ContentSettingsPattern pattern2 = 364 ContentSettingsPattern pattern2 =
356 ContentSettingsPattern::FromString("example.org"); 365 ContentSettingsPattern::FromString("example.org");
357 ContentSettingsPattern pattern3 = 366 ContentSettingsPattern pattern3 =
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
397 host4, CONTENT_SETTINGS_TYPE_COOKIES, 406 host4, CONTENT_SETTINGS_TYPE_COOKIES,
398 std::string(), false)); 407 std::string(), false));
399 408
400 pref_content_settings_provider.ShutdownOnUIThread(); 409 pref_content_settings_provider.ShutdownOnUIThread();
401 } 410 }
402 411
403 #if BUILDFLAG(ENABLE_PLUGINS) 412 #if BUILDFLAG(ENABLE_PLUGINS)
404 TEST_F(PrefProviderTest, ResourceIdentifier) { 413 TEST_F(PrefProviderTest, ResourceIdentifier) {
405 TestingProfile testing_profile; 414 TestingProfile testing_profile;
406 PrefProvider pref_content_settings_provider(testing_profile.GetPrefs(), 415 PrefProvider pref_content_settings_provider(testing_profile.GetPrefs(),
407 false); 416 false /* incognito */,
417 true /* store_last_modified */);
408 418
409 GURL host("http://example.com/"); 419 GURL host("http://example.com/");
410 ContentSettingsPattern pattern = 420 ContentSettingsPattern pattern =
411 ContentSettingsPattern::FromString("[*.]example.com"); 421 ContentSettingsPattern::FromString("[*.]example.com");
412 std::string resource1("someplugin"); 422 std::string resource1("someplugin");
413 std::string resource2("otherplugin"); 423 std::string resource2("otherplugin");
414 424
415 EXPECT_EQ(CONTENT_SETTING_DEFAULT, 425 EXPECT_EQ(CONTENT_SETTING_DEFAULT,
416 TestUtils::GetContentSetting(&pref_content_settings_provider, host, 426 TestUtils::GetContentSetting(&pref_content_settings_provider, host,
417 host, CONTENT_SETTINGS_TYPE_PLUGINS, 427 host, CONTENT_SETTINGS_TYPE_PLUGINS,
(...skipping 19 matching lines...) Expand all
437 sync_preferences::TestingPrefServiceSyncable prefs; 447 sync_preferences::TestingPrefServiceSyncable prefs;
438 PrefProvider::RegisterProfilePrefs(prefs.registry()); 448 PrefProvider::RegisterProfilePrefs(prefs.registry());
439 449
440 // Chain of events: a preference changes, |PrefProvider| notices it, and reads 450 // Chain of events: a preference changes, |PrefProvider| notices it, and reads
441 // and writes the preference. When the preference is written, a notification 451 // and writes the preference. When the preference is written, a notification
442 // is sent, and this used to happen when |PrefProvider| was still holding its 452 // is sent, and this used to happen when |PrefProvider| was still holding its
443 // lock. 453 // lock.
444 454
445 const WebsiteSettingsInfo* info = WebsiteSettingsRegistry::GetInstance()->Get( 455 const WebsiteSettingsInfo* info = WebsiteSettingsRegistry::GetInstance()->Get(
446 CONTENT_SETTINGS_TYPE_COOKIES); 456 CONTENT_SETTINGS_TYPE_COOKIES);
447 PrefProvider provider(&prefs, false); 457 PrefProvider provider(&prefs, false /* incognito */,
458 true /* store_last_modified */);
448 DeadlockCheckerObserver observer(&prefs, &provider); 459 DeadlockCheckerObserver observer(&prefs, &provider);
449 { 460 {
450 DictionaryPrefUpdate update(&prefs, info->pref_name()); 461 DictionaryPrefUpdate update(&prefs, info->pref_name());
451 base::DictionaryValue* mutable_settings = update.Get(); 462 base::DictionaryValue* mutable_settings = update.Get();
452 mutable_settings->SetWithoutPathExpansion( 463 mutable_settings->SetWithoutPathExpansion(
453 "www.example.com,*", base::MakeUnique<base::DictionaryValue>()); 464 "www.example.com,*", base::MakeUnique<base::DictionaryValue>());
454 } 465 }
455 EXPECT_TRUE(observer.notification_received()); 466 EXPECT_TRUE(observer.notification_received());
456 467
457 provider.ShutdownOnUIThread(); 468 provider.ShutdownOnUIThread();
458 } 469 }
459 470
460 TEST_F(PrefProviderTest, IncognitoInheritsValueMap) { 471 TEST_F(PrefProviderTest, IncognitoInheritsValueMap) {
461 sync_preferences::TestingPrefServiceSyncable prefs; 472 sync_preferences::TestingPrefServiceSyncable prefs;
462 PrefProvider::RegisterProfilePrefs(prefs.registry()); 473 PrefProvider::RegisterProfilePrefs(prefs.registry());
463 474
464 ContentSettingsPattern pattern_1 = 475 ContentSettingsPattern pattern_1 =
465 ContentSettingsPattern::FromString("google.com"); 476 ContentSettingsPattern::FromString("google.com");
466 ContentSettingsPattern pattern_2 = 477 ContentSettingsPattern pattern_2 =
467 ContentSettingsPattern::FromString("www.google.com"); 478 ContentSettingsPattern::FromString("www.google.com");
468 ContentSettingsPattern wildcard = 479 ContentSettingsPattern wildcard =
469 ContentSettingsPattern::FromString("*"); 480 ContentSettingsPattern::FromString("*");
470 std::unique_ptr<base::Value> value(new base::Value(CONTENT_SETTING_ALLOW)); 481 std::unique_ptr<base::Value> value(new base::Value(CONTENT_SETTING_ALLOW));
471 482
472 // Create a normal provider and set a setting. 483 // Create a normal provider and set a setting.
473 PrefProvider normal_provider(&prefs, false); 484 PrefProvider normal_provider(&prefs, false /* incognito */,
485 true /* store_last_modified */);
474 normal_provider.SetWebsiteSetting(pattern_1, wildcard, 486 normal_provider.SetWebsiteSetting(pattern_1, wildcard,
475 CONTENT_SETTINGS_TYPE_COOKIES, 487 CONTENT_SETTINGS_TYPE_COOKIES,
476 std::string(), value->DeepCopy()); 488 std::string(), value->DeepCopy());
477 489
478 // Non-OTR provider, Non-OTR iterator has one setting (pattern 1). 490 // Non-OTR provider, Non-OTR iterator has one setting (pattern 1).
479 { 491 {
480 std::unique_ptr<RuleIterator> it(normal_provider.GetRuleIterator( 492 std::unique_ptr<RuleIterator> it(normal_provider.GetRuleIterator(
481 CONTENT_SETTINGS_TYPE_COOKIES, std::string(), false)); 493 CONTENT_SETTINGS_TYPE_COOKIES, std::string(), false));
482 EXPECT_TRUE(it->HasNext()); 494 EXPECT_TRUE(it->HasNext());
483 EXPECT_EQ(pattern_1, it->Next().primary_pattern); 495 EXPECT_EQ(pattern_1, it->Next().primary_pattern);
484 EXPECT_FALSE(it->HasNext()); 496 EXPECT_FALSE(it->HasNext());
485 } 497 }
486 498
487 // Non-OTR provider, OTR iterator has no settings. 499 // Non-OTR provider, OTR iterator has no settings.
488 { 500 {
489 std::unique_ptr<RuleIterator> it(normal_provider.GetRuleIterator( 501 std::unique_ptr<RuleIterator> it(normal_provider.GetRuleIterator(
490 CONTENT_SETTINGS_TYPE_COOKIES, std::string(), true)); 502 CONTENT_SETTINGS_TYPE_COOKIES, std::string(), true));
491 EXPECT_FALSE(it); 503 EXPECT_FALSE(it);
492 } 504 }
493 505
494 // Create an incognito provider and set a setting. 506 // Create an incognito provider and set a setting.
495 PrefProvider incognito_provider(&prefs, true); 507 PrefProvider incognito_provider(&prefs, true /* incognito */,
508 true /* store_last_modified */);
496 incognito_provider.SetWebsiteSetting(pattern_2, wildcard, 509 incognito_provider.SetWebsiteSetting(pattern_2, wildcard,
497 CONTENT_SETTINGS_TYPE_COOKIES, 510 CONTENT_SETTINGS_TYPE_COOKIES,
498 std::string(), value->DeepCopy()); 511 std::string(), value->DeepCopy());
499 512
500 // OTR provider, non-OTR iterator has one setting (pattern 1). 513 // OTR provider, non-OTR iterator has one setting (pattern 1).
501 { 514 {
502 std::unique_ptr<RuleIterator> it(incognito_provider.GetRuleIterator( 515 std::unique_ptr<RuleIterator> it(incognito_provider.GetRuleIterator(
503 CONTENT_SETTINGS_TYPE_COOKIES, std::string(), false)); 516 CONTENT_SETTINGS_TYPE_COOKIES, std::string(), false));
504 EXPECT_TRUE(it->HasNext()); 517 EXPECT_TRUE(it->HasNext());
505 EXPECT_EQ(pattern_1, it->Next().primary_pattern); 518 EXPECT_EQ(pattern_1, it->Next().primary_pattern);
(...skipping 17 matching lines...) Expand all
523 sync_preferences::TestingPrefServiceSyncable prefs; 536 sync_preferences::TestingPrefServiceSyncable prefs;
524 PrefProvider::RegisterProfilePrefs(prefs.registry()); 537 PrefProvider::RegisterProfilePrefs(prefs.registry());
525 538
526 ContentSettingsPattern pattern = 539 ContentSettingsPattern pattern =
527 ContentSettingsPattern::FromString("google.com"); 540 ContentSettingsPattern::FromString("google.com");
528 ContentSettingsPattern wildcard = 541 ContentSettingsPattern wildcard =
529 ContentSettingsPattern::FromString("*"); 542 ContentSettingsPattern::FromString("*");
530 std::unique_ptr<base::Value> value(new base::Value(CONTENT_SETTING_ALLOW)); 543 std::unique_ptr<base::Value> value(new base::Value(CONTENT_SETTING_ALLOW));
531 ResourceIdentifier res_id("abcde"); 544 ResourceIdentifier res_id("abcde");
532 545
533 PrefProvider provider(&prefs, false); 546 PrefProvider provider(&prefs, false /* incognito */,
547 true /* store_last_modified */);
534 548
535 // Non-empty pattern, syncable, empty resource identifier. 549 // Non-empty pattern, syncable, empty resource identifier.
536 provider.SetWebsiteSetting(pattern, wildcard, 550 provider.SetWebsiteSetting(pattern, wildcard,
537 CONTENT_SETTINGS_TYPE_JAVASCRIPT, 551 CONTENT_SETTINGS_TYPE_JAVASCRIPT,
538 ResourceIdentifier(), value->DeepCopy()); 552 ResourceIdentifier(), value->DeepCopy());
539 553
540 // Non-empty pattern, non-syncable, empty resource identifier. 554 // Non-empty pattern, non-syncable, empty resource identifier.
541 provider.SetWebsiteSetting(pattern, wildcard, 555 provider.SetWebsiteSetting(pattern, wildcard,
542 CONTENT_SETTINGS_TYPE_GEOLOCATION, 556 CONTENT_SETTINGS_TYPE_GEOLOCATION,
543 ResourceIdentifier(), value->DeepCopy()); 557 ResourceIdentifier(), value->DeepCopy());
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
589 603
590 for (const char* pref : nonempty_prefs) { 604 for (const char* pref : nonempty_prefs) {
591 DictionaryPrefUpdate update(&prefs, pref); 605 DictionaryPrefUpdate update(&prefs, pref);
592 const base::DictionaryValue* dictionary = update.Get(); 606 const base::DictionaryValue* dictionary = update.Get();
593 EXPECT_EQ(1u, dictionary->size()); 607 EXPECT_EQ(1u, dictionary->size());
594 } 608 }
595 609
596 provider.ShutdownOnUIThread(); 610 provider.ShutdownOnUIThread();
597 } 611 }
598 612
613 TEST_F(PrefProviderTest, LastModified) {
614 sync_preferences::TestingPrefServiceSyncable prefs;
615 PrefProvider::RegisterProfilePrefs(prefs.registry());
616
617 ContentSettingsPattern pattern_1 =
618 ContentSettingsPattern::FromString("google.com");
619 ContentSettingsPattern pattern_2 =
620 ContentSettingsPattern::FromString("www.google.com");
621 auto value = base::MakeUnique<base::Value>(CONTENT_SETTING_ALLOW);
622
623 base::Time t1 = base::Time::Now();
624
625 // Create a provider and set a few settings.
626 PrefProvider provider(&prefs, false /* incognito */,
627 true /* store_last_modified */);
628 provider.SetWebsiteSetting(pattern_1, ContentSettingsPattern::Wildcard(),
629 CONTENT_SETTINGS_TYPE_COOKIES, std::string(),
630 value->DeepCopy());
631 provider.SetWebsiteSetting(pattern_2, ContentSettingsPattern::Wildcard(),
632 CONTENT_SETTINGS_TYPE_COOKIES, std::string(),
633 value->DeepCopy());
634 // Make sure that the timestamps for pattern_1 and patter_2 are before |t2|.
635 base::PlatformThread::Sleep(TestTimeouts::tiny_timeout());
636 base::Time t2 = base::Time::Now();
637
638 base::Time last_modified = provider.GetWebsiteSettingLastModified(
639 pattern_1, ContentSettingsPattern::Wildcard(),
640 CONTENT_SETTINGS_TYPE_COOKIES, std::string());
641 EXPECT_GE(last_modified, t1);
642 EXPECT_LT(last_modified, t2);
643 last_modified = provider.GetWebsiteSettingLastModified(
644 pattern_2, ContentSettingsPattern::Wildcard(),
645 CONTENT_SETTINGS_TYPE_COOKIES, std::string());
646 EXPECT_GE(last_modified, t1);
647 EXPECT_LT(last_modified, t2);
648
649 // A change for pattern_1, which will update the last_modified timestamp.
650 auto value2 = base::MakeUnique<base::Value>(CONTENT_SETTING_BLOCK);
651 provider.SetWebsiteSetting(pattern_1, ContentSettingsPattern::Wildcard(),
652 CONTENT_SETTINGS_TYPE_COOKIES, std::string(),
653 value2->DeepCopy());
654
655 last_modified = provider.GetWebsiteSettingLastModified(
656 pattern_1, ContentSettingsPattern::Wildcard(),
657 CONTENT_SETTINGS_TYPE_COOKIES, std::string());
658 EXPECT_GE(last_modified, t2);
659
660 // The timestamp of pattern_2 shouldn't change.
661 last_modified = provider.GetWebsiteSettingLastModified(
662 pattern_2, ContentSettingsPattern::Wildcard(),
663 CONTENT_SETTINGS_TYPE_COOKIES, std::string());
664 EXPECT_GE(last_modified, t1);
665 EXPECT_LT(last_modified, t2);
666
667 provider.ShutdownOnUIThread();
668 }
669
599 } // namespace content_settings 670 } // namespace content_settings
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698