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

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

Issue 2497853002: Create TemplateUrlData to base::Dictionary utility functions (Closed)
Patch Set: Fixed android compilation Created 4 years 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"
11 #include "components/policy/core/browser/configuration_policy_pref_store_test.h" 11 #include "components/policy/core/browser/configuration_policy_pref_store_test.h"
12 #include "components/policy/core/common/policy_types.h" 12 #include "components/policy/core/common/policy_types.h"
13 #include "components/policy/policy_constants.h" 13 #include "components/policy/policy_constants.h"
14 #include "components/search_engines/default_search_manager.h" 14 #include "components/search_engines/default_search_manager.h"
15 #include "components/search_engines/search_engines_pref_names.h" 15 #include "components/search_engines/search_engines_pref_names.h"
16 16
17 namespace {
18 // TODO(caitkp): Should we find a way to route this through DefaultSearchManager
19 // to avoid hardcoding this here?
20 const char kDefaultSearchProviderData[] =
21 "default_search_provider_data.template_url_data";
22 } // namespace
23
24 namespace policy { 17 namespace policy {
25 18
26 class DefaultSearchPolicyHandlerTest 19 class DefaultSearchPolicyHandlerTest
27 : public ConfigurationPolicyPrefStoreTest { 20 : public ConfigurationPolicyPrefStoreTest {
28 public: 21 public:
29 DefaultSearchPolicyHandlerTest() { 22 DefaultSearchPolicyHandlerTest() {
30 default_alternate_urls_.AppendString( 23 default_alternate_urls_.AppendString(
31 "http://www.google.com/#q={searchTerms}"); 24 "http://www.google.com/#q={searchTerms}");
32 default_alternate_urls_.AppendString( 25 default_alternate_urls_.AppendString(
33 "http://www.google.com/search#q={searchTerms}"); 26 "http://www.google.com/search#q={searchTerms}");
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 119
127 // Checks that if the default search policy is missing, that no elements of the 120 // Checks that if the default search policy is missing, that no elements of the
128 // default search policy will be present. 121 // default search policy will be present.
129 TEST_F(DefaultSearchPolicyHandlerTest, MissingUrl) { 122 TEST_F(DefaultSearchPolicyHandlerTest, MissingUrl) {
130 PolicyMap policy; 123 PolicyMap policy;
131 BuildDefaultSearchPolicy(&policy); 124 BuildDefaultSearchPolicy(&policy);
132 policy.Erase(key::kDefaultSearchProviderSearchURL); 125 policy.Erase(key::kDefaultSearchProviderSearchURL);
133 UpdateProviderPolicy(policy); 126 UpdateProviderPolicy(policy);
134 127
135 const base::Value* temp = nullptr; 128 const base::Value* temp = nullptr;
136 EXPECT_FALSE(store_->GetValue(kDefaultSearchProviderData, &temp)); 129 EXPECT_FALSE(store_->GetValue(
130 DefaultSearchManager::kDefaultSearchProviderDataPrefName, &temp));
137 } 131 }
138 132
139 // Checks that if the default search policy is invalid, that no elements of the 133 // Checks that if the default search policy is invalid, that no elements of the
140 // default search policy will be present. 134 // default search policy will be present.
141 TEST_F(DefaultSearchPolicyHandlerTest, Invalid) { 135 TEST_F(DefaultSearchPolicyHandlerTest, Invalid) {
142 PolicyMap policy; 136 PolicyMap policy;
143 BuildDefaultSearchPolicy(&policy); 137 BuildDefaultSearchPolicy(&policy);
144 const char bad_search_url[] = "http://test.com/noSearchTerms"; 138 const char bad_search_url[] = "http://test.com/noSearchTerms";
145 policy.Set(key::kDefaultSearchProviderSearchURL, POLICY_LEVEL_MANDATORY, 139 policy.Set(key::kDefaultSearchProviderSearchURL, POLICY_LEVEL_MANDATORY,
146 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, 140 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
147 base::WrapUnique(new base::StringValue(bad_search_url)), nullptr); 141 base::WrapUnique(new base::StringValue(bad_search_url)), nullptr);
148 UpdateProviderPolicy(policy); 142 UpdateProviderPolicy(policy);
149 143
150 const base::Value* temp = nullptr; 144 const base::Value* temp = nullptr;
151 EXPECT_FALSE(store_->GetValue(kDefaultSearchProviderData, &temp)); 145 EXPECT_FALSE(store_->GetValue(
146 DefaultSearchManager::kDefaultSearchProviderDataPrefName, &temp));
152 } 147 }
153 148
154 // Checks that for a fully defined search policy, all elements have been 149 // Checks that for a fully defined search policy, all elements have been
155 // read properly into the dictionary pref. 150 // read properly into the dictionary pref.
156 TEST_F(DefaultSearchPolicyHandlerTest, FullyDefined) { 151 TEST_F(DefaultSearchPolicyHandlerTest, FullyDefined) {
157 PolicyMap policy; 152 PolicyMap policy;
158 BuildDefaultSearchPolicy(&policy); 153 BuildDefaultSearchPolicy(&policy);
159 UpdateProviderPolicy(policy); 154 UpdateProviderPolicy(policy);
160 155
161 const base::Value* temp = NULL; 156 const base::Value* temp = NULL;
162 const base::DictionaryValue* dictionary; 157 const base::DictionaryValue* dictionary;
163 std::string value; 158 std::string value;
164 const base::ListValue* list_value; 159 const base::ListValue* list_value;
165 EXPECT_TRUE(store_->GetValue(kDefaultSearchProviderData, &temp)); 160 EXPECT_TRUE(store_->GetValue(
161 DefaultSearchManager::kDefaultSearchProviderDataPrefName, &temp));
166 temp->GetAsDictionary(&dictionary); 162 temp->GetAsDictionary(&dictionary);
167 163
168 EXPECT_TRUE(dictionary->GetString(DefaultSearchManager::kURL, &value)); 164 EXPECT_TRUE(dictionary->GetString(DefaultSearchManager::kURL, &value));
169 EXPECT_EQ(kSearchURL, value); 165 EXPECT_EQ(kSearchURL, value);
170 EXPECT_TRUE(dictionary->GetString(DefaultSearchManager::kShortName, &value)); 166 EXPECT_TRUE(dictionary->GetString(DefaultSearchManager::kShortName, &value));
171 EXPECT_EQ(kName, value); 167 EXPECT_EQ(kName, value);
172 EXPECT_TRUE(dictionary->GetString(DefaultSearchManager::kKeyword, &value)); 168 EXPECT_TRUE(dictionary->GetString(DefaultSearchManager::kKeyword, &value));
173 EXPECT_EQ(kKeyword, value); 169 EXPECT_EQ(kKeyword, value);
174 170
175 EXPECT_TRUE( 171 EXPECT_TRUE(
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 // Checks that disabling default search is properly reflected the dictionary 213 // Checks that disabling default search is properly reflected the dictionary
218 // pref. 214 // pref.
219 TEST_F(DefaultSearchPolicyHandlerTest, Disabled) { 215 TEST_F(DefaultSearchPolicyHandlerTest, Disabled) {
220 PolicyMap policy; 216 PolicyMap policy;
221 policy.Set(key::kDefaultSearchProviderEnabled, POLICY_LEVEL_MANDATORY, 217 policy.Set(key::kDefaultSearchProviderEnabled, POLICY_LEVEL_MANDATORY,
222 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, 218 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
223 base::WrapUnique(new base::FundamentalValue(false)), nullptr); 219 base::WrapUnique(new base::FundamentalValue(false)), nullptr);
224 UpdateProviderPolicy(policy); 220 UpdateProviderPolicy(policy);
225 const base::Value* temp = NULL; 221 const base::Value* temp = NULL;
226 const base::DictionaryValue* dictionary; 222 const base::DictionaryValue* dictionary;
227 EXPECT_TRUE(store_->GetValue(kDefaultSearchProviderData, &temp)); 223 EXPECT_TRUE(store_->GetValue(
224 DefaultSearchManager::kDefaultSearchProviderDataPrefName, &temp));
228 temp->GetAsDictionary(&dictionary); 225 temp->GetAsDictionary(&dictionary);
229 bool disabled = false; 226 bool disabled = false;
230 EXPECT_TRUE(dictionary->GetBoolean(DefaultSearchManager::kDisabledByPolicy, 227 EXPECT_TRUE(dictionary->GetBoolean(DefaultSearchManager::kDisabledByPolicy,
231 &disabled)); 228 &disabled));
232 EXPECT_TRUE(disabled); 229 EXPECT_TRUE(disabled);
233 } 230 }
234 231
235 // Checks that if the policy for default search is valid, i.e. there's a 232 // Checks that if the policy for default search is valid, i.e. there's a
236 // search URL, that all the elements have been given proper defaults. 233 // search URL, that all the elements have been given proper defaults.
237 TEST_F(DefaultSearchPolicyHandlerTest, MinimallyDefined) { 234 TEST_F(DefaultSearchPolicyHandlerTest, MinimallyDefined) {
238 PolicyMap policy; 235 PolicyMap policy;
239 policy.Set(key::kDefaultSearchProviderEnabled, POLICY_LEVEL_MANDATORY, 236 policy.Set(key::kDefaultSearchProviderEnabled, POLICY_LEVEL_MANDATORY,
240 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, 237 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
241 base::WrapUnique(new base::FundamentalValue(true)), nullptr); 238 base::WrapUnique(new base::FundamentalValue(true)), nullptr);
242 policy.Set(key::kDefaultSearchProviderSearchURL, POLICY_LEVEL_MANDATORY, 239 policy.Set(key::kDefaultSearchProviderSearchURL, POLICY_LEVEL_MANDATORY,
243 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, 240 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
244 base::WrapUnique(new base::StringValue(kSearchURL)), nullptr); 241 base::WrapUnique(new base::StringValue(kSearchURL)), nullptr);
245 UpdateProviderPolicy(policy); 242 UpdateProviderPolicy(policy);
246 243
247 const base::Value* temp = NULL; 244 const base::Value* temp = NULL;
248 const base::DictionaryValue* dictionary; 245 const base::DictionaryValue* dictionary;
249 std::string value; 246 std::string value;
250 const base::ListValue* list_value; 247 const base::ListValue* list_value;
251 EXPECT_TRUE(store_->GetValue(kDefaultSearchProviderData, &temp)); 248 EXPECT_TRUE(store_->GetValue(
249 DefaultSearchManager::kDefaultSearchProviderDataPrefName, &temp));
252 temp->GetAsDictionary(&dictionary); 250 temp->GetAsDictionary(&dictionary);
253 251
254 // Name and keyword should be derived from host. 252 // Name and keyword should be derived from host.
255 EXPECT_TRUE(dictionary->GetString(DefaultSearchManager::kURL, &value)); 253 EXPECT_TRUE(dictionary->GetString(DefaultSearchManager::kURL, &value));
256 EXPECT_EQ(kSearchURL, value); 254 EXPECT_EQ(kSearchURL, value);
257 EXPECT_TRUE(dictionary->GetString(DefaultSearchManager::kShortName, &value)); 255 EXPECT_TRUE(dictionary->GetString(DefaultSearchManager::kShortName, &value));
258 EXPECT_EQ(kHostName, value); 256 EXPECT_EQ(kHostName, value);
259 EXPECT_TRUE(dictionary->GetString(DefaultSearchManager::kKeyword, &value)); 257 EXPECT_TRUE(dictionary->GetString(DefaultSearchManager::kKeyword, &value));
260 EXPECT_EQ(kHostName, value); 258 EXPECT_EQ(kHostName, value);
261 259
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 base::WrapUnique(new base::FundamentalValue(true)), nullptr); 297 base::WrapUnique(new base::FundamentalValue(true)), nullptr);
300 policy.Set(key::kDefaultSearchProviderSearchURL, POLICY_LEVEL_MANDATORY, 298 policy.Set(key::kDefaultSearchProviderSearchURL, POLICY_LEVEL_MANDATORY,
301 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, 299 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
302 base::WrapUnique(new base::StringValue(kFileSearchURL)), nullptr); 300 base::WrapUnique(new base::StringValue(kFileSearchURL)), nullptr);
303 UpdateProviderPolicy(policy); 301 UpdateProviderPolicy(policy);
304 302
305 const base::Value* temp = NULL; 303 const base::Value* temp = NULL;
306 const base::DictionaryValue* dictionary; 304 const base::DictionaryValue* dictionary;
307 std::string value; 305 std::string value;
308 306
309 EXPECT_TRUE(store_->GetValue(kDefaultSearchProviderData, &temp)); 307 EXPECT_TRUE(store_->GetValue(
308 DefaultSearchManager::kDefaultSearchProviderDataPrefName, &temp));
310 temp->GetAsDictionary(&dictionary); 309 temp->GetAsDictionary(&dictionary);
311 310
312 EXPECT_TRUE(dictionary->GetString(DefaultSearchManager::kURL, &value)); 311 EXPECT_TRUE(dictionary->GetString(DefaultSearchManager::kURL, &value));
313 EXPECT_EQ(kFileSearchURL, value); 312 EXPECT_EQ(kFileSearchURL, value);
314 EXPECT_TRUE(dictionary->GetString(DefaultSearchManager::kShortName, &value)); 313 EXPECT_TRUE(dictionary->GetString(DefaultSearchManager::kShortName, &value));
315 EXPECT_EQ("_", value); 314 EXPECT_EQ("_", value);
316 EXPECT_TRUE(dictionary->GetString(DefaultSearchManager::kKeyword, &value)); 315 EXPECT_TRUE(dictionary->GetString(DefaultSearchManager::kKeyword, &value));
317 EXPECT_EQ("_", value); 316 EXPECT_EQ("_", value);
318 } 317 }
319 } // namespace policy 318 } // namespace policy
OLDNEW
« no previous file with comments | « components/search_engines/default_search_manager_unittest.cc ('k') | components/search_engines/template_url_data.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698