OLD | NEW |
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 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 175 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
176 GetContentSetting(&provider_, | 176 GetContentSetting(&provider_, |
177 GURL(), | 177 GURL(), |
178 GURL(), | 178 GURL(), |
179 CONTENT_SETTINGS_TYPE_COOKIES, | 179 CONTENT_SETTINGS_TYPE_COOKIES, |
180 std::string(), | 180 std::string(), |
181 false)); | 181 false)); |
182 } | 182 } |
183 | 183 |
184 TEST_F(DefaultProviderTest, OffTheRecord) { | 184 TEST_F(DefaultProviderTest, OffTheRecord) { |
185 content_settings::DefaultProvider otr_provider(profile_.GetPrefs(), true); | 185 content_settings::DefaultProvider otr_provider(profile_.GetPrefs(), |
| 186 true /* incognito */); |
186 | 187 |
187 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 188 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
188 GetContentSetting(&provider_, | 189 GetContentSetting(&provider_, |
189 GURL(), | 190 GURL(), |
190 GURL(), | 191 GURL(), |
191 CONTENT_SETTINGS_TYPE_COOKIES, | 192 CONTENT_SETTINGS_TYPE_COOKIES, |
192 std::string(), | 193 std::string(), |
193 false)); | 194 false /* include_incognito */)); |
194 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 195 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
195 GetContentSetting(&otr_provider, | 196 GetContentSetting(&otr_provider, |
196 GURL(), | 197 GURL(), |
197 GURL(), | 198 GURL(), |
198 CONTENT_SETTINGS_TYPE_COOKIES, | 199 CONTENT_SETTINGS_TYPE_COOKIES, |
199 std::string(), | 200 std::string(), |
200 true)); | 201 true /* include_incognito */)); |
201 | 202 |
202 // Changing content settings on the main provider should also affect the | 203 // Changing content settings on the main provider should also affect the |
203 // incognito map. | 204 // incognito map. |
204 provider_.SetWebsiteSetting( | 205 provider_.SetWebsiteSetting( |
205 ContentSettingsPattern::Wildcard(), | 206 ContentSettingsPattern::Wildcard(), |
206 ContentSettingsPattern::Wildcard(), | 207 ContentSettingsPattern::Wildcard(), |
207 CONTENT_SETTINGS_TYPE_COOKIES, | 208 CONTENT_SETTINGS_TYPE_COOKIES, |
208 std::string(), | 209 std::string(), |
209 new base::FundamentalValue(CONTENT_SETTING_BLOCK)); | 210 new base::FundamentalValue(CONTENT_SETTING_BLOCK)); |
210 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 211 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
211 GetContentSetting(&provider_, | 212 GetContentSetting(&provider_, |
212 GURL(), | 213 GURL(), |
213 GURL(), | 214 GURL(), |
214 CONTENT_SETTINGS_TYPE_COOKIES, | 215 CONTENT_SETTINGS_TYPE_COOKIES, |
215 std::string(), | 216 std::string(), |
216 false)); | 217 false /* include_incognito */)); |
217 | 218 |
218 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 219 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
219 GetContentSetting(&otr_provider, | 220 GetContentSetting(&otr_provider, |
220 GURL(), | 221 GURL(), |
221 GURL(), | 222 GURL(), |
222 CONTENT_SETTINGS_TYPE_COOKIES, | 223 CONTENT_SETTINGS_TYPE_COOKIES, |
223 std::string(), | 224 std::string(), |
224 true)); | 225 true /* include_incognito */)); |
225 | 226 |
226 // Changing content settings on the incognito provider should be ignored. | 227 // Changing content settings on the incognito provider should be ignored. |
227 scoped_ptr<base::Value> value( | 228 scoped_ptr<base::Value> value( |
228 new base::FundamentalValue(CONTENT_SETTING_ALLOW)); | 229 new base::FundamentalValue(CONTENT_SETTING_ALLOW)); |
229 bool owned = otr_provider.SetWebsiteSetting( | 230 bool owned = otr_provider.SetWebsiteSetting( |
230 ContentSettingsPattern::Wildcard(), | 231 ContentSettingsPattern::Wildcard(), |
231 ContentSettingsPattern::Wildcard(), | 232 ContentSettingsPattern::Wildcard(), |
232 CONTENT_SETTINGS_TYPE_COOKIES, | 233 CONTENT_SETTINGS_TYPE_COOKIES, |
233 std::string(), | 234 std::string(), |
234 value.get()); | 235 value.get()); |
235 EXPECT_FALSE(owned); | 236 EXPECT_FALSE(owned); |
236 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 237 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
237 GetContentSetting(&provider_, | 238 GetContentSetting(&provider_, |
238 GURL(), | 239 GURL(), |
239 GURL(), | 240 GURL(), |
240 CONTENT_SETTINGS_TYPE_COOKIES, | 241 CONTENT_SETTINGS_TYPE_COOKIES, |
241 std::string(), | 242 std::string(), |
242 false)); | 243 false /* include_incognito */)); |
243 | 244 |
244 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 245 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
245 GetContentSetting(&otr_provider, | 246 GetContentSetting(&otr_provider, |
246 GURL(), | 247 GURL(), |
247 GURL(), | 248 GURL(), |
248 CONTENT_SETTINGS_TYPE_COOKIES, | 249 CONTENT_SETTINGS_TYPE_COOKIES, |
249 std::string(), | 250 std::string(), |
250 true)); | 251 true /* include_incognito */)); |
| 252 |
| 253 // Check that new OTR DefaultProviders also inherit the correct value. |
| 254 content_settings::DefaultProvider otr_provider2(profile_.GetPrefs(), |
| 255 true /* incognito */); |
| 256 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 257 GetContentSetting(&otr_provider2, |
| 258 GURL(), |
| 259 GURL(), |
| 260 CONTENT_SETTINGS_TYPE_COOKIES, |
| 261 std::string(), |
| 262 true /* include_incognito */)); |
| 263 |
251 otr_provider.ShutdownOnUIThread(); | 264 otr_provider.ShutdownOnUIThread(); |
| 265 otr_provider2.ShutdownOnUIThread(); |
252 } | 266 } |
OLD | NEW |