OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/pref_content_settings_provider.h" | 5 #include "chrome/browser/content_settings/pref_content_settings_provider.h" |
6 | 6 |
| 7 #include "base/auto_reset.h" |
| 8 #include "base/command_line.h" |
7 #include "chrome/browser/content_settings/host_content_settings_map_unittest.h" | 9 #include "chrome/browser/content_settings/host_content_settings_map_unittest.h" |
8 #include "chrome/browser/prefs/pref_service.h" | 10 #include "chrome/browser/prefs/pref_service.h" |
| 11 #include "chrome/common/chrome_switches.h" |
9 #include "chrome/common/pref_names.h" | 12 #include "chrome/common/pref_names.h" |
10 #include "chrome/common/url_constants.h" | 13 #include "chrome/common/url_constants.h" |
11 #include "chrome/test/testing_pref_service.h" | 14 #include "chrome/test/testing_pref_service.h" |
12 #include "chrome/test/testing_profile.h" | 15 #include "chrome/test/testing_profile.h" |
13 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
14 | 17 |
15 | 18 |
16 namespace content_settings { | 19 namespace content_settings { |
17 | 20 |
18 class PrefDefaultProviderTest : public testing::Test { | 21 class PrefDefaultProviderTest : public testing::Test { |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 | 115 |
113 // Changing content settings on the off-the-record provider should be ignored. | 116 // Changing content settings on the off-the-record provider should be ignored. |
114 otr_provider.UpdateDefaultSetting(CONTENT_SETTINGS_TYPE_COOKIES, | 117 otr_provider.UpdateDefaultSetting(CONTENT_SETTINGS_TYPE_COOKIES, |
115 CONTENT_SETTING_ALLOW); | 118 CONTENT_SETTING_ALLOW); |
116 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 119 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
117 provider.ProvideDefaultSetting(CONTENT_SETTINGS_TYPE_COOKIES)); | 120 provider.ProvideDefaultSetting(CONTENT_SETTINGS_TYPE_COOKIES)); |
118 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 121 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
119 otr_provider.ProvideDefaultSetting(CONTENT_SETTINGS_TYPE_COOKIES)); | 122 otr_provider.ProvideDefaultSetting(CONTENT_SETTINGS_TYPE_COOKIES)); |
120 } | 123 } |
121 | 124 |
| 125 // //////////////////////////////////////////////////////////////////////////// |
| 126 // PrefContentSettingsProviderTest |
| 127 // |
| 128 |
| 129 bool SettingsEqual(const ContentSettings& settings1, |
| 130 const ContentSettings& settings2) { |
| 131 for (int i = 0; i < CONTENT_SETTINGS_NUM_TYPES; ++i) { |
| 132 if (settings1.settings[i] != settings2.settings[i]) |
| 133 return false; |
| 134 } |
| 135 return true; |
| 136 } |
| 137 |
| 138 class PrefProviderTest : public testing::Test { |
| 139 public: |
| 140 PrefProviderTest() : ui_thread_( |
| 141 BrowserThread::UI, &message_loop_) { |
| 142 } |
| 143 |
| 144 protected: |
| 145 MessageLoop message_loop_; |
| 146 BrowserThread ui_thread_; |
| 147 }; |
| 148 |
| 149 /* |
| 150 TEST_F(PrefContentSettingsProviderTest, Observer) { |
| 151 TestingProfile profile; |
| 152 Profile* p = &profile; |
| 153 PrefContentSettingsProvider pref_content_settings_provider(p); |
| 154 StubSettingsObserver observer; |
| 155 ContentSettingsPattern pattern("[*.]example.com"); |
| 156 pref_content_settings_provider.SetContentSetting( |
| 157 pattern, |
| 158 pattern, |
| 159 CONTENT_SETTINGS_TYPE_IMAGES, |
| 160 "", |
| 161 CONTENT_SETTING_ALLOW); |
| 162 EXPECT_EQ(&pref_content_settings_provider, observer.last_notifier); |
| 163 EXPECT_EQ(pattern, observer.last_pattern); |
| 164 EXPECT_FALSE(observer.last_update_all); |
| 165 EXPECT_FALSE(observer.last_update_all_types); |
| 166 EXPECT_EQ(1, observer.counter); |
| 167 |
| 168 pref_content_settings_provider.ClearSettingsForOneType( |
| 169 CONTENT_SETTINGS_TYPE_IMAGES); |
| 170 EXPECT_EQ(host_content_settings_map, observer.last_notifier); |
| 171 EXPECT_TRUE(observer.last_update_all); |
| 172 EXPECT_FALSE(observer.last_update_all_types); |
| 173 EXPECT_EQ(2, observer.counter); |
| 174 |
| 175 host_content_settings_map->ResetToDefaults(); |
| 176 EXPECT_EQ(host_content_settings_map, observer.last_notifier); |
| 177 EXPECT_TRUE(observer.last_update_all); |
| 178 EXPECT_TRUE(observer.last_update_all_types); |
| 179 EXPECT_EQ(3, observer.counter); |
| 180 |
| 181 host_content_settings_map->SetDefaultContentSetting( |
| 182 CONTENT_SETTINGS_TYPE_IMAGES, CONTENT_SETTING_BLOCK); |
| 183 EXPECT_EQ(host_content_settings_map, observer.last_notifier); |
| 184 EXPECT_TRUE(observer.last_update_all); |
| 185 EXPECT_FALSE(observer.last_update_all_types); |
| 186 EXPECT_EQ(4, observer.counter); |
| 187 } |
| 188 */ |
| 189 |
| 190 TEST_F(PrefProviderTest, Patterns) { |
| 191 TestingProfile testing_profile; |
| 192 PrefProvider pref_content_settings_provider( |
| 193 testing_profile.GetOriginalProfile()); |
| 194 |
| 195 GURL host1("http://example.com/"); |
| 196 GURL host2("http://www.example.com/"); |
| 197 GURL host3("http://example.org/"); |
| 198 ContentSettingsPattern pattern1("[*.]example.com"); |
| 199 ContentSettingsPattern pattern2("example.org"); |
| 200 |
| 201 EXPECT_EQ(CONTENT_SETTING_DEFAULT, |
| 202 pref_content_settings_provider.GetContentSetting( |
| 203 host1, host1, CONTENT_SETTINGS_TYPE_IMAGES, "")); |
| 204 pref_content_settings_provider.SetContentSetting( |
| 205 pattern1, |
| 206 pattern1, |
| 207 CONTENT_SETTINGS_TYPE_IMAGES, |
| 208 "", |
| 209 CONTENT_SETTING_BLOCK); |
| 210 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 211 pref_content_settings_provider.GetContentSetting( |
| 212 host1, host1, CONTENT_SETTINGS_TYPE_IMAGES, "")); |
| 213 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 214 pref_content_settings_provider.GetContentSetting( |
| 215 host2, host2, CONTENT_SETTINGS_TYPE_IMAGES, "")); |
| 216 |
| 217 EXPECT_EQ(CONTENT_SETTING_DEFAULT, |
| 218 pref_content_settings_provider.GetContentSetting( |
| 219 host3, host3, CONTENT_SETTINGS_TYPE_IMAGES, "")); |
| 220 pref_content_settings_provider.SetContentSetting( |
| 221 pattern2, |
| 222 pattern2, |
| 223 CONTENT_SETTINGS_TYPE_IMAGES, |
| 224 "", |
| 225 CONTENT_SETTING_BLOCK); |
| 226 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 227 pref_content_settings_provider.GetContentSetting( |
| 228 host3, host3, CONTENT_SETTINGS_TYPE_IMAGES, "")); |
| 229 } |
| 230 |
| 231 TEST_F(PrefProviderTest, ResourceIdentifier) { |
| 232 // This feature is currently behind a flag. |
| 233 CommandLine* cmd = CommandLine::ForCurrentProcess(); |
| 234 AutoReset<CommandLine> auto_reset(cmd, *cmd); |
| 235 cmd->AppendSwitch(switches::kEnableResourceContentSettings); |
| 236 |
| 237 TestingProfile testing_profile; |
| 238 PrefProvider pref_content_settings_provider( |
| 239 testing_profile.GetOriginalProfile()); |
| 240 |
| 241 GURL host("http://example.com/"); |
| 242 ContentSettingsPattern pattern("[*.]example.com"); |
| 243 std::string resource1("someplugin"); |
| 244 std::string resource2("otherplugin"); |
| 245 |
| 246 EXPECT_EQ(CONTENT_SETTING_DEFAULT, |
| 247 pref_content_settings_provider.GetContentSetting( |
| 248 host, host, CONTENT_SETTINGS_TYPE_PLUGINS, resource1)); |
| 249 pref_content_settings_provider.SetContentSetting( |
| 250 pattern, |
| 251 pattern, |
| 252 CONTENT_SETTINGS_TYPE_PLUGINS, |
| 253 resource1, |
| 254 CONTENT_SETTING_BLOCK); |
| 255 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 256 pref_content_settings_provider.GetContentSetting( |
| 257 host, host, CONTENT_SETTINGS_TYPE_PLUGINS, resource1)); |
| 258 EXPECT_EQ(CONTENT_SETTING_DEFAULT, |
| 259 pref_content_settings_provider.GetContentSetting( |
| 260 host, host, CONTENT_SETTINGS_TYPE_PLUGINS, resource2)); |
| 261 } |
| 262 |
122 } // namespace content_settings | 263 } // namespace content_settings |
OLD | NEW |