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 #if !defined(OS_IOS) | |
27 TEST_F(WebsiteSettingsRegistryTest, Get) { | 28 TEST_F(WebsiteSettingsRegistryTest, Get) { |
msramek
2016/05/24 14:29:24
I think the spirit of this test is not to test spe
raymes
2016/05/25 03:36:07
+1
lshang
2016/05/25 10:38:16
Done.
Cookies is ContentSettingsInfo, it don't ge
| |
28 // CONTENT_SETTINGS_TYPE_APP_BANNER should be registered. | 29 // CONTENT_SETTINGS_TYPE_APP_BANNER should be registered. |
29 const WebsiteSettingsInfo* info = | 30 const WebsiteSettingsInfo* info = |
30 registry()->Get(CONTENT_SETTINGS_TYPE_APP_BANNER); | 31 registry()->Get(CONTENT_SETTINGS_TYPE_APP_BANNER); |
31 ASSERT_TRUE(info); | 32 ASSERT_TRUE(info); |
32 EXPECT_EQ(CONTENT_SETTINGS_TYPE_APP_BANNER, info->type()); | 33 EXPECT_EQ(CONTENT_SETTINGS_TYPE_APP_BANNER, info->type()); |
33 EXPECT_EQ("app-banner", info->name()); | 34 EXPECT_EQ("app-banner", info->name()); |
34 } | 35 } |
36 #endif | |
35 | 37 |
36 TEST_F(WebsiteSettingsRegistryTest, GetByName) { | 38 TEST_F(WebsiteSettingsRegistryTest, GetByName) { |
37 // Random string shouldn't be registered. | 39 // Random string shouldn't be registered. |
38 EXPECT_FALSE(registry()->GetByName("abc")); | 40 EXPECT_FALSE(registry()->GetByName("abc")); |
41 const WebsiteSettingsInfo* info; | |
39 | 42 |
43 #if !defined(OS_IOS) | |
msramek
2016/05/24 14:29:24
Ditto here.
lshang
2016/05/25 10:38:17
Done.
| |
40 // "app-banner" should be registered. | 44 // "app-banner" should be registered. |
41 const WebsiteSettingsInfo* info = registry()->GetByName("app-banner"); | 45 info = registry()->GetByName("app-banner"); |
42 ASSERT_TRUE(info); | 46 ASSERT_TRUE(info); |
43 EXPECT_EQ(CONTENT_SETTINGS_TYPE_APP_BANNER, info->type()); | 47 EXPECT_EQ(CONTENT_SETTINGS_TYPE_APP_BANNER, info->type()); |
44 EXPECT_EQ("app-banner", info->name()); | 48 EXPECT_EQ("app-banner", info->name()); |
45 EXPECT_EQ(registry()->Get(CONTENT_SETTINGS_TYPE_APP_BANNER), info); | 49 EXPECT_EQ(registry()->Get(CONTENT_SETTINGS_TYPE_APP_BANNER), info); |
50 #endif | |
46 | 51 |
47 // Register a new setting. | 52 // Register a new setting. |
48 registry()->Register(static_cast<ContentSettingsType>(10), "test", nullptr, | 53 registry()->Register(static_cast<ContentSettingsType>(10), "test", nullptr, |
49 WebsiteSettingsInfo::UNSYNCABLE, | 54 WebsiteSettingsInfo::UNSYNCABLE, |
50 WebsiteSettingsInfo::LOSSY, | 55 WebsiteSettingsInfo::LOSSY, |
51 WebsiteSettingsInfo::TOP_LEVEL_DOMAIN_ONLY_SCOPE, | 56 WebsiteSettingsInfo::TOP_LEVEL_DOMAIN_ONLY_SCOPE, |
57 WebsiteSettingsInfo::ALL_PLATFORMS, | |
52 WebsiteSettingsInfo::INHERIT_IN_INCOGNITO); | 58 WebsiteSettingsInfo::INHERIT_IN_INCOGNITO); |
53 info = registry()->GetByName("test"); | 59 info = registry()->GetByName("test"); |
54 ASSERT_TRUE(info); | 60 ASSERT_TRUE(info); |
55 EXPECT_EQ(10, info->type()); | 61 EXPECT_EQ(10, info->type()); |
56 EXPECT_EQ("test", info->name()); | 62 EXPECT_EQ("test", info->name()); |
57 EXPECT_EQ(registry()->Get(static_cast<ContentSettingsType>(10)), info); | 63 EXPECT_EQ(registry()->Get(static_cast<ContentSettingsType>(10)), info); |
58 } | 64 } |
59 | 65 |
60 TEST_F(WebsiteSettingsRegistryTest, Properties) { | 66 TEST_F(WebsiteSettingsRegistryTest, Properties) { |
67 const WebsiteSettingsInfo* info; | |
68 #if !defined(OS_IOS) | |
msramek
2016/05/24 14:29:24
Ditto.
lshang
2016/05/25 10:38:16
Done.
| |
61 // "app-banner" should be registered. | 69 // "app-banner" should be registered. |
62 const WebsiteSettingsInfo* info = | 70 info = registry()->Get(CONTENT_SETTINGS_TYPE_APP_BANNER); |
63 registry()->Get(CONTENT_SETTINGS_TYPE_APP_BANNER); | |
64 ASSERT_TRUE(info); | 71 ASSERT_TRUE(info); |
65 EXPECT_EQ("profile.content_settings.exceptions.app_banner", | 72 EXPECT_EQ("profile.content_settings.exceptions.app_banner", |
66 info->pref_name()); | 73 info->pref_name()); |
67 EXPECT_EQ("profile.default_content_setting_values.app_banner", | 74 EXPECT_EQ("profile.default_content_setting_values.app_banner", |
68 info->default_value_pref_name()); | 75 info->default_value_pref_name()); |
69 ASSERT_FALSE(info->initial_default_value()); | 76 ASSERT_FALSE(info->initial_default_value()); |
70 EXPECT_EQ(PrefRegistry::LOSSY_PREF, info->GetPrefRegistrationFlags()); | 77 EXPECT_EQ(PrefRegistry::LOSSY_PREF, info->GetPrefRegistrationFlags()); |
71 | 78 #endif |
72 // Register a new setting. | 79 // Register a new setting. |
73 registry()->Register(static_cast<ContentSettingsType>(10), "test", | 80 registry()->Register(static_cast<ContentSettingsType>(10), "test", |
74 base::WrapUnique(new base::FundamentalValue(999)), | 81 base::WrapUnique(new base::FundamentalValue(999)), |
75 WebsiteSettingsInfo::SYNCABLE, | 82 WebsiteSettingsInfo::SYNCABLE, |
76 WebsiteSettingsInfo::LOSSY, | 83 WebsiteSettingsInfo::LOSSY, |
77 WebsiteSettingsInfo::TOP_LEVEL_DOMAIN_ONLY_SCOPE, | 84 WebsiteSettingsInfo::TOP_LEVEL_DOMAIN_ONLY_SCOPE, |
85 WebsiteSettingsInfo::ALL_PLATFORMS, | |
78 WebsiteSettingsInfo::INHERIT_IN_INCOGNITO); | 86 WebsiteSettingsInfo::INHERIT_IN_INCOGNITO); |
79 info = registry()->Get(static_cast<ContentSettingsType>(10)); | 87 info = registry()->Get(static_cast<ContentSettingsType>(10)); |
80 ASSERT_TRUE(info); | 88 ASSERT_TRUE(info); |
81 EXPECT_EQ("profile.content_settings.exceptions.test", info->pref_name()); | 89 EXPECT_EQ("profile.content_settings.exceptions.test", info->pref_name()); |
82 EXPECT_EQ("profile.default_content_setting_values.test", | 90 EXPECT_EQ("profile.default_content_setting_values.test", |
83 info->default_value_pref_name()); | 91 info->default_value_pref_name()); |
84 int setting; | 92 int setting; |
85 ASSERT_TRUE(info->initial_default_value()->GetAsInteger(&setting)); | 93 ASSERT_TRUE(info->initial_default_value()->GetAsInteger(&setting)); |
86 EXPECT_EQ(999, setting); | 94 EXPECT_EQ(999, setting); |
95 #if defined(OS_IOS) | |
96 EXPECT_EQ(PrefRegistry::LOSSY_PREF, info->GetPrefRegistrationFlags()); | |
97 #else | |
87 EXPECT_EQ(PrefRegistry::LOSSY_PREF | | 98 EXPECT_EQ(PrefRegistry::LOSSY_PREF | |
88 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF, | 99 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF, |
89 info->GetPrefRegistrationFlags()); | 100 info->GetPrefRegistrationFlags()); |
101 #endif | |
90 EXPECT_EQ(WebsiteSettingsInfo::TOP_LEVEL_DOMAIN_ONLY_SCOPE, | 102 EXPECT_EQ(WebsiteSettingsInfo::TOP_LEVEL_DOMAIN_ONLY_SCOPE, |
91 info->scoping_type()); | 103 info->scoping_type()); |
92 EXPECT_EQ(WebsiteSettingsInfo::INHERIT_IN_INCOGNITO, | 104 EXPECT_EQ(WebsiteSettingsInfo::INHERIT_IN_INCOGNITO, |
93 info->incognito_behavior()); | 105 info->incognito_behavior()); |
94 } | 106 } |
95 | 107 |
96 TEST_F(WebsiteSettingsRegistryTest, Iteration) { | 108 TEST_F(WebsiteSettingsRegistryTest, Iteration) { |
97 registry()->Register(static_cast<ContentSettingsType>(10), "test", | 109 registry()->Register(static_cast<ContentSettingsType>(10), "test", |
98 base::WrapUnique(new base::FundamentalValue(999)), | 110 base::WrapUnique(new base::FundamentalValue(999)), |
99 WebsiteSettingsInfo::SYNCABLE, | 111 WebsiteSettingsInfo::SYNCABLE, |
100 WebsiteSettingsInfo::LOSSY, | 112 WebsiteSettingsInfo::LOSSY, |
101 WebsiteSettingsInfo::TOP_LEVEL_DOMAIN_ONLY_SCOPE, | 113 WebsiteSettingsInfo::TOP_LEVEL_DOMAIN_ONLY_SCOPE, |
114 WebsiteSettingsInfo::ALL_PLATFORMS, | |
102 WebsiteSettingsInfo::INHERIT_IN_INCOGNITO); | 115 WebsiteSettingsInfo::INHERIT_IN_INCOGNITO); |
103 | 116 |
104 bool found = false; | 117 bool found = false; |
105 for (const WebsiteSettingsInfo* info : *registry()) { | 118 for (const WebsiteSettingsInfo* info : *registry()) { |
106 EXPECT_EQ(registry()->Get(info->type()), info); | 119 EXPECT_EQ(registry()->Get(info->type()), info); |
107 if (info->type() == 10) { | 120 if (info->type() == 10) { |
108 EXPECT_FALSE(found); | 121 EXPECT_FALSE(found); |
109 found = true; | 122 found = true; |
110 } | 123 } |
111 } | 124 } |
112 | 125 |
113 EXPECT_TRUE(found); | 126 EXPECT_TRUE(found); |
114 } | 127 } |
115 | 128 |
116 } // namespace content_settings | 129 } // namespace content_settings |
OLD | NEW |