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 "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 const std::string& url, | 63 const std::string& url, |
64 const std::string& suggest_url, | 64 const std::string& suggest_url, |
65 const std::string& alternate_url, | 65 const std::string& alternate_url, |
66 const std::string& favicon_url, | 66 const std::string& favicon_url, |
67 bool safe_for_autoreplace, | 67 bool safe_for_autoreplace, |
68 bool show_in_default_list, | 68 bool show_in_default_list, |
69 const std::string& encodings, | 69 const std::string& encodings, |
70 Time date_created, | 70 Time date_created, |
71 Time last_modified) { | 71 Time last_modified) { |
72 TemplateURLData data; | 72 TemplateURLData data; |
73 data.short_name = base::UTF8ToUTF16(short_name); | 73 data.SetShortName(base::UTF8ToUTF16(short_name)); |
74 data.SetKeyword(base::UTF8ToUTF16(keyword)); | 74 data.SetKeyword(base::UTF8ToUTF16(keyword)); |
75 data.SetURL(url); | 75 data.SetURL(url); |
76 data.suggestions_url = suggest_url; | 76 data.suggestions_url = suggest_url; |
77 if (!alternate_url.empty()) | 77 if (!alternate_url.empty()) |
78 data.alternate_urls.push_back(alternate_url); | 78 data.alternate_urls.push_back(alternate_url); |
79 data.favicon_url = GURL(favicon_url); | 79 data.favicon_url = GURL(favicon_url); |
80 data.safe_for_autoreplace = safe_for_autoreplace; | 80 data.safe_for_autoreplace = safe_for_autoreplace; |
81 data.show_in_default_list = show_in_default_list; | 81 data.show_in_default_list = show_in_default_list; |
82 base::SplitString(encodings, ';', &data.input_encodings); | 82 base::SplitString(encodings, ';', &data.input_encodings); |
83 data.date_created = date_created; | 83 data.date_created = date_created; |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 // Because times are stored with a granularity of one second, there is a loss | 242 // Because times are stored with a granularity of one second, there is a loss |
243 // of precision when serializing and deserializing the timestamps. Hence, only | 243 // of precision when serializing and deserializing the timestamps. Hence, only |
244 // expect timestamps to be equal to within one second of one another. | 244 // expect timestamps to be equal to within one second of one another. |
245 ASSERT_LT((expected - actual).magnitude(), base::TimeDelta::FromSeconds(1)); | 245 ASSERT_LT((expected - actual).magnitude(), base::TimeDelta::FromSeconds(1)); |
246 } | 246 } |
247 | 247 |
248 TemplateURL* TemplateURLServiceTest::CreatePreloadedTemplateURL( | 248 TemplateURL* TemplateURLServiceTest::CreatePreloadedTemplateURL( |
249 bool safe_for_autoreplace, | 249 bool safe_for_autoreplace, |
250 int prepopulate_id) { | 250 int prepopulate_id) { |
251 TemplateURLData data; | 251 TemplateURLData data; |
252 data.short_name = ASCIIToUTF16("unittest"); | 252 data.SetShortName(ASCIIToUTF16("unittest")); |
253 data.SetKeyword(ASCIIToUTF16("unittest")); | 253 data.SetKeyword(ASCIIToUTF16("unittest")); |
254 data.SetURL("http://www.unittest.com/{searchTerms}"); | 254 data.SetURL("http://www.unittest.com/{searchTerms}"); |
255 data.favicon_url = GURL("http://favicon.url"); | 255 data.favicon_url = GURL("http://favicon.url"); |
256 data.show_in_default_list = true; | 256 data.show_in_default_list = true; |
257 data.safe_for_autoreplace = safe_for_autoreplace; | 257 data.safe_for_autoreplace = safe_for_autoreplace; |
258 data.input_encodings.push_back("UTF-8"); | 258 data.input_encodings.push_back("UTF-8"); |
259 data.date_created = Time::FromTimeT(100); | 259 data.date_created = Time::FromTimeT(100); |
260 data.last_modified = Time::FromTimeT(100); | 260 data.last_modified = Time::FromTimeT(100); |
261 data.prepopulate_id = prepopulate_id; | 261 data.prepopulate_id = prepopulate_id; |
262 return new TemplateURL(data); | 262 return new TemplateURL(data); |
(...skipping 15 matching lines...) Expand all Loading... |
278 TEST_F(TemplateURLServiceTest, Load) { | 278 TEST_F(TemplateURLServiceTest, Load) { |
279 test_util()->VerifyLoad(); | 279 test_util()->VerifyLoad(); |
280 } | 280 } |
281 | 281 |
282 TEST_F(TemplateURLServiceTest, AddUpdateRemove) { | 282 TEST_F(TemplateURLServiceTest, AddUpdateRemove) { |
283 // Add a new TemplateURL. | 283 // Add a new TemplateURL. |
284 test_util()->VerifyLoad(); | 284 test_util()->VerifyLoad(); |
285 const size_t initial_count = model()->GetTemplateURLs().size(); | 285 const size_t initial_count = model()->GetTemplateURLs().size(); |
286 | 286 |
287 TemplateURLData data; | 287 TemplateURLData data; |
288 data.short_name = ASCIIToUTF16("google"); | 288 data.SetShortName(ASCIIToUTF16("google")); |
289 data.SetKeyword(ASCIIToUTF16("keyword")); | 289 data.SetKeyword(ASCIIToUTF16("keyword")); |
290 data.SetURL("http://www.google.com/foo/bar"); | 290 data.SetURL("http://www.google.com/foo/bar"); |
291 data.favicon_url = GURL("http://favicon.url"); | 291 data.favicon_url = GURL("http://favicon.url"); |
292 data.safe_for_autoreplace = true; | 292 data.safe_for_autoreplace = true; |
293 data.date_created = Time::FromTimeT(100); | 293 data.date_created = Time::FromTimeT(100); |
294 data.last_modified = Time::FromTimeT(100); | 294 data.last_modified = Time::FromTimeT(100); |
295 data.sync_guid = "00000000-0000-0000-0000-000000000001"; | 295 data.sync_guid = "00000000-0000-0000-0000-000000000001"; |
296 TemplateURL* t_url = new TemplateURL(data); | 296 TemplateURL* t_url = new TemplateURL(data); |
297 model()->Add(t_url); | 297 model()->Add(t_url); |
298 ASSERT_TRUE(model()->CanReplaceKeyword(ASCIIToUTF16("keyword"), GURL(), | 298 ASSERT_TRUE(model()->CanReplaceKeyword(ASCIIToUTF16("keyword"), GURL(), |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
356 test_util()->VerifyLoad(); | 356 test_util()->VerifyLoad(); |
357 | 357 |
358 AddKeywordWithDate( | 358 AddKeywordWithDate( |
359 "first", "keyword", "http://test1", std::string(), std::string(), | 359 "first", "keyword", "http://test1", std::string(), std::string(), |
360 std::string(), true, "UTF-8", Time(), Time()); | 360 std::string(), true, "UTF-8", Time(), Time()); |
361 VerifyObserverCount(1); | 361 VerifyObserverCount(1); |
362 | 362 |
363 // Test what happens when we try to add a TemplateURL with the same keyword as | 363 // Test what happens when we try to add a TemplateURL with the same keyword as |
364 // one in the model. | 364 // one in the model. |
365 TemplateURLData data; | 365 TemplateURLData data; |
366 data.short_name = ASCIIToUTF16("second"); | 366 data.SetShortName(ASCIIToUTF16("second")); |
367 data.SetKeyword(ASCIIToUTF16("keyword")); | 367 data.SetKeyword(ASCIIToUTF16("keyword")); |
368 data.SetURL("http://test2"); | 368 data.SetURL("http://test2"); |
369 data.safe_for_autoreplace = false; | 369 data.safe_for_autoreplace = false; |
370 TemplateURL* t_url = new TemplateURL(data); | 370 TemplateURL* t_url = new TemplateURL(data); |
371 model()->Add(t_url); | 371 model()->Add(t_url); |
372 | 372 |
373 // Because the old TemplateURL was replaceable and the new one wasn't, the new | 373 // Because the old TemplateURL was replaceable and the new one wasn't, the new |
374 // one should have replaced the old. | 374 // one should have replaced the old. |
375 VerifyObserverCount(1); | 375 VerifyObserverCount(1); |
376 EXPECT_EQ(t_url, model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword"))); | 376 EXPECT_EQ(t_url, model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword"))); |
377 EXPECT_EQ(ASCIIToUTF16("second"), t_url->short_name()); | 377 EXPECT_EQ(ASCIIToUTF16("second"), t_url->short_name()); |
378 EXPECT_EQ(ASCIIToUTF16("keyword"), t_url->keyword()); | 378 EXPECT_EQ(ASCIIToUTF16("keyword"), t_url->keyword()); |
379 EXPECT_FALSE(t_url->safe_for_autoreplace()); | 379 EXPECT_FALSE(t_url->safe_for_autoreplace()); |
380 | 380 |
381 // Now try adding a replaceable TemplateURL. This should just delete the | 381 // Now try adding a replaceable TemplateURL. This should just delete the |
382 // passed-in URL. | 382 // passed-in URL. |
383 data.short_name = ASCIIToUTF16("third"); | 383 data.SetShortName(ASCIIToUTF16("third")); |
384 data.SetURL("http://test3"); | 384 data.SetURL("http://test3"); |
385 data.safe_for_autoreplace = true; | 385 data.safe_for_autoreplace = true; |
386 model()->Add(new TemplateURL(data)); | 386 model()->Add(new TemplateURL(data)); |
387 VerifyObserverCount(0); | 387 VerifyObserverCount(0); |
388 EXPECT_EQ(t_url, model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword"))); | 388 EXPECT_EQ(t_url, model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword"))); |
389 EXPECT_EQ(ASCIIToUTF16("second"), t_url->short_name()); | 389 EXPECT_EQ(ASCIIToUTF16("second"), t_url->short_name()); |
390 EXPECT_EQ(ASCIIToUTF16("keyword"), t_url->keyword()); | 390 EXPECT_EQ(ASCIIToUTF16("keyword"), t_url->keyword()); |
391 EXPECT_FALSE(t_url->safe_for_autoreplace()); | 391 EXPECT_FALSE(t_url->safe_for_autoreplace()); |
392 | 392 |
393 // Now try adding a non-replaceable TemplateURL again. This should uniquify | 393 // Now try adding a non-replaceable TemplateURL again. This should uniquify |
394 // the existing entry's keyword. | 394 // the existing entry's keyword. |
395 data.short_name = ASCIIToUTF16("fourth"); | 395 data.SetShortName(ASCIIToUTF16("fourth")); |
396 data.SetURL("http://test4"); | 396 data.SetURL("http://test4"); |
397 data.safe_for_autoreplace = false; | 397 data.safe_for_autoreplace = false; |
398 TemplateURL* t_url2 = new TemplateURL(data); | 398 TemplateURL* t_url2 = new TemplateURL(data); |
399 model()->Add(t_url2); | 399 model()->Add(t_url2); |
400 VerifyObserverCount(1); | 400 VerifyObserverCount(1); |
401 EXPECT_EQ(t_url2, model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword"))); | 401 EXPECT_EQ(t_url2, model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword"))); |
402 EXPECT_EQ(ASCIIToUTF16("fourth"), t_url2->short_name()); | 402 EXPECT_EQ(ASCIIToUTF16("fourth"), t_url2->short_name()); |
403 EXPECT_EQ(ASCIIToUTF16("keyword"), t_url2->keyword()); | 403 EXPECT_EQ(ASCIIToUTF16("keyword"), t_url2->keyword()); |
404 EXPECT_EQ(ASCIIToUTF16("second"), t_url->short_name()); | 404 EXPECT_EQ(ASCIIToUTF16("second"), t_url->short_name()); |
405 EXPECT_EQ(ASCIIToUTF16("test2"), t_url->keyword()); | 405 EXPECT_EQ(ASCIIToUTF16("test2"), t_url->keyword()); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
457 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword")); | 457 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword")); |
458 ASSERT_TRUE(extension); | 458 ASSERT_TRUE(extension); |
459 // Adding a keyword that matches the extension. | 459 // Adding a keyword that matches the extension. |
460 AddKeywordWithDate( | 460 AddKeywordWithDate( |
461 "replaceable", "keyword", "http://test1", std::string(), std::string(), | 461 "replaceable", "keyword", "http://test1", std::string(), std::string(), |
462 std::string(), true, "UTF-8", Time(), Time()); | 462 std::string(), true, "UTF-8", Time(), Time()); |
463 | 463 |
464 // Adding another replaceable keyword should remove the existing one, but | 464 // Adding another replaceable keyword should remove the existing one, but |
465 // leave the extension as is. | 465 // leave the extension as is. |
466 TemplateURLData data; | 466 TemplateURLData data; |
467 data.short_name = ASCIIToUTF16("name1"); | 467 data.SetShortName(ASCIIToUTF16("name1")); |
468 data.SetKeyword(ASCIIToUTF16("keyword")); | 468 data.SetKeyword(ASCIIToUTF16("keyword")); |
469 data.SetURL("http://test3"); | 469 data.SetURL("http://test3"); |
470 data.safe_for_autoreplace = true; | 470 data.safe_for_autoreplace = true; |
471 TemplateURL* t_url = new TemplateURL(data); | 471 TemplateURL* t_url = new TemplateURL(data); |
472 model()->Add(t_url); | 472 model()->Add(t_url); |
473 EXPECT_EQ(extension, | 473 EXPECT_EQ(extension, |
474 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword"))); | 474 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword"))); |
475 EXPECT_EQ(t_url, model()->GetTemplateURLForHost("test3")); | 475 EXPECT_EQ(t_url, model()->GetTemplateURLForHost("test3")); |
476 | 476 |
477 // Adding a nonreplaceable keyword should remove the existing replaceable | 477 // Adding a nonreplaceable keyword should remove the existing replaceable |
478 // keyword and replace the extension as the associated URL for this keyword, | 478 // keyword and replace the extension as the associated URL for this keyword, |
479 // but not evict the extension from the service entirely. | 479 // but not evict the extension from the service entirely. |
480 data.short_name = ASCIIToUTF16("name2"); | 480 data.SetShortName(ASCIIToUTF16("name2")); |
481 data.SetURL("http://test4"); | 481 data.SetURL("http://test4"); |
482 data.safe_for_autoreplace = false; | 482 data.safe_for_autoreplace = false; |
483 TemplateURL* t_url2 = new TemplateURL(data); | 483 TemplateURL* t_url2 = new TemplateURL(data); |
484 model()->Add(t_url2); | 484 model()->Add(t_url2); |
485 EXPECT_EQ(t_url2, | 485 EXPECT_EQ(t_url2, |
486 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword"))); | 486 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword"))); |
487 } | 487 } |
488 | 488 |
489 TEST_F(TemplateURLServiceTest, NotPersistOmniboxExtensionKeyword) { | 489 TEST_F(TemplateURLServiceTest, NotPersistOmniboxExtensionKeyword) { |
490 test_util()->VerifyLoad(); | 490 test_util()->VerifyLoad(); |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
613 EXPECT_EQ(1U, model()->GetTemplateURLs().size()); | 613 EXPECT_EQ(1U, model()->GetTemplateURLs().size()); |
614 EXPECT_EQ(ASCIIToUTF16("key1"), model()->GetTemplateURLs()[0]->keyword()); | 614 EXPECT_EQ(ASCIIToUTF16("key1"), model()->GetTemplateURLs()[0]->keyword()); |
615 EXPECT_TRUE(model()->GetTemplateURLs()[0]->safe_for_autoreplace()); | 615 EXPECT_TRUE(model()->GetTemplateURLs()[0]->safe_for_autoreplace()); |
616 } | 616 } |
617 | 617 |
618 TEST_F(TemplateURLServiceTest, Reset) { | 618 TEST_F(TemplateURLServiceTest, Reset) { |
619 // Add a new TemplateURL. | 619 // Add a new TemplateURL. |
620 test_util()->VerifyLoad(); | 620 test_util()->VerifyLoad(); |
621 const size_t initial_count = model()->GetTemplateURLs().size(); | 621 const size_t initial_count = model()->GetTemplateURLs().size(); |
622 TemplateURLData data; | 622 TemplateURLData data; |
623 data.short_name = ASCIIToUTF16("google"); | 623 data.SetShortName(ASCIIToUTF16("google")); |
624 data.SetKeyword(ASCIIToUTF16("keyword")); | 624 data.SetKeyword(ASCIIToUTF16("keyword")); |
625 data.SetURL("http://www.google.com/foo/bar"); | 625 data.SetURL("http://www.google.com/foo/bar"); |
626 data.favicon_url = GURL("http://favicon.url"); | 626 data.favicon_url = GURL("http://favicon.url"); |
627 data.date_created = Time::FromTimeT(100); | 627 data.date_created = Time::FromTimeT(100); |
628 data.last_modified = Time::FromTimeT(100); | 628 data.last_modified = Time::FromTimeT(100); |
629 TemplateURL* t_url = new TemplateURL(data); | 629 TemplateURL* t_url = new TemplateURL(data); |
630 model()->Add(t_url); | 630 model()->Add(t_url); |
631 | 631 |
632 VerifyObserverCount(1); | 632 VerifyObserverCount(1); |
633 base::RunLoop().RunUntilIdle(); | 633 base::RunLoop().RunUntilIdle(); |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
737 // Now force the model to load and make sure we still have a default. | 737 // Now force the model to load and make sure we still have a default. |
738 test_util()->VerifyLoad(); | 738 test_util()->VerifyLoad(); |
739 | 739 |
740 ASSERT_TRUE(model()->GetDefaultSearchProvider()); | 740 ASSERT_TRUE(model()->GetDefaultSearchProvider()); |
741 } | 741 } |
742 | 742 |
743 TEST_F(TemplateURLServiceTest, DefaultSearchProviderLoadedFromPrefs) { | 743 TEST_F(TemplateURLServiceTest, DefaultSearchProviderLoadedFromPrefs) { |
744 test_util()->VerifyLoad(); | 744 test_util()->VerifyLoad(); |
745 | 745 |
746 TemplateURLData data; | 746 TemplateURLData data; |
747 data.short_name = ASCIIToUTF16("a"); | 747 data.SetShortName(ASCIIToUTF16("a")); |
748 data.safe_for_autoreplace = true; | 748 data.safe_for_autoreplace = true; |
749 data.SetURL("http://url/{searchTerms}"); | 749 data.SetURL("http://url/{searchTerms}"); |
750 data.suggestions_url = "http://url2"; | 750 data.suggestions_url = "http://url2"; |
751 data.instant_url = "http://instant"; | 751 data.instant_url = "http://instant"; |
752 data.date_created = Time::FromTimeT(100); | 752 data.date_created = Time::FromTimeT(100); |
753 data.last_modified = Time::FromTimeT(100); | 753 data.last_modified = Time::FromTimeT(100); |
754 TemplateURL* t_url = new TemplateURL(data); | 754 TemplateURL* t_url = new TemplateURL(data); |
755 model()->Add(t_url); | 755 model()->Add(t_url); |
756 const TemplateURLID id = t_url->id(); | 756 const TemplateURLID id = t_url->id(); |
757 | 757 |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
841 const char kAlternateURL[] = "http://test.com/search#t={searchTerms}"; | 841 const char kAlternateURL[] = "http://test.com/search#t={searchTerms}"; |
842 const char kSearchTermsReplacementKey[] = "espv"; | 842 const char kSearchTermsReplacementKey[] = "espv"; |
843 test_util()->SetManagedDefaultSearchPreferences(true, kName, kKeyword, | 843 test_util()->SetManagedDefaultSearchPreferences(true, kName, kKeyword, |
844 kSearchURL, std::string(), | 844 kSearchURL, std::string(), |
845 kIconURL, kEncodings, | 845 kIconURL, kEncodings, |
846 kAlternateURL, | 846 kAlternateURL, |
847 kSearchTermsReplacementKey); | 847 kSearchTermsReplacementKey); |
848 test_util()->VerifyLoad(); | 848 test_util()->VerifyLoad(); |
849 // Verify that the default manager we are getting is the managed one. | 849 // Verify that the default manager we are getting is the managed one. |
850 TemplateURLData data; | 850 TemplateURLData data; |
851 data.short_name = ASCIIToUTF16(kName); | 851 data.SetShortName(ASCIIToUTF16(kName)); |
852 data.SetKeyword(ASCIIToUTF16(kKeyword)); | 852 data.SetKeyword(ASCIIToUTF16(kKeyword)); |
853 data.SetURL(kSearchURL); | 853 data.SetURL(kSearchURL); |
854 data.favicon_url = GURL(kIconURL); | 854 data.favicon_url = GURL(kIconURL); |
855 data.show_in_default_list = true; | 855 data.show_in_default_list = true; |
856 base::SplitString(kEncodings, ';', &data.input_encodings); | 856 base::SplitString(kEncodings, ';', &data.input_encodings); |
857 data.alternate_urls.push_back(kAlternateURL); | 857 data.alternate_urls.push_back(kAlternateURL); |
858 data.search_terms_replacement_key = kSearchTermsReplacementKey; | 858 data.search_terms_replacement_key = kSearchTermsReplacementKey; |
859 scoped_ptr<TemplateURL> expected_managed_default(new TemplateURL(data)); | 859 scoped_ptr<TemplateURL> expected_managed_default(new TemplateURL(data)); |
860 EXPECT_TRUE(model()->is_default_search_managed()); | 860 EXPECT_TRUE(model()->is_default_search_managed()); |
861 const TemplateURL* actual_managed_default = | 861 const TemplateURL* actual_managed_default = |
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1220 const char kSearchTermsReplacementKey[] = "espv"; | 1220 const char kSearchTermsReplacementKey[] = "espv"; |
1221 test_util()->SetManagedDefaultSearchPreferences(true, kName, kKeyword, | 1221 test_util()->SetManagedDefaultSearchPreferences(true, kName, kKeyword, |
1222 kSearchURL, std::string(), kIconURL, kEncodings, kAlternateURL, | 1222 kSearchURL, std::string(), kIconURL, kEncodings, kAlternateURL, |
1223 kSearchTermsReplacementKey); | 1223 kSearchTermsReplacementKey); |
1224 VerifyObserverFired(); | 1224 VerifyObserverFired(); |
1225 EXPECT_TRUE(model()->is_default_search_managed()); | 1225 EXPECT_TRUE(model()->is_default_search_managed()); |
1226 EXPECT_EQ(initial_count + 2, model()->GetTemplateURLs().size()); | 1226 EXPECT_EQ(initial_count + 2, model()->GetTemplateURLs().size()); |
1227 | 1227 |
1228 // Verify that the default manager we are getting is the managed one. | 1228 // Verify that the default manager we are getting is the managed one. |
1229 TemplateURLData data; | 1229 TemplateURLData data; |
1230 data.short_name = ASCIIToUTF16(kName); | 1230 data.SetShortName(ASCIIToUTF16(kName)); |
1231 data.SetKeyword(ASCIIToUTF16(kKeyword)); | 1231 data.SetKeyword(ASCIIToUTF16(kKeyword)); |
1232 data.SetURL(kSearchURL); | 1232 data.SetURL(kSearchURL); |
1233 data.favicon_url = GURL(kIconURL); | 1233 data.favicon_url = GURL(kIconURL); |
1234 data.show_in_default_list = true; | 1234 data.show_in_default_list = true; |
1235 base::SplitString(kEncodings, ';', &data.input_encodings); | 1235 base::SplitString(kEncodings, ';', &data.input_encodings); |
1236 data.alternate_urls.push_back(kAlternateURL); | 1236 data.alternate_urls.push_back(kAlternateURL); |
1237 data.search_terms_replacement_key = kSearchTermsReplacementKey; | 1237 data.search_terms_replacement_key = kSearchTermsReplacementKey; |
1238 scoped_ptr<TemplateURL> expected_managed_default1(new TemplateURL(data)); | 1238 scoped_ptr<TemplateURL> expected_managed_default1(new TemplateURL(data)); |
1239 const TemplateURL* actual_managed_default = | 1239 const TemplateURL* actual_managed_default = |
1240 model()->GetDefaultSearchProvider(); | 1240 model()->GetDefaultSearchProvider(); |
1241 ExpectSimilar(expected_managed_default1.get(), actual_managed_default); | 1241 ExpectSimilar(expected_managed_default1.get(), actual_managed_default); |
1242 EXPECT_TRUE(actual_managed_default->show_in_default_list()); | 1242 EXPECT_TRUE(actual_managed_default->show_in_default_list()); |
1243 | 1243 |
1244 // Update the managed preference and check that the model has changed. | 1244 // Update the managed preference and check that the model has changed. |
1245 const char kNewName[] = "test2"; | 1245 const char kNewName[] = "test2"; |
1246 const char kNewKeyword[] = "other.com"; | 1246 const char kNewKeyword[] = "other.com"; |
1247 const char kNewSearchURL[] = "http://other.com/search?t={searchTerms}"; | 1247 const char kNewSearchURL[] = "http://other.com/search?t={searchTerms}"; |
1248 const char kNewSuggestURL[] = "http://other.com/suggest?t={searchTerms}"; | 1248 const char kNewSuggestURL[] = "http://other.com/suggest?t={searchTerms}"; |
1249 test_util()->SetManagedDefaultSearchPreferences(true, kNewName, kNewKeyword, | 1249 test_util()->SetManagedDefaultSearchPreferences(true, kNewName, kNewKeyword, |
1250 kNewSearchURL, kNewSuggestURL, std::string(), std::string(), | 1250 kNewSearchURL, kNewSuggestURL, std::string(), std::string(), |
1251 std::string(), std::string()); | 1251 std::string(), std::string()); |
1252 VerifyObserverFired(); | 1252 VerifyObserverFired(); |
1253 EXPECT_TRUE(model()->is_default_search_managed()); | 1253 EXPECT_TRUE(model()->is_default_search_managed()); |
1254 EXPECT_EQ(initial_count + 2, model()->GetTemplateURLs().size()); | 1254 EXPECT_EQ(initial_count + 2, model()->GetTemplateURLs().size()); |
1255 | 1255 |
1256 // Verify that the default manager we are now getting is the correct one. | 1256 // Verify that the default manager we are now getting is the correct one. |
1257 TemplateURLData data2; | 1257 TemplateURLData data2; |
1258 data2.short_name = ASCIIToUTF16(kNewName); | 1258 data2.SetShortName(ASCIIToUTF16(kNewName)); |
1259 data2.SetKeyword(ASCIIToUTF16(kNewKeyword)); | 1259 data2.SetKeyword(ASCIIToUTF16(kNewKeyword)); |
1260 data2.SetURL(kNewSearchURL); | 1260 data2.SetURL(kNewSearchURL); |
1261 data2.suggestions_url = kNewSuggestURL; | 1261 data2.suggestions_url = kNewSuggestURL; |
1262 data2.show_in_default_list = true; | 1262 data2.show_in_default_list = true; |
1263 scoped_ptr<TemplateURL> expected_managed_default2(new TemplateURL(data2)); | 1263 scoped_ptr<TemplateURL> expected_managed_default2(new TemplateURL(data2)); |
1264 actual_managed_default = model()->GetDefaultSearchProvider(); | 1264 actual_managed_default = model()->GetDefaultSearchProvider(); |
1265 ExpectSimilar(expected_managed_default2.get(), actual_managed_default); | 1265 ExpectSimilar(expected_managed_default2.get(), actual_managed_default); |
1266 EXPECT_EQ(actual_managed_default->show_in_default_list(), true); | 1266 EXPECT_EQ(actual_managed_default->show_in_default_list(), true); |
1267 | 1267 |
1268 // Remove all the managed prefs and check that we are no longer managed. | 1268 // Remove all the managed prefs and check that we are no longer managed. |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1323 } | 1323 } |
1324 | 1324 |
1325 // Test that if we load a TemplateURL with an empty GUID, the load process | 1325 // Test that if we load a TemplateURL with an empty GUID, the load process |
1326 // assigns it a newly generated GUID. | 1326 // assigns it a newly generated GUID. |
1327 TEST_F(TemplateURLServiceTest, PatchEmptySyncGUID) { | 1327 TEST_F(TemplateURLServiceTest, PatchEmptySyncGUID) { |
1328 // Add a new TemplateURL. | 1328 // Add a new TemplateURL. |
1329 test_util()->VerifyLoad(); | 1329 test_util()->VerifyLoad(); |
1330 const size_t initial_count = model()->GetTemplateURLs().size(); | 1330 const size_t initial_count = model()->GetTemplateURLs().size(); |
1331 | 1331 |
1332 TemplateURLData data; | 1332 TemplateURLData data; |
1333 data.short_name = ASCIIToUTF16("google"); | 1333 data.SetShortName(ASCIIToUTF16("google")); |
1334 data.SetKeyword(ASCIIToUTF16("keyword")); | 1334 data.SetKeyword(ASCIIToUTF16("keyword")); |
1335 data.SetURL("http://www.google.com/foo/bar"); | 1335 data.SetURL("http://www.google.com/foo/bar"); |
1336 data.sync_guid.clear(); | 1336 data.sync_guid.clear(); |
1337 TemplateURL* t_url = new TemplateURL(data); | 1337 TemplateURL* t_url = new TemplateURL(data); |
1338 model()->Add(t_url); | 1338 model()->Add(t_url); |
1339 | 1339 |
1340 VerifyObserverCount(1); | 1340 VerifyObserverCount(1); |
1341 base::RunLoop().RunUntilIdle(); | 1341 base::RunLoop().RunUntilIdle(); |
1342 ASSERT_EQ(initial_count + 1, model()->GetTemplateURLs().size()); | 1342 ASSERT_EQ(initial_count + 1, model()->GetTemplateURLs().size()); |
1343 | 1343 |
1344 // Reload the model to verify it was actually saved to the database and | 1344 // Reload the model to verify it was actually saved to the database and |
1345 // assigned a new GUID when brought back. | 1345 // assigned a new GUID when brought back. |
1346 test_util()->ResetModel(true); | 1346 test_util()->ResetModel(true); |
1347 ASSERT_EQ(initial_count + 1, model()->GetTemplateURLs().size()); | 1347 ASSERT_EQ(initial_count + 1, model()->GetTemplateURLs().size()); |
1348 const TemplateURL* loaded_url = | 1348 const TemplateURL* loaded_url = |
1349 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword")); | 1349 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword")); |
1350 ASSERT_FALSE(loaded_url == NULL); | 1350 ASSERT_FALSE(loaded_url == NULL); |
1351 ASSERT_FALSE(loaded_url->sync_guid().empty()); | 1351 ASSERT_FALSE(loaded_url->sync_guid().empty()); |
1352 } | 1352 } |
1353 | 1353 |
1354 // Test that if we load a TemplateURL with duplicate input encodings, the load | 1354 // Test that if we load a TemplateURL with duplicate input encodings, the load |
1355 // process de-dupes them. | 1355 // process de-dupes them. |
1356 TEST_F(TemplateURLServiceTest, DuplicateInputEncodings) { | 1356 TEST_F(TemplateURLServiceTest, DuplicateInputEncodings) { |
1357 // Add a new TemplateURL. | 1357 // Add a new TemplateURL. |
1358 test_util()->VerifyLoad(); | 1358 test_util()->VerifyLoad(); |
1359 const size_t initial_count = model()->GetTemplateURLs().size(); | 1359 const size_t initial_count = model()->GetTemplateURLs().size(); |
1360 | 1360 |
1361 TemplateURLData data; | 1361 TemplateURLData data; |
1362 data.short_name = ASCIIToUTF16("google"); | 1362 data.SetShortName(ASCIIToUTF16("google")); |
1363 data.SetKeyword(ASCIIToUTF16("keyword")); | 1363 data.SetKeyword(ASCIIToUTF16("keyword")); |
1364 data.SetURL("http://www.google.com/foo/bar"); | 1364 data.SetURL("http://www.google.com/foo/bar"); |
1365 std::vector<std::string> encodings; | 1365 std::vector<std::string> encodings; |
1366 data.input_encodings.push_back("UTF-8"); | 1366 data.input_encodings.push_back("UTF-8"); |
1367 data.input_encodings.push_back("UTF-8"); | 1367 data.input_encodings.push_back("UTF-8"); |
1368 data.input_encodings.push_back("UTF-16"); | 1368 data.input_encodings.push_back("UTF-16"); |
1369 data.input_encodings.push_back("UTF-8"); | 1369 data.input_encodings.push_back("UTF-8"); |
1370 data.input_encodings.push_back("Big5"); | 1370 data.input_encodings.push_back("Big5"); |
1371 data.input_encodings.push_back("UTF-16"); | 1371 data.input_encodings.push_back("UTF-16"); |
1372 data.input_encodings.push_back("Big5"); | 1372 data.input_encodings.push_back("Big5"); |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1463 const char kIconURL[] = "http://test.com/icon.jpg"; | 1463 const char kIconURL[] = "http://test.com/icon.jpg"; |
1464 const char kEncodings[] = "UTF-16;UTF-32"; | 1464 const char kEncodings[] = "UTF-16;UTF-32"; |
1465 const char kAlternateURL[] = "http://test.com/search#t={searchTerms}"; | 1465 const char kAlternateURL[] = "http://test.com/search#t={searchTerms}"; |
1466 const char kSearchTermsReplacementKey[] = "espv"; | 1466 const char kSearchTermsReplacementKey[] = "espv"; |
1467 test_util()->SetManagedDefaultSearchPreferences( | 1467 test_util()->SetManagedDefaultSearchPreferences( |
1468 true, kName, kKeyword, kSearchURL, std::string(), kIconURL, kEncodings, | 1468 true, kName, kKeyword, kSearchURL, std::string(), kIconURL, kEncodings, |
1469 kAlternateURL, kSearchTermsReplacementKey); | 1469 kAlternateURL, kSearchTermsReplacementKey); |
1470 test_util()->VerifyLoad(); | 1470 test_util()->VerifyLoad(); |
1471 // Verify that the default manager we are getting is the managed one. | 1471 // Verify that the default manager we are getting is the managed one. |
1472 TemplateURLData data; | 1472 TemplateURLData data; |
1473 data.short_name = ASCIIToUTF16(kName); | 1473 data.SetShortName(ASCIIToUTF16(kName)); |
1474 data.SetKeyword(ASCIIToUTF16(kKeyword)); | 1474 data.SetKeyword(ASCIIToUTF16(kKeyword)); |
1475 data.SetURL(kSearchURL); | 1475 data.SetURL(kSearchURL); |
1476 data.favicon_url = GURL(kIconURL); | 1476 data.favicon_url = GURL(kIconURL); |
1477 data.show_in_default_list = true; | 1477 data.show_in_default_list = true; |
1478 base::SplitString(kEncodings, ';', &data.input_encodings); | 1478 base::SplitString(kEncodings, ';', &data.input_encodings); |
1479 data.alternate_urls.push_back(kAlternateURL); | 1479 data.alternate_urls.push_back(kAlternateURL); |
1480 data.search_terms_replacement_key = kSearchTermsReplacementKey; | 1480 data.search_terms_replacement_key = kSearchTermsReplacementKey; |
1481 scoped_ptr<TemplateURL> expected_managed_default(new TemplateURL(data)); | 1481 scoped_ptr<TemplateURL> expected_managed_default(new TemplateURL(data)); |
1482 EXPECT_TRUE(model()->is_default_search_managed()); | 1482 EXPECT_TRUE(model()->is_default_search_managed()); |
1483 const TemplateURL* actual_managed_default = | 1483 const TemplateURL* actual_managed_default = |
1484 model()->GetDefaultSearchProvider(); | 1484 model()->GetDefaultSearchProvider(); |
1485 ExpectSimilar(expected_managed_default.get(), actual_managed_default); | 1485 ExpectSimilar(expected_managed_default.get(), actual_managed_default); |
1486 | 1486 |
1487 TemplateURL* ext_dse = CreateKeywordWithDate( | 1487 TemplateURL* ext_dse = CreateKeywordWithDate( |
1488 model(), "ext1", "ext1", "http://www.ext1.com/s?q={searchTerms}", | 1488 model(), "ext1", "ext1", "http://www.ext1.com/s?q={searchTerms}", |
1489 std::string(), std::string(), std::string(), | 1489 std::string(), std::string(), std::string(), |
1490 true, true, "UTF-8", Time(), Time()); | 1490 true, true, "UTF-8", Time(), Time()); |
1491 scoped_ptr<TemplateURL::AssociatedExtensionInfo> extension_info( | 1491 scoped_ptr<TemplateURL::AssociatedExtensionInfo> extension_info( |
1492 new TemplateURL::AssociatedExtensionInfo( | 1492 new TemplateURL::AssociatedExtensionInfo( |
1493 TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION, "ext1")); | 1493 TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION, "ext1")); |
1494 extension_info->wants_to_be_default_engine = true; | 1494 extension_info->wants_to_be_default_engine = true; |
1495 model()->AddExtensionControlledTURL(ext_dse, extension_info.Pass()); | 1495 model()->AddExtensionControlledTURL(ext_dse, extension_info.Pass()); |
1496 EXPECT_EQ(ext_dse, model()->GetTemplateURLForKeyword(ASCIIToUTF16("ext1"))); | 1496 EXPECT_EQ(ext_dse, model()->GetTemplateURLForKeyword(ASCIIToUTF16("ext1"))); |
1497 EXPECT_TRUE(model()->is_default_search_managed()); | 1497 EXPECT_TRUE(model()->is_default_search_managed()); |
1498 actual_managed_default = model()->GetDefaultSearchProvider(); | 1498 actual_managed_default = model()->GetDefaultSearchProvider(); |
1499 ExpectSimilar(expected_managed_default.get(), actual_managed_default); | 1499 ExpectSimilar(expected_managed_default.get(), actual_managed_default); |
1500 } | 1500 } |
OLD | NEW |