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

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

Issue 2459823002: [Sync] Rename syncable_prefs to sync_preferences. (Closed)
Patch Set: Created 4 years, 1 month 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"
(...skipping 16 matching lines...) Expand all
27 #include "components/content_settings/core/browser/website_settings_registry.h" 27 #include "components/content_settings/core/browser/website_settings_registry.h"
28 #include "components/content_settings/core/common/content_settings_pattern.h" 28 #include "components/content_settings/core/common/content_settings_pattern.h"
29 #include "components/content_settings/core/test/content_settings_test_utils.h" 29 #include "components/content_settings/core/test/content_settings_test_utils.h"
30 #include "components/pref_registry/pref_registry_syncable.h" 30 #include "components/pref_registry/pref_registry_syncable.h"
31 #include "components/prefs/default_pref_store.h" 31 #include "components/prefs/default_pref_store.h"
32 #include "components/prefs/overlay_user_pref_store.h" 32 #include "components/prefs/overlay_user_pref_store.h"
33 #include "components/prefs/pref_change_registrar.h" 33 #include "components/prefs/pref_change_registrar.h"
34 #include "components/prefs/pref_service.h" 34 #include "components/prefs/pref_service.h"
35 #include "components/prefs/scoped_user_pref_update.h" 35 #include "components/prefs/scoped_user_pref_update.h"
36 #include "components/prefs/testing_pref_store.h" 36 #include "components/prefs/testing_pref_store.h"
37 #include "components/syncable_prefs/pref_service_mock_factory.h" 37 #include "components/sync_preferences/pref_service_mock_factory.h"
38 #include "components/syncable_prefs/pref_service_syncable.h" 38 #include "components/sync_preferences/pref_service_syncable.h"
39 #include "components/syncable_prefs/testing_pref_service_syncable.h" 39 #include "components/sync_preferences/testing_pref_service_syncable.h"
40 #include "content/public/test/test_browser_thread_bundle.h" 40 #include "content/public/test/test_browser_thread_bundle.h"
41 #include "testing/gtest/include/gtest/gtest.h" 41 #include "testing/gtest/include/gtest/gtest.h"
42 #include "url/gurl.h" 42 #include "url/gurl.h"
43 43
44 using ::testing::_; 44 using ::testing::_;
45 45
46 namespace content_settings { 46 namespace content_settings {
47 47
48 class DeadlockCheckerThread : public base::PlatformThread::Delegate { 48 class DeadlockCheckerThread : public base::PlatformThread::Delegate {
49 public: 49 public:
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 pref_content_settings_provider.ShutdownOnUIThread(); 132 pref_content_settings_provider.ShutdownOnUIThread();
133 } 133 }
134 134
135 // Test for regression in which the PrefProvider modified the user pref store 135 // Test for regression in which the PrefProvider modified the user pref store
136 // of the OTR unintentionally: http://crbug.com/74466. 136 // of the OTR unintentionally: http://crbug.com/74466.
137 TEST_F(PrefProviderTest, Incognito) { 137 TEST_F(PrefProviderTest, Incognito) {
138 PersistentPrefStore* user_prefs = new TestingPrefStore(); 138 PersistentPrefStore* user_prefs = new TestingPrefStore();
139 OverlayUserPrefStore* otr_user_prefs = 139 OverlayUserPrefStore* otr_user_prefs =
140 new OverlayUserPrefStore(user_prefs); 140 new OverlayUserPrefStore(user_prefs);
141 141
142 syncable_prefs::PrefServiceMockFactory factory; 142 sync_preferences::PrefServiceMockFactory factory;
143 factory.set_user_prefs(make_scoped_refptr(user_prefs)); 143 factory.set_user_prefs(make_scoped_refptr(user_prefs));
144 scoped_refptr<user_prefs::PrefRegistrySyncable> registry( 144 scoped_refptr<user_prefs::PrefRegistrySyncable> registry(
145 new user_prefs::PrefRegistrySyncable); 145 new user_prefs::PrefRegistrySyncable);
146 syncable_prefs::PrefServiceSyncable* regular_prefs = 146 sync_preferences::PrefServiceSyncable* regular_prefs =
147 factory.CreateSyncable(registry.get()).release(); 147 factory.CreateSyncable(registry.get()).release();
148 148
149 chrome::RegisterUserProfilePrefs(registry.get()); 149 chrome::RegisterUserProfilePrefs(registry.get());
150 150
151 syncable_prefs::PrefServiceMockFactory otr_factory; 151 sync_preferences::PrefServiceMockFactory otr_factory;
152 otr_factory.set_user_prefs(make_scoped_refptr(otr_user_prefs)); 152 otr_factory.set_user_prefs(make_scoped_refptr(otr_user_prefs));
153 scoped_refptr<user_prefs::PrefRegistrySyncable> otr_registry( 153 scoped_refptr<user_prefs::PrefRegistrySyncable> otr_registry(
154 new user_prefs::PrefRegistrySyncable); 154 new user_prefs::PrefRegistrySyncable);
155 syncable_prefs::PrefServiceSyncable* otr_prefs = 155 sync_preferences::PrefServiceSyncable* otr_prefs =
156 otr_factory.CreateSyncable(otr_registry.get()).release(); 156 otr_factory.CreateSyncable(otr_registry.get()).release();
157 157
158 chrome::RegisterUserProfilePrefs(otr_registry.get()); 158 chrome::RegisterUserProfilePrefs(otr_registry.get());
159 159
160 TestingProfile::Builder profile_builder; 160 TestingProfile::Builder profile_builder;
161 profile_builder.SetPrefService(base::WrapUnique(regular_prefs)); 161 profile_builder.SetPrefService(base::WrapUnique(regular_prefs));
162 std::unique_ptr<TestingProfile> profile = profile_builder.Build(); 162 std::unique_ptr<TestingProfile> profile = profile_builder.Build();
163 163
164 TestingProfile::Builder otr_profile_builder; 164 TestingProfile::Builder otr_profile_builder;
165 otr_profile_builder.SetPrefService(base::WrapUnique(otr_prefs)); 165 otr_profile_builder.SetPrefService(base::WrapUnique(otr_prefs));
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 TestUtils::GetContentSetting(&pref_content_settings_provider, host, 322 TestUtils::GetContentSetting(&pref_content_settings_provider, host,
323 host, CONTENT_SETTINGS_TYPE_PLUGINS, 323 host, CONTENT_SETTINGS_TYPE_PLUGINS,
324 resource2, false)); 324 resource2, false));
325 325
326 pref_content_settings_provider.ShutdownOnUIThread(); 326 pref_content_settings_provider.ShutdownOnUIThread();
327 } 327 }
328 #endif 328 #endif
329 329
330 // http://crosbug.com/17760 330 // http://crosbug.com/17760
331 TEST_F(PrefProviderTest, Deadlock) { 331 TEST_F(PrefProviderTest, Deadlock) {
332 syncable_prefs::TestingPrefServiceSyncable prefs; 332 sync_preferences::TestingPrefServiceSyncable prefs;
333 PrefProvider::RegisterProfilePrefs(prefs.registry()); 333 PrefProvider::RegisterProfilePrefs(prefs.registry());
334 334
335 // Chain of events: a preference changes, |PrefProvider| notices it, and reads 335 // Chain of events: a preference changes, |PrefProvider| notices it, and reads
336 // and writes the preference. When the preference is written, a notification 336 // and writes the preference. When the preference is written, a notification
337 // is sent, and this used to happen when |PrefProvider| was still holding its 337 // is sent, and this used to happen when |PrefProvider| was still holding its
338 // lock. 338 // lock.
339 339
340 const WebsiteSettingsInfo* info = WebsiteSettingsRegistry::GetInstance()->Get( 340 const WebsiteSettingsInfo* info = WebsiteSettingsRegistry::GetInstance()->Get(
341 CONTENT_SETTINGS_TYPE_COOKIES); 341 CONTENT_SETTINGS_TYPE_COOKIES);
342 PrefProvider provider(&prefs, false); 342 PrefProvider provider(&prefs, false);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
381 base::Time second = pref_content_settings_provider.GetLastUsage( 381 base::Time second = pref_content_settings_provider.GetLastUsage(
382 pattern, pattern, CONTENT_SETTINGS_TYPE_GEOLOCATION); 382 pattern, pattern, CONTENT_SETTINGS_TYPE_GEOLOCATION);
383 383
384 base::TimeDelta delta = second - first; 384 base::TimeDelta delta = second - first;
385 EXPECT_EQ(delta.InSeconds(), 10); 385 EXPECT_EQ(delta.InSeconds(), 10);
386 386
387 pref_content_settings_provider.ShutdownOnUIThread(); 387 pref_content_settings_provider.ShutdownOnUIThread();
388 } 388 }
389 389
390 TEST_F(PrefProviderTest, IncognitoInheritsValueMap) { 390 TEST_F(PrefProviderTest, IncognitoInheritsValueMap) {
391 syncable_prefs::TestingPrefServiceSyncable prefs; 391 sync_preferences::TestingPrefServiceSyncable prefs;
392 PrefProvider::RegisterProfilePrefs(prefs.registry()); 392 PrefProvider::RegisterProfilePrefs(prefs.registry());
393 393
394 ContentSettingsPattern pattern_1 = 394 ContentSettingsPattern pattern_1 =
395 ContentSettingsPattern::FromString("google.com"); 395 ContentSettingsPattern::FromString("google.com");
396 ContentSettingsPattern pattern_2 = 396 ContentSettingsPattern pattern_2 =
397 ContentSettingsPattern::FromString("www.google.com"); 397 ContentSettingsPattern::FromString("www.google.com");
398 ContentSettingsPattern wildcard = 398 ContentSettingsPattern wildcard =
399 ContentSettingsPattern::FromString("*"); 399 ContentSettingsPattern::FromString("*");
400 std::unique_ptr<base::Value> value( 400 std::unique_ptr<base::Value> value(
401 new base::FundamentalValue(CONTENT_SETTING_ALLOW)); 401 new base::FundamentalValue(CONTENT_SETTING_ALLOW));
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
444 EXPECT_TRUE(it->HasNext()); 444 EXPECT_TRUE(it->HasNext());
445 EXPECT_EQ(pattern_2, it->Next().primary_pattern); 445 EXPECT_EQ(pattern_2, it->Next().primary_pattern);
446 EXPECT_FALSE(it->HasNext()); 446 EXPECT_FALSE(it->HasNext());
447 } 447 }
448 448
449 incognito_provider.ShutdownOnUIThread(); 449 incognito_provider.ShutdownOnUIThread();
450 normal_provider.ShutdownOnUIThread(); 450 normal_provider.ShutdownOnUIThread();
451 } 451 }
452 452
453 TEST_F(PrefProviderTest, ClearAllContentSettingsRules) { 453 TEST_F(PrefProviderTest, ClearAllContentSettingsRules) {
454 syncable_prefs::TestingPrefServiceSyncable prefs; 454 sync_preferences::TestingPrefServiceSyncable prefs;
455 PrefProvider::RegisterProfilePrefs(prefs.registry()); 455 PrefProvider::RegisterProfilePrefs(prefs.registry());
456 456
457 ContentSettingsPattern pattern = 457 ContentSettingsPattern pattern =
458 ContentSettingsPattern::FromString("google.com"); 458 ContentSettingsPattern::FromString("google.com");
459 ContentSettingsPattern wildcard = 459 ContentSettingsPattern wildcard =
460 ContentSettingsPattern::FromString("*"); 460 ContentSettingsPattern::FromString("*");
461 std::unique_ptr<base::Value> value( 461 std::unique_ptr<base::Value> value(
462 new base::FundamentalValue(CONTENT_SETTING_ALLOW)); 462 new base::FundamentalValue(CONTENT_SETTING_ALLOW));
463 ResourceIdentifier res_id("abcde"); 463 ResourceIdentifier res_id("abcde");
464 464
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
522 for (const char* pref : nonempty_prefs) { 522 for (const char* pref : nonempty_prefs) {
523 DictionaryPrefUpdate update(&prefs, pref); 523 DictionaryPrefUpdate update(&prefs, pref);
524 const base::DictionaryValue* dictionary = update.Get(); 524 const base::DictionaryValue* dictionary = update.Get();
525 EXPECT_EQ(1u, dictionary->size()); 525 EXPECT_EQ(1u, dictionary->size());
526 } 526 }
527 527
528 provider.ShutdownOnUIThread(); 528 provider.ShutdownOnUIThread();
529 } 529 }
530 530
531 } // namespace content_settings 531 } // namespace content_settings
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698