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 provider_.SetWebsiteSetting( |
92 ContentSettingsPattern::FromURL(secondary_url), | 94 ContentSettingsPattern::FromURL(primary_url), |
93 CONTENT_SETTINGS_TYPE_COOKIES, | 95 ContentSettingsPattern::FromURL(secondary_url), |
94 std::string(), | 96 CONTENT_SETTINGS_TYPE_COOKIES, |
95 CONTENT_SETTING_BLOCK); | 97 std::string(), |
| 98 Value::CreateIntegerValue(CONTENT_SETTING_BLOCK)); |
96 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 99 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
97 GetContentSetting(&provider_, | 100 GetContentSetting(&provider_, |
98 primary_url, | 101 primary_url, |
99 secondary_url, | 102 secondary_url, |
100 CONTENT_SETTINGS_TYPE_COOKIES, | 103 CONTENT_SETTINGS_TYPE_COOKIES, |
101 std::string(), | 104 std::string(), |
102 false)); | 105 false)); |
103 } | 106 } |
104 | 107 |
105 TEST_F(DefaultProviderTest, Observer) { | 108 TEST_F(DefaultProviderTest, Observer) { |
106 content_settings::MockObserver mock_observer; | 109 content_settings::MockObserver mock_observer; |
107 EXPECT_CALL(mock_observer, | 110 EXPECT_CALL(mock_observer, |
108 OnContentSettingChanged( | 111 OnContentSettingChanged( |
109 _, _, CONTENT_SETTINGS_TYPE_IMAGES, "")); | 112 _, _, CONTENT_SETTINGS_TYPE_IMAGES, "")); |
110 provider_.AddObserver(&mock_observer); | 113 provider_.AddObserver(&mock_observer); |
111 provider_.SetContentSetting(ContentSettingsPattern::Wildcard(), | 114 provider_.SetWebsiteSetting( |
112 ContentSettingsPattern::Wildcard(), | 115 ContentSettingsPattern::Wildcard(), |
113 CONTENT_SETTINGS_TYPE_IMAGES, | 116 ContentSettingsPattern::Wildcard(), |
114 std::string(), | 117 CONTENT_SETTINGS_TYPE_IMAGES, |
115 CONTENT_SETTING_BLOCK); | 118 std::string(), |
| 119 Value::CreateIntegerValue(CONTENT_SETTING_BLOCK)); |
116 | 120 |
117 EXPECT_CALL(mock_observer, | 121 EXPECT_CALL(mock_observer, |
118 OnContentSettingChanged( | 122 OnContentSettingChanged( |
119 _, _, CONTENT_SETTINGS_TYPE_GEOLOCATION, "")); | 123 _, _, CONTENT_SETTINGS_TYPE_GEOLOCATION, "")); |
120 provider_.SetContentSetting(ContentSettingsPattern::Wildcard(), | 124 provider_.SetWebsiteSetting( |
121 ContentSettingsPattern::Wildcard(), | 125 ContentSettingsPattern::Wildcard(), |
122 CONTENT_SETTINGS_TYPE_GEOLOCATION, | 126 ContentSettingsPattern::Wildcard(), |
123 std::string(), | 127 CONTENT_SETTINGS_TYPE_GEOLOCATION, |
124 CONTENT_SETTING_BLOCK); | 128 std::string(), |
| 129 Value::CreateIntegerValue(CONTENT_SETTING_BLOCK)); |
125 } | 130 } |
126 | 131 |
127 | 132 |
128 TEST_F(DefaultProviderTest, ObserveDefaultPref) { | 133 TEST_F(DefaultProviderTest, ObserveDefaultPref) { |
129 PrefService* prefs = profile_.GetPrefs(); | 134 PrefService* prefs = profile_.GetPrefs(); |
130 | 135 |
131 // Make a copy of the default pref value so we can reset it later. | 136 // Make a copy of the default pref value so we can reset it later. |
132 scoped_ptr<Value> default_value(prefs->FindPreference( | 137 scoped_ptr<Value> default_value(prefs->FindPreference( |
133 prefs::kDefaultContentSettings)->GetValue()->DeepCopy()); | 138 prefs::kDefaultContentSettings)->GetValue()->DeepCopy()); |
134 | 139 |
135 provider_.SetContentSetting(ContentSettingsPattern::Wildcard(), | 140 provider_.SetWebsiteSetting( |
136 ContentSettingsPattern::Wildcard(), | 141 ContentSettingsPattern::Wildcard(), |
137 CONTENT_SETTINGS_TYPE_COOKIES, | 142 ContentSettingsPattern::Wildcard(), |
138 std::string(), | 143 CONTENT_SETTINGS_TYPE_COOKIES, |
139 CONTENT_SETTING_BLOCK); | 144 std::string(), |
| 145 Value::CreateIntegerValue(CONTENT_SETTING_BLOCK)); |
140 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 146 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
141 GetContentSetting(&provider_, | 147 GetContentSetting(&provider_, |
142 GURL(), | 148 GURL(), |
143 GURL(), | 149 GURL(), |
144 CONTENT_SETTINGS_TYPE_COOKIES, | 150 CONTENT_SETTINGS_TYPE_COOKIES, |
145 std::string(), | 151 std::string(), |
146 false)); | 152 false)); |
147 | 153 |
148 // Make a copy of the pref's new value so we can reset it later. | 154 // Make a copy of the pref's new value so we can reset it later. |
149 scoped_ptr<Value> new_value(prefs->FindPreference( | 155 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, | 188 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
183 GetContentSetting(&otr_provider, | 189 GetContentSetting(&otr_provider, |
184 GURL(), | 190 GURL(), |
185 GURL(), | 191 GURL(), |
186 CONTENT_SETTINGS_TYPE_COOKIES, | 192 CONTENT_SETTINGS_TYPE_COOKIES, |
187 std::string(), | 193 std::string(), |
188 true)); | 194 true)); |
189 | 195 |
190 // Changing content settings on the main provider should also affect the | 196 // Changing content settings on the main provider should also affect the |
191 // incognito map. | 197 // incognito map. |
192 provider_.SetContentSetting(ContentSettingsPattern::Wildcard(), | 198 provider_.SetWebsiteSetting( |
193 ContentSettingsPattern::Wildcard(), | 199 ContentSettingsPattern::Wildcard(), |
194 CONTENT_SETTINGS_TYPE_COOKIES, | 200 ContentSettingsPattern::Wildcard(), |
195 std::string(), | 201 CONTENT_SETTINGS_TYPE_COOKIES, |
196 CONTENT_SETTING_BLOCK); | 202 std::string(), |
| 203 Value::CreateIntegerValue(CONTENT_SETTING_BLOCK)); |
197 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 204 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
198 GetContentSetting(&provider_, | 205 GetContentSetting(&provider_, |
199 GURL(), | 206 GURL(), |
200 GURL(), | 207 GURL(), |
201 CONTENT_SETTINGS_TYPE_COOKIES, | 208 CONTENT_SETTINGS_TYPE_COOKIES, |
202 std::string(), | 209 std::string(), |
203 false)); | 210 false)); |
204 | 211 |
205 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 212 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
206 GetContentSetting(&otr_provider, | 213 GetContentSetting(&otr_provider, |
207 GURL(), | 214 GURL(), |
208 GURL(), | 215 GURL(), |
209 CONTENT_SETTINGS_TYPE_COOKIES, | 216 CONTENT_SETTINGS_TYPE_COOKIES, |
210 std::string(), | 217 std::string(), |
211 true)); | 218 true)); |
212 | 219 |
213 // Changing content settings on the incognito provider should be ignored. | 220 // Changing content settings on the incognito provider should be ignored. |
214 otr_provider.SetContentSetting(ContentSettingsPattern::Wildcard(), | 221 otr_provider.SetWebsiteSetting( |
215 ContentSettingsPattern::Wildcard(), | 222 ContentSettingsPattern::Wildcard(), |
216 CONTENT_SETTINGS_TYPE_COOKIES, | 223 ContentSettingsPattern::Wildcard(), |
217 std::string(), | 224 CONTENT_SETTINGS_TYPE_COOKIES, |
218 CONTENT_SETTING_ALLOW); | 225 std::string(), |
| 226 Value::CreateIntegerValue(CONTENT_SETTING_ALLOW)); |
219 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 227 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
220 GetContentSetting(&provider_, | 228 GetContentSetting(&provider_, |
221 GURL(), | 229 GURL(), |
222 GURL(), | 230 GURL(), |
223 CONTENT_SETTINGS_TYPE_COOKIES, | 231 CONTENT_SETTINGS_TYPE_COOKIES, |
224 std::string(), | 232 std::string(), |
225 false)); | 233 false)); |
226 | 234 |
227 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 235 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
228 GetContentSetting(&otr_provider, | 236 GetContentSetting(&otr_provider, |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
279 | 287 |
280 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 288 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
281 GetContentSetting(&provider, | 289 GetContentSetting(&provider, |
282 GURL(), | 290 GURL(), |
283 GURL(), | 291 GURL(), |
284 CONTENT_SETTINGS_TYPE_GEOLOCATION, | 292 CONTENT_SETTINGS_TYPE_GEOLOCATION, |
285 std::string(), | 293 std::string(), |
286 false)); | 294 false)); |
287 provider.ShutdownOnUIThread(); | 295 provider.ShutdownOnUIThread(); |
288 } | 296 } |
OLD | NEW |