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 "components/content_settings/core/browser/website_settings_registry.h" | 5 #include "components/content_settings/core/browser/website_settings_registry.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
9 #include "base/values.h" | 9 #include "base/values.h" |
10 #include "components/content_settings/core/browser/website_settings_info.h" | 10 #include "components/content_settings/core/browser/website_settings_info.h" |
11 #include "components/content_settings/core/common/content_settings.h" | 11 #include "components/content_settings/core/common/content_settings.h" |
12 #include "components/content_settings/core/common/content_settings_types.h" | 12 #include "components/content_settings/core/common/content_settings_types.h" |
13 #include "components/pref_registry/pref_registry_syncable.h" | 13 #include "components/pref_registry/pref_registry_syncable.h" |
14 #include "components/prefs/pref_registry.h" | 14 #include "components/prefs/pref_registry.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
16 | 16 |
17 namespace content_settings { | 17 namespace content_settings { |
18 | 18 |
19 class WebsiteSettingsRegistryTest : public testing::Test { | 19 class WebsiteSettingsRegistryTest : public testing::Test { |
20 protected: | 20 protected: |
21 WebsiteSettingsRegistry* registry() { return ®istry_; } | 21 WebsiteSettingsRegistry* registry() { return ®istry_; } |
22 | 22 |
23 private: | 23 private: |
24 WebsiteSettingsRegistry registry_; | 24 WebsiteSettingsRegistry registry_; |
25 }; | 25 }; |
26 | 26 |
27 TEST_F(WebsiteSettingsRegistryTest, Get) { | 27 TEST_F(WebsiteSettingsRegistryTest, Get) { |
28 // CONTENT_SETTINGS_TYPE_APP_BANNER should be registered. | 28 // CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE should be registered. |
29 const WebsiteSettingsInfo* info = | 29 const WebsiteSettingsInfo* info = |
30 registry()->Get(CONTENT_SETTINGS_TYPE_APP_BANNER); | 30 registry()->Get(CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE); |
31 ASSERT_TRUE(info); | 31 ASSERT_TRUE(info); |
32 EXPECT_EQ(CONTENT_SETTINGS_TYPE_APP_BANNER, info->type()); | 32 EXPECT_EQ(CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE, info->type()); |
33 EXPECT_EQ("app-banner", info->name()); | 33 EXPECT_EQ("auto-select-certificate", info->name()); |
34 } | 34 } |
35 | 35 |
36 TEST_F(WebsiteSettingsRegistryTest, GetByName) { | 36 TEST_F(WebsiteSettingsRegistryTest, GetByName) { |
37 // Random string shouldn't be registered. | 37 // Random string shouldn't be registered. |
38 EXPECT_FALSE(registry()->GetByName("abc")); | 38 EXPECT_FALSE(registry()->GetByName("abc")); |
39 | 39 |
40 // "app-banner" should be registered. | 40 // "auto-select-certificate" should be registered. |
41 const WebsiteSettingsInfo* info = registry()->GetByName("app-banner"); | 41 const WebsiteSettingsInfo* info = |
| 42 registry()->GetByName("auto-select-certificate"); |
42 ASSERT_TRUE(info); | 43 ASSERT_TRUE(info); |
43 EXPECT_EQ(CONTENT_SETTINGS_TYPE_APP_BANNER, info->type()); | 44 EXPECT_EQ(CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE, info->type()); |
44 EXPECT_EQ("app-banner", info->name()); | 45 EXPECT_EQ("auto-select-certificate", info->name()); |
45 EXPECT_EQ(registry()->Get(CONTENT_SETTINGS_TYPE_APP_BANNER), info); | 46 EXPECT_EQ(registry()->Get(CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE), |
| 47 info); |
46 | 48 |
47 // Register a new setting. | 49 // Register a new setting. |
48 registry()->Register(static_cast<ContentSettingsType>(10), "test", nullptr, | 50 registry()->Register(static_cast<ContentSettingsType>(10), "test", nullptr, |
49 WebsiteSettingsInfo::UNSYNCABLE, | 51 WebsiteSettingsInfo::UNSYNCABLE, |
50 WebsiteSettingsInfo::LOSSY, | 52 WebsiteSettingsInfo::LOSSY, |
51 WebsiteSettingsInfo::TOP_LEVEL_DOMAIN_ONLY_SCOPE, | 53 WebsiteSettingsInfo::TOP_LEVEL_DOMAIN_ONLY_SCOPE, |
| 54 WebsiteSettingsRegistry::ALL_PLATFORMS, |
52 WebsiteSettingsInfo::INHERIT_IN_INCOGNITO); | 55 WebsiteSettingsInfo::INHERIT_IN_INCOGNITO); |
53 info = registry()->GetByName("test"); | 56 info = registry()->GetByName("test"); |
54 ASSERT_TRUE(info); | 57 ASSERT_TRUE(info); |
55 EXPECT_EQ(10, info->type()); | 58 EXPECT_EQ(10, info->type()); |
56 EXPECT_EQ("test", info->name()); | 59 EXPECT_EQ("test", info->name()); |
57 EXPECT_EQ(registry()->Get(static_cast<ContentSettingsType>(10)), info); | 60 EXPECT_EQ(registry()->Get(static_cast<ContentSettingsType>(10)), info); |
58 } | 61 } |
59 | 62 |
| 63 TEST_F(WebsiteSettingsRegistryTest, GetPlatformDependent) { |
| 64 #if defined(OS_IOS) |
| 65 // App banner shouldn't be registered on iOS. |
| 66 EXPECT_FALSE(registry()->Get(CONTENT_SETTINGS_TYPE_APP_BANNER)); |
| 67 #else |
| 68 // App banner should be registered on other platforms. |
| 69 EXPECT_TRUE(registry()->Get(CONTENT_SETTINGS_TYPE_APP_BANNER)); |
| 70 #endif |
| 71 |
| 72 // Auto select certificate is registered on all platforms. |
| 73 EXPECT_TRUE(registry()->Get(CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE)); |
| 74 } |
| 75 |
60 TEST_F(WebsiteSettingsRegistryTest, Properties) { | 76 TEST_F(WebsiteSettingsRegistryTest, Properties) { |
61 // "app-banner" should be registered. | 77 // "auto-select-certificate" should be registered. |
62 const WebsiteSettingsInfo* info = | 78 const WebsiteSettingsInfo* info = |
63 registry()->Get(CONTENT_SETTINGS_TYPE_APP_BANNER); | 79 registry()->Get(CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE); |
64 ASSERT_TRUE(info); | 80 ASSERT_TRUE(info); |
65 EXPECT_EQ("profile.content_settings.exceptions.app_banner", | 81 EXPECT_EQ("profile.content_settings.exceptions.auto_select_certificate", |
66 info->pref_name()); | 82 info->pref_name()); |
67 EXPECT_EQ("profile.default_content_setting_values.app_banner", | 83 EXPECT_EQ("profile.default_content_setting_values.auto_select_certificate", |
68 info->default_value_pref_name()); | 84 info->default_value_pref_name()); |
69 ASSERT_FALSE(info->initial_default_value()); | 85 ASSERT_FALSE(info->initial_default_value()); |
70 EXPECT_EQ(PrefRegistry::LOSSY_PREF, info->GetPrefRegistrationFlags()); | 86 EXPECT_EQ(PrefRegistry::NO_REGISTRATION_FLAGS, |
| 87 info->GetPrefRegistrationFlags()); |
71 | 88 |
72 // Register a new setting. | 89 // Register a new setting. |
73 registry()->Register(static_cast<ContentSettingsType>(10), "test", | 90 registry()->Register(static_cast<ContentSettingsType>(10), "test", |
74 base::WrapUnique(new base::FundamentalValue(999)), | 91 base::WrapUnique(new base::FundamentalValue(999)), |
75 WebsiteSettingsInfo::SYNCABLE, | 92 WebsiteSettingsInfo::SYNCABLE, |
76 WebsiteSettingsInfo::LOSSY, | 93 WebsiteSettingsInfo::LOSSY, |
77 WebsiteSettingsInfo::TOP_LEVEL_DOMAIN_ONLY_SCOPE, | 94 WebsiteSettingsInfo::TOP_LEVEL_DOMAIN_ONLY_SCOPE, |
| 95 WebsiteSettingsRegistry::ALL_PLATFORMS, |
78 WebsiteSettingsInfo::INHERIT_IN_INCOGNITO); | 96 WebsiteSettingsInfo::INHERIT_IN_INCOGNITO); |
79 info = registry()->Get(static_cast<ContentSettingsType>(10)); | 97 info = registry()->Get(static_cast<ContentSettingsType>(10)); |
80 ASSERT_TRUE(info); | 98 ASSERT_TRUE(info); |
81 EXPECT_EQ("profile.content_settings.exceptions.test", info->pref_name()); | 99 EXPECT_EQ("profile.content_settings.exceptions.test", info->pref_name()); |
82 EXPECT_EQ("profile.default_content_setting_values.test", | 100 EXPECT_EQ("profile.default_content_setting_values.test", |
83 info->default_value_pref_name()); | 101 info->default_value_pref_name()); |
84 int setting; | 102 int setting; |
85 ASSERT_TRUE(info->initial_default_value()->GetAsInteger(&setting)); | 103 ASSERT_TRUE(info->initial_default_value()->GetAsInteger(&setting)); |
86 EXPECT_EQ(999, setting); | 104 EXPECT_EQ(999, setting); |
| 105 #if defined(OS_IOS) |
| 106 EXPECT_EQ(PrefRegistry::LOSSY_PREF, info->GetPrefRegistrationFlags()); |
| 107 #else |
87 EXPECT_EQ(PrefRegistry::LOSSY_PREF | | 108 EXPECT_EQ(PrefRegistry::LOSSY_PREF | |
88 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF, | 109 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF, |
89 info->GetPrefRegistrationFlags()); | 110 info->GetPrefRegistrationFlags()); |
| 111 #endif |
90 EXPECT_EQ(WebsiteSettingsInfo::TOP_LEVEL_DOMAIN_ONLY_SCOPE, | 112 EXPECT_EQ(WebsiteSettingsInfo::TOP_LEVEL_DOMAIN_ONLY_SCOPE, |
91 info->scoping_type()); | 113 info->scoping_type()); |
92 EXPECT_EQ(WebsiteSettingsInfo::INHERIT_IN_INCOGNITO, | 114 EXPECT_EQ(WebsiteSettingsInfo::INHERIT_IN_INCOGNITO, |
93 info->incognito_behavior()); | 115 info->incognito_behavior()); |
94 } | 116 } |
95 | 117 |
96 TEST_F(WebsiteSettingsRegistryTest, Iteration) { | 118 TEST_F(WebsiteSettingsRegistryTest, Iteration) { |
97 registry()->Register(static_cast<ContentSettingsType>(10), "test", | 119 registry()->Register(static_cast<ContentSettingsType>(10), "test", |
98 base::WrapUnique(new base::FundamentalValue(999)), | 120 base::WrapUnique(new base::FundamentalValue(999)), |
99 WebsiteSettingsInfo::SYNCABLE, | 121 WebsiteSettingsInfo::SYNCABLE, |
100 WebsiteSettingsInfo::LOSSY, | 122 WebsiteSettingsInfo::LOSSY, |
101 WebsiteSettingsInfo::TOP_LEVEL_DOMAIN_ONLY_SCOPE, | 123 WebsiteSettingsInfo::TOP_LEVEL_DOMAIN_ONLY_SCOPE, |
| 124 WebsiteSettingsRegistry::ALL_PLATFORMS, |
102 WebsiteSettingsInfo::INHERIT_IN_INCOGNITO); | 125 WebsiteSettingsInfo::INHERIT_IN_INCOGNITO); |
103 | 126 |
104 bool found = false; | 127 bool found = false; |
105 for (const WebsiteSettingsInfo* info : *registry()) { | 128 for (const WebsiteSettingsInfo* info : *registry()) { |
106 EXPECT_EQ(registry()->Get(info->type()), info); | 129 EXPECT_EQ(registry()->Get(info->type()), info); |
107 if (info->type() == 10) { | 130 if (info->type() == 10) { |
108 EXPECT_FALSE(found); | 131 EXPECT_FALSE(found); |
109 found = true; | 132 found = true; |
110 } | 133 } |
111 } | 134 } |
112 | 135 |
113 EXPECT_TRUE(found); | 136 EXPECT_TRUE(found); |
114 } | 137 } |
115 | 138 |
116 } // namespace content_settings | 139 } // namespace content_settings |
OLD | NEW |