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 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
169 const std::string& url, | 169 const std::string& url, |
170 const std::string& suggest_url, | 170 const std::string& suggest_url, |
171 const std::string& alternate_url, | 171 const std::string& alternate_url, |
172 const std::string& favicon_url, | 172 const std::string& favicon_url, |
173 bool safe_for_autoreplace, | 173 bool safe_for_autoreplace, |
174 const std::string& encodings, | 174 const std::string& encodings, |
175 Time date_created, | 175 Time date_created, |
176 Time last_modified, | 176 Time last_modified, |
177 Time last_visited); | 177 Time last_visited); |
178 | 178 |
179 // Add extension controlled search engine with |keyword| to model. | |
180 TemplateURL* AddExtensionSearchEngine(const std::string& keyword, | |
181 const std::string& extension_name, | |
182 bool wants_to_be_default_engine, | |
183 const base::Time& install_time); | |
184 | |
179 // Verifies the two TemplateURLs are equal. | 185 // Verifies the two TemplateURLs are equal. |
180 void AssertEquals(const TemplateURL& expected, const TemplateURL& actual); | 186 void AssertEquals(const TemplateURL& expected, const TemplateURL& actual); |
181 | 187 |
182 // Verifies the two timestamps are equal, within the expected degree of | 188 // Verifies the two timestamps are equal, within the expected degree of |
183 // precision. | 189 // precision. |
184 void AssertTimesEqual(const base::Time& expected, const base::Time& actual); | 190 void AssertTimesEqual(const base::Time& expected, const base::Time& actual); |
185 | 191 |
186 // Create an URL that appears to have been prepopulated, but won't be in the | 192 // Create an URL that appears to have been prepopulated, but won't be in the |
187 // current data. | 193 // current data. |
188 std::unique_ptr<TemplateURL> CreatePreloadedTemplateURL( | 194 std::unique_ptr<TemplateURL> CreatePreloadedTemplateURL( |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
246 const std::string& encodings, | 252 const std::string& encodings, |
247 Time date_created, | 253 Time date_created, |
248 Time last_modified, | 254 Time last_modified, |
249 Time last_visited) { | 255 Time last_visited) { |
250 return ::AddKeywordWithDate(model(), short_name, keyword, url, suggest_url, | 256 return ::AddKeywordWithDate(model(), short_name, keyword, url, suggest_url, |
251 alternate_url, favicon_url, safe_for_autoreplace, | 257 alternate_url, favicon_url, safe_for_autoreplace, |
252 encodings, date_created, last_modified, | 258 encodings, date_created, last_modified, |
253 last_visited); | 259 last_visited); |
254 } | 260 } |
255 | 261 |
262 TemplateURL* TemplateURLServiceTest::AddExtensionSearchEngine( | |
263 const std::string& keyword, | |
264 const std::string& extension_name, | |
265 bool wants_to_be_default_engine, | |
266 const base::Time& install_time) { | |
267 std::unique_ptr<TemplateURLData> turl_data = | |
268 GenerateDummyTemplateURLData(keyword); | |
269 turl_data->safe_for_autoreplace = false; | |
270 | |
271 auto ext_dse = base::MakeUnique<TemplateURL>( | |
272 *turl_data, TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION); | |
273 auto extension_info = | |
274 base::MakeUnique<TemplateURL::AssociatedExtensionInfo>(extension_name); | |
275 extension_info->wants_to_be_default_engine = wants_to_be_default_engine; | |
276 extension_info->install_time = install_time; | |
277 | |
278 return model()->AddExtensionControlledTURL(std::move(ext_dse), | |
279 std::move(extension_info)); | |
280 } | |
281 | |
256 void TemplateURLServiceTest::AssertEquals(const TemplateURL& expected, | 282 void TemplateURLServiceTest::AssertEquals(const TemplateURL& expected, |
257 const TemplateURL& actual) { | 283 const TemplateURL& actual) { |
258 ASSERT_EQ(expected.short_name(), actual.short_name()); | 284 ASSERT_EQ(expected.short_name(), actual.short_name()); |
259 ASSERT_EQ(expected.keyword(), actual.keyword()); | 285 ASSERT_EQ(expected.keyword(), actual.keyword()); |
260 ASSERT_EQ(expected.url(), actual.url()); | 286 ASSERT_EQ(expected.url(), actual.url()); |
261 ASSERT_EQ(expected.suggestions_url(), actual.suggestions_url()); | 287 ASSERT_EQ(expected.suggestions_url(), actual.suggestions_url()); |
262 ASSERT_EQ(expected.favicon_url(), actual.favicon_url()); | 288 ASSERT_EQ(expected.favicon_url(), actual.favicon_url()); |
263 ASSERT_EQ(expected.alternate_urls(), actual.alternate_urls()); | 289 ASSERT_EQ(expected.alternate_urls(), actual.alternate_urls()); |
264 ASSERT_EQ(expected.prepopulate_id(), actual.prepopulate_id()); | 290 ASSERT_EQ(expected.prepopulate_id(), actual.prepopulate_id()); |
265 ASSERT_EQ(expected.safe_for_autoreplace(), actual.safe_for_autoreplace()); | 291 ASSERT_EQ(expected.safe_for_autoreplace(), actual.safe_for_autoreplace()); |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
463 EXPECT_EQ(ASCIIToUTF16("second"), t_url->short_name()); | 489 EXPECT_EQ(ASCIIToUTF16("second"), t_url->short_name()); |
464 EXPECT_EQ(ASCIIToUTF16("test2"), t_url->keyword()); | 490 EXPECT_EQ(ASCIIToUTF16("test2"), t_url->keyword()); |
465 } | 491 } |
466 | 492 |
467 TEST_F(TemplateURLServiceTest, AddExtensionKeyword) { | 493 TEST_F(TemplateURLServiceTest, AddExtensionKeyword) { |
468 test_util()->VerifyLoad(); | 494 test_util()->VerifyLoad(); |
469 | 495 |
470 AddKeywordWithDate("replaceable", "keyword1", "http://test1", std::string(), | 496 AddKeywordWithDate("replaceable", "keyword1", "http://test1", std::string(), |
471 std::string(), std::string(), true, "UTF-8", Time(), | 497 std::string(), std::string(), true, "UTF-8", Time(), |
472 Time(), Time()); | 498 Time(), Time()); |
473 TemplateURL* original2 = AddKeywordWithDate( | 499 AddKeywordWithDate("nonreplaceable", "keyword2", "http://test2", |
474 "nonreplaceable", "keyword2", "http://test2", std::string(), | 500 std::string(), std::string(), std::string(), false, |
475 std::string(), std::string(), false, "UTF-8", Time(), Time(), Time()); | 501 "UTF-8", Time(), Time(), Time()); |
476 model()->RegisterOmniboxKeyword("test3", "extension", "keyword3", | 502 model()->RegisterOmniboxKeyword("test3", "extension", "keyword3", |
477 "http://test3"); | 503 "http://test3", base::Time::FromDoubleT(1)); |
478 TemplateURL* original3 = | 504 TemplateURL* original3 = |
479 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword3")); | 505 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword3")); |
480 ASSERT_TRUE(original3); | 506 ASSERT_TRUE(original3); |
481 | 507 |
482 // Extension keywords should override replaceable keywords. | 508 // Extension keywords should override replaceable keywords. |
483 model()->RegisterOmniboxKeyword("id1", "test", "keyword1", "http://test4"); | 509 model()->RegisterOmniboxKeyword("id1", "test", "keyword1", "http://test4", |
510 base::Time::FromDoubleT(2)); | |
484 TemplateURL* extension1 = model()->FindTemplateURLForExtension( | 511 TemplateURL* extension1 = model()->FindTemplateURLForExtension( |
485 "id1", TemplateURL::OMNIBOX_API_EXTENSION); | 512 "id1", TemplateURL::OMNIBOX_API_EXTENSION); |
486 EXPECT_TRUE(extension1); | 513 EXPECT_TRUE(extension1); |
487 EXPECT_EQ(extension1, | 514 EXPECT_EQ(extension1, |
488 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword1"))); | 515 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword1"))); |
489 | 516 |
490 // They should not override non-replaceable keywords. | 517 // They should also override non-replaceable keywords. |
491 model()->RegisterOmniboxKeyword("id2", "test", "keyword2", "http://test5"); | 518 model()->RegisterOmniboxKeyword("id2", "test", "keyword2", "http://test5", |
519 base::Time::FromDoubleT(3)); | |
492 TemplateURL* extension2 = model()->FindTemplateURLForExtension( | 520 TemplateURL* extension2 = model()->FindTemplateURLForExtension( |
493 "id2", TemplateURL::OMNIBOX_API_EXTENSION); | 521 "id2", TemplateURL::OMNIBOX_API_EXTENSION); |
494 ASSERT_TRUE(extension2); | 522 ASSERT_TRUE(extension2); |
495 EXPECT_EQ(original2, | 523 EXPECT_EQ(extension2, |
496 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword2"))); | 524 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword2"))); |
497 | 525 |
498 // They should override extension keywords added earlier. | 526 // They should override extension keywords added earlier. |
499 model()->RegisterOmniboxKeyword("id3", "test", "keyword3", "http://test6"); | 527 model()->RegisterOmniboxKeyword("id3", "test", "keyword3", "http://test6", |
528 base::Time::FromDoubleT(4)); | |
500 TemplateURL* extension3 = model()->FindTemplateURLForExtension( | 529 TemplateURL* extension3 = model()->FindTemplateURLForExtension( |
501 "id3", TemplateURL::OMNIBOX_API_EXTENSION); | 530 "id3", TemplateURL::OMNIBOX_API_EXTENSION); |
502 ASSERT_TRUE(extension3); | 531 ASSERT_TRUE(extension3); |
503 EXPECT_EQ(extension3, | 532 EXPECT_EQ(extension3, |
504 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword3"))); | 533 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword3"))); |
505 } | 534 } |
506 | 535 |
507 TEST_F(TemplateURLServiceTest, AddSameKeywordWithExtensionPresent) { | 536 TEST_F(TemplateURLServiceTest, AddSameKeywordWithExtensionPresent) { |
508 test_util()->VerifyLoad(); | 537 test_util()->VerifyLoad(); |
509 | 538 |
510 // Similar to the AddSameKeyword test, but with an extension keyword masking a | 539 // Similar to the AddSameKeyword test, but with an extension keyword masking a |
511 // replaceable TemplateURL. We should still do correct conflict resolution | 540 // replaceable TemplateURL. We should still do correct conflict resolution |
512 // between the non-template URLs. | 541 // between the non-template URLs. |
513 model()->RegisterOmniboxKeyword("test2", "extension", "keyword", | 542 model()->RegisterOmniboxKeyword("test2", "extension", "keyword", |
514 "http://test2"); | 543 "http://test2", base::Time::Now()); |
vasilii
2017/02/21 13:17:51
If we don't care about the time I'd use Time(). Sa
Alexander Yashkin
2017/02/21 14:02:21
Done.
| |
515 TemplateURL* extension = | 544 TemplateURL* extension = |
516 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword")); | 545 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword")); |
517 ASSERT_TRUE(extension); | 546 ASSERT_TRUE(extension); |
518 // Adding a keyword that matches the extension. | 547 // Adding a keyword that matches the extension. |
519 AddKeywordWithDate("replaceable", "keyword", "http://test1", std::string(), | 548 AddKeywordWithDate("replaceable", "keyword", "http://test1", std::string(), |
520 std::string(), std::string(), true, "UTF-8", Time(), | 549 std::string(), std::string(), true, "UTF-8", Time(), |
521 Time(), Time()); | 550 Time(), Time()); |
522 | 551 |
523 // Adding another replaceable keyword should remove the existing one, but | 552 // Adding another replaceable keyword should remove the existing one, but |
524 // leave the extension as is. | 553 // leave the extension as is. |
525 TemplateURLData data; | 554 TemplateURLData data; |
526 data.SetShortName(ASCIIToUTF16("name1")); | 555 data.SetShortName(ASCIIToUTF16("name1")); |
527 data.SetKeyword(ASCIIToUTF16("keyword")); | 556 data.SetKeyword(ASCIIToUTF16("keyword")); |
528 data.SetURL("http://test3"); | 557 data.SetURL("http://test3"); |
529 data.safe_for_autoreplace = true; | 558 data.safe_for_autoreplace = true; |
530 TemplateURL* t_url = model()->Add(base::MakeUnique<TemplateURL>(data)); | 559 TemplateURL* t_url = model()->Add(base::MakeUnique<TemplateURL>(data)); |
531 EXPECT_EQ(extension, | 560 EXPECT_EQ(extension, |
532 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword"))); | 561 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword"))); |
533 EXPECT_EQ(t_url, model()->GetTemplateURLForHost("test3")); | 562 EXPECT_EQ(t_url, model()->GetTemplateURLForHost("test3")); |
534 | 563 |
535 // Adding a nonreplaceable keyword should remove the existing replaceable | 564 // Adding a nonreplaceable keyword should remove the existing replaceable |
536 // keyword and replace the extension as the associated URL for this keyword, | 565 // keyword, yet extension must still be set as the associated URL for this |
537 // but not evict the extension from the service entirely. | 566 // keyword. |
538 data.SetShortName(ASCIIToUTF16("name2")); | 567 data.SetShortName(ASCIIToUTF16("name2")); |
539 data.SetURL("http://test4"); | 568 data.SetURL("http://test4"); |
540 data.safe_for_autoreplace = false; | 569 data.safe_for_autoreplace = false; |
541 TemplateURL* t_url2 = model()->Add(base::MakeUnique<TemplateURL>(data)); | 570 model()->Add(base::MakeUnique<TemplateURL>(data)); |
542 EXPECT_EQ(t_url2, | 571 EXPECT_EQ(extension, |
543 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword"))); | 572 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword"))); |
544 } | 573 } |
545 | 574 |
546 TEST_F(TemplateURLServiceTest, NotPersistOmniboxExtensionKeyword) { | 575 TEST_F(TemplateURLServiceTest, NotPersistOmniboxExtensionKeyword) { |
547 test_util()->VerifyLoad(); | 576 test_util()->VerifyLoad(); |
548 | 577 |
549 // Register an omnibox keyword. | 578 // Register an omnibox keyword. |
550 model()->RegisterOmniboxKeyword("test", "extension", "keyword", | 579 model()->RegisterOmniboxKeyword("test", "extension", "keyword", |
551 "chrome-extension://test"); | 580 "chrome-extension://test", base::Time::Now()); |
552 ASSERT_TRUE(model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword"))); | 581 ASSERT_TRUE(model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword"))); |
553 | 582 |
554 // Reload the data. | 583 // Reload the data. |
555 test_util()->ResetModel(true); | 584 test_util()->ResetModel(true); |
556 | 585 |
557 // Ensure the omnibox keyword is not persisted. | 586 // Ensure the omnibox keyword is not persisted. |
558 ASSERT_FALSE(model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword"))); | 587 ASSERT_FALSE(model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword"))); |
559 } | 588 } |
560 | 589 |
561 TEST_F(TemplateURLServiceTest, ClearBrowsingData_Keywords) { | 590 TEST_F(TemplateURLServiceTest, ClearBrowsingData_Keywords) { |
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
872 | 901 |
873 // Remove bing. | 902 // Remove bing. |
874 TemplateURL* bing = model()->GetTemplateURLForKeyword( | 903 TemplateURL* bing = model()->GetTemplateURLForKeyword( |
875 ASCIIToUTF16("bing.com")); | 904 ASCIIToUTF16("bing.com")); |
876 ASSERT_TRUE(bing); | 905 ASSERT_TRUE(bing); |
877 model()->Remove(bing); | 906 model()->Remove(bing); |
878 EXPECT_FALSE(model()->GetTemplateURLForKeyword(ASCIIToUTF16("bing.com"))); | 907 EXPECT_FALSE(model()->GetTemplateURLForKeyword(ASCIIToUTF16("bing.com"))); |
879 | 908 |
880 // Register an extension with bing keyword. | 909 // Register an extension with bing keyword. |
881 model()->RegisterOmniboxKeyword("abcdefg", "extension_name", "bing.com", | 910 model()->RegisterOmniboxKeyword("abcdefg", "extension_name", "bing.com", |
882 "http://abcdefg"); | 911 "http://abcdefg", base::Time::Now()); |
883 EXPECT_TRUE(model()->GetTemplateURLForKeyword(ASCIIToUTF16("bing.com"))); | 912 EXPECT_TRUE(model()->GetTemplateURLForKeyword(ASCIIToUTF16("bing.com"))); |
884 | 913 |
885 model()->RepairPrepopulatedSearchEngines(); | 914 model()->RepairPrepopulatedSearchEngines(); |
886 | 915 |
887 // Google is default. | 916 // Google is default. |
888 ASSERT_EQ(google, model()->GetDefaultSearchProvider()); | 917 ASSERT_EQ(google, model()->GetDefaultSearchProvider()); |
889 // The keyword wasn't reverted. | 918 // The keyword wasn't reverted. |
890 EXPECT_EQ(ASCIIToUTF16("trash"), google->short_name()); | 919 EXPECT_EQ(ASCIIToUTF16("trash"), google->short_name()); |
891 EXPECT_EQ("www.google.com", | 920 EXPECT_EQ("www.google.com", |
892 google->GenerateSearchURL(model()->search_terms_data()).host()); | 921 google->GenerateSearchURL(model()->search_terms_data()).host()); |
(...skipping 758 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1651 std::move(ext_dse), std::move(extension_info)); | 1680 std::move(ext_dse), std::move(extension_info)); |
1652 EXPECT_EQ(ext_dse_ptr, model()->GetDefaultSearchProvider()); | 1681 EXPECT_EQ(ext_dse_ptr, model()->GetDefaultSearchProvider()); |
1653 | 1682 |
1654 test_util()->ResetModel(true); | 1683 test_util()->ResetModel(true); |
1655 user_dse = model()->GetTemplateURLForKeyword(ASCIIToUTF16("user")); | 1684 user_dse = model()->GetTemplateURLForKeyword(ASCIIToUTF16("user")); |
1656 ExpectSimilar(user_dse, model()->GetDefaultSearchProvider()); | 1685 ExpectSimilar(user_dse, model()->GetDefaultSearchProvider()); |
1657 EXPECT_FALSE(model()->GetTemplateURLForKeyword(ASCIIToUTF16("ext1"))); | 1686 EXPECT_FALSE(model()->GetTemplateURLForKeyword(ASCIIToUTF16("ext1"))); |
1658 EXPECT_FALSE(model()->GetTemplateURLForKeyword(ASCIIToUTF16("ext2"))); | 1687 EXPECT_FALSE(model()->GetTemplateURLForKeyword(ASCIIToUTF16("ext2"))); |
1659 } | 1688 } |
1660 | 1689 |
1690 // Checks that correct priority is applied when resolving conflicts between the | |
1691 // omnibox extension, search engine extension and user search engines with same | |
1692 // keyword. | |
1693 TEST_F(TemplateURLServiceTest, CheckEnginesWithSameKeywords) { | |
1694 test_util()->VerifyLoad(); | |
1695 // TemplateURLData used for user engines. | |
1696 std::unique_ptr<TemplateURLData> turl_data = | |
1697 GenerateDummyTemplateURLData("common_keyword"); | |
1698 turl_data->safe_for_autoreplace = false; | |
1699 | |
1700 // Add non replaceable user engine. | |
1701 const TemplateURL* user1 = | |
1702 model()->Add(base::MakeUnique<TemplateURL>(*turl_data)); | |
1703 | |
1704 // Add default extension engine with same keyword as user engine. | |
1705 const TemplateURL* extension = AddExtensionSearchEngine( | |
1706 "common_keyword", "extension_id", true, base::Time::Now()); | |
vasilii
2017/02/21 13:17:51
Again here we want to exclude the possibility that
Alexander Yashkin
2017/02/21 14:02:21
Done.
| |
1707 | |
1708 // Add another non replaceable user engine with same keyword as extension. | |
1709 const TemplateURL* user2 = | |
1710 model()->Add(base::MakeUnique<TemplateURL>(*turl_data)); | |
1711 | |
1712 // Check extension DSE is set as default and its keyword is not changed. | |
1713 auto current_dse = model()->GetDefaultSearchProvider(); | |
1714 EXPECT_EQ(extension, current_dse); | |
1715 EXPECT_EQ(ASCIIToUTF16("common_keyword"), current_dse->keyword()); | |
1716 | |
1717 // Register omnibox keyword with same keyword as extension. | |
1718 model()->RegisterOmniboxKeyword("omnibox_api_extension_id", "extension_name", | |
1719 "common_keyword", "http://test3", | |
1720 base::Time::Now()); | |
1721 TemplateURL* omnibox_api = model()->FindTemplateURLForExtension( | |
1722 "omnibox_api_extension_id", TemplateURL::OMNIBOX_API_EXTENSION); | |
1723 | |
1724 // Expect that first non replaceable user engine keyword is changed because of | |
1725 // conflict. Second user engine will keep its keyword. | |
1726 EXPECT_NE(ASCIIToUTF16("common_keyword"), user1->keyword()); | |
1727 EXPECT_EQ(ASCIIToUTF16("common_keyword"), user2->keyword()); | |
1728 | |
1729 // Check that extensions kept their keywords. | |
1730 EXPECT_EQ(ASCIIToUTF16("common_keyword"), extension->keyword()); | |
1731 EXPECT_EQ(ASCIIToUTF16("common_keyword"), omnibox_api->keyword()); | |
1732 | |
1733 // Omnibox api is accessible by keyword as most relevant. | |
1734 EXPECT_EQ(omnibox_api, | |
1735 model()->GetTemplateURLForKeyword(ASCIIToUTF16("common_keyword"))); | |
1736 // Extension controlled search engine is still set as default and can be found | |
1737 // in TemplateURLService. | |
1738 EXPECT_EQ(extension, model()->GetDefaultSearchProvider()); | |
1739 EXPECT_EQ(extension, | |
1740 model()->FindTemplateURLForExtension( | |
1741 "extension_id", TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION)); | |
1742 | |
1743 // Test removing engines. | |
1744 // Remove omnibox api extension. | |
1745 model()->RemoveExtensionControlledTURL("omnibox_api_extension_id", | |
1746 TemplateURL::OMNIBOX_API_EXTENSION); | |
1747 // Expect that keyword is now corresponds to extension search engine. | |
1748 EXPECT_EQ(extension, | |
1749 model()->GetTemplateURLForKeyword(ASCIIToUTF16("common_keyword"))); | |
1750 // Remove extension engine. | |
1751 model()->RemoveExtensionControlledTURL( | |
1752 "extension_id", TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION); | |
1753 EXPECT_NE(extension, model()->GetDefaultSearchProvider()); | |
1754 // Now latest user engine is returned for keyword. | |
1755 EXPECT_EQ(user2, | |
1756 model()->GetTemplateURLForKeyword(ASCIIToUTF16("common_keyword"))); | |
1757 } | |
1758 | |
1759 // Check that two extensions with same engine are handled corrected. | |
1760 TEST_F(TemplateURLServiceTest, ExtensionsWithSameKeywords) { | |
1761 test_util()->VerifyLoad(); | |
1762 | |
1763 // Add non default extension engine. | |
1764 const TemplateURL* extension1 = AddExtensionSearchEngine( | |
1765 "common_keyword", "extension_id1", false, base::Time::FromDoubleT(1)); | |
1766 | |
1767 // Check that GetTemplateURLForKeyword returns last installed extension. | |
1768 EXPECT_EQ(extension1, | |
1769 model()->GetTemplateURLForKeyword(ASCIIToUTF16("common_keyword"))); | |
1770 | |
1771 // Add default extension engine with the same keyword. | |
1772 const TemplateURL* extension2 = AddExtensionSearchEngine( | |
1773 "common_keyword", "extension_id2", true, base::Time::FromDoubleT(2)); | |
1774 | |
1775 // Check that GetTemplateURLForKeyword now returns extension2 because it was | |
1776 // installed later. | |
1777 EXPECT_EQ(extension2, | |
1778 model()->GetTemplateURLForKeyword(ASCIIToUTF16("common_keyword"))); | |
1779 | |
1780 // Add another non default extension with same keyword. This action must not | |
1781 // change any keyword due to conflict. | |
1782 const TemplateURL* extension3 = AddExtensionSearchEngine( | |
1783 "common_keyword", "extension_id3", false, base::Time::FromDoubleT(3)); | |
1784 | |
1785 // Check that extension2 is set as default. | |
1786 EXPECT_EQ(extension2, model()->GetDefaultSearchProvider()); | |
1787 | |
1788 // Check that GetTemplateURLForKeyword returns last installed extension. | |
1789 EXPECT_EQ(extension3, | |
1790 model()->GetTemplateURLForKeyword(ASCIIToUTF16("common_keyword"))); | |
1791 // Check that all keywords for extensions are left unchanged. | |
1792 EXPECT_EQ(ASCIIToUTF16("common_keyword"), extension1->keyword()); | |
1793 EXPECT_EQ(ASCIIToUTF16("common_keyword"), extension2->keyword()); | |
1794 EXPECT_EQ(ASCIIToUTF16("common_keyword"), extension3->keyword()); | |
1795 } | |
1796 | |
1661 TEST_F(TemplateURLServiceTest, ExtensionEngineVsPolicy) { | 1797 TEST_F(TemplateURLServiceTest, ExtensionEngineVsPolicy) { |
1662 // Set a managed preference that establishes a default search provider. | 1798 // Set a managed preference that establishes a default search provider. |
1663 std::unique_ptr<TemplateURLData> managed = CreateTestSearchEngine(); | 1799 std::unique_ptr<TemplateURLData> managed = CreateTestSearchEngine(); |
1664 SetManagedDefaultSearchPreferences(*managed, true, test_util()->profile()); | 1800 SetManagedDefaultSearchPreferences(*managed, true, test_util()->profile()); |
1665 test_util()->VerifyLoad(); | 1801 test_util()->VerifyLoad(); |
1666 // Verify that the default manager we are getting is the managed one. | 1802 // Verify that the default manager we are getting is the managed one. |
1667 auto expected_managed_default = base::MakeUnique<TemplateURL>(*managed); | 1803 auto expected_managed_default = base::MakeUnique<TemplateURL>(*managed); |
1668 EXPECT_TRUE(model()->is_default_search_managed()); | 1804 EXPECT_TRUE(model()->is_default_search_managed()); |
1669 const TemplateURL* actual_managed_default = | 1805 const TemplateURL* actual_managed_default = |
1670 model()->GetDefaultSearchProvider(); | 1806 model()->GetDefaultSearchProvider(); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1719 TemplateURL* update_url = | 1855 TemplateURL* update_url = |
1720 model()->GetTemplateURLForKeyword(ASCIIToUTF16("engine_keyword")); | 1856 model()->GetTemplateURLForKeyword(ASCIIToUTF16("engine_keyword")); |
1721 const base::Time update_last_modified = update_url->last_modified(); | 1857 const base::Time update_last_modified = update_url->last_modified(); |
1722 model()->SetUserSelectedDefaultSearchProvider(update_url); | 1858 model()->SetUserSelectedDefaultSearchProvider(update_url); |
1723 TemplateURL* reloaded_url = | 1859 TemplateURL* reloaded_url = |
1724 model()->GetTemplateURLForKeyword(ASCIIToUTF16("engine_keyword")); | 1860 model()->GetTemplateURLForKeyword(ASCIIToUTF16("engine_keyword")); |
1725 const base::Time reloaded_last_modified = reloaded_url->last_modified(); | 1861 const base::Time reloaded_last_modified = reloaded_url->last_modified(); |
1726 EXPECT_NE(original_last_modified, reloaded_last_modified); | 1862 EXPECT_NE(original_last_modified, reloaded_last_modified); |
1727 EXPECT_EQ(update_last_modified, reloaded_last_modified); | 1863 EXPECT_EQ(update_last_modified, reloaded_last_modified); |
1728 } | 1864 } |
OLD | NEW |