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

Side by Side Diff: components/search_engines/default_search_policy_handler_unittest.cc

Issue 1940153002: Use std::unique_ptr to express ownership of base::Value in PolicyMap::Entry (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: another-fix Created 4 years, 7 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/search_engines/default_search_policy_handler.h" 5 #include "components/search_engines/default_search_policy_handler.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
10 #include "components/policy/core/browser/configuration_policy_pref_store.h" 10 #include "components/policy/core/browser/configuration_policy_pref_store.h"
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 "http://test.com/newtab"; 79 "http://test.com/newtab";
80 const char DefaultSearchPolicyHandlerTest::kFileSearchURL[] = 80 const char DefaultSearchPolicyHandlerTest::kFileSearchURL[] =
81 "file:///c:/path/to/search?t={searchTerms}"; 81 "file:///c:/path/to/search?t={searchTerms}";
82 const char DefaultSearchPolicyHandlerTest::kHostName[] = "test.com"; 82 const char DefaultSearchPolicyHandlerTest::kHostName[] = "test.com";
83 83
84 void DefaultSearchPolicyHandlerTest:: 84 void DefaultSearchPolicyHandlerTest::
85 BuildDefaultSearchPolicy(PolicyMap* policy) { 85 BuildDefaultSearchPolicy(PolicyMap* policy) {
86 base::ListValue* encodings = new base::ListValue(); 86 base::ListValue* encodings = new base::ListValue();
87 encodings->AppendString("UTF-16"); 87 encodings->AppendString("UTF-16");
88 encodings->AppendString("UTF-8"); 88 encodings->AppendString("UTF-8");
89 policy->Set(key::kDefaultSearchProviderEnabled, 89 policy->Set(key::kDefaultSearchProviderEnabled, POLICY_LEVEL_MANDATORY,
90 POLICY_LEVEL_MANDATORY, 90 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
91 POLICY_SCOPE_USER, 91 base::WrapUnique(new base::FundamentalValue(true)), nullptr);
92 POLICY_SOURCE_CLOUD, 92 policy->Set(key::kDefaultSearchProviderSearchURL, POLICY_LEVEL_MANDATORY,
93 new base::FundamentalValue(true), 93 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
94 NULL); 94 base::WrapUnique(new base::StringValue(kSearchURL)), nullptr);
95 policy->Set(key::kDefaultSearchProviderSearchURL, 95 policy->Set(key::kDefaultSearchProviderName, POLICY_LEVEL_MANDATORY,
96 POLICY_LEVEL_MANDATORY, 96 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
97 POLICY_SCOPE_USER, 97 base::WrapUnique(new base::StringValue(kName)), nullptr);
98 POLICY_SOURCE_CLOUD, 98 policy->Set(key::kDefaultSearchProviderKeyword, POLICY_LEVEL_MANDATORY,
99 new base::StringValue(kSearchURL), 99 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
100 NULL); 100 base::WrapUnique(new base::StringValue(kKeyword)), nullptr);
101 policy->Set(key::kDefaultSearchProviderName, 101 policy->Set(key::kDefaultSearchProviderSuggestURL, POLICY_LEVEL_MANDATORY,
102 POLICY_LEVEL_MANDATORY, 102 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
103 POLICY_SCOPE_USER, 103 base::WrapUnique(new base::StringValue(kSuggestURL)), nullptr);
104 POLICY_SOURCE_CLOUD, 104 policy->Set(key::kDefaultSearchProviderIconURL, POLICY_LEVEL_MANDATORY,
105 new base::StringValue(kName), 105 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
106 NULL); 106 base::WrapUnique(new base::StringValue(kIconURL)), nullptr);
107 policy->Set(key::kDefaultSearchProviderKeyword,
108 POLICY_LEVEL_MANDATORY,
109 POLICY_SCOPE_USER,
110 POLICY_SOURCE_CLOUD,
111 new base::StringValue(kKeyword),
112 NULL);
113 policy->Set(key::kDefaultSearchProviderSuggestURL,
114 POLICY_LEVEL_MANDATORY,
115 POLICY_SCOPE_USER,
116 POLICY_SOURCE_CLOUD,
117 new base::StringValue(kSuggestURL),
118 NULL);
119 policy->Set(key::kDefaultSearchProviderIconURL,
120 POLICY_LEVEL_MANDATORY,
121 POLICY_SCOPE_USER,
122 POLICY_SOURCE_CLOUD,
123 new base::StringValue(kIconURL),
124 NULL);
125 policy->Set(key::kDefaultSearchProviderEncodings, POLICY_LEVEL_MANDATORY, 107 policy->Set(key::kDefaultSearchProviderEncodings, POLICY_LEVEL_MANDATORY,
126 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, encodings, nullptr); 108 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
109 base::WrapUnique(encodings), nullptr);
127 policy->Set(key::kDefaultSearchProviderAlternateURLs, POLICY_LEVEL_MANDATORY, 110 policy->Set(key::kDefaultSearchProviderAlternateURLs, POLICY_LEVEL_MANDATORY,
128 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, 111 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
129 default_alternate_urls_.DeepCopy(), nullptr); 112 default_alternate_urls_.CreateDeepCopy(), nullptr);
130 policy->Set(key::kDefaultSearchProviderSearchTermsReplacementKey, 113 policy->Set(key::kDefaultSearchProviderSearchTermsReplacementKey,
131 POLICY_LEVEL_MANDATORY, 114 POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
132 POLICY_SCOPE_USER, 115 base::WrapUnique(new base::StringValue(kReplacementKey)),
133 POLICY_SOURCE_CLOUD, 116 nullptr);
134 new base::StringValue(kReplacementKey), 117 policy->Set(key::kDefaultSearchProviderImageURL, POLICY_LEVEL_MANDATORY,
135 NULL); 118 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
136 policy->Set(key::kDefaultSearchProviderImageURL, 119 base::WrapUnique(new base::StringValue(kImageURL)), nullptr);
137 POLICY_LEVEL_MANDATORY,
138 POLICY_SCOPE_USER,
139 POLICY_SOURCE_CLOUD,
140 new base::StringValue(kImageURL),
141 NULL);
142 policy->Set(key::kDefaultSearchProviderImageURLPostParams, 120 policy->Set(key::kDefaultSearchProviderImageURLPostParams,
143 POLICY_LEVEL_MANDATORY, 121 POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
144 POLICY_SCOPE_USER, 122 base::WrapUnique(new base::StringValue(kImageParams)), nullptr);
145 POLICY_SOURCE_CLOUD, 123 policy->Set(key::kDefaultSearchProviderNewTabURL, POLICY_LEVEL_MANDATORY,
146 new base::StringValue(kImageParams), 124 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
147 NULL); 125 base::WrapUnique(new base::StringValue(kNewTabURL)), nullptr);
148 policy->Set(key::kDefaultSearchProviderNewTabURL,
149 POLICY_LEVEL_MANDATORY,
150 POLICY_SCOPE_USER,
151 POLICY_SOURCE_CLOUD,
152 new base::StringValue(kNewTabURL),
153 NULL);
154 } 126 }
155 127
156 // Checks that if the default search policy is missing, that no elements of the 128 // Checks that if the default search policy is missing, that no elements of the
157 // default search policy will be present. 129 // default search policy will be present.
158 TEST_F(DefaultSearchPolicyHandlerTest, MissingUrl) { 130 TEST_F(DefaultSearchPolicyHandlerTest, MissingUrl) {
159 PolicyMap policy; 131 PolicyMap policy;
160 BuildDefaultSearchPolicy(&policy); 132 BuildDefaultSearchPolicy(&policy);
161 policy.Erase(key::kDefaultSearchProviderSearchURL); 133 policy.Erase(key::kDefaultSearchProviderSearchURL);
162 UpdateProviderPolicy(policy); 134 UpdateProviderPolicy(policy);
163 135
164 const base::Value* temp = nullptr; 136 const base::Value* temp = nullptr;
165 EXPECT_FALSE(store_->GetValue(kDefaultSearchProviderData, &temp)); 137 EXPECT_FALSE(store_->GetValue(kDefaultSearchProviderData, &temp));
166 } 138 }
167 139
168 // Checks that if the default search policy is invalid, that no elements of the 140 // Checks that if the default search policy is invalid, that no elements of the
169 // default search policy will be present. 141 // default search policy will be present.
170 TEST_F(DefaultSearchPolicyHandlerTest, Invalid) { 142 TEST_F(DefaultSearchPolicyHandlerTest, Invalid) {
171 PolicyMap policy; 143 PolicyMap policy;
172 BuildDefaultSearchPolicy(&policy); 144 BuildDefaultSearchPolicy(&policy);
173 const char bad_search_url[] = "http://test.com/noSearchTerms"; 145 const char bad_search_url[] = "http://test.com/noSearchTerms";
174 policy.Set(key::kDefaultSearchProviderSearchURL, POLICY_LEVEL_MANDATORY, 146 policy.Set(key::kDefaultSearchProviderSearchURL, POLICY_LEVEL_MANDATORY,
175 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, 147 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
176 new base::StringValue(bad_search_url), nullptr); 148 base::WrapUnique(new base::StringValue(bad_search_url)), nullptr);
177 UpdateProviderPolicy(policy); 149 UpdateProviderPolicy(policy);
178 150
179 const base::Value* temp = nullptr; 151 const base::Value* temp = nullptr;
180 EXPECT_FALSE(store_->GetValue(kDefaultSearchProviderData, &temp)); 152 EXPECT_FALSE(store_->GetValue(kDefaultSearchProviderData, &temp));
181 } 153 }
182 154
183 // Checks that for a fully defined search policy, all elements have been 155 // Checks that for a fully defined search policy, all elements have been
184 // read properly into the dictionary pref. 156 // read properly into the dictionary pref.
185 TEST_F(DefaultSearchPolicyHandlerTest, FullyDefined) { 157 TEST_F(DefaultSearchPolicyHandlerTest, FullyDefined) {
186 PolicyMap policy; 158 PolicyMap policy;
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 212
241 EXPECT_TRUE(dictionary->GetString(DefaultSearchManager::kInstantURLPostParams, 213 EXPECT_TRUE(dictionary->GetString(DefaultSearchManager::kInstantURLPostParams,
242 &value)); 214 &value));
243 EXPECT_EQ(std::string(), value); 215 EXPECT_EQ(std::string(), value);
244 } 216 }
245 217
246 // Checks that disabling default search is properly reflected the dictionary 218 // Checks that disabling default search is properly reflected the dictionary
247 // pref. 219 // pref.
248 TEST_F(DefaultSearchPolicyHandlerTest, Disabled) { 220 TEST_F(DefaultSearchPolicyHandlerTest, Disabled) {
249 PolicyMap policy; 221 PolicyMap policy;
250 policy.Set(key::kDefaultSearchProviderEnabled, 222 policy.Set(key::kDefaultSearchProviderEnabled, POLICY_LEVEL_MANDATORY,
251 POLICY_LEVEL_MANDATORY, 223 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
252 POLICY_SCOPE_USER, 224 base::WrapUnique(new base::FundamentalValue(false)), nullptr);
253 POLICY_SOURCE_CLOUD,
254 new base::FundamentalValue(false),
255 NULL);
256 UpdateProviderPolicy(policy); 225 UpdateProviderPolicy(policy);
257 const base::Value* temp = NULL; 226 const base::Value* temp = NULL;
258 const base::DictionaryValue* dictionary; 227 const base::DictionaryValue* dictionary;
259 EXPECT_TRUE(store_->GetValue(kDefaultSearchProviderData, &temp)); 228 EXPECT_TRUE(store_->GetValue(kDefaultSearchProviderData, &temp));
260 temp->GetAsDictionary(&dictionary); 229 temp->GetAsDictionary(&dictionary);
261 bool disabled = false; 230 bool disabled = false;
262 EXPECT_TRUE(dictionary->GetBoolean(DefaultSearchManager::kDisabledByPolicy, 231 EXPECT_TRUE(dictionary->GetBoolean(DefaultSearchManager::kDisabledByPolicy,
263 &disabled)); 232 &disabled));
264 EXPECT_TRUE(disabled); 233 EXPECT_TRUE(disabled);
265 } 234 }
266 235
267 // Checks that if the policy for default search is valid, i.e. there's a 236 // Checks that if the policy for default search is valid, i.e. there's a
268 // search URL, that all the elements have been given proper defaults. 237 // search URL, that all the elements have been given proper defaults.
269 TEST_F(DefaultSearchPolicyHandlerTest, MinimallyDefined) { 238 TEST_F(DefaultSearchPolicyHandlerTest, MinimallyDefined) {
270 PolicyMap policy; 239 PolicyMap policy;
271 policy.Set(key::kDefaultSearchProviderEnabled, 240 policy.Set(key::kDefaultSearchProviderEnabled, POLICY_LEVEL_MANDATORY,
272 POLICY_LEVEL_MANDATORY, 241 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
273 POLICY_SCOPE_USER, 242 base::WrapUnique(new base::FundamentalValue(true)), nullptr);
274 POLICY_SOURCE_CLOUD, 243 policy.Set(key::kDefaultSearchProviderSearchURL, POLICY_LEVEL_MANDATORY,
275 new base::FundamentalValue(true), 244 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
276 NULL); 245 base::WrapUnique(new base::StringValue(kSearchURL)), nullptr);
277 policy.Set(key::kDefaultSearchProviderSearchURL,
278 POLICY_LEVEL_MANDATORY,
279 POLICY_SCOPE_USER,
280 POLICY_SOURCE_CLOUD,
281 new base::StringValue(kSearchURL),
282 NULL);
283 UpdateProviderPolicy(policy); 246 UpdateProviderPolicy(policy);
284 247
285 const base::Value* temp = NULL; 248 const base::Value* temp = NULL;
286 const base::DictionaryValue* dictionary; 249 const base::DictionaryValue* dictionary;
287 std::string value; 250 std::string value;
288 const base::ListValue* list_value; 251 const base::ListValue* list_value;
289 EXPECT_TRUE(store_->GetValue(kDefaultSearchProviderData, &temp)); 252 EXPECT_TRUE(store_->GetValue(kDefaultSearchProviderData, &temp));
290 temp->GetAsDictionary(&dictionary); 253 temp->GetAsDictionary(&dictionary);
291 254
292 // Name and keyword should be derived from host. 255 // Name and keyword should be derived from host.
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 EXPECT_EQ(std::string(), value); 288 EXPECT_EQ(std::string(), value);
326 EXPECT_TRUE(dictionary->GetString(DefaultSearchManager::kInstantURLPostParams, 289 EXPECT_TRUE(dictionary->GetString(DefaultSearchManager::kInstantURLPostParams,
327 &value)); 290 &value));
328 EXPECT_EQ(std::string(), value); 291 EXPECT_EQ(std::string(), value);
329 } 292 }
330 293
331 // Checks that setting a file URL as the default search is reflected properly in 294 // Checks that setting a file URL as the default search is reflected properly in
332 // the dictionary pref. 295 // the dictionary pref.
333 TEST_F(DefaultSearchPolicyHandlerTest, FileURL) { 296 TEST_F(DefaultSearchPolicyHandlerTest, FileURL) {
334 PolicyMap policy; 297 PolicyMap policy;
335 policy.Set(key::kDefaultSearchProviderEnabled, 298 policy.Set(key::kDefaultSearchProviderEnabled, POLICY_LEVEL_MANDATORY,
336 POLICY_LEVEL_MANDATORY, 299 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
337 POLICY_SCOPE_USER, 300 base::WrapUnique(new base::FundamentalValue(true)), nullptr);
338 POLICY_SOURCE_CLOUD, 301 policy.Set(key::kDefaultSearchProviderSearchURL, POLICY_LEVEL_MANDATORY,
339 new base::FundamentalValue(true), 302 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
340 NULL); 303 base::WrapUnique(new base::StringValue(kFileSearchURL)), nullptr);
341 policy.Set(key::kDefaultSearchProviderSearchURL,
342 POLICY_LEVEL_MANDATORY,
343 POLICY_SCOPE_USER,
344 POLICY_SOURCE_CLOUD,
345 new base::StringValue(kFileSearchURL),
346 NULL);
347 UpdateProviderPolicy(policy); 304 UpdateProviderPolicy(policy);
348 305
349 const base::Value* temp = NULL; 306 const base::Value* temp = NULL;
350 const base::DictionaryValue* dictionary; 307 const base::DictionaryValue* dictionary;
351 std::string value; 308 std::string value;
352 309
353 EXPECT_TRUE(store_->GetValue(kDefaultSearchProviderData, &temp)); 310 EXPECT_TRUE(store_->GetValue(kDefaultSearchProviderData, &temp));
354 temp->GetAsDictionary(&dictionary); 311 temp->GetAsDictionary(&dictionary);
355 312
356 EXPECT_TRUE(dictionary->GetString(DefaultSearchManager::kURL, &value)); 313 EXPECT_TRUE(dictionary->GetString(DefaultSearchManager::kURL, &value));
357 EXPECT_EQ(kFileSearchURL, value); 314 EXPECT_EQ(kFileSearchURL, value);
358 EXPECT_TRUE(dictionary->GetString(DefaultSearchManager::kShortName, &value)); 315 EXPECT_TRUE(dictionary->GetString(DefaultSearchManager::kShortName, &value));
359 EXPECT_EQ("_", value); 316 EXPECT_EQ("_", value);
360 EXPECT_TRUE(dictionary->GetString(DefaultSearchManager::kKeyword, &value)); 317 EXPECT_TRUE(dictionary->GetString(DefaultSearchManager::kKeyword, &value));
361 EXPECT_EQ("_", value); 318 EXPECT_EQ("_", value);
362 } 319 }
363 } // namespace policy 320 } // namespace policy
OLDNEW
« no previous file with comments | « components/policy/tools/generate_policy_source.py ('k') | components/sync_driver/sync_policy_handler_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698