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

Unified 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, 1 month 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 side-by-side diff with in-line comments
Download patch
Index: components/search_engines/search_engines_test_util.cc
diff --git a/components/search_engines/search_engines_test_util.cc b/components/search_engines/search_engines_test_util.cc
new file mode 100644
index 0000000000000000000000000000000000000000..cb6cbc6b2a15d233a5331a718b39ca603c14c813
--- /dev/null
+++ b/components/search_engines/search_engines_test_util.cc
@@ -0,0 +1,119 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "components/search_engines/search_engines_test_util.h"
+
+#include "base/macros.h"
+#include "base/memory/ptr_util.h"
+#include "base/strings/string_split.h"
+#include "base/strings/utf_string_conversions.h"
+#include "components/policy/core/common/policy_types.h"
+#include "components/policy/policy_constants.h"
+#include "components/search_engines/template_url.h"
+#include "components/search_engines/template_url_data.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+// Generate TemplateUrlData structure useful for tests filled with values
+// 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
+std::unique_ptr<TemplateURLData> GenerateDummyTemplateURLData(
+ const std::string& type) {
+ std::unique_ptr<TemplateURLData> data(new TemplateURLData());
+ 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
+ data->SetKeyword(base::UTF8ToUTF16(std::string(type).append("key")));
+ data->SetURL(std::string("http://").append(type).append("foo/{searchTerms}"));
+ data->suggestions_url = std::string("http://").append(type).append("sugg");
+ data->alternate_urls.push_back(
+ std::string("http://").append(type).append("foo/alt"));
+ data->favicon_url = GURL("http://icon1");
+ data->safe_for_autoreplace = true;
+ data->input_encodings = base::SplitString(
+ "UTF-8;UTF-16", ";", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
+ data->date_created = base::Time();
+ data->last_modified = base::Time();
+ return data;
+}
+
+// Checks that the two TemplateURLs are similar. Does not check the id, the
+// date_created or the last_modified time. Neither pointer should be NULL.
+void ExpectSimilar(const TemplateURLData* expected,
+ const TemplateURLData* actual) {
+ ASSERT_TRUE(expected != NULL);
+ 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
+
+ EXPECT_EQ(expected->short_name(), actual->short_name());
+ EXPECT_EQ(expected->keyword(), actual->keyword());
+ EXPECT_EQ(expected->url(), actual->url());
+ EXPECT_EQ(expected->suggestions_url, actual->suggestions_url);
+ EXPECT_EQ(expected->instant_url, actual->instant_url);
+ EXPECT_EQ(expected->image_url, actual->image_url);
+ EXPECT_EQ(expected->new_tab_url, actual->new_tab_url);
+ EXPECT_EQ(expected->contextual_search_url, actual->contextual_search_url);
+
+ EXPECT_EQ(expected->search_url_post_params, actual->search_url_post_params);
+ EXPECT_EQ(expected->suggestions_url_post_params,
+ actual->suggestions_url_post_params);
+ EXPECT_EQ(expected->instant_url_post_params, actual->instant_url_post_params);
+ EXPECT_EQ(expected->image_url_post_params, actual->image_url_post_params);
+
+ EXPECT_EQ(expected->favicon_url, actual->favicon_url);
+ EXPECT_EQ(expected->safe_for_autoreplace, actual->safe_for_autoreplace);
+ EXPECT_EQ(expected->input_encodings, actual->input_encodings);
+ EXPECT_EQ(expected->alternate_urls, actual->alternate_urls);
+ EXPECT_TRUE(TemplateURL::SearchTermsReplacementKeysMatch(
+ expected->search_terms_replacement_key,
+ actual->search_terms_replacement_key));
+}
+
+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
+
+void BuildDefaultSearchPolicy(const TemplateURLData& data, PolicyMap* policy) {
+ auto alternate_urls = base::MakeUnique<base::ListValue>();
+ for (const auto& alternate_url : data.alternate_urls)
+ alternate_urls->AppendString(alternate_url);
+ auto encodings = base::MakeUnique<base::ListValue>();
+ for (const auto& input_encoding : data.input_encodings)
+ encodings->AppendString(input_encoding);
+
+ policy->Set(key::kDefaultSearchProviderEnabled, POLICY_LEVEL_MANDATORY,
+ POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
+ base::MakeUnique<base::FundamentalValue>(true), nullptr);
+ policy->Set(key::kDefaultSearchProviderSearchURL, POLICY_LEVEL_MANDATORY,
+ POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
+ base::MakeUnique<base::StringValue>(data.url()), nullptr);
+ policy->Set(key::kDefaultSearchProviderName, POLICY_LEVEL_MANDATORY,
+ POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
+ base::MakeUnique<base::StringValue>(data.short_name()), nullptr);
+ policy->Set(key::kDefaultSearchProviderKeyword, POLICY_LEVEL_MANDATORY,
+ POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
+ base::MakeUnique<base::StringValue>(data.keyword()), nullptr);
+ policy->Set(key::kDefaultSearchProviderSuggestURL, POLICY_LEVEL_MANDATORY,
+ POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
+ base::MakeUnique<base::StringValue>(data.suggestions_url),
+ nullptr);
+ policy->Set(key::kDefaultSearchProviderIconURL, POLICY_LEVEL_MANDATORY,
+ POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
+ base::MakeUnique<base::StringValue>(data.favicon_url.spec()),
+ nullptr);
+ policy->Set(key::kDefaultSearchProviderEncodings, POLICY_LEVEL_MANDATORY,
+ POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, std::move(encodings),
+ nullptr);
+ policy->Set(key::kDefaultSearchProviderAlternateURLs, POLICY_LEVEL_MANDATORY,
+ POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, std::move(alternate_urls),
+ nullptr);
+ policy->Set(
+ key::kDefaultSearchProviderSearchTermsReplacementKey,
+ POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
+ base::MakeUnique<base::StringValue>(data.search_terms_replacement_key),
+ nullptr);
+ policy->Set(key::kDefaultSearchProviderImageURL, POLICY_LEVEL_MANDATORY,
+ POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
+ base::MakeUnique<base::StringValue>(data.image_url), nullptr);
+ policy->Set(key::kDefaultSearchProviderImageURLPostParams,
+ POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
+ base::MakeUnique<base::StringValue>(data.image_url_post_params),
+ nullptr);
+ policy->Set(key::kDefaultSearchProviderNewTabURL, POLICY_LEVEL_MANDATORY,
+ POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
+ base::MakeUnique<base::StringValue>(data.new_tab_url), nullptr);
+}

Powered by Google App Engine
This is Rietveld 408576698