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

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

Issue 1252973002: Remove the migration code from content_settings::DefaultProvider. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 5 years, 4 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
« no previous file with comments | « no previous file | chrome/browser/content_settings/host_content_settings_map_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "base/memory/scoped_ptr.h" 5 #include "base/memory/scoped_ptr.h"
6 #include "base/message_loop/message_loop.h" 6 #include "base/message_loop/message_loop.h"
7 #include "base/prefs/pref_service.h" 7 #include "base/prefs/pref_service.h"
8 #include "base/prefs/scoped_user_pref_update.h" 8 #include "base/prefs/scoped_user_pref_update.h"
9 #include "base/prefs/testing_pref_service.h" 9 #include "base/prefs/testing_pref_service.h"
10 #include "chrome/browser/content_settings/content_settings_mock_observer.h" 10 #include "chrome/browser/content_settings/content_settings_mock_observer.h"
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 _, _, CONTENT_SETTINGS_TYPE_GEOLOCATION, "")); 133 _, _, CONTENT_SETTINGS_TYPE_GEOLOCATION, ""));
134 provider_.SetWebsiteSetting( 134 provider_.SetWebsiteSetting(
135 ContentSettingsPattern::Wildcard(), 135 ContentSettingsPattern::Wildcard(),
136 ContentSettingsPattern::Wildcard(), 136 ContentSettingsPattern::Wildcard(),
137 CONTENT_SETTINGS_TYPE_GEOLOCATION, 137 CONTENT_SETTINGS_TYPE_GEOLOCATION,
138 std::string(), 138 std::string(),
139 new base::FundamentalValue(CONTENT_SETTING_BLOCK)); 139 new base::FundamentalValue(CONTENT_SETTING_BLOCK));
140 } 140 }
141 141
142 142
143 TEST_F(DefaultProviderTest, ObserveDefaultPref) { 143 TEST_F(DefaultProviderTest, ObservePref) {
144 PrefService* prefs = profile_.GetPrefs(); 144 PrefService* prefs = profile_.GetPrefs();
145 145
146 // Make a copy of the default pref value so we can reset it later.
147 scoped_ptr<base::Value> default_value(prefs->FindPreference(
148 prefs::kDefaultContentSettings)->GetValue()->DeepCopy());
149
150 provider_.SetWebsiteSetting( 146 provider_.SetWebsiteSetting(
151 ContentSettingsPattern::Wildcard(), 147 ContentSettingsPattern::Wildcard(),
152 ContentSettingsPattern::Wildcard(), 148 ContentSettingsPattern::Wildcard(),
153 CONTENT_SETTINGS_TYPE_COOKIES, 149 CONTENT_SETTINGS_TYPE_COOKIES,
154 std::string(), 150 std::string(),
155 new base::FundamentalValue(CONTENT_SETTING_BLOCK)); 151 new base::FundamentalValue(CONTENT_SETTING_BLOCK));
156 EXPECT_EQ(CONTENT_SETTING_BLOCK, 152 EXPECT_EQ(CONTENT_SETTING_BLOCK,
157 GetContentSetting(&provider_, 153 GetContentSetting(&provider_,
158 GURL(), 154 GURL(),
159 GURL(), 155 GURL(),
160 CONTENT_SETTINGS_TYPE_COOKIES, 156 CONTENT_SETTINGS_TYPE_COOKIES,
161 std::string(), 157 std::string(),
162 false)); 158 false));
163 159
164 // Make a copy of the pref's new value so we can reset it later.
165 scoped_ptr<base::Value> new_value(prefs->FindPreference(
166 prefs::kDefaultContentSettings)->GetValue()->DeepCopy());
167
168 // Clearing the backing pref should also clear the internal cache. 160 // Clearing the backing pref should also clear the internal cache.
169 prefs->Set(prefs::kDefaultContentSettings, *default_value); 161 prefs->ClearPref(prefs::kDefaultCookiesSetting);
170 EXPECT_EQ(CONTENT_SETTING_ALLOW, 162 EXPECT_EQ(CONTENT_SETTING_ALLOW,
171 GetContentSetting(&provider_, 163 GetContentSetting(&provider_,
172 GURL(), 164 GURL(),
173 GURL(), 165 GURL(),
174 CONTENT_SETTINGS_TYPE_COOKIES, 166 CONTENT_SETTINGS_TYPE_COOKIES,
175 std::string(), 167 std::string(),
176 false)); 168 false));
177 // Reseting the pref to its previous value should update the cache. 169 // Reseting the pref to its previous value should update the cache.
178 prefs->Set(prefs::kDefaultContentSettings, *new_value); 170 prefs->SetInteger(prefs::kDefaultCookiesSetting, CONTENT_SETTING_BLOCK);
179 EXPECT_EQ(CONTENT_SETTING_BLOCK, 171 EXPECT_EQ(CONTENT_SETTING_BLOCK,
180 GetContentSetting(&provider_, 172 GetContentSetting(&provider_,
181 GURL(), 173 GURL(),
182 GURL(), 174 GURL(),
183 CONTENT_SETTINGS_TYPE_COOKIES, 175 CONTENT_SETTINGS_TYPE_COOKIES,
184 std::string(), 176 std::string(),
185 false)); 177 false));
186 } 178 }
187 179
188 TEST_F(DefaultProviderTest, OffTheRecord) { 180 TEST_F(DefaultProviderTest, OffTheRecord) {
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 239
248 EXPECT_EQ(CONTENT_SETTING_BLOCK, 240 EXPECT_EQ(CONTENT_SETTING_BLOCK,
249 GetContentSetting(&otr_provider, 241 GetContentSetting(&otr_provider,
250 GURL(), 242 GURL(),
251 GURL(), 243 GURL(),
252 CONTENT_SETTINGS_TYPE_COOKIES, 244 CONTENT_SETTINGS_TYPE_COOKIES,
253 std::string(), 245 std::string(),
254 true)); 246 true));
255 otr_provider.ShutdownOnUIThread(); 247 otr_provider.ShutdownOnUIThread();
256 } 248 }
257
258
259 // TODO(msramek): The two tests below test syncing between old versions
260 // of Chrome using a dictionary pref and new versions using individual integer
261 // prefs for default content settings. Remove the tests together with
262 // the dictionary setting after two stable releases.
263 TEST_F(DefaultProviderTest, SyncFromDictionaryToIndividualPreferences) {
264 PrefService* prefs = profile_.GetPrefs();
265
266 {
267 DictionaryPrefUpdate update(prefs, prefs::kDefaultContentSettings);
268 base::DictionaryValue* default_settings_dictionary = update.Get();
269
270 default_settings_dictionary->SetWithoutPathExpansion(
271 content_settings::GetTypeName(CONTENT_SETTINGS_TYPE_COOKIES),
272 new base::FundamentalValue(CONTENT_SETTING_BLOCK));
273 default_settings_dictionary->SetWithoutPathExpansion(
274 content_settings::GetTypeName(CONTENT_SETTINGS_TYPE_GEOLOCATION),
275 new base::FundamentalValue(CONTENT_SETTING_BLOCK));
276 }
277
278 // Cookies should sync, but geolocation should not.
279 EXPECT_EQ(CONTENT_SETTING_BLOCK, IntToContentSetting(
280 prefs->GetInteger(prefs::kDefaultCookiesSetting)));
281 EXPECT_EQ(CONTENT_SETTING_ASK, IntToContentSetting(
282 prefs->GetInteger(prefs::kDefaultGeolocationSetting)));
283 }
284
285 TEST_F(DefaultProviderTest, SyncFromIndividualPreferencesToDictionary) {
286 PrefService* prefs = profile_.GetPrefs();
287
288 prefs->SetInteger(prefs::kDefaultJavaScriptSetting, CONTENT_SETTING_BLOCK);
289 prefs->SetInteger(prefs::kDefaultSSLCertDecisionsSetting,
290 CONTENT_SETTING_BLOCK);
291
292 // Javascript should sync, but cert decisions should not.
293 const base::DictionaryValue* default_settings_dictionary =
294 prefs->GetDictionary(prefs::kDefaultContentSettings);
295 int js_setting;
296 bool has_cd_setting;
297
298 default_settings_dictionary->GetIntegerWithoutPathExpansion(
299 content_settings::GetTypeName(CONTENT_SETTINGS_TYPE_JAVASCRIPT),
300 &js_setting);
301 has_cd_setting = default_settings_dictionary->HasKey(
302 content_settings::GetTypeName(CONTENT_SETTINGS_TYPE_SSL_CERT_DECISIONS));
303
304 EXPECT_EQ(CONTENT_SETTING_BLOCK, IntToContentSetting(js_setting));
305 EXPECT_FALSE(has_cd_setting);
306 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/content_settings/host_content_settings_map_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698