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

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

Issue 2479113002: Make extensions DSE persistent in browser prefs (Closed)
Patch Set: Added DSE tests 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
(Empty)
1 // Copyright 2016 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/search_engines_test_util.h"
6
7 #include "base/macros.h"
8 #include "base/memory/ptr_util.h"
9 #include "base/strings/string_split.h"
10 #include "base/strings/utf_string_conversions.h"
11 #include "components/policy/core/common/policy_types.h"
12 #include "components/policy/policy_constants.h"
13 #include "components/search_engines/template_url.h"
14 #include "components/search_engines/template_url_data.h"
15 #include "testing/gtest/include/gtest/gtest.h"
16
17 // Generate TemplateUrlData structure useful for tests filled with values
18 // autogenerated from type param.
vasilii 2016/11/30 14:00:03 No need to copy/paste the comment.
Alexander Yashkin 2016/12/05 18:16:48 Deleted
19 std::unique_ptr<TemplateURLData> GenerateDummyTemplateURLData(
20 const std::string& type) {
21 std::unique_ptr<TemplateURLData> data(new TemplateURLData());
22 data->SetShortName(base::UTF8ToUTF16(std::string(type).append("name")));
vasilii 2016/11/30 14:00:03 type + "name"? Here and below.
Alexander Yashkin 2016/12/05 18:16:48 I was sure append was preferrable in code style. C
vasilii 2016/12/06 19:16:42 It's the same performance but better readabilty.
Peter Kasting 2016/12/06 19:23:11 There's no official preference. Unofficially, I n
23 data->SetKeyword(base::UTF8ToUTF16(std::string(type).append("key")));
24 data->SetURL(std::string("http://").append(type).append("foo/{searchTerms}"));
25 data->suggestions_url = std::string("http://").append(type).append("sugg");
26 data->alternate_urls.push_back(
27 std::string("http://").append(type).append("foo/alt"));
28 data->favicon_url = GURL("http://icon1");
29 data->safe_for_autoreplace = true;
30 data->input_encodings = base::SplitString(
31 "UTF-8;UTF-16", ";", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
32 data->date_created = base::Time();
33 data->last_modified = base::Time();
34 return data;
35 }
36
37 // Checks that the two TemplateURLs are similar. Does not check the id, the
38 // date_created or the last_modified time. Neither pointer should be NULL.
39 void ExpectSimilar(const TemplateURLData* expected,
40 const TemplateURLData* actual) {
41 ASSERT_TRUE(expected != NULL);
42 ASSERT_TRUE(actual != NULL);
vasilii 2016/11/30 14:00:03 Would it be easier to take const TemplateURLData&
Alexander Yashkin 2016/12/05 18:16:48 That would mean to delete ASSERT_TRUE on input poi
vasilii 2016/12/06 19:16:42 I see that you copied an existing function. Then i
43
44 EXPECT_EQ(expected->short_name(), actual->short_name());
45 EXPECT_EQ(expected->keyword(), actual->keyword());
46 EXPECT_EQ(expected->url(), actual->url());
47 EXPECT_EQ(expected->suggestions_url, actual->suggestions_url);
48 EXPECT_EQ(expected->instant_url, actual->instant_url);
49 EXPECT_EQ(expected->image_url, actual->image_url);
50 EXPECT_EQ(expected->new_tab_url, actual->new_tab_url);
51 EXPECT_EQ(expected->contextual_search_url, actual->contextual_search_url);
52
53 EXPECT_EQ(expected->search_url_post_params, actual->search_url_post_params);
54 EXPECT_EQ(expected->suggestions_url_post_params,
55 actual->suggestions_url_post_params);
56 EXPECT_EQ(expected->instant_url_post_params, actual->instant_url_post_params);
57 EXPECT_EQ(expected->image_url_post_params, actual->image_url_post_params);
58
59 EXPECT_EQ(expected->favicon_url, actual->favicon_url);
60 EXPECT_EQ(expected->safe_for_autoreplace, actual->safe_for_autoreplace);
61 EXPECT_EQ(expected->input_encodings, actual->input_encodings);
62 EXPECT_EQ(expected->alternate_urls, actual->alternate_urls);
63 EXPECT_TRUE(TemplateURL::SearchTermsReplacementKeysMatch(
64 expected->search_terms_replacement_key,
65 actual->search_terms_replacement_key));
66 }
67
68 using namespace policy;
vasilii 2016/11/30 14:00:03 The style guide doesn't allow "using namespace". "
Alexander Yashkin 2016/12/05 18:16:48 Removed this function, its not used after I switch
69
70 void BuildDefaultSearchPolicy(const TemplateURLData& data, PolicyMap* policy) {
71 auto alternate_urls = base::MakeUnique<base::ListValue>();
72 for (const auto& alternate_url : data.alternate_urls)
73 alternate_urls->AppendString(alternate_url);
74 auto encodings = base::MakeUnique<base::ListValue>();
75 for (const auto& input_encoding : data.input_encodings)
76 encodings->AppendString(input_encoding);
77
78 policy->Set(key::kDefaultSearchProviderEnabled, POLICY_LEVEL_MANDATORY,
79 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
80 base::MakeUnique<base::FundamentalValue>(true), nullptr);
81 policy->Set(key::kDefaultSearchProviderSearchURL, POLICY_LEVEL_MANDATORY,
82 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
83 base::MakeUnique<base::StringValue>(data.url()), nullptr);
84 policy->Set(key::kDefaultSearchProviderName, POLICY_LEVEL_MANDATORY,
85 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
86 base::MakeUnique<base::StringValue>(data.short_name()), nullptr);
87 policy->Set(key::kDefaultSearchProviderKeyword, POLICY_LEVEL_MANDATORY,
88 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
89 base::MakeUnique<base::StringValue>(data.keyword()), nullptr);
90 policy->Set(key::kDefaultSearchProviderSuggestURL, POLICY_LEVEL_MANDATORY,
91 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
92 base::MakeUnique<base::StringValue>(data.suggestions_url),
93 nullptr);
94 policy->Set(key::kDefaultSearchProviderIconURL, POLICY_LEVEL_MANDATORY,
95 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
96 base::MakeUnique<base::StringValue>(data.favicon_url.spec()),
97 nullptr);
98 policy->Set(key::kDefaultSearchProviderEncodings, POLICY_LEVEL_MANDATORY,
99 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, std::move(encodings),
100 nullptr);
101 policy->Set(key::kDefaultSearchProviderAlternateURLs, POLICY_LEVEL_MANDATORY,
102 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, std::move(alternate_urls),
103 nullptr);
104 policy->Set(
105 key::kDefaultSearchProviderSearchTermsReplacementKey,
106 POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
107 base::MakeUnique<base::StringValue>(data.search_terms_replacement_key),
108 nullptr);
109 policy->Set(key::kDefaultSearchProviderImageURL, POLICY_LEVEL_MANDATORY,
110 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
111 base::MakeUnique<base::StringValue>(data.image_url), nullptr);
112 policy->Set(key::kDefaultSearchProviderImageURLPostParams,
113 POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
114 base::MakeUnique<base::StringValue>(data.image_url_post_params),
115 nullptr);
116 policy->Set(key::kDefaultSearchProviderNewTabURL, POLICY_LEVEL_MANDATORY,
117 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
118 base::MakeUnique<base::StringValue>(data.new_tab_url), nullptr);
119 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698