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/message_loop/message_loop.h" | 5 #include "base/message_loop/message_loop.h" |
6 #include "chrome/browser/content_settings/cookie_settings_factory.h" | 6 #include "chrome/browser/content_settings/cookie_settings_factory.h" |
7 #include "chrome/test/base/testing_profile.h" | 7 #include "chrome/test/base/testing_profile.h" |
8 #include "components/content_settings/core/browser/cookie_settings.h" | 8 #include "components/content_settings/core/browser/cookie_settings.h" |
9 #include "components/content_settings/core/common/content_settings_pattern.h" | 9 #include "components/content_settings/core/common/content_settings_pattern.h" |
10 #include "components/prefs/pref_service.h" | 10 #include "components/prefs/pref_service.h" |
(...skipping 23 matching lines...) Expand all Loading... |
34 const GURL kFirstPartySite; | 34 const GURL kFirstPartySite; |
35 const GURL kHttpsSite; | 35 const GURL kHttpsSite; |
36 }; | 36 }; |
37 | 37 |
38 TEST_F(CookieSettingsFactoryTest, IncognitoBehaviorOfBlockingRules) { | 38 TEST_F(CookieSettingsFactoryTest, IncognitoBehaviorOfBlockingRules) { |
39 scoped_refptr<content_settings::CookieSettings> incognito_settings = | 39 scoped_refptr<content_settings::CookieSettings> incognito_settings = |
40 CookieSettingsFactory::GetForProfile(profile_.GetOffTheRecordProfile()); | 40 CookieSettingsFactory::GetForProfile(profile_.GetOffTheRecordProfile()); |
41 | 41 |
42 // Modify the regular cookie settings after the incognito cookie settings have | 42 // Modify the regular cookie settings after the incognito cookie settings have |
43 // been instantiated. | 43 // been instantiated. |
44 cookie_settings_->SetCookieSetting( | 44 cookie_settings_->SetCookieSetting(kBlockedSite, CONTENT_SETTING_BLOCK); |
45 ContentSettingsPattern::FromURL(kBlockedSite), | |
46 ContentSettingsPattern::Wildcard(), CONTENT_SETTING_BLOCK); | |
47 | 45 |
48 // The modification should apply to the regular profile and incognito profile. | 46 // The modification should apply to the regular profile and incognito profile. |
49 EXPECT_FALSE( | 47 EXPECT_FALSE( |
50 cookie_settings_->IsReadingCookieAllowed(kBlockedSite, kBlockedSite)); | 48 cookie_settings_->IsReadingCookieAllowed(kBlockedSite, kBlockedSite)); |
51 EXPECT_FALSE( | 49 EXPECT_FALSE( |
52 incognito_settings->IsReadingCookieAllowed(kBlockedSite, kBlockedSite)); | 50 incognito_settings->IsReadingCookieAllowed(kBlockedSite, kBlockedSite)); |
53 | 51 |
54 // Modify an incognito cookie setting and check that this does not propagate | 52 // Modify an incognito cookie setting and check that this does not propagate |
55 // into regular mode. | 53 // into regular mode. |
56 incognito_settings->SetCookieSetting( | 54 incognito_settings->SetCookieSetting(kHttpsSite, CONTENT_SETTING_BLOCK); |
57 ContentSettingsPattern::FromURL(kHttpsSite), | |
58 ContentSettingsPattern::Wildcard(), CONTENT_SETTING_BLOCK); | |
59 EXPECT_TRUE(cookie_settings_->IsReadingCookieAllowed(kHttpsSite, kHttpsSite)); | 55 EXPECT_TRUE(cookie_settings_->IsReadingCookieAllowed(kHttpsSite, kHttpsSite)); |
60 EXPECT_FALSE( | 56 EXPECT_FALSE( |
61 incognito_settings->IsReadingCookieAllowed(kHttpsSite, kHttpsSite)); | 57 incognito_settings->IsReadingCookieAllowed(kHttpsSite, kHttpsSite)); |
62 } | 58 } |
63 | 59 |
64 TEST_F(CookieSettingsFactoryTest, IncognitoBehaviorOfBlockingEverything) { | 60 TEST_F(CookieSettingsFactoryTest, IncognitoBehaviorOfBlockingEverything) { |
65 scoped_refptr<content_settings::CookieSettings> incognito_settings = | 61 scoped_refptr<content_settings::CookieSettings> incognito_settings = |
66 CookieSettingsFactory::GetForProfile(profile_.GetOffTheRecordProfile()); | 62 CookieSettingsFactory::GetForProfile(profile_.GetOffTheRecordProfile()); |
67 | 63 |
68 // Apply the general blocking to the regular profile. | 64 // Apply the general blocking to the regular profile. |
69 cookie_settings_->SetDefaultCookieSetting(CONTENT_SETTING_BLOCK); | 65 cookie_settings_->SetDefaultCookieSetting(CONTENT_SETTING_BLOCK); |
70 | 66 |
71 // It should be effective for regular and incognito session. | 67 // It should be effective for regular and incognito session. |
72 EXPECT_FALSE(cookie_settings_->IsReadingCookieAllowed(kFirstPartySite, | 68 EXPECT_FALSE(cookie_settings_->IsReadingCookieAllowed(kFirstPartySite, |
73 kFirstPartySite)); | 69 kFirstPartySite)); |
74 EXPECT_FALSE(incognito_settings->IsReadingCookieAllowed(kFirstPartySite, | 70 EXPECT_FALSE(incognito_settings->IsReadingCookieAllowed(kFirstPartySite, |
75 kFirstPartySite)); | 71 kFirstPartySite)); |
76 | 72 |
77 // A whitelisted item set in incognito mode should only apply to incognito | 73 // A whitelisted item set in incognito mode should only apply to incognito |
78 // mode. | 74 // mode. |
79 incognito_settings->SetCookieSetting( | 75 incognito_settings->SetCookieSetting(kAllowedSite, CONTENT_SETTING_ALLOW); |
80 ContentSettingsPattern::FromURL(kAllowedSite), | |
81 ContentSettingsPattern::Wildcard(), CONTENT_SETTING_ALLOW); | |
82 EXPECT_TRUE( | 76 EXPECT_TRUE( |
83 incognito_settings->IsReadingCookieAllowed(kAllowedSite, kAllowedSite)); | 77 incognito_settings->IsReadingCookieAllowed(kAllowedSite, kAllowedSite)); |
84 EXPECT_FALSE( | 78 EXPECT_FALSE( |
85 cookie_settings_->IsReadingCookieAllowed(kAllowedSite, kAllowedSite)); | 79 cookie_settings_->IsReadingCookieAllowed(kAllowedSite, kAllowedSite)); |
86 | 80 |
87 // A whitelisted item set in regular mode should apply to regular and | 81 // A whitelisted item set in regular mode should apply to regular and |
88 // incognito mode. | 82 // incognito mode. |
89 cookie_settings_->SetCookieSetting( | 83 cookie_settings_->SetCookieSetting(kHttpsSite, CONTENT_SETTING_ALLOW); |
90 ContentSettingsPattern::FromURL(kHttpsSite), | |
91 ContentSettingsPattern::Wildcard(), CONTENT_SETTING_ALLOW); | |
92 EXPECT_TRUE( | 84 EXPECT_TRUE( |
93 incognito_settings->IsReadingCookieAllowed(kHttpsSite, kHttpsSite)); | 85 incognito_settings->IsReadingCookieAllowed(kHttpsSite, kHttpsSite)); |
94 EXPECT_TRUE(cookie_settings_->IsReadingCookieAllowed(kHttpsSite, kHttpsSite)); | 86 EXPECT_TRUE(cookie_settings_->IsReadingCookieAllowed(kHttpsSite, kHttpsSite)); |
95 } | 87 } |
96 | 88 |
97 } // namespace | 89 } // namespace |
OLD | NEW |