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 "base/message_loop/message_loop.h" | 6 #include "base/message_loop/message_loop.h" |
7 #include "base/prefs/pref_service.h" | 7 #include "base/prefs/pref_service.h" |
8 #include "base/prefs/testing_pref_service.h" | 8 #include "base/prefs/testing_pref_service.h" |
9 #include "chrome/browser/content_settings/content_settings_default_provider.h" | 9 #include "chrome/browser/content_settings/content_settings_default_provider.h" |
10 #include "chrome/browser/content_settings/content_settings_mock_observer.h" | 10 #include "chrome/browser/content_settings/content_settings_mock_observer.h" |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 GURL(), | 42 GURL(), |
43 GURL(), | 43 GURL(), |
44 CONTENT_SETTINGS_TYPE_COOKIES, | 44 CONTENT_SETTINGS_TYPE_COOKIES, |
45 std::string(), | 45 std::string(), |
46 false)); | 46 false)); |
47 provider_.SetWebsiteSetting( | 47 provider_.SetWebsiteSetting( |
48 ContentSettingsPattern::Wildcard(), | 48 ContentSettingsPattern::Wildcard(), |
49 ContentSettingsPattern::Wildcard(), | 49 ContentSettingsPattern::Wildcard(), |
50 CONTENT_SETTINGS_TYPE_COOKIES, | 50 CONTENT_SETTINGS_TYPE_COOKIES, |
51 std::string(), | 51 std::string(), |
52 Value::CreateIntegerValue(CONTENT_SETTING_BLOCK)); | 52 base::Value::CreateIntegerValue(CONTENT_SETTING_BLOCK)); |
53 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 53 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
54 GetContentSetting(&provider_, | 54 GetContentSetting(&provider_, |
55 GURL(), | 55 GURL(), |
56 GURL(), | 56 GURL(), |
57 CONTENT_SETTINGS_TYPE_COOKIES, | 57 CONTENT_SETTINGS_TYPE_COOKIES, |
58 std::string(), | 58 std::string(), |
59 false)); | 59 false)); |
60 | 60 |
61 EXPECT_EQ(CONTENT_SETTING_ASK, | 61 EXPECT_EQ(CONTENT_SETTING_ASK, |
62 GetContentSetting(&provider_, | 62 GetContentSetting(&provider_, |
63 GURL(), | 63 GURL(), |
64 GURL(), | 64 GURL(), |
65 CONTENT_SETTINGS_TYPE_GEOLOCATION, | 65 CONTENT_SETTINGS_TYPE_GEOLOCATION, |
66 std::string(), | 66 std::string(), |
67 false)); | 67 false)); |
68 provider_.SetWebsiteSetting( | 68 provider_.SetWebsiteSetting( |
69 ContentSettingsPattern::Wildcard(), | 69 ContentSettingsPattern::Wildcard(), |
70 ContentSettingsPattern::Wildcard(), | 70 ContentSettingsPattern::Wildcard(), |
71 CONTENT_SETTINGS_TYPE_GEOLOCATION, | 71 CONTENT_SETTINGS_TYPE_GEOLOCATION, |
72 std::string(), | 72 std::string(), |
73 Value::CreateIntegerValue(CONTENT_SETTING_BLOCK)); | 73 base::Value::CreateIntegerValue(CONTENT_SETTING_BLOCK)); |
74 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 74 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
75 GetContentSetting(&provider_, | 75 GetContentSetting(&provider_, |
76 GURL(), | 76 GURL(), |
77 GURL(), | 77 GURL(), |
78 CONTENT_SETTINGS_TYPE_GEOLOCATION, | 78 CONTENT_SETTINGS_TYPE_GEOLOCATION, |
79 std::string(), | 79 std::string(), |
80 false)); | 80 false)); |
81 | 81 |
82 scoped_ptr<base::Value> value( | 82 scoped_ptr<base::Value> value( |
83 GetContentSettingValue(&provider_, | 83 GetContentSettingValue(&provider_, |
(...skipping 10 matching lines...) Expand all Loading... |
94 GURL secondary_url("http://www.google.com"); | 94 GURL secondary_url("http://www.google.com"); |
95 | 95 |
96 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 96 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
97 GetContentSetting(&provider_, | 97 GetContentSetting(&provider_, |
98 primary_url, | 98 primary_url, |
99 secondary_url, | 99 secondary_url, |
100 CONTENT_SETTINGS_TYPE_COOKIES, | 100 CONTENT_SETTINGS_TYPE_COOKIES, |
101 std::string(), | 101 std::string(), |
102 false)); | 102 false)); |
103 scoped_ptr<base::Value> value( | 103 scoped_ptr<base::Value> value( |
104 Value::CreateIntegerValue(CONTENT_SETTING_BLOCK)); | 104 base::Value::CreateIntegerValue(CONTENT_SETTING_BLOCK)); |
105 bool owned = provider_.SetWebsiteSetting( | 105 bool owned = provider_.SetWebsiteSetting( |
106 ContentSettingsPattern::FromURL(primary_url), | 106 ContentSettingsPattern::FromURL(primary_url), |
107 ContentSettingsPattern::FromURL(secondary_url), | 107 ContentSettingsPattern::FromURL(secondary_url), |
108 CONTENT_SETTINGS_TYPE_COOKIES, | 108 CONTENT_SETTINGS_TYPE_COOKIES, |
109 std::string(), | 109 std::string(), |
110 value.get()); | 110 value.get()); |
111 EXPECT_FALSE(owned); | 111 EXPECT_FALSE(owned); |
112 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 112 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
113 GetContentSetting(&provider_, | 113 GetContentSetting(&provider_, |
114 primary_url, | 114 primary_url, |
115 secondary_url, | 115 secondary_url, |
116 CONTENT_SETTINGS_TYPE_COOKIES, | 116 CONTENT_SETTINGS_TYPE_COOKIES, |
117 std::string(), | 117 std::string(), |
118 false)); | 118 false)); |
119 } | 119 } |
120 | 120 |
121 TEST_F(DefaultProviderTest, Observer) { | 121 TEST_F(DefaultProviderTest, Observer) { |
122 content_settings::MockObserver mock_observer; | 122 content_settings::MockObserver mock_observer; |
123 EXPECT_CALL(mock_observer, | 123 EXPECT_CALL(mock_observer, |
124 OnContentSettingChanged( | 124 OnContentSettingChanged( |
125 _, _, CONTENT_SETTINGS_TYPE_IMAGES, "")); | 125 _, _, CONTENT_SETTINGS_TYPE_IMAGES, "")); |
126 provider_.AddObserver(&mock_observer); | 126 provider_.AddObserver(&mock_observer); |
127 provider_.SetWebsiteSetting( | 127 provider_.SetWebsiteSetting( |
128 ContentSettingsPattern::Wildcard(), | 128 ContentSettingsPattern::Wildcard(), |
129 ContentSettingsPattern::Wildcard(), | 129 ContentSettingsPattern::Wildcard(), |
130 CONTENT_SETTINGS_TYPE_IMAGES, | 130 CONTENT_SETTINGS_TYPE_IMAGES, |
131 std::string(), | 131 std::string(), |
132 Value::CreateIntegerValue(CONTENT_SETTING_BLOCK)); | 132 base::Value::CreateIntegerValue(CONTENT_SETTING_BLOCK)); |
133 | 133 |
134 EXPECT_CALL(mock_observer, | 134 EXPECT_CALL(mock_observer, |
135 OnContentSettingChanged( | 135 OnContentSettingChanged( |
136 _, _, CONTENT_SETTINGS_TYPE_GEOLOCATION, "")); | 136 _, _, CONTENT_SETTINGS_TYPE_GEOLOCATION, "")); |
137 provider_.SetWebsiteSetting( | 137 provider_.SetWebsiteSetting( |
138 ContentSettingsPattern::Wildcard(), | 138 ContentSettingsPattern::Wildcard(), |
139 ContentSettingsPattern::Wildcard(), | 139 ContentSettingsPattern::Wildcard(), |
140 CONTENT_SETTINGS_TYPE_GEOLOCATION, | 140 CONTENT_SETTINGS_TYPE_GEOLOCATION, |
141 std::string(), | 141 std::string(), |
142 Value::CreateIntegerValue(CONTENT_SETTING_BLOCK)); | 142 base::Value::CreateIntegerValue(CONTENT_SETTING_BLOCK)); |
143 } | 143 } |
144 | 144 |
145 | 145 |
146 TEST_F(DefaultProviderTest, ObserveDefaultPref) { | 146 TEST_F(DefaultProviderTest, ObserveDefaultPref) { |
147 PrefService* prefs = profile_.GetPrefs(); | 147 PrefService* prefs = profile_.GetPrefs(); |
148 | 148 |
149 // Make a copy of the default pref value so we can reset it later. | 149 // Make a copy of the default pref value so we can reset it later. |
150 scoped_ptr<Value> default_value(prefs->FindPreference( | 150 scoped_ptr<base::Value> default_value(prefs->FindPreference( |
151 prefs::kDefaultContentSettings)->GetValue()->DeepCopy()); | 151 prefs::kDefaultContentSettings)->GetValue()->DeepCopy()); |
152 | 152 |
153 provider_.SetWebsiteSetting( | 153 provider_.SetWebsiteSetting( |
154 ContentSettingsPattern::Wildcard(), | 154 ContentSettingsPattern::Wildcard(), |
155 ContentSettingsPattern::Wildcard(), | 155 ContentSettingsPattern::Wildcard(), |
156 CONTENT_SETTINGS_TYPE_COOKIES, | 156 CONTENT_SETTINGS_TYPE_COOKIES, |
157 std::string(), | 157 std::string(), |
158 Value::CreateIntegerValue(CONTENT_SETTING_BLOCK)); | 158 base::Value::CreateIntegerValue(CONTENT_SETTING_BLOCK)); |
159 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 159 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
160 GetContentSetting(&provider_, | 160 GetContentSetting(&provider_, |
161 GURL(), | 161 GURL(), |
162 GURL(), | 162 GURL(), |
163 CONTENT_SETTINGS_TYPE_COOKIES, | 163 CONTENT_SETTINGS_TYPE_COOKIES, |
164 std::string(), | 164 std::string(), |
165 false)); | 165 false)); |
166 | 166 |
167 // Make a copy of the pref's new value so we can reset it later. | 167 // Make a copy of the pref's new value so we can reset it later. |
168 scoped_ptr<Value> new_value(prefs->FindPreference( | 168 scoped_ptr<base::Value> new_value(prefs->FindPreference( |
169 prefs::kDefaultContentSettings)->GetValue()->DeepCopy()); | 169 prefs::kDefaultContentSettings)->GetValue()->DeepCopy()); |
170 | 170 |
171 // Clearing the backing pref should also clear the internal cache. | 171 // Clearing the backing pref should also clear the internal cache. |
172 prefs->Set(prefs::kDefaultContentSettings, *default_value); | 172 prefs->Set(prefs::kDefaultContentSettings, *default_value); |
173 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 173 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
174 GetContentSetting(&provider_, | 174 GetContentSetting(&provider_, |
175 GURL(), | 175 GURL(), |
176 GURL(), | 176 GURL(), |
177 CONTENT_SETTINGS_TYPE_COOKIES, | 177 CONTENT_SETTINGS_TYPE_COOKIES, |
178 std::string(), | 178 std::string(), |
(...skipping 27 matching lines...) Expand all Loading... |
206 std::string(), | 206 std::string(), |
207 true)); | 207 true)); |
208 | 208 |
209 // Changing content settings on the main provider should also affect the | 209 // Changing content settings on the main provider should also affect the |
210 // incognito map. | 210 // incognito map. |
211 provider_.SetWebsiteSetting( | 211 provider_.SetWebsiteSetting( |
212 ContentSettingsPattern::Wildcard(), | 212 ContentSettingsPattern::Wildcard(), |
213 ContentSettingsPattern::Wildcard(), | 213 ContentSettingsPattern::Wildcard(), |
214 CONTENT_SETTINGS_TYPE_COOKIES, | 214 CONTENT_SETTINGS_TYPE_COOKIES, |
215 std::string(), | 215 std::string(), |
216 Value::CreateIntegerValue(CONTENT_SETTING_BLOCK)); | 216 base::Value::CreateIntegerValue(CONTENT_SETTING_BLOCK)); |
217 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 217 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
218 GetContentSetting(&provider_, | 218 GetContentSetting(&provider_, |
219 GURL(), | 219 GURL(), |
220 GURL(), | 220 GURL(), |
221 CONTENT_SETTINGS_TYPE_COOKIES, | 221 CONTENT_SETTINGS_TYPE_COOKIES, |
222 std::string(), | 222 std::string(), |
223 false)); | 223 false)); |
224 | 224 |
225 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 225 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
226 GetContentSetting(&otr_provider, | 226 GetContentSetting(&otr_provider, |
227 GURL(), | 227 GURL(), |
228 GURL(), | 228 GURL(), |
229 CONTENT_SETTINGS_TYPE_COOKIES, | 229 CONTENT_SETTINGS_TYPE_COOKIES, |
230 std::string(), | 230 std::string(), |
231 true)); | 231 true)); |
232 | 232 |
233 // Changing content settings on the incognito provider should be ignored. | 233 // Changing content settings on the incognito provider should be ignored. |
234 scoped_ptr<base::Value> value( | 234 scoped_ptr<base::Value> value( |
235 Value::CreateIntegerValue(CONTENT_SETTING_ALLOW)); | 235 base::Value::CreateIntegerValue(CONTENT_SETTING_ALLOW)); |
236 bool owned = otr_provider.SetWebsiteSetting( | 236 bool owned = otr_provider.SetWebsiteSetting( |
237 ContentSettingsPattern::Wildcard(), | 237 ContentSettingsPattern::Wildcard(), |
238 ContentSettingsPattern::Wildcard(), | 238 ContentSettingsPattern::Wildcard(), |
239 CONTENT_SETTINGS_TYPE_COOKIES, | 239 CONTENT_SETTINGS_TYPE_COOKIES, |
240 std::string(), | 240 std::string(), |
241 value.get()); | 241 value.get()); |
242 EXPECT_FALSE(owned); | 242 EXPECT_FALSE(owned); |
243 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 243 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
244 GetContentSetting(&provider_, | 244 GetContentSetting(&provider_, |
245 GURL(), | 245 GURL(), |
246 GURL(), | 246 GURL(), |
247 CONTENT_SETTINGS_TYPE_COOKIES, | 247 CONTENT_SETTINGS_TYPE_COOKIES, |
248 std::string(), | 248 std::string(), |
249 false)); | 249 false)); |
250 | 250 |
251 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 251 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
252 GetContentSetting(&otr_provider, | 252 GetContentSetting(&otr_provider, |
253 GURL(), | 253 GURL(), |
254 GURL(), | 254 GURL(), |
255 CONTENT_SETTINGS_TYPE_COOKIES, | 255 CONTENT_SETTINGS_TYPE_COOKIES, |
256 std::string(), | 256 std::string(), |
257 true)); | 257 true)); |
258 otr_provider.ShutdownOnUIThread(); | 258 otr_provider.ShutdownOnUIThread(); |
259 } | 259 } |
OLD | NEW |