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_manager.h" | 5 #include "components/search_engines/default_search_manager.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 | 10 |
(...skipping 11 matching lines...) Expand all Loading... | |
22 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
23 | 23 |
24 namespace { | 24 namespace { |
25 // A dictionary to hold all data related to the Default Search Engine. | 25 // A dictionary to hold all data related to the Default Search Engine. |
26 // Eventually, this should replace all the data stored in the | 26 // Eventually, this should replace all the data stored in the |
27 // default_search_provider.* prefs. | 27 // default_search_provider.* prefs. |
28 const char kDefaultSearchProviderData[] = | 28 const char kDefaultSearchProviderData[] = |
29 "default_search_provider_data.template_url_data"; | 29 "default_search_provider_data.template_url_data"; |
30 | 30 |
31 // Checks that the two TemplateURLs are similar. Does not check the id, the | 31 // Checks that the two TemplateURLs are similar. Does not check the id, the |
32 // date_created or the last_modified time. Neither pointer should be NULL. | 32 // date_created, the last_modified time or the last_visited time. Neither |
Peter Kasting
2016/11/21 03:35:08
Nit: See earlier comment about wording
ltian
2016/11/28 22:08:02
Done.
| |
33 // pointer should be NULL. | |
33 void ExpectSimilar(const TemplateURLData* expected, | 34 void ExpectSimilar(const TemplateURLData* expected, |
34 const TemplateURLData* actual) { | 35 const TemplateURLData* actual) { |
35 ASSERT_TRUE(expected != NULL); | 36 ASSERT_TRUE(expected != NULL); |
36 ASSERT_TRUE(actual != NULL); | 37 ASSERT_TRUE(actual != NULL); |
37 | 38 |
38 EXPECT_EQ(expected->short_name(), actual->short_name()); | 39 EXPECT_EQ(expected->short_name(), actual->short_name()); |
39 EXPECT_EQ(expected->keyword(), actual->keyword()); | 40 EXPECT_EQ(expected->keyword(), actual->keyword()); |
40 EXPECT_EQ(expected->url(), actual->url()); | 41 EXPECT_EQ(expected->url(), actual->url()); |
41 EXPECT_EQ(expected->suggestions_url, actual->suggestions_url); | 42 EXPECT_EQ(expected->suggestions_url, actual->suggestions_url); |
42 EXPECT_EQ(expected->favicon_url, actual->favicon_url); | 43 EXPECT_EQ(expected->favicon_url, actual->favicon_url); |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
130 data->SetURL(std::string("http://").append(type).append("foo/{searchTerms}")); | 131 data->SetURL(std::string("http://").append(type).append("foo/{searchTerms}")); |
131 data->suggestions_url = std::string("http://").append(type).append("sugg"); | 132 data->suggestions_url = std::string("http://").append(type).append("sugg"); |
132 data->alternate_urls.push_back( | 133 data->alternate_urls.push_back( |
133 std::string("http://").append(type).append("foo/alt")); | 134 std::string("http://").append(type).append("foo/alt")); |
134 data->favicon_url = GURL("http://icon1"); | 135 data->favicon_url = GURL("http://icon1"); |
135 data->safe_for_autoreplace = true; | 136 data->safe_for_autoreplace = true; |
136 data->input_encodings = base::SplitString( | 137 data->input_encodings = base::SplitString( |
137 "UTF-8;UTF-16", ";", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); | 138 "UTF-8;UTF-16", ";", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
138 data->date_created = base::Time(); | 139 data->date_created = base::Time(); |
139 data->last_modified = base::Time(); | 140 data->last_modified = base::Time(); |
141 data->last_visited = base::Time(); | |
140 return data; | 142 return data; |
141 } | 143 } |
142 | 144 |
143 } // namespace | 145 } // namespace |
144 | 146 |
145 class DefaultSearchManagerTest : public testing::Test { | 147 class DefaultSearchManagerTest : public testing::Test { |
146 public: | 148 public: |
147 DefaultSearchManagerTest() {}; | 149 DefaultSearchManagerTest() {}; |
148 | 150 |
149 void SetUp() override { | 151 void SetUp() override { |
(...skipping 21 matching lines...) Expand all Loading... | |
171 data.SetKeyword(base::UTF8ToUTF16("key1")); | 173 data.SetKeyword(base::UTF8ToUTF16("key1")); |
172 data.SetURL("http://foo1/{searchTerms}"); | 174 data.SetURL("http://foo1/{searchTerms}"); |
173 data.suggestions_url = "http://sugg1"; | 175 data.suggestions_url = "http://sugg1"; |
174 data.alternate_urls.push_back("http://foo1/alt"); | 176 data.alternate_urls.push_back("http://foo1/alt"); |
175 data.favicon_url = GURL("http://icon1"); | 177 data.favicon_url = GURL("http://icon1"); |
176 data.safe_for_autoreplace = true; | 178 data.safe_for_autoreplace = true; |
177 data.input_encodings = base::SplitString( | 179 data.input_encodings = base::SplitString( |
178 "UTF-8;UTF-16", ";", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); | 180 "UTF-8;UTF-16", ";", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
179 data.date_created = base::Time(); | 181 data.date_created = base::Time(); |
180 data.last_modified = base::Time(); | 182 data.last_modified = base::Time(); |
183 data.last_modified = base::Time(); | |
181 | 184 |
182 manager.SetUserSelectedDefaultSearchEngine(data); | 185 manager.SetUserSelectedDefaultSearchEngine(data); |
183 TemplateURLData* read_data = manager.GetDefaultSearchEngine(NULL); | 186 TemplateURLData* read_data = manager.GetDefaultSearchEngine(NULL); |
184 ExpectSimilar(&data, read_data); | 187 ExpectSimilar(&data, read_data); |
185 } | 188 } |
186 | 189 |
187 // Test DefaultSearchmanager handles user-selected DSEs correctly. | 190 // Test DefaultSearchmanager handles user-selected DSEs correctly. |
188 TEST_F(DefaultSearchManagerTest, DefaultSearchSetByUserPref) { | 191 TEST_F(DefaultSearchManagerTest, DefaultSearchSetByUserPref) { |
189 size_t default_search_index = 0; | 192 size_t default_search_index = 0; |
190 DefaultSearchManager manager(pref_service(), | 193 DefaultSearchManager manager(pref_service(), |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
321 | 324 |
322 ExpectSimilar(extension_data_3.get(), | 325 ExpectSimilar(extension_data_3.get(), |
323 manager.GetDefaultSearchEngine(&source)); | 326 manager.GetDefaultSearchEngine(&source)); |
324 EXPECT_EQ(DefaultSearchManager::FROM_EXTENSION, source); | 327 EXPECT_EQ(DefaultSearchManager::FROM_EXTENSION, source); |
325 | 328 |
326 manager.ClearExtensionControlledDefaultSearchEngine(); | 329 manager.ClearExtensionControlledDefaultSearchEngine(); |
327 | 330 |
328 ExpectSimilar(data.get(), manager.GetDefaultSearchEngine(&source)); | 331 ExpectSimilar(data.get(), manager.GetDefaultSearchEngine(&source)); |
329 EXPECT_EQ(DefaultSearchManager::FROM_USER, source); | 332 EXPECT_EQ(DefaultSearchManager::FROM_USER, source); |
330 } | 333 } |
OLD | NEW |