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 "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
11 #include "base/prefs/scoped_user_pref_update.h" | 11 #include "base/prefs/scoped_user_pref_update.h" |
12 #include "chrome/browser/content_settings/content_settings_details.h" | 12 #include "chrome/browser/content_settings/content_settings_details.h" |
13 #include "chrome/browser/content_settings/cookie_settings.h" | 13 #include "chrome/browser/content_settings/cookie_settings.h" |
14 #include "chrome/browser/content_settings/host_content_settings_map.h" | 14 #include "chrome/browser/content_settings/host_content_settings_map.h" |
15 #include "chrome/browser/content_settings/mock_settings_observer.h" | 15 #include "chrome/browser/content_settings/mock_settings_observer.h" |
| 16 #include "chrome/common/chrome_content_settings_client.h" |
16 #include "chrome/common/chrome_switches.h" | 17 #include "chrome/common/chrome_switches.h" |
17 #include "chrome/common/pref_names.h" | 18 #include "chrome/common/pref_names.h" |
18 #include "chrome/common/url_constants.h" | 19 #include "chrome/common/url_constants.h" |
19 #include "chrome/test/base/testing_pref_service_syncable.h" | 20 #include "chrome/test/base/testing_pref_service_syncable.h" |
20 #include "chrome/test/base/testing_profile.h" | 21 #include "chrome/test/base/testing_profile.h" |
21 #include "content/public/test/test_browser_thread.h" | 22 #include "content/public/test/test_browser_thread.h" |
22 #include "net/base/static_cookie_policy.h" | 23 #include "net/base/static_cookie_policy.h" |
23 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
24 #include "url/gurl.h" | 25 #include "url/gurl.h" |
25 | 26 |
26 using content::BrowserThread; | 27 using content::BrowserThread; |
27 | 28 |
28 using ::testing::_; | 29 using ::testing::_; |
29 | 30 |
30 class HostContentSettingsMapTest : public testing::Test { | 31 class HostContentSettingsMapTest : public testing::Test { |
31 public: | 32 public: |
32 HostContentSettingsMapTest() : ui_thread_(BrowserThread::UI, &message_loop_) { | 33 HostContentSettingsMapTest() : ui_thread_(BrowserThread::UI, &message_loop_) { |
33 } | 34 } |
34 | 35 |
| 36 content_settings::ContentSettingsClient* client() { |
| 37 return &client_; |
| 38 } |
| 39 |
35 protected: | 40 protected: |
36 base::MessageLoop message_loop_; | 41 base::MessageLoop message_loop_; |
37 content::TestBrowserThread ui_thread_; | 42 content::TestBrowserThread ui_thread_; |
| 43 content_settings::ChromeContentSettingsClient client_; |
38 }; | 44 }; |
39 | 45 |
40 TEST_F(HostContentSettingsMapTest, DefaultValues) { | 46 TEST_F(HostContentSettingsMapTest, DefaultValues) { |
41 TestingProfile profile; | 47 TestingProfile profile; |
42 HostContentSettingsMap* host_content_settings_map = | 48 HostContentSettingsMap* host_content_settings_map = |
43 profile.GetHostContentSettingsMap(); | 49 profile.GetHostContentSettingsMap(); |
44 | 50 |
45 // Check setting defaults. | 51 // Check setting defaults. |
46 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 52 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
47 host_content_settings_map->GetDefaultContentSetting( | 53 host_content_settings_map->GetDefaultContentSetting( |
(...skipping 23 matching lines...) Expand all Loading... |
71 } | 77 } |
72 | 78 |
73 TEST_F(HostContentSettingsMapTest, IndividualSettings) { | 79 TEST_F(HostContentSettingsMapTest, IndividualSettings) { |
74 TestingProfile profile; | 80 TestingProfile profile; |
75 HostContentSettingsMap* host_content_settings_map = | 81 HostContentSettingsMap* host_content_settings_map = |
76 profile.GetHostContentSettingsMap(); | 82 profile.GetHostContentSettingsMap(); |
77 | 83 |
78 // Check returning individual settings. | 84 // Check returning individual settings. |
79 GURL host("http://example.com/"); | 85 GURL host("http://example.com/"); |
80 ContentSettingsPattern pattern = | 86 ContentSettingsPattern pattern = |
81 ContentSettingsPattern::FromString("[*.]example.com"); | 87 ContentSettingsPattern::FromString(client(), "[*.]example.com"); |
82 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 88 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
83 host_content_settings_map->GetContentSetting( | 89 host_content_settings_map->GetContentSetting( |
84 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); | 90 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); |
85 host_content_settings_map->SetContentSetting( | 91 host_content_settings_map->SetContentSetting( |
86 pattern, | 92 pattern, |
87 ContentSettingsPattern::Wildcard(), | 93 ContentSettingsPattern::Wildcard(), |
88 CONTENT_SETTINGS_TYPE_IMAGES, | 94 CONTENT_SETTINGS_TYPE_IMAGES, |
89 std::string(), | 95 std::string(), |
90 CONTENT_SETTING_DEFAULT); | 96 CONTENT_SETTING_DEFAULT); |
91 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 97 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 host, host, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string())); | 150 host, host, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string())); |
145 EXPECT_EQ(CONTENT_SETTING_ASK, | 151 EXPECT_EQ(CONTENT_SETTING_ASK, |
146 host_content_settings_map->GetContentSetting( | 152 host_content_settings_map->GetContentSetting( |
147 host, host, CONTENT_SETTINGS_TYPE_FULLSCREEN, std::string())); | 153 host, host, CONTENT_SETTINGS_TYPE_FULLSCREEN, std::string())); |
148 EXPECT_EQ(CONTENT_SETTING_ASK, | 154 EXPECT_EQ(CONTENT_SETTING_ASK, |
149 host_content_settings_map->GetContentSetting( | 155 host_content_settings_map->GetContentSetting( |
150 host, host, CONTENT_SETTINGS_TYPE_MOUSELOCK, std::string())); | 156 host, host, CONTENT_SETTINGS_TYPE_MOUSELOCK, std::string())); |
151 | 157 |
152 // Check returning all hosts for a setting. | 158 // Check returning all hosts for a setting. |
153 ContentSettingsPattern pattern2 = | 159 ContentSettingsPattern pattern2 = |
154 ContentSettingsPattern::FromString("[*.]example.org"); | 160 ContentSettingsPattern::FromString(client(), "[*.]example.org"); |
155 host_content_settings_map->SetContentSetting( | 161 host_content_settings_map->SetContentSetting( |
156 pattern2, | 162 pattern2, |
157 ContentSettingsPattern::Wildcard(), | 163 ContentSettingsPattern::Wildcard(), |
158 CONTENT_SETTINGS_TYPE_IMAGES, | 164 CONTENT_SETTINGS_TYPE_IMAGES, |
159 std::string(), | 165 std::string(), |
160 CONTENT_SETTING_BLOCK); | 166 CONTENT_SETTING_BLOCK); |
161 host_content_settings_map->SetContentSetting( | 167 host_content_settings_map->SetContentSetting( |
162 pattern2, | 168 pattern2, |
163 ContentSettingsPattern::Wildcard(), | 169 ContentSettingsPattern::Wildcard(), |
164 CONTENT_SETTINGS_TYPE_PLUGINS, | 170 CONTENT_SETTINGS_TYPE_PLUGINS, |
(...skipping 14 matching lines...) Expand all Loading... |
179 EXPECT_EQ(1U, host_settings.size()); | 185 EXPECT_EQ(1U, host_settings.size()); |
180 } | 186 } |
181 | 187 |
182 TEST_F(HostContentSettingsMapTest, Clear) { | 188 TEST_F(HostContentSettingsMapTest, Clear) { |
183 TestingProfile profile; | 189 TestingProfile profile; |
184 HostContentSettingsMap* host_content_settings_map = | 190 HostContentSettingsMap* host_content_settings_map = |
185 profile.GetHostContentSettingsMap(); | 191 profile.GetHostContentSettingsMap(); |
186 | 192 |
187 // Check clearing one type. | 193 // Check clearing one type. |
188 ContentSettingsPattern pattern = | 194 ContentSettingsPattern pattern = |
189 ContentSettingsPattern::FromString("[*.]example.org"); | 195 ContentSettingsPattern::FromString(client(), "[*.]example.org"); |
190 ContentSettingsPattern pattern2 = | 196 ContentSettingsPattern pattern2 = |
191 ContentSettingsPattern::FromString("[*.]example.net"); | 197 ContentSettingsPattern::FromString(client(), "[*.]example.net"); |
192 host_content_settings_map->SetContentSetting( | 198 host_content_settings_map->SetContentSetting( |
193 pattern2, | 199 pattern2, |
194 ContentSettingsPattern::Wildcard(), | 200 ContentSettingsPattern::Wildcard(), |
195 CONTENT_SETTINGS_TYPE_IMAGES, | 201 CONTENT_SETTINGS_TYPE_IMAGES, |
196 std::string(), | 202 std::string(), |
197 CONTENT_SETTING_BLOCK); | 203 CONTENT_SETTING_BLOCK); |
198 host_content_settings_map->SetContentSetting( | 204 host_content_settings_map->SetContentSetting( |
199 pattern, | 205 pattern, |
200 ContentSettingsPattern::Wildcard(), | 206 ContentSettingsPattern::Wildcard(), |
201 CONTENT_SETTINGS_TYPE_IMAGES, | 207 CONTENT_SETTINGS_TYPE_IMAGES, |
(...skipping 26 matching lines...) Expand all Loading... |
228 | 234 |
229 TEST_F(HostContentSettingsMapTest, Patterns) { | 235 TEST_F(HostContentSettingsMapTest, Patterns) { |
230 TestingProfile profile; | 236 TestingProfile profile; |
231 HostContentSettingsMap* host_content_settings_map = | 237 HostContentSettingsMap* host_content_settings_map = |
232 profile.GetHostContentSettingsMap(); | 238 profile.GetHostContentSettingsMap(); |
233 | 239 |
234 GURL host1("http://example.com/"); | 240 GURL host1("http://example.com/"); |
235 GURL host2("http://www.example.com/"); | 241 GURL host2("http://www.example.com/"); |
236 GURL host3("http://example.org/"); | 242 GURL host3("http://example.org/"); |
237 ContentSettingsPattern pattern1 = | 243 ContentSettingsPattern pattern1 = |
238 ContentSettingsPattern::FromString("[*.]example.com"); | 244 ContentSettingsPattern::FromString(client(), "[*.]example.com"); |
239 ContentSettingsPattern pattern2 = | 245 ContentSettingsPattern pattern2 = |
240 ContentSettingsPattern::FromString("example.org"); | 246 ContentSettingsPattern::FromString(client(), "example.org"); |
241 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 247 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
242 host_content_settings_map->GetContentSetting( | 248 host_content_settings_map->GetContentSetting( |
243 host1, host1, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); | 249 host1, host1, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); |
244 host_content_settings_map->SetContentSetting( | 250 host_content_settings_map->SetContentSetting( |
245 pattern1, | 251 pattern1, |
246 ContentSettingsPattern::Wildcard(), | 252 ContentSettingsPattern::Wildcard(), |
247 CONTENT_SETTINGS_TYPE_IMAGES, | 253 CONTENT_SETTINGS_TYPE_IMAGES, |
248 std::string(), | 254 std::string(), |
249 CONTENT_SETTING_BLOCK); | 255 CONTENT_SETTING_BLOCK); |
250 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 256 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
(...skipping 16 matching lines...) Expand all Loading... |
267 host3, host3, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); | 273 host3, host3, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); |
268 } | 274 } |
269 | 275 |
270 TEST_F(HostContentSettingsMapTest, Observer) { | 276 TEST_F(HostContentSettingsMapTest, Observer) { |
271 TestingProfile profile; | 277 TestingProfile profile; |
272 HostContentSettingsMap* host_content_settings_map = | 278 HostContentSettingsMap* host_content_settings_map = |
273 profile.GetHostContentSettingsMap(); | 279 profile.GetHostContentSettingsMap(); |
274 MockSettingsObserver observer; | 280 MockSettingsObserver observer; |
275 | 281 |
276 ContentSettingsPattern primary_pattern = | 282 ContentSettingsPattern primary_pattern = |
277 ContentSettingsPattern::FromString("[*.]example.com"); | 283 ContentSettingsPattern::FromString(client(), "[*.]example.com"); |
278 ContentSettingsPattern secondary_pattern = | 284 ContentSettingsPattern secondary_pattern = |
279 ContentSettingsPattern::Wildcard(); | 285 ContentSettingsPattern::Wildcard(); |
280 EXPECT_CALL(observer, | 286 EXPECT_CALL(observer, |
281 OnContentSettingsChanged(host_content_settings_map, | 287 OnContentSettingsChanged(host_content_settings_map, |
282 CONTENT_SETTINGS_TYPE_IMAGES, | 288 CONTENT_SETTINGS_TYPE_IMAGES, |
283 false, | 289 false, |
284 primary_pattern, | 290 primary_pattern, |
285 secondary_pattern, | 291 secondary_pattern, |
286 false)); | 292 false)); |
287 host_content_settings_map->SetContentSetting( | 293 host_content_settings_map->SetContentSetting( |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
349 HostContentSettingsMap* host_content_settings_map = | 355 HostContentSettingsMap* host_content_settings_map = |
350 profile.GetHostContentSettingsMap(); | 356 profile.GetHostContentSettingsMap(); |
351 | 357 |
352 PrefService* prefs = profile.GetPrefs(); | 358 PrefService* prefs = profile.GetPrefs(); |
353 | 359 |
354 // Make a copy of the default pref value so we can reset it later. | 360 // Make a copy of the default pref value so we can reset it later. |
355 scoped_ptr<base::Value> default_value(prefs->FindPreference( | 361 scoped_ptr<base::Value> default_value(prefs->FindPreference( |
356 prefs::kContentSettingsPatternPairs)->GetValue()->DeepCopy()); | 362 prefs::kContentSettingsPatternPairs)->GetValue()->DeepCopy()); |
357 | 363 |
358 ContentSettingsPattern pattern = | 364 ContentSettingsPattern pattern = |
359 ContentSettingsPattern::FromString("[*.]example.com"); | 365 ContentSettingsPattern::FromString(client(), "[*.]example.com"); |
360 GURL host("http://example.com"); | 366 GURL host("http://example.com"); |
361 | 367 |
362 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 368 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
363 host_content_settings_map->GetContentSetting( | 369 host_content_settings_map->GetContentSetting( |
364 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); | 370 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); |
365 | 371 |
366 host_content_settings_map->SetContentSetting( | 372 host_content_settings_map->SetContentSetting( |
367 pattern, | 373 pattern, |
368 ContentSettingsPattern::Wildcard(), | 374 ContentSettingsPattern::Wildcard(), |
369 CONTENT_SETTINGS_TYPE_IMAGES, | 375 CONTENT_SETTINGS_TYPE_IMAGES, |
(...skipping 21 matching lines...) Expand all Loading... |
391 } | 397 } |
392 | 398 |
393 TEST_F(HostContentSettingsMapTest, HostTrimEndingDotCheck) { | 399 TEST_F(HostContentSettingsMapTest, HostTrimEndingDotCheck) { |
394 TestingProfile profile; | 400 TestingProfile profile; |
395 HostContentSettingsMap* host_content_settings_map = | 401 HostContentSettingsMap* host_content_settings_map = |
396 profile.GetHostContentSettingsMap(); | 402 profile.GetHostContentSettingsMap(); |
397 CookieSettings* cookie_settings = | 403 CookieSettings* cookie_settings = |
398 CookieSettings::Factory::GetForProfile(&profile).get(); | 404 CookieSettings::Factory::GetForProfile(&profile).get(); |
399 | 405 |
400 ContentSettingsPattern pattern = | 406 ContentSettingsPattern pattern = |
401 ContentSettingsPattern::FromString("[*.]example.com"); | 407 ContentSettingsPattern::FromString(client(), "[*.]example.com"); |
402 GURL host_ending_with_dot("http://example.com./"); | 408 GURL host_ending_with_dot("http://example.com./"); |
403 | 409 |
404 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 410 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
405 host_content_settings_map->GetContentSetting( | 411 host_content_settings_map->GetContentSetting( |
406 host_ending_with_dot, | 412 host_ending_with_dot, |
407 host_ending_with_dot, | 413 host_ending_with_dot, |
408 CONTENT_SETTINGS_TYPE_IMAGES, | 414 CONTENT_SETTINGS_TYPE_IMAGES, |
409 std::string())); | 415 std::string())); |
410 host_content_settings_map->SetContentSetting( | 416 host_content_settings_map->SetContentSetting( |
411 pattern, | 417 pattern, |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
545 std::string())); | 551 std::string())); |
546 } | 552 } |
547 | 553 |
548 TEST_F(HostContentSettingsMapTest, NestedSettings) { | 554 TEST_F(HostContentSettingsMapTest, NestedSettings) { |
549 TestingProfile profile; | 555 TestingProfile profile; |
550 HostContentSettingsMap* host_content_settings_map = | 556 HostContentSettingsMap* host_content_settings_map = |
551 profile.GetHostContentSettingsMap(); | 557 profile.GetHostContentSettingsMap(); |
552 | 558 |
553 GURL host("http://a.b.example.com/"); | 559 GURL host("http://a.b.example.com/"); |
554 ContentSettingsPattern pattern1 = | 560 ContentSettingsPattern pattern1 = |
555 ContentSettingsPattern::FromString("[*.]example.com"); | 561 ContentSettingsPattern::FromString(client(), "[*.]example.com"); |
556 ContentSettingsPattern pattern2 = | 562 ContentSettingsPattern pattern2 = |
557 ContentSettingsPattern::FromString("[*.]b.example.com"); | 563 ContentSettingsPattern::FromString(client(), "[*.]b.example.com"); |
558 ContentSettingsPattern pattern3 = | 564 ContentSettingsPattern pattern3 = |
559 ContentSettingsPattern::FromString("a.b.example.com"); | 565 ContentSettingsPattern::FromString(client(), "a.b.example.com"); |
560 | 566 |
561 host_content_settings_map->SetContentSetting( | 567 host_content_settings_map->SetContentSetting( |
562 pattern1, | 568 pattern1, |
563 ContentSettingsPattern::Wildcard(), | 569 ContentSettingsPattern::Wildcard(), |
564 CONTENT_SETTINGS_TYPE_IMAGES, | 570 CONTENT_SETTINGS_TYPE_IMAGES, |
565 std::string(), | 571 std::string(), |
566 CONTENT_SETTING_BLOCK); | 572 CONTENT_SETTING_BLOCK); |
567 | 573 |
568 host_content_settings_map->SetContentSetting( | 574 host_content_settings_map->SetContentSetting( |
569 pattern2, | 575 pattern2, |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
614 TEST_F(HostContentSettingsMapTest, OffTheRecord) { | 620 TEST_F(HostContentSettingsMapTest, OffTheRecord) { |
615 TestingProfile profile; | 621 TestingProfile profile; |
616 HostContentSettingsMap* host_content_settings_map = | 622 HostContentSettingsMap* host_content_settings_map = |
617 profile.GetHostContentSettingsMap(); | 623 profile.GetHostContentSettingsMap(); |
618 scoped_refptr<HostContentSettingsMap> otr_map( | 624 scoped_refptr<HostContentSettingsMap> otr_map( |
619 new HostContentSettingsMap(profile.GetPrefs(), | 625 new HostContentSettingsMap(profile.GetPrefs(), |
620 true)); | 626 true)); |
621 | 627 |
622 GURL host("http://example.com/"); | 628 GURL host("http://example.com/"); |
623 ContentSettingsPattern pattern = | 629 ContentSettingsPattern pattern = |
624 ContentSettingsPattern::FromString("[*.]example.com"); | 630 ContentSettingsPattern::FromString(client(), "[*.]example.com"); |
625 | 631 |
626 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 632 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
627 host_content_settings_map->GetContentSetting( | 633 host_content_settings_map->GetContentSetting( |
628 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); | 634 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); |
629 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 635 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
630 otr_map->GetContentSetting( | 636 otr_map->GetContentSetting( |
631 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); | 637 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); |
632 | 638 |
633 // Changing content settings on the main map should also affect the | 639 // Changing content settings on the main map should also affect the |
634 // incognito map. | 640 // incognito map. |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
756 | 762 |
757 TEST_F(HostContentSettingsMapTest, | 763 TEST_F(HostContentSettingsMapTest, |
758 GetNonDefaultContentSettingsIfTypeManaged) { | 764 GetNonDefaultContentSettingsIfTypeManaged) { |
759 TestingProfile profile; | 765 TestingProfile profile; |
760 HostContentSettingsMap* host_content_settings_map = | 766 HostContentSettingsMap* host_content_settings_map = |
761 profile.GetHostContentSettingsMap(); | 767 profile.GetHostContentSettingsMap(); |
762 TestingPrefServiceSyncable* prefs = profile.GetTestingPrefService(); | 768 TestingPrefServiceSyncable* prefs = profile.GetTestingPrefService(); |
763 | 769 |
764 // Set pattern for JavaScript setting. | 770 // Set pattern for JavaScript setting. |
765 ContentSettingsPattern pattern = | 771 ContentSettingsPattern pattern = |
766 ContentSettingsPattern::FromString("[*.]example.com"); | 772 ContentSettingsPattern::FromString(client(), "[*.]example.com"); |
767 host_content_settings_map->SetContentSetting( | 773 host_content_settings_map->SetContentSetting( |
768 pattern, | 774 pattern, |
769 ContentSettingsPattern::Wildcard(), | 775 ContentSettingsPattern::Wildcard(), |
770 CONTENT_SETTINGS_TYPE_JAVASCRIPT, | 776 CONTENT_SETTINGS_TYPE_JAVASCRIPT, |
771 std::string(), | 777 std::string(), |
772 CONTENT_SETTING_BLOCK); | 778 CONTENT_SETTING_BLOCK); |
773 | 779 |
774 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 780 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
775 host_content_settings_map->GetDefaultContentSetting( | 781 host_content_settings_map->GetDefaultContentSetting( |
776 CONTENT_SETTINGS_TYPE_JAVASCRIPT, NULL)); | 782 CONTENT_SETTINGS_TYPE_JAVASCRIPT, NULL)); |
(...skipping 19 matching lines...) Expand all Loading... |
796 HostContentSettingsMap* host_content_settings_map = | 802 HostContentSettingsMap* host_content_settings_map = |
797 profile.GetHostContentSettingsMap(); | 803 profile.GetHostContentSettingsMap(); |
798 TestingPrefServiceSyncable* prefs = profile.GetTestingPrefService(); | 804 TestingPrefServiceSyncable* prefs = profile.GetTestingPrefService(); |
799 | 805 |
800 // Block all JavaScript. | 806 // Block all JavaScript. |
801 host_content_settings_map->SetDefaultContentSetting( | 807 host_content_settings_map->SetDefaultContentSetting( |
802 CONTENT_SETTINGS_TYPE_JAVASCRIPT, CONTENT_SETTING_BLOCK); | 808 CONTENT_SETTINGS_TYPE_JAVASCRIPT, CONTENT_SETTING_BLOCK); |
803 | 809 |
804 // Set an exception to allow "[*.]example.com" | 810 // Set an exception to allow "[*.]example.com" |
805 ContentSettingsPattern pattern = | 811 ContentSettingsPattern pattern = |
806 ContentSettingsPattern::FromString("[*.]example.com"); | 812 ContentSettingsPattern::FromString(client(), "[*.]example.com"); |
807 | 813 |
808 host_content_settings_map->SetContentSetting( | 814 host_content_settings_map->SetContentSetting( |
809 pattern, | 815 pattern, |
810 ContentSettingsPattern::Wildcard(), | 816 ContentSettingsPattern::Wildcard(), |
811 CONTENT_SETTINGS_TYPE_JAVASCRIPT, | 817 CONTENT_SETTINGS_TYPE_JAVASCRIPT, |
812 std::string(), | 818 std::string(), |
813 CONTENT_SETTING_ALLOW); | 819 CONTENT_SETTING_ALLOW); |
814 | 820 |
815 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 821 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
816 host_content_settings_map->GetDefaultContentSetting( | 822 host_content_settings_map->GetDefaultContentSetting( |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
891 } | 897 } |
892 | 898 |
893 TEST_F(HostContentSettingsMapTest, GetContentSetting) { | 899 TEST_F(HostContentSettingsMapTest, GetContentSetting) { |
894 TestingProfile profile; | 900 TestingProfile profile; |
895 HostContentSettingsMap* host_content_settings_map = | 901 HostContentSettingsMap* host_content_settings_map = |
896 profile.GetHostContentSettingsMap(); | 902 profile.GetHostContentSettingsMap(); |
897 | 903 |
898 GURL host("http://example.com/"); | 904 GURL host("http://example.com/"); |
899 GURL embedder("chrome://foo"); | 905 GURL embedder("chrome://foo"); |
900 ContentSettingsPattern pattern = | 906 ContentSettingsPattern pattern = |
901 ContentSettingsPattern::FromString("[*.]example.com"); | 907 ContentSettingsPattern::FromString(client(), "[*.]example.com"); |
902 host_content_settings_map->SetContentSetting( | 908 host_content_settings_map->SetContentSetting( |
903 pattern, | 909 pattern, |
904 ContentSettingsPattern::Wildcard(), | 910 ContentSettingsPattern::Wildcard(), |
905 CONTENT_SETTINGS_TYPE_IMAGES, | 911 CONTENT_SETTINGS_TYPE_IMAGES, |
906 std::string(), | 912 std::string(), |
907 CONTENT_SETTING_BLOCK); | 913 CONTENT_SETTING_BLOCK); |
908 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 914 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
909 host_content_settings_map->GetContentSetting( | 915 host_content_settings_map->GetContentSetting( |
910 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); | 916 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); |
911 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 917 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
975 GURL("http://other.com"), | 981 GURL("http://other.com"), |
976 CONTENT_SETTINGS_TYPE_COOKIES, | 982 CONTENT_SETTINGS_TYPE_COOKIES, |
977 std::string())); | 983 std::string())); |
978 EXPECT_EQ(CONTENT_SETTING_SESSION_ONLY, | 984 EXPECT_EQ(CONTENT_SETTING_SESSION_ONLY, |
979 host_content_settings_map->GetContentSetting( | 985 host_content_settings_map->GetContentSetting( |
980 GURL("http://third.com"), | 986 GURL("http://third.com"), |
981 GURL("http://third.com"), | 987 GURL("http://third.com"), |
982 CONTENT_SETTINGS_TYPE_COOKIES, | 988 CONTENT_SETTINGS_TYPE_COOKIES, |
983 std::string())); | 989 std::string())); |
984 } | 990 } |
OLD | NEW |