OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/template_url_service.h" | 5 #include "components/search_engines/template_url_service.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 #include <utility> | 10 #include <utility> |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
67 const std::string& keyword, | 67 const std::string& keyword, |
68 const std::string& url, | 68 const std::string& url, |
69 const std::string& suggest_url, | 69 const std::string& suggest_url, |
70 const std::string& alternate_url, | 70 const std::string& alternate_url, |
71 const std::string& favicon_url, | 71 const std::string& favicon_url, |
72 bool safe_for_autoreplace, | 72 bool safe_for_autoreplace, |
73 int prepopulate_id, | 73 int prepopulate_id, |
74 const std::string& encodings, | 74 const std::string& encodings, |
75 Time date_created, | 75 Time date_created, |
76 Time last_modified, | 76 Time last_modified, |
77 Time last_visited, | |
77 TemplateURL::Type type = TemplateURL::NORMAL) { | 78 TemplateURL::Type type = TemplateURL::NORMAL) { |
78 TemplateURLData data; | 79 TemplateURLData data; |
79 data.SetShortName(base::UTF8ToUTF16(short_name)); | 80 data.SetShortName(base::UTF8ToUTF16(short_name)); |
80 data.SetKeyword(base::UTF8ToUTF16(keyword)); | 81 data.SetKeyword(base::UTF8ToUTF16(keyword)); |
81 data.SetURL(url); | 82 data.SetURL(url); |
82 data.suggestions_url = suggest_url; | 83 data.suggestions_url = suggest_url; |
83 if (!alternate_url.empty()) | 84 if (!alternate_url.empty()) |
84 data.alternate_urls.push_back(alternate_url); | 85 data.alternate_urls.push_back(alternate_url); |
85 data.favicon_url = GURL(favicon_url); | 86 data.favicon_url = GURL(favicon_url); |
86 data.safe_for_autoreplace = safe_for_autoreplace; | 87 data.safe_for_autoreplace = safe_for_autoreplace; |
87 data.prepopulate_id = prepopulate_id; | 88 data.prepopulate_id = prepopulate_id; |
88 data.input_encodings = base::SplitString( | 89 data.input_encodings = base::SplitString( |
89 encodings, ";", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); | 90 encodings, ";", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
90 data.date_created = date_created; | 91 data.date_created = date_created; |
91 data.last_modified = last_modified; | 92 data.last_modified = last_modified; |
93 data.last_visited = last_visited; | |
92 return base::MakeUnique<TemplateURL>(data, type); | 94 return base::MakeUnique<TemplateURL>(data, type); |
93 } | 95 } |
94 | 96 |
95 TemplateURL* AddKeywordWithDate( | 97 TemplateURL* AddKeywordWithDate( |
96 TemplateURLService* model, | 98 TemplateURLService* model, |
97 const std::string& short_name, | 99 const std::string& short_name, |
98 const std::string& keyword, | 100 const std::string& keyword, |
99 const std::string& url, | 101 const std::string& url, |
100 const std::string& suggest_url, | 102 const std::string& suggest_url, |
101 const std::string& alternate_url, | 103 const std::string& alternate_url, |
102 const std::string& favicon_url, | 104 const std::string& favicon_url, |
103 bool safe_for_autoreplace, | 105 bool safe_for_autoreplace, |
104 const std::string& encodings, | 106 const std::string& encodings, |
105 Time date_created, | 107 Time date_created, |
106 Time last_modified) { | 108 Time last_modified, |
109 Time last_visited) { | |
107 TemplateURL* t_url = model->Add(CreateKeywordWithDate( | 110 TemplateURL* t_url = model->Add(CreateKeywordWithDate( |
108 model, short_name, keyword, url, suggest_url, alternate_url, favicon_url, | 111 model, short_name, keyword, url, suggest_url, alternate_url, |
109 safe_for_autoreplace, 0, encodings, date_created, last_modified)); | 112 favicon_url, safe_for_autoreplace, 0, encodings, date_created, |
113 last_modified, last_visited)); | |
110 EXPECT_NE(0, t_url->id()); | 114 EXPECT_NE(0, t_url->id()); |
111 return t_url; | 115 return t_url; |
112 } | 116 } |
113 | 117 |
114 // Checks that the two TemplateURLs are similar. It does not check the id, the | 118 // Checks that the two TemplateURLs are similar. It does not check the id, the |
115 // date_created or the last_modified time. Neither pointer should be NULL. | 119 // date_created, the last_modified and the last_visit time. Neither pointer |
Peter Kasting
2016/11/21 03:35:08
Nit: Shorter, and more future-proof: "It does not
ltian
2016/11/28 22:08:01
Done.
| |
120 // should be NULL. | |
116 void ExpectSimilar(const TemplateURL* expected, const TemplateURL* actual) { | 121 void ExpectSimilar(const TemplateURL* expected, const TemplateURL* actual) { |
117 ASSERT_TRUE(expected != NULL); | 122 ASSERT_TRUE(expected != NULL); |
118 ASSERT_TRUE(actual != NULL); | 123 ASSERT_TRUE(actual != NULL); |
119 EXPECT_EQ(expected->short_name(), actual->short_name()); | 124 EXPECT_EQ(expected->short_name(), actual->short_name()); |
120 EXPECT_EQ(expected->keyword(), actual->keyword()); | 125 EXPECT_EQ(expected->keyword(), actual->keyword()); |
121 EXPECT_EQ(expected->url(), actual->url()); | 126 EXPECT_EQ(expected->url(), actual->url()); |
122 EXPECT_EQ(expected->suggestions_url(), actual->suggestions_url()); | 127 EXPECT_EQ(expected->suggestions_url(), actual->suggestions_url()); |
123 EXPECT_EQ(expected->favicon_url(), actual->favicon_url()); | 128 EXPECT_EQ(expected->favicon_url(), actual->favicon_url()); |
124 EXPECT_EQ(expected->alternate_urls(), actual->alternate_urls()); | 129 EXPECT_EQ(expected->alternate_urls(), actual->alternate_urls()); |
125 EXPECT_EQ(expected->safe_for_autoreplace(), actual->safe_for_autoreplace()); | 130 EXPECT_EQ(expected->safe_for_autoreplace(), actual->safe_for_autoreplace()); |
(...skipping 21 matching lines...) Expand all Loading... | |
147 | 152 |
148 TemplateURL* AddKeywordWithDate(const std::string& short_name, | 153 TemplateURL* AddKeywordWithDate(const std::string& short_name, |
149 const std::string& keyword, | 154 const std::string& keyword, |
150 const std::string& url, | 155 const std::string& url, |
151 const std::string& suggest_url, | 156 const std::string& suggest_url, |
152 const std::string& alternate_url, | 157 const std::string& alternate_url, |
153 const std::string& favicon_url, | 158 const std::string& favicon_url, |
154 bool safe_for_autoreplace, | 159 bool safe_for_autoreplace, |
155 const std::string& encodings, | 160 const std::string& encodings, |
156 Time date_created, | 161 Time date_created, |
157 Time last_modified); | 162 Time last_modified, |
163 Time last_visited); | |
158 | 164 |
159 // Verifies the two TemplateURLs are equal. | 165 // Verifies the two TemplateURLs are equal. |
160 void AssertEquals(const TemplateURL& expected, const TemplateURL& actual); | 166 void AssertEquals(const TemplateURL& expected, const TemplateURL& actual); |
161 | 167 |
162 // Verifies the two timestamps are equal, within the expected degree of | 168 // Verifies the two timestamps are equal, within the expected degree of |
163 // precision. | 169 // precision. |
164 void AssertTimesEqual(const base::Time& expected, const base::Time& actual); | 170 void AssertTimesEqual(const base::Time& expected, const base::Time& actual); |
165 | 171 |
166 // Create an URL that appears to have been prepopulated, but won't be in the | 172 // Create an URL that appears to have been prepopulated, but won't be in the |
167 // current data. | 173 // current data. |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
215 TemplateURL* TemplateURLServiceTest::AddKeywordWithDate( | 221 TemplateURL* TemplateURLServiceTest::AddKeywordWithDate( |
216 const std::string& short_name, | 222 const std::string& short_name, |
217 const std::string& keyword, | 223 const std::string& keyword, |
218 const std::string& url, | 224 const std::string& url, |
219 const std::string& suggest_url, | 225 const std::string& suggest_url, |
220 const std::string& alternate_url, | 226 const std::string& alternate_url, |
221 const std::string& favicon_url, | 227 const std::string& favicon_url, |
222 bool safe_for_autoreplace, | 228 bool safe_for_autoreplace, |
223 const std::string& encodings, | 229 const std::string& encodings, |
224 Time date_created, | 230 Time date_created, |
225 Time last_modified) { | 231 Time last_modified, |
232 Time last_visited) { | |
226 return ::AddKeywordWithDate(model(), short_name, keyword, url, suggest_url, | 233 return ::AddKeywordWithDate(model(), short_name, keyword, url, suggest_url, |
227 alternate_url, favicon_url, safe_for_autoreplace, | 234 alternate_url, favicon_url, safe_for_autoreplace, |
228 encodings, date_created, last_modified); | 235 encodings, date_created, last_modified, |
236 last_visited); | |
229 } | 237 } |
230 | 238 |
231 void TemplateURLServiceTest::AssertEquals(const TemplateURL& expected, | 239 void TemplateURLServiceTest::AssertEquals(const TemplateURL& expected, |
232 const TemplateURL& actual) { | 240 const TemplateURL& actual) { |
233 ASSERT_EQ(expected.short_name(), actual.short_name()); | 241 ASSERT_EQ(expected.short_name(), actual.short_name()); |
234 ASSERT_EQ(expected.keyword(), actual.keyword()); | 242 ASSERT_EQ(expected.keyword(), actual.keyword()); |
235 ASSERT_EQ(expected.url(), actual.url()); | 243 ASSERT_EQ(expected.url(), actual.url()); |
236 ASSERT_EQ(expected.suggestions_url(), actual.suggestions_url()); | 244 ASSERT_EQ(expected.suggestions_url(), actual.suggestions_url()); |
237 ASSERT_EQ(expected.favicon_url(), actual.favicon_url()); | 245 ASSERT_EQ(expected.favicon_url(), actual.favicon_url()); |
238 ASSERT_EQ(expected.alternate_urls(), actual.alternate_urls()); | 246 ASSERT_EQ(expected.alternate_urls(), actual.alternate_urls()); |
239 ASSERT_EQ(expected.prepopulate_id(), actual.prepopulate_id()); | 247 ASSERT_EQ(expected.prepopulate_id(), actual.prepopulate_id()); |
240 ASSERT_EQ(expected.safe_for_autoreplace(), actual.safe_for_autoreplace()); | 248 ASSERT_EQ(expected.safe_for_autoreplace(), actual.safe_for_autoreplace()); |
241 ASSERT_EQ(expected.input_encodings(), actual.input_encodings()); | 249 ASSERT_EQ(expected.input_encodings(), actual.input_encodings()); |
242 ASSERT_EQ(expected.id(), actual.id()); | 250 ASSERT_EQ(expected.id(), actual.id()); |
243 ASSERT_EQ(expected.date_created(), actual.date_created()); | 251 ASSERT_EQ(expected.date_created(), actual.date_created()); |
244 AssertTimesEqual(expected.last_modified(), actual.last_modified()); | 252 AssertTimesEqual(expected.last_modified(), actual.last_modified()); |
253 ASSERT_EQ(expected.last_visited(), actual.last_visited()); | |
245 ASSERT_EQ(expected.sync_guid(), actual.sync_guid()); | 254 ASSERT_EQ(expected.sync_guid(), actual.sync_guid()); |
246 ASSERT_EQ(expected.search_terms_replacement_key(), | 255 ASSERT_EQ(expected.search_terms_replacement_key(), |
247 actual.search_terms_replacement_key()); | 256 actual.search_terms_replacement_key()); |
248 } | 257 } |
249 | 258 |
250 void TemplateURLServiceTest::AssertTimesEqual(const base::Time& expected, | 259 void TemplateURLServiceTest::AssertTimesEqual(const base::Time& expected, |
251 const base::Time& actual) { | 260 const base::Time& actual) { |
252 // Because times are stored with a granularity of one second, there is a loss | 261 // Because times are stored with a granularity of one second, there is a loss |
253 // of precision when serializing and deserializing the timestamps. Hence, only | 262 // of precision when serializing and deserializing the timestamps. Hence, only |
254 // expect timestamps to be equal to within one second of one another. | 263 // expect timestamps to be equal to within one second of one another. |
255 ASSERT_LT((expected - actual).magnitude(), base::TimeDelta::FromSeconds(1)); | 264 ASSERT_LT((expected - actual).magnitude(), base::TimeDelta::FromSeconds(1)); |
256 } | 265 } |
257 | 266 |
258 std::unique_ptr<TemplateURL> TemplateURLServiceTest::CreatePreloadedTemplateURL( | 267 std::unique_ptr<TemplateURL> TemplateURLServiceTest::CreatePreloadedTemplateURL( |
259 bool safe_for_autoreplace, | 268 bool safe_for_autoreplace, |
260 int prepopulate_id) { | 269 int prepopulate_id) { |
261 TemplateURLData data; | 270 TemplateURLData data; |
262 data.SetShortName(ASCIIToUTF16("unittest")); | 271 data.SetShortName(ASCIIToUTF16("unittest")); |
263 data.SetKeyword(ASCIIToUTF16("unittest")); | 272 data.SetKeyword(ASCIIToUTF16("unittest")); |
264 data.SetURL("http://www.unittest.com/{searchTerms}"); | 273 data.SetURL("http://www.unittest.com/{searchTerms}"); |
265 data.favicon_url = GURL("http://favicon.url"); | 274 data.favicon_url = GURL("http://favicon.url"); |
266 data.safe_for_autoreplace = safe_for_autoreplace; | 275 data.safe_for_autoreplace = safe_for_autoreplace; |
267 data.input_encodings.push_back("UTF-8"); | 276 data.input_encodings.push_back("UTF-8"); |
268 data.date_created = Time::FromTimeT(100); | 277 data.date_created = Time::FromTimeT(100); |
269 data.last_modified = Time::FromTimeT(100); | 278 data.last_modified = Time::FromTimeT(100); |
279 data.last_visited = Time::FromTimeT(100); | |
270 data.prepopulate_id = prepopulate_id; | 280 data.prepopulate_id = prepopulate_id; |
271 return base::MakeUnique<TemplateURL>(data); | 281 return base::MakeUnique<TemplateURL>(data); |
272 } | 282 } |
273 | 283 |
274 void TemplateURLServiceTest::VerifyObserverCount(int expected_changed_count) { | 284 void TemplateURLServiceTest::VerifyObserverCount(int expected_changed_count) { |
275 EXPECT_EQ(expected_changed_count, test_util_->GetObserverCount()); | 285 EXPECT_EQ(expected_changed_count, test_util_->GetObserverCount()); |
276 test_util_->ResetObserverCount(); | 286 test_util_->ResetObserverCount(); |
277 } | 287 } |
278 | 288 |
279 void TemplateURLServiceTest::VerifyObserverFired() { | 289 void TemplateURLServiceTest::VerifyObserverFired() { |
(...skipping 14 matching lines...) Expand all Loading... | |
294 const size_t initial_count = model()->GetTemplateURLs().size(); | 304 const size_t initial_count = model()->GetTemplateURLs().size(); |
295 | 305 |
296 TemplateURLData data; | 306 TemplateURLData data; |
297 data.SetShortName(ASCIIToUTF16("google")); | 307 data.SetShortName(ASCIIToUTF16("google")); |
298 data.SetKeyword(ASCIIToUTF16("keyword")); | 308 data.SetKeyword(ASCIIToUTF16("keyword")); |
299 data.SetURL("http://www.google.com/foo/bar"); | 309 data.SetURL("http://www.google.com/foo/bar"); |
300 data.favicon_url = GURL("http://favicon.url"); | 310 data.favicon_url = GURL("http://favicon.url"); |
301 data.safe_for_autoreplace = true; | 311 data.safe_for_autoreplace = true; |
302 data.date_created = Time::FromTimeT(100); | 312 data.date_created = Time::FromTimeT(100); |
303 data.last_modified = Time::FromTimeT(100); | 313 data.last_modified = Time::FromTimeT(100); |
314 data.last_visited = Time::FromTimeT(100); | |
304 data.sync_guid = "00000000-0000-0000-0000-000000000001"; | 315 data.sync_guid = "00000000-0000-0000-0000-000000000001"; |
305 TemplateURL* t_url = model()->Add(base::MakeUnique<TemplateURL>(data)); | 316 TemplateURL* t_url = model()->Add(base::MakeUnique<TemplateURL>(data)); |
306 ASSERT_TRUE(model()->CanAddAutogeneratedKeyword(ASCIIToUTF16("keyword"), | 317 ASSERT_TRUE(model()->CanAddAutogeneratedKeyword(ASCIIToUTF16("keyword"), |
307 GURL(), NULL)); | 318 GURL(), NULL)); |
308 VerifyObserverCount(1); | 319 VerifyObserverCount(1); |
309 base::RunLoop().RunUntilIdle(); | 320 base::RunLoop().RunUntilIdle(); |
310 ASSERT_EQ(initial_count + 1, model()->GetTemplateURLs().size()); | 321 ASSERT_EQ(initial_count + 1, model()->GetTemplateURLs().size()); |
311 ASSERT_EQ(t_url, model()->GetTemplateURLForKeyword(t_url->keyword())); | 322 ASSERT_EQ(t_url, model()->GetTemplateURLForKeyword(t_url->keyword())); |
312 // We need to make a second copy as the model takes ownership of |t_url| and | 323 // We need to make a second copy as the model takes ownership of |t_url| and |
313 // will delete it. We have to do this after calling Add() since that gives | 324 // will delete it. We have to do this after calling Add() since that gives |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
360 test_util()->ResetModel(true); | 371 test_util()->ResetModel(true); |
361 ASSERT_EQ(initial_count, model()->GetTemplateURLs().size()); | 372 ASSERT_EQ(initial_count, model()->GetTemplateURLs().size()); |
362 EXPECT_TRUE(model()->GetTemplateURLForKeyword(ASCIIToUTF16("b")) == NULL); | 373 EXPECT_TRUE(model()->GetTemplateURLForKeyword(ASCIIToUTF16("b")) == NULL); |
363 } | 374 } |
364 | 375 |
365 TEST_F(TemplateURLServiceTest, AddSameKeyword) { | 376 TEST_F(TemplateURLServiceTest, AddSameKeyword) { |
366 test_util()->VerifyLoad(); | 377 test_util()->VerifyLoad(); |
367 | 378 |
368 AddKeywordWithDate( | 379 AddKeywordWithDate( |
369 "first", "keyword", "http://test1", std::string(), std::string(), | 380 "first", "keyword", "http://test1", std::string(), std::string(), |
370 std::string(), true, "UTF-8", Time(), Time()); | 381 std::string(), true, "UTF-8", Time(), Time(), Time()); |
371 VerifyObserverCount(1); | 382 VerifyObserverCount(1); |
372 | 383 |
373 // Test what happens when we try to add a TemplateURL with the same keyword as | 384 // Test what happens when we try to add a TemplateURL with the same keyword as |
374 // one in the model. | 385 // one in the model. |
375 TemplateURLData data; | 386 TemplateURLData data; |
376 data.SetShortName(ASCIIToUTF16("second")); | 387 data.SetShortName(ASCIIToUTF16("second")); |
377 data.SetKeyword(ASCIIToUTF16("keyword")); | 388 data.SetKeyword(ASCIIToUTF16("keyword")); |
378 data.SetURL("http://test2"); | 389 data.SetURL("http://test2"); |
379 data.safe_for_autoreplace = false; | 390 data.safe_for_autoreplace = false; |
380 TemplateURL* t_url = model()->Add(base::MakeUnique<TemplateURL>(data)); | 391 TemplateURL* t_url = model()->Add(base::MakeUnique<TemplateURL>(data)); |
(...skipping 30 matching lines...) Expand all Loading... | |
411 EXPECT_EQ(ASCIIToUTF16("keyword"), t_url2->keyword()); | 422 EXPECT_EQ(ASCIIToUTF16("keyword"), t_url2->keyword()); |
412 EXPECT_EQ(ASCIIToUTF16("second"), t_url->short_name()); | 423 EXPECT_EQ(ASCIIToUTF16("second"), t_url->short_name()); |
413 EXPECT_EQ(ASCIIToUTF16("test2"), t_url->keyword()); | 424 EXPECT_EQ(ASCIIToUTF16("test2"), t_url->keyword()); |
414 } | 425 } |
415 | 426 |
416 TEST_F(TemplateURLServiceTest, AddExtensionKeyword) { | 427 TEST_F(TemplateURLServiceTest, AddExtensionKeyword) { |
417 test_util()->VerifyLoad(); | 428 test_util()->VerifyLoad(); |
418 | 429 |
419 AddKeywordWithDate( | 430 AddKeywordWithDate( |
420 "replaceable", "keyword1", "http://test1", std::string(), std::string(), | 431 "replaceable", "keyword1", "http://test1", std::string(), std::string(), |
421 std::string(), true, "UTF-8", Time(), Time()); | 432 std::string(), true, "UTF-8", Time(), Time(), Time()); |
422 TemplateURL* original2 = AddKeywordWithDate( | 433 TemplateURL* original2 = AddKeywordWithDate( |
423 "nonreplaceable", "keyword2", "http://test2", std::string(), | 434 "nonreplaceable", "keyword2", "http://test2", std::string(), |
424 std::string(), std::string(), false, "UTF-8", Time(), Time()); | 435 std::string(), std::string(), false, "UTF-8", Time(), Time(), Time()); |
425 model()->RegisterOmniboxKeyword("test3", "extension", "keyword3", | 436 model()->RegisterOmniboxKeyword("test3", "extension", "keyword3", |
426 "http://test3"); | 437 "http://test3"); |
427 TemplateURL* original3 = | 438 TemplateURL* original3 = |
428 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword3")); | 439 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword3")); |
429 ASSERT_TRUE(original3); | 440 ASSERT_TRUE(original3); |
430 | 441 |
431 // Extension keywords should override replaceable keywords. | 442 // Extension keywords should override replaceable keywords. |
432 model()->RegisterOmniboxKeyword("id1", "test", "keyword1", "http://test4"); | 443 model()->RegisterOmniboxKeyword("id1", "test", "keyword1", "http://test4"); |
433 TemplateURL* extension1 = model()->FindTemplateURLForExtension( | 444 TemplateURL* extension1 = model()->FindTemplateURLForExtension( |
434 "id1", TemplateURL::OMNIBOX_API_EXTENSION); | 445 "id1", TemplateURL::OMNIBOX_API_EXTENSION); |
(...skipping 25 matching lines...) Expand all Loading... | |
460 // replaceable TemplateURL. We should still do correct conflict resolution | 471 // replaceable TemplateURL. We should still do correct conflict resolution |
461 // between the non-template URLs. | 472 // between the non-template URLs. |
462 model()->RegisterOmniboxKeyword("test2", "extension", "keyword", | 473 model()->RegisterOmniboxKeyword("test2", "extension", "keyword", |
463 "http://test2"); | 474 "http://test2"); |
464 TemplateURL* extension = | 475 TemplateURL* extension = |
465 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword")); | 476 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword")); |
466 ASSERT_TRUE(extension); | 477 ASSERT_TRUE(extension); |
467 // Adding a keyword that matches the extension. | 478 // Adding a keyword that matches the extension. |
468 AddKeywordWithDate( | 479 AddKeywordWithDate( |
469 "replaceable", "keyword", "http://test1", std::string(), std::string(), | 480 "replaceable", "keyword", "http://test1", std::string(), std::string(), |
470 std::string(), true, "UTF-8", Time(), Time()); | 481 std::string(), true, "UTF-8", Time(), Time(), Time()); |
471 | 482 |
472 // Adding another replaceable keyword should remove the existing one, but | 483 // Adding another replaceable keyword should remove the existing one, but |
473 // leave the extension as is. | 484 // leave the extension as is. |
474 TemplateURLData data; | 485 TemplateURLData data; |
475 data.SetShortName(ASCIIToUTF16("name1")); | 486 data.SetShortName(ASCIIToUTF16("name1")); |
476 data.SetKeyword(ASCIIToUTF16("keyword")); | 487 data.SetKeyword(ASCIIToUTF16("keyword")); |
477 data.SetURL("http://test3"); | 488 data.SetURL("http://test3"); |
478 data.safe_for_autoreplace = true; | 489 data.safe_for_autoreplace = true; |
479 TemplateURL* t_url = model()->Add(base::MakeUnique<TemplateURL>(data)); | 490 TemplateURL* t_url = model()->Add(base::MakeUnique<TemplateURL>(data)); |
480 EXPECT_EQ(extension, | 491 EXPECT_EQ(extension, |
(...skipping 30 matching lines...) Expand all Loading... | |
511 Time now = Time::Now(); | 522 Time now = Time::Now(); |
512 TimeDelta one_day = TimeDelta::FromDays(1); | 523 TimeDelta one_day = TimeDelta::FromDays(1); |
513 Time month_ago = now - TimeDelta::FromDays(30); | 524 Time month_ago = now - TimeDelta::FromDays(30); |
514 | 525 |
515 // Nothing has been added. | 526 // Nothing has been added. |
516 EXPECT_EQ(0U, model()->GetTemplateURLs().size()); | 527 EXPECT_EQ(0U, model()->GetTemplateURLs().size()); |
517 | 528 |
518 // Create one with a 0 time. | 529 // Create one with a 0 time. |
519 AddKeywordWithDate("name1", "key1", "http://foo1", "http://suggest1", | 530 AddKeywordWithDate("name1", "key1", "http://foo1", "http://suggest1", |
520 std::string(), "http://icon1", true, "UTF-8;UTF-16", | 531 std::string(), "http://icon1", true, "UTF-8;UTF-16", |
521 Time(), Time()); | 532 Time(), Time(), Time()); |
522 // Create one for now and +/- 1 day. | 533 // Create one for now and +/- 1 day. |
523 AddKeywordWithDate("name2", "key2", "http://foo2", "http://suggest2", | 534 AddKeywordWithDate("name2", "key2", "http://foo2", "http://suggest2", |
524 std::string(), "http://icon2", true, "UTF-8;UTF-16", | 535 std::string(), "http://icon2", true, "UTF-8;UTF-16", |
525 now - one_day, Time()); | 536 now - one_day, Time(), Time()); |
526 AddKeywordWithDate("name3", "key3", "http://foo3", std::string(), | 537 AddKeywordWithDate("name3", "key3", "http://foo3", std::string(), |
527 std::string(), std::string(), true, std::string(), now, | 538 std::string(), std::string(), true, std::string(), now, |
528 Time()); | 539 Time(), Time()); |
529 AddKeywordWithDate("name4", "key4", "http://foo4", std::string(), | 540 AddKeywordWithDate("name4", "key4", "http://foo4", std::string(), |
530 std::string(), std::string(), true, std::string(), | 541 std::string(), std::string(), true, std::string(), |
531 now + one_day, Time()); | 542 now + one_day, Time(), Time()); |
532 // Try the other three states. | 543 // Try the other three states. |
533 AddKeywordWithDate("name5", "key5", "http://foo5", "http://suggest5", | 544 AddKeywordWithDate("name5", "key5", "http://foo5", "http://suggest5", |
534 std::string(), "http://icon5", false, "UTF-8;UTF-16", now, | 545 std::string(), "http://icon5", false, "UTF-8;UTF-16", now, |
535 Time()); | 546 Time(), Time()); |
536 AddKeywordWithDate("name6", "key6", "http://foo6", "http://suggest6", | 547 AddKeywordWithDate("name6", "key6", "http://foo6", "http://suggest6", |
537 std::string(), "http://icon6", false, "UTF-8;UTF-16", | 548 std::string(), "http://icon6", false, "UTF-8;UTF-16", |
538 month_ago, Time()); | 549 month_ago, Time(), Time()); |
539 | 550 |
540 // We just added a few items, validate them. | 551 // We just added a few items, validate them. |
541 EXPECT_EQ(6U, model()->GetTemplateURLs().size()); | 552 EXPECT_EQ(6U, model()->GetTemplateURLs().size()); |
542 | 553 |
543 // Try removing from current timestamp. This should delete the one in the | 554 // Try removing from current timestamp. This should delete the one in the |
544 // future and one very recent one. | 555 // future and one very recent one. |
545 model()->RemoveAutoGeneratedSince(now); | 556 model()->RemoveAutoGeneratedSince(now); |
546 EXPECT_EQ(4U, model()->GetTemplateURLs().size()); | 557 EXPECT_EQ(4U, model()->GetTemplateURLs().size()); |
547 | 558 |
548 // Try removing from two months ago. This should only delete items that are | 559 // Try removing from two months ago. This should only delete items that are |
(...skipping 26 matching lines...) Expand all Loading... | |
575 Time now = Time::Now(); | 586 Time now = Time::Now(); |
576 TimeDelta one_day = TimeDelta::FromDays(1); | 587 TimeDelta one_day = TimeDelta::FromDays(1); |
577 Time month_ago = now - TimeDelta::FromDays(30); | 588 Time month_ago = now - TimeDelta::FromDays(30); |
578 | 589 |
579 // Nothing has been added. | 590 // Nothing has been added. |
580 EXPECT_EQ(0U, model()->GetTemplateURLs().size()); | 591 EXPECT_EQ(0U, model()->GetTemplateURLs().size()); |
581 | 592 |
582 // Create one for now and +/- 1 day. | 593 // Create one for now and +/- 1 day. |
583 AddKeywordWithDate("name1", "key1", "http://foo1", "http://suggest1", | 594 AddKeywordWithDate("name1", "key1", "http://foo1", "http://suggest1", |
584 std::string(), "http://icon2", true, "UTF-8;UTF-16", | 595 std::string(), "http://icon2", true, "UTF-8;UTF-16", |
585 now - one_day, Time()); | 596 now - one_day, Time(), Time()); |
586 AddKeywordWithDate("name2", "key2", "http://foo2", std::string(), | 597 AddKeywordWithDate("name2", "key2", "http://foo2", std::string(), |
587 std::string(), std::string(), true, std::string(), now, | 598 std::string(), std::string(), true, std::string(), now, |
588 Time()); | 599 Time(), Time()); |
589 AddKeywordWithDate("name3", "key3", "http://foo3", std::string(), | 600 AddKeywordWithDate("name3", "key3", "http://foo3", std::string(), |
590 std::string(), std::string(), true, std::string(), | 601 std::string(), std::string(), true, std::string(), |
591 now + one_day, Time()); | 602 now + one_day, Time(), Time()); |
592 | 603 |
593 // We just added a few items, validate them. | 604 // We just added a few items, validate them. |
594 EXPECT_EQ(3U, model()->GetTemplateURLs().size()); | 605 EXPECT_EQ(3U, model()->GetTemplateURLs().size()); |
595 | 606 |
596 // Try removing foo2. This should delete foo2, but leave foo1 and 3 untouched. | 607 // Try removing foo2. This should delete foo2, but leave foo1 and 3 untouched. |
597 GURL url2("http://foo2"); | 608 GURL url2("http://foo2"); |
598 model()->RemoveAutoGeneratedForUrlsBetween( | 609 model()->RemoveAutoGeneratedForUrlsBetween( |
599 base::Bind(static_cast<bool (*)(const GURL&, const GURL&)>(operator==), | 610 base::Bind(static_cast<bool (*)(const GURL&, const GURL&)>(operator==), |
600 url2), | 611 url2), |
601 month_ago, now + one_day); | 612 month_ago, now + one_day); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
633 // Add a new TemplateURL. | 644 // Add a new TemplateURL. |
634 test_util()->VerifyLoad(); | 645 test_util()->VerifyLoad(); |
635 const size_t initial_count = model()->GetTemplateURLs().size(); | 646 const size_t initial_count = model()->GetTemplateURLs().size(); |
636 TemplateURLData data; | 647 TemplateURLData data; |
637 data.SetShortName(ASCIIToUTF16("google")); | 648 data.SetShortName(ASCIIToUTF16("google")); |
638 data.SetKeyword(ASCIIToUTF16("keyword")); | 649 data.SetKeyword(ASCIIToUTF16("keyword")); |
639 data.SetURL("http://www.google.com/foo/bar"); | 650 data.SetURL("http://www.google.com/foo/bar"); |
640 data.favicon_url = GURL("http://favicon.url"); | 651 data.favicon_url = GURL("http://favicon.url"); |
641 data.date_created = Time::FromTimeT(100); | 652 data.date_created = Time::FromTimeT(100); |
642 data.last_modified = Time::FromTimeT(100); | 653 data.last_modified = Time::FromTimeT(100); |
654 data.last_visited = Time::FromTimeT(100); | |
643 TemplateURL* t_url = model()->Add(base::MakeUnique<TemplateURL>(data)); | 655 TemplateURL* t_url = model()->Add(base::MakeUnique<TemplateURL>(data)); |
644 | 656 |
645 VerifyObserverCount(1); | 657 VerifyObserverCount(1); |
646 base::RunLoop().RunUntilIdle(); | 658 base::RunLoop().RunUntilIdle(); |
647 | 659 |
648 base::Time now = base::Time::Now(); | 660 base::Time now = base::Time::Now(); |
649 std::unique_ptr<base::SimpleTestClock> clock(new base::SimpleTestClock); | 661 std::unique_ptr<base::SimpleTestClock> clock(new base::SimpleTestClock); |
650 clock->SetNow(now); | 662 clock->SetNow(now); |
651 model()->set_clock(std::move(clock)); | 663 model()->set_clock(std::move(clock)); |
652 | 664 |
(...skipping 22 matching lines...) Expand all Loading... | |
675 AssertEquals(*cloned_url, *read_url); | 687 AssertEquals(*cloned_url, *read_url); |
676 AssertTimesEqual(now, read_url->last_modified()); | 688 AssertTimesEqual(now, read_url->last_modified()); |
677 } | 689 } |
678 | 690 |
679 TEST_F(TemplateURLServiceTest, DefaultSearchProvider) { | 691 TEST_F(TemplateURLServiceTest, DefaultSearchProvider) { |
680 // Add a new TemplateURL. | 692 // Add a new TemplateURL. |
681 test_util()->VerifyLoad(); | 693 test_util()->VerifyLoad(); |
682 const size_t initial_count = model()->GetTemplateURLs().size(); | 694 const size_t initial_count = model()->GetTemplateURLs().size(); |
683 TemplateURL* t_url = AddKeywordWithDate( | 695 TemplateURL* t_url = AddKeywordWithDate( |
684 "name1", "key1", "http://foo1/{searchTerms}", "http://sugg1", | 696 "name1", "key1", "http://foo1/{searchTerms}", "http://sugg1", |
685 std::string(), "http://icon1", true, "UTF-8;UTF-16", Time(), Time()); | 697 std::string(), "http://icon1", true, "UTF-8;UTF-16", Time(), Time(), Time( )); |
686 test_util()->ResetObserverCount(); | 698 test_util()->ResetObserverCount(); |
687 | 699 |
688 model()->SetUserSelectedDefaultSearchProvider(t_url); | 700 model()->SetUserSelectedDefaultSearchProvider(t_url); |
689 ASSERT_EQ(t_url, model()->GetDefaultSearchProvider()); | 701 ASSERT_EQ(t_url, model()->GetDefaultSearchProvider()); |
690 ASSERT_TRUE(t_url->safe_for_autoreplace()); | 702 ASSERT_TRUE(t_url->safe_for_autoreplace()); |
691 ASSERT_TRUE(model()->ShowInDefaultList(t_url)); | 703 ASSERT_TRUE(model()->ShowInDefaultList(t_url)); |
692 | 704 |
693 // Setting the default search provider should have caused notification. | 705 // Setting the default search provider should have caused notification. |
694 VerifyObserverCount(1); | 706 VerifyObserverCount(1); |
695 base::RunLoop().RunUntilIdle(); | 707 base::RunLoop().RunUntilIdle(); |
696 | 708 |
697 std::unique_ptr<TemplateURL> cloned_url( | 709 std::unique_ptr<TemplateURL> cloned_url( |
698 base::MakeUnique<TemplateURL>(t_url->data())); | 710 base::MakeUnique<TemplateURL>(t_url->data())); |
699 | 711 |
700 // Make sure when we reload we get a default search provider. | 712 // Make sure when we reload we get a default search provider. |
701 test_util()->ResetModel(true); | 713 test_util()->ResetModel(true); |
702 EXPECT_EQ(initial_count + 1, model()->GetTemplateURLs().size()); | 714 EXPECT_EQ(initial_count + 1, model()->GetTemplateURLs().size()); |
703 ASSERT_TRUE(model()->GetDefaultSearchProvider()); | 715 ASSERT_TRUE(model()->GetDefaultSearchProvider()); |
704 AssertEquals(*cloned_url, *model()->GetDefaultSearchProvider()); | 716 AssertEquals(*cloned_url, *model()->GetDefaultSearchProvider()); |
705 } | 717 } |
706 | 718 |
707 TEST_F(TemplateURLServiceTest, CantReplaceWithSameKeyword) { | 719 TEST_F(TemplateURLServiceTest, CantReplaceWithSameKeyword) { |
708 test_util()->ChangeModelToLoadState(); | 720 test_util()->ChangeModelToLoadState(); |
709 ASSERT_TRUE(model()->CanAddAutogeneratedKeyword(ASCIIToUTF16("foo"), GURL(), | 721 ASSERT_TRUE(model()->CanAddAutogeneratedKeyword(ASCIIToUTF16("foo"), GURL(), |
710 NULL)); | 722 NULL)); |
711 TemplateURL* t_url = AddKeywordWithDate( | 723 TemplateURL* t_url = AddKeywordWithDate( |
712 "name1", "foo", "http://foo1", "http://sugg1", std::string(), | 724 "name1", "foo", "http://foo1", "http://sugg1", std::string(), |
713 "http://icon1", true, "UTF-8;UTF-16", Time(), Time()); | 725 "http://icon1", true, "UTF-8;UTF-16", Time(), Time(), Time()); |
714 | 726 |
715 // Can still replace, newly added template url is marked safe to replace. | 727 // Can still replace, newly added template url is marked safe to replace. |
716 ASSERT_TRUE(model()->CanAddAutogeneratedKeyword(ASCIIToUTF16("foo"), | 728 ASSERT_TRUE(model()->CanAddAutogeneratedKeyword(ASCIIToUTF16("foo"), |
717 GURL("http://foo2"), NULL)); | 729 GURL("http://foo2"), NULL)); |
718 | 730 |
719 // ResetTemplateURL marks the TemplateURL as unsafe to replace, so it should | 731 // ResetTemplateURL marks the TemplateURL as unsafe to replace, so it should |
720 // no longer be replaceable. | 732 // no longer be replaceable. |
721 model()->ResetTemplateURL(t_url, t_url->short_name(), t_url->keyword(), | 733 model()->ResetTemplateURL(t_url, t_url->short_name(), t_url->keyword(), |
722 t_url->url()); | 734 t_url->url()); |
723 | 735 |
724 ASSERT_FALSE(model()->CanAddAutogeneratedKeyword(ASCIIToUTF16("foo"), | 736 ASSERT_FALSE(model()->CanAddAutogeneratedKeyword(ASCIIToUTF16("foo"), |
725 GURL("http://foo2"), NULL)); | 737 GURL("http://foo2"), NULL)); |
726 } | 738 } |
727 | 739 |
728 TEST_F(TemplateURLServiceTest, CantReplaceWithSameHosts) { | 740 TEST_F(TemplateURLServiceTest, CantReplaceWithSameHosts) { |
729 test_util()->ChangeModelToLoadState(); | 741 test_util()->ChangeModelToLoadState(); |
730 ASSERT_TRUE(model()->CanAddAutogeneratedKeyword(ASCIIToUTF16("foo"), | 742 ASSERT_TRUE(model()->CanAddAutogeneratedKeyword(ASCIIToUTF16("foo"), |
731 GURL("http://foo.com"), NULL)); | 743 GURL("http://foo.com"), NULL)); |
732 TemplateURL* t_url = AddKeywordWithDate( | 744 TemplateURL* t_url = AddKeywordWithDate( |
733 "name1", "foo", "http://foo.com", "http://sugg1", std::string(), | 745 "name1", "foo", "http://foo.com", "http://sugg1", std::string(), |
734 "http://icon1", true, "UTF-8;UTF-16", Time(), Time()); | 746 "http://icon1", true, "UTF-8;UTF-16", Time(), Time(), Time()); |
735 | 747 |
736 // Can still replace, newly added template url is marked safe to replace. | 748 // Can still replace, newly added template url is marked safe to replace. |
737 ASSERT_TRUE(model()->CanAddAutogeneratedKeyword(ASCIIToUTF16("bar"), | 749 ASSERT_TRUE(model()->CanAddAutogeneratedKeyword(ASCIIToUTF16("bar"), |
738 GURL("http://foo.com"), NULL)); | 750 GURL("http://foo.com"), NULL)); |
739 | 751 |
740 // ResetTemplateURL marks the TemplateURL as unsafe to replace, so it should | 752 // ResetTemplateURL marks the TemplateURL as unsafe to replace, so it should |
741 // no longer be replaceable. | 753 // no longer be replaceable. |
742 model()->ResetTemplateURL(t_url, t_url->short_name(), t_url->keyword(), | 754 model()->ResetTemplateURL(t_url, t_url->short_name(), t_url->keyword(), |
743 t_url->url()); | 755 t_url->url()); |
744 | 756 |
(...skipping 15 matching lines...) Expand all Loading... | |
760 test_util()->VerifyLoad(); | 772 test_util()->VerifyLoad(); |
761 | 773 |
762 TemplateURLData data; | 774 TemplateURLData data; |
763 data.SetShortName(ASCIIToUTF16("a")); | 775 data.SetShortName(ASCIIToUTF16("a")); |
764 data.safe_for_autoreplace = true; | 776 data.safe_for_autoreplace = true; |
765 data.SetURL("http://url/{searchTerms}"); | 777 data.SetURL("http://url/{searchTerms}"); |
766 data.suggestions_url = "http://url2"; | 778 data.suggestions_url = "http://url2"; |
767 data.instant_url = "http://instant"; | 779 data.instant_url = "http://instant"; |
768 data.date_created = Time::FromTimeT(100); | 780 data.date_created = Time::FromTimeT(100); |
769 data.last_modified = Time::FromTimeT(100); | 781 data.last_modified = Time::FromTimeT(100); |
782 data.last_visited = Time::FromTimeT(100); | |
770 TemplateURL* t_url = model()->Add(base::MakeUnique<TemplateURL>(data)); | 783 TemplateURL* t_url = model()->Add(base::MakeUnique<TemplateURL>(data)); |
771 const TemplateURLID id = t_url->id(); | 784 const TemplateURLID id = t_url->id(); |
772 | 785 |
773 model()->SetUserSelectedDefaultSearchProvider(t_url); | 786 model()->SetUserSelectedDefaultSearchProvider(t_url); |
774 base::RunLoop().RunUntilIdle(); | 787 base::RunLoop().RunUntilIdle(); |
775 std::unique_ptr<TemplateURL> cloned_url( | 788 std::unique_ptr<TemplateURL> cloned_url( |
776 base::MakeUnique<TemplateURL>(t_url->data())); | 789 base::MakeUnique<TemplateURL>(t_url->data())); |
777 | 790 |
778 // Reset the model and don't load it. The template url we set as the default | 791 // Reset the model and don't load it. The template url we set as the default |
779 // should be pulled from prefs now. | 792 // should be pulled from prefs now. |
(...skipping 25 matching lines...) Expand all Loading... | |
805 ASSERT_TRUE(google); | 818 ASSERT_TRUE(google); |
806 model()->ResetTemplateURL(google, ASCIIToUTF16("trash"), ASCIIToUTF16("xxx"), | 819 model()->ResetTemplateURL(google, ASCIIToUTF16("trash"), ASCIIToUTF16("xxx"), |
807 "http://www.foo.com/s?q={searchTerms}"); | 820 "http://www.foo.com/s?q={searchTerms}"); |
808 EXPECT_EQ(ASCIIToUTF16("trash"), google->short_name()); | 821 EXPECT_EQ(ASCIIToUTF16("trash"), google->short_name()); |
809 EXPECT_EQ(ASCIIToUTF16("xxx"), google->keyword()); | 822 EXPECT_EQ(ASCIIToUTF16("xxx"), google->keyword()); |
810 | 823 |
811 // Add third-party default search engine. | 824 // Add third-party default search engine. |
812 TemplateURL* user_dse = AddKeywordWithDate( | 825 TemplateURL* user_dse = AddKeywordWithDate( |
813 "malware", "google.com", "http://www.goo.com/s?q={searchTerms}", | 826 "malware", "google.com", "http://www.goo.com/s?q={searchTerms}", |
814 std::string(), std::string(), std::string(), | 827 std::string(), std::string(), std::string(), |
815 true, "UTF-8", Time(), Time()); | 828 true, "UTF-8", Time(), Time(), Time()); |
816 model()->SetUserSelectedDefaultSearchProvider(user_dse); | 829 model()->SetUserSelectedDefaultSearchProvider(user_dse); |
817 EXPECT_EQ(user_dse, model()->GetDefaultSearchProvider()); | 830 EXPECT_EQ(user_dse, model()->GetDefaultSearchProvider()); |
818 | 831 |
819 // Remove bing. | 832 // Remove bing. |
820 TemplateURL* bing = model()->GetTemplateURLForKeyword( | 833 TemplateURL* bing = model()->GetTemplateURLForKeyword( |
821 ASCIIToUTF16("bing.com")); | 834 ASCIIToUTF16("bing.com")); |
822 ASSERT_TRUE(bing); | 835 ASSERT_TRUE(bing); |
823 model()->Remove(bing); | 836 model()->Remove(bing); |
824 EXPECT_FALSE(model()->GetTemplateURLForKeyword(ASCIIToUTF16("bing.com"))); | 837 EXPECT_FALSE(model()->GetTemplateURLForKeyword(ASCIIToUTF16("bing.com"))); |
825 | 838 |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
901 { "http://x/foo?q=b&q=xx", base::string16() }, | 914 { "http://x/foo?q=b&q=xx", base::string16() }, |
902 { "http://x/foo#query=xx", ASCIIToUTF16("xx") }, | 915 { "http://x/foo#query=xx", ASCIIToUTF16("xx") }, |
903 { "http://x/foo?q=b#query=xx", ASCIIToUTF16("xx") }, | 916 { "http://x/foo?q=b#query=xx", ASCIIToUTF16("xx") }, |
904 { "http://x/foo?q=b#q=xx", ASCIIToUTF16("b") }, | 917 { "http://x/foo?q=b#q=xx", ASCIIToUTF16("b") }, |
905 { "http://x/foo?query=b#q=xx", base::string16() }, | 918 { "http://x/foo?query=b#q=xx", base::string16() }, |
906 }; | 919 }; |
907 | 920 |
908 test_util()->ChangeModelToLoadState(); | 921 test_util()->ChangeModelToLoadState(); |
909 AddKeywordWithDate("name", "x", "http://x/foo?q={searchTerms}", | 922 AddKeywordWithDate("name", "x", "http://x/foo?q={searchTerms}", |
910 "http://sugg1", "http://x/foo#query={searchTerms}", | 923 "http://sugg1", "http://x/foo#query={searchTerms}", |
911 "http://icon1", false, "UTF-8;UTF-16", Time(), Time()); | 924 "http://icon1", false, "UTF-8;UTF-16", Time(), Time(), Time ()); |
Peter Kasting
2016/11/21 03:35:08
Nit: 80 columns (several places)
(Running git cl
ltian
2016/11/28 22:08:02
Done.
| |
912 | 925 |
913 for (size_t i = 0; i < arraysize(data); ++i) { | 926 for (size_t i = 0; i < arraysize(data); ++i) { |
914 TemplateURLService::URLVisitedDetails details = { | 927 TemplateURLService::URLVisitedDetails details = { |
915 GURL(data[i].url), false | 928 GURL(data[i].url), false |
916 }; | 929 }; |
917 model()->UpdateKeywordSearchTermsForURL(details); | 930 model()->UpdateKeywordSearchTermsForURL(details); |
918 EXPECT_EQ(data[i].term, test_util()->GetAndClearSearchTerm()); | 931 EXPECT_EQ(data[i].term, test_util()->GetAndClearSearchTerm()); |
919 } | 932 } |
920 } | 933 } |
921 | 934 |
922 TEST_F(TemplateURLServiceTest, DontUpdateKeywordSearchForNonReplaceable) { | 935 TEST_F(TemplateURLServiceTest, DontUpdateKeywordSearchForNonReplaceable) { |
923 struct TestData { | 936 struct TestData { |
924 const std::string url; | 937 const std::string url; |
925 } data[] = { | 938 } data[] = { |
926 { "http://foo/" }, | 939 { "http://foo/" }, |
927 { "http://x/bar?q=xx" }, | 940 { "http://x/bar?q=xx" }, |
928 { "http://x/foo?y=xx" }, | 941 { "http://x/foo?y=xx" }, |
929 }; | 942 }; |
930 | 943 |
931 test_util()->ChangeModelToLoadState(); | 944 test_util()->ChangeModelToLoadState(); |
932 AddKeywordWithDate("name", "x", "http://x/foo", "http://sugg1", std::string(), | 945 AddKeywordWithDate("name", "x", "http://x/foo", "http://sugg1", std::string(), |
933 "http://icon1", false, "UTF-8;UTF-16", Time(), Time()); | 946 "http://icon1", false, "UTF-8;UTF-16", Time(), Time(), Time ()); |
934 | 947 |
935 for (size_t i = 0; i < arraysize(data); ++i) { | 948 for (size_t i = 0; i < arraysize(data); ++i) { |
936 TemplateURLService::URLVisitedDetails details = { | 949 TemplateURLService::URLVisitedDetails details = { |
937 GURL(data[i].url), false | 950 GURL(data[i].url), false |
938 }; | 951 }; |
939 model()->UpdateKeywordSearchTermsForURL(details); | 952 model()->UpdateKeywordSearchTermsForURL(details); |
940 ASSERT_EQ(base::string16(), test_util()->GetAndClearSearchTerm()); | 953 ASSERT_EQ(base::string16(), test_util()->GetAndClearSearchTerm()); |
941 } | 954 } |
942 } | 955 } |
943 | 956 |
944 TEST_F(TemplateURLServiceWithoutFallbackTest, ChangeGoogleBaseValue) { | 957 TEST_F(TemplateURLServiceWithoutFallbackTest, ChangeGoogleBaseValue) { |
945 // NOTE: Do not load the prepopulate data, which also has a {google:baseURL} | 958 // NOTE: Do not load the prepopulate data, which also has a {google:baseURL} |
946 // keyword in it and would confuse this test. | 959 // keyword in it and would confuse this test. |
947 test_util()->ChangeModelToLoadState(); | 960 test_util()->ChangeModelToLoadState(); |
948 | 961 |
949 test_util()->SetGoogleBaseURL(GURL("http://google.com/")); | 962 test_util()->SetGoogleBaseURL(GURL("http://google.com/")); |
950 const TemplateURL* t_url = AddKeywordWithDate( | 963 const TemplateURL* t_url = AddKeywordWithDate( |
951 "name", "google.com", "{google:baseURL}?q={searchTerms}", "http://sugg1", | 964 "name", "google.com", "{google:baseURL}?q={searchTerms}", "http://sugg1", |
952 std::string(), "http://icon1", false, "UTF-8;UTF-16", Time(), Time()); | 965 std::string(), "http://icon1", false, "UTF-8;UTF-16", Time(), Time(), Time ()); |
953 ASSERT_EQ(t_url, model()->GetTemplateURLForHost("google.com")); | 966 ASSERT_EQ(t_url, model()->GetTemplateURLForHost("google.com")); |
954 EXPECT_EQ("google.com", t_url->url_ref().GetHost(search_terms_data())); | 967 EXPECT_EQ("google.com", t_url->url_ref().GetHost(search_terms_data())); |
955 EXPECT_EQ(ASCIIToUTF16("google.com"), t_url->keyword()); | 968 EXPECT_EQ(ASCIIToUTF16("google.com"), t_url->keyword()); |
956 | 969 |
957 // Change the Google base url. | 970 // Change the Google base url. |
958 test_util()->ResetObserverCount(); | 971 test_util()->ResetObserverCount(); |
959 test_util()->SetGoogleBaseURL(GURL("http://google.co.uk/")); | 972 test_util()->SetGoogleBaseURL(GURL("http://google.co.uk/")); |
960 VerifyObserverCount(1); | 973 VerifyObserverCount(1); |
961 | 974 |
962 // Make sure the host->TemplateURL map was updated appropriately. | 975 // Make sure the host->TemplateURL map was updated appropriately. |
963 ASSERT_EQ(t_url, model()->GetTemplateURLForHost("google.co.uk")); | 976 ASSERT_EQ(t_url, model()->GetTemplateURLForHost("google.co.uk")); |
964 EXPECT_TRUE(model()->GetTemplateURLForHost("google.com") == NULL); | 977 EXPECT_TRUE(model()->GetTemplateURLForHost("google.com") == NULL); |
965 EXPECT_EQ("google.co.uk", t_url->url_ref().GetHost(search_terms_data())); | 978 EXPECT_EQ("google.co.uk", t_url->url_ref().GetHost(search_terms_data())); |
966 EXPECT_EQ(ASCIIToUTF16("google.co.uk"), t_url->keyword()); | 979 EXPECT_EQ(ASCIIToUTF16("google.co.uk"), t_url->keyword()); |
967 EXPECT_EQ("http://google.co.uk/?q=x", t_url->url_ref().ReplaceSearchTerms( | 980 EXPECT_EQ("http://google.co.uk/?q=x", t_url->url_ref().ReplaceSearchTerms( |
968 TemplateURLRef::SearchTermsArgs(ASCIIToUTF16("x")), search_terms_data())); | 981 TemplateURLRef::SearchTermsArgs(ASCIIToUTF16("x")), search_terms_data())); |
969 | 982 |
970 // Now add a manual entry and then change the Google base URL such that the | 983 // Now add a manual entry and then change the Google base URL such that the |
971 // autogenerated Google search keyword would conflict. | 984 // autogenerated Google search keyword would conflict. |
972 TemplateURL* manual = AddKeywordWithDate( | 985 TemplateURL* manual = AddKeywordWithDate( |
973 "manual", "google.de", "http://google.de/search?q={searchTerms}", | 986 "manual", "google.de", "http://google.de/search?q={searchTerms}", |
974 std::string(), std::string(), std::string(), false, "UTF-8", Time(), | 987 std::string(), std::string(), std::string(), false, "UTF-8", Time(), |
975 Time()); | 988 Time(), Time()); |
976 test_util()->SetGoogleBaseURL(GURL("http://google.de")); | 989 test_util()->SetGoogleBaseURL(GURL("http://google.de")); |
977 | 990 |
978 // Verify that the manual entry is untouched, and the autogenerated keyword | 991 // Verify that the manual entry is untouched, and the autogenerated keyword |
979 // has not changed. | 992 // has not changed. |
980 ASSERT_EQ(manual, | 993 ASSERT_EQ(manual, |
981 model()->GetTemplateURLForKeyword(ASCIIToUTF16("google.de"))); | 994 model()->GetTemplateURLForKeyword(ASCIIToUTF16("google.de"))); |
982 EXPECT_EQ("google.de", manual->url_ref().GetHost(search_terms_data())); | 995 EXPECT_EQ("google.de", manual->url_ref().GetHost(search_terms_data())); |
983 ASSERT_EQ(t_url, | 996 ASSERT_EQ(t_url, |
984 model()->GetTemplateURLForKeyword(ASCIIToUTF16("google.co.uk"))); | 997 model()->GetTemplateURLForKeyword(ASCIIToUTF16("google.co.uk"))); |
985 EXPECT_EQ("google.de", t_url->url_ref().GetHost(search_terms_data())); | 998 EXPECT_EQ("google.de", t_url->url_ref().GetHost(search_terms_data())); |
(...skipping 16 matching lines...) Expand all Loading... | |
1002 // KEYWORD visits. | 1015 // KEYWORD visits. |
1003 TEST_F(TemplateURLServiceTest, GenerateVisitOnKeyword) { | 1016 TEST_F(TemplateURLServiceTest, GenerateVisitOnKeyword) { |
1004 test_util()->profile()->CreateBookmarkModel(false); | 1017 test_util()->profile()->CreateBookmarkModel(false); |
1005 ASSERT_TRUE(test_util()->profile()->CreateHistoryService(true, false)); | 1018 ASSERT_TRUE(test_util()->profile()->CreateHistoryService(true, false)); |
1006 test_util()->ResetModel(true); | 1019 test_util()->ResetModel(true); |
1007 | 1020 |
1008 // Create a keyword. | 1021 // Create a keyword. |
1009 TemplateURL* t_url = AddKeywordWithDate( | 1022 TemplateURL* t_url = AddKeywordWithDate( |
1010 "keyword", "keyword", "http://foo.com/foo?query={searchTerms}", | 1023 "keyword", "keyword", "http://foo.com/foo?query={searchTerms}", |
1011 "http://sugg1", std::string(), "http://icon1", true, "UTF-8;UTF-16", | 1024 "http://sugg1", std::string(), "http://icon1", true, "UTF-8;UTF-16", |
1012 base::Time::Now(), base::Time::Now()); | 1025 base::Time::Now(), base::Time::Now(), base::Time::Now()); |
Peter Kasting
2016/11/21 03:35:08
Is it important that we set this to Time::Now()?
ltian
2016/11/28 22:08:02
Done.
| |
1013 | 1026 |
1014 // Add a visit that matches the url of the keyword. | 1027 // Add a visit that matches the url of the keyword. |
1015 history::HistoryService* history = HistoryServiceFactory::GetForProfile( | 1028 history::HistoryService* history = HistoryServiceFactory::GetForProfile( |
1016 test_util()->profile(), ServiceAccessType::EXPLICIT_ACCESS); | 1029 test_util()->profile(), ServiceAccessType::EXPLICIT_ACCESS); |
1017 history->AddPage( | 1030 history->AddPage( |
1018 GURL(t_url->url_ref().ReplaceSearchTerms( | 1031 GURL(t_url->url_ref().ReplaceSearchTerms( |
1019 TemplateURLRef::SearchTermsArgs(ASCIIToUTF16("blah")), | 1032 TemplateURLRef::SearchTermsArgs(ASCIIToUTF16("blah")), |
1020 search_terms_data())), | 1033 search_terms_data())), |
1021 base::Time::Now(), NULL, 0, GURL(), history::RedirectList(), | 1034 base::Time::Now(), NULL, 0, GURL(), history::RedirectList(), |
1022 ui::PAGE_TRANSITION_KEYWORD, history::SOURCE_BROWSED, false); | 1035 ui::PAGE_TRANSITION_KEYWORD, history::SOURCE_BROWSED, false); |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1213 // the default search as managed. Also check that we are getting the right | 1226 // the default search as managed. Also check that we are getting the right |
1214 // values. | 1227 // values. |
1215 TEST_F(TemplateURLServiceTest, TestManagedDefaultSearch) { | 1228 TEST_F(TemplateURLServiceTest, TestManagedDefaultSearch) { |
1216 test_util()->VerifyLoad(); | 1229 test_util()->VerifyLoad(); |
1217 const size_t initial_count = model()->GetTemplateURLs().size(); | 1230 const size_t initial_count = model()->GetTemplateURLs().size(); |
1218 test_util()->ResetObserverCount(); | 1231 test_util()->ResetObserverCount(); |
1219 | 1232 |
1220 // Set a regular default search provider. | 1233 // Set a regular default search provider. |
1221 TemplateURL* regular_default = AddKeywordWithDate( | 1234 TemplateURL* regular_default = AddKeywordWithDate( |
1222 "name1", "key1", "http://foo1/{searchTerms}", "http://sugg1", | 1235 "name1", "key1", "http://foo1/{searchTerms}", "http://sugg1", |
1223 std::string(), "http://icon1", true, "UTF-8;UTF-16", Time(), Time()); | 1236 std::string(), "http://icon1", true, "UTF-8;UTF-16", Time(), Time(), Time( )); |
1224 VerifyObserverCount(1); | 1237 VerifyObserverCount(1); |
1225 model()->SetUserSelectedDefaultSearchProvider(regular_default); | 1238 model()->SetUserSelectedDefaultSearchProvider(regular_default); |
1226 // Adding the URL and setting the default search provider should have caused | 1239 // Adding the URL and setting the default search provider should have caused |
1227 // notifications. | 1240 // notifications. |
1228 VerifyObserverCount(1); | 1241 VerifyObserverCount(1); |
1229 EXPECT_FALSE(model()->is_default_search_managed()); | 1242 EXPECT_FALSE(model()->is_default_search_managed()); |
1230 EXPECT_EQ(initial_count + 1, model()->GetTemplateURLs().size()); | 1243 EXPECT_EQ(initial_count + 1, model()->GetTemplateURLs().size()); |
1231 | 1244 |
1232 // Set a managed preference that establishes a default search provider. | 1245 // Set a managed preference that establishes a default search provider. |
1233 const char kName[] = "test1"; | 1246 const char kName[] = "test1"; |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1409 ASSERT_FALSE(loaded_url == NULL); | 1422 ASSERT_FALSE(loaded_url == NULL); |
1410 EXPECT_EQ(4U, loaded_url->input_encodings().size()); | 1423 EXPECT_EQ(4U, loaded_url->input_encodings().size()); |
1411 } | 1424 } |
1412 | 1425 |
1413 TEST_F(TemplateURLServiceTest, DefaultExtensionEngine) { | 1426 TEST_F(TemplateURLServiceTest, DefaultExtensionEngine) { |
1414 test_util()->VerifyLoad(); | 1427 test_util()->VerifyLoad(); |
1415 // Add third-party default search engine. | 1428 // Add third-party default search engine. |
1416 TemplateURL* user_dse = AddKeywordWithDate( | 1429 TemplateURL* user_dse = AddKeywordWithDate( |
1417 "user", "user", "http://www.goo.com/s?q={searchTerms}", | 1430 "user", "user", "http://www.goo.com/s?q={searchTerms}", |
1418 std::string(), std::string(), std::string(), | 1431 std::string(), std::string(), std::string(), |
1419 true, "UTF-8", Time(), Time()); | 1432 true, "UTF-8", Time(), Time(), Time()); |
1420 model()->SetUserSelectedDefaultSearchProvider(user_dse); | 1433 model()->SetUserSelectedDefaultSearchProvider(user_dse); |
1421 EXPECT_EQ(user_dse, model()->GetDefaultSearchProvider()); | 1434 EXPECT_EQ(user_dse, model()->GetDefaultSearchProvider()); |
1422 | 1435 |
1423 std::unique_ptr<TemplateURL> ext_dse = CreateKeywordWithDate( | 1436 std::unique_ptr<TemplateURL> ext_dse = CreateKeywordWithDate( |
1424 model(), "ext", "ext", "http://www.search.com/s?q={searchTerms}", | 1437 model(), "ext", "ext", "http://www.search.com/s?q={searchTerms}", |
1425 std::string(), std::string(), std::string(), true, kPrepopulatedId, | 1438 std::string(), std::string(), std::string(), true, kPrepopulatedId, |
1426 "UTF-8", Time(), Time(), TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION); | 1439 "UTF-8", Time(), Time(), Time(), |
1440 TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION); | |
1427 std::unique_ptr<TemplateURL::AssociatedExtensionInfo> extension_info( | 1441 std::unique_ptr<TemplateURL::AssociatedExtensionInfo> extension_info( |
1428 new TemplateURL::AssociatedExtensionInfo("ext")); | 1442 new TemplateURL::AssociatedExtensionInfo("ext")); |
1429 extension_info->wants_to_be_default_engine = true; | 1443 extension_info->wants_to_be_default_engine = true; |
1430 TemplateURL* ext_dse_ptr = model()->AddExtensionControlledTURL( | 1444 TemplateURL* ext_dse_ptr = model()->AddExtensionControlledTURL( |
1431 std::move(ext_dse), std::move(extension_info)); | 1445 std::move(ext_dse), std::move(extension_info)); |
1432 EXPECT_EQ(ext_dse_ptr, model()->GetDefaultSearchProvider()); | 1446 EXPECT_EQ(ext_dse_ptr, model()->GetDefaultSearchProvider()); |
1433 | 1447 |
1434 model()->RemoveExtensionControlledTURL( | 1448 model()->RemoveExtensionControlledTURL( |
1435 "ext", TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION); | 1449 "ext", TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION); |
1436 ExpectSimilar(user_dse, model()->GetDefaultSearchProvider()); | 1450 ExpectSimilar(user_dse, model()->GetDefaultSearchProvider()); |
1437 } | 1451 } |
1438 | 1452 |
1439 TEST_F(TemplateURLServiceTest, ExtensionEnginesNotPersist) { | 1453 TEST_F(TemplateURLServiceTest, ExtensionEnginesNotPersist) { |
1440 test_util()->VerifyLoad(); | 1454 test_util()->VerifyLoad(); |
1441 // Add third-party default search engine. | 1455 // Add third-party default search engine. |
1442 TemplateURL* user_dse = AddKeywordWithDate( | 1456 TemplateURL* user_dse = AddKeywordWithDate( |
1443 "user", "user", "http://www.goo.com/s?q={searchTerms}", | 1457 "user", "user", "http://www.goo.com/s?q={searchTerms}", |
1444 std::string(), std::string(), std::string(), | 1458 std::string(), std::string(), std::string(), |
1445 true, "UTF-8", Time(), Time()); | 1459 true, "UTF-8", Time(), Time(), Time()); |
1446 model()->SetUserSelectedDefaultSearchProvider(user_dse); | 1460 model()->SetUserSelectedDefaultSearchProvider(user_dse); |
1447 EXPECT_EQ(user_dse, model()->GetDefaultSearchProvider()); | 1461 EXPECT_EQ(user_dse, model()->GetDefaultSearchProvider()); |
1448 | 1462 |
1449 std::unique_ptr<TemplateURL> ext_dse = CreateKeywordWithDate( | 1463 std::unique_ptr<TemplateURL> ext_dse = CreateKeywordWithDate( |
1450 model(), "ext1", "ext1", "http://www.ext1.com/s?q={searchTerms}", | 1464 model(), "ext1", "ext1", "http://www.ext1.com/s?q={searchTerms}", |
1451 std::string(), std::string(), std::string(), true, 0, "UTF-8", Time(), | 1465 std::string(), std::string(), std::string(), true, 0, "UTF-8", Time(), |
1452 Time(), TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION); | 1466 Time(), Time(), TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION); |
1453 std::unique_ptr<TemplateURL::AssociatedExtensionInfo> extension_info( | 1467 std::unique_ptr<TemplateURL::AssociatedExtensionInfo> extension_info( |
1454 new TemplateURL::AssociatedExtensionInfo("ext1")); | 1468 new TemplateURL::AssociatedExtensionInfo("ext1")); |
1455 extension_info->wants_to_be_default_engine = false; | 1469 extension_info->wants_to_be_default_engine = false; |
1456 model()->AddExtensionControlledTURL(std::move(ext_dse), | 1470 model()->AddExtensionControlledTURL(std::move(ext_dse), |
1457 std::move(extension_info)); | 1471 std::move(extension_info)); |
1458 EXPECT_EQ(user_dse, model()->GetDefaultSearchProvider()); | 1472 EXPECT_EQ(user_dse, model()->GetDefaultSearchProvider()); |
1459 | 1473 |
1460 ext_dse = CreateKeywordWithDate( | 1474 ext_dse = CreateKeywordWithDate( |
1461 model(), "ext2", "ext2", "http://www.ext2.com/s?q={searchTerms}", | 1475 model(), "ext2", "ext2", "http://www.ext2.com/s?q={searchTerms}", |
1462 std::string(), std::string(), std::string(), true, kPrepopulatedId, | 1476 std::string(), std::string(), std::string(), true, kPrepopulatedId, |
1463 "UTF-8", Time(), Time(), TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION); | 1477 "UTF-8", Time(), Time(), Time(), |
1478 TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION); | |
1464 extension_info.reset(new TemplateURL::AssociatedExtensionInfo("ext2")); | 1479 extension_info.reset(new TemplateURL::AssociatedExtensionInfo("ext2")); |
1465 extension_info->wants_to_be_default_engine = true; | 1480 extension_info->wants_to_be_default_engine = true; |
1466 TemplateURL* ext_dse_ptr = model()->AddExtensionControlledTURL( | 1481 TemplateURL* ext_dse_ptr = model()->AddExtensionControlledTURL( |
1467 std::move(ext_dse), std::move(extension_info)); | 1482 std::move(ext_dse), std::move(extension_info)); |
1468 EXPECT_EQ(ext_dse_ptr, model()->GetDefaultSearchProvider()); | 1483 EXPECT_EQ(ext_dse_ptr, model()->GetDefaultSearchProvider()); |
1469 | 1484 |
1470 test_util()->ResetModel(true); | 1485 test_util()->ResetModel(true); |
1471 user_dse = model()->GetTemplateURLForKeyword(ASCIIToUTF16("user")); | 1486 user_dse = model()->GetTemplateURLForKeyword(ASCIIToUTF16("user")); |
1472 ExpectSimilar(user_dse, model()->GetDefaultSearchProvider()); | 1487 ExpectSimilar(user_dse, model()->GetDefaultSearchProvider()); |
1473 EXPECT_FALSE(model()->GetTemplateURLForKeyword(ASCIIToUTF16("ext1"))); | 1488 EXPECT_FALSE(model()->GetTemplateURLForKeyword(ASCIIToUTF16("ext1"))); |
(...skipping 25 matching lines...) Expand all Loading... | |
1499 data.search_terms_replacement_key = kSearchTermsReplacementKey; | 1514 data.search_terms_replacement_key = kSearchTermsReplacementKey; |
1500 std::unique_ptr<TemplateURL> expected_managed_default(new TemplateURL(data)); | 1515 std::unique_ptr<TemplateURL> expected_managed_default(new TemplateURL(data)); |
1501 EXPECT_TRUE(model()->is_default_search_managed()); | 1516 EXPECT_TRUE(model()->is_default_search_managed()); |
1502 const TemplateURL* actual_managed_default = | 1517 const TemplateURL* actual_managed_default = |
1503 model()->GetDefaultSearchProvider(); | 1518 model()->GetDefaultSearchProvider(); |
1504 ExpectSimilar(expected_managed_default.get(), actual_managed_default); | 1519 ExpectSimilar(expected_managed_default.get(), actual_managed_default); |
1505 | 1520 |
1506 std::unique_ptr<TemplateURL> ext_dse = CreateKeywordWithDate( | 1521 std::unique_ptr<TemplateURL> ext_dse = CreateKeywordWithDate( |
1507 model(), "ext1", "ext1", "http://www.ext1.com/s?q={searchTerms}", | 1522 model(), "ext1", "ext1", "http://www.ext1.com/s?q={searchTerms}", |
1508 std::string(), std::string(), std::string(), true, kPrepopulatedId, | 1523 std::string(), std::string(), std::string(), true, kPrepopulatedId, |
1509 "UTF-8", Time(), Time(), TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION); | 1524 "UTF-8", Time(), Time(), Time(), |
1525 TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION); | |
1510 std::unique_ptr<TemplateURL::AssociatedExtensionInfo> extension_info( | 1526 std::unique_ptr<TemplateURL::AssociatedExtensionInfo> extension_info( |
1511 new TemplateURL::AssociatedExtensionInfo("ext1")); | 1527 new TemplateURL::AssociatedExtensionInfo("ext1")); |
1512 extension_info->wants_to_be_default_engine = true; | 1528 extension_info->wants_to_be_default_engine = true; |
1513 TemplateURL* ext_dse_ptr = model()->AddExtensionControlledTURL( | 1529 TemplateURL* ext_dse_ptr = model()->AddExtensionControlledTURL( |
1514 std::move(ext_dse), std::move(extension_info)); | 1530 std::move(ext_dse), std::move(extension_info)); |
1515 EXPECT_EQ(ext_dse_ptr, | 1531 EXPECT_EQ(ext_dse_ptr, |
1516 model()->GetTemplateURLForKeyword(ASCIIToUTF16("ext1"))); | 1532 model()->GetTemplateURLForKeyword(ASCIIToUTF16("ext1"))); |
1517 EXPECT_TRUE(model()->is_default_search_managed()); | 1533 EXPECT_TRUE(model()->is_default_search_managed()); |
1518 actual_managed_default = model()->GetDefaultSearchProvider(); | 1534 actual_managed_default = model()->GetDefaultSearchProvider(); |
1519 ExpectSimilar(expected_managed_default.get(), actual_managed_default); | 1535 ExpectSimilar(expected_managed_default.get(), actual_managed_default); |
1520 } | 1536 } |
1537 | |
1538 TEST_F(TemplateURLServiceTest, LastVisitedTimeUpdate) { | |
1539 test_util()->VerifyLoad(); | |
1540 TemplateURL* original_url = AddKeywordWithDate( | |
1541 "name1", "key1", "http://foo1","http://suggest1", | |
1542 std::string(), "http://icon1", true, "UTF-8;UTF-16", | |
1543 Time(), Time(), Time()); | |
1544 base::Time original_last_visited = original_url->last_visited(); | |
Peter Kasting
2016/11/21 03:35:08
Nit: Can be const (2 places)
ltian
2016/11/28 22:08:02
Done.
| |
1545 model()->UpdateTemplateURLVisitTime(original_url); | |
1546 TemplateURL* modified_url = model()->GetTemplateURLForKeyword( | |
Peter Kasting
2016/11/21 03:35:08
Nit: If you follow my next comment, then this coul
ltian
2016/11/28 22:08:01
git cl format does as you suggest.
Peter Kasting
2016/12/01 07:38:24
"Inlined into the next statement" isn't about line
| |
1547 ASCIIToUTF16("key1")); | |
1548 base::Time modifed_last_visited = modified_url->last_visited(); | |
1549 EXPECT_NE(original_last_visited, modified_url->last_visited()); | |
Peter Kasting
2016/11/21 03:35:08
Nit: Use |modifed_last_visited|
ltian
2016/11/28 22:08:01
Done.
| |
1550 test_util()->ResetModel(true); | |
1551 TemplateURL* reloaded_url = model()->GetTemplateURLForKeyword( | |
Peter Kasting
2016/11/21 03:35:08
Nit: Prefer to linebreak after '=' rather than in
ltian
2016/11/28 22:08:02
Done.
| |
1552 ASCIIToUTF16("key1")); | |
1553 // Times are stored with a granularity of one second, there is a loss | |
1554 // of precision when serializing and deserializing the timestamps. | |
Peter Kasting
2016/11/21 03:35:08
Nit: Comment not necessary (this is just explainin
ltian
2016/11/28 22:08:02
Done.
| |
1555 AssertTimesEqual(modifed_last_visited, reloaded_url ->last_visited()); | |
Peter Kasting
2016/11/21 03:35:08
Nit: No space before ->
ltian
2016/11/28 22:08:02
Done.
| |
1556 | |
1557 } | |
OLD | NEW |