OLD | NEW |
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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 "file:///c:/path/to/search?t={searchTerms}"; | 74 "file:///c:/path/to/search?t={searchTerms}"; |
75 const char DefaultSearchPolicyHandlerTest::kHostName[] = "test.com"; | 75 const char DefaultSearchPolicyHandlerTest::kHostName[] = "test.com"; |
76 | 76 |
77 void DefaultSearchPolicyHandlerTest:: | 77 void DefaultSearchPolicyHandlerTest:: |
78 BuildDefaultSearchPolicy(PolicyMap* policy) { | 78 BuildDefaultSearchPolicy(PolicyMap* policy) { |
79 base::ListValue* encodings = new base::ListValue(); | 79 base::ListValue* encodings = new base::ListValue(); |
80 encodings->AppendString("UTF-16"); | 80 encodings->AppendString("UTF-16"); |
81 encodings->AppendString("UTF-8"); | 81 encodings->AppendString("UTF-8"); |
82 policy->Set(key::kDefaultSearchProviderEnabled, POLICY_LEVEL_MANDATORY, | 82 policy->Set(key::kDefaultSearchProviderEnabled, POLICY_LEVEL_MANDATORY, |
83 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, | 83 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
84 base::MakeUnique<base::FundamentalValue>(true), nullptr); | 84 base::MakeUnique<base::Value>(true), nullptr); |
85 policy->Set(key::kDefaultSearchProviderSearchURL, POLICY_LEVEL_MANDATORY, | 85 policy->Set(key::kDefaultSearchProviderSearchURL, POLICY_LEVEL_MANDATORY, |
86 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, | 86 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
87 base::MakeUnique<base::StringValue>(kSearchURL), nullptr); | 87 base::MakeUnique<base::StringValue>(kSearchURL), nullptr); |
88 policy->Set(key::kDefaultSearchProviderName, POLICY_LEVEL_MANDATORY, | 88 policy->Set(key::kDefaultSearchProviderName, POLICY_LEVEL_MANDATORY, |
89 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, | 89 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
90 base::MakeUnique<base::StringValue>(kName), nullptr); | 90 base::MakeUnique<base::StringValue>(kName), nullptr); |
91 policy->Set(key::kDefaultSearchProviderKeyword, POLICY_LEVEL_MANDATORY, | 91 policy->Set(key::kDefaultSearchProviderKeyword, POLICY_LEVEL_MANDATORY, |
92 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, | 92 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
93 base::MakeUnique<base::StringValue>(kKeyword), nullptr); | 93 base::MakeUnique<base::StringValue>(kKeyword), nullptr); |
94 policy->Set(key::kDefaultSearchProviderSuggestURL, POLICY_LEVEL_MANDATORY, | 94 policy->Set(key::kDefaultSearchProviderSuggestURL, POLICY_LEVEL_MANDATORY, |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 &value)); | 256 &value)); |
257 EXPECT_EQ(std::string(), value); | 257 EXPECT_EQ(std::string(), value); |
258 } | 258 } |
259 | 259 |
260 // Checks that disabling default search is properly reflected the dictionary | 260 // Checks that disabling default search is properly reflected the dictionary |
261 // pref. | 261 // pref. |
262 TEST_F(DefaultSearchPolicyHandlerTest, Disabled) { | 262 TEST_F(DefaultSearchPolicyHandlerTest, Disabled) { |
263 PolicyMap policy; | 263 PolicyMap policy; |
264 policy.Set(key::kDefaultSearchProviderEnabled, POLICY_LEVEL_MANDATORY, | 264 policy.Set(key::kDefaultSearchProviderEnabled, POLICY_LEVEL_MANDATORY, |
265 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, | 265 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
266 base::WrapUnique(new base::FundamentalValue(false)), nullptr); | 266 base::WrapUnique(new base::Value(false)), nullptr); |
267 UpdateProviderPolicy(policy); | 267 UpdateProviderPolicy(policy); |
268 const base::Value* temp = NULL; | 268 const base::Value* temp = NULL; |
269 const base::DictionaryValue* dictionary; | 269 const base::DictionaryValue* dictionary; |
270 EXPECT_TRUE(store_->GetValue( | 270 EXPECT_TRUE(store_->GetValue( |
271 DefaultSearchManager::kDefaultSearchProviderDataPrefName, &temp)); | 271 DefaultSearchManager::kDefaultSearchProviderDataPrefName, &temp)); |
272 temp->GetAsDictionary(&dictionary); | 272 temp->GetAsDictionary(&dictionary); |
273 bool disabled = false; | 273 bool disabled = false; |
274 EXPECT_TRUE(dictionary->GetBoolean(DefaultSearchManager::kDisabledByPolicy, | 274 EXPECT_TRUE(dictionary->GetBoolean(DefaultSearchManager::kDisabledByPolicy, |
275 &disabled)); | 275 &disabled)); |
276 EXPECT_TRUE(disabled); | 276 EXPECT_TRUE(disabled); |
277 } | 277 } |
278 | 278 |
279 // Checks that if the policy for default search is valid, i.e. there's a | 279 // Checks that if the policy for default search is valid, i.e. there's a |
280 // search URL, that all the elements have been given proper defaults. | 280 // search URL, that all the elements have been given proper defaults. |
281 TEST_F(DefaultSearchPolicyHandlerTest, MinimallyDefined) { | 281 TEST_F(DefaultSearchPolicyHandlerTest, MinimallyDefined) { |
282 PolicyMap policy; | 282 PolicyMap policy; |
283 policy.Set(key::kDefaultSearchProviderEnabled, POLICY_LEVEL_MANDATORY, | 283 policy.Set(key::kDefaultSearchProviderEnabled, POLICY_LEVEL_MANDATORY, |
284 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, | 284 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
285 base::WrapUnique(new base::FundamentalValue(true)), nullptr); | 285 base::WrapUnique(new base::Value(true)), nullptr); |
286 policy.Set(key::kDefaultSearchProviderSearchURL, POLICY_LEVEL_MANDATORY, | 286 policy.Set(key::kDefaultSearchProviderSearchURL, POLICY_LEVEL_MANDATORY, |
287 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, | 287 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
288 base::WrapUnique(new base::StringValue(kSearchURL)), nullptr); | 288 base::WrapUnique(new base::StringValue(kSearchURL)), nullptr); |
289 UpdateProviderPolicy(policy); | 289 UpdateProviderPolicy(policy); |
290 | 290 |
291 const base::Value* temp = NULL; | 291 const base::Value* temp = NULL; |
292 const base::DictionaryValue* dictionary; | 292 const base::DictionaryValue* dictionary; |
293 std::string value; | 293 std::string value; |
294 const base::ListValue* list_value; | 294 const base::ListValue* list_value; |
295 EXPECT_TRUE(store_->GetValue( | 295 EXPECT_TRUE(store_->GetValue( |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
334 &value)); | 334 &value)); |
335 EXPECT_EQ(std::string(), value); | 335 EXPECT_EQ(std::string(), value); |
336 } | 336 } |
337 | 337 |
338 // Checks that setting a file URL as the default search is reflected properly in | 338 // Checks that setting a file URL as the default search is reflected properly in |
339 // the dictionary pref. | 339 // the dictionary pref. |
340 TEST_F(DefaultSearchPolicyHandlerTest, FileURL) { | 340 TEST_F(DefaultSearchPolicyHandlerTest, FileURL) { |
341 PolicyMap policy; | 341 PolicyMap policy; |
342 policy.Set(key::kDefaultSearchProviderEnabled, POLICY_LEVEL_MANDATORY, | 342 policy.Set(key::kDefaultSearchProviderEnabled, POLICY_LEVEL_MANDATORY, |
343 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, | 343 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
344 base::WrapUnique(new base::FundamentalValue(true)), nullptr); | 344 base::WrapUnique(new base::Value(true)), nullptr); |
345 policy.Set(key::kDefaultSearchProviderSearchURL, POLICY_LEVEL_MANDATORY, | 345 policy.Set(key::kDefaultSearchProviderSearchURL, POLICY_LEVEL_MANDATORY, |
346 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, | 346 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
347 base::WrapUnique(new base::StringValue(kFileSearchURL)), nullptr); | 347 base::WrapUnique(new base::StringValue(kFileSearchURL)), nullptr); |
348 UpdateProviderPolicy(policy); | 348 UpdateProviderPolicy(policy); |
349 | 349 |
350 const base::Value* temp = NULL; | 350 const base::Value* temp = NULL; |
351 const base::DictionaryValue* dictionary; | 351 const base::DictionaryValue* dictionary; |
352 std::string value; | 352 std::string value; |
353 | 353 |
354 EXPECT_TRUE(store_->GetValue( | 354 EXPECT_TRUE(store_->GetValue( |
355 DefaultSearchManager::kDefaultSearchProviderDataPrefName, &temp)); | 355 DefaultSearchManager::kDefaultSearchProviderDataPrefName, &temp)); |
356 temp->GetAsDictionary(&dictionary); | 356 temp->GetAsDictionary(&dictionary); |
357 | 357 |
358 EXPECT_TRUE(dictionary->GetString(DefaultSearchManager::kURL, &value)); | 358 EXPECT_TRUE(dictionary->GetString(DefaultSearchManager::kURL, &value)); |
359 EXPECT_EQ(kFileSearchURL, value); | 359 EXPECT_EQ(kFileSearchURL, value); |
360 EXPECT_TRUE(dictionary->GetString(DefaultSearchManager::kShortName, &value)); | 360 EXPECT_TRUE(dictionary->GetString(DefaultSearchManager::kShortName, &value)); |
361 EXPECT_EQ("_", value); | 361 EXPECT_EQ("_", value); |
362 EXPECT_TRUE(dictionary->GetString(DefaultSearchManager::kKeyword, &value)); | 362 EXPECT_TRUE(dictionary->GetString(DefaultSearchManager::kKeyword, &value)); |
363 EXPECT_EQ("_", value); | 363 EXPECT_EQ("_", value); |
364 } | 364 } |
365 | 365 |
366 } // namespace policy | 366 } // namespace policy |
OLD | NEW |