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

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

Issue 2541493002: Refactor search_engines tests to better reuse code (Closed)
Patch Set: Fixed after review 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
« no previous file with comments | « components/search_engines/default_search_pref_test_util.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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.
4
5 #include "components/search_engines/default_search_pref_test_util.h"
6
7 #include "base/strings/string_split.h"
8 #include "components/search_engines/default_search_manager.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10
11 // static
12 std::unique_ptr<base::DictionaryValue>
13 DefaultSearchPrefTestUtil::CreateDefaultSearchPreferenceValue(
14 bool enabled,
15 const std::string& name,
16 const std::string& keyword,
17 const std::string& search_url,
18 const std::string& suggest_url,
19 const std::string& icon_url,
20 const std::string& encodings,
21 const std::string& alternate_url,
22 const std::string& search_terms_replacement_key) {
23 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue);
24 if (!enabled) {
25 value->SetBoolean(DefaultSearchManager::kDisabledByPolicy, true);
26 return value;
27 }
28
29 EXPECT_FALSE(keyword.empty());
30 EXPECT_FALSE(search_url.empty());
31 value->Set(DefaultSearchManager::kShortName,
32 new base::StringValue(name));
33 value->Set(DefaultSearchManager::kKeyword,
34 new base::StringValue(keyword));
35 value->Set(DefaultSearchManager::kURL,
36 new base::StringValue(search_url));
37 value->Set(DefaultSearchManager::kSuggestionsURL,
38 new base::StringValue(suggest_url));
39 value->Set(DefaultSearchManager::kFaviconURL,
40 new base::StringValue(icon_url));
41 value->Set(DefaultSearchManager::kSearchTermsReplacementKey,
42 new base::StringValue(search_terms_replacement_key));
43
44 std::unique_ptr<base::ListValue> encodings_list(new base::ListValue);
45 for (const std::string& term : base::SplitString(
46 encodings, ";", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL))
47 encodings_list->AppendString(term);
48 value->Set(DefaultSearchManager::kInputEncodings, encodings_list.release());
49
50 std::unique_ptr<base::ListValue> alternate_url_list(new base::ListValue());
51 if (!alternate_url.empty())
52 alternate_url_list->AppendString(alternate_url);
53 value->Set(DefaultSearchManager::kAlternateURLs,
54 alternate_url_list.release());
55 return value;
56 }
OLDNEW
« no previous file with comments | « components/search_engines/default_search_pref_test_util.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698