Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(75)

Side by Side Diff: chrome/browser/content_settings/host_content_settings_map_unittest.cc

Issue 2078903002: Set custom-scoped patterns in HostContentSettingsMapTest to keep test coverage (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <memory> 5 #include <memory>
6 #include <string> 6 #include <string>
7 7
8 #include "base/auto_reset.h" 8 #include "base/auto_reset.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/json/json_reader.h" 10 #include "base/json/json_reader.h"
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 } 294 }
295 295
296 TEST_F(HostContentSettingsMapTest, Patterns) { 296 TEST_F(HostContentSettingsMapTest, Patterns) {
297 TestingProfile profile; 297 TestingProfile profile;
298 HostContentSettingsMap* host_content_settings_map = 298 HostContentSettingsMap* host_content_settings_map =
299 HostContentSettingsMapFactory::GetForProfile(&profile); 299 HostContentSettingsMapFactory::GetForProfile(&profile);
300 300
301 GURL host1("http://example.com/"); 301 GURL host1("http://example.com/");
302 GURL host2("http://www.example.com/"); 302 GURL host2("http://www.example.com/");
303 GURL host3("http://example.org/"); 303 GURL host3("http://example.org/");
304 ContentSettingsPattern pattern1 =
305 ContentSettingsPattern::FromString("[*.]example.com");
306 ContentSettingsPattern pattern2 =
307 ContentSettingsPattern::FromString("example.org");
304 EXPECT_EQ(CONTENT_SETTING_ALLOW, 308 EXPECT_EQ(CONTENT_SETTING_ALLOW,
305 host_content_settings_map->GetContentSetting( 309 host_content_settings_map->GetContentSetting(
306 host1, host1, CONTENT_SETTINGS_TYPE_COOKIES, std::string())); 310 host1, host1, CONTENT_SETTINGS_TYPE_COOKIES, std::string()));
307 host_content_settings_map->SetContentSettingDefaultScope( 311 host_content_settings_map->SetContentSettingCustomScope(
308 host1, GURL(), CONTENT_SETTINGS_TYPE_COOKIES, std::string(), 312 pattern1, ContentSettingsPattern::Wildcard(),
309 CONTENT_SETTING_BLOCK); 313 CONTENT_SETTINGS_TYPE_COOKIES, std::string(), CONTENT_SETTING_BLOCK);
310 EXPECT_EQ(CONTENT_SETTING_BLOCK, 314 EXPECT_EQ(CONTENT_SETTING_BLOCK,
311 host_content_settings_map->GetContentSetting( 315 host_content_settings_map->GetContentSetting(
312 host1, host1, CONTENT_SETTINGS_TYPE_COOKIES, std::string())); 316 host1, host1, CONTENT_SETTINGS_TYPE_COOKIES, std::string()));
313 EXPECT_EQ(CONTENT_SETTING_BLOCK, 317 EXPECT_EQ(CONTENT_SETTING_BLOCK,
314 host_content_settings_map->GetContentSetting( 318 host_content_settings_map->GetContentSetting(
315 host2, host2, CONTENT_SETTINGS_TYPE_COOKIES, std::string())); 319 host2, host2, CONTENT_SETTINGS_TYPE_COOKIES, std::string()));
316 EXPECT_EQ(CONTENT_SETTING_ALLOW, 320 EXPECT_EQ(CONTENT_SETTING_ALLOW,
317 host_content_settings_map->GetContentSetting( 321 host_content_settings_map->GetContentSetting(
318 host3, host3, CONTENT_SETTINGS_TYPE_COOKIES, std::string())); 322 host3, host3, CONTENT_SETTINGS_TYPE_COOKIES, std::string()));
319 host_content_settings_map->SetContentSettingDefaultScope( 323 host_content_settings_map->SetContentSettingCustomScope(
320 host3, GURL(), CONTENT_SETTINGS_TYPE_COOKIES, std::string(), 324 pattern2, ContentSettingsPattern::Wildcard(),
321 CONTENT_SETTING_BLOCK); 325 CONTENT_SETTINGS_TYPE_COOKIES, std::string(), CONTENT_SETTING_BLOCK);
322 EXPECT_EQ(CONTENT_SETTING_BLOCK, 326 EXPECT_EQ(CONTENT_SETTING_BLOCK,
323 host_content_settings_map->GetContentSetting( 327 host_content_settings_map->GetContentSetting(
324 host3, host3, CONTENT_SETTINGS_TYPE_COOKIES, std::string())); 328 host3, host3, CONTENT_SETTINGS_TYPE_COOKIES, std::string()));
325 } 329 }
326 330
327 TEST_F(HostContentSettingsMapTest, Observer) { 331 TEST_F(HostContentSettingsMapTest, Observer) {
328 TestingProfile profile; 332 TestingProfile profile;
329 HostContentSettingsMap* host_content_settings_map = 333 HostContentSettingsMap* host_content_settings_map =
330 HostContentSettingsMapFactory::GetForProfile(&profile); 334 HostContentSettingsMapFactory::GetForProfile(&profile);
331 MockSettingsObserver observer(host_content_settings_map); 335 MockSettingsObserver observer(host_content_settings_map);
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
564 CONTENT_SETTINGS_TYPE_AUTOPLAY, std::string())); 568 CONTENT_SETTINGS_TYPE_AUTOPLAY, std::string()));
565 host_content_settings_map->SetContentSettingDefaultScope( 569 host_content_settings_map->SetContentSettingDefaultScope(
566 host_ending_with_dot, GURL(), CONTENT_SETTINGS_TYPE_AUTOPLAY, 570 host_ending_with_dot, GURL(), CONTENT_SETTINGS_TYPE_AUTOPLAY,
567 std::string(), CONTENT_SETTING_DEFAULT); 571 std::string(), CONTENT_SETTING_DEFAULT);
568 EXPECT_EQ(CONTENT_SETTING_ALLOW, 572 EXPECT_EQ(CONTENT_SETTING_ALLOW,
569 host_content_settings_map->GetContentSetting( 573 host_content_settings_map->GetContentSetting(
570 host_ending_with_dot, host_ending_with_dot, 574 host_ending_with_dot, host_ending_with_dot,
571 CONTENT_SETTINGS_TYPE_AUTOPLAY, std::string())); 575 CONTENT_SETTINGS_TYPE_AUTOPLAY, std::string()));
572 } 576 }
573 577
574 TEST_F(HostContentSettingsMapTest, NestedSettings) { 578 TEST_F(HostContentSettingsMapTest, NestedSettings) {
raymes 2016/06/20 04:43:59 As discussed, this test is a bit confusing so mayb
msramek 2016/06/20 16:20:04 Agreed. We're currently testing that other types
lshang 2016/06/22 01:51:50 Just to clarify, did you mean Pattern::FromString(
575 TestingProfile profile; 579 TestingProfile profile;
576 HostContentSettingsMap* host_content_settings_map = 580 HostContentSettingsMap* host_content_settings_map =
577 HostContentSettingsMapFactory::GetForProfile(&profile); 581 HostContentSettingsMapFactory::GetForProfile(&profile);
578 582
579 GURL host("http://a.b.example.com/"); 583 GURL host("http://a.b.example.com/");
580 GURL host1("http://example.com/"); 584 ContentSettingsPattern pattern1 =
581 GURL host2("http://b.example.com/"); 585 ContentSettingsPattern::FromString("[*.]example.com");
586 ContentSettingsPattern pattern2 =
587 ContentSettingsPattern::FromString("[*.]b.example.com");
588 ContentSettingsPattern pattern3 =
589 ContentSettingsPattern::FromString("a.b.example.com");
582 590
583 host_content_settings_map->SetContentSettingDefaultScope( 591 host_content_settings_map->SetContentSettingCustomScope(
584 host1, GURL(), CONTENT_SETTINGS_TYPE_POPUPS, std::string(), 592 pattern1, ContentSettingsPattern::Wildcard(),
585 CONTENT_SETTING_BLOCK); 593 CONTENT_SETTINGS_TYPE_POPUPS, std::string(), CONTENT_SETTING_BLOCK);
586 594
587 host_content_settings_map->SetContentSettingDefaultScope( 595 host_content_settings_map->SetContentSettingCustomScope(
588 host2, GURL(), CONTENT_SETTINGS_TYPE_COOKIES, std::string(), 596 pattern2, ContentSettingsPattern::Wildcard(),
589 CONTENT_SETTING_BLOCK); 597 CONTENT_SETTINGS_TYPE_COOKIES, std::string(), CONTENT_SETTING_BLOCK);
590 598
591 host_content_settings_map->SetContentSettingDefaultScope( 599 host_content_settings_map->SetContentSettingCustomScope(
592 host, GURL(), CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS, std::string(), 600 pattern3, ContentSettingsPattern::Wildcard(),
601 CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS, std::string(),
593 CONTENT_SETTING_BLOCK); 602 CONTENT_SETTING_BLOCK);
594 host_content_settings_map->SetDefaultContentSetting( 603 host_content_settings_map->SetDefaultContentSetting(
595 CONTENT_SETTINGS_TYPE_JAVASCRIPT, CONTENT_SETTING_BLOCK); 604 CONTENT_SETTINGS_TYPE_JAVASCRIPT, CONTENT_SETTING_BLOCK);
596 605
597 EXPECT_EQ(CONTENT_SETTING_BLOCK, 606 EXPECT_EQ(CONTENT_SETTING_BLOCK,
msramek 2016/06/20 16:20:04 nit: For better readability, please reorder this s
lshang 2016/06/22 01:51:50 Done. I deleted NOTIFICATIONS, FULLSCREEN, MOUSELO
598 host_content_settings_map->GetContentSetting( 607 host_content_settings_map->GetContentSetting(
599 host, host, CONTENT_SETTINGS_TYPE_COOKIES, std::string())); 608 host, host, CONTENT_SETTINGS_TYPE_COOKIES, std::string()));
600 EXPECT_EQ(CONTENT_SETTING_BLOCK, 609 EXPECT_EQ(CONTENT_SETTING_BLOCK,
601 host_content_settings_map->GetContentSetting( 610 host_content_settings_map->GetContentSetting(
602 host, host, CONTENT_SETTINGS_TYPE_POPUPS, std::string())); 611 host, host, CONTENT_SETTINGS_TYPE_POPUPS, std::string()));
603 EXPECT_EQ(CONTENT_SETTING_BLOCK, 612 EXPECT_EQ(CONTENT_SETTING_BLOCK,
604 host_content_settings_map->GetContentSetting( 613 host_content_settings_map->GetContentSetting(
605 host, host, CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string())); 614 host, host, CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string()));
606 EXPECT_EQ(CONTENT_SETTING_BLOCK, 615 EXPECT_EQ(CONTENT_SETTING_BLOCK,
607 host_content_settings_map->GetContentSetting( 616 host_content_settings_map->GetContentSetting(
(...skipping 681 matching lines...) Expand 10 before | Expand all | Expand 10 after
1289 base::DictionaryValue test_value; 1298 base::DictionaryValue test_value;
1290 test_value.SetString("test", "value"); 1299 test_value.SetString("test", "value");
1291 host_content_settings_map->SetWebsiteSettingDefaultScope( 1300 host_content_settings_map->SetWebsiteSettingDefaultScope(
1292 unsupported_url, unsupported_url, CONTENT_SETTINGS_TYPE_APP_BANNER, 1301 unsupported_url, unsupported_url, CONTENT_SETTINGS_TYPE_APP_BANNER,
1293 std::string(), base::WrapUnique(test_value.DeepCopy())); 1302 std::string(), base::WrapUnique(test_value.DeepCopy()));
1294 EXPECT_EQ(nullptr, 1303 EXPECT_EQ(nullptr,
1295 host_content_settings_map->GetWebsiteSetting( 1304 host_content_settings_map->GetWebsiteSetting(
1296 unsupported_url, unsupported_url, 1305 unsupported_url, unsupported_url,
1297 CONTENT_SETTINGS_TYPE_APP_BANNER, std::string(), nullptr)); 1306 CONTENT_SETTINGS_TYPE_APP_BANNER, std::string(), nullptr));
1298 } 1307 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698