1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/auto_reset.h"
#include "base/command_line.h"
#include "base/json/json_reader.h"
#include "base/json/json_writer.h"
#include "base/message_loop/message_loop.h"
#include "base/prefs/pref_service.h"
#include "base/prefs/scoped_user_pref_update.h"
#include "chrome/browser/content_settings/content_settings_mock_observer.h"
#include "chrome/browser/content_settings/cookie_settings.h"
#include "chrome/browser/content_settings/mock_settings_observer.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/url_constants.h"
#include "chrome/test/base/testing_pref_service_syncable.h"
#include "chrome/test/base/testing_profile.h"
#include "components/content_settings/core/browser/content_settings_details.h"
#include "components/content_settings/core/browser/host_content_settings_map.h"
#include "content/public/test/test_browser_thread.h"
#include "net/base/static_cookie_policy.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "url/gurl.h"
using content::BrowserThread;
using ::testing::_;
class HostContentSettingsMapTest : public testing::Test {
public:
HostContentSettingsMapTest() : ui_thread_(BrowserThread::UI, &message_loop_) {
}
protected:
base::MessageLoop message_loop_;
content::TestBrowserThread ui_thread_;
};
TEST_F(HostContentSettingsMapTest, DefaultValues) {
TestingProfile profile;
HostContentSettingsMap* host_content_settings_map =
profile.GetHostContentSettingsMap();
// Check setting defaults.
EXPECT_EQ(CONTENT_SETTING_ALLOW,
host_content_settings_map->GetDefaultContentSetting(
CONTENT_SETTINGS_TYPE_JAVASCRIPT, NULL));
host_content_settings_map->SetDefaultContentSetting(
CONTENT_SETTINGS_TYPE_IMAGES, CONTENT_SETTING_BLOCK);
EXPECT_EQ(CONTENT_SETTING_BLOCK,
host_content_settings_map->GetDefaultContentSetting(
CONTENT_SETTINGS_TYPE_IMAGES, NULL));
EXPECT_EQ(CONTENT_SETTING_ALLOW, host_content_settings_map->GetContentSetting(
GURL(chrome::kChromeUINewTabURL),
GURL(chrome::kChromeUINewTabURL),
CONTENT_SETTINGS_TYPE_IMAGES,
std::string()));
host_content_settings_map->SetDefaultContentSetting(
CONTENT_SETTINGS_TYPE_PLUGINS, CONTENT_SETTING_ALLOW);
EXPECT_EQ(CONTENT_SETTING_ALLOW,
host_content_settings_map->GetDefaultContentSetting(
CONTENT_SETTINGS_TYPE_PLUGINS, NULL));
host_content_settings_map->SetDefaultContentSetting(
CONTENT_SETTINGS_TYPE_PLUGINS, CONTENT_SETTING_BLOCK);
EXPECT_EQ(CONTENT_SETTING_BLOCK,
host_content_settings_map->GetDefaultContentSetting(
CONTENT_SETTINGS_TYPE_PLUGINS, NULL));
host_content_settings_map->SetDefaultContentSetting(
CONTENT_SETTINGS_TYPE_PLUGINS, CONTENT_SETTING_ASK);
EXPECT_EQ(CONTENT_SETTING_ASK,
host_content_settings_map->GetDefaultContentSetting(
CONTENT_SETTINGS_TYPE_PLUGINS, NULL));
host_content_settings_map->SetDefaultContentSetting(
CONTENT_SETTINGS_TYPE_PLUGINS, CONTENT_SETTING_DETECT_IMPORTANT_CONTENT);
EXPECT_EQ(CONTENT_SETTING_DETECT_IMPORTANT_CONTENT,
host_content_settings_map->GetDefaultContentSetting(
CONTENT_SETTINGS_TYPE_PLUGINS, NULL));
host_content_settings_map->SetDefaultContentSetting(
CONTENT_SETTINGS_TYPE_POPUPS, CONTENT_SETTING_ALLOW);
EXPECT_EQ(CONTENT_SETTING_ALLOW,
host_content_settings_map->GetDefaultContentSetting(
CONTENT_SETTINGS_TYPE_POPUPS, NULL));
}
TEST_F(HostContentSettingsMapTest, IndividualSettings) {
TestingProfile profile;
HostContentSettingsMap* host_content_settings_map =
profile.GetHostContentSettingsMap();
// Check returning individual settings.
GURL host("http://example.com/");
ContentSettingsPattern pattern =
ContentSettingsPattern::FromString("[*.]example.com");
EXPECT_EQ(CONTENT_SETTING_ALLOW,
host_content_settings_map->GetContentSetting(
host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
host_content_settings_map->SetContentSetting(
pattern,
ContentSettingsPattern::Wildcard(),
CONTENT_SETTINGS_TYPE_IMAGES,
std::string(),
CONTENT_SETTING_DEFAULT);
EXPECT_EQ(CONTENT_SETTING_ALLOW,
host_content_settings_map->GetContentSetting(
host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
host_content_settings_map->SetContentSetting(
pattern,
ContentSettingsPattern::Wildcard(),
CONTENT_SETTINGS_TYPE_IMAGES,
std::string(),
CONTENT_SETTING_BLOCK);
EXPECT_EQ(CONTENT_SETTING_BLOCK,
host_content_settings_map->GetContentSetting(
host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
EXPECT_EQ(CONTENT_SETTING_ALLOW,
host_content_settings_map->GetContentSetting(
host, host, CONTENT_SETTINGS_TYPE_PLUGINS, std::string()));
// Check returning all settings for a host.
host_content_settings_map->SetContentSetting(
pattern,
ContentSettingsPattern::Wildcard(),
CONTENT_SETTINGS_TYPE_IMAGES,
std::string(),
CONTENT_SETTING_DEFAULT);
EXPECT_EQ(CONTENT_SETTING_ALLOW,
host_content_settings_map->GetContentSetting(
host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
host_content_settings_map->SetContentSetting(
pattern,
ContentSettingsPattern::Wildcard(),
CONTENT_SETTINGS_TYPE_JAVASCRIPT,
std::string(),
CONTENT_SETTING_BLOCK);
EXPECT_EQ(CONTENT_SETTING_BLOCK,
host_content_settings_map->GetContentSetting(
host, host, CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string()));
host_content_settings_map->SetContentSetting(
pattern,
ContentSettingsPattern::Wildcard(),
CONTENT_SETTINGS_TYPE_PLUGINS,
std::string(),
CONTENT_SETTING_ALLOW);
EXPECT_EQ(CONTENT_SETTING_ALLOW,
host_content_settings_map->GetContentSetting(
host, host, CONTENT_SETTINGS_TYPE_PLUGINS, std::string()));
EXPECT_EQ(CONTENT_SETTING_BLOCK,
host_content_settings_map->GetContentSetting(
host, host, CONTENT_SETTINGS_TYPE_POPUPS, std::string()));
EXPECT_EQ(CONTENT_SETTING_ASK,
host_content_settings_map->GetContentSetting(
host, host, CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string()));
EXPECT_EQ(
CONTENT_SETTING_ASK,
host_content_settings_map->GetContentSetting(
host, host, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string()));
EXPECT_EQ(CONTENT_SETTING_ASK,
host_content_settings_map->GetContentSetting(
host, host, CONTENT_SETTINGS_TYPE_FULLSCREEN, std::string()));
EXPECT_EQ(CONTENT_SETTING_ASK,
host_content_settings_map->GetContentSetting(
host, host, CONTENT_SETTINGS_TYPE_MOUSELOCK, std::string()));
// Check returning all hosts for a setting.
ContentSettingsPattern pattern2 =
ContentSettingsPattern::FromString("[*.]example.org");
host_content_settings_map->SetContentSetting(
pattern2,
ContentSettingsPattern::Wildcard(),
CONTENT_SETTINGS_TYPE_IMAGES,
std::string(),
CONTENT_SETTING_BLOCK);
host_content_settings_map->SetContentSetting(
pattern2,
ContentSettingsPattern::Wildcard(),
CONTENT_SETTINGS_TYPE_PLUGINS,
std::string(),
CONTENT_SETTING_BLOCK);
ContentSettingsForOneType host_settings;
host_content_settings_map->GetSettingsForOneType(
CONTENT_SETTINGS_TYPE_IMAGES, std::string(), &host_settings);
// |host_settings| contains the default setting and an exception.
EXPECT_EQ(2U, host_settings.size());
host_content_settings_map->GetSettingsForOneType(
CONTENT_SETTINGS_TYPE_PLUGINS, std::string(), &host_settings);
// |host_settings| contains the default setting and 2 exceptions.
EXPECT_EQ(3U, host_settings.size());
host_content_settings_map->GetSettingsForOneType(
CONTENT_SETTINGS_TYPE_POPUPS, std::string(), &host_settings);
// |host_settings| contains only the default setting.
EXPECT_EQ(1U, host_settings.size());
}
TEST_F(HostContentSettingsMapTest, Clear) {
TestingProfile profile;
HostContentSettingsMap* host_content_settings_map =
profile.GetHostContentSettingsMap();
// Check clearing one type.
ContentSettingsPattern pattern =
ContentSettingsPattern::FromString("[*.]example.org");
ContentSettingsPattern pattern2 =
ContentSettingsPattern::FromString("[*.]example.net");
host_content_settings_map->SetContentSetting(
pattern2,
ContentSettingsPattern::Wildcard(),
CONTENT_SETTINGS_TYPE_IMAGES,
std::string(),
CONTENT_SETTING_BLOCK);
host_content_settings_map->SetContentSetting(
pattern,
ContentSettingsPattern::Wildcard(),
CONTENT_SETTINGS_TYPE_IMAGES,
std::string(),
CONTENT_SETTING_BLOCK);
host_content_settings_map->SetContentSetting(
pattern,
ContentSettingsPattern::Wildcard(),
CONTENT_SETTINGS_TYPE_PLUGINS,
std::string(),
CONTENT_SETTING_BLOCK);
host_content_settings_map->SetContentSetting(
pattern2,
ContentSettingsPattern::Wildcard(),
CONTENT_SETTINGS_TYPE_IMAGES,
std::string(),
CONTENT_SETTING_BLOCK);
host_content_settings_map->ClearSettingsForOneType(
CONTENT_SETTINGS_TYPE_IMAGES);
ContentSettingsForOneType host_settings;
host_content_settings_map->GetSettingsForOneType(
CONTENT_SETTINGS_TYPE_IMAGES, std::string(), &host_settings);
// |host_settings| contains only the default setting.
EXPECT_EQ(1U, host_settings.size());
host_content_settings_map->GetSettingsForOneType(
CONTENT_SETTINGS_TYPE_PLUGINS, std::string(), &host_settings);
// |host_settings| contains the default setting and an exception.
EXPECT_EQ(2U, host_settings.size());
}
TEST_F(HostContentSettingsMapTest, Patterns) {
TestingProfile profile;
HostContentSettingsMap* host_content_settings_map =
profile.GetHostContentSettingsMap();
GURL host1("http://example.com/");
GURL host2("http://www.example.com/");
GURL host3("http://example.org/");
ContentSettingsPattern pattern1 =
ContentSettingsPattern::FromString("[*.]example.com");
ContentSettingsPattern pattern2 =
ContentSettingsPattern::FromString("example.org");
EXPECT_EQ(CONTENT_SETTING_ALLOW,
host_content_settings_map->GetContentSetting(
host1, host1, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
host_content_settings_map->SetContentSetting(
pattern1,
ContentSettingsPattern::Wildcard(),
CONTENT_SETTINGS_TYPE_IMAGES,
std::string(),
CONTENT_SETTING_BLOCK);
EXPECT_EQ(CONTENT_SETTING_BLOCK,
host_content_settings_map->GetContentSetting(
host1, host1, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
EXPECT_EQ(CONTENT_SETTING_BLOCK,
host_content_settings_map->GetContentSetting(
host2, host2, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
EXPECT_EQ(CONTENT_SETTING_ALLOW,
host_content_settings_map->GetContentSetting(
host3, host3, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
host_content_settings_map->SetContentSetting(
pattern2,
ContentSettingsPattern::Wildcard(),
CONTENT_SETTINGS_TYPE_IMAGES,
std::string(),
CONTENT_SETTING_BLOCK);
EXPECT_EQ(CONTENT_SETTING_BLOCK,
host_content_settings_map->GetContentSetting(
host3, host3, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
}
TEST_F(HostContentSettingsMapTest, Observer) {
TestingProfile profile;
HostContentSettingsMap* host_content_settings_map =
profile.GetHostContentSettingsMap();
MockSettingsObserver observer(host_content_settings_map);
ContentSettingsPattern primary_pattern =
ContentSettingsPattern::FromString("[*.]example.com");
ContentSettingsPattern secondary_pattern =
ContentSettingsPattern::Wildcard();
EXPECT_CALL(observer,
OnContentSettingsChanged(host_content_settings_map,
CONTENT_SETTINGS_TYPE_IMAGES,
false,
primary_pattern,
secondary_pattern,
false));
host_content_settings_map->SetContentSetting(
primary_pattern,
secondary_pattern,
CONTENT_SETTINGS_TYPE_IMAGES,
std::string(),
CONTENT_SETTING_ALLOW);
::testing::Mock::VerifyAndClearExpectations(&observer);
EXPECT_CALL(observer,
OnContentSettingsChanged(host_content_settings_map,
CONTENT_SETTINGS_TYPE_IMAGES, false,
_, _, true));
host_content_settings_map->ClearSettingsForOneType(
CONTENT_SETTINGS_TYPE_IMAGES);
::testing::Mock::VerifyAndClearExpectations(&observer);
EXPECT_CALL(observer,
OnContentSettingsChanged(host_content_settings_map,
CONTENT_SETTINGS_TYPE_IMAGES, false,
_, _, true));
host_content_settings_map->SetDefaultContentSetting(
CONTENT_SETTINGS_TYPE_IMAGES, CONTENT_SETTING_BLOCK);
}
TEST_F(HostContentSettingsMapTest, ObserveDefaultPref) {
TestingProfile profile;
HostContentSettingsMap* host_content_settings_map =
profile.GetHostContentSettingsMap();
PrefService* prefs = profile.GetPrefs();
// Make a copy of the default pref value so we can reset it later.
scoped_ptr<base::Value> default_value(prefs->FindPreference(
prefs::kDefaultContentSettings)->GetValue()->DeepCopy());
GURL host("http://example.com");
host_content_settings_map->SetDefaultContentSetting(
CONTENT_SETTINGS_TYPE_IMAGES, CONTENT_SETTING_BLOCK);
EXPECT_EQ(CONTENT_SETTING_BLOCK,
host_content_settings_map->GetContentSetting(
host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
// Make a copy of the pref's new value so we can reset it later.
scoped_ptr<base::Value> new_value(prefs->FindPreference(
prefs::kDefaultContentSettings)->GetValue()->DeepCopy());
// Clearing the backing pref should also clear the internal cache.
prefs->Set(prefs::kDefaultContentSettings, *default_value);
EXPECT_EQ(CONTENT_SETTING_ALLOW,
host_content_settings_map->GetContentSetting(
host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
// Reseting the pref to its previous value should update the cache.
prefs->Set(prefs::kDefaultContentSettings, *new_value);
EXPECT_EQ(CONTENT_SETTING_BLOCK,
host_content_settings_map->GetContentSetting(
host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
}
TEST_F(HostContentSettingsMapTest, ObserveExceptionPref) {
TestingProfile profile;
HostContentSettingsMap* host_content_settings_map =
profile.GetHostContentSettingsMap();
PrefService* prefs = profile.GetPrefs();
// Make a copy of the default pref value so we can reset it later.
scoped_ptr<base::Value> default_value(prefs->FindPreference(
prefs::kContentSettingsPatternPairs)->GetValue()->DeepCopy());
ContentSettingsPattern pattern =
ContentSettingsPattern::FromString("[*.]example.com");
GURL host("http://example.com");
EXPECT_EQ(CONTENT_SETTING_ALLOW,
host_content_settings_map->GetContentSetting(
host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
host_content_settings_map->SetContentSetting(
pattern,
ContentSettingsPattern::Wildcard(),
CONTENT_SETTINGS_TYPE_IMAGES,
std::string(),
CONTENT_SETTING_BLOCK);
EXPECT_EQ(CONTENT_SETTING_BLOCK,
host_content_settings_map->GetContentSetting(
host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
// Make a copy of the pref's new value so we can reset it later.
scoped_ptr<base::Value> new_value(prefs->FindPreference(
prefs::kContentSettingsPatternPairs)->GetValue()->DeepCopy());
// Clearing the backing pref should also clear the internal cache.
prefs->Set(prefs::kContentSettingsPatternPairs, *default_value);
EXPECT_EQ(CONTENT_SETTING_ALLOW,
host_content_settings_map->GetContentSetting(
host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
// Reseting the pref to its previous value should update the cache.
prefs->Set(prefs::kContentSettingsPatternPairs, *new_value);
EXPECT_EQ(CONTENT_SETTING_BLOCK,
host_content_settings_map->GetContentSetting(
host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
}
TEST_F(HostContentSettingsMapTest, HostTrimEndingDotCheck) {
TestingProfile profile;
HostContentSettingsMap* host_content_settings_map =
profile.GetHostContentSettingsMap();
CookieSettings* cookie_settings =
CookieSettings::Factory::GetForProfile(&profile).get();
ContentSettingsPattern pattern =
ContentSettingsPattern::FromString("[*.]example.com");
GURL host_ending_with_dot("http://example.com./");
EXPECT_EQ(CONTENT_SETTING_ALLOW,
host_content_settings_map->GetContentSetting(
host_ending_with_dot,
host_ending_with_dot,
CONTENT_SETTINGS_TYPE_IMAGES,
std::string()));
host_content_settings_map->SetContentSetting(
pattern,
ContentSettingsPattern::Wildcard(),
CONTENT_SETTINGS_TYPE_IMAGES,
std::string(),
CONTENT_SETTING_DEFAULT);
EXPECT_EQ(
CONTENT_SETTING_ALLOW,
host_content_settings_map->GetContentSetting(host_ending_with_dot,
host_ending_with_dot,
CONTENT_SETTINGS_TYPE_IMAGES,
std::string()));
host_content_settings_map->SetContentSetting(
pattern,
ContentSettingsPattern::Wildcard(),
CONTENT_SETTINGS_TYPE_IMAGES,
std::string(),
CONTENT_SETTING_BLOCK);
EXPECT_EQ(
CONTENT_SETTING_BLOCK,
host_content_settings_map->GetContentSetting(host_ending_with_dot,
host_ending_with_dot,
CONTENT_SETTINGS_TYPE_IMAGES,
std::string()));
EXPECT_TRUE(cookie_settings->IsSettingCookieAllowed(
host_ending_with_dot, host_ending_with_dot));
host_content_settings_map->SetContentSetting(
pattern,
ContentSettingsPattern::Wildcard(),
CONTENT_SETTINGS_TYPE_COOKIES,
std::string(),
CONTENT_SETTING_DEFAULT);
EXPECT_TRUE(cookie_settings->IsSettingCookieAllowed(
host_ending_with_dot, host_ending_with_dot));
host_content_settings_map->SetContentSetting(
pattern,
ContentSettingsPattern::Wildcard(),
CONTENT_SETTINGS_TYPE_COOKIES,
std::string(),
CONTENT_SETTING_BLOCK);
EXPECT_FALSE(cookie_settings->IsSettingCookieAllowed(
host_ending_with_dot, host_ending_with_dot));
EXPECT_EQ(CONTENT_SETTING_ALLOW,
host_content_settings_map->GetContentSetting(
host_ending_with_dot,
host_ending_with_dot,
CONTENT_SETTINGS_TYPE_JAVASCRIPT,
std::string()));
host_content_settings_map->SetContentSetting(
pattern,
ContentSettingsPattern::Wildcard(),
CONTENT_SETTINGS_TYPE_JAVASCRIPT,
std::string(),
CONTENT_SETTING_DEFAULT);
EXPECT_EQ(CONTENT_SETTING_ALLOW,
host_content_settings_map->GetContentSetting(
host_ending_with_dot,
host_ending_with_dot,
CONTENT_SETTINGS_TYPE_JAVASCRIPT,
std::string()));
host_content_settings_map->SetContentSetting(
pattern,
ContentSettingsPattern::Wildcard(),
CONTENT_SETTINGS_TYPE_JAVASCRIPT,
std::string(),
CONTENT_SETTING_BLOCK);
EXPECT_EQ(CONTENT_SETTING_BLOCK,
host_content_settings_map->GetContentSetting(
host_ending_with_dot,
host_ending_with_dot,
CONTENT_SETTINGS_TYPE_JAVASCRIPT,
std::string()));
EXPECT_EQ(CONTENT_SETTING_ALLOW,
host_content_settings_map->GetContentSetting(
host_ending_with_dot,
host_ending_with_dot,
CONTENT_SETTINGS_TYPE_PLUGINS,
std::string()));
host_content_settings_map->SetContentSetting(
pattern,
ContentSettingsPattern::Wildcard(),
CONTENT_SETTINGS_TYPE_PLUGINS,
std::string(),
CONTENT_SETTING_DEFAULT);
EXPECT_EQ(CONTENT_SETTING_ALLOW,
host_content_settings_map->GetContentSetting(
host_ending_with_dot,
host_ending_with_dot,
CONTENT_SETTINGS_TYPE_PLUGINS,
std::string()));
host_content_settings_map->SetContentSetting(
pattern,
ContentSettingsPattern::Wildcard(),
CONTENT_SETTINGS_TYPE_PLUGINS,
std::string(),
CONTENT_SETTING_BLOCK);
EXPECT_EQ(CONTENT_SETTING_BLOCK,
host_content_settings_map->GetContentSetting(
host_ending_with_dot,
host_ending_with_dot,
CONTENT_SETTINGS_TYPE_PLUGINS,
std::string()));
EXPECT_EQ(
CONTENT_SETTING_BLOCK,
host_content_settings_map->GetContentSetting(host_ending_with_dot,
host_ending_with_dot,
CONTENT_SETTINGS_TYPE_POPUPS,
std::string()));
host_content_settings_map->SetContentSetting(
pattern,
ContentSettingsPattern::Wildcard(),
CONTENT_SETTINGS_TYPE_POPUPS,
std::string(),
CONTENT_SETTING_DEFAULT);
EXPECT_EQ(
CONTENT_SETTING_BLOCK,
host_content_settings_map->GetContentSetting(host_ending_with_dot,
host_ending_with_dot,
CONTENT_SETTINGS_TYPE_POPUPS,
std::string()));
host_content_settings_map->SetContentSetting(
pattern,
ContentSettingsPattern::Wildcard(),
CONTENT_SETTINGS_TYPE_POPUPS,
std::string(),
CONTENT_SETTING_ALLOW);
EXPECT_EQ(
CONTENT_SETTING_ALLOW,
host_content_settings_map->GetContentSetting(host_ending_with_dot,
host_ending_with_dot,
CONTENT_SETTINGS_TYPE_POPUPS,
std::string()));
}
TEST_F(HostContentSettingsMapTest, NestedSettings) {
TestingProfile profile;
HostContentSettingsMap* host_content_settings_map =
profile.GetHostContentSettingsMap();
GURL host("http://a.b.example.com/");
ContentSettingsPattern pattern1 =
ContentSettingsPattern::FromString("[*.]example.com");
ContentSettingsPattern pattern2 =
ContentSettingsPattern::FromString("[*.]b.example.com");
ContentSettingsPattern pattern3 =
ContentSettingsPattern::FromString("a.b.example.com");
host_content_settings_map->SetContentSetting(
pattern1,
ContentSettingsPattern::Wildcard(),
CONTENT_SETTINGS_TYPE_IMAGES,
std::string(),
CONTENT_SETTING_BLOCK);
host_content_settings_map->SetContentSetting(
pattern2,
ContentSettingsPattern::Wildcard(),
CONTENT_SETTINGS_TYPE_COOKIES,
std::string(),
CONTENT_SETTING_BLOCK);
host_content_settings_map->SetContentSetting(
pattern3,
ContentSettingsPattern::Wildcard(),
CONTENT_SETTINGS_TYPE_PLUGINS,
std::string(),
CONTENT_SETTING_BLOCK);
host_content_settings_map->SetDefaultContentSetting(
CONTENT_SETTINGS_TYPE_JAVASCRIPT, CONTENT_SETTING_BLOCK);
EXPECT_EQ(CONTENT_SETTING_BLOCK,
host_content_settings_map->GetContentSetting(
host, host, CONTENT_SETTINGS_TYPE_COOKIES, std::string()));
EXPECT_EQ(CONTENT_SETTING_BLOCK,
host_content_settings_map->GetContentSetting(
host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
EXPECT_EQ(CONTENT_SETTING_BLOCK,
host_content_settings_map->GetContentSetting(
host, host, CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string()));
EXPECT_EQ(CONTENT_SETTING_BLOCK,
host_content_settings_map->GetContentSetting(
host, host, CONTENT_SETTINGS_TYPE_PLUGINS, std::string()));
EXPECT_EQ(CONTENT_SETTING_BLOCK,
host_content_settings_map->GetContentSetting(
host, host, CONTENT_SETTINGS_TYPE_POPUPS, std::string()));
EXPECT_EQ(CONTENT_SETTING_ASK,
host_content_settings_map->GetContentSetting(
host, host, CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string()));
EXPECT_EQ(
CONTENT_SETTING_ASK,
host_content_settings_map->GetContentSetting(
host, host, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string()));
EXPECT_EQ(CONTENT_SETTING_ASK,
host_content_settings_map->GetContentSetting(
host, host, CONTENT_SETTINGS_TYPE_FULLSCREEN, std::string()));
EXPECT_EQ(CONTENT_SETTING_ASK,
host_content_settings_map->GetContentSetting(
host, host, CONTENT_SETTINGS_TYPE_MOUSELOCK, std::string()));
}
TEST_F(HostContentSettingsMapTest, OffTheRecord) {
TestingProfile profile;
HostContentSettingsMap* host_content_settings_map =
profile.GetHostContentSettingsMap();
scoped_refptr<HostContentSettingsMap> otr_map(
new HostContentSettingsMap(profile.GetPrefs(),
true));
GURL host("http://example.com/");
ContentSettingsPattern pattern =
ContentSettingsPattern::FromString("[*.]example.com");
EXPECT_EQ(CONTENT_SETTING_ALLOW,
host_content_settings_map->GetContentSetting(
host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
EXPECT_EQ(CONTENT_SETTING_ALLOW,
otr_map->GetContentSetting(
host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
// Changing content settings on the main map should also affect the
// incognito map.
host_content_settings_map->SetContentSetting(
pattern,
ContentSettingsPattern::Wildcard(),
CONTENT_SETTINGS_TYPE_IMAGES,
std::string(),
CONTENT_SETTING_BLOCK);
EXPECT_EQ(CONTENT_SETTING_BLOCK,
host_content_settings_map->GetContentSetting(
host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
EXPECT_EQ(CONTENT_SETTING_BLOCK,
otr_map->GetContentSetting(
host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
// Changing content settings on the incognito map should NOT affect the
// main map.
otr_map->SetContentSetting(pattern,
ContentSettingsPattern::Wildcard(),
CONTENT_SETTINGS_TYPE_IMAGES,
std::string(),
CONTENT_SETTING_ALLOW);
EXPECT_EQ(CONTENT_SETTING_BLOCK,
host_content_settings_map->GetContentSetting(
host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
EXPECT_EQ(CONTENT_SETTING_ALLOW,
otr_map->GetContentSetting(
host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
otr_map->ShutdownOnUIThread();
}
// For a single Unicode encoded pattern, check if it gets converted to punycode
// and old pattern gets deleted.
TEST_F(HostContentSettingsMapTest, CanonicalizeExceptionsUnicodeOnly) {
TestingProfile profile;
PrefService* prefs = profile.GetPrefs();
// Set utf-8 data.
{
DictionaryPrefUpdate update(prefs, prefs::kContentSettingsPatternPairs);
base::DictionaryValue* all_settings_dictionary = update.Get();
ASSERT_TRUE(NULL != all_settings_dictionary);
base::DictionaryValue* dummy_payload = new base::DictionaryValue;
dummy_payload->SetInteger("images", CONTENT_SETTING_ALLOW);
all_settings_dictionary->SetWithoutPathExpansion("[*.]\xC4\x87ira.com,*",
dummy_payload);
}
profile.GetHostContentSettingsMap();
const base::DictionaryValue* all_settings_dictionary =
prefs->GetDictionary(prefs::kContentSettingsPatternPairs);
const base::DictionaryValue* result = NULL;
EXPECT_FALSE(all_settings_dictionary->GetDictionaryWithoutPathExpansion(
"[*.]\xC4\x87ira.com,*", &result));
EXPECT_TRUE(all_settings_dictionary->GetDictionaryWithoutPathExpansion(
"[*.]xn--ira-ppa.com,*", &result));
}
// If both Unicode and its punycode pattern exist, make sure we don't touch the
// settings for the punycode, and that Unicode pattern gets deleted.
TEST_F(HostContentSettingsMapTest, CanonicalizeExceptionsUnicodeAndPunycode) {
TestingProfile profile;
scoped_ptr<base::Value> value(base::JSONReader::Read(
"{\"[*.]\\xC4\\x87ira.com,*\":{\"images\":1}}"));
profile.GetPrefs()->Set(prefs::kContentSettingsPatternPairs, *value);
// Set punycode equivalent, with different setting.
scoped_ptr<base::Value> puny_value(base::JSONReader::Read(
"{\"[*.]xn--ira-ppa.com,*\":{\"images\":2}}"));
profile.GetPrefs()->Set(prefs::kContentSettingsPatternPairs, *puny_value);
// Initialize the content map.
profile.GetHostContentSettingsMap();
const base::DictionaryValue* content_setting_prefs =
profile.GetPrefs()->GetDictionary(prefs::kContentSettingsPatternPairs);
std::string prefs_as_json;
base::JSONWriter::Write(content_setting_prefs, &prefs_as_json);
EXPECT_STREQ("{\"[*.]xn--ira-ppa.com,*\":{\"images\":2}}",
prefs_as_json.c_str());
}
// If a default-content-setting is managed, the managed value should be used
// instead of the default value.
TEST_F(HostContentSettingsMapTest, ManagedDefaultContentSetting) {
TestingProfile profile;
HostContentSettingsMap* host_content_settings_map =
profile.GetHostContentSettingsMap();
TestingPrefServiceSyncable* prefs = profile.GetTestingPrefService();
EXPECT_EQ(CONTENT_SETTING_ALLOW,
host_content_settings_map->GetDefaultContentSetting(
CONTENT_SETTINGS_TYPE_JAVASCRIPT, NULL));
// Set managed-default-content-setting through the coresponding preferences.
prefs->SetManagedPref(prefs::kManagedDefaultJavaScriptSetting,
new base::FundamentalValue(CONTENT_SETTING_BLOCK));
EXPECT_EQ(CONTENT_SETTING_BLOCK,
host_content_settings_map->GetDefaultContentSetting(
CONTENT_SETTINGS_TYPE_JAVASCRIPT, NULL));
// Remove managed-default-content-settings-preferences.
prefs->RemoveManagedPref(prefs::kManagedDefaultJavaScriptSetting);
EXPECT_EQ(CONTENT_SETTING_ALLOW,
host_content_settings_map->GetDefaultContentSetting(
CONTENT_SETTINGS_TYPE_JAVASCRIPT, NULL));
// Set preference to manage the default-content-setting for Plugins.
prefs->SetManagedPref(prefs::kManagedDefaultPluginsSetting,
new base::FundamentalValue(CONTENT_SETTING_BLOCK));
EXPECT_EQ(CONTENT_SETTING_BLOCK,
host_content_settings_map->GetDefaultContentSetting(
CONTENT_SETTINGS_TYPE_PLUGINS, NULL));
// Remove the preference to manage the default-content-setting for Plugins.
prefs->RemoveManagedPref(prefs::kManagedDefaultPluginsSetting);
EXPECT_EQ(CONTENT_SETTING_ALLOW,
host_content_settings_map->GetDefaultContentSetting(
CONTENT_SETTINGS_TYPE_PLUGINS, NULL));
}
TEST_F(HostContentSettingsMapTest,
GetNonDefaultContentSettingsIfTypeManaged) {
TestingProfile profile;
HostContentSettingsMap* host_content_settings_map =
profile.GetHostContentSettingsMap();
TestingPrefServiceSyncable* prefs = profile.GetTestingPrefService();
// Set pattern for JavaScript setting.
ContentSettingsPattern pattern =
ContentSettingsPattern::FromString("[*.]example.com");
host_content_settings_map->SetContentSetting(
pattern,
ContentSettingsPattern::Wildcard(),
CONTENT_SETTINGS_TYPE_JAVASCRIPT,
std::string(),
CONTENT_SETTING_BLOCK);
EXPECT_EQ(CONTENT_SETTING_ALLOW,
host_content_settings_map->GetDefaultContentSetting(
CONTENT_SETTINGS_TYPE_JAVASCRIPT, NULL));
GURL host("http://example.com/");
EXPECT_EQ(CONTENT_SETTING_BLOCK,
host_content_settings_map->GetContentSetting(
host, host, CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string()));
// Set managed-default-content-setting for content-settings-type JavaScript.
prefs->SetManagedPref(prefs::kManagedDefaultJavaScriptSetting,
new base::FundamentalValue(CONTENT_SETTING_ALLOW));
EXPECT_EQ(CONTENT_SETTING_ALLOW,
host_content_settings_map->GetContentSetting(
host, host, CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string()));
}
// Managed default content setting should have higher priority
// than user defined patterns.
TEST_F(HostContentSettingsMapTest,
ManagedDefaultContentSettingIgnoreUserPattern) {
TestingProfile profile;
HostContentSettingsMap* host_content_settings_map =
profile.GetHostContentSettingsMap();
TestingPrefServiceSyncable* prefs = profile.GetTestingPrefService();
// Block all JavaScript.
host_content_settings_map->SetDefaultContentSetting(
CONTENT_SETTINGS_TYPE_JAVASCRIPT, CONTENT_SETTING_BLOCK);
// Set an exception to allow "[*.]example.com"
ContentSettingsPattern pattern =
ContentSettingsPattern::FromString("[*.]example.com");
host_content_settings_map->SetContentSetting(
pattern,
ContentSettingsPattern::Wildcard(),
CONTENT_SETTINGS_TYPE_JAVASCRIPT,
std::string(),
CONTENT_SETTING_ALLOW);
EXPECT_EQ(CONTENT_SETTING_BLOCK,
host_content_settings_map->GetDefaultContentSetting(
CONTENT_SETTINGS_TYPE_JAVASCRIPT, NULL));
GURL host("http://example.com/");
EXPECT_EQ(CONTENT_SETTING_ALLOW,
host_content_settings_map->GetContentSetting(
host, host, CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string()));
// Set managed-default-content-settings-preferences.
prefs->SetManagedPref(prefs::kManagedDefaultJavaScriptSetting,
new base::FundamentalValue(CONTENT_SETTING_BLOCK));
EXPECT_EQ(CONTENT_SETTING_BLOCK,
host_content_settings_map->GetContentSetting(
host, host, CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string()));
// Remove managed-default-content-settings-preferences.
prefs->RemoveManagedPref(prefs::kManagedDefaultJavaScriptSetting);
EXPECT_EQ(CONTENT_SETTING_ALLOW,
host_content_settings_map->GetContentSetting(
host, host, CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string()));
}
// If a default-content-setting is set to managed setting, the user defined
// setting should be preserved.
TEST_F(HostContentSettingsMapTest, OverwrittenDefaultContentSetting) {
TestingProfile profile;
HostContentSettingsMap* host_content_settings_map =
profile.GetHostContentSettingsMap();
TestingPrefServiceSyncable* prefs = profile.GetTestingPrefService();
// Set user defined default-content-setting for Cookies.
host_content_settings_map->SetDefaultContentSetting(
CONTENT_SETTINGS_TYPE_COOKIES, CONTENT_SETTING_BLOCK);
EXPECT_EQ(CONTENT_SETTING_BLOCK,
host_content_settings_map->GetDefaultContentSetting(
CONTENT_SETTINGS_TYPE_COOKIES, NULL));
// Set preference to manage the default-content-setting for Cookies.
prefs->SetManagedPref(prefs::kManagedDefaultCookiesSetting,
new base::FundamentalValue(CONTENT_SETTING_ALLOW));
EXPECT_EQ(CONTENT_SETTING_ALLOW,
host_content_settings_map->GetDefaultContentSetting(
CONTENT_SETTINGS_TYPE_COOKIES, NULL));
// Remove the preference to manage the default-content-setting for Cookies.
prefs->RemoveManagedPref(prefs::kManagedDefaultCookiesSetting);
EXPECT_EQ(CONTENT_SETTING_BLOCK,
host_content_settings_map->GetDefaultContentSetting(
CONTENT_SETTINGS_TYPE_COOKIES, NULL));
}
// If a setting for a default-content-setting-type is set while the type is
// managed, then the new setting should be preserved and used after the
// default-content-setting-type is not managed anymore.
TEST_F(HostContentSettingsMapTest, SettingDefaultContentSettingsWhenManaged) {
TestingProfile profile;
HostContentSettingsMap* host_content_settings_map =
profile.GetHostContentSettingsMap();
TestingPrefServiceSyncable* prefs = profile.GetTestingPrefService();
prefs->SetManagedPref(prefs::kManagedDefaultPluginsSetting,
new base::FundamentalValue(CONTENT_SETTING_ALLOW));
EXPECT_EQ(CONTENT_SETTING_ALLOW,
host_content_settings_map->GetDefaultContentSetting(
CONTENT_SETTINGS_TYPE_PLUGINS, NULL));
host_content_settings_map->SetDefaultContentSetting(
CONTENT_SETTINGS_TYPE_PLUGINS, CONTENT_SETTING_BLOCK);
EXPECT_EQ(CONTENT_SETTING_ALLOW,
host_content_settings_map->GetDefaultContentSetting(
CONTENT_SETTINGS_TYPE_PLUGINS, NULL));
prefs->RemoveManagedPref(prefs::kManagedDefaultPluginsSetting);
EXPECT_EQ(CONTENT_SETTING_BLOCK,
host_content_settings_map->GetDefaultContentSetting(
CONTENT_SETTINGS_TYPE_PLUGINS, NULL));
}
TEST_F(HostContentSettingsMapTest, GetContentSetting) {
TestingProfile profile;
HostContentSettingsMap* host_content_settings_map =
profile.GetHostContentSettingsMap();
GURL host("http://example.com/");
GURL embedder("chrome://foo");
ContentSettingsPattern pattern =
ContentSettingsPattern::FromString("[*.]example.com");
host_content_settings_map->SetContentSetting(
pattern,
ContentSettingsPattern::Wildcard(),
CONTENT_SETTINGS_TYPE_IMAGES,
std::string(),
CONTENT_SETTING_BLOCK);
EXPECT_EQ(CONTENT_SETTING_BLOCK,
host_content_settings_map->GetContentSetting(
host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
EXPECT_EQ(CONTENT_SETTING_ALLOW,
host_content_settings_map->GetContentSetting(
embedder, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
}
TEST_F(HostContentSettingsMapTest, ShouldAllowAllContent) {
GURL http_host("http://example.com/");
GURL https_host("https://example.com/");
GURL embedder("chrome://foo");
GURL extension("chrome-extension://foo");
EXPECT_FALSE(HostContentSettingsMap::ShouldAllowAllContent(
http_host, embedder, CONTENT_SETTINGS_TYPE_NOTIFICATIONS));
EXPECT_FALSE(HostContentSettingsMap::ShouldAllowAllContent(
http_host, embedder, CONTENT_SETTINGS_TYPE_GEOLOCATION));
EXPECT_FALSE(HostContentSettingsMap::ShouldAllowAllContent(
http_host, embedder, CONTENT_SETTINGS_TYPE_COOKIES));
EXPECT_TRUE(HostContentSettingsMap::ShouldAllowAllContent(
https_host, embedder, CONTENT_SETTINGS_TYPE_COOKIES));
EXPECT_TRUE(HostContentSettingsMap::ShouldAllowAllContent(
https_host, embedder, CONTENT_SETTINGS_TYPE_COOKIES));
EXPECT_TRUE(HostContentSettingsMap::ShouldAllowAllContent(
embedder, http_host, CONTENT_SETTINGS_TYPE_COOKIES));
#if defined(ENABLE_EXTENSIONS)
EXPECT_TRUE(HostContentSettingsMap::ShouldAllowAllContent(
extension, extension, CONTENT_SETTINGS_TYPE_COOKIES));
#else
EXPECT_FALSE(HostContentSettingsMap::ShouldAllowAllContent(
extension, extension, CONTENT_SETTINGS_TYPE_COOKIES));
#endif
EXPECT_FALSE(HostContentSettingsMap::ShouldAllowAllContent(
extension, extension, CONTENT_SETTINGS_TYPE_PLUGINS));
EXPECT_FALSE(HostContentSettingsMap::ShouldAllowAllContent(
extension, http_host, CONTENT_SETTINGS_TYPE_COOKIES));
}
TEST_F(HostContentSettingsMapTest, AddContentSettingsObserver) {
TestingProfile profile;
HostContentSettingsMap* host_content_settings_map =
profile.GetHostContentSettingsMap();
content_settings::MockObserver mock_observer;
GURL host("http://example.com/");
ContentSettingsPattern pattern =
ContentSettingsPattern::FromString("[*.]example.com");
EXPECT_CALL(mock_observer,
OnContentSettingChanged(pattern,
ContentSettingsPattern::Wildcard(),
CONTENT_SETTINGS_TYPE_IMAGES,
""));
host_content_settings_map->AddObserver(&mock_observer);
EXPECT_EQ(CONTENT_SETTING_ALLOW,
host_content_settings_map->GetContentSetting(
host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
host_content_settings_map->SetContentSetting(
pattern,
ContentSettingsPattern::Wildcard(),
CONTENT_SETTINGS_TYPE_IMAGES,
std::string(),
CONTENT_SETTING_DEFAULT);
}
TEST_F(HostContentSettingsMapTest, OverrideAllowedWebsiteSetting) {
TestingProfile profile;
HostContentSettingsMap* host_content_settings_map =
profile.GetHostContentSettingsMap();
GURL host("http://example.com/");
ContentSettingsPattern pattern =
ContentSettingsPattern::FromString("[*.]example.com");
host_content_settings_map->SetContentSetting(
pattern,
ContentSettingsPattern::Wildcard(),
CONTENT_SETTINGS_TYPE_GEOLOCATION,
std::string(),
CONTENT_SETTING_ALLOW);
EXPECT_EQ(CONTENT_SETTING_ALLOW,
host_content_settings_map->GetContentSetting(
host, host, CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string()));
// Disabling should override an allowed exception.
host_content_settings_map->SetContentSettingOverride(
CONTENT_SETTINGS_TYPE_GEOLOCATION, false);
EXPECT_EQ(CONTENT_SETTING_BLOCK,
host_content_settings_map->GetContentSetting(
host, host, CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string()));
host_content_settings_map->SetContentSettingOverride(
CONTENT_SETTINGS_TYPE_GEOLOCATION, true);
EXPECT_EQ(CONTENT_SETTING_ALLOW,
host_content_settings_map->GetContentSetting(
host, host, CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string()));
}
TEST_F(HostContentSettingsMapTest, OverrideAllowedDefaultSetting) {
TestingProfile profile;
HostContentSettingsMap* host_content_settings_map =
profile.GetHostContentSettingsMap();
// Check setting defaults.
EXPECT_EQ(CONTENT_SETTING_ALLOW,
host_content_settings_map->GetDefaultContentSetting(
CONTENT_SETTINGS_TYPE_IMAGES, NULL));
GURL host("http://example.com/");
EXPECT_EQ(CONTENT_SETTING_ALLOW,
host_content_settings_map->GetContentSetting(
host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
// Disabling should override an allowed default setting.
host_content_settings_map->SetContentSettingOverride(
CONTENT_SETTINGS_TYPE_IMAGES, false);
EXPECT_EQ(CONTENT_SETTING_BLOCK,
host_content_settings_map->GetContentSetting(
host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
// Enabling shouldn't override positively.
host_content_settings_map->SetContentSettingOverride(
CONTENT_SETTINGS_TYPE_IMAGES, true);
EXPECT_EQ(CONTENT_SETTING_ALLOW,
host_content_settings_map->GetContentSetting(
host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
host_content_settings_map->SetDefaultContentSetting(
CONTENT_SETTINGS_TYPE_IMAGES, CONTENT_SETTING_BLOCK);
EXPECT_EQ(CONTENT_SETTING_BLOCK,
host_content_settings_map->GetContentSetting(
host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
}
|