Chromium Code Reviews| 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 "components/content_settings/core/browser/content_settings_pref_provide r.h" | 5 #include "components/content_settings/core/browser/content_settings_pref_provide r.h" |
| 6 | 6 |
| 7 #include "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| (...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 510 CONTENT_SETTINGS_TYPE_IMAGES, std::string(), true)); | 510 CONTENT_SETTINGS_TYPE_IMAGES, std::string(), true)); |
| 511 EXPECT_TRUE(it->HasNext()); | 511 EXPECT_TRUE(it->HasNext()); |
| 512 EXPECT_EQ(pattern_2, it->Next().primary_pattern); | 512 EXPECT_EQ(pattern_2, it->Next().primary_pattern); |
| 513 EXPECT_FALSE(it->HasNext()); | 513 EXPECT_FALSE(it->HasNext()); |
| 514 } | 514 } |
| 515 | 515 |
| 516 incognito_provider.ShutdownOnUIThread(); | 516 incognito_provider.ShutdownOnUIThread(); |
| 517 normal_provider.ShutdownOnUIThread(); | 517 normal_provider.ShutdownOnUIThread(); |
| 518 } | 518 } |
| 519 | 519 |
| 520 TEST_F(PrefProviderTest, IncognitoDoesNotInheritNotifications) { | |
| 521 syncable_prefs::TestingPrefServiceSyncable prefs; | |
| 522 PrefProvider::RegisterProfilePrefs(prefs.registry()); | |
| 523 | |
| 524 ContentSettingsPattern pattern_1 = | |
| 525 ContentSettingsPattern::FromString("google.com"); | |
| 526 ContentSettingsPattern pattern_2 = | |
| 527 ContentSettingsPattern::FromString("www.google.com"); | |
| 528 ContentSettingsPattern wildcard = | |
| 529 ContentSettingsPattern::FromString("*"); | |
| 530 scoped_ptr<base::Value> value( | |
| 531 new base::FundamentalValue(CONTENT_SETTING_ALLOW)); | |
| 532 | |
| 533 // Create a normal provider and set a setting. | |
| 534 PrefProvider normal_provider(&prefs, false); | |
|
Peter Beverloo
2015/11/16 17:14:32
nit: may be worth annotating the boolean parameter
johnme
2015/11/26 17:31:54
Removed from patch, but I've added this elsewhere.
| |
| 535 normal_provider.SetWebsiteSetting(pattern_1, | |
| 536 wildcard, | |
| 537 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, | |
| 538 std::string(), | |
| 539 value->DeepCopy()); | |
| 540 | |
| 541 // Non-OTR provider, Non-OTR iterator has one setting (pattern 1). | |
| 542 { | |
| 543 scoped_ptr<RuleIterator> it(normal_provider.GetRuleIterator( | |
| 544 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string(), false)); | |
| 545 EXPECT_TRUE(it->HasNext()); | |
| 546 EXPECT_EQ(pattern_1, it->Next().primary_pattern); | |
| 547 EXPECT_FALSE(it->HasNext()); | |
| 548 } | |
| 549 | |
| 550 // Non-OTR provider, OTR iterator has no settings. | |
| 551 { | |
| 552 scoped_ptr<RuleIterator> it(normal_provider.GetRuleIterator( | |
| 553 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string(), true)); | |
| 554 EXPECT_FALSE(it->HasNext()); | |
| 555 } | |
| 556 | |
| 557 // Create an incognito provider and set a setting. | |
| 558 PrefProvider incognito_provider(&prefs, true); | |
|
Peter Beverloo
2015/11/16 17:14:32
dito
johnme
2015/11/26 17:31:54
Removed from patch, but I've added this elsewhere.
| |
| 559 incognito_provider.SetWebsiteSetting(pattern_2, | |
| 560 wildcard, | |
| 561 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, | |
| 562 std::string(), | |
| 563 value->DeepCopy()); | |
| 564 | |
| 565 // OTR provider, non-OTR iterator has no settings. | |
| 566 { | |
| 567 scoped_ptr<RuleIterator> it(incognito_provider.GetRuleIterator( | |
| 568 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string(), false)); | |
| 569 EXPECT_FALSE(it->HasNext()); | |
| 570 } | |
| 571 | |
| 572 // OTR provider, OTR iterator has one setting (pattern 2). | |
| 573 { | |
| 574 scoped_ptr<RuleIterator> it(incognito_provider.GetRuleIterator( | |
| 575 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string(), true)); | |
| 576 EXPECT_TRUE(it->HasNext()); | |
| 577 EXPECT_EQ(pattern_2, it->Next().primary_pattern); | |
| 578 EXPECT_FALSE(it->HasNext()); | |
| 579 } | |
| 580 | |
| 581 incognito_provider.ShutdownOnUIThread(); | |
| 582 normal_provider.ShutdownOnUIThread(); | |
| 583 } | |
| 584 | |
| 520 TEST_F(PrefProviderTest, ClearAllContentSettingsRules) { | 585 TEST_F(PrefProviderTest, ClearAllContentSettingsRules) { |
| 521 syncable_prefs::TestingPrefServiceSyncable prefs; | 586 syncable_prefs::TestingPrefServiceSyncable prefs; |
| 522 PrefProvider::RegisterProfilePrefs(prefs.registry()); | 587 PrefProvider::RegisterProfilePrefs(prefs.registry()); |
| 523 | 588 |
| 524 ContentSettingsPattern pattern = | 589 ContentSettingsPattern pattern = |
| 525 ContentSettingsPattern::FromString("google.com"); | 590 ContentSettingsPattern::FromString("google.com"); |
| 526 ContentSettingsPattern wildcard = | 591 ContentSettingsPattern wildcard = |
| 527 ContentSettingsPattern::FromString("*"); | 592 ContentSettingsPattern::FromString("*"); |
| 528 scoped_ptr<base::Value> value( | 593 scoped_ptr<base::Value> value( |
| 529 new base::FundamentalValue(CONTENT_SETTING_ALLOW)); | 594 new base::FundamentalValue(CONTENT_SETTING_ALLOW)); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 584 for (const char* pref : nonempty_prefs) { | 649 for (const char* pref : nonempty_prefs) { |
| 585 DictionaryPrefUpdate update(&prefs, pref); | 650 DictionaryPrefUpdate update(&prefs, pref); |
| 586 const base::DictionaryValue* dictionary = update.Get(); | 651 const base::DictionaryValue* dictionary = update.Get(); |
| 587 EXPECT_EQ(1u, dictionary->size()); | 652 EXPECT_EQ(1u, dictionary->size()); |
| 588 } | 653 } |
| 589 | 654 |
| 590 provider.ShutdownOnUIThread(); | 655 provider.ShutdownOnUIThread(); |
| 591 } | 656 } |
| 592 | 657 |
| 593 } // namespace content_settings | 658 } // namespace content_settings |
| OLD | NEW |