OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/logging.h" | 5 #include "base/logging.h" |
6 #include "base/prefs/pref_registry.h" | 6 #include "base/prefs/pref_registry.h" |
7 #include "base/values.h" | 7 #include "base/values.h" |
8 #include "components/content_settings/core/browser/website_settings_info.h" | 8 #include "components/content_settings/core/browser/website_settings_info.h" |
9 #include "components/content_settings/core/browser/website_settings_registry.h" | 9 #include "components/content_settings/core/browser/website_settings_registry.h" |
10 #include "components/content_settings/core/common/content_settings.h" | 10 #include "components/content_settings/core/common/content_settings.h" |
(...skipping 28 matching lines...) Expand all Loading... |
39 const WebsiteSettingsInfo* info = registry()->GetByName("app-banner"); | 39 const WebsiteSettingsInfo* info = registry()->GetByName("app-banner"); |
40 ASSERT_TRUE(info); | 40 ASSERT_TRUE(info); |
41 EXPECT_EQ(CONTENT_SETTINGS_TYPE_APP_BANNER, info->type()); | 41 EXPECT_EQ(CONTENT_SETTINGS_TYPE_APP_BANNER, info->type()); |
42 EXPECT_EQ("app-banner", info->name()); | 42 EXPECT_EQ("app-banner", info->name()); |
43 EXPECT_EQ(registry()->Get(CONTENT_SETTINGS_TYPE_APP_BANNER), info); | 43 EXPECT_EQ(registry()->Get(CONTENT_SETTINGS_TYPE_APP_BANNER), info); |
44 | 44 |
45 // Register a new setting. | 45 // Register a new setting. |
46 registry()->Register(static_cast<ContentSettingsType>(10), "test", nullptr, | 46 registry()->Register(static_cast<ContentSettingsType>(10), "test", nullptr, |
47 WebsiteSettingsInfo::UNSYNCABLE, | 47 WebsiteSettingsInfo::UNSYNCABLE, |
48 WebsiteSettingsInfo::LOSSY, | 48 WebsiteSettingsInfo::LOSSY, |
49 WebsiteSettingsInfo::TOP_LEVEL_DOMAIN_ONLY_SCOPE); | 49 WebsiteSettingsInfo::TOP_LEVEL_DOMAIN_ONLY_SCOPE, |
| 50 WebsiteSettingsInfo::INHERIT_IN_INCOGNITO); |
50 info = registry()->GetByName("test"); | 51 info = registry()->GetByName("test"); |
51 ASSERT_TRUE(info); | 52 ASSERT_TRUE(info); |
52 EXPECT_EQ(10, info->type()); | 53 EXPECT_EQ(10, info->type()); |
53 EXPECT_EQ("test", info->name()); | 54 EXPECT_EQ("test", info->name()); |
54 EXPECT_EQ(registry()->Get(static_cast<ContentSettingsType>(10)), info); | 55 EXPECT_EQ(registry()->Get(static_cast<ContentSettingsType>(10)), info); |
55 } | 56 } |
56 | 57 |
57 TEST_F(WebsiteSettingsRegistryTest, Properties) { | 58 TEST_F(WebsiteSettingsRegistryTest, Properties) { |
58 // "app-banner" should be registered. | 59 // "app-banner" should be registered. |
59 const WebsiteSettingsInfo* info = | 60 const WebsiteSettingsInfo* info = |
60 registry()->Get(CONTENT_SETTINGS_TYPE_APP_BANNER); | 61 registry()->Get(CONTENT_SETTINGS_TYPE_APP_BANNER); |
61 ASSERT_TRUE(info); | 62 ASSERT_TRUE(info); |
62 EXPECT_EQ("profile.content_settings.exceptions.app_banner", | 63 EXPECT_EQ("profile.content_settings.exceptions.app_banner", |
63 info->pref_name()); | 64 info->pref_name()); |
64 EXPECT_EQ("profile.default_content_setting_values.app_banner", | 65 EXPECT_EQ("profile.default_content_setting_values.app_banner", |
65 info->default_value_pref_name()); | 66 info->default_value_pref_name()); |
66 ASSERT_FALSE(info->initial_default_value()); | 67 ASSERT_FALSE(info->initial_default_value()); |
67 EXPECT_EQ(PrefRegistry::LOSSY_PREF, info->GetPrefRegistrationFlags()); | 68 EXPECT_EQ(PrefRegistry::LOSSY_PREF, info->GetPrefRegistrationFlags()); |
68 | 69 |
69 // Register a new setting. | 70 // Register a new setting. |
70 registry()->Register(static_cast<ContentSettingsType>(10), "test", | 71 registry()->Register(static_cast<ContentSettingsType>(10), "test", |
71 make_scoped_ptr(new base::FundamentalValue(999)), | 72 make_scoped_ptr(new base::FundamentalValue(999)), |
72 WebsiteSettingsInfo::SYNCABLE, | 73 WebsiteSettingsInfo::SYNCABLE, |
73 WebsiteSettingsInfo::LOSSY, | 74 WebsiteSettingsInfo::LOSSY, |
74 WebsiteSettingsInfo::TOP_LEVEL_DOMAIN_ONLY_SCOPE); | 75 WebsiteSettingsInfo::TOP_LEVEL_DOMAIN_ONLY_SCOPE, |
| 76 WebsiteSettingsInfo::INHERIT_IN_INCOGNITO); |
75 info = registry()->Get(static_cast<ContentSettingsType>(10)); | 77 info = registry()->Get(static_cast<ContentSettingsType>(10)); |
76 ASSERT_TRUE(info); | 78 ASSERT_TRUE(info); |
77 EXPECT_EQ("profile.content_settings.exceptions.test", info->pref_name()); | 79 EXPECT_EQ("profile.content_settings.exceptions.test", info->pref_name()); |
78 EXPECT_EQ("profile.default_content_setting_values.test", | 80 EXPECT_EQ("profile.default_content_setting_values.test", |
79 info->default_value_pref_name()); | 81 info->default_value_pref_name()); |
80 int setting; | 82 int setting; |
81 ASSERT_TRUE(info->initial_default_value()->GetAsInteger(&setting)); | 83 ASSERT_TRUE(info->initial_default_value()->GetAsInteger(&setting)); |
82 EXPECT_EQ(999, setting); | 84 EXPECT_EQ(999, setting); |
83 EXPECT_EQ(PrefRegistry::LOSSY_PREF | | 85 EXPECT_EQ(PrefRegistry::LOSSY_PREF | |
84 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF, | 86 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF, |
85 info->GetPrefRegistrationFlags()); | 87 info->GetPrefRegistrationFlags()); |
86 EXPECT_EQ(WebsiteSettingsInfo::TOP_LEVEL_DOMAIN_ONLY_SCOPE, | 88 EXPECT_EQ(WebsiteSettingsInfo::TOP_LEVEL_DOMAIN_ONLY_SCOPE, |
87 info->scoping_type()); | 89 info->scoping_type()); |
| 90 EXPECT_EQ(WebsiteSettingsInfo::INHERIT_IN_INCOGNITO, |
| 91 info->incognito_behavior()); |
88 } | 92 } |
89 | 93 |
90 TEST_F(WebsiteSettingsRegistryTest, Iteration) { | 94 TEST_F(WebsiteSettingsRegistryTest, Iteration) { |
91 registry()->Register(static_cast<ContentSettingsType>(10), "test", | 95 registry()->Register(static_cast<ContentSettingsType>(10), "test", |
92 make_scoped_ptr(new base::FundamentalValue(999)), | 96 make_scoped_ptr(new base::FundamentalValue(999)), |
93 WebsiteSettingsInfo::SYNCABLE, | 97 WebsiteSettingsInfo::SYNCABLE, |
94 WebsiteSettingsInfo::LOSSY, | 98 WebsiteSettingsInfo::LOSSY, |
95 WebsiteSettingsInfo::TOP_LEVEL_DOMAIN_ONLY_SCOPE); | 99 WebsiteSettingsInfo::TOP_LEVEL_DOMAIN_ONLY_SCOPE, |
| 100 WebsiteSettingsInfo::INHERIT_IN_INCOGNITO); |
96 | 101 |
97 bool found = false; | 102 bool found = false; |
98 for (const WebsiteSettingsInfo* info : *registry()) { | 103 for (const WebsiteSettingsInfo* info : *registry()) { |
99 EXPECT_EQ(registry()->Get(info->type()), info); | 104 EXPECT_EQ(registry()->Get(info->type()), info); |
100 if (info->type() == 10) { | 105 if (info->type() == 10) { |
101 EXPECT_FALSE(found); | 106 EXPECT_FALSE(found); |
102 found = true; | 107 found = true; |
103 } | 108 } |
104 } | 109 } |
105 | 110 |
106 EXPECT_TRUE(found); | 111 EXPECT_TRUE(found); |
107 } | 112 } |
108 | 113 |
109 } // namespace content_settings | 114 } // namespace content_settings |
OLD | NEW |