| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/values.h" | 5 #include "base/values.h" |
| 6 #include "chrome/browser/content_settings/cookie_settings.h" |
| 6 #include "chrome/browser/content_settings/host_content_settings_map.h" | 7 #include "chrome/browser/content_settings/host_content_settings_map.h" |
| 7 #include "chrome/browser/extensions/extension_special_storage_policy.h" | 8 #include "chrome/browser/extensions/extension_special_storage_policy.h" |
| 8 #include "chrome/common/content_settings.h" | 9 #include "chrome/common/content_settings.h" |
| 9 #include "chrome/common/content_settings_types.h" | 10 #include "chrome/common/content_settings_types.h" |
| 10 #include "chrome/common/extensions/extension.h" | 11 #include "chrome/common/extensions/extension.h" |
| 11 #include "chrome/common/extensions/extension_constants.h" | 12 #include "chrome/common/extensions/extension_constants.h" |
| 12 #include "chrome/test/base/testing_profile.h" | 13 #include "chrome/test/base/testing_profile.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 14 | 15 |
| 15 namespace keys = extension_manifest_keys; | 16 namespace keys = extension_manifest_keys; |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 EXPECT_FALSE(policy->IsStorageProtected(GURL("http://explicit/"))); | 214 EXPECT_FALSE(policy->IsStorageProtected(GURL("http://explicit/"))); |
| 214 EXPECT_FALSE(policy->IsStorageProtected(GURL("http://foo.wildcards/"))); | 215 EXPECT_FALSE(policy->IsStorageProtected(GURL("http://foo.wildcards/"))); |
| 215 EXPECT_FALSE(policy->IsStorageProtected(GURL("https://bar.wildcards/"))); | 216 EXPECT_FALSE(policy->IsStorageProtected(GURL("https://bar.wildcards/"))); |
| 216 } | 217 } |
| 217 | 218 |
| 218 TEST_F(ExtensionSpecialStoragePolicyTest, HasSessionOnlyOrigins) { | 219 TEST_F(ExtensionSpecialStoragePolicyTest, HasSessionOnlyOrigins) { |
| 219 MessageLoop message_loop; | 220 MessageLoop message_loop; |
| 220 BrowserThread ui_thread(BrowserThread::UI, &message_loop); | 221 BrowserThread ui_thread(BrowserThread::UI, &message_loop); |
| 221 | 222 |
| 222 TestingProfile profile; | 223 TestingProfile profile; |
| 223 HostContentSettingsMap* host_content_settings_map = | 224 CookieSettings* cookie_settings = CookieSettings::GetForProfile(&profile); |
| 224 profile.GetHostContentSettingsMap(); | |
| 225 scoped_refptr<ExtensionSpecialStoragePolicy> policy( | 225 scoped_refptr<ExtensionSpecialStoragePolicy> policy( |
| 226 new ExtensionSpecialStoragePolicy(host_content_settings_map)); | 226 new ExtensionSpecialStoragePolicy(cookie_settings)); |
| 227 | 227 |
| 228 EXPECT_FALSE(policy->HasSessionOnlyOrigins()); | 228 EXPECT_FALSE(policy->HasSessionOnlyOrigins()); |
| 229 | 229 |
| 230 // The default setting can be session-only. | 230 // The default setting can be session-only. |
| 231 host_content_settings_map->SetDefaultContentSetting( | 231 cookie_settings->SetDefaultCookieSetting(CONTENT_SETTING_SESSION_ONLY); |
| 232 CONTENT_SETTINGS_TYPE_COOKIES, CONTENT_SETTING_SESSION_ONLY); | |
| 233 EXPECT_TRUE(policy->HasSessionOnlyOrigins()); | 232 EXPECT_TRUE(policy->HasSessionOnlyOrigins()); |
| 234 | 233 |
| 235 host_content_settings_map->SetDefaultContentSetting( | 234 cookie_settings->SetDefaultCookieSetting(CONTENT_SETTING_ALLOW); |
| 236 CONTENT_SETTINGS_TYPE_COOKIES, CONTENT_SETTING_ALLOW); | |
| 237 EXPECT_FALSE(policy->HasSessionOnlyOrigins()); | 235 EXPECT_FALSE(policy->HasSessionOnlyOrigins()); |
| 238 | 236 |
| 239 // Or the session-onlyness can affect individual origins. | 237 // Or the session-onlyness can affect individual origins. |
| 240 ContentSettingsPattern pattern = | 238 ContentSettingsPattern pattern = |
| 241 ContentSettingsPattern::FromString("pattern.com"); | 239 ContentSettingsPattern::FromString("pattern.com"); |
| 242 | 240 |
| 243 host_content_settings_map->SetContentSetting( | 241 cookie_settings->SetCookieSetting(pattern, CONTENT_SETTING_SESSION_ONLY); |
| 244 pattern, ContentSettingsPattern::Wildcard(), | |
| 245 CONTENT_SETTINGS_TYPE_COOKIES, "", CONTENT_SETTING_SESSION_ONLY); | |
| 246 | 242 |
| 247 EXPECT_TRUE(policy->HasSessionOnlyOrigins()); | 243 EXPECT_TRUE(policy->HasSessionOnlyOrigins()); |
| 248 | 244 |
| 249 // Clearing an origin-spesific rule. | 245 // Clearing an origin-spesific rule. |
| 250 host_content_settings_map->SetContentSetting( | 246 cookie_settings->ResetCookieSetting(pattern); |
| 251 pattern, ContentSettingsPattern::Wildcard(), | |
| 252 CONTENT_SETTINGS_TYPE_COOKIES, "", CONTENT_SETTING_DEFAULT); | |
| 253 | 247 |
| 254 EXPECT_FALSE(policy->HasSessionOnlyOrigins()); | 248 EXPECT_FALSE(policy->HasSessionOnlyOrigins()); |
| 255 } | 249 } |
| OLD | NEW |