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

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

Issue 388963002: Get rid of the rest of CreateStringValue (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix bad rebase Created 6 years, 5 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 | Annotate | Revision Log
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 "base/memory/scoped_ptr.h" 5 #include "base/memory/scoped_ptr.h"
6 #include "components/policy/core/browser/configuration_policy_pref_store.h" 6 #include "components/policy/core/browser/configuration_policy_pref_store.h"
7 #include "components/policy/core/browser/configuration_policy_pref_store_test.h" 7 #include "components/policy/core/browser/configuration_policy_pref_store_test.h"
8 #include "components/search_engines/default_search_manager.h" 8 #include "components/search_engines/default_search_manager.h"
9 #include "components/search_engines/default_search_policy_handler.h" 9 #include "components/search_engines/default_search_policy_handler.h"
10 #include "components/search_engines/search_engines_pref_names.h" 10 #include "components/search_engines/search_engines_pref_names.h"
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 void DefaultSearchPolicyHandlerTest:: 80 void DefaultSearchPolicyHandlerTest::
81 BuildDefaultSearchPolicy(PolicyMap* policy) { 81 BuildDefaultSearchPolicy(PolicyMap* policy) {
82 base::ListValue* encodings = new base::ListValue(); 82 base::ListValue* encodings = new base::ListValue();
83 encodings->AppendString("UTF-16"); 83 encodings->AppendString("UTF-16");
84 encodings->AppendString("UTF-8"); 84 encodings->AppendString("UTF-8");
85 policy->Set(key::kDefaultSearchProviderEnabled, 85 policy->Set(key::kDefaultSearchProviderEnabled,
86 POLICY_LEVEL_MANDATORY, 86 POLICY_LEVEL_MANDATORY,
87 POLICY_SCOPE_USER, 87 POLICY_SCOPE_USER,
88 new base::FundamentalValue(true), 88 new base::FundamentalValue(true),
89 NULL); 89 NULL);
90 policy->Set(key::kDefaultSearchProviderSearchURL, POLICY_LEVEL_MANDATORY, 90 policy->Set(key::kDefaultSearchProviderSearchURL,
91 POLICY_SCOPE_USER, base::Value::CreateStringValue(kSearchURL), 91 POLICY_LEVEL_MANDATORY,
92 POLICY_SCOPE_USER,
93 new base::StringValue(kSearchURL),
92 NULL); 94 NULL);
93 policy->Set(key::kDefaultSearchProviderName, POLICY_LEVEL_MANDATORY, 95 policy->Set(key::kDefaultSearchProviderName,
94 POLICY_SCOPE_USER, base::Value::CreateStringValue(kName), NULL); 96 POLICY_LEVEL_MANDATORY,
95 policy->Set(key::kDefaultSearchProviderKeyword, POLICY_LEVEL_MANDATORY, 97 POLICY_SCOPE_USER,
96 POLICY_SCOPE_USER, base::Value::CreateStringValue(kKeyword), 98 new base::StringValue(kName),
97 NULL); 99 NULL);
98 policy->Set(key::kDefaultSearchProviderSuggestURL, POLICY_LEVEL_MANDATORY, 100 policy->Set(key::kDefaultSearchProviderKeyword,
99 POLICY_SCOPE_USER, base::Value::CreateStringValue(kSuggestURL), 101 POLICY_LEVEL_MANDATORY,
102 POLICY_SCOPE_USER,
103 new base::StringValue(kKeyword),
100 NULL); 104 NULL);
101 policy->Set(key::kDefaultSearchProviderIconURL, POLICY_LEVEL_MANDATORY, 105 policy->Set(key::kDefaultSearchProviderSuggestURL,
102 POLICY_SCOPE_USER, base::Value::CreateStringValue(kIconURL), 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),
103 NULL); 114 NULL);
104 policy->Set(key::kDefaultSearchProviderEncodings, POLICY_LEVEL_MANDATORY, 115 policy->Set(key::kDefaultSearchProviderEncodings, POLICY_LEVEL_MANDATORY,
105 POLICY_SCOPE_USER, encodings, NULL); 116 POLICY_SCOPE_USER, encodings, NULL);
106 policy->Set(key::kDefaultSearchProviderAlternateURLs, POLICY_LEVEL_MANDATORY, 117 policy->Set(key::kDefaultSearchProviderAlternateURLs, POLICY_LEVEL_MANDATORY,
107 POLICY_SCOPE_USER, default_alternate_urls_.DeepCopy(), NULL); 118 POLICY_SCOPE_USER, default_alternate_urls_.DeepCopy(), NULL);
108 policy->Set(key::kDefaultSearchProviderSearchTermsReplacementKey, 119 policy->Set(key::kDefaultSearchProviderSearchTermsReplacementKey,
109 POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, 120 POLICY_LEVEL_MANDATORY,
110 base::Value::CreateStringValue(kReplacementKey), NULL); 121 POLICY_SCOPE_USER,
122 new base::StringValue(kReplacementKey),
123 NULL);
111 policy->Set(key::kDefaultSearchProviderImageURL, 124 policy->Set(key::kDefaultSearchProviderImageURL,
112 POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, 125 POLICY_LEVEL_MANDATORY,
113 base::Value::CreateStringValue(kImageURL), NULL); 126 POLICY_SCOPE_USER,
127 new base::StringValue(kImageURL),
128 NULL);
114 policy->Set(key::kDefaultSearchProviderImageURLPostParams, 129 policy->Set(key::kDefaultSearchProviderImageURLPostParams,
115 POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, 130 POLICY_LEVEL_MANDATORY,
116 base::Value::CreateStringValue(kImageParams), NULL); 131 POLICY_SCOPE_USER,
132 new base::StringValue(kImageParams),
133 NULL);
117 policy->Set(key::kDefaultSearchProviderNewTabURL, 134 policy->Set(key::kDefaultSearchProviderNewTabURL,
118 POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, 135 POLICY_LEVEL_MANDATORY,
119 base::Value::CreateStringValue(kNewTabURL), NULL); 136 POLICY_SCOPE_USER,
137 new base::StringValue(kNewTabURL),
138 NULL);
120 } 139 }
121 140
122 // Checks that if the policy for default search is valid, i.e. there's a 141 // Checks that if the policy for default search is valid, i.e. there's a
123 // search URL, that all the elements have been given proper defaults. 142 // search URL, that all the elements have been given proper defaults.
124 TEST_F(DefaultSearchPolicyHandlerTest, MinimallyDefined) { 143 TEST_F(DefaultSearchPolicyHandlerTest, MinimallyDefined) {
125 PolicyMap policy; 144 PolicyMap policy;
126 policy.Set(key::kDefaultSearchProviderEnabled, 145 policy.Set(key::kDefaultSearchProviderEnabled,
127 POLICY_LEVEL_MANDATORY, 146 POLICY_LEVEL_MANDATORY,
128 POLICY_SCOPE_USER, 147 POLICY_SCOPE_USER,
129 new base::FundamentalValue(true), 148 new base::FundamentalValue(true),
130 NULL); 149 NULL);
131 policy.Set(key::kDefaultSearchProviderSearchURL, POLICY_LEVEL_MANDATORY, 150 policy.Set(key::kDefaultSearchProviderSearchURL,
132 POLICY_SCOPE_USER, base::Value::CreateStringValue(kSearchURL), 151 POLICY_LEVEL_MANDATORY,
152 POLICY_SCOPE_USER,
153 new base::StringValue(kSearchURL),
133 NULL); 154 NULL);
134 UpdateProviderPolicy(policy); 155 UpdateProviderPolicy(policy);
135 156
136 const base::Value* value = NULL; 157 const base::Value* value = NULL;
137 EXPECT_TRUE(store_->GetValue(prefs::kDefaultSearchProviderSearchURL, &value)); 158 EXPECT_TRUE(store_->GetValue(prefs::kDefaultSearchProviderSearchURL, &value));
138 EXPECT_TRUE(base::StringValue(kSearchURL).Equals(value)); 159 EXPECT_TRUE(base::StringValue(kSearchURL).Equals(value));
139 160
140 EXPECT_TRUE(store_->GetValue(prefs::kDefaultSearchProviderName, &value)); 161 EXPECT_TRUE(store_->GetValue(prefs::kDefaultSearchProviderName, &value));
141 EXPECT_TRUE(base::StringValue(kHostName).Equals(value)); 162 EXPECT_TRUE(base::StringValue(kHostName).Equals(value));
142 163
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 EXPECT_FALSE(store_->GetValue(prefs::kDefaultSearchProviderInstantURL, NULL)); 291 EXPECT_FALSE(store_->GetValue(prefs::kDefaultSearchProviderInstantURL, NULL));
271 EXPECT_FALSE(store_->GetValue(prefs::kDefaultSearchProviderNewTabURL, NULL)); 292 EXPECT_FALSE(store_->GetValue(prefs::kDefaultSearchProviderNewTabURL, NULL));
272 } 293 }
273 294
274 // Checks that if the default search policy is invalid, that no elements of the 295 // Checks that if the default search policy is invalid, that no elements of the
275 // default search policy will be present. 296 // default search policy will be present.
276 TEST_F(DefaultSearchPolicyHandlerTest, Invalid) { 297 TEST_F(DefaultSearchPolicyHandlerTest, Invalid) {
277 PolicyMap policy; 298 PolicyMap policy;
278 BuildDefaultSearchPolicy(&policy); 299 BuildDefaultSearchPolicy(&policy);
279 const char bad_search_url[] = "http://test.com/noSearchTerms"; 300 const char bad_search_url[] = "http://test.com/noSearchTerms";
280 policy.Set(key::kDefaultSearchProviderSearchURL, POLICY_LEVEL_MANDATORY, 301 policy.Set(key::kDefaultSearchProviderSearchURL,
302 POLICY_LEVEL_MANDATORY,
281 POLICY_SCOPE_USER, 303 POLICY_SCOPE_USER,
282 base::Value::CreateStringValue(bad_search_url), NULL); 304 new base::StringValue(bad_search_url),
305 NULL);
283 UpdateProviderPolicy(policy); 306 UpdateProviderPolicy(policy);
284 307
285 EXPECT_FALSE(store_->GetValue(prefs::kDefaultSearchProviderSearchURL, NULL)); 308 EXPECT_FALSE(store_->GetValue(prefs::kDefaultSearchProviderSearchURL, NULL));
286 EXPECT_FALSE(store_->GetValue(prefs::kDefaultSearchProviderName, NULL)); 309 EXPECT_FALSE(store_->GetValue(prefs::kDefaultSearchProviderName, NULL));
287 EXPECT_FALSE(store_->GetValue(prefs::kDefaultSearchProviderKeyword, NULL)); 310 EXPECT_FALSE(store_->GetValue(prefs::kDefaultSearchProviderKeyword, NULL));
288 EXPECT_FALSE(store_->GetValue(prefs::kDefaultSearchProviderSuggestURL, NULL)); 311 EXPECT_FALSE(store_->GetValue(prefs::kDefaultSearchProviderSuggestURL, NULL));
289 EXPECT_FALSE(store_->GetValue(prefs::kDefaultSearchProviderIconURL, NULL)); 312 EXPECT_FALSE(store_->GetValue(prefs::kDefaultSearchProviderIconURL, NULL));
290 EXPECT_FALSE(store_->GetValue(prefs::kDefaultSearchProviderEncodings, NULL)); 313 EXPECT_FALSE(store_->GetValue(prefs::kDefaultSearchProviderEncodings, NULL));
291 EXPECT_FALSE(store_->GetValue(prefs::kDefaultSearchProviderAlternateURLs, 314 EXPECT_FALSE(store_->GetValue(prefs::kDefaultSearchProviderAlternateURLs,
292 NULL)); 315 NULL));
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
407 TEST_F(DefaultSearchPolicyHandlerTest, DictionaryPrefMinimallyDefined) { 430 TEST_F(DefaultSearchPolicyHandlerTest, DictionaryPrefMinimallyDefined) {
408 PolicyMap policy; 431 PolicyMap policy;
409 policy.Set(key::kDefaultSearchProviderEnabled, 432 policy.Set(key::kDefaultSearchProviderEnabled,
410 POLICY_LEVEL_MANDATORY, 433 POLICY_LEVEL_MANDATORY,
411 POLICY_SCOPE_USER, 434 POLICY_SCOPE_USER,
412 new base::FundamentalValue(true), 435 new base::FundamentalValue(true),
413 NULL); 436 NULL);
414 policy.Set(key::kDefaultSearchProviderSearchURL, 437 policy.Set(key::kDefaultSearchProviderSearchURL,
415 POLICY_LEVEL_MANDATORY, 438 POLICY_LEVEL_MANDATORY,
416 POLICY_SCOPE_USER, 439 POLICY_SCOPE_USER,
417 base::Value::CreateStringValue(kSearchURL), 440 new base::StringValue(kSearchURL),
418 NULL); 441 NULL);
419 UpdateProviderPolicy(policy); 442 UpdateProviderPolicy(policy);
420 443
421 const base::Value* temp = NULL; 444 const base::Value* temp = NULL;
422 const base::DictionaryValue* dictionary; 445 const base::DictionaryValue* dictionary;
423 std::string value; 446 std::string value;
424 const base::ListValue* list_value; 447 const base::ListValue* list_value;
425 EXPECT_TRUE(store_->GetValue(kDefaultSearchProviderData, &temp)); 448 EXPECT_TRUE(store_->GetValue(kDefaultSearchProviderData, &temp));
426 temp->GetAsDictionary(&dictionary); 449 temp->GetAsDictionary(&dictionary);
427 450
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
469 TEST_F(DefaultSearchPolicyHandlerTest, DictionaryPrefFileURL) { 492 TEST_F(DefaultSearchPolicyHandlerTest, DictionaryPrefFileURL) {
470 PolicyMap policy; 493 PolicyMap policy;
471 policy.Set(key::kDefaultSearchProviderEnabled, 494 policy.Set(key::kDefaultSearchProviderEnabled,
472 POLICY_LEVEL_MANDATORY, 495 POLICY_LEVEL_MANDATORY,
473 POLICY_SCOPE_USER, 496 POLICY_SCOPE_USER,
474 new base::FundamentalValue(true), 497 new base::FundamentalValue(true),
475 NULL); 498 NULL);
476 policy.Set(key::kDefaultSearchProviderSearchURL, 499 policy.Set(key::kDefaultSearchProviderSearchURL,
477 POLICY_LEVEL_MANDATORY, 500 POLICY_LEVEL_MANDATORY,
478 POLICY_SCOPE_USER, 501 POLICY_SCOPE_USER,
479 base::Value::CreateStringValue(kFileSearchURL), 502 new base::StringValue(kFileSearchURL),
480 NULL); 503 NULL);
481 UpdateProviderPolicy(policy); 504 UpdateProviderPolicy(policy);
482 505
483 const base::Value* temp = NULL; 506 const base::Value* temp = NULL;
484 const base::DictionaryValue* dictionary; 507 const base::DictionaryValue* dictionary;
485 std::string value; 508 std::string value;
486 509
487 EXPECT_TRUE(store_->GetValue(kDefaultSearchProviderData, &temp)); 510 EXPECT_TRUE(store_->GetValue(kDefaultSearchProviderData, &temp));
488 temp->GetAsDictionary(&dictionary); 511 temp->GetAsDictionary(&dictionary);
489 512
490 EXPECT_TRUE(dictionary->GetString(DefaultSearchManager::kURL, &value)); 513 EXPECT_TRUE(dictionary->GetString(DefaultSearchManager::kURL, &value));
491 EXPECT_EQ(kFileSearchURL, value); 514 EXPECT_EQ(kFileSearchURL, value);
492 EXPECT_TRUE(dictionary->GetString(DefaultSearchManager::kShortName, &value)); 515 EXPECT_TRUE(dictionary->GetString(DefaultSearchManager::kShortName, &value));
493 EXPECT_EQ("_", value); 516 EXPECT_EQ("_", value);
494 EXPECT_TRUE(dictionary->GetString(DefaultSearchManager::kKeyword, &value)); 517 EXPECT_TRUE(dictionary->GetString(DefaultSearchManager::kKeyword, &value));
495 EXPECT_EQ("_", value); 518 EXPECT_EQ("_", value);
496 } 519 }
497 } // namespace policy 520 } // namespace policy
OLDNEW
« no previous file with comments | « components/search_engines/default_search_policy_handler.cc ('k') | components/url_matcher/url_matcher_factory_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698