| 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 <memory> | 5 #include <memory> |
| 6 | 6 |
| 7 #include "base/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
| 8 #include "chrome/browser/content_settings/content_settings_mock_observer.h" | 8 #include "chrome/browser/content_settings/content_settings_mock_observer.h" |
| 9 #include "chrome/common/pref_names.h" | 9 #include "chrome/common/pref_names.h" |
| 10 #include "chrome/test/base/testing_profile.h" | 10 #include "chrome/test/base/testing_profile.h" |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 TestingProfile profile_; | 36 TestingProfile profile_; |
| 37 DefaultProvider provider_; | 37 DefaultProvider provider_; |
| 38 }; | 38 }; |
| 39 | 39 |
| 40 TEST_F(DefaultProviderTest, DefaultValues) { | 40 TEST_F(DefaultProviderTest, DefaultValues) { |
| 41 // Check setting defaults. | 41 // Check setting defaults. |
| 42 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 42 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 43 TestUtils::GetContentSetting(&provider_, GURL(), GURL(), | 43 TestUtils::GetContentSetting(&provider_, GURL(), GURL(), |
| 44 CONTENT_SETTINGS_TYPE_COOKIES, | 44 CONTENT_SETTINGS_TYPE_COOKIES, |
| 45 std::string(), false)); | 45 std::string(), false)); |
| 46 provider_.SetWebsiteSetting( | 46 provider_.SetWebsiteSetting(ContentSettingsPattern::Wildcard(), |
| 47 ContentSettingsPattern::Wildcard(), | 47 ContentSettingsPattern::Wildcard(), |
| 48 ContentSettingsPattern::Wildcard(), | 48 CONTENT_SETTINGS_TYPE_COOKIES, std::string(), |
| 49 CONTENT_SETTINGS_TYPE_COOKIES, | 49 new base::Value(CONTENT_SETTING_BLOCK)); |
| 50 std::string(), | |
| 51 new base::FundamentalValue(CONTENT_SETTING_BLOCK)); | |
| 52 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 50 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 53 TestUtils::GetContentSetting(&provider_, GURL(), GURL(), | 51 TestUtils::GetContentSetting(&provider_, GURL(), GURL(), |
| 54 CONTENT_SETTINGS_TYPE_COOKIES, | 52 CONTENT_SETTINGS_TYPE_COOKIES, |
| 55 std::string(), false)); | 53 std::string(), false)); |
| 56 | 54 |
| 57 EXPECT_EQ(CONTENT_SETTING_ASK, | 55 EXPECT_EQ(CONTENT_SETTING_ASK, |
| 58 TestUtils::GetContentSetting(&provider_, GURL(), GURL(), | 56 TestUtils::GetContentSetting(&provider_, GURL(), GURL(), |
| 59 CONTENT_SETTINGS_TYPE_GEOLOCATION, | 57 CONTENT_SETTINGS_TYPE_GEOLOCATION, |
| 60 std::string(), false)); | 58 std::string(), false)); |
| 61 provider_.SetWebsiteSetting( | 59 provider_.SetWebsiteSetting(ContentSettingsPattern::Wildcard(), |
| 62 ContentSettingsPattern::Wildcard(), | 60 ContentSettingsPattern::Wildcard(), |
| 63 ContentSettingsPattern::Wildcard(), | 61 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string(), |
| 64 CONTENT_SETTINGS_TYPE_GEOLOCATION, | 62 new base::Value(CONTENT_SETTING_BLOCK)); |
| 65 std::string(), | |
| 66 new base::FundamentalValue(CONTENT_SETTING_BLOCK)); | |
| 67 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 63 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 68 TestUtils::GetContentSetting(&provider_, GURL(), GURL(), | 64 TestUtils::GetContentSetting(&provider_, GURL(), GURL(), |
| 69 CONTENT_SETTINGS_TYPE_GEOLOCATION, | 65 CONTENT_SETTINGS_TYPE_GEOLOCATION, |
| 70 std::string(), false)); | 66 std::string(), false)); |
| 71 | 67 |
| 72 std::unique_ptr<base::Value> value(TestUtils::GetContentSettingValue( | 68 std::unique_ptr<base::Value> value(TestUtils::GetContentSettingValue( |
| 73 &provider_, GURL("http://example.com/"), GURL("http://example.com/"), | 69 &provider_, GURL("http://example.com/"), GURL("http://example.com/"), |
| 74 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE, std::string(), false)); | 70 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE, std::string(), false)); |
| 75 EXPECT_FALSE(value.get()); | 71 EXPECT_FALSE(value.get()); |
| 76 } | 72 } |
| 77 | 73 |
| 78 TEST_F(DefaultProviderTest, IgnoreNonDefaultSettings) { | 74 TEST_F(DefaultProviderTest, IgnoreNonDefaultSettings) { |
| 79 GURL primary_url("http://www.google.com"); | 75 GURL primary_url("http://www.google.com"); |
| 80 GURL secondary_url("http://www.google.com"); | 76 GURL secondary_url("http://www.google.com"); |
| 81 | 77 |
| 82 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 78 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 83 TestUtils::GetContentSetting(&provider_, primary_url, secondary_url, | 79 TestUtils::GetContentSetting(&provider_, primary_url, secondary_url, |
| 84 CONTENT_SETTINGS_TYPE_COOKIES, | 80 CONTENT_SETTINGS_TYPE_COOKIES, |
| 85 std::string(), false)); | 81 std::string(), false)); |
| 86 std::unique_ptr<base::Value> value( | 82 std::unique_ptr<base::Value> value(new base::Value(CONTENT_SETTING_BLOCK)); |
| 87 new base::FundamentalValue(CONTENT_SETTING_BLOCK)); | |
| 88 bool owned = provider_.SetWebsiteSetting( | 83 bool owned = provider_.SetWebsiteSetting( |
| 89 ContentSettingsPattern::FromURL(primary_url), | 84 ContentSettingsPattern::FromURL(primary_url), |
| 90 ContentSettingsPattern::FromURL(secondary_url), | 85 ContentSettingsPattern::FromURL(secondary_url), |
| 91 CONTENT_SETTINGS_TYPE_COOKIES, | 86 CONTENT_SETTINGS_TYPE_COOKIES, |
| 92 std::string(), | 87 std::string(), |
| 93 value.get()); | 88 value.get()); |
| 94 EXPECT_FALSE(owned); | 89 EXPECT_FALSE(owned); |
| 95 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 90 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 96 TestUtils::GetContentSetting(&provider_, primary_url, secondary_url, | 91 TestUtils::GetContentSetting(&provider_, primary_url, secondary_url, |
| 97 CONTENT_SETTINGS_TYPE_COOKIES, | 92 CONTENT_SETTINGS_TYPE_COOKIES, |
| 98 std::string(), false)); | 93 std::string(), false)); |
| 99 } | 94 } |
| 100 | 95 |
| 101 TEST_F(DefaultProviderTest, Observer) { | 96 TEST_F(DefaultProviderTest, Observer) { |
| 102 MockObserver mock_observer; | 97 MockObserver mock_observer; |
| 103 EXPECT_CALL(mock_observer, | 98 EXPECT_CALL(mock_observer, |
| 104 OnContentSettingChanged( | 99 OnContentSettingChanged( |
| 105 _, _, CONTENT_SETTINGS_TYPE_COOKIES, "")); | 100 _, _, CONTENT_SETTINGS_TYPE_COOKIES, "")); |
| 106 provider_.AddObserver(&mock_observer); | 101 provider_.AddObserver(&mock_observer); |
| 107 provider_.SetWebsiteSetting( | 102 provider_.SetWebsiteSetting(ContentSettingsPattern::Wildcard(), |
| 108 ContentSettingsPattern::Wildcard(), | 103 ContentSettingsPattern::Wildcard(), |
| 109 ContentSettingsPattern::Wildcard(), | 104 CONTENT_SETTINGS_TYPE_COOKIES, std::string(), |
| 110 CONTENT_SETTINGS_TYPE_COOKIES, | 105 new base::Value(CONTENT_SETTING_BLOCK)); |
| 111 std::string(), | |
| 112 new base::FundamentalValue(CONTENT_SETTING_BLOCK)); | |
| 113 | 106 |
| 114 EXPECT_CALL(mock_observer, | 107 EXPECT_CALL(mock_observer, |
| 115 OnContentSettingChanged( | 108 OnContentSettingChanged( |
| 116 _, _, CONTENT_SETTINGS_TYPE_GEOLOCATION, "")); | 109 _, _, CONTENT_SETTINGS_TYPE_GEOLOCATION, "")); |
| 117 provider_.SetWebsiteSetting( | 110 provider_.SetWebsiteSetting(ContentSettingsPattern::Wildcard(), |
| 118 ContentSettingsPattern::Wildcard(), | 111 ContentSettingsPattern::Wildcard(), |
| 119 ContentSettingsPattern::Wildcard(), | 112 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string(), |
| 120 CONTENT_SETTINGS_TYPE_GEOLOCATION, | 113 new base::Value(CONTENT_SETTING_BLOCK)); |
| 121 std::string(), | |
| 122 new base::FundamentalValue(CONTENT_SETTING_BLOCK)); | |
| 123 } | 114 } |
| 124 | 115 |
| 125 | 116 |
| 126 TEST_F(DefaultProviderTest, ObservePref) { | 117 TEST_F(DefaultProviderTest, ObservePref) { |
| 127 PrefService* prefs = profile_.GetPrefs(); | 118 PrefService* prefs = profile_.GetPrefs(); |
| 128 | 119 |
| 129 provider_.SetWebsiteSetting( | 120 provider_.SetWebsiteSetting(ContentSettingsPattern::Wildcard(), |
| 130 ContentSettingsPattern::Wildcard(), | 121 ContentSettingsPattern::Wildcard(), |
| 131 ContentSettingsPattern::Wildcard(), | 122 CONTENT_SETTINGS_TYPE_COOKIES, std::string(), |
| 132 CONTENT_SETTINGS_TYPE_COOKIES, | 123 new base::Value(CONTENT_SETTING_BLOCK)); |
| 133 std::string(), | |
| 134 new base::FundamentalValue(CONTENT_SETTING_BLOCK)); | |
| 135 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 124 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 136 TestUtils::GetContentSetting(&provider_, GURL(), GURL(), | 125 TestUtils::GetContentSetting(&provider_, GURL(), GURL(), |
| 137 CONTENT_SETTINGS_TYPE_COOKIES, | 126 CONTENT_SETTINGS_TYPE_COOKIES, |
| 138 std::string(), false)); | 127 std::string(), false)); |
| 139 const WebsiteSettingsInfo* info = WebsiteSettingsRegistry::GetInstance()->Get( | 128 const WebsiteSettingsInfo* info = WebsiteSettingsRegistry::GetInstance()->Get( |
| 140 CONTENT_SETTINGS_TYPE_COOKIES); | 129 CONTENT_SETTINGS_TYPE_COOKIES); |
| 141 // Clearing the backing pref should also clear the internal cache. | 130 // Clearing the backing pref should also clear the internal cache. |
| 142 prefs->ClearPref(info->default_value_pref_name()); | 131 prefs->ClearPref(info->default_value_pref_name()); |
| 143 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 132 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 144 TestUtils::GetContentSetting(&provider_, GURL(), GURL(), | 133 TestUtils::GetContentSetting(&provider_, GURL(), GURL(), |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 TestUtils::GetContentSetting( | 180 TestUtils::GetContentSetting( |
| 192 &provider_, GURL(), GURL(), CONTENT_SETTINGS_TYPE_COOKIES, | 181 &provider_, GURL(), GURL(), CONTENT_SETTINGS_TYPE_COOKIES, |
| 193 std::string(), false /* include_incognito */)); | 182 std::string(), false /* include_incognito */)); |
| 194 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 183 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 195 TestUtils::GetContentSetting( | 184 TestUtils::GetContentSetting( |
| 196 &otr_provider, GURL(), GURL(), CONTENT_SETTINGS_TYPE_COOKIES, | 185 &otr_provider, GURL(), GURL(), CONTENT_SETTINGS_TYPE_COOKIES, |
| 197 std::string(), true /* include_incognito */)); | 186 std::string(), true /* include_incognito */)); |
| 198 | 187 |
| 199 // Changing content settings on the main provider should also affect the | 188 // Changing content settings on the main provider should also affect the |
| 200 // incognito map. | 189 // incognito map. |
| 201 provider_.SetWebsiteSetting( | 190 provider_.SetWebsiteSetting(ContentSettingsPattern::Wildcard(), |
| 202 ContentSettingsPattern::Wildcard(), | 191 ContentSettingsPattern::Wildcard(), |
| 203 ContentSettingsPattern::Wildcard(), | 192 CONTENT_SETTINGS_TYPE_COOKIES, std::string(), |
| 204 CONTENT_SETTINGS_TYPE_COOKIES, | 193 new base::Value(CONTENT_SETTING_BLOCK)); |
| 205 std::string(), | |
| 206 new base::FundamentalValue(CONTENT_SETTING_BLOCK)); | |
| 207 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 194 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 208 TestUtils::GetContentSetting( | 195 TestUtils::GetContentSetting( |
| 209 &provider_, GURL(), GURL(), CONTENT_SETTINGS_TYPE_COOKIES, | 196 &provider_, GURL(), GURL(), CONTENT_SETTINGS_TYPE_COOKIES, |
| 210 std::string(), false /* include_incognito */)); | 197 std::string(), false /* include_incognito */)); |
| 211 | 198 |
| 212 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 199 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 213 TestUtils::GetContentSetting( | 200 TestUtils::GetContentSetting( |
| 214 &otr_provider, GURL(), GURL(), CONTENT_SETTINGS_TYPE_COOKIES, | 201 &otr_provider, GURL(), GURL(), CONTENT_SETTINGS_TYPE_COOKIES, |
| 215 std::string(), true /* include_incognito */)); | 202 std::string(), true /* include_incognito */)); |
| 216 | 203 |
| 217 // Changing content settings on the incognito provider should be ignored. | 204 // Changing content settings on the incognito provider should be ignored. |
| 218 std::unique_ptr<base::Value> value( | 205 std::unique_ptr<base::Value> value(new base::Value(CONTENT_SETTING_ALLOW)); |
| 219 new base::FundamentalValue(CONTENT_SETTING_ALLOW)); | |
| 220 bool owned = otr_provider.SetWebsiteSetting( | 206 bool owned = otr_provider.SetWebsiteSetting( |
| 221 ContentSettingsPattern::Wildcard(), | 207 ContentSettingsPattern::Wildcard(), |
| 222 ContentSettingsPattern::Wildcard(), | 208 ContentSettingsPattern::Wildcard(), |
| 223 CONTENT_SETTINGS_TYPE_COOKIES, | 209 CONTENT_SETTINGS_TYPE_COOKIES, |
| 224 std::string(), | 210 std::string(), |
| 225 value.release()); | 211 value.release()); |
| 226 EXPECT_TRUE(owned); | 212 EXPECT_TRUE(owned); |
| 227 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 213 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 228 TestUtils::GetContentSetting( | 214 TestUtils::GetContentSetting( |
| 229 &provider_, GURL(), GURL(), CONTENT_SETTINGS_TYPE_COOKIES, | 215 &provider_, GURL(), GURL(), CONTENT_SETTINGS_TYPE_COOKIES, |
| 230 std::string(), false /* include_incognito */)); | 216 std::string(), false /* include_incognito */)); |
| 231 | 217 |
| 232 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 218 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 233 TestUtils::GetContentSetting( | 219 TestUtils::GetContentSetting( |
| 234 &otr_provider, GURL(), GURL(), CONTENT_SETTINGS_TYPE_COOKIES, | 220 &otr_provider, GURL(), GURL(), CONTENT_SETTINGS_TYPE_COOKIES, |
| 235 std::string(), true /* include_incognito */)); | 221 std::string(), true /* include_incognito */)); |
| 236 | 222 |
| 237 // Check that new OTR DefaultProviders also inherit the correct value. | 223 // Check that new OTR DefaultProviders also inherit the correct value. |
| 238 DefaultProvider otr_provider2(profile_.GetPrefs(), true /* incognito */); | 224 DefaultProvider otr_provider2(profile_.GetPrefs(), true /* incognito */); |
| 239 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 225 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 240 TestUtils::GetContentSetting( | 226 TestUtils::GetContentSetting( |
| 241 &otr_provider2, GURL(), GURL(), CONTENT_SETTINGS_TYPE_COOKIES, | 227 &otr_provider2, GURL(), GURL(), CONTENT_SETTINGS_TYPE_COOKIES, |
| 242 std::string(), true /* include_incognito */)); | 228 std::string(), true /* include_incognito */)); |
| 243 | 229 |
| 244 otr_provider.ShutdownOnUIThread(); | 230 otr_provider.ShutdownOnUIThread(); |
| 245 otr_provider2.ShutdownOnUIThread(); | 231 otr_provider2.ShutdownOnUIThread(); |
| 246 } | 232 } |
| 247 | 233 |
| 248 } // namespace content_settings | 234 } // namespace content_settings |
| OLD | NEW |