OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/auto_reset.h" | 5 #include "base/auto_reset.h" |
6 #include "base/command_line.h" | 6 #include "base/command_line.h" |
7 #include "base/json/json_reader.h" | 7 #include "base/json/json_reader.h" |
8 #include "base/json/json_writer.h" | 8 #include "base/json/json_writer.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "chrome/browser/content_settings/content_settings_mock_observer.h" | 10 #include "chrome/browser/content_settings/content_settings_mock_observer.h" |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
225 // |host_settings| contains only the default setting. | 225 // |host_settings| contains only the default setting. |
226 EXPECT_EQ(1U, host_settings.size()); | 226 EXPECT_EQ(1U, host_settings.size()); |
227 #if defined(ENABLE_PLUGINS) | 227 #if defined(ENABLE_PLUGINS) |
228 host_content_settings_map->GetSettingsForOneType( | 228 host_content_settings_map->GetSettingsForOneType( |
229 CONTENT_SETTINGS_TYPE_PLUGINS, std::string(), &host_settings); | 229 CONTENT_SETTINGS_TYPE_PLUGINS, std::string(), &host_settings); |
230 // |host_settings| contains the default setting and an exception. | 230 // |host_settings| contains the default setting and an exception. |
231 EXPECT_EQ(2U, host_settings.size()); | 231 EXPECT_EQ(2U, host_settings.size()); |
232 #endif | 232 #endif |
233 } | 233 } |
234 | 234 |
235 TEST_F(HostContentSettingsMapTest, Patterns) { | 235 TEST_F(HostContentSettingsMapTest, Origins) { |
msramek
2016/04/19 18:51:34
Hmm. This test indeed doesn't test patterns anymor
raymes
2016/04/20 01:53:21
That's a good point. We can still test patterns he
lshang
2016/06/15 06:26:41
Yep, I've changed it back to explicitly use patter
lshang
2016/06/15 06:26:41
As above.
| |
236 TestingProfile profile; | 236 TestingProfile profile; |
237 HostContentSettingsMap* host_content_settings_map = | 237 HostContentSettingsMap* host_content_settings_map = |
238 HostContentSettingsMapFactory::GetForProfile(&profile); | 238 HostContentSettingsMapFactory::GetForProfile(&profile); |
239 | 239 |
240 GURL host1("http://example.com/"); | 240 GURL host1("http://example.com/"); |
241 GURL host2("http://www.example.com/"); | 241 GURL host2("http://www.example.com/"); |
242 GURL host3("http://example.org/"); | 242 GURL host3("http://example.org/"); |
243 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 243 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
244 host_content_settings_map->GetContentSetting( | 244 host_content_settings_map->GetContentSetting( |
245 host1, host1, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); | 245 host1, host1, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); |
246 host_content_settings_map->SetContentSettingDefaultScope( | 246 host_content_settings_map->SetContentSettingDefaultScope( |
247 host1, GURL(), CONTENT_SETTINGS_TYPE_IMAGES, std::string(), | 247 host1, GURL(), CONTENT_SETTINGS_TYPE_IMAGES, std::string(), |
248 CONTENT_SETTING_BLOCK); | 248 CONTENT_SETTING_BLOCK); |
249 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 249 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
250 host_content_settings_map->GetContentSetting( | 250 host_content_settings_map->GetContentSetting( |
251 host1, host1, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); | 251 host1, host1, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); |
252 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 252 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
253 host_content_settings_map->GetContentSetting( | 253 host_content_settings_map->GetContentSetting( |
254 host2, host2, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); | 254 host2, host2, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); |
255 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 255 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
256 host_content_settings_map->GetContentSetting( | 256 host_content_settings_map->GetContentSetting( |
257 host3, host3, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); | 257 host3, host3, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); |
258 host_content_settings_map->SetContentSettingDefaultScope( | 258 host_content_settings_map->SetContentSettingDefaultScope( |
259 host3, GURL(), CONTENT_SETTINGS_TYPE_IMAGES, std::string(), | 259 host3, GURL(), CONTENT_SETTINGS_TYPE_IMAGES, std::string(), |
260 CONTENT_SETTING_BLOCK); | 260 CONTENT_SETTING_BLOCK); |
261 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 261 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
262 host_content_settings_map->GetContentSetting( | 262 host_content_settings_map->GetContentSetting( |
263 host3, host3, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); | 263 host3, host3, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); |
264 } | 264 } |
265 | 265 |
266 TEST_F(HostContentSettingsMapTest, Observer) { | 266 TEST_F(HostContentSettingsMapTest, Observer) { |
267 TestingProfile profile; | 267 TestingProfile profile; |
268 HostContentSettingsMap* host_content_settings_map = | 268 HostContentSettingsMap* host_content_settings_map = |
269 HostContentSettingsMapFactory::GetForProfile(&profile); | 269 HostContentSettingsMapFactory::GetForProfile(&profile); |
270 MockSettingsObserver observer(host_content_settings_map); | 270 MockSettingsObserver observer(host_content_settings_map); |
271 | 271 |
272 GURL host("http://example.com/"); | 272 GURL host("http://example.com/"); |
273 ContentSettingsPattern primary_pattern = | 273 ContentSettingsPattern primary_pattern = |
274 ContentSettingsPattern::FromString("[*.]example.com"); | 274 ContentSettingsPattern::FromString("http://example.com:80"); |
275 ContentSettingsPattern secondary_pattern = | 275 ContentSettingsPattern secondary_pattern = |
276 ContentSettingsPattern::Wildcard(); | 276 ContentSettingsPattern::Wildcard(); |
277 EXPECT_CALL(observer, | 277 EXPECT_CALL(observer, |
278 OnContentSettingsChanged(host_content_settings_map, | 278 OnContentSettingsChanged(host_content_settings_map, |
279 CONTENT_SETTINGS_TYPE_IMAGES, | 279 CONTENT_SETTINGS_TYPE_IMAGES, |
280 false, | 280 false, |
281 primary_pattern, | 281 primary_pattern, |
282 secondary_pattern, | 282 secondary_pattern, |
283 false)); | 283 false)); |
284 host_content_settings_map->SetContentSettingDefaultScope( | 284 host_content_settings_map->SetContentSettingDefaultScope( |
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
537 host_content_settings_map->SetContentSettingDefaultScope( | 537 host_content_settings_map->SetContentSettingDefaultScope( |
538 host2, GURL(), CONTENT_SETTINGS_TYPE_COOKIES, std::string(), | 538 host2, GURL(), CONTENT_SETTINGS_TYPE_COOKIES, std::string(), |
539 CONTENT_SETTING_BLOCK); | 539 CONTENT_SETTING_BLOCK); |
540 | 540 |
541 host_content_settings_map->SetContentSettingDefaultScope( | 541 host_content_settings_map->SetContentSettingDefaultScope( |
542 host, GURL(), CONTENT_SETTINGS_TYPE_PLUGINS, std::string(), | 542 host, GURL(), CONTENT_SETTINGS_TYPE_PLUGINS, std::string(), |
543 CONTENT_SETTING_BLOCK); | 543 CONTENT_SETTING_BLOCK); |
544 host_content_settings_map->SetDefaultContentSetting( | 544 host_content_settings_map->SetDefaultContentSetting( |
545 CONTENT_SETTINGS_TYPE_JAVASCRIPT, CONTENT_SETTING_BLOCK); | 545 CONTENT_SETTINGS_TYPE_JAVASCRIPT, CONTENT_SETTING_BLOCK); |
546 | 546 |
547 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 547 // Cookies and Images only take effect per-origin. |
raymes
2016/04/20 01:53:21
Same here, I think since this test explicitly test
lshang
2016/06/15 06:26:41
Done.
| |
548 EXPECT_EQ(CONTENT_SETTING_ALLOW, | |
548 host_content_settings_map->GetContentSetting( | 549 host_content_settings_map->GetContentSetting( |
549 host, host, CONTENT_SETTINGS_TYPE_COOKIES, std::string())); | 550 host, host, CONTENT_SETTINGS_TYPE_COOKIES, std::string())); |
550 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 551 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
551 host_content_settings_map->GetContentSetting( | 552 host_content_settings_map->GetContentSetting( |
552 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); | 553 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); |
554 // Default settings affect all sites which have no exceptions. | |
553 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 555 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
554 host_content_settings_map->GetContentSetting( | 556 host_content_settings_map->GetContentSetting( |
555 host, host, CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string())); | 557 host, host, CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string())); |
556 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 558 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
557 host_content_settings_map->GetContentSetting( | 559 host_content_settings_map->GetContentSetting( |
558 host, host, CONTENT_SETTINGS_TYPE_PLUGINS, std::string())); | 560 host, host, CONTENT_SETTINGS_TYPE_PLUGINS, std::string())); |
559 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 561 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
560 host_content_settings_map->GetContentSetting( | 562 host_content_settings_map->GetContentSetting( |
561 host, host, CONTENT_SETTINGS_TYPE_POPUPS, std::string())); | 563 host, host, CONTENT_SETTINGS_TYPE_POPUPS, std::string())); |
562 EXPECT_EQ(CONTENT_SETTING_ASK, | 564 EXPECT_EQ(CONTENT_SETTING_ASK, |
(...skipping 483 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1046 } | 1048 } |
1047 | 1049 |
1048 TEST_F(HostContentSettingsMapTest, AddContentSettingsObserver) { | 1050 TEST_F(HostContentSettingsMapTest, AddContentSettingsObserver) { |
1049 TestingProfile profile; | 1051 TestingProfile profile; |
1050 HostContentSettingsMap* host_content_settings_map = | 1052 HostContentSettingsMap* host_content_settings_map = |
1051 HostContentSettingsMapFactory::GetForProfile(&profile); | 1053 HostContentSettingsMapFactory::GetForProfile(&profile); |
1052 content_settings::MockObserver mock_observer; | 1054 content_settings::MockObserver mock_observer; |
1053 | 1055 |
1054 GURL host("http://example.com/"); | 1056 GURL host("http://example.com/"); |
1055 ContentSettingsPattern pattern = | 1057 ContentSettingsPattern pattern = |
1056 ContentSettingsPattern::FromString("[*.]example.com"); | 1058 ContentSettingsPattern::FromString("http://example.com:80"); |
1057 EXPECT_CALL(mock_observer, | 1059 EXPECT_CALL(mock_observer, |
1058 OnContentSettingChanged(pattern, | 1060 OnContentSettingChanged(pattern, |
1059 ContentSettingsPattern::Wildcard(), | 1061 ContentSettingsPattern::Wildcard(), |
1060 CONTENT_SETTINGS_TYPE_IMAGES, | 1062 CONTENT_SETTINGS_TYPE_IMAGES, |
1061 "")); | 1063 "")); |
1062 | 1064 |
1063 host_content_settings_map->AddObserver(&mock_observer); | 1065 host_content_settings_map->AddObserver(&mock_observer); |
1064 | 1066 |
1065 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 1067 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
1066 host_content_settings_map->GetContentSetting( | 1068 host_content_settings_map->GetContentSetting( |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1184 host, host, CONTENT_SETTINGS_TYPE_KEYGEN, std::string())); | 1186 host, host, CONTENT_SETTINGS_TYPE_KEYGEN, std::string())); |
1185 | 1187 |
1186 // After migrating old settings, changes to the setting works. | 1188 // After migrating old settings, changes to the setting works. |
1187 host_content_settings_map->SetContentSettingDefaultScope( | 1189 host_content_settings_map->SetContentSettingDefaultScope( |
1188 host, GURL(), CONTENT_SETTINGS_TYPE_KEYGEN, std::string(), | 1190 host, GURL(), CONTENT_SETTINGS_TYPE_KEYGEN, std::string(), |
1189 CONTENT_SETTING_BLOCK); | 1191 CONTENT_SETTING_BLOCK); |
1190 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 1192 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
1191 host_content_settings_map->GetContentSetting( | 1193 host_content_settings_map->GetContentSetting( |
1192 host, host, CONTENT_SETTINGS_TYPE_KEYGEN, std::string())); | 1194 host, host, CONTENT_SETTINGS_TYPE_KEYGEN, std::string())); |
1193 } | 1195 } |
OLD | NEW |