| 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 27 matching lines...) Expand all Loading... |
| 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(kBlockedSite, CONTENT_SETTING_BLOCK); | 44 cookie_settings_->SetCookieSetting(kBlockedSite, CONTENT_SETTING_BLOCK); |
| 45 | 45 |
| 46 // The modification should apply to the regular profile and incognito profile. | 46 // The modification should apply to the regular profile and incognito profile. |
| 47 EXPECT_FALSE( | 47 EXPECT_FALSE( |
| 48 cookie_settings_->IsReadingCookieAllowed(kBlockedSite, kBlockedSite)); | 48 cookie_settings_->IsCookieAccessAllowed(kBlockedSite, kBlockedSite)); |
| 49 EXPECT_FALSE( | 49 EXPECT_FALSE( |
| 50 incognito_settings->IsReadingCookieAllowed(kBlockedSite, kBlockedSite)); | 50 incognito_settings->IsCookieAccessAllowed(kBlockedSite, kBlockedSite)); |
| 51 | 51 |
| 52 // 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 |
| 53 // into regular mode. | 53 // into regular mode. |
| 54 incognito_settings->SetCookieSetting(kHttpsSite, CONTENT_SETTING_BLOCK); | 54 incognito_settings->SetCookieSetting(kHttpsSite, CONTENT_SETTING_BLOCK); |
| 55 EXPECT_TRUE(cookie_settings_->IsReadingCookieAllowed(kHttpsSite, kHttpsSite)); | 55 EXPECT_TRUE(cookie_settings_->IsCookieAccessAllowed(kHttpsSite, kHttpsSite)); |
| 56 EXPECT_FALSE( | 56 EXPECT_FALSE( |
| 57 incognito_settings->IsReadingCookieAllowed(kHttpsSite, kHttpsSite)); | 57 incognito_settings->IsCookieAccessAllowed(kHttpsSite, kHttpsSite)); |
| 58 } | 58 } |
| 59 | 59 |
| 60 TEST_F(CookieSettingsFactoryTest, IncognitoBehaviorOfBlockingEverything) { | 60 TEST_F(CookieSettingsFactoryTest, IncognitoBehaviorOfBlockingEverything) { |
| 61 scoped_refptr<content_settings::CookieSettings> incognito_settings = | 61 scoped_refptr<content_settings::CookieSettings> incognito_settings = |
| 62 CookieSettingsFactory::GetForProfile(profile_.GetOffTheRecordProfile()); | 62 CookieSettingsFactory::GetForProfile(profile_.GetOffTheRecordProfile()); |
| 63 | 63 |
| 64 // Apply the general blocking to the regular profile. | 64 // Apply the general blocking to the regular profile. |
| 65 cookie_settings_->SetDefaultCookieSetting(CONTENT_SETTING_BLOCK); | 65 cookie_settings_->SetDefaultCookieSetting(CONTENT_SETTING_BLOCK); |
| 66 | 66 |
| 67 // It should be effective for regular and incognito session. | 67 // It should be effective for regular and incognito session. |
| 68 EXPECT_FALSE(cookie_settings_->IsReadingCookieAllowed(kFirstPartySite, | 68 EXPECT_FALSE(cookie_settings_->IsCookieAccessAllowed(kFirstPartySite, |
| 69 kFirstPartySite)); | 69 kFirstPartySite)); |
| 70 EXPECT_FALSE(incognito_settings->IsReadingCookieAllowed(kFirstPartySite, | 70 EXPECT_FALSE(incognito_settings->IsCookieAccessAllowed(kFirstPartySite, |
| 71 kFirstPartySite)); | 71 kFirstPartySite)); |
| 72 | 72 |
| 73 // 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 |
| 74 // mode. | 74 // mode. |
| 75 incognito_settings->SetCookieSetting(kAllowedSite, CONTENT_SETTING_ALLOW); | 75 incognito_settings->SetCookieSetting(kAllowedSite, CONTENT_SETTING_ALLOW); |
| 76 EXPECT_TRUE( | 76 EXPECT_TRUE( |
| 77 incognito_settings->IsReadingCookieAllowed(kAllowedSite, kAllowedSite)); | 77 incognito_settings->IsCookieAccessAllowed(kAllowedSite, kAllowedSite)); |
| 78 EXPECT_FALSE( | 78 EXPECT_FALSE( |
| 79 cookie_settings_->IsReadingCookieAllowed(kAllowedSite, kAllowedSite)); | 79 cookie_settings_->IsCookieAccessAllowed(kAllowedSite, kAllowedSite)); |
| 80 | 80 |
| 81 // 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 |
| 82 // incognito mode. | 82 // incognito mode. |
| 83 cookie_settings_->SetCookieSetting(kHttpsSite, CONTENT_SETTING_ALLOW); | 83 cookie_settings_->SetCookieSetting(kHttpsSite, CONTENT_SETTING_ALLOW); |
| 84 EXPECT_TRUE( | 84 EXPECT_TRUE( |
| 85 incognito_settings->IsReadingCookieAllowed(kHttpsSite, kHttpsSite)); | 85 incognito_settings->IsCookieAccessAllowed(kHttpsSite, kHttpsSite)); |
| 86 EXPECT_TRUE(cookie_settings_->IsReadingCookieAllowed(kHttpsSite, kHttpsSite)); | 86 EXPECT_TRUE(cookie_settings_->IsCookieAccessAllowed(kHttpsSite, kHttpsSite)); |
| 87 } | 87 } |
| 88 | 88 |
| 89 } // namespace | 89 } // namespace |
| OLD | NEW |