| 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 <stddef.h> | 5 #include <stddef.h> |
| 6 | 6 |
| 7 #include "base/macros.h" | 7 #include "base/macros.h" |
| 8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
| 9 #include "base/values.h" | 9 #include "base/values.h" |
| 10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
| (...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 313 policy_->RevokeRightsForExtension(protected_app.get()); | 313 policy_->RevokeRightsForExtension(protected_app.get()); |
| 314 ExpectProtectedBy(empty_set, GURL("http://explicit/")); | 314 ExpectProtectedBy(empty_set, GURL("http://explicit/")); |
| 315 ExpectProtectedBy(empty_set, GURL("http://foo.wildcards/")); | 315 ExpectProtectedBy(empty_set, GURL("http://foo.wildcards/")); |
| 316 ExpectProtectedBy(empty_set, GURL("https://bar.wildcards/")); | 316 ExpectProtectedBy(empty_set, GURL("https://bar.wildcards/")); |
| 317 } | 317 } |
| 318 | 318 |
| 319 TEST_F(ExtensionSpecialStoragePolicyTest, HasSessionOnlyOrigins) { | 319 TEST_F(ExtensionSpecialStoragePolicyTest, HasSessionOnlyOrigins) { |
| 320 TestingProfile profile; | 320 TestingProfile profile; |
| 321 content_settings::CookieSettings* cookie_settings = | 321 content_settings::CookieSettings* cookie_settings = |
| 322 CookieSettingsFactory::GetForProfile(&profile).get(); | 322 CookieSettingsFactory::GetForProfile(&profile).get(); |
| 323 policy_ = new ExtensionSpecialStoragePolicy(&profile); | 323 policy_ = new ExtensionSpecialStoragePolicy(cookie_settings); |
| 324 | 324 |
| 325 EXPECT_FALSE(policy_->HasSessionOnlyOrigins()); | 325 EXPECT_FALSE(policy_->HasSessionOnlyOrigins()); |
| 326 | 326 |
| 327 // The default setting can be session-only. | 327 // The default setting can be session-only. |
| 328 cookie_settings->SetDefaultCookieSetting(CONTENT_SETTING_SESSION_ONLY); | 328 cookie_settings->SetDefaultCookieSetting(CONTENT_SETTING_SESSION_ONLY); |
| 329 EXPECT_TRUE(policy_->HasSessionOnlyOrigins()); | 329 EXPECT_TRUE(policy_->HasSessionOnlyOrigins()); |
| 330 | 330 |
| 331 cookie_settings->SetDefaultCookieSetting(CONTENT_SETTING_ALLOW); | 331 cookie_settings->SetDefaultCookieSetting(CONTENT_SETTING_ALLOW); |
| 332 EXPECT_FALSE(policy_->HasSessionOnlyOrigins()); | 332 EXPECT_FALSE(policy_->HasSessionOnlyOrigins()); |
| 333 | 333 |
| 334 // Or the session-onlyness can affect individual origins. | 334 // Or the session-onlyness can affect individual origins. |
| 335 GURL url("http://pattern.com"); | 335 GURL url("http://pattern.com"); |
| 336 cookie_settings->SetCookieSetting(url, CONTENT_SETTING_SESSION_ONLY); | 336 cookie_settings->SetCookieSetting(url, CONTENT_SETTING_SESSION_ONLY); |
| 337 | 337 |
| 338 EXPECT_TRUE(policy_->HasSessionOnlyOrigins()); | 338 EXPECT_TRUE(policy_->HasSessionOnlyOrigins()); |
| 339 | 339 |
| 340 // Clearing an origin-specific rule. | 340 // Clearing an origin-specific rule. |
| 341 cookie_settings->ResetCookieSetting(url); | 341 cookie_settings->ResetCookieSetting(url); |
| 342 | 342 |
| 343 EXPECT_FALSE(policy_->HasSessionOnlyOrigins()); | 343 EXPECT_FALSE(policy_->HasSessionOnlyOrigins()); |
| 344 } | 344 } |
| 345 | 345 |
| 346 TEST_F(ExtensionSpecialStoragePolicyTest, IsStorageDurableTest) { | 346 TEST_F(ExtensionSpecialStoragePolicyTest, IsStorageDurableTest) { |
| 347 TestingProfile profile; | 347 TestingProfile profile; |
| 348 policy_ = new ExtensionSpecialStoragePolicy(&profile); | 348 content_settings::CookieSettings* cookie_settings = |
| 349 const GURL kHttpsUrl("https://foo.com"); | 349 CookieSettingsFactory::GetForProfile(&profile).get(); |
| 350 policy_ = new ExtensionSpecialStoragePolicy(cookie_settings); |
| 351 const GURL kHttpUrl("http://foo.com"); |
| 350 | 352 |
| 351 EXPECT_FALSE(policy_->IsStorageDurable(kHttpsUrl)); | 353 EXPECT_FALSE(policy_->IsStorageDurable(kHttpUrl)); |
| 352 | 354 |
| 353 HostContentSettingsMap* content_settings_map = | 355 HostContentSettingsMap* content_settings_map = |
| 354 HostContentSettingsMapFactory::GetForProfile(&profile); | 356 HostContentSettingsMapFactory::GetForProfile(&profile); |
| 355 content_settings_map->SetContentSettingDefaultScope( | 357 content_settings_map->SetContentSettingDefaultScope( |
| 356 kHttpsUrl, GURL(), CONTENT_SETTINGS_TYPE_DURABLE_STORAGE, std::string(), | 358 kHttpUrl, GURL(), CONTENT_SETTINGS_TYPE_DURABLE_STORAGE, std::string(), |
| 357 CONTENT_SETTING_ALLOW); | 359 CONTENT_SETTING_ALLOW); |
| 358 | 360 |
| 359 EXPECT_TRUE(policy_->IsStorageDurable(kHttpsUrl)); | 361 EXPECT_TRUE(policy_->IsStorageDurable(kHttpUrl)); |
| 360 } | 362 } |
| 361 | 363 |
| 362 TEST_F(ExtensionSpecialStoragePolicyTest, NotificationTest) { | 364 TEST_F(ExtensionSpecialStoragePolicyTest, NotificationTest) { |
| 363 PolicyChangeObserver observer; | 365 PolicyChangeObserver observer; |
| 364 policy_->AddObserver(&observer); | 366 policy_->AddObserver(&observer); |
| 365 | 367 |
| 366 scoped_refptr<Extension> apps[] = { | 368 scoped_refptr<Extension> apps[] = { |
| 367 CreateProtectedApp(), | 369 CreateProtectedApp(), |
| 368 CreateUnlimitedApp(), | 370 CreateUnlimitedApp(), |
| 369 }; | 371 }; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 406 EXPECT_TRUE(observer.IsCompleted()); | 408 EXPECT_TRUE(observer.IsCompleted()); |
| 407 } | 409 } |
| 408 | 410 |
| 409 observer.ExpectClear(); | 411 observer.ExpectClear(); |
| 410 policy_->RevokeRightsForAllExtensions(); | 412 policy_->RevokeRightsForAllExtensions(); |
| 411 base::RunLoop().RunUntilIdle(); | 413 base::RunLoop().RunUntilIdle(); |
| 412 EXPECT_TRUE(observer.IsCompleted()); | 414 EXPECT_TRUE(observer.IsCompleted()); |
| 413 | 415 |
| 414 policy_->RemoveObserver(&observer); | 416 policy_->RemoveObserver(&observer); |
| 415 } | 417 } |
| OLD | NEW |