| 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 "chrome/browser/content_settings/content_settings_default_provider.h" | 6 #include "chrome/browser/content_settings/content_settings_default_provider.h" |
| 7 #include "chrome/browser/content_settings/content_settings_mock_observer.h" | 7 #include "chrome/browser/content_settings/content_settings_mock_observer.h" |
| 8 #include "chrome/browser/content_settings/content_settings_utils.h" | 8 #include "chrome/browser/content_settings/content_settings_utils.h" |
| 9 #include "chrome/browser/prefs/pref_service.h" | 9 #include "chrome/browser/prefs/pref_service.h" |
| 10 #include "chrome/common/pref_names.h" | 10 #include "chrome/common/pref_names.h" |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 | 36 |
| 37 TEST_F(DefaultProviderTest, DefaultValues) { | 37 TEST_F(DefaultProviderTest, DefaultValues) { |
| 38 // Check setting defaults. | 38 // Check setting defaults. |
| 39 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 39 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 40 GetContentSetting(&provider_, | 40 GetContentSetting(&provider_, |
| 41 GURL(), | 41 GURL(), |
| 42 GURL(), | 42 GURL(), |
| 43 CONTENT_SETTINGS_TYPE_COOKIES, | 43 CONTENT_SETTINGS_TYPE_COOKIES, |
| 44 std::string(), | 44 std::string(), |
| 45 false)); | 45 false)); |
| 46 provider_.SetContentSetting(ContentSettingsPattern::Wildcard(), | 46 provider_.SetWebsiteSetting( |
| 47 ContentSettingsPattern::Wildcard(), | 47 ContentSettingsPattern::Wildcard(), |
| 48 CONTENT_SETTINGS_TYPE_COOKIES, | 48 ContentSettingsPattern::Wildcard(), |
| 49 std::string(), | 49 CONTENT_SETTINGS_TYPE_COOKIES, |
| 50 CONTENT_SETTING_BLOCK); | 50 std::string(), |
| 51 Value::CreateIntegerValue(CONTENT_SETTING_BLOCK)); |
| 51 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 52 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 52 GetContentSetting(&provider_, | 53 GetContentSetting(&provider_, |
| 53 GURL(), | 54 GURL(), |
| 54 GURL(), | 55 GURL(), |
| 55 CONTENT_SETTINGS_TYPE_COOKIES, | 56 CONTENT_SETTINGS_TYPE_COOKIES, |
| 56 std::string(), | 57 std::string(), |
| 57 false)); | 58 false)); |
| 58 | 59 |
| 59 EXPECT_EQ(CONTENT_SETTING_ASK, | 60 EXPECT_EQ(CONTENT_SETTING_ASK, |
| 60 GetContentSetting(&provider_, | 61 GetContentSetting(&provider_, |
| 61 GURL(), | 62 GURL(), |
| 62 GURL(), | 63 GURL(), |
| 63 CONTENT_SETTINGS_TYPE_GEOLOCATION, | 64 CONTENT_SETTINGS_TYPE_GEOLOCATION, |
| 64 std::string(), | 65 std::string(), |
| 65 false)); | 66 false)); |
| 66 provider_.SetContentSetting(ContentSettingsPattern::Wildcard(), | 67 provider_.SetWebsiteSetting( |
| 67 ContentSettingsPattern::Wildcard(), | 68 ContentSettingsPattern::Wildcard(), |
| 68 CONTENT_SETTINGS_TYPE_GEOLOCATION, | 69 ContentSettingsPattern::Wildcard(), |
| 69 std::string(), | 70 CONTENT_SETTINGS_TYPE_GEOLOCATION, |
| 70 CONTENT_SETTING_BLOCK); | 71 std::string(), |
| 72 Value::CreateIntegerValue(CONTENT_SETTING_BLOCK)); |
| 71 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 73 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 72 GetContentSetting(&provider_, | 74 GetContentSetting(&provider_, |
| 73 GURL(), | 75 GURL(), |
| 74 GURL(), | 76 GURL(), |
| 75 CONTENT_SETTINGS_TYPE_GEOLOCATION, | 77 CONTENT_SETTINGS_TYPE_GEOLOCATION, |
| 76 std::string(), | 78 std::string(), |
| 77 false)); | 79 false)); |
| 78 } | 80 } |
| 79 | 81 |
| 80 TEST_F(DefaultProviderTest, IgnoreNonDefaultSettings) { | 82 TEST_F(DefaultProviderTest, IgnoreNonDefaultSettings) { |
| 81 GURL primary_url("http://www.google.com"); | 83 GURL primary_url("http://www.google.com"); |
| 82 GURL secondary_url("http://www.google.com"); | 84 GURL secondary_url("http://www.google.com"); |
| 83 | 85 |
| 84 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 86 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 85 GetContentSetting(&provider_, | 87 GetContentSetting(&provider_, |
| 86 primary_url, | 88 primary_url, |
| 87 secondary_url, | 89 secondary_url, |
| 88 CONTENT_SETTINGS_TYPE_COOKIES, | 90 CONTENT_SETTINGS_TYPE_COOKIES, |
| 89 std::string(), | 91 std::string(), |
| 90 false)); | 92 false)); |
| 91 provider_.SetContentSetting(ContentSettingsPattern::FromURL(primary_url), | 93 scoped_ptr<base::Value> value( |
| 92 ContentSettingsPattern::FromURL(secondary_url), | 94 Value::CreateIntegerValue(CONTENT_SETTING_BLOCK)); |
| 93 CONTENT_SETTINGS_TYPE_COOKIES, | 95 bool owned = provider_.SetWebsiteSetting( |
| 94 std::string(), | 96 ContentSettingsPattern::FromURL(primary_url), |
| 95 CONTENT_SETTING_BLOCK); | 97 ContentSettingsPattern::FromURL(secondary_url), |
| 98 CONTENT_SETTINGS_TYPE_COOKIES, |
| 99 std::string(), |
| 100 value.get()); |
| 101 EXPECT_FALSE(owned); |
| 96 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 102 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 97 GetContentSetting(&provider_, | 103 GetContentSetting(&provider_, |
| 98 primary_url, | 104 primary_url, |
| 99 secondary_url, | 105 secondary_url, |
| 100 CONTENT_SETTINGS_TYPE_COOKIES, | 106 CONTENT_SETTINGS_TYPE_COOKIES, |
| 101 std::string(), | 107 std::string(), |
| 102 false)); | 108 false)); |
| 103 } | 109 } |
| 104 | 110 |
| 105 TEST_F(DefaultProviderTest, Observer) { | 111 TEST_F(DefaultProviderTest, Observer) { |
| 106 content_settings::MockObserver mock_observer; | 112 content_settings::MockObserver mock_observer; |
| 107 EXPECT_CALL(mock_observer, | 113 EXPECT_CALL(mock_observer, |
| 108 OnContentSettingChanged( | 114 OnContentSettingChanged( |
| 109 _, _, CONTENT_SETTINGS_TYPE_IMAGES, "")); | 115 _, _, CONTENT_SETTINGS_TYPE_IMAGES, "")); |
| 110 provider_.AddObserver(&mock_observer); | 116 provider_.AddObserver(&mock_observer); |
| 111 provider_.SetContentSetting(ContentSettingsPattern::Wildcard(), | 117 provider_.SetWebsiteSetting( |
| 112 ContentSettingsPattern::Wildcard(), | 118 ContentSettingsPattern::Wildcard(), |
| 113 CONTENT_SETTINGS_TYPE_IMAGES, | 119 ContentSettingsPattern::Wildcard(), |
| 114 std::string(), | 120 CONTENT_SETTINGS_TYPE_IMAGES, |
| 115 CONTENT_SETTING_BLOCK); | 121 std::string(), |
| 122 Value::CreateIntegerValue(CONTENT_SETTING_BLOCK)); |
| 116 | 123 |
| 117 EXPECT_CALL(mock_observer, | 124 EXPECT_CALL(mock_observer, |
| 118 OnContentSettingChanged( | 125 OnContentSettingChanged( |
| 119 _, _, CONTENT_SETTINGS_TYPE_GEOLOCATION, "")); | 126 _, _, CONTENT_SETTINGS_TYPE_GEOLOCATION, "")); |
| 120 provider_.SetContentSetting(ContentSettingsPattern::Wildcard(), | 127 provider_.SetWebsiteSetting( |
| 121 ContentSettingsPattern::Wildcard(), | 128 ContentSettingsPattern::Wildcard(), |
| 122 CONTENT_SETTINGS_TYPE_GEOLOCATION, | 129 ContentSettingsPattern::Wildcard(), |
| 123 std::string(), | 130 CONTENT_SETTINGS_TYPE_GEOLOCATION, |
| 124 CONTENT_SETTING_BLOCK); | 131 std::string(), |
| 132 Value::CreateIntegerValue(CONTENT_SETTING_BLOCK)); |
| 125 } | 133 } |
| 126 | 134 |
| 127 | 135 |
| 128 TEST_F(DefaultProviderTest, ObserveDefaultPref) { | 136 TEST_F(DefaultProviderTest, ObserveDefaultPref) { |
| 129 PrefService* prefs = profile_.GetPrefs(); | 137 PrefService* prefs = profile_.GetPrefs(); |
| 130 | 138 |
| 131 // Make a copy of the default pref value so we can reset it later. | 139 // Make a copy of the default pref value so we can reset it later. |
| 132 scoped_ptr<Value> default_value(prefs->FindPreference( | 140 scoped_ptr<Value> default_value(prefs->FindPreference( |
| 133 prefs::kDefaultContentSettings)->GetValue()->DeepCopy()); | 141 prefs::kDefaultContentSettings)->GetValue()->DeepCopy()); |
| 134 | 142 |
| 135 provider_.SetContentSetting(ContentSettingsPattern::Wildcard(), | 143 provider_.SetWebsiteSetting( |
| 136 ContentSettingsPattern::Wildcard(), | 144 ContentSettingsPattern::Wildcard(), |
| 137 CONTENT_SETTINGS_TYPE_COOKIES, | 145 ContentSettingsPattern::Wildcard(), |
| 138 std::string(), | 146 CONTENT_SETTINGS_TYPE_COOKIES, |
| 139 CONTENT_SETTING_BLOCK); | 147 std::string(), |
| 148 Value::CreateIntegerValue(CONTENT_SETTING_BLOCK)); |
| 140 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 149 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 141 GetContentSetting(&provider_, | 150 GetContentSetting(&provider_, |
| 142 GURL(), | 151 GURL(), |
| 143 GURL(), | 152 GURL(), |
| 144 CONTENT_SETTINGS_TYPE_COOKIES, | 153 CONTENT_SETTINGS_TYPE_COOKIES, |
| 145 std::string(), | 154 std::string(), |
| 146 false)); | 155 false)); |
| 147 | 156 |
| 148 // Make a copy of the pref's new value so we can reset it later. | 157 // Make a copy of the pref's new value so we can reset it later. |
| 149 scoped_ptr<Value> new_value(prefs->FindPreference( | 158 scoped_ptr<Value> new_value(prefs->FindPreference( |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 191 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 183 GetContentSetting(&otr_provider, | 192 GetContentSetting(&otr_provider, |
| 184 GURL(), | 193 GURL(), |
| 185 GURL(), | 194 GURL(), |
| 186 CONTENT_SETTINGS_TYPE_COOKIES, | 195 CONTENT_SETTINGS_TYPE_COOKIES, |
| 187 std::string(), | 196 std::string(), |
| 188 true)); | 197 true)); |
| 189 | 198 |
| 190 // Changing content settings on the main provider should also affect the | 199 // Changing content settings on the main provider should also affect the |
| 191 // incognito map. | 200 // incognito map. |
| 192 provider_.SetContentSetting(ContentSettingsPattern::Wildcard(), | 201 provider_.SetWebsiteSetting( |
| 193 ContentSettingsPattern::Wildcard(), | 202 ContentSettingsPattern::Wildcard(), |
| 194 CONTENT_SETTINGS_TYPE_COOKIES, | 203 ContentSettingsPattern::Wildcard(), |
| 195 std::string(), | 204 CONTENT_SETTINGS_TYPE_COOKIES, |
| 196 CONTENT_SETTING_BLOCK); | 205 std::string(), |
| 206 Value::CreateIntegerValue(CONTENT_SETTING_BLOCK)); |
| 197 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 207 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 198 GetContentSetting(&provider_, | 208 GetContentSetting(&provider_, |
| 199 GURL(), | 209 GURL(), |
| 200 GURL(), | 210 GURL(), |
| 201 CONTENT_SETTINGS_TYPE_COOKIES, | 211 CONTENT_SETTINGS_TYPE_COOKIES, |
| 202 std::string(), | 212 std::string(), |
| 203 false)); | 213 false)); |
| 204 | 214 |
| 205 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 215 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 206 GetContentSetting(&otr_provider, | 216 GetContentSetting(&otr_provider, |
| 207 GURL(), | 217 GURL(), |
| 208 GURL(), | 218 GURL(), |
| 209 CONTENT_SETTINGS_TYPE_COOKIES, | 219 CONTENT_SETTINGS_TYPE_COOKIES, |
| 210 std::string(), | 220 std::string(), |
| 211 true)); | 221 true)); |
| 212 | 222 |
| 213 // Changing content settings on the incognito provider should be ignored. | 223 // Changing content settings on the incognito provider should be ignored. |
| 214 otr_provider.SetContentSetting(ContentSettingsPattern::Wildcard(), | 224 scoped_ptr<base::Value> value( |
| 215 ContentSettingsPattern::Wildcard(), | 225 Value::CreateIntegerValue(CONTENT_SETTING_ALLOW)); |
| 216 CONTENT_SETTINGS_TYPE_COOKIES, | 226 bool owned = otr_provider.SetWebsiteSetting( |
| 217 std::string(), | 227 ContentSettingsPattern::Wildcard(), |
| 218 CONTENT_SETTING_ALLOW); | 228 ContentSettingsPattern::Wildcard(), |
| 229 CONTENT_SETTINGS_TYPE_COOKIES, |
| 230 std::string(), |
| 231 value.get()); |
| 232 EXPECT_FALSE(owned); |
| 219 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 233 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 220 GetContentSetting(&provider_, | 234 GetContentSetting(&provider_, |
| 221 GURL(), | 235 GURL(), |
| 222 GURL(), | 236 GURL(), |
| 223 CONTENT_SETTINGS_TYPE_COOKIES, | 237 CONTENT_SETTINGS_TYPE_COOKIES, |
| 224 std::string(), | 238 std::string(), |
| 225 false)); | 239 false)); |
| 226 | 240 |
| 227 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 241 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 228 GetContentSetting(&otr_provider, | 242 GetContentSetting(&otr_provider, |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 279 | 293 |
| 280 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 294 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 281 GetContentSetting(&provider, | 295 GetContentSetting(&provider, |
| 282 GURL(), | 296 GURL(), |
| 283 GURL(), | 297 GURL(), |
| 284 CONTENT_SETTINGS_TYPE_GEOLOCATION, | 298 CONTENT_SETTINGS_TYPE_GEOLOCATION, |
| 285 std::string(), | 299 std::string(), |
| 286 false)); | 300 false)); |
| 287 provider.ShutdownOnUIThread(); | 301 provider.ShutdownOnUIThread(); |
| 288 } | 302 } |
| OLD | NEW |