Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(66)

Side by Side Diff: chrome/browser/content_settings/content_settings_policy_provider_unittest.cc

Issue 2666093002: Remove base::FundamentalValue (Closed)
Patch Set: Rebase Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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_policy_provi der.h" 5 #include "components/content_settings/core/browser/content_settings_policy_provi der.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <string> 8 #include <string>
9 9
10 #include "base/auto_reset.h" 10 #include "base/auto_reset.h"
(...skipping 30 matching lines...) Expand all
41 sync_preferences::TestingPrefServiceSyncable* prefs = 41 sync_preferences::TestingPrefServiceSyncable* prefs =
42 profile.GetTestingPrefService(); 42 profile.GetTestingPrefService();
43 PolicyProvider provider(prefs); 43 PolicyProvider provider(prefs);
44 44
45 std::unique_ptr<RuleIterator> rule_iterator(provider.GetRuleIterator( 45 std::unique_ptr<RuleIterator> rule_iterator(provider.GetRuleIterator(
46 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string(), false)); 46 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string(), false));
47 EXPECT_FALSE(rule_iterator); 47 EXPECT_FALSE(rule_iterator);
48 48
49 // Change the managed value of the default geolocation setting 49 // Change the managed value of the default geolocation setting
50 prefs->SetManagedPref(prefs::kManagedDefaultGeolocationSetting, 50 prefs->SetManagedPref(prefs::kManagedDefaultGeolocationSetting,
51 new base::FundamentalValue(CONTENT_SETTING_BLOCK)); 51 new base::Value(CONTENT_SETTING_BLOCK));
52 52
53 rule_iterator = provider.GetRuleIterator(CONTENT_SETTINGS_TYPE_GEOLOCATION, 53 rule_iterator = provider.GetRuleIterator(CONTENT_SETTINGS_TYPE_GEOLOCATION,
54 std::string(), false); 54 std::string(), false);
55 ASSERT_TRUE(rule_iterator); 55 ASSERT_TRUE(rule_iterator);
56 EXPECT_TRUE(rule_iterator->HasNext()); 56 EXPECT_TRUE(rule_iterator->HasNext());
57 Rule rule = rule_iterator->Next(); 57 Rule rule = rule_iterator->Next();
58 EXPECT_FALSE(rule_iterator->HasNext()); 58 EXPECT_FALSE(rule_iterator->HasNext());
59 59
60 EXPECT_EQ(ContentSettingsPattern::Wildcard(), rule.primary_pattern); 60 EXPECT_EQ(ContentSettingsPattern::Wildcard(), rule.primary_pattern);
61 EXPECT_EQ(ContentSettingsPattern::Wildcard(), rule.secondary_pattern); 61 EXPECT_EQ(ContentSettingsPattern::Wildcard(), rule.secondary_pattern);
62 EXPECT_EQ(CONTENT_SETTING_BLOCK, ValueToContentSetting(rule.value.get())); 62 EXPECT_EQ(CONTENT_SETTING_BLOCK, ValueToContentSetting(rule.value.get()));
63 63
64 provider.ShutdownOnUIThread(); 64 provider.ShutdownOnUIThread();
65 } 65 }
66 66
67 TEST_F(PolicyProviderTest, ManagedDefaultContentSettings) { 67 TEST_F(PolicyProviderTest, ManagedDefaultContentSettings) {
68 TestingProfile profile; 68 TestingProfile profile;
69 sync_preferences::TestingPrefServiceSyncable* prefs = 69 sync_preferences::TestingPrefServiceSyncable* prefs =
70 profile.GetTestingPrefService(); 70 profile.GetTestingPrefService();
71 PolicyProvider provider(prefs); 71 PolicyProvider provider(prefs);
72 72
73 prefs->SetManagedPref(prefs::kManagedDefaultPluginsSetting, 73 prefs->SetManagedPref(prefs::kManagedDefaultPluginsSetting,
74 new base::FundamentalValue(CONTENT_SETTING_BLOCK)); 74 new base::Value(CONTENT_SETTING_BLOCK));
75 75
76 std::unique_ptr<RuleIterator> rule_iterator(provider.GetRuleIterator( 76 std::unique_ptr<RuleIterator> rule_iterator(provider.GetRuleIterator(
77 CONTENT_SETTINGS_TYPE_PLUGINS, std::string(), false)); 77 CONTENT_SETTINGS_TYPE_PLUGINS, std::string(), false));
78 EXPECT_TRUE(rule_iterator->HasNext()); 78 EXPECT_TRUE(rule_iterator->HasNext());
79 Rule rule = rule_iterator->Next(); 79 Rule rule = rule_iterator->Next();
80 EXPECT_FALSE(rule_iterator->HasNext()); 80 EXPECT_FALSE(rule_iterator->HasNext());
81 81
82 EXPECT_EQ(ContentSettingsPattern::Wildcard(), rule.primary_pattern); 82 EXPECT_EQ(ContentSettingsPattern::Wildcard(), rule.primary_pattern);
83 EXPECT_EQ(ContentSettingsPattern::Wildcard(), rule.secondary_pattern); 83 EXPECT_EQ(ContentSettingsPattern::Wildcard(), rule.secondary_pattern);
84 EXPECT_EQ(CONTENT_SETTING_BLOCK, ValueToContentSetting(rule.value.get())); 84 EXPECT_EQ(CONTENT_SETTING_BLOCK, ValueToContentSetting(rule.value.get()));
85 85
86 provider.ShutdownOnUIThread(); 86 provider.ShutdownOnUIThread();
87 } 87 }
88 88
89 TEST_F(PolicyProviderTest, ManagedDefaultPluginSettingsExperiment) { 89 TEST_F(PolicyProviderTest, ManagedDefaultPluginSettingsExperiment) {
90 base::test::ScopedFeatureList scoped_feature_list; 90 base::test::ScopedFeatureList scoped_feature_list;
91 scoped_feature_list.InitFromCommandLine("IgnoreDefaultPluginsSetting", 91 scoped_feature_list.InitFromCommandLine("IgnoreDefaultPluginsSetting",
92 std::string()); 92 std::string());
93 93
94 TestingProfile profile; 94 TestingProfile profile;
95 sync_preferences::TestingPrefServiceSyncable* prefs = 95 sync_preferences::TestingPrefServiceSyncable* prefs =
96 profile.GetTestingPrefService(); 96 profile.GetTestingPrefService();
97 PolicyProvider provider(prefs); 97 PolicyProvider provider(prefs);
98 98
99 // ForceDefaultPluginsSettingAsk overrides this to ASK. 99 // ForceDefaultPluginsSettingAsk overrides this to ASK.
100 prefs->SetManagedPref(prefs::kManagedDefaultPluginsSetting, 100 prefs->SetManagedPref(prefs::kManagedDefaultPluginsSetting,
101 new base::FundamentalValue(CONTENT_SETTING_BLOCK)); 101 new base::Value(CONTENT_SETTING_BLOCK));
102 prefs->SetManagedPref(prefs::kManagedDefaultJavaScriptSetting, 102 prefs->SetManagedPref(prefs::kManagedDefaultJavaScriptSetting,
103 new base::FundamentalValue(CONTENT_SETTING_BLOCK)); 103 new base::Value(CONTENT_SETTING_BLOCK));
104 104
105 std::unique_ptr<RuleIterator> plugin_rule_iterator(provider.GetRuleIterator( 105 std::unique_ptr<RuleIterator> plugin_rule_iterator(provider.GetRuleIterator(
106 CONTENT_SETTINGS_TYPE_PLUGINS, std::string(), false)); 106 CONTENT_SETTINGS_TYPE_PLUGINS, std::string(), false));
107 // Policy should be removed when running under experiment. 107 // Policy should be removed when running under experiment.
108 EXPECT_FALSE(plugin_rule_iterator); 108 EXPECT_FALSE(plugin_rule_iterator);
109 109
110 std::unique_ptr<RuleIterator> js_rule_iterator(provider.GetRuleIterator( 110 std::unique_ptr<RuleIterator> js_rule_iterator(provider.GetRuleIterator(
111 CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string(), false)); 111 CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string(), false));
112 // Other policies should be left alone. 112 // Other policies should be left alone.
113 EXPECT_TRUE(js_rule_iterator->HasNext()); 113 EXPECT_TRUE(js_rule_iterator->HasNext());
(...skipping 19 matching lines...) Expand all
133 MockObserver mock_observer; 133 MockObserver mock_observer;
134 EXPECT_CALL(mock_observer, 134 EXPECT_CALL(mock_observer,
135 OnContentSettingChanged(_, 135 OnContentSettingChanged(_,
136 _, 136 _,
137 CONTENT_SETTINGS_TYPE_DEFAULT, 137 CONTENT_SETTINGS_TYPE_DEFAULT,
138 "")); 138 ""));
139 provider.AddObserver(&mock_observer); 139 provider.AddObserver(&mock_observer);
140 140
141 // Set the managed default-content-setting. 141 // Set the managed default-content-setting.
142 prefs->SetManagedPref(prefs::kManagedDefaultImagesSetting, 142 prefs->SetManagedPref(prefs::kManagedDefaultImagesSetting,
143 new base::FundamentalValue(CONTENT_SETTING_BLOCK)); 143 new base::Value(CONTENT_SETTING_BLOCK));
144 ::testing::Mock::VerifyAndClearExpectations(&mock_observer); 144 ::testing::Mock::VerifyAndClearExpectations(&mock_observer);
145 EXPECT_CALL(mock_observer, 145 EXPECT_CALL(mock_observer,
146 OnContentSettingChanged(_, 146 OnContentSettingChanged(_,
147 _, 147 _,
148 CONTENT_SETTINGS_TYPE_DEFAULT, 148 CONTENT_SETTINGS_TYPE_DEFAULT,
149 "")); 149 ""));
150 // Remove the managed default-content-setting. 150 // Remove the managed default-content-setting.
151 prefs->RemoveManagedPref(prefs::kManagedDefaultImagesSetting); 151 prefs->RemoveManagedPref(prefs::kManagedDefaultImagesSetting);
152 provider.ShutdownOnUIThread(); 152 provider.ShutdownOnUIThread();
153 } 153 }
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 std::string(), false)); 186 std::string(), false));
187 187
188 int int_value = -1; 188 int int_value = -1;
189 value_ptr->GetAsInteger(&int_value); 189 value_ptr->GetAsInteger(&int_value);
190 EXPECT_EQ(CONTENT_SETTING_BLOCK, IntToContentSetting(int_value)); 190 EXPECT_EQ(CONTENT_SETTING_BLOCK, IntToContentSetting(int_value));
191 191
192 // The PolicyProvider does not allow setting content settings as they are 192 // The PolicyProvider does not allow setting content settings as they are
193 // enforced via policies and not set by the user or extension. So a call to 193 // enforced via policies and not set by the user or extension. So a call to
194 // SetWebsiteSetting does nothing. 194 // SetWebsiteSetting does nothing.
195 std::unique_ptr<base::Value> value_block( 195 std::unique_ptr<base::Value> value_block(
196 new base::FundamentalValue(CONTENT_SETTING_BLOCK)); 196 new base::Value(CONTENT_SETTING_BLOCK));
197 bool owned = provider.SetWebsiteSetting(yt_url_pattern, 197 bool owned = provider.SetWebsiteSetting(yt_url_pattern,
198 yt_url_pattern, 198 yt_url_pattern,
199 CONTENT_SETTINGS_TYPE_COOKIES, 199 CONTENT_SETTINGS_TYPE_COOKIES,
200 std::string(), 200 std::string(),
201 value_block.get()); 201 value_block.get());
202 EXPECT_FALSE(owned); 202 EXPECT_FALSE(owned);
203 EXPECT_EQ(CONTENT_SETTING_DEFAULT, 203 EXPECT_EQ(CONTENT_SETTING_DEFAULT,
204 TestUtils::GetContentSetting(&provider, youtube_url, youtube_url, 204 TestUtils::GetContentSetting(&provider, youtube_url, youtube_url,
205 CONTENT_SETTINGS_TYPE_COOKIES, 205 CONTENT_SETTINGS_TYPE_COOKIES,
206 std::string(), false)); 206 std::string(), false));
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 ASSERT_EQ(base::Value::Type::DICTIONARY, cert_filter->GetType()); 276 ASSERT_EQ(base::Value::Type::DICTIONARY, cert_filter->GetType());
277 base::DictionaryValue* dict_value = 277 base::DictionaryValue* dict_value =
278 static_cast<base::DictionaryValue*>(cert_filter.get()); 278 static_cast<base::DictionaryValue*>(cert_filter.get());
279 std::string actual_common_name; 279 std::string actual_common_name;
280 ASSERT_TRUE(dict_value->GetString("ISSUER.CN", &actual_common_name)); 280 ASSERT_TRUE(dict_value->GetString("ISSUER.CN", &actual_common_name));
281 EXPECT_EQ("issuer name", actual_common_name); 281 EXPECT_EQ("issuer name", actual_common_name);
282 provider.ShutdownOnUIThread(); 282 provider.ShutdownOnUIThread();
283 } 283 }
284 284
285 } // namespace content_settings 285 } // namespace content_settings
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698