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

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

Issue 7088017: Split incognito extension content settings in session-only and persistent. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: review Created 9 years, 6 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "chrome/browser/content_settings/stub_settings_observer.h" 9 #include "chrome/browser/content_settings/mock_settings_observer.h"
10 #include "chrome/browser/prefs/browser_prefs.h" 10 #include "chrome/browser/prefs/browser_prefs.h"
11 #include "chrome/browser/prefs/default_pref_store.h" 11 #include "chrome/browser/prefs/default_pref_store.h"
12 #include "chrome/browser/prefs/overlay_persistent_pref_store.h" 12 #include "chrome/browser/prefs/overlay_persistent_pref_store.h"
13 #include "chrome/browser/prefs/pref_service.h" 13 #include "chrome/browser/prefs/pref_service.h"
14 #include "chrome/browser/prefs/pref_service_mock_builder.h"
14 #include "chrome/browser/prefs/testing_pref_store.h" 15 #include "chrome/browser/prefs/testing_pref_store.h"
15 #include "chrome/common/chrome_switches.h" 16 #include "chrome/common/chrome_switches.h"
16 #include "chrome/common/pref_names.h" 17 #include "chrome/common/pref_names.h"
17 #include "chrome/common/url_constants.h" 18 #include "chrome/common/url_constants.h"
18 #include "chrome/test/testing_browser_process_test.h" 19 #include "chrome/test/testing_browser_process_test.h"
19 #include "chrome/test/testing_pref_service.h" 20 #include "chrome/test/testing_pref_service.h"
20 #include "chrome/test/testing_profile.h" 21 #include "chrome/test/testing_profile.h"
21 #include "content/browser/browser_thread.h" 22 #include "content/browser/browser_thread.h"
22 #include "googleurl/src/gurl.h" 23 #include "googleurl/src/gurl.h"
23 #include "testing/gtest/include/gtest/gtest.h" 24 #include "testing/gtest/include/gtest/gtest.h"
24 25
25 namespace { 26 using ::testing::_;
26 class ContentSettingsPrefService : public PrefService {
27 public:
28 ContentSettingsPrefService(PrefStore* managed_platform_prefs,
29 PrefStore* managed_cloud_prefs,
30 PrefStore* extension_prefs,
31 PrefStore* command_line_prefs,
32 PersistentPrefStore* user_prefs,
33 PrefStore* recommended_platform_prefs,
34 PrefStore* recommended_cloud_prefs,
35 DefaultPrefStore* default_store)
36 : PrefService(
37 managed_platform_prefs, managed_cloud_prefs, extension_prefs,
38 command_line_prefs, user_prefs, recommended_platform_prefs,
39 recommended_cloud_prefs, default_store, false) {}
40 virtual ~ContentSettingsPrefService() {}
41 };
42 }
43 27
44 namespace content_settings { 28 namespace content_settings {
45 29
46 class PrefDefaultProviderTest : public TestingBrowserProcessTest { 30 class PrefDefaultProviderTest : public TestingBrowserProcessTest {
47 public: 31 public:
48 PrefDefaultProviderTest() 32 PrefDefaultProviderTest()
49 : ui_thread_(BrowserThread::UI, &message_loop_) { 33 : ui_thread_(BrowserThread::UI, &message_loop_) {
50 } 34 }
51 35
52 protected: 36 protected:
(...skipping 16 matching lines...) Expand all
69 EXPECT_EQ(CONTENT_SETTING_BLOCK, 53 EXPECT_EQ(CONTENT_SETTING_BLOCK,
70 provider.ProvideDefaultSetting(CONTENT_SETTINGS_TYPE_COOKIES)); 54 provider.ProvideDefaultSetting(CONTENT_SETTINGS_TYPE_COOKIES));
71 provider.ResetToDefaults(); 55 provider.ResetToDefaults();
72 EXPECT_EQ(CONTENT_SETTING_ALLOW, 56 EXPECT_EQ(CONTENT_SETTING_ALLOW,
73 provider.ProvideDefaultSetting(CONTENT_SETTINGS_TYPE_COOKIES)); 57 provider.ProvideDefaultSetting(CONTENT_SETTINGS_TYPE_COOKIES));
74 } 58 }
75 59
76 TEST_F(PrefDefaultProviderTest, Observer) { 60 TEST_F(PrefDefaultProviderTest, Observer) {
77 TestingProfile profile; 61 TestingProfile profile;
78 PrefDefaultProvider provider(&profile); 62 PrefDefaultProvider provider(&profile);
79 StubSettingsObserver observer; 63 MockSettingsObserver observer;
80 64
65 EXPECT_CALL(observer,
66 OnContentSettingsChanged(profile.GetHostContentSettingsMap(),
67 CONTENT_SETTINGS_TYPE_IMAGES, false,
68 _, true));
69 // Expect a second call because the PrefDefaultProvider in the TestingProfile
70 // also observes the default content settings preference.
71 EXPECT_CALL(observer,
72 OnContentSettingsChanged(profile.GetHostContentSettingsMap(),
73 CONTENT_SETTINGS_TYPE_DEFAULT, true,
74 _, true));
81 provider.UpdateDefaultSetting( 75 provider.UpdateDefaultSetting(
82 CONTENT_SETTINGS_TYPE_IMAGES, CONTENT_SETTING_BLOCK); 76 CONTENT_SETTINGS_TYPE_IMAGES, CONTENT_SETTING_BLOCK);
83 EXPECT_EQ(profile.GetHostContentSettingsMap(), observer.last_notifier);
84 EXPECT_TRUE(observer.last_update_all);
85 EXPECT_FALSE(observer.last_update_all_types);
86 EXPECT_EQ(1, observer.counter);
87 } 77 }
88 78
89 TEST_F(PrefDefaultProviderTest, ObserveDefaultPref) { 79 TEST_F(PrefDefaultProviderTest, ObserveDefaultPref) {
90 TestingProfile profile; 80 TestingProfile profile;
91 PrefDefaultProvider provider(&profile); 81 PrefDefaultProvider provider(&profile);
92 82
93 PrefService* prefs = profile.GetPrefs(); 83 PrefService* prefs = profile.GetPrefs();
94 84
95 // Make a copy of the default pref value so we can reset it later. 85 // Make a copy of the default pref value so we can reset it later.
96 scoped_ptr<Value> default_value(prefs->FindPreference( 86 scoped_ptr<Value> default_value(prefs->FindPreference(
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 protected: 159 protected:
170 MessageLoop message_loop_; 160 MessageLoop message_loop_;
171 BrowserThread ui_thread_; 161 BrowserThread ui_thread_;
172 }; 162 };
173 163
174 TEST_F(PrefProviderTest, Observer) { 164 TEST_F(PrefProviderTest, Observer) {
175 TestingProfile profile; 165 TestingProfile profile;
176 profile.GetHostContentSettingsMap(); 166 profile.GetHostContentSettingsMap();
177 Profile* p = &profile; 167 Profile* p = &profile;
178 PrefProvider pref_content_settings_provider(p); 168 PrefProvider pref_content_settings_provider(p);
179 StubSettingsObserver observer; 169 MockSettingsObserver observer;
180 ContentSettingsPattern pattern = 170 ContentSettingsPattern pattern =
181 ContentSettingsPattern::FromString("[*.]example.com"); 171 ContentSettingsPattern::FromString("[*.]example.com");
182 172
173 // Expect 2 calls: One from the update and one from canonicalization.
174 EXPECT_CALL(observer,
175 OnContentSettingsChanged(profile.GetHostContentSettingsMap(),
176 CONTENT_SETTINGS_TYPE_IMAGES, false,
177 pattern, false));
178 EXPECT_CALL(observer,
179 OnContentSettingsChanged(profile.GetHostContentSettingsMap(),
180 CONTENT_SETTINGS_TYPE_DEFAULT, true,
181 _, true));
183 pref_content_settings_provider.SetContentSetting( 182 pref_content_settings_provider.SetContentSetting(
184 pattern, 183 pattern,
185 pattern, 184 pattern,
186 CONTENT_SETTINGS_TYPE_IMAGES, 185 CONTENT_SETTINGS_TYPE_IMAGES,
187 "", 186 "",
188 CONTENT_SETTING_ALLOW); 187 CONTENT_SETTING_ALLOW);
189 EXPECT_EQ(profile.GetHostContentSettingsMap(), observer.last_notifier);
190 EXPECT_EQ(pattern, observer.last_pattern);
191 EXPECT_FALSE(observer.last_update_all);
192 EXPECT_FALSE(observer.last_update_all_types);
193 // Expect 2 calls: One from the update and one from canonicalization.
194 EXPECT_EQ(2, observer.counter);
195 } 188 }
196 189
197 // Test for regression in which the PrefProvider modified the user pref store 190 // Test for regression in which the PrefProvider modified the user pref store
198 // of the OTR unintentionally: http://crbug.com/74466. 191 // of the OTR unintentionally: http://crbug.com/74466.
199 TEST_F(PrefProviderTest, Incognito) { 192 TEST_F(PrefProviderTest, Incognito) {
200 DefaultPrefStore* default_prefs = new DefaultPrefStore();
201 PersistentPrefStore* user_prefs = new TestingPrefStore(); 193 PersistentPrefStore* user_prefs = new TestingPrefStore();
202 OverlayPersistentPrefStore* otr_user_prefs = 194 OverlayPersistentPrefStore* otr_user_prefs =
203 new OverlayPersistentPrefStore(user_prefs); 195 new OverlayPersistentPrefStore(user_prefs);
204 196
205 PrefService* regular_prefs = new ContentSettingsPrefService( 197 PrefServiceMockBuilder builder;
206 NULL, // managed_platform_prefs 198 PrefService* regular_prefs = builder.WithUserPrefs(user_prefs).Create();
207 NULL, // managed_cloud_prefs
208 NULL, // extension_prefs
209 NULL, // command_line_prefs
210 user_prefs,
211 NULL, // recommended_platform_prefs,
212 NULL, // recommended_cloud_prefs,
213 default_prefs);
214 199
215 Profile::RegisterUserPrefs(regular_prefs); 200 Profile::RegisterUserPrefs(regular_prefs);
216 browser::RegisterUserPrefs(regular_prefs); 201 browser::RegisterUserPrefs(regular_prefs);
217 202
218 PrefService* otr_prefs = new ContentSettingsPrefService( 203 PrefService* otr_prefs = builder.WithUserPrefs(otr_user_prefs).Create();
219 NULL, // managed_platform_prefs 204
220 NULL, // managed_cloud_prefs 205 Profile::RegisterUserPrefs(otr_prefs);
221 NULL, // extension_prefs 206 browser::RegisterUserPrefs(otr_prefs);
222 NULL, // command_line_prefs
223 otr_user_prefs,
224 NULL, // recommended_platform_prefs,
225 NULL, // recommended_cloud_prefs,
226 default_prefs);
227 207
228 TestingProfile profile; 208 TestingProfile profile;
229 TestingProfile* otr_profile = new TestingProfile; 209 TestingProfile* otr_profile = new TestingProfile;
230 profile.SetOffTheRecordProfile(otr_profile); 210 profile.SetOffTheRecordProfile(otr_profile);
231 profile.SetPrefService(regular_prefs); 211 profile.SetPrefService(regular_prefs);
232 otr_profile->set_incognito(true); 212 otr_profile->set_incognito(true);
233 otr_profile->SetPrefService(otr_prefs); 213 otr_profile->SetPrefService(otr_prefs);
234 profile.GetHostContentSettingsMap(); 214 profile.GetHostContentSettingsMap();
235 215
236 PrefProvider pref_content_settings_provider(&profile); 216 PrefProvider pref_content_settings_provider(&profile);
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 CONTENT_SETTING_BLOCK); 325 CONTENT_SETTING_BLOCK);
346 EXPECT_EQ(CONTENT_SETTING_BLOCK, 326 EXPECT_EQ(CONTENT_SETTING_BLOCK,
347 pref_content_settings_provider.GetContentSetting( 327 pref_content_settings_provider.GetContentSetting(
348 host, host, CONTENT_SETTINGS_TYPE_PLUGINS, resource1)); 328 host, host, CONTENT_SETTINGS_TYPE_PLUGINS, resource1));
349 EXPECT_EQ(CONTENT_SETTING_DEFAULT, 329 EXPECT_EQ(CONTENT_SETTING_DEFAULT,
350 pref_content_settings_provider.GetContentSetting( 330 pref_content_settings_provider.GetContentSetting(
351 host, host, CONTENT_SETTINGS_TYPE_PLUGINS, resource2)); 331 host, host, CONTENT_SETTINGS_TYPE_PLUGINS, resource2));
352 } 332 }
353 333
354 } // namespace content_settings 334 } // namespace content_settings
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698