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 "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/bind_helpers.h" | 6 #include "base/bind_helpers.h" |
7 #include "base/callback.h" | 7 #include "base/callback.h" |
8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
9 #include "base/memory/scoped_vector.h" | 9 #include "base/memory/scoped_vector.h" |
10 #include "base/string_split.h" | 10 #include "base/string_split.h" |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 t_url->SetSuggestionsURL(suggest_url); | 251 t_url->SetSuggestionsURL(suggest_url); |
252 t_url->SetURL(url); | 252 t_url->SetURL(url); |
253 t_url->set_favicon_url(GURL(favicon_url)); | 253 t_url->set_favicon_url(GURL(favicon_url)); |
254 model()->Add(t_url); | 254 model()->Add(t_url); |
255 EXPECT_NE(0, t_url->id()); | 255 EXPECT_NE(0, t_url->id()); |
256 return t_url; | 256 return t_url; |
257 } | 257 } |
258 | 258 |
259 void TemplateURLServiceTest::AssertEquals(const TemplateURL& expected, | 259 void TemplateURLServiceTest::AssertEquals(const TemplateURL& expected, |
260 const TemplateURL& actual) { | 260 const TemplateURL& actual) { |
261 ASSERT_TRUE(TemplateURLRef::SameUrlRefs(expected.url(), actual.url())); | 261 ASSERT_EQ(expected.short_name(), actual.short_name()); |
262 ASSERT_TRUE(TemplateURLRef::SameUrlRefs(expected.suggestions_url(), | 262 ASSERT_EQ(expected.url(), actual.url()); |
263 actual.suggestions_url())); | 263 ASSERT_EQ(expected.suggestions_url(), actual.suggestions_url()); |
264 ASSERT_EQ(expected.keyword(), actual.keyword()); | 264 ASSERT_EQ(expected.keyword(), actual.keyword()); |
265 ASSERT_EQ(expected.short_name(), actual.short_name()); | 265 ASSERT_EQ(expected.show_in_default_list(), actual.show_in_default_list()); |
266 ASSERT_EQ(JoinString(expected.input_encodings(), ';'), | 266 ASSERT_EQ(expected.safe_for_autoreplace(), actual.safe_for_autoreplace()); |
267 JoinString(actual.input_encodings(), ';')); | |
268 ASSERT_EQ(expected.favicon_url(), actual.favicon_url()); | 267 ASSERT_EQ(expected.favicon_url(), actual.favicon_url()); |
269 ASSERT_EQ(expected.id(), actual.id()); | |
270 ASSERT_EQ(expected.safe_for_autoreplace(), actual.safe_for_autoreplace()); | |
271 ASSERT_EQ(expected.show_in_default_list(), actual.show_in_default_list()); | |
272 ASSERT_EQ(expected.date_created(), actual.date_created()); | 268 ASSERT_EQ(expected.date_created(), actual.date_created()); |
273 ASSERT_EQ(expected.last_modified(), actual.last_modified()); | 269 ASSERT_EQ(expected.last_modified(), actual.last_modified()); |
| 270 ASSERT_EQ(expected.input_encodings(), actual.input_encodings()); |
| 271 ASSERT_EQ(expected.id(), actual.id()); |
274 ASSERT_EQ(expected.sync_guid(), actual.sync_guid()); | 272 ASSERT_EQ(expected.sync_guid(), actual.sync_guid()); |
275 } | 273 } |
276 | 274 |
277 void TemplateURLServiceTest::ExpectSimilar(const TemplateURL* expected, | 275 void TemplateURLServiceTest::ExpectSimilar(const TemplateURL* expected, |
278 const TemplateURL* actual) { | 276 const TemplateURL* actual) { |
279 ASSERT_TRUE(expected != NULL); | 277 ASSERT_TRUE(expected != NULL); |
280 ASSERT_TRUE(actual != NULL); | 278 ASSERT_TRUE(actual != NULL); |
281 EXPECT_TRUE(TemplateURLRef::SameUrlRefs(expected->url(), actual->url())); | 279 EXPECT_EQ(expected->short_name(), actual->short_name()); |
282 EXPECT_TRUE(TemplateURLRef::SameUrlRefs(expected->suggestions_url(), | 280 EXPECT_EQ(expected->url(), actual->url()); |
283 actual->suggestions_url())); | 281 EXPECT_EQ(expected->suggestions_url(), actual->suggestions_url()); |
284 EXPECT_EQ(expected->keyword(), actual->keyword()); | 282 EXPECT_EQ(expected->keyword(), actual->keyword()); |
285 EXPECT_EQ(expected->short_name(), actual->short_name()); | 283 EXPECT_EQ(expected->show_in_default_list(), actual->show_in_default_list()); |
286 EXPECT_EQ(JoinString(expected->input_encodings(), ';'), | 284 EXPECT_EQ(expected->safe_for_autoreplace(), actual->safe_for_autoreplace()); |
287 JoinString(actual->input_encodings(), ';')); | |
288 EXPECT_EQ(expected->favicon_url(), actual->favicon_url()); | 285 EXPECT_EQ(expected->favicon_url(), actual->favicon_url()); |
289 EXPECT_EQ(expected->safe_for_autoreplace(), actual->safe_for_autoreplace()); | 286 EXPECT_EQ(expected->input_encodings(), actual->input_encodings()); |
290 EXPECT_EQ(expected->show_in_default_list(), actual->show_in_default_list()); | |
291 } | 287 } |
292 | 288 |
293 void TemplateURLServiceTest::SetManagedDefaultSearchPreferences( | 289 void TemplateURLServiceTest::SetManagedDefaultSearchPreferences( |
294 bool enabled, | 290 bool enabled, |
295 const std::string& name, | 291 const std::string& name, |
296 const std::string& search_url, | 292 const std::string& search_url, |
297 const std::string& suggest_url, | 293 const std::string& suggest_url, |
298 const std::string& icon_url, | 294 const std::string& icon_url, |
299 const std::string& encodings, | 295 const std::string& encodings, |
300 const std::string& keyword) { | 296 const std::string& keyword) { |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
336 size_t default_search_provider_index = 0; | 332 size_t default_search_provider_index = 0; |
337 TemplateURLPrepopulateData::GetPrepopulatedEngines( | 333 TemplateURLPrepopulateData::GetPrepopulatedEngines( |
338 test_util_.profile()->GetPrefs(), &prepopulated_urls.get(), | 334 test_util_.profile()->GetPrefs(), &prepopulated_urls.get(), |
339 &default_search_provider_index); | 335 &default_search_provider_index); |
340 EXPECT_LT(index_offset_from_default, prepopulated_urls.size()); | 336 EXPECT_LT(index_offset_from_default, prepopulated_urls.size()); |
341 size_t prepopulated_index = (default_search_provider_index + | 337 size_t prepopulated_index = (default_search_provider_index + |
342 index_offset_from_default) % prepopulated_urls.size(); | 338 index_offset_from_default) % prepopulated_urls.size(); |
343 TemplateURL* t_url = CreatePreloadedTemplateURL(safe_for_autoreplace, | 339 TemplateURL* t_url = CreatePreloadedTemplateURL(safe_for_autoreplace, |
344 prepopulated_urls[prepopulated_index]->prepopulate_id()); | 340 prepopulated_urls[prepopulated_index]->prepopulate_id()); |
345 *prepopulated_display_url = | 341 *prepopulated_display_url = |
346 prepopulated_urls[prepopulated_index]->url()->DisplayURL(); | 342 prepopulated_urls[prepopulated_index]->url_ref().DisplayURL(); |
347 return t_url; | 343 return t_url; |
348 } | 344 } |
349 | 345 |
350 void TemplateURLServiceTest::TestLoadUpdatingPreloadedURL( | 346 void TemplateURLServiceTest::TestLoadUpdatingPreloadedURL( |
351 size_t index_offset_from_default) { | 347 size_t index_offset_from_default) { |
352 string16 prepopulated_url; | 348 string16 prepopulated_url; |
353 TemplateURL* t_url = CreateReplaceablePreloadedTemplateURL(false, | 349 TemplateURL* t_url = CreateReplaceablePreloadedTemplateURL(false, |
354 index_offset_from_default, &prepopulated_url); | 350 index_offset_from_default, &prepopulated_url); |
355 | 351 |
356 string16 original_url = t_url->url()->DisplayURL(); | 352 string16 original_url = t_url->url_ref().DisplayURL(); |
357 ASSERT_NE(prepopulated_url, original_url); | 353 ASSERT_NE(prepopulated_url, original_url); |
358 | 354 |
359 // Then add it to the model and save it all. | 355 // Then add it to the model and save it all. |
360 test_util_.ChangeModelToLoadState(); | 356 test_util_.ChangeModelToLoadState(); |
361 model()->Add(t_url); | 357 model()->Add(t_url); |
362 const TemplateURL* keyword_url = | 358 const TemplateURL* keyword_url = |
363 model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")); | 359 model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")); |
364 ASSERT_EQ(t_url, keyword_url); | 360 ASSERT_EQ(t_url, keyword_url); |
365 ASSERT_EQ(original_url, keyword_url->url()->DisplayURL()); | 361 ASSERT_EQ(original_url, keyword_url->url_ref().DisplayURL()); |
366 test_util_.BlockTillServiceProcessesRequests(); | 362 test_util_.BlockTillServiceProcessesRequests(); |
367 | 363 |
368 // Now reload the model and verify that the merge updates the url. | 364 // Now reload the model and verify that the merge updates the url. |
369 test_util_.ResetModel(true); | 365 test_util_.ResetModel(true); |
370 keyword_url = model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")); | 366 keyword_url = model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")); |
371 ASSERT_TRUE(keyword_url != NULL); | 367 ASSERT_TRUE(keyword_url != NULL); |
372 ASSERT_EQ(prepopulated_url, keyword_url->url()->DisplayURL()); | 368 ASSERT_EQ(prepopulated_url, keyword_url->url_ref().DisplayURL()); |
373 | 369 |
374 // Wait for any saves to finish. | 370 // Wait for any saves to finish. |
375 test_util_.BlockTillServiceProcessesRequests(); | 371 test_util_.BlockTillServiceProcessesRequests(); |
376 | 372 |
377 // Reload the model to verify that change was saved correctly. | 373 // Reload the model to verify that change was saved correctly. |
378 test_util_.ResetModel(true); | 374 test_util_.ResetModel(true); |
379 keyword_url = model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")); | 375 keyword_url = model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")); |
380 ASSERT_TRUE(keyword_url != NULL); | 376 ASSERT_TRUE(keyword_url != NULL); |
381 ASSERT_EQ(prepopulated_url, keyword_url->url()->DisplayURL()); | 377 ASSERT_EQ(prepopulated_url, keyword_url->url_ref().DisplayURL()); |
382 } | 378 } |
383 | 379 |
384 void TemplateURLServiceTest::VerifyObserverCount(int expected_changed_count) { | 380 void TemplateURLServiceTest::VerifyObserverCount(int expected_changed_count) { |
385 EXPECT_EQ(expected_changed_count, test_util_.GetObserverCount()); | 381 EXPECT_EQ(expected_changed_count, test_util_.GetObserverCount()); |
386 test_util_.ResetObserverCount(); | 382 test_util_.ResetObserverCount(); |
387 } | 383 } |
388 | 384 |
389 void TemplateURLServiceTest::VerifyObserverFired() { | 385 void TemplateURLServiceTest::VerifyObserverFired() { |
390 EXPECT_LE(1, test_util_.GetObserverCount()); | 386 EXPECT_LE(1, test_util_.GetObserverCount()); |
391 test_util_.ResetObserverCount(); | 387 test_util_.ResetObserverCount(); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
439 // resets the TimeProvider in the TemplateURLService. | 435 // resets the TimeProvider in the TemplateURLService. |
440 StrictMock<base::MockTimeProvider> mock_time; | 436 StrictMock<base::MockTimeProvider> mock_time; |
441 model()->set_time_provider(&base::MockTimeProvider::StaticNow); | 437 model()->set_time_provider(&base::MockTimeProvider::StaticNow); |
442 EXPECT_CALL(mock_time, Now()).WillOnce(Return(base::Time::FromDoubleT(1337))); | 438 EXPECT_CALL(mock_time, Now()).WillOnce(Return(base::Time::FromDoubleT(1337))); |
443 | 439 |
444 // Mutate an element and verify it succeeded. | 440 // Mutate an element and verify it succeeded. |
445 model()->ResetTemplateURL(loaded_url, ASCIIToUTF16("a"), ASCIIToUTF16("b"), | 441 model()->ResetTemplateURL(loaded_url, ASCIIToUTF16("a"), ASCIIToUTF16("b"), |
446 "c"); | 442 "c"); |
447 ASSERT_EQ(ASCIIToUTF16("a"), loaded_url->short_name()); | 443 ASSERT_EQ(ASCIIToUTF16("a"), loaded_url->short_name()); |
448 ASSERT_EQ(ASCIIToUTF16("b"), loaded_url->keyword()); | 444 ASSERT_EQ(ASCIIToUTF16("b"), loaded_url->keyword()); |
449 ASSERT_EQ("c", loaded_url->url()->url()); | 445 ASSERT_EQ("c", loaded_url->url()); |
450 ASSERT_FALSE(loaded_url->safe_for_autoreplace()); | 446 ASSERT_FALSE(loaded_url->safe_for_autoreplace()); |
451 ASSERT_TRUE(model()->CanReplaceKeyword(ASCIIToUTF16("keyword"), GURL(), | 447 ASSERT_TRUE(model()->CanReplaceKeyword(ASCIIToUTF16("keyword"), GURL(), |
452 NULL)); | 448 NULL)); |
453 ASSERT_FALSE(model()->CanReplaceKeyword(ASCIIToUTF16("b"), GURL(), NULL)); | 449 ASSERT_FALSE(model()->CanReplaceKeyword(ASCIIToUTF16("b"), GURL(), NULL)); |
454 cloned_url = *loaded_url; | 450 cloned_url = *loaded_url; |
455 test_util_.BlockTillServiceProcessesRequests(); | 451 test_util_.BlockTillServiceProcessesRequests(); |
456 test_util_.ResetModel(true); | 452 test_util_.ResetModel(true); |
457 ASSERT_EQ(initial_count + 1, model()->GetTemplateURLs().size()); | 453 ASSERT_EQ(initial_count + 1, model()->GetTemplateURLs().size()); |
458 loaded_url = model()->GetTemplateURLForKeyword(ASCIIToUTF16("b")); | 454 loaded_url = model()->GetTemplateURLForKeyword(ASCIIToUTF16("b")); |
459 ASSERT_TRUE(loaded_url != NULL); | 455 ASSERT_TRUE(loaded_url != NULL); |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
646 model()->set_time_provider(&base::MockTimeProvider::StaticNow); | 642 model()->set_time_provider(&base::MockTimeProvider::StaticNow); |
647 EXPECT_CALL(mock_time, Now()).WillOnce(Return(base::Time::FromDoubleT(1337))); | 643 EXPECT_CALL(mock_time, Now()).WillOnce(Return(base::Time::FromDoubleT(1337))); |
648 | 644 |
649 // Reset the short name, keyword, url and make sure it takes. | 645 // Reset the short name, keyword, url and make sure it takes. |
650 const string16 new_short_name(ASCIIToUTF16("a")); | 646 const string16 new_short_name(ASCIIToUTF16("a")); |
651 const string16 new_keyword(ASCIIToUTF16("b")); | 647 const string16 new_keyword(ASCIIToUTF16("b")); |
652 const std::string new_url("c"); | 648 const std::string new_url("c"); |
653 model()->ResetTemplateURL(t_url, new_short_name, new_keyword, new_url); | 649 model()->ResetTemplateURL(t_url, new_short_name, new_keyword, new_url); |
654 ASSERT_EQ(new_short_name, t_url->short_name()); | 650 ASSERT_EQ(new_short_name, t_url->short_name()); |
655 ASSERT_EQ(new_keyword, t_url->keyword()); | 651 ASSERT_EQ(new_keyword, t_url->keyword()); |
656 ASSERT_EQ(new_url, t_url->url()->url()); | 652 ASSERT_EQ(new_url, t_url->url()); |
657 | 653 |
658 // Make sure the mappings in the model were updated. | 654 // Make sure the mappings in the model were updated. |
659 ASSERT_EQ(t_url, model()->GetTemplateURLForKeyword(new_keyword)); | 655 ASSERT_EQ(t_url, model()->GetTemplateURLForKeyword(new_keyword)); |
660 ASSERT_TRUE( | 656 ASSERT_TRUE( |
661 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword")) == NULL); | 657 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword")) == NULL); |
662 | 658 |
663 TemplateURL last_url(*t_url); | 659 TemplateURL last_url(*t_url); |
664 | 660 |
665 // Reload the model from the database and make sure the change took. | 661 // Reload the model from the database and make sure the change took. |
666 test_util_.ResetModel(true); | 662 test_util_.ResetModel(true); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
731 "http://sugg1", "http://icon1", "UTF-8;UTF-16", "name1", true, Time(), | 727 "http://sugg1", "http://icon1", "UTF-8;UTF-16", "name1", true, Time(), |
732 Time()); | 728 Time()); |
733 | 729 |
734 // Can still replace, newly added template url is marked safe to replace. | 730 // Can still replace, newly added template url is marked safe to replace. |
735 ASSERT_TRUE(model()->CanReplaceKeyword(ASCIIToUTF16("foo"), | 731 ASSERT_TRUE(model()->CanReplaceKeyword(ASCIIToUTF16("foo"), |
736 GURL("http://foo2"), NULL)); | 732 GURL("http://foo2"), NULL)); |
737 | 733 |
738 // ResetTemplateURL marks the TemplateURL as unsafe to replace, so it should | 734 // ResetTemplateURL marks the TemplateURL as unsafe to replace, so it should |
739 // no longer be replaceable. | 735 // no longer be replaceable. |
740 model()->ResetTemplateURL(t_url, t_url->short_name(), t_url->keyword(), | 736 model()->ResetTemplateURL(t_url, t_url->short_name(), t_url->keyword(), |
741 t_url->url()->url()); | 737 t_url->url()); |
742 | 738 |
743 ASSERT_FALSE(model()->CanReplaceKeyword(ASCIIToUTF16("foo"), | 739 ASSERT_FALSE(model()->CanReplaceKeyword(ASCIIToUTF16("foo"), |
744 GURL("http://foo2"), NULL)); | 740 GURL("http://foo2"), NULL)); |
745 } | 741 } |
746 | 742 |
747 TEST_F(TemplateURLServiceTest, CantReplaceWithSameHosts) { | 743 TEST_F(TemplateURLServiceTest, CantReplaceWithSameHosts) { |
748 test_util_.ChangeModelToLoadState(); | 744 test_util_.ChangeModelToLoadState(); |
749 ASSERT_TRUE(model()->CanReplaceKeyword(ASCIIToUTF16("foo"), | 745 ASSERT_TRUE(model()->CanReplaceKeyword(ASCIIToUTF16("foo"), |
750 GURL("http://foo.com"), NULL)); | 746 GURL("http://foo.com"), NULL)); |
751 TemplateURL* t_url = AddKeywordWithDate("foo", false, "http://foo.com", | 747 TemplateURL* t_url = AddKeywordWithDate("foo", false, "http://foo.com", |
752 "http://sugg1", "http://icon1", "UTF-8;UTF-16", "name1", true, Time(), | 748 "http://sugg1", "http://icon1", "UTF-8;UTF-16", "name1", true, Time(), |
753 Time()); | 749 Time()); |
754 | 750 |
755 // Can still replace, newly added template url is marked safe to replace. | 751 // Can still replace, newly added template url is marked safe to replace. |
756 ASSERT_TRUE(model()->CanReplaceKeyword(ASCIIToUTF16("bar"), | 752 ASSERT_TRUE(model()->CanReplaceKeyword(ASCIIToUTF16("bar"), |
757 GURL("http://foo.com"), NULL)); | 753 GURL("http://foo.com"), NULL)); |
758 | 754 |
759 // ResetTemplateURL marks the TemplateURL as unsafe to replace, so it should | 755 // ResetTemplateURL marks the TemplateURL as unsafe to replace, so it should |
760 // no longer be replaceable. | 756 // no longer be replaceable. |
761 model()->ResetTemplateURL(t_url, t_url->short_name(), t_url->keyword(), | 757 model()->ResetTemplateURL(t_url, t_url->short_name(), t_url->keyword(), |
762 t_url->url()->url()); | 758 t_url->url()); |
763 | 759 |
764 ASSERT_FALSE(model()->CanReplaceKeyword(ASCIIToUTF16("bar"), | 760 ASSERT_FALSE(model()->CanReplaceKeyword(ASCIIToUTF16("bar"), |
765 GURL("http://foo.com"), NULL)); | 761 GURL("http://foo.com"), NULL)); |
766 } | 762 } |
767 | 763 |
768 TEST_F(TemplateURLServiceTest, HasDefaultSearchProvider) { | 764 TEST_F(TemplateURLServiceTest, HasDefaultSearchProvider) { |
769 // We should have a default search provider even if we haven't loaded. | 765 // We should have a default search provider even if we haven't loaded. |
770 ASSERT_TRUE(model()->GetDefaultSearchProvider()); | 766 ASSERT_TRUE(model()->GetDefaultSearchProvider()); |
771 | 767 |
772 // Now force the model to load and make sure we still have a default. | 768 // Now force the model to load and make sure we still have a default. |
(...skipping 21 matching lines...) Expand all Loading... |
794 TemplateURL first_default_search_provider(*t_url); | 790 TemplateURL first_default_search_provider(*t_url); |
795 | 791 |
796 // Reset the model and don't load it. The template url we set as the default | 792 // Reset the model and don't load it. The template url we set as the default |
797 // should be pulled from prefs now. | 793 // should be pulled from prefs now. |
798 test_util_.ResetModel(false); | 794 test_util_.ResetModel(false); |
799 | 795 |
800 // NOTE: This doesn't use AssertEquals as only a subset of the TemplateURLs | 796 // NOTE: This doesn't use AssertEquals as only a subset of the TemplateURLs |
801 // value are persisted to prefs. | 797 // value are persisted to prefs. |
802 const TemplateURL* default_turl = model()->GetDefaultSearchProvider(); | 798 const TemplateURL* default_turl = model()->GetDefaultSearchProvider(); |
803 ASSERT_TRUE(default_turl); | 799 ASSERT_TRUE(default_turl); |
804 ASSERT_TRUE(default_turl->url()); | 800 ASSERT_EQ("http://url", default_turl->url()); |
805 ASSERT_EQ("http://url", default_turl->url()->url()); | 801 ASSERT_EQ("http://url2", default_turl->suggestions_url()); |
806 ASSERT_TRUE(default_turl->suggestions_url()); | 802 EXPECT_EQ("http://instant", default_turl->instant_url()); |
807 ASSERT_EQ("http://url2", default_turl->suggestions_url()->url()); | |
808 ASSERT_TRUE(default_turl->instant_url()); | |
809 EXPECT_EQ("http://instant", default_turl->instant_url()->url()); | |
810 ASSERT_EQ(ASCIIToUTF16("a"), default_turl->short_name()); | 803 ASSERT_EQ(ASCIIToUTF16("a"), default_turl->short_name()); |
811 ASSERT_EQ(id, default_turl->id()); | 804 ASSERT_EQ(id, default_turl->id()); |
812 | 805 |
813 // Now do a load and make sure the default search provider really takes. | 806 // Now do a load and make sure the default search provider really takes. |
814 test_util_.VerifyLoad(); | 807 test_util_.VerifyLoad(); |
815 | 808 |
816 ASSERT_TRUE(model()->GetDefaultSearchProvider()); | 809 ASSERT_TRUE(model()->GetDefaultSearchProvider()); |
817 AssertEquals(first_default_search_provider, | 810 AssertEquals(first_default_search_provider, |
818 *model()->GetDefaultSearchProvider()); | 811 *model()->GetDefaultSearchProvider()); |
819 } | 812 } |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
917 TEST_F(TemplateURLServiceTest, ChangeGoogleBaseValue) { | 910 TEST_F(TemplateURLServiceTest, ChangeGoogleBaseValue) { |
918 // NOTE: Do not do a VerifyLoad() here as it will load the prepopulate data, | 911 // NOTE: Do not do a VerifyLoad() here as it will load the prepopulate data, |
919 // which also has a {google:baseURL} keyword in it, which will confuse this | 912 // which also has a {google:baseURL} keyword in it, which will confuse this |
920 // test. | 913 // test. |
921 test_util_.ChangeModelToLoadState(); | 914 test_util_.ChangeModelToLoadState(); |
922 test_util_.SetGoogleBaseURL("http://google.com/"); | 915 test_util_.SetGoogleBaseURL("http://google.com/"); |
923 const TemplateURL* t_url = AddKeywordWithDate("google.com", true, | 916 const TemplateURL* t_url = AddKeywordWithDate("google.com", true, |
924 "{google:baseURL}?q={searchTerms}", "http://sugg1", "http://icon1", | 917 "{google:baseURL}?q={searchTerms}", "http://sugg1", "http://icon1", |
925 "UTF-8;UTF-16", "name", false, Time(), Time()); | 918 "UTF-8;UTF-16", "name", false, Time(), Time()); |
926 ASSERT_EQ(t_url, model()->GetTemplateURLForHost("google.com")); | 919 ASSERT_EQ(t_url, model()->GetTemplateURLForHost("google.com")); |
927 EXPECT_EQ("google.com", t_url->url()->GetHost()); | 920 EXPECT_EQ("google.com", t_url->url_ref().GetHost()); |
928 EXPECT_EQ(ASCIIToUTF16("google.com"), t_url->keyword()); | 921 EXPECT_EQ(ASCIIToUTF16("google.com"), t_url->keyword()); |
929 | 922 |
930 // Change the Google base url. | 923 // Change the Google base url. |
931 test_util_.ResetObserverCount(); | 924 test_util_.ResetObserverCount(); |
932 test_util_.SetGoogleBaseURL("http://google.co.uk/"); | 925 test_util_.SetGoogleBaseURL("http://google.co.uk/"); |
933 VerifyObserverCount(1); | 926 VerifyObserverCount(1); |
934 | 927 |
935 // Make sure the host->TemplateURL map was updated appropriately. | 928 // Make sure the host->TemplateURL map was updated appropriately. |
936 ASSERT_EQ(t_url, model()->GetTemplateURLForHost("google.co.uk")); | 929 ASSERT_EQ(t_url, model()->GetTemplateURLForHost("google.co.uk")); |
937 EXPECT_TRUE(model()->GetTemplateURLForHost("google.com") == NULL); | 930 EXPECT_TRUE(model()->GetTemplateURLForHost("google.com") == NULL); |
938 EXPECT_EQ("google.co.uk", t_url->url()->GetHost()); | 931 EXPECT_EQ("google.co.uk", t_url->url_ref().GetHost()); |
939 EXPECT_EQ(ASCIIToUTF16("google.co.uk"), t_url->keyword()); | 932 EXPECT_EQ(ASCIIToUTF16("google.co.uk"), t_url->keyword()); |
940 EXPECT_EQ("http://google.co.uk/?q=x", t_url->url()->ReplaceSearchTerms( | 933 EXPECT_EQ("http://google.co.uk/?q=x", t_url->url_ref().ReplaceSearchTerms( |
941 ASCIIToUTF16("x"), TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16())); | 934 ASCIIToUTF16("x"), TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16())); |
942 } | 935 } |
943 | 936 |
944 struct QueryHistoryCallbackImpl { | 937 struct QueryHistoryCallbackImpl { |
945 QueryHistoryCallbackImpl() : success(false) {} | 938 QueryHistoryCallbackImpl() : success(false) {} |
946 | 939 |
947 void Callback(HistoryService::Handle handle, | 940 void Callback(HistoryService::Handle handle, |
948 bool success, | 941 bool success, |
949 const history::URLRow* row, | 942 const history::URLRow* row, |
950 history::VisitVector* visits) { | 943 history::VisitVector* visits) { |
(...skipping 18 matching lines...) Expand all Loading... |
969 // Create a keyword. | 962 // Create a keyword. |
970 TemplateURL* t_url = AddKeywordWithDate( | 963 TemplateURL* t_url = AddKeywordWithDate( |
971 "keyword", false, "http://foo.com/foo?query={searchTerms}", | 964 "keyword", false, "http://foo.com/foo?query={searchTerms}", |
972 "http://sugg1", "http://icon1", "UTF-8;UTF-16", "keyword", | 965 "http://sugg1", "http://icon1", "UTF-8;UTF-16", "keyword", |
973 true, base::Time::Now(), base::Time::Now()); | 966 true, base::Time::Now(), base::Time::Now()); |
974 | 967 |
975 // Add a visit that matches the url of the keyword. | 968 // Add a visit that matches the url of the keyword. |
976 HistoryService* history = | 969 HistoryService* history = |
977 test_util_.profile()->GetHistoryService(Profile::EXPLICIT_ACCESS); | 970 test_util_.profile()->GetHistoryService(Profile::EXPLICIT_ACCESS); |
978 history->AddPage( | 971 history->AddPage( |
979 GURL(t_url->url()->ReplaceSearchTerms(ASCIIToUTF16("blah"), | 972 GURL(t_url->url_ref().ReplaceSearchTerms(ASCIIToUTF16("blah"), |
980 TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16())), | 973 TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16())), |
981 NULL, 0, GURL(), content::PAGE_TRANSITION_KEYWORD, | 974 NULL, 0, GURL(), content::PAGE_TRANSITION_KEYWORD, |
982 history::RedirectList(), history::SOURCE_BROWSED, false); | 975 history::RedirectList(), history::SOURCE_BROWSED, false); |
983 | 976 |
984 // Wait for history to finish processing the request. | 977 // Wait for history to finish processing the request. |
985 test_util_.profile()->BlockUntilHistoryProcessesPendingRequests(); | 978 test_util_.profile()->BlockUntilHistoryProcessesPendingRequests(); |
986 | 979 |
987 // Query history for the generated url. | 980 // Query history for the generated url. |
988 CancelableRequestConsumer consumer; | 981 CancelableRequestConsumer consumer; |
989 QueryHistoryCallbackImpl callback; | 982 QueryHistoryCallbackImpl callback; |
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1318 | 1311 |
1319 // Reload the model to verify it was actually saved to the database and | 1312 // Reload the model to verify it was actually saved to the database and |
1320 // assigned a new GUID when brought back. | 1313 // assigned a new GUID when brought back. |
1321 test_util_.ResetModel(true); | 1314 test_util_.ResetModel(true); |
1322 ASSERT_EQ(initial_count + 1, model()->GetTemplateURLs().size()); | 1315 ASSERT_EQ(initial_count + 1, model()->GetTemplateURLs().size()); |
1323 const TemplateURL* loaded_url = | 1316 const TemplateURL* loaded_url = |
1324 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword")); | 1317 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword")); |
1325 ASSERT_TRUE(loaded_url != NULL); | 1318 ASSERT_TRUE(loaded_url != NULL); |
1326 ASSERT_FALSE(loaded_url->sync_guid().empty()); | 1319 ASSERT_FALSE(loaded_url->sync_guid().empty()); |
1327 } | 1320 } |
OLD | NEW |