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/auto_reset.h" | 5 #include "base/auto_reset.h" |
6 #include "base/command_line.h" | 6 #include "base/command_line.h" |
7 #include "base/json/json_reader.h" | 7 #include "base/json/json_reader.h" |
8 #include "base/json/json_writer.h" | 8 #include "base/json/json_writer.h" |
9 #include "chrome/browser/content_settings/content_settings_details.h" | 9 #include "chrome/browser/content_settings/content_settings_details.h" |
10 #include "chrome/browser/content_settings/host_content_settings_map.h" | 10 #include "chrome/browser/content_settings/host_content_settings_map.h" |
11 #include "chrome/browser/content_settings/stub_settings_observer.h" | 11 #include "chrome/browser/content_settings/mock_settings_observer.h" |
12 #include "chrome/browser/prefs/pref_service.h" | 12 #include "chrome/browser/prefs/pref_service.h" |
13 #include "chrome/browser/prefs/scoped_user_pref_update.h" | 13 #include "chrome/browser/prefs/scoped_user_pref_update.h" |
14 #include "chrome/common/chrome_switches.h" | 14 #include "chrome/common/chrome_switches.h" |
15 #include "chrome/common/pref_names.h" | 15 #include "chrome/common/pref_names.h" |
16 #include "chrome/common/url_constants.h" | 16 #include "chrome/common/url_constants.h" |
17 #include "chrome/test/testing_browser_process_test.h" | 17 #include "chrome/test/testing_browser_process_test.h" |
18 #include "chrome/test/testing_pref_service.h" | 18 #include "chrome/test/testing_pref_service.h" |
19 #include "chrome/test/testing_profile.h" | 19 #include "chrome/test/testing_profile.h" |
20 #include "googleurl/src/gurl.h" | 20 #include "googleurl/src/gurl.h" |
21 #include "net/base/static_cookie_policy.h" | 21 #include "net/base/static_cookie_policy.h" |
22 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
23 | 23 |
| 24 using ::testing::_; |
| 25 |
24 namespace { | 26 namespace { |
25 | 27 |
26 bool SettingsEqual(const ContentSettings& settings1, | 28 bool SettingsEqual(const ContentSettings& settings1, |
27 const ContentSettings& settings2) { | 29 const ContentSettings& settings2) { |
28 for (int i = 0; i < CONTENT_SETTINGS_NUM_TYPES; ++i) { | 30 for (int i = 0; i < CONTENT_SETTINGS_NUM_TYPES; ++i) { |
29 if (settings1.settings[i] != settings2.settings[i]) | 31 if (settings1.settings[i] != settings2.settings[i]) |
30 return false; | 32 return false; |
31 } | 33 } |
32 return true; | 34 return true; |
33 } | 35 } |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 CONTENT_SETTINGS_TYPE_IMAGES, "", CONTENT_SETTING_BLOCK); | 208 CONTENT_SETTINGS_TYPE_IMAGES, "", CONTENT_SETTING_BLOCK); |
207 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 209 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
208 host_content_settings_map->GetContentSetting( | 210 host_content_settings_map->GetContentSetting( |
209 host3, CONTENT_SETTINGS_TYPE_IMAGES, "")); | 211 host3, CONTENT_SETTINGS_TYPE_IMAGES, "")); |
210 } | 212 } |
211 | 213 |
212 TEST_F(HostContentSettingsMapTest, Observer) { | 214 TEST_F(HostContentSettingsMapTest, Observer) { |
213 TestingProfile profile; | 215 TestingProfile profile; |
214 HostContentSettingsMap* host_content_settings_map = | 216 HostContentSettingsMap* host_content_settings_map = |
215 profile.GetHostContentSettingsMap(); | 217 profile.GetHostContentSettingsMap(); |
216 StubSettingsObserver observer; | 218 MockSettingsObserver observer; |
217 | 219 |
218 ContentSettingsPattern pattern = | 220 ContentSettingsPattern pattern = |
219 ContentSettingsPattern::FromString("[*.]example.com"); | 221 ContentSettingsPattern::FromString("[*.]example.com"); |
| 222 EXPECT_CALL(observer, |
| 223 OnContentSettingsChanged(host_content_settings_map, |
| 224 CONTENT_SETTINGS_TYPE_IMAGES, false, |
| 225 pattern, false)); |
220 host_content_settings_map->SetContentSetting(pattern, | 226 host_content_settings_map->SetContentSetting(pattern, |
221 CONTENT_SETTINGS_TYPE_IMAGES, "", CONTENT_SETTING_ALLOW); | 227 CONTENT_SETTINGS_TYPE_IMAGES, "", CONTENT_SETTING_ALLOW); |
222 EXPECT_EQ(host_content_settings_map, observer.last_notifier); | 228 ::testing::Mock::VerifyAndClearExpectations(&observer); |
223 EXPECT_EQ(pattern, observer.last_pattern); | |
224 EXPECT_FALSE(observer.last_update_all); | |
225 EXPECT_FALSE(observer.last_update_all_types); | |
226 EXPECT_EQ(1, observer.counter); | |
227 | 229 |
| 230 EXPECT_CALL(observer, |
| 231 OnContentSettingsChanged(host_content_settings_map, |
| 232 CONTENT_SETTINGS_TYPE_IMAGES, false, |
| 233 _, true)); |
228 host_content_settings_map->ClearSettingsForOneType( | 234 host_content_settings_map->ClearSettingsForOneType( |
229 CONTENT_SETTINGS_TYPE_IMAGES); | 235 CONTENT_SETTINGS_TYPE_IMAGES); |
230 EXPECT_EQ(host_content_settings_map, observer.last_notifier); | 236 ::testing::Mock::VerifyAndClearExpectations(&observer); |
231 EXPECT_TRUE(observer.last_update_all); | |
232 EXPECT_FALSE(observer.last_update_all_types); | |
233 EXPECT_EQ(2, observer.counter); | |
234 | 237 |
| 238 EXPECT_CALL(observer, |
| 239 OnContentSettingsChanged(host_content_settings_map, |
| 240 CONTENT_SETTINGS_TYPE_IMAGES, false, |
| 241 _, true)); |
235 host_content_settings_map->SetDefaultContentSetting( | 242 host_content_settings_map->SetDefaultContentSetting( |
236 CONTENT_SETTINGS_TYPE_IMAGES, CONTENT_SETTING_BLOCK); | 243 CONTENT_SETTINGS_TYPE_IMAGES, CONTENT_SETTING_BLOCK); |
237 EXPECT_EQ(host_content_settings_map, observer.last_notifier); | |
238 EXPECT_TRUE(observer.last_update_all); | |
239 EXPECT_FALSE(observer.last_update_all_types); | |
240 EXPECT_EQ(3, observer.counter); | |
241 } | 244 } |
242 | 245 |
243 TEST_F(HostContentSettingsMapTest, ObserveDefaultPref) { | 246 TEST_F(HostContentSettingsMapTest, ObserveDefaultPref) { |
244 TestingProfile profile; | 247 TestingProfile profile; |
245 HostContentSettingsMap* host_content_settings_map = | 248 HostContentSettingsMap* host_content_settings_map = |
246 profile.GetHostContentSettingsMap(); | 249 profile.GetHostContentSettingsMap(); |
247 | 250 |
248 PrefService* prefs = profile.GetPrefs(); | 251 PrefService* prefs = profile.GetPrefs(); |
249 | 252 |
250 // Make a copy of the default pref value so we can reset it later. | 253 // Make a copy of the default pref value so we can reset it later. |
(...skipping 810 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1061 kAllowedSite, kFirstPartySite, true)); | 1064 kAllowedSite, kFirstPartySite, true)); |
1062 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 1065 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
1063 host_content_settings_map->GetCookieContentSetting( | 1066 host_content_settings_map->GetCookieContentSetting( |
1064 kAllowedSite, kAllowedSite, false)); | 1067 kAllowedSite, kAllowedSite, false)); |
1065 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 1068 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
1066 host_content_settings_map->GetCookieContentSetting( | 1069 host_content_settings_map->GetCookieContentSetting( |
1067 kAllowedSite, kAllowedSite, true)); | 1070 kAllowedSite, kAllowedSite, true)); |
1068 } | 1071 } |
1069 | 1072 |
1070 } // namespace | 1073 } // namespace |
OLD | NEW |