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

Side by Side Diff: chrome/browser/search_engines/template_url_service_unittest.cc

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

Powered by Google App Engine
This is Rietveld 408576698