Add diagnostics_writer.cc to the list of files allowed to printf.
[chromium-blink-merge.git] / components / search_engines / default_search_policy_handler_unittest.cc
blob94620de8d9f5ba10a41b14ce99024146f580d534
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
3 // found in the LICENSE file.
5 #include "base/memory/scoped_ptr.h"
6 #include "components/policy/core/browser/configuration_policy_pref_store.h"
7 #include "components/policy/core/browser/configuration_policy_pref_store_test.h"
8 #include "components/search_engines/default_search_manager.h"
9 #include "components/search_engines/default_search_policy_handler.h"
10 #include "components/search_engines/search_engines_pref_names.h"
11 #include "policy/policy_constants.h"
13 namespace {
14 // TODO(caitkp): Should we find a way to route this through DefaultSearchManager
15 // to avoid hardcoding this here?
16 const char kDefaultSearchProviderData[] =
17 "default_search_provider_data.template_url_data";
18 } // namespace
20 namespace policy {
22 class DefaultSearchPolicyHandlerTest
23 : public ConfigurationPolicyPrefStoreTest {
24 public:
25 DefaultSearchPolicyHandlerTest() {
26 default_alternate_urls_.AppendString(
27 "http://www.google.com/#q={searchTerms}");
28 default_alternate_urls_.AppendString(
29 "http://www.google.com/search#q={searchTerms}");
32 virtual void SetUp() OVERRIDE {
33 handler_list_.AddHandler(make_scoped_ptr<ConfigurationPolicyHandler>(
34 new DefaultSearchPolicyHandler));
37 protected:
38 static const char kSearchURL[];
39 static const char kSuggestURL[];
40 static const char kIconURL[];
41 static const char kName[];
42 static const char kKeyword[];
43 static const char kReplacementKey[];
44 static const char kImageURL[];
45 static const char kImageParams[];
46 static const char kNewTabURL[];
47 static const char kFileSearchURL[];
48 static const char kHostName[];
50 // Build a default search policy by setting search-related keys in |policy| to
51 // reasonable values. You can update any of the keys after calling this
52 // method.
53 void BuildDefaultSearchPolicy(PolicyMap* policy);
55 base::ListValue default_alternate_urls_;
58 const char DefaultSearchPolicyHandlerTest::kSearchURL[] =
59 "http://test.com/search?t={searchTerms}";
60 const char DefaultSearchPolicyHandlerTest::kSuggestURL[] =
61 "http://test.com/sugg?={searchTerms}";
62 const char DefaultSearchPolicyHandlerTest::kIconURL[] =
63 "http://test.com/icon.jpg";
64 const char DefaultSearchPolicyHandlerTest::kName[] =
65 "MyName";
66 const char DefaultSearchPolicyHandlerTest::kKeyword[] =
67 "MyKeyword";
68 const char DefaultSearchPolicyHandlerTest::kReplacementKey[] =
69 "espv";
70 const char DefaultSearchPolicyHandlerTest::kImageURL[] =
71 "http://test.com/searchbyimage/upload";
72 const char DefaultSearchPolicyHandlerTest::kImageParams[] =
73 "image_content=content,image_url=http://test.com/test.png";
74 const char DefaultSearchPolicyHandlerTest::kNewTabURL[] =
75 "http://test.com/newtab";
76 const char DefaultSearchPolicyHandlerTest::kFileSearchURL[] =
77 "file:///c:/path/to/search?t={searchTerms}";
78 const char DefaultSearchPolicyHandlerTest::kHostName[] = "test.com";
80 void DefaultSearchPolicyHandlerTest::
81 BuildDefaultSearchPolicy(PolicyMap* policy) {
82 base::ListValue* encodings = new base::ListValue();
83 encodings->AppendString("UTF-16");
84 encodings->AppendString("UTF-8");
85 policy->Set(key::kDefaultSearchProviderEnabled,
86 POLICY_LEVEL_MANDATORY,
87 POLICY_SCOPE_USER,
88 new base::FundamentalValue(true),
89 NULL);
90 policy->Set(key::kDefaultSearchProviderSearchURL,
91 POLICY_LEVEL_MANDATORY,
92 POLICY_SCOPE_USER,
93 new base::StringValue(kSearchURL),
94 NULL);
95 policy->Set(key::kDefaultSearchProviderName,
96 POLICY_LEVEL_MANDATORY,
97 POLICY_SCOPE_USER,
98 new base::StringValue(kName),
99 NULL);
100 policy->Set(key::kDefaultSearchProviderKeyword,
101 POLICY_LEVEL_MANDATORY,
102 POLICY_SCOPE_USER,
103 new base::StringValue(kKeyword),
104 NULL);
105 policy->Set(key::kDefaultSearchProviderSuggestURL,
106 POLICY_LEVEL_MANDATORY,
107 POLICY_SCOPE_USER,
108 new base::StringValue(kSuggestURL),
109 NULL);
110 policy->Set(key::kDefaultSearchProviderIconURL,
111 POLICY_LEVEL_MANDATORY,
112 POLICY_SCOPE_USER,
113 new base::StringValue(kIconURL),
114 NULL);
115 policy->Set(key::kDefaultSearchProviderEncodings, POLICY_LEVEL_MANDATORY,
116 POLICY_SCOPE_USER, encodings, NULL);
117 policy->Set(key::kDefaultSearchProviderAlternateURLs, POLICY_LEVEL_MANDATORY,
118 POLICY_SCOPE_USER, default_alternate_urls_.DeepCopy(), NULL);
119 policy->Set(key::kDefaultSearchProviderSearchTermsReplacementKey,
120 POLICY_LEVEL_MANDATORY,
121 POLICY_SCOPE_USER,
122 new base::StringValue(kReplacementKey),
123 NULL);
124 policy->Set(key::kDefaultSearchProviderImageURL,
125 POLICY_LEVEL_MANDATORY,
126 POLICY_SCOPE_USER,
127 new base::StringValue(kImageURL),
128 NULL);
129 policy->Set(key::kDefaultSearchProviderImageURLPostParams,
130 POLICY_LEVEL_MANDATORY,
131 POLICY_SCOPE_USER,
132 new base::StringValue(kImageParams),
133 NULL);
134 policy->Set(key::kDefaultSearchProviderNewTabURL,
135 POLICY_LEVEL_MANDATORY,
136 POLICY_SCOPE_USER,
137 new base::StringValue(kNewTabURL),
138 NULL);
141 // Checks that if the policy for default search is valid, i.e. there's a
142 // search URL, that all the elements have been given proper defaults.
143 TEST_F(DefaultSearchPolicyHandlerTest, MinimallyDefined) {
144 PolicyMap policy;
145 policy.Set(key::kDefaultSearchProviderEnabled,
146 POLICY_LEVEL_MANDATORY,
147 POLICY_SCOPE_USER,
148 new base::FundamentalValue(true),
149 NULL);
150 policy.Set(key::kDefaultSearchProviderSearchURL,
151 POLICY_LEVEL_MANDATORY,
152 POLICY_SCOPE_USER,
153 new base::StringValue(kSearchURL),
154 NULL);
155 UpdateProviderPolicy(policy);
157 const base::Value* value = NULL;
158 EXPECT_TRUE(store_->GetValue(prefs::kDefaultSearchProviderSearchURL, &value));
159 EXPECT_TRUE(base::StringValue(kSearchURL).Equals(value));
161 EXPECT_TRUE(store_->GetValue(prefs::kDefaultSearchProviderName, &value));
162 EXPECT_TRUE(base::StringValue(kHostName).Equals(value));
164 EXPECT_TRUE(store_->GetValue(prefs::kDefaultSearchProviderKeyword, &value));
165 EXPECT_TRUE(base::StringValue(kHostName).Equals(value));
167 EXPECT_TRUE(store_->GetValue(prefs::kDefaultSearchProviderSuggestURL,
168 &value));
169 EXPECT_TRUE(base::StringValue(std::string()).Equals(value));
171 EXPECT_TRUE(store_->GetValue(prefs::kDefaultSearchProviderIconURL, &value));
172 EXPECT_TRUE(base::StringValue(std::string()).Equals(value));
174 EXPECT_TRUE(store_->GetValue(prefs::kDefaultSearchProviderEncodings, &value));
175 EXPECT_TRUE(base::StringValue(std::string()).Equals(value));
177 EXPECT_TRUE(store_->GetValue(prefs::kDefaultSearchProviderInstantURL,
178 &value));
179 EXPECT_TRUE(base::StringValue(std::string()).Equals(value));
181 EXPECT_TRUE(store_->GetValue(prefs::kDefaultSearchProviderAlternateURLs,
182 &value));
183 EXPECT_TRUE(base::ListValue().Equals(value));
185 EXPECT_TRUE(
186 store_->GetValue(prefs::kDefaultSearchProviderSearchTermsReplacementKey,
187 &value));
188 EXPECT_TRUE(base::StringValue(std::string()).Equals(value));
190 EXPECT_TRUE(store_->GetValue(prefs::kDefaultSearchProviderImageURL, &value));
191 EXPECT_TRUE(base::StringValue(std::string()).Equals(value));
193 EXPECT_TRUE(store_->GetValue(
194 prefs::kDefaultSearchProviderSearchURLPostParams, &value));
195 EXPECT_TRUE(base::StringValue(std::string()).Equals(value));
197 EXPECT_TRUE(store_->GetValue(
198 prefs::kDefaultSearchProviderSuggestURLPostParams, &value));
199 EXPECT_TRUE(base::StringValue(std::string()).Equals(value));
201 EXPECT_TRUE(store_->GetValue(
202 prefs::kDefaultSearchProviderInstantURLPostParams, &value));
203 EXPECT_TRUE(base::StringValue(std::string()).Equals(value));
205 EXPECT_TRUE(store_->GetValue(
206 prefs::kDefaultSearchProviderImageURLPostParams, &value));
207 EXPECT_TRUE(base::StringValue(std::string()).Equals(value));
209 EXPECT_TRUE(store_->GetValue(
210 prefs::kDefaultSearchProviderNewTabURL, &value));
211 EXPECT_TRUE(base::StringValue(std::string()).Equals(value));
214 // Checks that for a fully defined search policy, all elements have been
215 // read properly.
216 TEST_F(DefaultSearchPolicyHandlerTest, FullyDefined) {
217 PolicyMap policy;
218 BuildDefaultSearchPolicy(&policy);
219 UpdateProviderPolicy(policy);
221 const base::Value* value = NULL;
222 EXPECT_TRUE(store_->GetValue(prefs::kDefaultSearchProviderSearchURL, &value));
223 EXPECT_TRUE(base::StringValue(kSearchURL).Equals(value));
225 EXPECT_TRUE(store_->GetValue(prefs::kDefaultSearchProviderName, &value));
226 EXPECT_TRUE(base::StringValue(kName).Equals(value));
228 EXPECT_TRUE(store_->GetValue(prefs::kDefaultSearchProviderKeyword, &value));
229 EXPECT_TRUE(base::StringValue(kKeyword).Equals(value));
231 EXPECT_TRUE(store_->GetValue(prefs::kDefaultSearchProviderSuggestURL,
232 &value));
233 EXPECT_TRUE(base::StringValue(kSuggestURL).Equals(value));
235 EXPECT_TRUE(store_->GetValue(prefs::kDefaultSearchProviderIconURL, &value));
236 EXPECT_TRUE(base::StringValue(kIconURL).Equals(value));
238 EXPECT_TRUE(store_->GetValue(prefs::kDefaultSearchProviderEncodings, &value));
239 EXPECT_TRUE(base::StringValue("UTF-16;UTF-8").Equals(value));
241 EXPECT_TRUE(store_->GetValue(
242 prefs::kDefaultSearchProviderAlternateURLs, &value));
243 EXPECT_TRUE(default_alternate_urls_.Equals(value));
245 EXPECT_TRUE(
246 store_->GetValue(prefs::kDefaultSearchProviderSearchTermsReplacementKey,
247 &value));
248 EXPECT_TRUE(base::StringValue(kReplacementKey).Equals(value));
250 EXPECT_TRUE(store_->GetValue(prefs::kDefaultSearchProviderImageURL, &value));
251 EXPECT_TRUE(base::StringValue(std::string(kImageURL)).Equals(value));
253 EXPECT_TRUE(store_->GetValue(prefs::kDefaultSearchProviderImageURLPostParams,
254 &value));
255 EXPECT_TRUE(base::StringValue(std::string(kImageParams)).Equals(value));
257 EXPECT_TRUE(store_->GetValue(
258 prefs::kDefaultSearchProviderSearchURLPostParams, &value));
259 EXPECT_TRUE(base::StringValue(std::string()).Equals(value));
261 EXPECT_TRUE(store_->GetValue(
262 prefs::kDefaultSearchProviderSuggestURLPostParams, &value));
263 EXPECT_TRUE(base::StringValue(std::string()).Equals(value));
265 EXPECT_TRUE(store_->GetValue(
266 prefs::kDefaultSearchProviderInstantURLPostParams, &value));
267 EXPECT_TRUE(base::StringValue(std::string()).Equals(value));
270 // Checks that if the default search policy is missing, that no elements of the
271 // default search policy will be present.
272 TEST_F(DefaultSearchPolicyHandlerTest, MissingUrl) {
273 PolicyMap policy;
274 BuildDefaultSearchPolicy(&policy);
275 policy.Erase(key::kDefaultSearchProviderSearchURL);
276 UpdateProviderPolicy(policy);
278 EXPECT_FALSE(store_->GetValue(prefs::kDefaultSearchProviderSearchURL, NULL));
279 EXPECT_FALSE(store_->GetValue(prefs::kDefaultSearchProviderName, NULL));
280 EXPECT_FALSE(store_->GetValue(prefs::kDefaultSearchProviderKeyword, NULL));
281 EXPECT_FALSE(store_->GetValue(prefs::kDefaultSearchProviderSuggestURL, NULL));
282 EXPECT_FALSE(store_->GetValue(prefs::kDefaultSearchProviderIconURL, NULL));
283 EXPECT_FALSE(store_->GetValue(prefs::kDefaultSearchProviderEncodings, NULL));
284 EXPECT_FALSE(store_->GetValue(prefs::kDefaultSearchProviderAlternateURLs,
285 NULL));
286 EXPECT_FALSE(store_->GetValue(
287 prefs::kDefaultSearchProviderSearchTermsReplacementKey, NULL));
288 EXPECT_FALSE(store_->GetValue(prefs::kDefaultSearchProviderImageURL, NULL));
289 EXPECT_FALSE(store_->GetValue(
290 prefs::kDefaultSearchProviderImageURLPostParams, NULL));
291 EXPECT_FALSE(store_->GetValue(prefs::kDefaultSearchProviderInstantURL, NULL));
292 EXPECT_FALSE(store_->GetValue(prefs::kDefaultSearchProviderNewTabURL, NULL));
295 // Checks that if the default search policy is invalid, that no elements of the
296 // default search policy will be present.
297 TEST_F(DefaultSearchPolicyHandlerTest, Invalid) {
298 PolicyMap policy;
299 BuildDefaultSearchPolicy(&policy);
300 const char bad_search_url[] = "http://test.com/noSearchTerms";
301 policy.Set(key::kDefaultSearchProviderSearchURL,
302 POLICY_LEVEL_MANDATORY,
303 POLICY_SCOPE_USER,
304 new base::StringValue(bad_search_url),
305 NULL);
306 UpdateProviderPolicy(policy);
308 EXPECT_FALSE(store_->GetValue(prefs::kDefaultSearchProviderSearchURL, NULL));
309 EXPECT_FALSE(store_->GetValue(prefs::kDefaultSearchProviderName, NULL));
310 EXPECT_FALSE(store_->GetValue(prefs::kDefaultSearchProviderKeyword, NULL));
311 EXPECT_FALSE(store_->GetValue(prefs::kDefaultSearchProviderSuggestURL, NULL));
312 EXPECT_FALSE(store_->GetValue(prefs::kDefaultSearchProviderIconURL, NULL));
313 EXPECT_FALSE(store_->GetValue(prefs::kDefaultSearchProviderEncodings, NULL));
314 EXPECT_FALSE(store_->GetValue(prefs::kDefaultSearchProviderAlternateURLs,
315 NULL));
316 EXPECT_FALSE(store_->GetValue(
317 prefs::kDefaultSearchProviderSearchTermsReplacementKey, NULL));
318 EXPECT_FALSE(store_->GetValue(prefs::kDefaultSearchProviderImageURL, NULL));
319 EXPECT_FALSE(store_->GetValue(
320 prefs::kDefaultSearchProviderImageURLPostParams, NULL));
321 EXPECT_FALSE(store_->GetValue(prefs::kDefaultSearchProviderInstantURL, NULL));
322 EXPECT_FALSE(store_->GetValue(prefs::kDefaultSearchProviderNewTabURL, NULL));
325 // Checks that if the default search policy is invalid, that no elements of the
326 // default search policy will be present.
327 TEST_F(DefaultSearchPolicyHandlerTest, Disabled) {
328 PolicyMap policy;
329 policy.Set(key::kDefaultSearchProviderEnabled,
330 POLICY_LEVEL_MANDATORY,
331 POLICY_SCOPE_USER,
332 new base::FundamentalValue(false),
333 NULL);
334 UpdateProviderPolicy(policy);
336 const base::Value* value = NULL;
337 EXPECT_TRUE(store_->GetValue(prefs::kDefaultSearchProviderEnabled, &value));
338 base::FundamentalValue expected_enabled(false);
339 EXPECT_TRUE(base::Value::Equals(&expected_enabled, value));
340 EXPECT_TRUE(store_->GetValue(prefs::kDefaultSearchProviderSearchURL, &value));
341 base::StringValue expected_search_url((std::string()));
342 EXPECT_TRUE(base::Value::Equals(&expected_search_url, value));
345 // Checks that for a fully defined search policy, all elements have been
346 // read properly into the dictionary pref.
347 TEST_F(DefaultSearchPolicyHandlerTest, DictionaryPref) {
348 PolicyMap policy;
349 BuildDefaultSearchPolicy(&policy);
350 UpdateProviderPolicy(policy);
352 const base::Value* temp = NULL;
353 const base::DictionaryValue* dictionary;
354 std::string value;
355 const base::ListValue* list_value;
356 EXPECT_TRUE(store_->GetValue(kDefaultSearchProviderData, &temp));
357 temp->GetAsDictionary(&dictionary);
359 EXPECT_TRUE(dictionary->GetString(DefaultSearchManager::kURL, &value));
360 EXPECT_EQ(kSearchURL, value);
361 EXPECT_TRUE(dictionary->GetString(DefaultSearchManager::kShortName, &value));
362 EXPECT_EQ(kName, value);
363 EXPECT_TRUE(dictionary->GetString(DefaultSearchManager::kKeyword, &value));
364 EXPECT_EQ(kKeyword, value);
366 EXPECT_TRUE(
367 dictionary->GetString(DefaultSearchManager::kSuggestionsURL, &value));
368 EXPECT_EQ(kSuggestURL, value);
369 EXPECT_TRUE(dictionary->GetString(DefaultSearchManager::kFaviconURL, &value));
370 EXPECT_EQ(kIconURL, value);
372 base::ListValue encodings;
373 encodings.AppendString("UTF-16");
374 encodings.AppendString("UTF-8");
376 EXPECT_TRUE(
377 dictionary->GetList(DefaultSearchManager::kInputEncodings, &list_value));
378 EXPECT_TRUE(encodings.Equals(list_value));
380 EXPECT_TRUE(
381 dictionary->GetList(DefaultSearchManager::kAlternateURLs, &list_value));
382 EXPECT_TRUE(default_alternate_urls_.Equals(list_value));
384 EXPECT_TRUE(dictionary->GetString(
385 DefaultSearchManager::kSearchTermsReplacementKey, &value));
386 EXPECT_EQ(kReplacementKey, value);
388 EXPECT_TRUE(dictionary->GetString(DefaultSearchManager::kImageURL, &value));
389 EXPECT_EQ(kImageURL, value);
391 EXPECT_TRUE(
392 dictionary->GetString(DefaultSearchManager::kImageURLPostParams, &value));
393 EXPECT_EQ(kImageParams, value);
395 EXPECT_TRUE(dictionary->GetString(DefaultSearchManager::kSearchURLPostParams,
396 &value));
397 EXPECT_EQ(std::string(), value);
399 EXPECT_TRUE(dictionary->GetString(
400 DefaultSearchManager::kSuggestionsURLPostParams, &value));
401 EXPECT_EQ(std::string(), value);
403 EXPECT_TRUE(dictionary->GetString(DefaultSearchManager::kInstantURLPostParams,
404 &value));
405 EXPECT_EQ(std::string(), value);
408 // Checks that disabling default search is properly reflected the dictionary
409 // pref.
410 TEST_F(DefaultSearchPolicyHandlerTest, DictionaryPrefDSEDisabled) {
411 PolicyMap policy;
412 policy.Set(key::kDefaultSearchProviderEnabled,
413 POLICY_LEVEL_MANDATORY,
414 POLICY_SCOPE_USER,
415 new base::FundamentalValue(false),
416 NULL);
417 UpdateProviderPolicy(policy);
418 const base::Value* temp = NULL;
419 const base::DictionaryValue* dictionary;
420 EXPECT_TRUE(store_->GetValue(kDefaultSearchProviderData, &temp));
421 temp->GetAsDictionary(&dictionary);
422 bool disabled = false;
423 EXPECT_TRUE(dictionary->GetBoolean(DefaultSearchManager::kDisabledByPolicy,
424 &disabled));
425 EXPECT_TRUE(disabled);
428 // Checks that if the policy for default search is valid, i.e. there's a
429 // search URL, that all the elements have been given proper defaults.
430 TEST_F(DefaultSearchPolicyHandlerTest, DictionaryPrefMinimallyDefined) {
431 PolicyMap policy;
432 policy.Set(key::kDefaultSearchProviderEnabled,
433 POLICY_LEVEL_MANDATORY,
434 POLICY_SCOPE_USER,
435 new base::FundamentalValue(true),
436 NULL);
437 policy.Set(key::kDefaultSearchProviderSearchURL,
438 POLICY_LEVEL_MANDATORY,
439 POLICY_SCOPE_USER,
440 new base::StringValue(kSearchURL),
441 NULL);
442 UpdateProviderPolicy(policy);
444 const base::Value* temp = NULL;
445 const base::DictionaryValue* dictionary;
446 std::string value;
447 const base::ListValue* list_value;
448 EXPECT_TRUE(store_->GetValue(kDefaultSearchProviderData, &temp));
449 temp->GetAsDictionary(&dictionary);
451 // Name and keyword should be derived from host.
452 EXPECT_TRUE(dictionary->GetString(DefaultSearchManager::kURL, &value));
453 EXPECT_EQ(kSearchURL, value);
454 EXPECT_TRUE(dictionary->GetString(DefaultSearchManager::kShortName, &value));
455 EXPECT_EQ(kHostName, value);
456 EXPECT_TRUE(dictionary->GetString(DefaultSearchManager::kKeyword, &value));
457 EXPECT_EQ(kHostName, value);
459 // Everything else should be set to the default value.
460 EXPECT_TRUE(
461 dictionary->GetString(DefaultSearchManager::kSuggestionsURL, &value));
462 EXPECT_EQ(std::string(), value);
463 EXPECT_TRUE(dictionary->GetString(DefaultSearchManager::kFaviconURL, &value));
464 EXPECT_EQ(std::string(), value);
465 EXPECT_TRUE(
466 dictionary->GetList(DefaultSearchManager::kInputEncodings, &list_value));
467 EXPECT_TRUE(base::ListValue().Equals(list_value));
468 EXPECT_TRUE(
469 dictionary->GetList(DefaultSearchManager::kAlternateURLs, &list_value));
470 EXPECT_TRUE(base::ListValue().Equals(list_value));
471 EXPECT_TRUE(dictionary->GetString(
472 DefaultSearchManager::kSearchTermsReplacementKey, &value));
473 EXPECT_EQ(std::string(), value);
474 EXPECT_TRUE(dictionary->GetString(DefaultSearchManager::kImageURL, &value));
475 EXPECT_EQ(std::string(), value);
476 EXPECT_TRUE(
477 dictionary->GetString(DefaultSearchManager::kImageURLPostParams, &value));
478 EXPECT_EQ(std::string(), value);
479 EXPECT_TRUE(dictionary->GetString(DefaultSearchManager::kSearchURLPostParams,
480 &value));
481 EXPECT_EQ(std::string(), value);
482 EXPECT_TRUE(dictionary->GetString(
483 DefaultSearchManager::kSuggestionsURLPostParams, &value));
484 EXPECT_EQ(std::string(), value);
485 EXPECT_TRUE(dictionary->GetString(DefaultSearchManager::kInstantURLPostParams,
486 &value));
487 EXPECT_EQ(std::string(), value);
490 // Checks that setting a file URL as the default search is reflected properly in
491 // the dictionary pref.
492 TEST_F(DefaultSearchPolicyHandlerTest, DictionaryPrefFileURL) {
493 PolicyMap policy;
494 policy.Set(key::kDefaultSearchProviderEnabled,
495 POLICY_LEVEL_MANDATORY,
496 POLICY_SCOPE_USER,
497 new base::FundamentalValue(true),
498 NULL);
499 policy.Set(key::kDefaultSearchProviderSearchURL,
500 POLICY_LEVEL_MANDATORY,
501 POLICY_SCOPE_USER,
502 new base::StringValue(kFileSearchURL),
503 NULL);
504 UpdateProviderPolicy(policy);
506 const base::Value* temp = NULL;
507 const base::DictionaryValue* dictionary;
508 std::string value;
510 EXPECT_TRUE(store_->GetValue(kDefaultSearchProviderData, &temp));
511 temp->GetAsDictionary(&dictionary);
513 EXPECT_TRUE(dictionary->GetString(DefaultSearchManager::kURL, &value));
514 EXPECT_EQ(kFileSearchURL, value);
515 EXPECT_TRUE(dictionary->GetString(DefaultSearchManager::kShortName, &value));
516 EXPECT_EQ("_", value);
517 EXPECT_TRUE(dictionary->GetString(DefaultSearchManager::kKeyword, &value));
518 EXPECT_EQ("_", value);
520 } // namespace policy