| 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" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 ASSERT_TRUE(info); | 43 ASSERT_TRUE(info); |
| 44 EXPECT_EQ(CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE, info->type()); | 44 EXPECT_EQ(CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE, info->type()); |
| 45 EXPECT_EQ("auto-select-certificate", info->name()); | 45 EXPECT_EQ("auto-select-certificate", info->name()); |
| 46 EXPECT_EQ(registry()->Get(CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE), | 46 EXPECT_EQ(registry()->Get(CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE), |
| 47 info); | 47 info); |
| 48 | 48 |
| 49 // Register a new setting. | 49 // Register a new setting. |
| 50 registry()->Register(static_cast<ContentSettingsType>(10), "test", nullptr, | 50 registry()->Register(static_cast<ContentSettingsType>(10), "test", nullptr, |
| 51 WebsiteSettingsInfo::UNSYNCABLE, | 51 WebsiteSettingsInfo::UNSYNCABLE, |
| 52 WebsiteSettingsInfo::LOSSY, | 52 WebsiteSettingsInfo::LOSSY, |
| 53 WebsiteSettingsInfo::TOP_LEVEL_DOMAIN_ONLY_SCOPE, | 53 WebsiteSettingsInfo::TOP_LEVEL_ORIGIN_ONLY_SCOPE, |
| 54 WebsiteSettingsRegistry::ALL_PLATFORMS, | 54 WebsiteSettingsRegistry::ALL_PLATFORMS, |
| 55 WebsiteSettingsInfo::INHERIT_IN_INCOGNITO); | 55 WebsiteSettingsInfo::INHERIT_IN_INCOGNITO); |
| 56 info = registry()->GetByName("test"); | 56 info = registry()->GetByName("test"); |
| 57 ASSERT_TRUE(info); | 57 ASSERT_TRUE(info); |
| 58 EXPECT_EQ(10, info->type()); | 58 EXPECT_EQ(10, info->type()); |
| 59 EXPECT_EQ("test", info->name()); | 59 EXPECT_EQ("test", info->name()); |
| 60 EXPECT_EQ(registry()->Get(static_cast<ContentSettingsType>(10)), info); | 60 EXPECT_EQ(registry()->Get(static_cast<ContentSettingsType>(10)), info); |
| 61 } | 61 } |
| 62 | 62 |
| 63 TEST_F(WebsiteSettingsRegistryTest, GetPlatformDependent) { | 63 TEST_F(WebsiteSettingsRegistryTest, GetPlatformDependent) { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 84 info->default_value_pref_name()); | 84 info->default_value_pref_name()); |
| 85 ASSERT_FALSE(info->initial_default_value()); | 85 ASSERT_FALSE(info->initial_default_value()); |
| 86 EXPECT_EQ(PrefRegistry::NO_REGISTRATION_FLAGS, | 86 EXPECT_EQ(PrefRegistry::NO_REGISTRATION_FLAGS, |
| 87 info->GetPrefRegistrationFlags()); | 87 info->GetPrefRegistrationFlags()); |
| 88 | 88 |
| 89 // Register a new setting. | 89 // Register a new setting. |
| 90 registry()->Register(static_cast<ContentSettingsType>(10), "test", | 90 registry()->Register(static_cast<ContentSettingsType>(10), "test", |
| 91 base::WrapUnique(new base::FundamentalValue(999)), | 91 base::WrapUnique(new base::FundamentalValue(999)), |
| 92 WebsiteSettingsInfo::SYNCABLE, | 92 WebsiteSettingsInfo::SYNCABLE, |
| 93 WebsiteSettingsInfo::LOSSY, | 93 WebsiteSettingsInfo::LOSSY, |
| 94 WebsiteSettingsInfo::TOP_LEVEL_DOMAIN_ONLY_SCOPE, | 94 WebsiteSettingsInfo::TOP_LEVEL_ORIGIN_ONLY_SCOPE, |
| 95 WebsiteSettingsRegistry::ALL_PLATFORMS, | 95 WebsiteSettingsRegistry::ALL_PLATFORMS, |
| 96 WebsiteSettingsInfo::INHERIT_IN_INCOGNITO); | 96 WebsiteSettingsInfo::INHERIT_IN_INCOGNITO); |
| 97 info = registry()->Get(static_cast<ContentSettingsType>(10)); | 97 info = registry()->Get(static_cast<ContentSettingsType>(10)); |
| 98 ASSERT_TRUE(info); | 98 ASSERT_TRUE(info); |
| 99 EXPECT_EQ("profile.content_settings.exceptions.test", info->pref_name()); | 99 EXPECT_EQ("profile.content_settings.exceptions.test", info->pref_name()); |
| 100 EXPECT_EQ("profile.default_content_setting_values.test", | 100 EXPECT_EQ("profile.default_content_setting_values.test", |
| 101 info->default_value_pref_name()); | 101 info->default_value_pref_name()); |
| 102 int setting; | 102 int setting; |
| 103 ASSERT_TRUE(info->initial_default_value()->GetAsInteger(&setting)); | 103 ASSERT_TRUE(info->initial_default_value()->GetAsInteger(&setting)); |
| 104 EXPECT_EQ(999, setting); | 104 EXPECT_EQ(999, setting); |
| 105 #if defined(OS_IOS) | 105 #if defined(OS_IOS) |
| 106 EXPECT_EQ(PrefRegistry::LOSSY_PREF, info->GetPrefRegistrationFlags()); | 106 EXPECT_EQ(PrefRegistry::LOSSY_PREF, info->GetPrefRegistrationFlags()); |
| 107 #else | 107 #else |
| 108 EXPECT_EQ(PrefRegistry::LOSSY_PREF | | 108 EXPECT_EQ(PrefRegistry::LOSSY_PREF | |
| 109 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF, | 109 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF, |
| 110 info->GetPrefRegistrationFlags()); | 110 info->GetPrefRegistrationFlags()); |
| 111 #endif | 111 #endif |
| 112 EXPECT_EQ(WebsiteSettingsInfo::TOP_LEVEL_DOMAIN_ONLY_SCOPE, | 112 EXPECT_EQ(WebsiteSettingsInfo::TOP_LEVEL_ORIGIN_ONLY_SCOPE, |
| 113 info->scoping_type()); | 113 info->scoping_type()); |
| 114 EXPECT_EQ(WebsiteSettingsInfo::INHERIT_IN_INCOGNITO, | 114 EXPECT_EQ(WebsiteSettingsInfo::INHERIT_IN_INCOGNITO, |
| 115 info->incognito_behavior()); | 115 info->incognito_behavior()); |
| 116 } | 116 } |
| 117 | 117 |
| 118 TEST_F(WebsiteSettingsRegistryTest, Iteration) { | 118 TEST_F(WebsiteSettingsRegistryTest, Iteration) { |
| 119 registry()->Register(static_cast<ContentSettingsType>(10), "test", | 119 registry()->Register(static_cast<ContentSettingsType>(10), "test", |
| 120 base::WrapUnique(new base::FundamentalValue(999)), | 120 base::WrapUnique(new base::FundamentalValue(999)), |
| 121 WebsiteSettingsInfo::SYNCABLE, | 121 WebsiteSettingsInfo::SYNCABLE, |
| 122 WebsiteSettingsInfo::LOSSY, | 122 WebsiteSettingsInfo::LOSSY, |
| 123 WebsiteSettingsInfo::TOP_LEVEL_DOMAIN_ONLY_SCOPE, | 123 WebsiteSettingsInfo::TOP_LEVEL_ORIGIN_ONLY_SCOPE, |
| 124 WebsiteSettingsRegistry::ALL_PLATFORMS, | 124 WebsiteSettingsRegistry::ALL_PLATFORMS, |
| 125 WebsiteSettingsInfo::INHERIT_IN_INCOGNITO); | 125 WebsiteSettingsInfo::INHERIT_IN_INCOGNITO); |
| 126 | 126 |
| 127 bool found = false; | 127 bool found = false; |
| 128 for (const WebsiteSettingsInfo* info : *registry()) { | 128 for (const WebsiteSettingsInfo* info : *registry()) { |
| 129 EXPECT_EQ(registry()->Get(info->type()), info); | 129 EXPECT_EQ(registry()->Get(info->type()), info); |
| 130 if (info->type() == 10) { | 130 if (info->type() == 10) { |
| 131 EXPECT_FALSE(found); | 131 EXPECT_FALSE(found); |
| 132 found = true; | 132 found = true; |
| 133 } | 133 } |
| 134 } | 134 } |
| 135 | 135 |
| 136 EXPECT_TRUE(found); | 136 EXPECT_TRUE(found); |
| 137 } | 137 } |
| 138 | 138 |
| 139 } // namespace content_settings | 139 } // namespace content_settings |
| OLD | NEW |