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

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

Issue 2479113002: Make extensions DSE persistent in browser prefs (Closed)
Patch Set: Fixed default extension keywords conflicts problem Created 3 years, 11 months 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/utf_string_conversions.h"
10 #include "components/search_engines/default_search_manager.h"
11 #include "components/search_engines/template_url.h"
12 #include "components/search_engines/template_url_data.h"
13 #include "components/search_engines/template_url_data_util.h"
14 #include "components/sync_preferences/testing_pref_service_syncable.h"
15 #include "testing/gtest/include/gtest/gtest.h"
16
17 std::unique_ptr<TemplateURLData> GenerateDummyTemplateURLData(
18 const std::string& provider_name) {
19 auto data = base::MakeUnique<TemplateURLData>();
20 data->SetShortName(base::UTF8ToUTF16(provider_name + "name"));
21 data->SetKeyword(base::UTF8ToUTF16(provider_name + "key"));
22 data->SetURL(std::string("http://") + provider_name + "foo/{searchTerms}");
23 data->suggestions_url = std::string("http://") + provider_name + "sugg";
24 data->alternate_urls.push_back(std::string("http://") + provider_name +
25 "foo/alt");
26 data->favicon_url = GURL("http://icon1");
27 data->safe_for_autoreplace = true;
28 data->input_encodings = {"UTF-8", "UTF-16"};
29 data->date_created = base::Time();
30 data->last_modified = base::Time();
31 return data;
32 }
33
34 void ExpectSimilar(const TemplateURLData* expected,
35 const TemplateURLData* actual) {
36 ASSERT_TRUE(expected);
37 ASSERT_TRUE(actual);
38
39 EXPECT_EQ(expected->short_name(), actual->short_name());
40 EXPECT_EQ(expected->keyword(), actual->keyword());
41 EXPECT_EQ(expected->url(), actual->url());
42 EXPECT_EQ(expected->suggestions_url, actual->suggestions_url);
43 EXPECT_EQ(expected->instant_url, actual->instant_url);
44 EXPECT_EQ(expected->image_url, actual->image_url);
45 EXPECT_EQ(expected->new_tab_url, actual->new_tab_url);
46 EXPECT_EQ(expected->contextual_search_url, actual->contextual_search_url);
47
48 EXPECT_EQ(expected->search_url_post_params, actual->search_url_post_params);
49 EXPECT_EQ(expected->suggestions_url_post_params,
50 actual->suggestions_url_post_params);
51 EXPECT_EQ(expected->instant_url_post_params, actual->instant_url_post_params);
52 EXPECT_EQ(expected->image_url_post_params, actual->image_url_post_params);
53
54 EXPECT_EQ(expected->favicon_url, actual->favicon_url);
55 EXPECT_EQ(expected->safe_for_autoreplace, actual->safe_for_autoreplace);
56 EXPECT_EQ(expected->input_encodings, actual->input_encodings);
57 EXPECT_EQ(expected->alternate_urls, actual->alternate_urls);
58 EXPECT_TRUE(TemplateURL::SearchTermsReplacementKeysMatch(
59 expected->search_terms_replacement_key,
60 actual->search_terms_replacement_key));
61 }
62
63 void SetExtensionDefaultSearchInPrefs(
64 sync_preferences::TestingPrefServiceSyncable* prefs,
65 const TemplateURLData& data,
66 const std::string& extension_id) {
67 std::unique_ptr<base::DictionaryValue> entry =
68 TemplateURLDataToDictionary(data);
69 entry->SetString(DefaultSearchManager::kExtensionID, extension_id);
70 prefs->SetExtensionPref(
71 DefaultSearchManager::kDefaultSearchProviderDataPrefName,
72 entry.release());
73 }
74
75 void RemoveExtensionDefaultSearchFromPrefs(
76 sync_preferences::TestingPrefServiceSyncable* prefs) {
77 prefs->RemoveExtensionPref(
78 DefaultSearchManager::kDefaultSearchProviderDataPrefName);
79 }
OLDNEW
« no previous file with comments | « components/search_engines/search_engines_test_util.h ('k') | components/search_engines/template_url.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698