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(cookie_settings); | 323 policy_ = new ExtensionSpecialStoragePolicy(&profile); |
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 content_settings::CookieSettings* cookie_settings = | 348 policy_ = new ExtensionSpecialStoragePolicy(&profile); |
349 CookieSettingsFactory::GetForProfile(&profile).get(); | 349 const GURL kHttpsUrl("https://foo.com"); |
350 policy_ = new ExtensionSpecialStoragePolicy(cookie_settings); | |
351 const GURL kHttpUrl("http://foo.com"); | |
352 | 350 |
353 EXPECT_FALSE(policy_->IsStorageDurable(kHttpUrl)); | 351 EXPECT_FALSE(policy_->IsStorageDurable(kHttpsUrl)); |
354 | 352 |
355 HostContentSettingsMap* content_settings_map = | 353 HostContentSettingsMap* content_settings_map = |
356 HostContentSettingsMapFactory::GetForProfile(&profile); | 354 HostContentSettingsMapFactory::GetForProfile(&profile); |
357 content_settings_map->SetContentSettingDefaultScope( | 355 content_settings_map->SetContentSettingDefaultScope( |
358 kHttpUrl, GURL(), CONTENT_SETTINGS_TYPE_DURABLE_STORAGE, std::string(), | 356 kHttpsUrl, GURL(), CONTENT_SETTINGS_TYPE_DURABLE_STORAGE, std::string(), |
359 CONTENT_SETTING_ALLOW); | 357 CONTENT_SETTING_ALLOW); |
360 | 358 |
361 EXPECT_TRUE(policy_->IsStorageDurable(kHttpUrl)); | 359 EXPECT_TRUE(policy_->IsStorageDurable(kHttpsUrl)); |
362 } | 360 } |
363 | 361 |
364 TEST_F(ExtensionSpecialStoragePolicyTest, NotificationTest) { | 362 TEST_F(ExtensionSpecialStoragePolicyTest, NotificationTest) { |
365 PolicyChangeObserver observer; | 363 PolicyChangeObserver observer; |
366 policy_->AddObserver(&observer); | 364 policy_->AddObserver(&observer); |
367 | 365 |
368 scoped_refptr<Extension> apps[] = { | 366 scoped_refptr<Extension> apps[] = { |
369 CreateProtectedApp(), | 367 CreateProtectedApp(), |
370 CreateUnlimitedApp(), | 368 CreateUnlimitedApp(), |
371 }; | 369 }; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
408 EXPECT_TRUE(observer.IsCompleted()); | 406 EXPECT_TRUE(observer.IsCompleted()); |
409 } | 407 } |
410 | 408 |
411 observer.ExpectClear(); | 409 observer.ExpectClear(); |
412 policy_->RevokeRightsForAllExtensions(); | 410 policy_->RevokeRightsForAllExtensions(); |
413 base::RunLoop().RunUntilIdle(); | 411 base::RunLoop().RunUntilIdle(); |
414 EXPECT_TRUE(observer.IsCompleted()); | 412 EXPECT_TRUE(observer.IsCompleted()); |
415 | 413 |
416 policy_->RemoveObserver(&observer); | 414 policy_->RemoveObserver(&observer); |
417 } | 415 } |
OLD | NEW |