Chromium Code Reviews| 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 // PrefProviderTest | |
| 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 TEST_F(PrefProviderTest, Observer) { | |
| 150 TestingProfile profile; | |
| 151 Profile* p = &profile; | |
| 152 PrefProvider pref_content_settings_provider(p); | |
| 153 StubSettingsObserver observer; | |
| 154 ContentSettingsPattern pattern("[*.]example.com"); | |
| 155 pref_content_settings_provider.SetContentSetting( | |
| 156 pattern, | |
| 157 pattern, | |
| 158 CONTENT_SETTINGS_TYPE_IMAGES, | |
| 159 "", | |
| 160 CONTENT_SETTING_ALLOW); | |
| 161 EXPECT_EQ(profile.GetHostContentSettingsMap(), observer.last_notifier); | |
| 162 EXPECT_EQ(pattern, observer.last_pattern); | |
| 163 EXPECT_FALSE(observer.last_update_all); | |
| 164 EXPECT_FALSE(observer.last_update_all_types); | |
| 165 EXPECT_EQ(1, observer.counter); | |
| 166 | |
| 167 /* | |
|
Bernhard Bauer
2011/02/07 09:46:46
Ugh. Code that's commented out usually should be r
| |
| 168 pref_content_settings_provider.ClearAllContentSettingsRules( | |
| 169 CONTENT_SETTINGS_TYPE_IMAGES); | |
| 170 EXPECT_EQ(profile.GetHostContentSettingsMap(), 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 pref_content_settings_provider.ResetToDefaults(); | |
| 176 EXPECT_EQ(2, observer.counter); | |
| 177 | |
| 178 pref_content_settings_provider.SetContentSetting( | |
| 179 pattern, | |
| 180 pattern, | |
| 181 CONTENT_SETTINGS_TYPE_IMAGES, | |
| 182 "", | |
| 183 CONTENT_SETTING_BLOCK); | |
| 184 EXPECT_EQ(profile.GetHostContentSettingsMap(), observer.last_notifier); | |
| 185 EXPECT_TRUE(observer.last_update_all); | |
| 186 EXPECT_FALSE(observer.last_update_all_types); | |
| 187 EXPECT_EQ(3, observer.counter); | |
| 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 |