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