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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 const std::string& keyword, | 71 const std::string& keyword, |
72 const std::string& url, | 72 const std::string& url, |
73 const std::string& suggest_url, | 73 const std::string& suggest_url, |
74 const std::string& alternate_url, | 74 const std::string& alternate_url, |
75 const std::string& favicon_url, | 75 const std::string& favicon_url, |
76 bool safe_for_autoreplace, | 76 bool safe_for_autoreplace, |
77 int prepopulate_id, | 77 int prepopulate_id, |
78 const std::string& encodings, | 78 const std::string& encodings, |
79 Time date_created, | 79 Time date_created, |
80 Time last_modified, | 80 Time last_modified, |
| 81 Time last_visited, |
81 TemplateURL::Type type = TemplateURL::NORMAL) { | 82 TemplateURL::Type type = TemplateURL::NORMAL) { |
82 TemplateURLData data; | 83 TemplateURLData data; |
83 data.SetShortName(base::UTF8ToUTF16(short_name)); | 84 data.SetShortName(base::UTF8ToUTF16(short_name)); |
84 data.SetKeyword(base::UTF8ToUTF16(keyword)); | 85 data.SetKeyword(base::UTF8ToUTF16(keyword)); |
85 data.SetURL(url); | 86 data.SetURL(url); |
86 data.suggestions_url = suggest_url; | 87 data.suggestions_url = suggest_url; |
87 if (!alternate_url.empty()) | 88 if (!alternate_url.empty()) |
88 data.alternate_urls.push_back(alternate_url); | 89 data.alternate_urls.push_back(alternate_url); |
89 data.favicon_url = GURL(favicon_url); | 90 data.favicon_url = GURL(favicon_url); |
90 data.safe_for_autoreplace = safe_for_autoreplace; | 91 data.safe_for_autoreplace = safe_for_autoreplace; |
91 data.prepopulate_id = prepopulate_id; | 92 data.prepopulate_id = prepopulate_id; |
92 data.input_encodings = base::SplitString( | 93 data.input_encodings = base::SplitString( |
93 encodings, ";", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); | 94 encodings, ";", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
94 data.date_created = date_created; | 95 data.date_created = date_created; |
95 data.last_modified = last_modified; | 96 data.last_modified = last_modified; |
| 97 data.last_visited = last_visited; |
96 return base::MakeUnique<TemplateURL>(data, type); | 98 return base::MakeUnique<TemplateURL>(data, type); |
97 } | 99 } |
98 | 100 |
99 TemplateURL* AddKeywordWithDate( | 101 TemplateURL* AddKeywordWithDate(TemplateURLService* model, |
100 TemplateURLService* model, | 102 const std::string& short_name, |
101 const std::string& short_name, | 103 const std::string& keyword, |
102 const std::string& keyword, | 104 const std::string& url, |
103 const std::string& url, | 105 const std::string& suggest_url, |
104 const std::string& suggest_url, | 106 const std::string& alternate_url, |
105 const std::string& alternate_url, | 107 const std::string& favicon_url, |
106 const std::string& favicon_url, | 108 bool safe_for_autoreplace, |
107 bool safe_for_autoreplace, | 109 const std::string& encodings, |
108 const std::string& encodings, | 110 Time date_created, |
109 Time date_created, | 111 Time last_modified, |
110 Time last_modified) { | 112 Time last_visited) { |
111 TemplateURL* t_url = model->Add(CreateKeywordWithDate( | 113 TemplateURL* t_url = model->Add(CreateKeywordWithDate( |
112 model, short_name, keyword, url, suggest_url, alternate_url, favicon_url, | 114 model, short_name, keyword, url, suggest_url, alternate_url, favicon_url, |
113 safe_for_autoreplace, 0, encodings, date_created, last_modified)); | 115 safe_for_autoreplace, 0, encodings, date_created, last_modified, |
| 116 last_visited)); |
114 EXPECT_NE(0, t_url->id()); | 117 EXPECT_NE(0, t_url->id()); |
115 return t_url; | 118 return t_url; |
116 } | 119 } |
117 | 120 |
118 // Checks that the two TemplateURLs are similar. It does not check the id, the | 121 // Checks that the two TemplateURLs are similar. It does not check the id or |
119 // date_created or the last_modified time. Neither pointer should be NULL. | 122 // any time-related fields. Neither pointer should be NULL. |
120 void ExpectSimilar(const TemplateURL* expected, const TemplateURL* actual) { | 123 void ExpectSimilar(const TemplateURL* expected, const TemplateURL* actual) { |
121 ASSERT_TRUE(expected != NULL); | 124 ASSERT_TRUE(expected != NULL); |
122 ASSERT_TRUE(actual != NULL); | 125 ASSERT_TRUE(actual != NULL); |
123 EXPECT_EQ(expected->short_name(), actual->short_name()); | 126 EXPECT_EQ(expected->short_name(), actual->short_name()); |
124 EXPECT_EQ(expected->keyword(), actual->keyword()); | 127 EXPECT_EQ(expected->keyword(), actual->keyword()); |
125 EXPECT_EQ(expected->url(), actual->url()); | 128 EXPECT_EQ(expected->url(), actual->url()); |
126 EXPECT_EQ(expected->suggestions_url(), actual->suggestions_url()); | 129 EXPECT_EQ(expected->suggestions_url(), actual->suggestions_url()); |
127 EXPECT_EQ(expected->favicon_url(), actual->favicon_url()); | 130 EXPECT_EQ(expected->favicon_url(), actual->favicon_url()); |
128 EXPECT_EQ(expected->alternate_urls(), actual->alternate_urls()); | 131 EXPECT_EQ(expected->alternate_urls(), actual->alternate_urls()); |
129 EXPECT_EQ(expected->safe_for_autoreplace(), actual->safe_for_autoreplace()); | 132 EXPECT_EQ(expected->safe_for_autoreplace(), actual->safe_for_autoreplace()); |
(...skipping 30 matching lines...) Expand all Loading... |
160 | 163 |
161 TemplateURL* AddKeywordWithDate(const std::string& short_name, | 164 TemplateURL* AddKeywordWithDate(const std::string& short_name, |
162 const std::string& keyword, | 165 const std::string& keyword, |
163 const std::string& url, | 166 const std::string& url, |
164 const std::string& suggest_url, | 167 const std::string& suggest_url, |
165 const std::string& alternate_url, | 168 const std::string& alternate_url, |
166 const std::string& favicon_url, | 169 const std::string& favicon_url, |
167 bool safe_for_autoreplace, | 170 bool safe_for_autoreplace, |
168 const std::string& encodings, | 171 const std::string& encodings, |
169 Time date_created, | 172 Time date_created, |
170 Time last_modified); | 173 Time last_modified, |
| 174 Time last_visited); |
171 | 175 |
172 // Verifies the two TemplateURLs are equal. | 176 // Verifies the two TemplateURLs are equal. |
173 void AssertEquals(const TemplateURL& expected, const TemplateURL& actual); | 177 void AssertEquals(const TemplateURL& expected, const TemplateURL& actual); |
174 | 178 |
175 // Verifies the two timestamps are equal, within the expected degree of | 179 // Verifies the two timestamps are equal, within the expected degree of |
176 // precision. | 180 // precision. |
177 void AssertTimesEqual(const base::Time& expected, const base::Time& actual); | 181 void AssertTimesEqual(const base::Time& expected, const base::Time& actual); |
178 | 182 |
179 // Create an URL that appears to have been prepopulated, but won't be in the | 183 // Create an URL that appears to have been prepopulated, but won't be in the |
180 // current data. | 184 // current data. |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 TemplateURL* TemplateURLServiceTest::AddKeywordWithDate( | 232 TemplateURL* TemplateURLServiceTest::AddKeywordWithDate( |
229 const std::string& short_name, | 233 const std::string& short_name, |
230 const std::string& keyword, | 234 const std::string& keyword, |
231 const std::string& url, | 235 const std::string& url, |
232 const std::string& suggest_url, | 236 const std::string& suggest_url, |
233 const std::string& alternate_url, | 237 const std::string& alternate_url, |
234 const std::string& favicon_url, | 238 const std::string& favicon_url, |
235 bool safe_for_autoreplace, | 239 bool safe_for_autoreplace, |
236 const std::string& encodings, | 240 const std::string& encodings, |
237 Time date_created, | 241 Time date_created, |
238 Time last_modified) { | 242 Time last_modified, |
| 243 Time last_visited) { |
239 return ::AddKeywordWithDate(model(), short_name, keyword, url, suggest_url, | 244 return ::AddKeywordWithDate(model(), short_name, keyword, url, suggest_url, |
240 alternate_url, favicon_url, safe_for_autoreplace, | 245 alternate_url, favicon_url, safe_for_autoreplace, |
241 encodings, date_created, last_modified); | 246 encodings, date_created, last_modified, |
| 247 last_visited); |
242 } | 248 } |
243 | 249 |
244 void TemplateURLServiceTest::AssertEquals(const TemplateURL& expected, | 250 void TemplateURLServiceTest::AssertEquals(const TemplateURL& expected, |
245 const TemplateURL& actual) { | 251 const TemplateURL& actual) { |
246 ASSERT_EQ(expected.short_name(), actual.short_name()); | 252 ASSERT_EQ(expected.short_name(), actual.short_name()); |
247 ASSERT_EQ(expected.keyword(), actual.keyword()); | 253 ASSERT_EQ(expected.keyword(), actual.keyword()); |
248 ASSERT_EQ(expected.url(), actual.url()); | 254 ASSERT_EQ(expected.url(), actual.url()); |
249 ASSERT_EQ(expected.suggestions_url(), actual.suggestions_url()); | 255 ASSERT_EQ(expected.suggestions_url(), actual.suggestions_url()); |
250 ASSERT_EQ(expected.favicon_url(), actual.favicon_url()); | 256 ASSERT_EQ(expected.favicon_url(), actual.favicon_url()); |
251 ASSERT_EQ(expected.alternate_urls(), actual.alternate_urls()); | 257 ASSERT_EQ(expected.alternate_urls(), actual.alternate_urls()); |
252 ASSERT_EQ(expected.prepopulate_id(), actual.prepopulate_id()); | 258 ASSERT_EQ(expected.prepopulate_id(), actual.prepopulate_id()); |
253 ASSERT_EQ(expected.safe_for_autoreplace(), actual.safe_for_autoreplace()); | 259 ASSERT_EQ(expected.safe_for_autoreplace(), actual.safe_for_autoreplace()); |
254 ASSERT_EQ(expected.input_encodings(), actual.input_encodings()); | 260 ASSERT_EQ(expected.input_encodings(), actual.input_encodings()); |
255 ASSERT_EQ(expected.id(), actual.id()); | 261 ASSERT_EQ(expected.id(), actual.id()); |
256 ASSERT_EQ(expected.date_created(), actual.date_created()); | 262 ASSERT_EQ(expected.date_created(), actual.date_created()); |
257 AssertTimesEqual(expected.last_modified(), actual.last_modified()); | 263 AssertTimesEqual(expected.last_modified(), actual.last_modified()); |
| 264 ASSERT_EQ(expected.last_visited(), actual.last_visited()); |
258 ASSERT_EQ(expected.sync_guid(), actual.sync_guid()); | 265 ASSERT_EQ(expected.sync_guid(), actual.sync_guid()); |
259 ASSERT_EQ(expected.search_terms_replacement_key(), | 266 ASSERT_EQ(expected.search_terms_replacement_key(), |
260 actual.search_terms_replacement_key()); | 267 actual.search_terms_replacement_key()); |
261 } | 268 } |
262 | 269 |
263 void TemplateURLServiceTest::AssertTimesEqual(const base::Time& expected, | 270 void TemplateURLServiceTest::AssertTimesEqual(const base::Time& expected, |
264 const base::Time& actual) { | 271 const base::Time& actual) { |
265 // Because times are stored with a granularity of one second, there is a loss | 272 // Because times are stored with a granularity of one second, there is a loss |
266 // of precision when serializing and deserializing the timestamps. Hence, only | 273 // of precision when serializing and deserializing the timestamps. Hence, only |
267 // expect timestamps to be equal to within one second of one another. | 274 // expect timestamps to be equal to within one second of one another. |
268 ASSERT_LT((expected - actual).magnitude(), base::TimeDelta::FromSeconds(1)); | 275 ASSERT_LT((expected - actual).magnitude(), base::TimeDelta::FromSeconds(1)); |
269 } | 276 } |
270 | 277 |
271 std::unique_ptr<TemplateURL> TemplateURLServiceTest::CreatePreloadedTemplateURL( | 278 std::unique_ptr<TemplateURL> TemplateURLServiceTest::CreatePreloadedTemplateURL( |
272 bool safe_for_autoreplace, | 279 bool safe_for_autoreplace, |
273 int prepopulate_id) { | 280 int prepopulate_id) { |
274 TemplateURLData data; | 281 TemplateURLData data; |
275 data.SetShortName(ASCIIToUTF16("unittest")); | 282 data.SetShortName(ASCIIToUTF16("unittest")); |
276 data.SetKeyword(ASCIIToUTF16("unittest")); | 283 data.SetKeyword(ASCIIToUTF16("unittest")); |
277 data.SetURL("http://www.unittest.com/{searchTerms}"); | 284 data.SetURL("http://www.unittest.com/{searchTerms}"); |
278 data.favicon_url = GURL("http://favicon.url"); | 285 data.favicon_url = GURL("http://favicon.url"); |
279 data.safe_for_autoreplace = safe_for_autoreplace; | 286 data.safe_for_autoreplace = safe_for_autoreplace; |
280 data.input_encodings.push_back("UTF-8"); | 287 data.input_encodings.push_back("UTF-8"); |
281 data.date_created = Time::FromTimeT(100); | 288 data.date_created = Time::FromTimeT(100); |
282 data.last_modified = Time::FromTimeT(100); | 289 data.last_modified = Time::FromTimeT(100); |
| 290 data.last_visited = Time::FromTimeT(100); |
283 data.prepopulate_id = prepopulate_id; | 291 data.prepopulate_id = prepopulate_id; |
284 return base::MakeUnique<TemplateURL>(data); | 292 return base::MakeUnique<TemplateURL>(data); |
285 } | 293 } |
286 | 294 |
287 void TemplateURLServiceTest::VerifyObserverCount(int expected_changed_count) { | 295 void TemplateURLServiceTest::VerifyObserverCount(int expected_changed_count) { |
288 EXPECT_EQ(expected_changed_count, test_util_->GetObserverCount()); | 296 EXPECT_EQ(expected_changed_count, test_util_->GetObserverCount()); |
289 test_util_->ResetObserverCount(); | 297 test_util_->ResetObserverCount(); |
290 } | 298 } |
291 | 299 |
292 void TemplateURLServiceTest::VerifyObserverFired() { | 300 void TemplateURLServiceTest::VerifyObserverFired() { |
(...skipping 14 matching lines...) Expand all Loading... |
307 const size_t initial_count = model()->GetTemplateURLs().size(); | 315 const size_t initial_count = model()->GetTemplateURLs().size(); |
308 | 316 |
309 TemplateURLData data; | 317 TemplateURLData data; |
310 data.SetShortName(ASCIIToUTF16("google")); | 318 data.SetShortName(ASCIIToUTF16("google")); |
311 data.SetKeyword(ASCIIToUTF16("keyword")); | 319 data.SetKeyword(ASCIIToUTF16("keyword")); |
312 data.SetURL("http://www.google.com/foo/bar"); | 320 data.SetURL("http://www.google.com/foo/bar"); |
313 data.favicon_url = GURL("http://favicon.url"); | 321 data.favicon_url = GURL("http://favicon.url"); |
314 data.safe_for_autoreplace = true; | 322 data.safe_for_autoreplace = true; |
315 data.date_created = Time::FromTimeT(100); | 323 data.date_created = Time::FromTimeT(100); |
316 data.last_modified = Time::FromTimeT(100); | 324 data.last_modified = Time::FromTimeT(100); |
| 325 data.last_visited = Time::FromTimeT(100); |
317 data.sync_guid = "00000000-0000-0000-0000-000000000001"; | 326 data.sync_guid = "00000000-0000-0000-0000-000000000001"; |
318 TemplateURL* t_url = model()->Add(base::MakeUnique<TemplateURL>(data)); | 327 TemplateURL* t_url = model()->Add(base::MakeUnique<TemplateURL>(data)); |
319 ASSERT_TRUE(model()->CanAddAutogeneratedKeyword(ASCIIToUTF16("keyword"), | 328 ASSERT_TRUE(model()->CanAddAutogeneratedKeyword(ASCIIToUTF16("keyword"), |
320 GURL(), NULL)); | 329 GURL(), NULL)); |
321 VerifyObserverCount(1); | 330 VerifyObserverCount(1); |
322 base::RunLoop().RunUntilIdle(); | 331 base::RunLoop().RunUntilIdle(); |
323 ASSERT_EQ(initial_count + 1, model()->GetTemplateURLs().size()); | 332 ASSERT_EQ(initial_count + 1, model()->GetTemplateURLs().size()); |
324 ASSERT_EQ(t_url, model()->GetTemplateURLForKeyword(t_url->keyword())); | 333 ASSERT_EQ(t_url, model()->GetTemplateURLForKeyword(t_url->keyword())); |
325 // We need to make a second copy as the model takes ownership of |t_url| and | 334 // We need to make a second copy as the model takes ownership of |t_url| and |
326 // will delete it. We have to do this after calling Add() since that gives | 335 // will delete it. We have to do this after calling Add() since that gives |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
371 model()->Remove(loaded_url); | 380 model()->Remove(loaded_url); |
372 VerifyObserverCount(1); | 381 VerifyObserverCount(1); |
373 test_util()->ResetModel(true); | 382 test_util()->ResetModel(true); |
374 ASSERT_EQ(initial_count, model()->GetTemplateURLs().size()); | 383 ASSERT_EQ(initial_count, model()->GetTemplateURLs().size()); |
375 EXPECT_TRUE(model()->GetTemplateURLForKeyword(ASCIIToUTF16("b")) == NULL); | 384 EXPECT_TRUE(model()->GetTemplateURLForKeyword(ASCIIToUTF16("b")) == NULL); |
376 } | 385 } |
377 | 386 |
378 TEST_F(TemplateURLServiceTest, AddSameKeyword) { | 387 TEST_F(TemplateURLServiceTest, AddSameKeyword) { |
379 test_util()->VerifyLoad(); | 388 test_util()->VerifyLoad(); |
380 | 389 |
381 AddKeywordWithDate( | 390 AddKeywordWithDate("first", "keyword", "http://test1", std::string(), |
382 "first", "keyword", "http://test1", std::string(), std::string(), | 391 std::string(), std::string(), true, "UTF-8", Time(), |
383 std::string(), true, "UTF-8", Time(), Time()); | 392 Time(), Time()); |
384 VerifyObserverCount(1); | 393 VerifyObserverCount(1); |
385 | 394 |
386 // Test what happens when we try to add a TemplateURL with the same keyword as | 395 // Test what happens when we try to add a TemplateURL with the same keyword as |
387 // one in the model. | 396 // one in the model. |
388 TemplateURLData data; | 397 TemplateURLData data; |
389 data.SetShortName(ASCIIToUTF16("second")); | 398 data.SetShortName(ASCIIToUTF16("second")); |
390 data.SetKeyword(ASCIIToUTF16("keyword")); | 399 data.SetKeyword(ASCIIToUTF16("keyword")); |
391 data.SetURL("http://test2"); | 400 data.SetURL("http://test2"); |
392 data.safe_for_autoreplace = false; | 401 data.safe_for_autoreplace = false; |
393 TemplateURL* t_url = model()->Add(base::MakeUnique<TemplateURL>(data)); | 402 TemplateURL* t_url = model()->Add(base::MakeUnique<TemplateURL>(data)); |
(...skipping 28 matching lines...) Expand all Loading... |
422 EXPECT_EQ(t_url2, model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword"))); | 431 EXPECT_EQ(t_url2, model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword"))); |
423 EXPECT_EQ(ASCIIToUTF16("fourth"), t_url2->short_name()); | 432 EXPECT_EQ(ASCIIToUTF16("fourth"), t_url2->short_name()); |
424 EXPECT_EQ(ASCIIToUTF16("keyword"), t_url2->keyword()); | 433 EXPECT_EQ(ASCIIToUTF16("keyword"), t_url2->keyword()); |
425 EXPECT_EQ(ASCIIToUTF16("second"), t_url->short_name()); | 434 EXPECT_EQ(ASCIIToUTF16("second"), t_url->short_name()); |
426 EXPECT_EQ(ASCIIToUTF16("test2"), t_url->keyword()); | 435 EXPECT_EQ(ASCIIToUTF16("test2"), t_url->keyword()); |
427 } | 436 } |
428 | 437 |
429 TEST_F(TemplateURLServiceTest, AddExtensionKeyword) { | 438 TEST_F(TemplateURLServiceTest, AddExtensionKeyword) { |
430 test_util()->VerifyLoad(); | 439 test_util()->VerifyLoad(); |
431 | 440 |
432 AddKeywordWithDate( | 441 AddKeywordWithDate("replaceable", "keyword1", "http://test1", std::string(), |
433 "replaceable", "keyword1", "http://test1", std::string(), std::string(), | 442 std::string(), std::string(), true, "UTF-8", Time(), |
434 std::string(), true, "UTF-8", Time(), Time()); | 443 Time(), Time()); |
435 TemplateURL* original2 = AddKeywordWithDate( | 444 TemplateURL* original2 = AddKeywordWithDate( |
436 "nonreplaceable", "keyword2", "http://test2", std::string(), | 445 "nonreplaceable", "keyword2", "http://test2", std::string(), |
437 std::string(), std::string(), false, "UTF-8", Time(), Time()); | 446 std::string(), std::string(), false, "UTF-8", Time(), Time(), Time()); |
438 model()->RegisterOmniboxKeyword("test3", "extension", "keyword3", | 447 model()->RegisterOmniboxKeyword("test3", "extension", "keyword3", |
439 "http://test3"); | 448 "http://test3"); |
440 TemplateURL* original3 = | 449 TemplateURL* original3 = |
441 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword3")); | 450 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword3")); |
442 ASSERT_TRUE(original3); | 451 ASSERT_TRUE(original3); |
443 | 452 |
444 // Extension keywords should override replaceable keywords. | 453 // Extension keywords should override replaceable keywords. |
445 model()->RegisterOmniboxKeyword("id1", "test", "keyword1", "http://test4"); | 454 model()->RegisterOmniboxKeyword("id1", "test", "keyword1", "http://test4"); |
446 TemplateURL* extension1 = model()->FindTemplateURLForExtension( | 455 TemplateURL* extension1 = model()->FindTemplateURLForExtension( |
447 "id1", TemplateURL::OMNIBOX_API_EXTENSION); | 456 "id1", TemplateURL::OMNIBOX_API_EXTENSION); |
(...skipping 23 matching lines...) Expand all Loading... |
471 | 480 |
472 // Similar to the AddSameKeyword test, but with an extension keyword masking a | 481 // Similar to the AddSameKeyword test, but with an extension keyword masking a |
473 // replaceable TemplateURL. We should still do correct conflict resolution | 482 // replaceable TemplateURL. We should still do correct conflict resolution |
474 // between the non-template URLs. | 483 // between the non-template URLs. |
475 model()->RegisterOmniboxKeyword("test2", "extension", "keyword", | 484 model()->RegisterOmniboxKeyword("test2", "extension", "keyword", |
476 "http://test2"); | 485 "http://test2"); |
477 TemplateURL* extension = | 486 TemplateURL* extension = |
478 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword")); | 487 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword")); |
479 ASSERT_TRUE(extension); | 488 ASSERT_TRUE(extension); |
480 // Adding a keyword that matches the extension. | 489 // Adding a keyword that matches the extension. |
481 AddKeywordWithDate( | 490 AddKeywordWithDate("replaceable", "keyword", "http://test1", std::string(), |
482 "replaceable", "keyword", "http://test1", std::string(), std::string(), | 491 std::string(), std::string(), true, "UTF-8", Time(), |
483 std::string(), true, "UTF-8", Time(), Time()); | 492 Time(), Time()); |
484 | 493 |
485 // Adding another replaceable keyword should remove the existing one, but | 494 // Adding another replaceable keyword should remove the existing one, but |
486 // leave the extension as is. | 495 // leave the extension as is. |
487 TemplateURLData data; | 496 TemplateURLData data; |
488 data.SetShortName(ASCIIToUTF16("name1")); | 497 data.SetShortName(ASCIIToUTF16("name1")); |
489 data.SetKeyword(ASCIIToUTF16("keyword")); | 498 data.SetKeyword(ASCIIToUTF16("keyword")); |
490 data.SetURL("http://test3"); | 499 data.SetURL("http://test3"); |
491 data.safe_for_autoreplace = true; | 500 data.safe_for_autoreplace = true; |
492 TemplateURL* t_url = model()->Add(base::MakeUnique<TemplateURL>(data)); | 501 TemplateURL* t_url = model()->Add(base::MakeUnique<TemplateURL>(data)); |
493 EXPECT_EQ(extension, | 502 EXPECT_EQ(extension, |
(...skipping 30 matching lines...) Expand all Loading... |
524 Time now = Time::Now(); | 533 Time now = Time::Now(); |
525 TimeDelta one_day = TimeDelta::FromDays(1); | 534 TimeDelta one_day = TimeDelta::FromDays(1); |
526 Time month_ago = now - TimeDelta::FromDays(30); | 535 Time month_ago = now - TimeDelta::FromDays(30); |
527 | 536 |
528 // Nothing has been added. | 537 // Nothing has been added. |
529 EXPECT_EQ(0U, model()->GetTemplateURLs().size()); | 538 EXPECT_EQ(0U, model()->GetTemplateURLs().size()); |
530 | 539 |
531 // Create one with a 0 time. | 540 // Create one with a 0 time. |
532 AddKeywordWithDate("name1", "key1", "http://foo1", "http://suggest1", | 541 AddKeywordWithDate("name1", "key1", "http://foo1", "http://suggest1", |
533 std::string(), "http://icon1", true, "UTF-8;UTF-16", | 542 std::string(), "http://icon1", true, "UTF-8;UTF-16", |
534 Time(), Time()); | 543 Time(), Time(), Time()); |
535 // Create one for now and +/- 1 day. | 544 // Create one for now and +/- 1 day. |
536 AddKeywordWithDate("name2", "key2", "http://foo2", "http://suggest2", | 545 AddKeywordWithDate("name2", "key2", "http://foo2", "http://suggest2", |
537 std::string(), "http://icon2", true, "UTF-8;UTF-16", | 546 std::string(), "http://icon2", true, "UTF-8;UTF-16", |
538 now - one_day, Time()); | 547 now - one_day, Time(), Time()); |
539 AddKeywordWithDate("name3", "key3", "http://foo3", std::string(), | 548 AddKeywordWithDate("name3", "key3", "http://foo3", std::string(), |
540 std::string(), std::string(), true, std::string(), now, | 549 std::string(), std::string(), true, std::string(), now, |
541 Time()); | 550 Time(), Time()); |
542 AddKeywordWithDate("name4", "key4", "http://foo4", std::string(), | 551 AddKeywordWithDate("name4", "key4", "http://foo4", std::string(), |
543 std::string(), std::string(), true, std::string(), | 552 std::string(), std::string(), true, std::string(), |
544 now + one_day, Time()); | 553 now + one_day, Time(), Time()); |
545 // Try the other three states. | 554 // Try the other three states. |
546 AddKeywordWithDate("name5", "key5", "http://foo5", "http://suggest5", | 555 AddKeywordWithDate("name5", "key5", "http://foo5", "http://suggest5", |
547 std::string(), "http://icon5", false, "UTF-8;UTF-16", now, | 556 std::string(), "http://icon5", false, "UTF-8;UTF-16", now, |
548 Time()); | 557 Time(), Time()); |
549 AddKeywordWithDate("name6", "key6", "http://foo6", "http://suggest6", | 558 AddKeywordWithDate("name6", "key6", "http://foo6", "http://suggest6", |
550 std::string(), "http://icon6", false, "UTF-8;UTF-16", | 559 std::string(), "http://icon6", false, "UTF-8;UTF-16", |
551 month_ago, Time()); | 560 month_ago, Time(), Time()); |
552 | 561 |
553 // We just added a few items, validate them. | 562 // We just added a few items, validate them. |
554 EXPECT_EQ(6U, model()->GetTemplateURLs().size()); | 563 EXPECT_EQ(6U, model()->GetTemplateURLs().size()); |
555 | 564 |
556 // Try removing from current timestamp. This should delete the one in the | 565 // Try removing from current timestamp. This should delete the one in the |
557 // future and one very recent one. | 566 // future and one very recent one. |
558 model()->RemoveAutoGeneratedSince(now); | 567 model()->RemoveAutoGeneratedSince(now); |
559 EXPECT_EQ(4U, model()->GetTemplateURLs().size()); | 568 EXPECT_EQ(4U, model()->GetTemplateURLs().size()); |
560 | 569 |
561 // Try removing from two months ago. This should only delete items that are | 570 // Try removing from two months ago. This should only delete items that are |
(...skipping 26 matching lines...) Expand all Loading... |
588 Time now = Time::Now(); | 597 Time now = Time::Now(); |
589 TimeDelta one_day = TimeDelta::FromDays(1); | 598 TimeDelta one_day = TimeDelta::FromDays(1); |
590 Time month_ago = now - TimeDelta::FromDays(30); | 599 Time month_ago = now - TimeDelta::FromDays(30); |
591 | 600 |
592 // Nothing has been added. | 601 // Nothing has been added. |
593 EXPECT_EQ(0U, model()->GetTemplateURLs().size()); | 602 EXPECT_EQ(0U, model()->GetTemplateURLs().size()); |
594 | 603 |
595 // Create one for now and +/- 1 day. | 604 // Create one for now and +/- 1 day. |
596 AddKeywordWithDate("name1", "key1", "http://foo1", "http://suggest1", | 605 AddKeywordWithDate("name1", "key1", "http://foo1", "http://suggest1", |
597 std::string(), "http://icon2", true, "UTF-8;UTF-16", | 606 std::string(), "http://icon2", true, "UTF-8;UTF-16", |
598 now - one_day, Time()); | 607 now - one_day, Time(), Time()); |
599 AddKeywordWithDate("name2", "key2", "http://foo2", std::string(), | 608 AddKeywordWithDate("name2", "key2", "http://foo2", std::string(), |
600 std::string(), std::string(), true, std::string(), now, | 609 std::string(), std::string(), true, std::string(), now, |
601 Time()); | 610 Time(), Time()); |
602 AddKeywordWithDate("name3", "key3", "http://foo3", std::string(), | 611 AddKeywordWithDate("name3", "key3", "http://foo3", std::string(), |
603 std::string(), std::string(), true, std::string(), | 612 std::string(), std::string(), true, std::string(), |
604 now + one_day, Time()); | 613 now + one_day, Time(), Time()); |
605 | 614 |
606 // We just added a few items, validate them. | 615 // We just added a few items, validate them. |
607 EXPECT_EQ(3U, model()->GetTemplateURLs().size()); | 616 EXPECT_EQ(3U, model()->GetTemplateURLs().size()); |
608 | 617 |
609 // Try removing foo2. This should delete foo2, but leave foo1 and 3 untouched. | 618 // Try removing foo2. This should delete foo2, but leave foo1 and 3 untouched. |
610 GURL url2("http://foo2"); | 619 GURL url2("http://foo2"); |
611 model()->RemoveAutoGeneratedForUrlsBetween( | 620 model()->RemoveAutoGeneratedForUrlsBetween( |
612 base::Bind(static_cast<bool (*)(const GURL&, const GURL&)>(operator==), | 621 base::Bind(static_cast<bool (*)(const GURL&, const GURL&)>(operator==), |
613 url2), | 622 url2), |
614 month_ago, now + one_day); | 623 month_ago, now + one_day); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
646 // Add a new TemplateURL. | 655 // Add a new TemplateURL. |
647 test_util()->VerifyLoad(); | 656 test_util()->VerifyLoad(); |
648 const size_t initial_count = model()->GetTemplateURLs().size(); | 657 const size_t initial_count = model()->GetTemplateURLs().size(); |
649 TemplateURLData data; | 658 TemplateURLData data; |
650 data.SetShortName(ASCIIToUTF16("google")); | 659 data.SetShortName(ASCIIToUTF16("google")); |
651 data.SetKeyword(ASCIIToUTF16("keyword")); | 660 data.SetKeyword(ASCIIToUTF16("keyword")); |
652 data.SetURL("http://www.google.com/foo/bar"); | 661 data.SetURL("http://www.google.com/foo/bar"); |
653 data.favicon_url = GURL("http://favicon.url"); | 662 data.favicon_url = GURL("http://favicon.url"); |
654 data.date_created = Time::FromTimeT(100); | 663 data.date_created = Time::FromTimeT(100); |
655 data.last_modified = Time::FromTimeT(100); | 664 data.last_modified = Time::FromTimeT(100); |
| 665 data.last_visited = Time::FromTimeT(100); |
656 TemplateURL* t_url = model()->Add(base::MakeUnique<TemplateURL>(data)); | 666 TemplateURL* t_url = model()->Add(base::MakeUnique<TemplateURL>(data)); |
657 | 667 |
658 VerifyObserverCount(1); | 668 VerifyObserverCount(1); |
659 base::RunLoop().RunUntilIdle(); | 669 base::RunLoop().RunUntilIdle(); |
660 | 670 |
661 base::Time now = base::Time::Now(); | 671 base::Time now = base::Time::Now(); |
662 std::unique_ptr<base::SimpleTestClock> clock(new base::SimpleTestClock); | 672 std::unique_ptr<base::SimpleTestClock> clock(new base::SimpleTestClock); |
663 clock->SetNow(now); | 673 clock->SetNow(now); |
664 model()->set_clock(std::move(clock)); | 674 model()->set_clock(std::move(clock)); |
665 | 675 |
(...skipping 20 matching lines...) Expand all Loading... |
686 const TemplateURL* read_url = model()->GetTemplateURLForKeyword(new_keyword); | 696 const TemplateURL* read_url = model()->GetTemplateURLForKeyword(new_keyword); |
687 ASSERT_TRUE(read_url); | 697 ASSERT_TRUE(read_url); |
688 AssertEquals(*cloned_url, *read_url); | 698 AssertEquals(*cloned_url, *read_url); |
689 AssertTimesEqual(now, read_url->last_modified()); | 699 AssertTimesEqual(now, read_url->last_modified()); |
690 } | 700 } |
691 | 701 |
692 TEST_F(TemplateURLServiceTest, DefaultSearchProvider) { | 702 TEST_F(TemplateURLServiceTest, DefaultSearchProvider) { |
693 // Add a new TemplateURL. | 703 // Add a new TemplateURL. |
694 test_util()->VerifyLoad(); | 704 test_util()->VerifyLoad(); |
695 const size_t initial_count = model()->GetTemplateURLs().size(); | 705 const size_t initial_count = model()->GetTemplateURLs().size(); |
696 TemplateURL* t_url = AddKeywordWithDate( | 706 TemplateURL* t_url = |
697 "name1", "key1", "http://foo1/{searchTerms}", "http://sugg1", | 707 AddKeywordWithDate("name1", "key1", "http://foo1/{searchTerms}", |
698 std::string(), "http://icon1", true, "UTF-8;UTF-16", Time(), Time()); | 708 "http://sugg1", std::string(), "http://icon1", true, |
| 709 "UTF-8;UTF-16", Time(), Time(), Time()); |
699 test_util()->ResetObserverCount(); | 710 test_util()->ResetObserverCount(); |
700 | 711 |
701 model()->SetUserSelectedDefaultSearchProvider(t_url); | 712 model()->SetUserSelectedDefaultSearchProvider(t_url); |
702 ASSERT_EQ(t_url, model()->GetDefaultSearchProvider()); | 713 ASSERT_EQ(t_url, model()->GetDefaultSearchProvider()); |
703 ASSERT_TRUE(t_url->safe_for_autoreplace()); | 714 ASSERT_TRUE(t_url->safe_for_autoreplace()); |
704 ASSERT_TRUE(model()->ShowInDefaultList(t_url)); | 715 ASSERT_TRUE(model()->ShowInDefaultList(t_url)); |
705 | 716 |
706 // Setting the default search provider should have caused notification. | 717 // Setting the default search provider should have caused notification. |
707 VerifyObserverCount(1); | 718 VerifyObserverCount(1); |
708 base::RunLoop().RunUntilIdle(); | 719 base::RunLoop().RunUntilIdle(); |
709 | 720 |
710 std::unique_ptr<TemplateURL> cloned_url( | 721 std::unique_ptr<TemplateURL> cloned_url( |
711 base::MakeUnique<TemplateURL>(t_url->data())); | 722 base::MakeUnique<TemplateURL>(t_url->data())); |
712 | 723 |
713 // Make sure when we reload we get a default search provider. | 724 // Make sure when we reload we get a default search provider. |
714 test_util()->ResetModel(true); | 725 test_util()->ResetModel(true); |
715 EXPECT_EQ(initial_count + 1, model()->GetTemplateURLs().size()); | 726 EXPECT_EQ(initial_count + 1, model()->GetTemplateURLs().size()); |
716 ASSERT_TRUE(model()->GetDefaultSearchProvider()); | 727 ASSERT_TRUE(model()->GetDefaultSearchProvider()); |
717 AssertEquals(*cloned_url, *model()->GetDefaultSearchProvider()); | 728 AssertEquals(*cloned_url, *model()->GetDefaultSearchProvider()); |
718 } | 729 } |
719 | 730 |
720 TEST_F(TemplateURLServiceTest, CantReplaceWithSameKeyword) { | 731 TEST_F(TemplateURLServiceTest, CantReplaceWithSameKeyword) { |
721 test_util()->ChangeModelToLoadState(); | 732 test_util()->ChangeModelToLoadState(); |
722 ASSERT_TRUE(model()->CanAddAutogeneratedKeyword(ASCIIToUTF16("foo"), GURL(), | 733 ASSERT_TRUE(model()->CanAddAutogeneratedKeyword(ASCIIToUTF16("foo"), GURL(), |
723 NULL)); | 734 NULL)); |
724 TemplateURL* t_url = AddKeywordWithDate( | 735 TemplateURL* t_url = AddKeywordWithDate( |
725 "name1", "foo", "http://foo1", "http://sugg1", std::string(), | 736 "name1", "foo", "http://foo1", "http://sugg1", std::string(), |
726 "http://icon1", true, "UTF-8;UTF-16", Time(), Time()); | 737 "http://icon1", true, "UTF-8;UTF-16", Time(), Time(), Time()); |
727 | 738 |
728 // Can still replace, newly added template url is marked safe to replace. | 739 // Can still replace, newly added template url is marked safe to replace. |
729 ASSERT_TRUE(model()->CanAddAutogeneratedKeyword(ASCIIToUTF16("foo"), | 740 ASSERT_TRUE(model()->CanAddAutogeneratedKeyword(ASCIIToUTF16("foo"), |
730 GURL("http://foo2"), NULL)); | 741 GURL("http://foo2"), NULL)); |
731 | 742 |
732 // ResetTemplateURL marks the TemplateURL as unsafe to replace, so it should | 743 // ResetTemplateURL marks the TemplateURL as unsafe to replace, so it should |
733 // no longer be replaceable. | 744 // no longer be replaceable. |
734 model()->ResetTemplateURL(t_url, t_url->short_name(), t_url->keyword(), | 745 model()->ResetTemplateURL(t_url, t_url->short_name(), t_url->keyword(), |
735 t_url->url()); | 746 t_url->url()); |
736 | 747 |
737 ASSERT_FALSE(model()->CanAddAutogeneratedKeyword(ASCIIToUTF16("foo"), | 748 ASSERT_FALSE(model()->CanAddAutogeneratedKeyword(ASCIIToUTF16("foo"), |
738 GURL("http://foo2"), NULL)); | 749 GURL("http://foo2"), NULL)); |
739 } | 750 } |
740 | 751 |
741 TEST_F(TemplateURLServiceTest, CantReplaceWithSameHosts) { | 752 TEST_F(TemplateURLServiceTest, CantReplaceWithSameHosts) { |
742 test_util()->ChangeModelToLoadState(); | 753 test_util()->ChangeModelToLoadState(); |
743 ASSERT_TRUE(model()->CanAddAutogeneratedKeyword(ASCIIToUTF16("foo"), | 754 ASSERT_TRUE(model()->CanAddAutogeneratedKeyword(ASCIIToUTF16("foo"), |
744 GURL("http://foo.com"), NULL)); | 755 GURL("http://foo.com"), NULL)); |
745 TemplateURL* t_url = AddKeywordWithDate( | 756 TemplateURL* t_url = AddKeywordWithDate( |
746 "name1", "foo", "http://foo.com", "http://sugg1", std::string(), | 757 "name1", "foo", "http://foo.com", "http://sugg1", std::string(), |
747 "http://icon1", true, "UTF-8;UTF-16", Time(), Time()); | 758 "http://icon1", true, "UTF-8;UTF-16", Time(), Time(), Time()); |
748 | 759 |
749 // Can still replace, newly added template url is marked safe to replace. | 760 // Can still replace, newly added template url is marked safe to replace. |
750 ASSERT_TRUE(model()->CanAddAutogeneratedKeyword(ASCIIToUTF16("bar"), | 761 ASSERT_TRUE(model()->CanAddAutogeneratedKeyword(ASCIIToUTF16("bar"), |
751 GURL("http://foo.com"), NULL)); | 762 GURL("http://foo.com"), NULL)); |
752 | 763 |
753 // ResetTemplateURL marks the TemplateURL as unsafe to replace, so it should | 764 // ResetTemplateURL marks the TemplateURL as unsafe to replace, so it should |
754 // no longer be replaceable. | 765 // no longer be replaceable. |
755 model()->ResetTemplateURL(t_url, t_url->short_name(), t_url->keyword(), | 766 model()->ResetTemplateURL(t_url, t_url->short_name(), t_url->keyword(), |
756 t_url->url()); | 767 t_url->url()); |
757 | 768 |
(...skipping 15 matching lines...) Expand all Loading... |
773 test_util()->VerifyLoad(); | 784 test_util()->VerifyLoad(); |
774 | 785 |
775 TemplateURLData data; | 786 TemplateURLData data; |
776 data.SetShortName(ASCIIToUTF16("a")); | 787 data.SetShortName(ASCIIToUTF16("a")); |
777 data.safe_for_autoreplace = true; | 788 data.safe_for_autoreplace = true; |
778 data.SetURL("http://url/{searchTerms}"); | 789 data.SetURL("http://url/{searchTerms}"); |
779 data.suggestions_url = "http://url2"; | 790 data.suggestions_url = "http://url2"; |
780 data.instant_url = "http://instant"; | 791 data.instant_url = "http://instant"; |
781 data.date_created = Time::FromTimeT(100); | 792 data.date_created = Time::FromTimeT(100); |
782 data.last_modified = Time::FromTimeT(100); | 793 data.last_modified = Time::FromTimeT(100); |
| 794 data.last_visited = Time::FromTimeT(100); |
783 TemplateURL* t_url = model()->Add(base::MakeUnique<TemplateURL>(data)); | 795 TemplateURL* t_url = model()->Add(base::MakeUnique<TemplateURL>(data)); |
784 const TemplateURLID id = t_url->id(); | 796 const TemplateURLID id = t_url->id(); |
785 | 797 |
786 model()->SetUserSelectedDefaultSearchProvider(t_url); | 798 model()->SetUserSelectedDefaultSearchProvider(t_url); |
787 base::RunLoop().RunUntilIdle(); | 799 base::RunLoop().RunUntilIdle(); |
788 std::unique_ptr<TemplateURL> cloned_url( | 800 std::unique_ptr<TemplateURL> cloned_url( |
789 base::MakeUnique<TemplateURL>(t_url->data())); | 801 base::MakeUnique<TemplateURL>(t_url->data())); |
790 | 802 |
791 // Reset the model and don't load it. The template url we set as the default | 803 // Reset the model and don't load it. The template url we set as the default |
792 // should be pulled from prefs now. | 804 // should be pulled from prefs now. |
(...skipping 24 matching lines...) Expand all Loading... |
817 ASCIIToUTF16("google.com")); | 829 ASCIIToUTF16("google.com")); |
818 ASSERT_TRUE(google); | 830 ASSERT_TRUE(google); |
819 model()->ResetTemplateURL(google, ASCIIToUTF16("trash"), ASCIIToUTF16("xxx"), | 831 model()->ResetTemplateURL(google, ASCIIToUTF16("trash"), ASCIIToUTF16("xxx"), |
820 "http://www.foo.com/s?q={searchTerms}"); | 832 "http://www.foo.com/s?q={searchTerms}"); |
821 EXPECT_EQ(ASCIIToUTF16("trash"), google->short_name()); | 833 EXPECT_EQ(ASCIIToUTF16("trash"), google->short_name()); |
822 EXPECT_EQ(ASCIIToUTF16("xxx"), google->keyword()); | 834 EXPECT_EQ(ASCIIToUTF16("xxx"), google->keyword()); |
823 | 835 |
824 // Add third-party default search engine. | 836 // Add third-party default search engine. |
825 TemplateURL* user_dse = AddKeywordWithDate( | 837 TemplateURL* user_dse = AddKeywordWithDate( |
826 "malware", "google.com", "http://www.goo.com/s?q={searchTerms}", | 838 "malware", "google.com", "http://www.goo.com/s?q={searchTerms}", |
827 std::string(), std::string(), std::string(), | 839 std::string(), std::string(), std::string(), true, "UTF-8", Time(), |
828 true, "UTF-8", Time(), Time()); | 840 Time(), Time()); |
829 model()->SetUserSelectedDefaultSearchProvider(user_dse); | 841 model()->SetUserSelectedDefaultSearchProvider(user_dse); |
830 EXPECT_EQ(user_dse, model()->GetDefaultSearchProvider()); | 842 EXPECT_EQ(user_dse, model()->GetDefaultSearchProvider()); |
831 | 843 |
832 // Remove bing. | 844 // Remove bing. |
833 TemplateURL* bing = model()->GetTemplateURLForKeyword( | 845 TemplateURL* bing = model()->GetTemplateURLForKeyword( |
834 ASCIIToUTF16("bing.com")); | 846 ASCIIToUTF16("bing.com")); |
835 ASSERT_TRUE(bing); | 847 ASSERT_TRUE(bing); |
836 model()->Remove(bing); | 848 model()->Remove(bing); |
837 EXPECT_FALSE(model()->GetTemplateURLForKeyword(ASCIIToUTF16("bing.com"))); | 849 EXPECT_FALSE(model()->GetTemplateURLForKeyword(ASCIIToUTF16("bing.com"))); |
838 | 850 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
895 { "http://x/foo?q=b&q=xx", base::string16() }, | 907 { "http://x/foo?q=b&q=xx", base::string16() }, |
896 { "http://x/foo#query=xx", ASCIIToUTF16("xx") }, | 908 { "http://x/foo#query=xx", ASCIIToUTF16("xx") }, |
897 { "http://x/foo?q=b#query=xx", ASCIIToUTF16("xx") }, | 909 { "http://x/foo?q=b#query=xx", ASCIIToUTF16("xx") }, |
898 { "http://x/foo?q=b#q=xx", ASCIIToUTF16("b") }, | 910 { "http://x/foo?q=b#q=xx", ASCIIToUTF16("b") }, |
899 { "http://x/foo?query=b#q=xx", base::string16() }, | 911 { "http://x/foo?query=b#q=xx", base::string16() }, |
900 }; | 912 }; |
901 | 913 |
902 test_util()->ChangeModelToLoadState(); | 914 test_util()->ChangeModelToLoadState(); |
903 AddKeywordWithDate("name", "x", "http://x/foo?q={searchTerms}", | 915 AddKeywordWithDate("name", "x", "http://x/foo?q={searchTerms}", |
904 "http://sugg1", "http://x/foo#query={searchTerms}", | 916 "http://sugg1", "http://x/foo#query={searchTerms}", |
905 "http://icon1", false, "UTF-8;UTF-16", Time(), Time()); | 917 "http://icon1", false, "UTF-8;UTF-16", Time(), Time(), |
| 918 Time()); |
906 | 919 |
907 for (size_t i = 0; i < arraysize(data); ++i) { | 920 for (size_t i = 0; i < arraysize(data); ++i) { |
908 TemplateURLService::URLVisitedDetails details = { | 921 TemplateURLService::URLVisitedDetails details = { |
909 GURL(data[i].url), false | 922 GURL(data[i].url), false |
910 }; | 923 }; |
911 model()->UpdateKeywordSearchTermsForURL(details); | 924 model()->UpdateKeywordSearchTermsForURL(details); |
912 EXPECT_EQ(data[i].term, test_util()->GetAndClearSearchTerm()); | 925 EXPECT_EQ(data[i].term, test_util()->GetAndClearSearchTerm()); |
913 } | 926 } |
914 } | 927 } |
915 | 928 |
916 TEST_F(TemplateURLServiceTest, DontUpdateKeywordSearchForNonReplaceable) { | 929 TEST_F(TemplateURLServiceTest, DontUpdateKeywordSearchForNonReplaceable) { |
917 struct TestData { | 930 struct TestData { |
918 const std::string url; | 931 const std::string url; |
919 } data[] = { | 932 } data[] = { |
920 { "http://foo/" }, | 933 { "http://foo/" }, |
921 { "http://x/bar?q=xx" }, | 934 { "http://x/bar?q=xx" }, |
922 { "http://x/foo?y=xx" }, | 935 { "http://x/foo?y=xx" }, |
923 }; | 936 }; |
924 | 937 |
925 test_util()->ChangeModelToLoadState(); | 938 test_util()->ChangeModelToLoadState(); |
926 AddKeywordWithDate("name", "x", "http://x/foo", "http://sugg1", std::string(), | 939 AddKeywordWithDate("name", "x", "http://x/foo", "http://sugg1", std::string(), |
927 "http://icon1", false, "UTF-8;UTF-16", Time(), Time()); | 940 "http://icon1", false, "UTF-8;UTF-16", Time(), Time(), |
| 941 Time()); |
928 | 942 |
929 for (size_t i = 0; i < arraysize(data); ++i) { | 943 for (size_t i = 0; i < arraysize(data); ++i) { |
930 TemplateURLService::URLVisitedDetails details = { | 944 TemplateURLService::URLVisitedDetails details = { |
931 GURL(data[i].url), false | 945 GURL(data[i].url), false |
932 }; | 946 }; |
933 model()->UpdateKeywordSearchTermsForURL(details); | 947 model()->UpdateKeywordSearchTermsForURL(details); |
934 ASSERT_EQ(base::string16(), test_util()->GetAndClearSearchTerm()); | 948 ASSERT_EQ(base::string16(), test_util()->GetAndClearSearchTerm()); |
935 } | 949 } |
936 } | 950 } |
937 | 951 |
938 TEST_F(TemplateURLServiceWithoutFallbackTest, ChangeGoogleBaseValue) { | 952 TEST_F(TemplateURLServiceWithoutFallbackTest, ChangeGoogleBaseValue) { |
939 // NOTE: Do not load the prepopulate data, which also has a {google:baseURL} | 953 // NOTE: Do not load the prepopulate data, which also has a {google:baseURL} |
940 // keyword in it and would confuse this test. | 954 // keyword in it and would confuse this test. |
941 test_util()->ChangeModelToLoadState(); | 955 test_util()->ChangeModelToLoadState(); |
942 | 956 |
943 test_util()->SetGoogleBaseURL(GURL("http://google.com/")); | 957 test_util()->SetGoogleBaseURL(GURL("http://google.com/")); |
944 const TemplateURL* t_url = AddKeywordWithDate( | 958 const TemplateURL* t_url = AddKeywordWithDate( |
945 "name", "google.com", "{google:baseURL}?q={searchTerms}", "http://sugg1", | 959 "name", "google.com", "{google:baseURL}?q={searchTerms}", "http://sugg1", |
946 std::string(), "http://icon1", false, "UTF-8;UTF-16", Time(), Time()); | 960 std::string(), "http://icon1", false, "UTF-8;UTF-16", Time(), Time(), |
| 961 Time()); |
947 ASSERT_EQ(t_url, model()->GetTemplateURLForHost("google.com")); | 962 ASSERT_EQ(t_url, model()->GetTemplateURLForHost("google.com")); |
948 EXPECT_EQ("google.com", t_url->url_ref().GetHost(search_terms_data())); | 963 EXPECT_EQ("google.com", t_url->url_ref().GetHost(search_terms_data())); |
949 EXPECT_EQ(ASCIIToUTF16("google.com"), t_url->keyword()); | 964 EXPECT_EQ(ASCIIToUTF16("google.com"), t_url->keyword()); |
950 | 965 |
951 // Change the Google base url. | 966 // Change the Google base url. |
952 test_util()->ResetObserverCount(); | 967 test_util()->ResetObserverCount(); |
953 test_util()->SetGoogleBaseURL(GURL("http://google.co.uk/")); | 968 test_util()->SetGoogleBaseURL(GURL("http://google.co.uk/")); |
954 VerifyObserverCount(1); | 969 VerifyObserverCount(1); |
955 | 970 |
956 // Make sure the host->TemplateURL map was updated appropriately. | 971 // Make sure the host->TemplateURL map was updated appropriately. |
957 ASSERT_EQ(t_url, model()->GetTemplateURLForHost("google.co.uk")); | 972 ASSERT_EQ(t_url, model()->GetTemplateURLForHost("google.co.uk")); |
958 EXPECT_TRUE(model()->GetTemplateURLForHost("google.com") == NULL); | 973 EXPECT_TRUE(model()->GetTemplateURLForHost("google.com") == NULL); |
959 EXPECT_EQ("google.co.uk", t_url->url_ref().GetHost(search_terms_data())); | 974 EXPECT_EQ("google.co.uk", t_url->url_ref().GetHost(search_terms_data())); |
960 EXPECT_EQ(ASCIIToUTF16("google.co.uk"), t_url->keyword()); | 975 EXPECT_EQ(ASCIIToUTF16("google.co.uk"), t_url->keyword()); |
961 EXPECT_EQ("http://google.co.uk/?q=x", t_url->url_ref().ReplaceSearchTerms( | 976 EXPECT_EQ("http://google.co.uk/?q=x", t_url->url_ref().ReplaceSearchTerms( |
962 TemplateURLRef::SearchTermsArgs(ASCIIToUTF16("x")), search_terms_data())); | 977 TemplateURLRef::SearchTermsArgs(ASCIIToUTF16("x")), search_terms_data())); |
963 | 978 |
964 // Now add a manual entry and then change the Google base URL such that the | 979 // Now add a manual entry and then change the Google base URL such that the |
965 // autogenerated Google search keyword would conflict. | 980 // autogenerated Google search keyword would conflict. |
966 TemplateURL* manual = AddKeywordWithDate( | 981 TemplateURL* manual = AddKeywordWithDate( |
967 "manual", "google.de", "http://google.de/search?q={searchTerms}", | 982 "manual", "google.de", "http://google.de/search?q={searchTerms}", |
968 std::string(), std::string(), std::string(), false, "UTF-8", Time(), | 983 std::string(), std::string(), std::string(), false, "UTF-8", Time(), |
969 Time()); | 984 Time(), Time()); |
970 test_util()->SetGoogleBaseURL(GURL("http://google.de")); | 985 test_util()->SetGoogleBaseURL(GURL("http://google.de")); |
971 | 986 |
972 // Verify that the manual entry is untouched, and the autogenerated keyword | 987 // Verify that the manual entry is untouched, and the autogenerated keyword |
973 // has not changed. | 988 // has not changed. |
974 ASSERT_EQ(manual, | 989 ASSERT_EQ(manual, |
975 model()->GetTemplateURLForKeyword(ASCIIToUTF16("google.de"))); | 990 model()->GetTemplateURLForKeyword(ASCIIToUTF16("google.de"))); |
976 EXPECT_EQ("google.de", manual->url_ref().GetHost(search_terms_data())); | 991 EXPECT_EQ("google.de", manual->url_ref().GetHost(search_terms_data())); |
977 ASSERT_EQ(t_url, | 992 ASSERT_EQ(t_url, |
978 model()->GetTemplateURLForKeyword(ASCIIToUTF16("google.co.uk"))); | 993 model()->GetTemplateURLForKeyword(ASCIIToUTF16("google.co.uk"))); |
979 EXPECT_EQ("google.de", t_url->url_ref().GetHost(search_terms_data())); | 994 EXPECT_EQ("google.de", t_url->url_ref().GetHost(search_terms_data())); |
(...skipping 16 matching lines...) Expand all Loading... |
996 // KEYWORD visits. | 1011 // KEYWORD visits. |
997 TEST_F(TemplateURLServiceTest, GenerateVisitOnKeyword) { | 1012 TEST_F(TemplateURLServiceTest, GenerateVisitOnKeyword) { |
998 test_util()->profile()->CreateBookmarkModel(false); | 1013 test_util()->profile()->CreateBookmarkModel(false); |
999 ASSERT_TRUE(test_util()->profile()->CreateHistoryService(true, false)); | 1014 ASSERT_TRUE(test_util()->profile()->CreateHistoryService(true, false)); |
1000 test_util()->ResetModel(true); | 1015 test_util()->ResetModel(true); |
1001 | 1016 |
1002 // Create a keyword. | 1017 // Create a keyword. |
1003 TemplateURL* t_url = AddKeywordWithDate( | 1018 TemplateURL* t_url = AddKeywordWithDate( |
1004 "keyword", "keyword", "http://foo.com/foo?query={searchTerms}", | 1019 "keyword", "keyword", "http://foo.com/foo?query={searchTerms}", |
1005 "http://sugg1", std::string(), "http://icon1", true, "UTF-8;UTF-16", | 1020 "http://sugg1", std::string(), "http://icon1", true, "UTF-8;UTF-16", |
1006 base::Time::Now(), base::Time::Now()); | 1021 base::Time::Now(), base::Time::Now(), base::Time()); |
1007 | 1022 |
1008 // Add a visit that matches the url of the keyword. | 1023 // Add a visit that matches the url of the keyword. |
1009 history::HistoryService* history = HistoryServiceFactory::GetForProfile( | 1024 history::HistoryService* history = HistoryServiceFactory::GetForProfile( |
1010 test_util()->profile(), ServiceAccessType::EXPLICIT_ACCESS); | 1025 test_util()->profile(), ServiceAccessType::EXPLICIT_ACCESS); |
1011 history->AddPage( | 1026 history->AddPage( |
1012 GURL(t_url->url_ref().ReplaceSearchTerms( | 1027 GURL(t_url->url_ref().ReplaceSearchTerms( |
1013 TemplateURLRef::SearchTermsArgs(ASCIIToUTF16("blah")), | 1028 TemplateURLRef::SearchTermsArgs(ASCIIToUTF16("blah")), |
1014 search_terms_data())), | 1029 search_terms_data())), |
1015 base::Time::Now(), NULL, 0, GURL(), history::RedirectList(), | 1030 base::Time::Now(), NULL, 0, GURL(), history::RedirectList(), |
1016 ui::PAGE_TRANSITION_KEYWORD, history::SOURCE_BROWSED, false); | 1031 ui::PAGE_TRANSITION_KEYWORD, history::SOURCE_BROWSED, false); |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1205 | 1220 |
1206 // Verifies that if the default search URL preference is managed, we report | 1221 // Verifies that if the default search URL preference is managed, we report |
1207 // the default search as managed. Also check that we are getting the right | 1222 // the default search as managed. Also check that we are getting the right |
1208 // values. | 1223 // values. |
1209 TEST_F(TemplateURLServiceTest, TestManagedDefaultSearch) { | 1224 TEST_F(TemplateURLServiceTest, TestManagedDefaultSearch) { |
1210 test_util()->VerifyLoad(); | 1225 test_util()->VerifyLoad(); |
1211 const size_t initial_count = model()->GetTemplateURLs().size(); | 1226 const size_t initial_count = model()->GetTemplateURLs().size(); |
1212 test_util()->ResetObserverCount(); | 1227 test_util()->ResetObserverCount(); |
1213 | 1228 |
1214 // Set a regular default search provider. | 1229 // Set a regular default search provider. |
1215 TemplateURL* regular_default = AddKeywordWithDate( | 1230 TemplateURL* regular_default = |
1216 "name1", "key1", "http://foo1/{searchTerms}", "http://sugg1", | 1231 AddKeywordWithDate("name1", "key1", "http://foo1/{searchTerms}", |
1217 std::string(), "http://icon1", true, "UTF-8;UTF-16", Time(), Time()); | 1232 "http://sugg1", std::string(), "http://icon1", true, |
| 1233 "UTF-8;UTF-16", Time(), Time(), Time()); |
1218 VerifyObserverCount(1); | 1234 VerifyObserverCount(1); |
1219 model()->SetUserSelectedDefaultSearchProvider(regular_default); | 1235 model()->SetUserSelectedDefaultSearchProvider(regular_default); |
1220 // Adding the URL and setting the default search provider should have caused | 1236 // Adding the URL and setting the default search provider should have caused |
1221 // notifications. | 1237 // notifications. |
1222 VerifyObserverCount(1); | 1238 VerifyObserverCount(1); |
1223 EXPECT_FALSE(model()->is_default_search_managed()); | 1239 EXPECT_FALSE(model()->is_default_search_managed()); |
1224 EXPECT_EQ(initial_count + 1, model()->GetTemplateURLs().size()); | 1240 EXPECT_EQ(initial_count + 1, model()->GetTemplateURLs().size()); |
1225 | 1241 |
1226 // Set a managed preference that establishes a default search provider. | 1242 // Set a managed preference that establishes a default search provider. |
1227 std::unique_ptr<TemplateURLData> managed = CreateTestSearchEngine(); | 1243 std::unique_ptr<TemplateURLData> managed = CreateTestSearchEngine(); |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1369 ASSERT_EQ(initial_count + 1, model()->GetTemplateURLs().size()); | 1385 ASSERT_EQ(initial_count + 1, model()->GetTemplateURLs().size()); |
1370 loaded_url = model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword")); | 1386 loaded_url = model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword")); |
1371 ASSERT_FALSE(loaded_url == NULL); | 1387 ASSERT_FALSE(loaded_url == NULL); |
1372 EXPECT_EQ(4U, loaded_url->input_encodings().size()); | 1388 EXPECT_EQ(4U, loaded_url->input_encodings().size()); |
1373 } | 1389 } |
1374 | 1390 |
1375 TEST_F(TemplateURLServiceTest, DefaultExtensionEngine) { | 1391 TEST_F(TemplateURLServiceTest, DefaultExtensionEngine) { |
1376 test_util()->VerifyLoad(); | 1392 test_util()->VerifyLoad(); |
1377 // Add third-party default search engine. | 1393 // Add third-party default search engine. |
1378 TemplateURL* user_dse = AddKeywordWithDate( | 1394 TemplateURL* user_dse = AddKeywordWithDate( |
1379 "user", "user", "http://www.goo.com/s?q={searchTerms}", | 1395 "user", "user", "http://www.goo.com/s?q={searchTerms}", std::string(), |
1380 std::string(), std::string(), std::string(), | 1396 std::string(), std::string(), true, "UTF-8", Time(), Time(), Time()); |
1381 true, "UTF-8", Time(), Time()); | |
1382 model()->SetUserSelectedDefaultSearchProvider(user_dse); | 1397 model()->SetUserSelectedDefaultSearchProvider(user_dse); |
1383 EXPECT_EQ(user_dse, model()->GetDefaultSearchProvider()); | 1398 EXPECT_EQ(user_dse, model()->GetDefaultSearchProvider()); |
1384 | 1399 |
1385 std::unique_ptr<TemplateURL> ext_dse = CreateKeywordWithDate( | 1400 std::unique_ptr<TemplateURL> ext_dse = CreateKeywordWithDate( |
1386 model(), "ext", "ext", "http://www.search.com/s?q={searchTerms}", | 1401 model(), "ext", "ext", "http://www.search.com/s?q={searchTerms}", |
1387 std::string(), std::string(), std::string(), true, kPrepopulatedId, | 1402 std::string(), std::string(), std::string(), true, kPrepopulatedId, |
1388 "UTF-8", Time(), Time(), TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION); | 1403 "UTF-8", Time(), Time(), Time(), |
| 1404 TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION); |
1389 std::unique_ptr<TemplateURL::AssociatedExtensionInfo> extension_info( | 1405 std::unique_ptr<TemplateURL::AssociatedExtensionInfo> extension_info( |
1390 new TemplateURL::AssociatedExtensionInfo("ext")); | 1406 new TemplateURL::AssociatedExtensionInfo("ext")); |
1391 extension_info->wants_to_be_default_engine = true; | 1407 extension_info->wants_to_be_default_engine = true; |
1392 TemplateURL* ext_dse_ptr = model()->AddExtensionControlledTURL( | 1408 TemplateURL* ext_dse_ptr = model()->AddExtensionControlledTURL( |
1393 std::move(ext_dse), std::move(extension_info)); | 1409 std::move(ext_dse), std::move(extension_info)); |
1394 EXPECT_EQ(ext_dse_ptr, model()->GetDefaultSearchProvider()); | 1410 EXPECT_EQ(ext_dse_ptr, model()->GetDefaultSearchProvider()); |
1395 | 1411 |
1396 model()->RemoveExtensionControlledTURL( | 1412 model()->RemoveExtensionControlledTURL( |
1397 "ext", TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION); | 1413 "ext", TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION); |
1398 ExpectSimilar(user_dse, model()->GetDefaultSearchProvider()); | 1414 ExpectSimilar(user_dse, model()->GetDefaultSearchProvider()); |
1399 } | 1415 } |
1400 | 1416 |
1401 TEST_F(TemplateURLServiceTest, ExtensionEnginesNotPersist) { | 1417 TEST_F(TemplateURLServiceTest, ExtensionEnginesNotPersist) { |
1402 test_util()->VerifyLoad(); | 1418 test_util()->VerifyLoad(); |
1403 // Add third-party default search engine. | 1419 // Add third-party default search engine. |
1404 TemplateURL* user_dse = AddKeywordWithDate( | 1420 TemplateURL* user_dse = AddKeywordWithDate( |
1405 "user", "user", "http://www.goo.com/s?q={searchTerms}", | 1421 "user", "user", "http://www.goo.com/s?q={searchTerms}", std::string(), |
1406 std::string(), std::string(), std::string(), | 1422 std::string(), std::string(), true, "UTF-8", Time(), Time(), Time()); |
1407 true, "UTF-8", Time(), Time()); | |
1408 model()->SetUserSelectedDefaultSearchProvider(user_dse); | 1423 model()->SetUserSelectedDefaultSearchProvider(user_dse); |
1409 EXPECT_EQ(user_dse, model()->GetDefaultSearchProvider()); | 1424 EXPECT_EQ(user_dse, model()->GetDefaultSearchProvider()); |
1410 | 1425 |
1411 std::unique_ptr<TemplateURL> ext_dse = CreateKeywordWithDate( | 1426 std::unique_ptr<TemplateURL> ext_dse = CreateKeywordWithDate( |
1412 model(), "ext1", "ext1", "http://www.ext1.com/s?q={searchTerms}", | 1427 model(), "ext1", "ext1", "http://www.ext1.com/s?q={searchTerms}", |
1413 std::string(), std::string(), std::string(), true, 0, "UTF-8", Time(), | 1428 std::string(), std::string(), std::string(), true, 0, "UTF-8", Time(), |
1414 Time(), TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION); | 1429 Time(), Time(), TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION); |
1415 std::unique_ptr<TemplateURL::AssociatedExtensionInfo> extension_info( | 1430 std::unique_ptr<TemplateURL::AssociatedExtensionInfo> extension_info( |
1416 new TemplateURL::AssociatedExtensionInfo("ext1")); | 1431 new TemplateURL::AssociatedExtensionInfo("ext1")); |
1417 extension_info->wants_to_be_default_engine = false; | 1432 extension_info->wants_to_be_default_engine = false; |
1418 model()->AddExtensionControlledTURL(std::move(ext_dse), | 1433 model()->AddExtensionControlledTURL(std::move(ext_dse), |
1419 std::move(extension_info)); | 1434 std::move(extension_info)); |
1420 EXPECT_EQ(user_dse, model()->GetDefaultSearchProvider()); | 1435 EXPECT_EQ(user_dse, model()->GetDefaultSearchProvider()); |
1421 | 1436 |
1422 ext_dse = CreateKeywordWithDate( | 1437 ext_dse = CreateKeywordWithDate( |
1423 model(), "ext2", "ext2", "http://www.ext2.com/s?q={searchTerms}", | 1438 model(), "ext2", "ext2", "http://www.ext2.com/s?q={searchTerms}", |
1424 std::string(), std::string(), std::string(), true, kPrepopulatedId, | 1439 std::string(), std::string(), std::string(), true, kPrepopulatedId, |
1425 "UTF-8", Time(), Time(), TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION); | 1440 "UTF-8", Time(), Time(), Time(), |
| 1441 TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION); |
1426 extension_info.reset(new TemplateURL::AssociatedExtensionInfo("ext2")); | 1442 extension_info.reset(new TemplateURL::AssociatedExtensionInfo("ext2")); |
1427 extension_info->wants_to_be_default_engine = true; | 1443 extension_info->wants_to_be_default_engine = true; |
1428 TemplateURL* ext_dse_ptr = model()->AddExtensionControlledTURL( | 1444 TemplateURL* ext_dse_ptr = model()->AddExtensionControlledTURL( |
1429 std::move(ext_dse), std::move(extension_info)); | 1445 std::move(ext_dse), std::move(extension_info)); |
1430 EXPECT_EQ(ext_dse_ptr, model()->GetDefaultSearchProvider()); | 1446 EXPECT_EQ(ext_dse_ptr, model()->GetDefaultSearchProvider()); |
1431 | 1447 |
1432 test_util()->ResetModel(true); | 1448 test_util()->ResetModel(true); |
1433 user_dse = model()->GetTemplateURLForKeyword(ASCIIToUTF16("user")); | 1449 user_dse = model()->GetTemplateURLForKeyword(ASCIIToUTF16("user")); |
1434 ExpectSimilar(user_dse, model()->GetDefaultSearchProvider()); | 1450 ExpectSimilar(user_dse, model()->GetDefaultSearchProvider()); |
1435 EXPECT_FALSE(model()->GetTemplateURLForKeyword(ASCIIToUTF16("ext1"))); | 1451 EXPECT_FALSE(model()->GetTemplateURLForKeyword(ASCIIToUTF16("ext1"))); |
1436 EXPECT_FALSE(model()->GetTemplateURLForKeyword(ASCIIToUTF16("ext2"))); | 1452 EXPECT_FALSE(model()->GetTemplateURLForKeyword(ASCIIToUTF16("ext2"))); |
1437 } | 1453 } |
1438 | 1454 |
1439 TEST_F(TemplateURLServiceTest, ExtensionEngineVsPolicy) { | 1455 TEST_F(TemplateURLServiceTest, ExtensionEngineVsPolicy) { |
1440 // Set a managed preference that establishes a default search provider. | 1456 // Set a managed preference that establishes a default search provider. |
1441 std::unique_ptr<TemplateURLData> managed = CreateTestSearchEngine(); | 1457 std::unique_ptr<TemplateURLData> managed = CreateTestSearchEngine(); |
1442 SetManagedDefaultSearchPreferences(*managed, true, test_util()->profile()); | 1458 SetManagedDefaultSearchPreferences(*managed, true, test_util()->profile()); |
1443 test_util()->VerifyLoad(); | 1459 test_util()->VerifyLoad(); |
1444 // Verify that the default manager we are getting is the managed one. | 1460 // Verify that the default manager we are getting is the managed one. |
1445 auto expected_managed_default = base::MakeUnique<TemplateURL>(*managed); | 1461 auto expected_managed_default = base::MakeUnique<TemplateURL>(*managed); |
1446 EXPECT_TRUE(model()->is_default_search_managed()); | 1462 EXPECT_TRUE(model()->is_default_search_managed()); |
1447 const TemplateURL* actual_managed_default = | 1463 const TemplateURL* actual_managed_default = |
1448 model()->GetDefaultSearchProvider(); | 1464 model()->GetDefaultSearchProvider(); |
1449 ExpectSimilar(expected_managed_default.get(), actual_managed_default); | 1465 ExpectSimilar(expected_managed_default.get(), actual_managed_default); |
1450 | 1466 |
1451 std::unique_ptr<TemplateURL> ext_dse = CreateKeywordWithDate( | 1467 std::unique_ptr<TemplateURL> ext_dse = CreateKeywordWithDate( |
1452 model(), "ext1", "ext1", "http://www.ext1.com/s?q={searchTerms}", | 1468 model(), "ext1", "ext1", "http://www.ext1.com/s?q={searchTerms}", |
1453 std::string(), std::string(), std::string(), true, kPrepopulatedId, | 1469 std::string(), std::string(), std::string(), true, kPrepopulatedId, |
1454 "UTF-8", Time(), Time(), TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION); | 1470 "UTF-8", Time(), Time(), Time(), |
| 1471 TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION); |
1455 auto extension_info = | 1472 auto extension_info = |
1456 base::MakeUnique<TemplateURL::AssociatedExtensionInfo>("ext1"); | 1473 base::MakeUnique<TemplateURL::AssociatedExtensionInfo>("ext1"); |
1457 extension_info->wants_to_be_default_engine = true; | 1474 extension_info->wants_to_be_default_engine = true; |
1458 TemplateURL* ext_dse_ptr = model()->AddExtensionControlledTURL( | 1475 TemplateURL* ext_dse_ptr = model()->AddExtensionControlledTURL( |
1459 std::move(ext_dse), std::move(extension_info)); | 1476 std::move(ext_dse), std::move(extension_info)); |
1460 EXPECT_EQ(ext_dse_ptr, | 1477 EXPECT_EQ(ext_dse_ptr, |
1461 model()->GetTemplateURLForKeyword(ASCIIToUTF16("ext1"))); | 1478 model()->GetTemplateURLForKeyword(ASCIIToUTF16("ext1"))); |
1462 EXPECT_TRUE(model()->is_default_search_managed()); | 1479 EXPECT_TRUE(model()->is_default_search_managed()); |
1463 actual_managed_default = model()->GetDefaultSearchProvider(); | 1480 actual_managed_default = model()->GetDefaultSearchProvider(); |
1464 ExpectSimilar(expected_managed_default.get(), actual_managed_default); | 1481 ExpectSimilar(expected_managed_default.get(), actual_managed_default); |
1465 } | 1482 } |
| 1483 |
| 1484 TEST_F(TemplateURLServiceTest, LastVisitedTimeUpdate) { |
| 1485 test_util()->VerifyLoad(); |
| 1486 TemplateURL* original_url = AddKeywordWithDate( |
| 1487 "name1", "key1", "http://foo1", "http://suggest1", std::string(), |
| 1488 "http://icon1", true, "UTF-8;UTF-16", Time(), Time(), Time()); |
| 1489 const base::Time original_last_visited = original_url->last_visited(); |
| 1490 model()->UpdateTemplateURLVisitTime(original_url); |
| 1491 TemplateURL* modified_url = |
| 1492 model()->GetTemplateURLForKeyword(ASCIIToUTF16("key1")); |
| 1493 const base::Time modified_last_visited = modified_url->last_visited(); |
| 1494 EXPECT_NE(original_last_visited, modified_last_visited); |
| 1495 test_util()->ResetModel(true); |
| 1496 TemplateURL* reloaded_url = |
| 1497 model()->GetTemplateURLForKeyword(ASCIIToUTF16("key1")); |
| 1498 AssertTimesEqual(modified_last_visited, reloaded_url->last_visited()); |
| 1499 } |
OLD | NEW |