| 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_pref_test_util.h" | 5 #include "components/search_engines/default_search_pref_test_util.h" |
| 6 | 6 |
| 7 #include "base/strings/string_split.h" | 7 #include "base/strings/string_split.h" |
| 8 #include "components/search_engines/default_search_manager.h" | 8 #include "components/search_engines/default_search_manager.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 | 10 |
| 11 // static | 11 // static |
| 12 scoped_ptr<base::DictionaryValue> | 12 scoped_ptr<base::DictionaryValue> |
| 13 DefaultSearchPrefTestUtil::CreateDefaultSearchPreferenceValue( | 13 DefaultSearchPrefTestUtil::CreateDefaultSearchPreferenceValue( |
| 14 bool enabled, | 14 bool enabled, |
| 15 const std::string& name, | 15 const std::string& name, |
| 16 const std::string& keyword, | 16 const std::string& keyword, |
| 17 const std::string& search_url, | 17 const std::string& search_url, |
| 18 const std::string& suggest_url, | 18 const std::string& suggest_url, |
| 19 const std::string& icon_url, | 19 const std::string& icon_url, |
| 20 const std::string& encodings, | 20 const std::string& encodings, |
| 21 const std::string& alternate_url, | 21 const std::string& alternate_url, |
| 22 const std::string& search_terms_replacement_key) { | 22 const std::string& search_terms_replacement_key) { |
| 23 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue); | 23 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue); |
| 24 if (!enabled) { | 24 if (!enabled) { |
| 25 value->SetBoolean(DefaultSearchManager::kDisabledByPolicy, true); | 25 value->SetBoolean(DefaultSearchManager::kDisabledByPolicy, true); |
| 26 return value.Pass(); | 26 return value; |
| 27 } | 27 } |
| 28 | 28 |
| 29 EXPECT_FALSE(keyword.empty()); | 29 EXPECT_FALSE(keyword.empty()); |
| 30 EXPECT_FALSE(search_url.empty()); | 30 EXPECT_FALSE(search_url.empty()); |
| 31 value->Set(DefaultSearchManager::kShortName, | 31 value->Set(DefaultSearchManager::kShortName, |
| 32 new base::StringValue(name)); | 32 new base::StringValue(name)); |
| 33 value->Set(DefaultSearchManager::kKeyword, | 33 value->Set(DefaultSearchManager::kKeyword, |
| 34 new base::StringValue(keyword)); | 34 new base::StringValue(keyword)); |
| 35 value->Set(DefaultSearchManager::kURL, | 35 value->Set(DefaultSearchManager::kURL, |
| 36 new base::StringValue(search_url)); | 36 new base::StringValue(search_url)); |
| 37 value->Set(DefaultSearchManager::kSuggestionsURL, | 37 value->Set(DefaultSearchManager::kSuggestionsURL, |
| 38 new base::StringValue(suggest_url)); | 38 new base::StringValue(suggest_url)); |
| 39 value->Set(DefaultSearchManager::kFaviconURL, | 39 value->Set(DefaultSearchManager::kFaviconURL, |
| 40 new base::StringValue(icon_url)); | 40 new base::StringValue(icon_url)); |
| 41 value->Set(DefaultSearchManager::kSearchTermsReplacementKey, | 41 value->Set(DefaultSearchManager::kSearchTermsReplacementKey, |
| 42 new base::StringValue(search_terms_replacement_key)); | 42 new base::StringValue(search_terms_replacement_key)); |
| 43 | 43 |
| 44 scoped_ptr<base::ListValue> encodings_list(new base::ListValue); | 44 scoped_ptr<base::ListValue> encodings_list(new base::ListValue); |
| 45 for (const std::string& term : base::SplitString( | 45 for (const std::string& term : base::SplitString( |
| 46 encodings, ";", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL)) | 46 encodings, ";", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL)) |
| 47 encodings_list->AppendString(term); | 47 encodings_list->AppendString(term); |
| 48 value->Set(DefaultSearchManager::kInputEncodings, encodings_list.release()); | 48 value->Set(DefaultSearchManager::kInputEncodings, encodings_list.release()); |
| 49 | 49 |
| 50 scoped_ptr<base::ListValue> alternate_url_list(new base::ListValue()); | 50 scoped_ptr<base::ListValue> alternate_url_list(new base::ListValue()); |
| 51 if (!alternate_url.empty()) | 51 if (!alternate_url.empty()) |
| 52 alternate_url_list->Append(new base::StringValue(alternate_url)); | 52 alternate_url_list->Append(new base::StringValue(alternate_url)); |
| 53 value->Set(DefaultSearchManager::kAlternateURLs, | 53 value->Set(DefaultSearchManager::kAlternateURLs, |
| 54 alternate_url_list.release()); | 54 alternate_url_list.release()); |
| 55 return value.Pass(); | 55 return value; |
| 56 } | 56 } |
| OLD | NEW |