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

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

Issue 12079097: Introduce PrefRegistrySyncable, simplifying PrefServiceSyncable. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge to head again; base::File changes conflicted. Created 7 years, 10 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 | Annotate | Revision Log
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 "chrome/browser/content_settings/content_settings_pref_provider.h" 5 #include "chrome/browser/content_settings/content_settings_pref_provider.h"
6 6
7 #include "base/auto_reset.h" 7 #include "base/auto_reset.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
11 #include "base/prefs/default_pref_store.h" 11 #include "base/prefs/default_pref_store.h"
12 #include "base/prefs/overlay_user_pref_store.h" 12 #include "base/prefs/overlay_user_pref_store.h"
13 #include "base/prefs/public/pref_change_registrar.h" 13 #include "base/prefs/public/pref_change_registrar.h"
14 #include "base/prefs/testing_pref_store.h" 14 #include "base/prefs/testing_pref_store.h"
15 #include "base/threading/platform_thread.h" 15 #include "base/threading/platform_thread.h"
16 #include "base/values.h" 16 #include "base/values.h"
17 #include "chrome/browser/content_settings/content_settings_mock_observer.h" 17 #include "chrome/browser/content_settings/content_settings_mock_observer.h"
18 #include "chrome/browser/content_settings/content_settings_utils.h" 18 #include "chrome/browser/content_settings/content_settings_utils.h"
19 #include "chrome/browser/prefs/browser_prefs.h" 19 #include "chrome/browser/prefs/browser_prefs.h"
20 #include "chrome/browser/prefs/pref_registry_syncable.h"
20 #include "chrome/browser/prefs/pref_service.h" 21 #include "chrome/browser/prefs/pref_service.h"
21 #include "chrome/browser/prefs/pref_service_mock_builder.h" 22 #include "chrome/browser/prefs/pref_service_mock_builder.h"
23 #include "chrome/browser/prefs/pref_service_syncable.h"
22 #include "chrome/browser/prefs/scoped_user_pref_update.h" 24 #include "chrome/browser/prefs/scoped_user_pref_update.h"
23 #include "chrome/common/chrome_switches.h" 25 #include "chrome/common/chrome_switches.h"
24 #include "chrome/common/pref_names.h" 26 #include "chrome/common/pref_names.h"
25 #include "chrome/common/url_constants.h" 27 #include "chrome/common/url_constants.h"
26 #include "chrome/test/base/testing_pref_service.h" 28 #include "chrome/test/base/testing_pref_service.h"
27 #include "chrome/test/base/testing_profile.h" 29 #include "chrome/test/base/testing_profile.h"
28 #include "content/public/test/test_browser_thread.h" 30 #include "content/public/test/test_browser_thread.h"
29 #include "googleurl/src/gurl.h" 31 #include "googleurl/src/gurl.h"
30 #include "testing/gtest/include/gtest/gtest.h" 32 #include "testing/gtest/include/gtest/gtest.h"
31 33
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 129
128 // Test for regression in which the PrefProvider modified the user pref store 130 // Test for regression in which the PrefProvider modified the user pref store
129 // of the OTR unintentionally: http://crbug.com/74466. 131 // of the OTR unintentionally: http://crbug.com/74466.
130 TEST_F(PrefProviderTest, Incognito) { 132 TEST_F(PrefProviderTest, Incognito) {
131 PersistentPrefStore* user_prefs = new TestingPrefStore(); 133 PersistentPrefStore* user_prefs = new TestingPrefStore();
132 OverlayUserPrefStore* otr_user_prefs = 134 OverlayUserPrefStore* otr_user_prefs =
133 new OverlayUserPrefStore(user_prefs); 135 new OverlayUserPrefStore(user_prefs);
134 136
135 PrefServiceMockBuilder builder; 137 PrefServiceMockBuilder builder;
136 builder.WithUserPrefs(user_prefs); 138 builder.WithUserPrefs(user_prefs);
137 PrefServiceSyncable* regular_prefs = builder.CreateSyncable(); 139 scoped_refptr<PrefRegistrySyncable> registry(new PrefRegistrySyncable);
140 PrefServiceSyncable* regular_prefs = builder.CreateSyncable(registry);
138 141
139 Profile::RegisterUserPrefs(regular_prefs); 142 Profile::RegisterUserPrefs(registry);
140 chrome::RegisterUserPrefs(regular_prefs); 143 chrome::RegisterUserPrefs(regular_prefs, registry);
141 144
142 builder.WithUserPrefs(otr_user_prefs); 145 builder.WithUserPrefs(otr_user_prefs);
143 PrefServiceSyncable* otr_prefs = builder.CreateSyncable(); 146 scoped_refptr<PrefRegistrySyncable> otr_registry(new PrefRegistrySyncable);
147 PrefServiceSyncable* otr_prefs = builder.CreateSyncable(otr_registry);
144 148
145 Profile::RegisterUserPrefs(otr_prefs); 149 Profile::RegisterUserPrefs(otr_registry);
146 chrome::RegisterUserPrefs(otr_prefs); 150 chrome::RegisterUserPrefs(otr_prefs, otr_registry);
147 151
148 TestingProfile profile; 152 TestingProfile profile;
149 TestingProfile* otr_profile = new TestingProfile; 153 TestingProfile* otr_profile = new TestingProfile;
150 profile.SetOffTheRecordProfile(otr_profile); 154 profile.SetOffTheRecordProfile(otr_profile);
151 profile.SetPrefService(regular_prefs); 155 profile.SetPrefService(regular_prefs);
152 otr_profile->set_incognito(true); 156 otr_profile->set_incognito(true);
153 otr_profile->SetPrefService(otr_prefs); 157 otr_profile->SetPrefService(otr_prefs);
154 158
155 PrefProvider pref_content_settings_provider(regular_prefs, false); 159 PrefProvider pref_content_settings_provider(regular_prefs, false);
156 PrefProvider pref_content_settings_provider_incognito(otr_prefs, true); 160 PrefProvider pref_content_settings_provider_incognito(otr_prefs, true);
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 secondary_url, 365 secondary_url,
362 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE, 366 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE,
363 std::string(), 367 std::string(),
364 false)); 368 false));
365 provider.ShutdownOnUIThread(); 369 provider.ShutdownOnUIThread();
366 } 370 }
367 371
368 // http://crosbug.com/17760 372 // http://crosbug.com/17760
369 TEST_F(PrefProviderTest, Deadlock) { 373 TEST_F(PrefProviderTest, Deadlock) {
370 TestingPrefServiceSyncable prefs; 374 TestingPrefServiceSyncable prefs;
371 PrefProvider::RegisterUserPrefs(&prefs); 375 PrefProvider::RegisterUserPrefs(prefs.registry());
372 376
373 // Chain of events: a preference changes, |PrefProvider| notices it, and reads 377 // Chain of events: a preference changes, |PrefProvider| notices it, and reads
374 // and writes the preference. When the preference is written, a notification 378 // and writes the preference. When the preference is written, a notification
375 // is sent, and this used to happen when |PrefProvider| was still holding its 379 // is sent, and this used to happen when |PrefProvider| was still holding its
376 // lock. 380 // lock.
377 381
378 PrefProvider provider(&prefs, false); 382 PrefProvider provider(&prefs, false);
379 DeadlockCheckerObserver observer(&prefs, &provider); 383 DeadlockCheckerObserver observer(&prefs, &provider);
380 { 384 {
381 DictionaryPrefUpdate update(&prefs, 385 DictionaryPrefUpdate update(&prefs,
382 prefs::kContentSettingsPatternPairs); 386 prefs::kContentSettingsPatternPairs);
383 DictionaryValue* mutable_settings = update.Get(); 387 DictionaryValue* mutable_settings = update.Get();
384 mutable_settings->SetWithoutPathExpansion("www.example.com,*", 388 mutable_settings->SetWithoutPathExpansion("www.example.com,*",
385 new base::DictionaryValue()); 389 new base::DictionaryValue());
386 } 390 }
387 EXPECT_TRUE(observer.notification_received()); 391 EXPECT_TRUE(observer.notification_received());
388 392
389 provider.ShutdownOnUIThread(); 393 provider.ShutdownOnUIThread();
390 } 394 }
391 395
392 } // namespace content_settings 396 } // namespace content_settings
OLDNEW
« no previous file with comments | « chrome/browser/content_settings/content_settings_pref_provider.cc ('k') | chrome/browser/content_settings/cookie_settings.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698