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

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

Issue 2682453002: Changed keywords conflicts resolution for extensions search engines. (Closed)
Patch Set: Updated test, check removal of search engines. Created 3 years, 10 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
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 "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
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 TemplateURL* AddExtensionSearchEngine(const std::string& keyword,
vasilii 2017/02/20 15:30:08 A comment?
Alexander Yashkin 2017/02/20 19:52:47 Done.
180 const std::string& extension_name,
181 bool wants_to_be_default_engine);
182
179 // Verifies the two TemplateURLs are equal. 183 // Verifies the two TemplateURLs are equal.
180 void AssertEquals(const TemplateURL& expected, const TemplateURL& actual); 184 void AssertEquals(const TemplateURL& expected, const TemplateURL& actual);
181 185
182 // Verifies the two timestamps are equal, within the expected degree of 186 // Verifies the two timestamps are equal, within the expected degree of
183 // precision. 187 // precision.
184 void AssertTimesEqual(const base::Time& expected, const base::Time& actual); 188 void AssertTimesEqual(const base::Time& expected, const base::Time& actual);
185 189
186 // Create an URL that appears to have been prepopulated, but won't be in the 190 // Create an URL that appears to have been prepopulated, but won't be in the
187 // current data. 191 // current data.
188 std::unique_ptr<TemplateURL> CreatePreloadedTemplateURL( 192 std::unique_ptr<TemplateURL> CreatePreloadedTemplateURL(
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 const std::string& encodings, 250 const std::string& encodings,
247 Time date_created, 251 Time date_created,
248 Time last_modified, 252 Time last_modified,
249 Time last_visited) { 253 Time last_visited) {
250 return ::AddKeywordWithDate(model(), short_name, keyword, url, suggest_url, 254 return ::AddKeywordWithDate(model(), short_name, keyword, url, suggest_url,
251 alternate_url, favicon_url, safe_for_autoreplace, 255 alternate_url, favicon_url, safe_for_autoreplace,
252 encodings, date_created, last_modified, 256 encodings, date_created, last_modified,
253 last_visited); 257 last_visited);
254 } 258 }
255 259
260 TemplateURL* TemplateURLServiceTest::AddExtensionSearchEngine(
261 const std::string& keyword,
262 const std::string& extension_name,
263 bool wants_to_be_default_engine) {
264 auto turl_data = GenerateDummyTemplateURLData(keyword);
vasilii 2017/02/20 15:30:08 The explicit type improves readabilty here.
Alexander Yashkin 2017/02/20 19:52:47 Done.
265 turl_data->safe_for_autoreplace = false;
266
267 auto ext_dse = base::MakeUnique<TemplateURL>(
268 *turl_data, TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION);
269 auto extension_info =
270 base::MakeUnique<TemplateURL::AssociatedExtensionInfo>(extension_name);
271 extension_info->wants_to_be_default_engine = wants_to_be_default_engine;
272 extension_info->install_time = base::Time::Now();
273
274 return model()->AddExtensionControlledTURL(std::move(ext_dse),
275 std::move(extension_info));
276 }
277
256 void TemplateURLServiceTest::AssertEquals(const TemplateURL& expected, 278 void TemplateURLServiceTest::AssertEquals(const TemplateURL& expected,
257 const TemplateURL& actual) { 279 const TemplateURL& actual) {
258 ASSERT_EQ(expected.short_name(), actual.short_name()); 280 ASSERT_EQ(expected.short_name(), actual.short_name());
259 ASSERT_EQ(expected.keyword(), actual.keyword()); 281 ASSERT_EQ(expected.keyword(), actual.keyword());
260 ASSERT_EQ(expected.url(), actual.url()); 282 ASSERT_EQ(expected.url(), actual.url());
261 ASSERT_EQ(expected.suggestions_url(), actual.suggestions_url()); 283 ASSERT_EQ(expected.suggestions_url(), actual.suggestions_url());
262 ASSERT_EQ(expected.favicon_url(), actual.favicon_url()); 284 ASSERT_EQ(expected.favicon_url(), actual.favicon_url());
263 ASSERT_EQ(expected.alternate_urls(), actual.alternate_urls()); 285 ASSERT_EQ(expected.alternate_urls(), actual.alternate_urls());
264 ASSERT_EQ(expected.prepopulate_id(), actual.prepopulate_id()); 286 ASSERT_EQ(expected.prepopulate_id(), actual.prepopulate_id());
265 ASSERT_EQ(expected.safe_for_autoreplace(), actual.safe_for_autoreplace()); 287 ASSERT_EQ(expected.safe_for_autoreplace(), actual.safe_for_autoreplace());
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
457 data.safe_for_autoreplace = false; 479 data.safe_for_autoreplace = false;
458 TemplateURL* t_url2 = model()->Add(base::MakeUnique<TemplateURL>(data)); 480 TemplateURL* t_url2 = model()->Add(base::MakeUnique<TemplateURL>(data));
459 VerifyObserverCount(1); 481 VerifyObserverCount(1);
460 EXPECT_EQ(t_url2, model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword"))); 482 EXPECT_EQ(t_url2, model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword")));
461 EXPECT_EQ(ASCIIToUTF16("fourth"), t_url2->short_name()); 483 EXPECT_EQ(ASCIIToUTF16("fourth"), t_url2->short_name());
462 EXPECT_EQ(ASCIIToUTF16("keyword"), t_url2->keyword()); 484 EXPECT_EQ(ASCIIToUTF16("keyword"), t_url2->keyword());
463 EXPECT_EQ(ASCIIToUTF16("second"), t_url->short_name()); 485 EXPECT_EQ(ASCIIToUTF16("second"), t_url->short_name());
464 EXPECT_EQ(ASCIIToUTF16("test2"), t_url->keyword()); 486 EXPECT_EQ(ASCIIToUTF16("test2"), t_url->keyword());
465 } 487 }
466 488
467 TEST_F(TemplateURLServiceTest, AddExtensionKeyword) { 489 TEST_F(TemplateURLServiceTest, AddExtensionKeyword) {
vasilii 2017/02/20 15:30:08 I'd rename the test to AddOmniboxExtensionKeyword
vasilii 2017/02/21 13:17:51 If you do not address a comment you should explain
Alexander Yashkin 2017/02/21 14:02:21 Sorry missed it. Where is a bug in codereview tool
468 test_util()->VerifyLoad(); 490 test_util()->VerifyLoad();
469 491
470 AddKeywordWithDate("replaceable", "keyword1", "http://test1", std::string(), 492 AddKeywordWithDate("replaceable", "keyword1", "http://test1", std::string(),
471 std::string(), std::string(), true, "UTF-8", Time(), 493 std::string(), std::string(), true, "UTF-8", Time(),
472 Time(), Time()); 494 Time(), Time());
473 TemplateURL* original2 = AddKeywordWithDate( 495 AddKeywordWithDate("nonreplaceable", "keyword2", "http://test2",
474 "nonreplaceable", "keyword2", "http://test2", std::string(), 496 std::string(), std::string(), std::string(), false,
475 std::string(), std::string(), false, "UTF-8", Time(), Time(), Time()); 497 "UTF-8", Time(), Time(), Time());
476 model()->RegisterOmniboxKeyword("test3", "extension", "keyword3", 498 model()->RegisterOmniboxKeyword("test3", "extension", "keyword3",
477 "http://test3"); 499 "http://test3", base::Time::Now());
478 TemplateURL* original3 = 500 TemplateURL* original3 =
479 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword3")); 501 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword3"));
480 ASSERT_TRUE(original3); 502 ASSERT_TRUE(original3);
481 503
482 // Extension keywords should override replaceable keywords. 504 // Extension keywords should override replaceable keywords.
483 model()->RegisterOmniboxKeyword("id1", "test", "keyword1", "http://test4"); 505 model()->RegisterOmniboxKeyword("id1", "test", "keyword1", "http://test4",
506 base::Time::Now());
484 TemplateURL* extension1 = model()->FindTemplateURLForExtension( 507 TemplateURL* extension1 = model()->FindTemplateURLForExtension(
485 "id1", TemplateURL::OMNIBOX_API_EXTENSION); 508 "id1", TemplateURL::OMNIBOX_API_EXTENSION);
486 EXPECT_TRUE(extension1); 509 EXPECT_TRUE(extension1);
487 EXPECT_EQ(extension1, 510 EXPECT_EQ(extension1,
488 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword1"))); 511 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword1")));
489 512
490 // They should not override non-replaceable keywords. 513 // They should also override non-replaceable keywords.
491 model()->RegisterOmniboxKeyword("id2", "test", "keyword2", "http://test5"); 514 model()->RegisterOmniboxKeyword("id2", "test", "keyword2", "http://test5",
515 base::Time::Now());
492 TemplateURL* extension2 = model()->FindTemplateURLForExtension( 516 TemplateURL* extension2 = model()->FindTemplateURLForExtension(
493 "id2", TemplateURL::OMNIBOX_API_EXTENSION); 517 "id2", TemplateURL::OMNIBOX_API_EXTENSION);
494 ASSERT_TRUE(extension2); 518 ASSERT_TRUE(extension2);
495 EXPECT_EQ(original2, 519 EXPECT_EQ(extension2,
496 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword2"))); 520 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword2")));
497 521
498 // They should override extension keywords added earlier. 522 // They should override extension keywords added earlier.
499 model()->RegisterOmniboxKeyword("id3", "test", "keyword3", "http://test6"); 523 model()->RegisterOmniboxKeyword("id3", "test", "keyword3", "http://test6",
524 base::Time::Now());
vasilii 2017/02/20 15:30:08 I see a source of flakiness here. base::Time::Now(
Alexander Yashkin 2017/02/20 19:52:47 Agree, changed to base::Time::FromDoubleT() in cas
500 TemplateURL* extension3 = model()->FindTemplateURLForExtension( 525 TemplateURL* extension3 = model()->FindTemplateURLForExtension(
501 "id3", TemplateURL::OMNIBOX_API_EXTENSION); 526 "id3", TemplateURL::OMNIBOX_API_EXTENSION);
502 ASSERT_TRUE(extension3); 527 ASSERT_TRUE(extension3);
503 EXPECT_EQ(extension3, 528 EXPECT_EQ(extension3,
504 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword3"))); 529 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword3")));
505 } 530 }
506 531
507 TEST_F(TemplateURLServiceTest, AddSameKeywordWithExtensionPresent) { 532 TEST_F(TemplateURLServiceTest, AddSameKeywordWithExtensionPresent) {
vasilii 2017/02/20 15:30:08 AddSameKeywordWithOmniboxExtensionPresent
Alexander Yashkin 2017/02/21 14:02:21 Done.
508 test_util()->VerifyLoad(); 533 test_util()->VerifyLoad();
509 534
510 // Similar to the AddSameKeyword test, but with an extension keyword masking a 535 // Similar to the AddSameKeyword test, but with an extension keyword masking a
511 // replaceable TemplateURL. We should still do correct conflict resolution 536 // replaceable TemplateURL. We should still do correct conflict resolution
512 // between the non-template URLs. 537 // between the non-template URLs.
513 model()->RegisterOmniboxKeyword("test2", "extension", "keyword", 538 model()->RegisterOmniboxKeyword("test2", "extension", "keyword",
514 "http://test2"); 539 "http://test2", base::Time::Now());
515 TemplateURL* extension = 540 TemplateURL* extension =
516 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword")); 541 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword"));
517 ASSERT_TRUE(extension); 542 ASSERT_TRUE(extension);
518 // Adding a keyword that matches the extension. 543 // Adding a keyword that matches the extension.
519 AddKeywordWithDate("replaceable", "keyword", "http://test1", std::string(), 544 AddKeywordWithDate("replaceable", "keyword", "http://test1", std::string(),
520 std::string(), std::string(), true, "UTF-8", Time(), 545 std::string(), std::string(), true, "UTF-8", Time(),
521 Time(), Time()); 546 Time(), Time());
522 547
523 // Adding another replaceable keyword should remove the existing one, but 548 // Adding another replaceable keyword should remove the existing one, but
524 // leave the extension as is. 549 // leave the extension as is.
525 TemplateURLData data; 550 TemplateURLData data;
526 data.SetShortName(ASCIIToUTF16("name1")); 551 data.SetShortName(ASCIIToUTF16("name1"));
527 data.SetKeyword(ASCIIToUTF16("keyword")); 552 data.SetKeyword(ASCIIToUTF16("keyword"));
528 data.SetURL("http://test3"); 553 data.SetURL("http://test3");
529 data.safe_for_autoreplace = true; 554 data.safe_for_autoreplace = true;
530 TemplateURL* t_url = model()->Add(base::MakeUnique<TemplateURL>(data)); 555 TemplateURL* t_url = model()->Add(base::MakeUnique<TemplateURL>(data));
531 EXPECT_EQ(extension, 556 EXPECT_EQ(extension,
532 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword"))); 557 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword")));
533 EXPECT_EQ(t_url, model()->GetTemplateURLForHost("test3")); 558 EXPECT_EQ(t_url, model()->GetTemplateURLForHost("test3"));
534 559
535 // Adding a nonreplaceable keyword should remove the existing replaceable 560 // Adding a nonreplaceable keyword should remove the existing replaceable
536 // keyword and replace the extension as the associated URL for this keyword, 561 // keyword, yet extension must still be set as the associated URL for this
537 // but not evict the extension from the service entirely. 562 // keyword.
538 data.SetShortName(ASCIIToUTF16("name2")); 563 data.SetShortName(ASCIIToUTF16("name2"));
539 data.SetURL("http://test4"); 564 data.SetURL("http://test4");
540 data.safe_for_autoreplace = false; 565 data.safe_for_autoreplace = false;
541 TemplateURL* t_url2 = model()->Add(base::MakeUnique<TemplateURL>(data)); 566 model()->Add(base::MakeUnique<TemplateURL>(data));
542 EXPECT_EQ(t_url2, 567 EXPECT_EQ(extension,
543 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword"))); 568 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword")));
544 } 569 }
545 570
546 TEST_F(TemplateURLServiceTest, NotPersistOmniboxExtensionKeyword) { 571 TEST_F(TemplateURLServiceTest, NotPersistOmniboxExtensionKeyword) {
547 test_util()->VerifyLoad(); 572 test_util()->VerifyLoad();
548 573
549 // Register an omnibox keyword. 574 // Register an omnibox keyword.
550 model()->RegisterOmniboxKeyword("test", "extension", "keyword", 575 model()->RegisterOmniboxKeyword("test", "extension", "keyword",
551 "chrome-extension://test"); 576 "chrome-extension://test", base::Time::Now());
552 ASSERT_TRUE(model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword"))); 577 ASSERT_TRUE(model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword")));
553 578
554 // Reload the data. 579 // Reload the data.
555 test_util()->ResetModel(true); 580 test_util()->ResetModel(true);
556 581
557 // Ensure the omnibox keyword is not persisted. 582 // Ensure the omnibox keyword is not persisted.
558 ASSERT_FALSE(model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword"))); 583 ASSERT_FALSE(model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword")));
559 } 584 }
560 585
561 TEST_F(TemplateURLServiceTest, ClearBrowsingData_Keywords) { 586 TEST_F(TemplateURLServiceTest, ClearBrowsingData_Keywords) {
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after
872 897
873 // Remove bing. 898 // Remove bing.
874 TemplateURL* bing = model()->GetTemplateURLForKeyword( 899 TemplateURL* bing = model()->GetTemplateURLForKeyword(
875 ASCIIToUTF16("bing.com")); 900 ASCIIToUTF16("bing.com"));
876 ASSERT_TRUE(bing); 901 ASSERT_TRUE(bing);
877 model()->Remove(bing); 902 model()->Remove(bing);
878 EXPECT_FALSE(model()->GetTemplateURLForKeyword(ASCIIToUTF16("bing.com"))); 903 EXPECT_FALSE(model()->GetTemplateURLForKeyword(ASCIIToUTF16("bing.com")));
879 904
880 // Register an extension with bing keyword. 905 // Register an extension with bing keyword.
881 model()->RegisterOmniboxKeyword("abcdefg", "extension_name", "bing.com", 906 model()->RegisterOmniboxKeyword("abcdefg", "extension_name", "bing.com",
882 "http://abcdefg"); 907 "http://abcdefg", base::Time::Now());
883 EXPECT_TRUE(model()->GetTemplateURLForKeyword(ASCIIToUTF16("bing.com"))); 908 EXPECT_TRUE(model()->GetTemplateURLForKeyword(ASCIIToUTF16("bing.com")));
884 909
885 model()->RepairPrepopulatedSearchEngines(); 910 model()->RepairPrepopulatedSearchEngines();
886 911
887 // Google is default. 912 // Google is default.
888 ASSERT_EQ(google, model()->GetDefaultSearchProvider()); 913 ASSERT_EQ(google, model()->GetDefaultSearchProvider());
889 // The keyword wasn't reverted. 914 // The keyword wasn't reverted.
890 EXPECT_EQ(ASCIIToUTF16("trash"), google->short_name()); 915 EXPECT_EQ(ASCIIToUTF16("trash"), google->short_name());
891 EXPECT_EQ("www.google.com", 916 EXPECT_EQ("www.google.com",
892 google->GenerateSearchURL(model()->search_terms_data()).host()); 917 google->GenerateSearchURL(model()->search_terms_data()).host());
(...skipping 758 matching lines...) Expand 10 before | Expand all | Expand 10 after
1651 std::move(ext_dse), std::move(extension_info)); 1676 std::move(ext_dse), std::move(extension_info));
1652 EXPECT_EQ(ext_dse_ptr, model()->GetDefaultSearchProvider()); 1677 EXPECT_EQ(ext_dse_ptr, model()->GetDefaultSearchProvider());
1653 1678
1654 test_util()->ResetModel(true); 1679 test_util()->ResetModel(true);
1655 user_dse = model()->GetTemplateURLForKeyword(ASCIIToUTF16("user")); 1680 user_dse = model()->GetTemplateURLForKeyword(ASCIIToUTF16("user"));
1656 ExpectSimilar(user_dse, model()->GetDefaultSearchProvider()); 1681 ExpectSimilar(user_dse, model()->GetDefaultSearchProvider());
1657 EXPECT_FALSE(model()->GetTemplateURLForKeyword(ASCIIToUTF16("ext1"))); 1682 EXPECT_FALSE(model()->GetTemplateURLForKeyword(ASCIIToUTF16("ext1")));
1658 EXPECT_FALSE(model()->GetTemplateURLForKeyword(ASCIIToUTF16("ext2"))); 1683 EXPECT_FALSE(model()->GetTemplateURLForKeyword(ASCIIToUTF16("ext2")));
1659 } 1684 }
1660 1685
1686 // Check that default extension engine and user engines with same keywords are
vasilii 2017/02/20 15:30:08 It checks the priority between the omnibox extensi
Alexander Yashkin 2017/02/20 19:52:47 Reworded.
1687 // handled corrected.
1688 TEST_F(TemplateURLServiceTest, DefaultExtensionAndEnginesWithSameKeywords) {
1689 test_util()->VerifyLoad();
1690 // TemplateURLData used for user engines.
1691 auto turl_data = GenerateDummyTemplateURLData("common_keyword");
1692 turl_data->safe_for_autoreplace = false;
1693
1694 // Add non replaceable user engine.
1695 const TemplateURL* user1 =
1696 model()->Add(base::MakeUnique<TemplateURL>(*turl_data));
1697
1698 // Add default extension engine with same keyword as user engine.
1699 const TemplateURL* extension =
1700 AddExtensionSearchEngine("common_keyword", "extension_id", true);
1701
1702 // Add another non replaceable user engine with same keyword as extension.
1703 const TemplateURL* user2 =
1704 model()->Add(base::MakeUnique<TemplateURL>(*turl_data));
1705
1706 // Wait for any saves to finish.
1707 base::RunLoop().RunUntilIdle();
vasilii 2017/02/20 15:30:08 Why?
Alexander Yashkin 2017/02/20 19:52:47 Copied from another test. I think its unnecessary
1708
1709 // Check extension DSE is set as default and its keyword is not changed.
1710 auto current_dse = model()->GetDefaultSearchProvider();
1711 EXPECT_EQ(extension, current_dse);
1712 EXPECT_EQ(ASCIIToUTF16("common_keyword"), current_dse->keyword());
1713
1714 // Register omnibox keyword with same keyword as extension.
1715 model()->RegisterOmniboxKeyword("omnibox_api", "extension_name",
vasilii 2017/02/20 15:30:08 Can you use "extension_id" or similar as the first
Alexander Yashkin 2017/02/20 19:52:47 Changed to "omnibox_api_extension_id". Did I unde
1716 "common_keyword", "http://test3",
1717 base::Time::Now());
1718 TemplateURL* omnibox_api = model()->FindTemplateURLForExtension(
1719 "omnibox_api", TemplateURL::OMNIBOX_API_EXTENSION);
1720
1721 // Expect that first non replaceable user engine keyword is changed because of
1722 // conflict. Second user engine will keep its keyword.
1723 EXPECT_NE(ASCIIToUTF16("common_keyword"), user1->keyword());
1724 EXPECT_EQ(ASCIIToUTF16("common_keyword"), user2->keyword());
1725
1726 // Check that extensions kept their keywords.
1727 EXPECT_EQ(ASCIIToUTF16("common_keyword"), extension->keyword());
1728 EXPECT_EQ(ASCIIToUTF16("common_keyword"), omnibox_api->keyword());
1729
1730 // Omnibox api is accessible by keyword as most relevant.
1731 EXPECT_EQ(omnibox_api,
1732 model()->GetTemplateURLForKeyword(ASCIIToUTF16("common_keyword")));
1733 // Extension controlled search engine is still set as default and can be found
1734 // in TemplateURLService.
1735 EXPECT_EQ(extension, model()->GetDefaultSearchProvider());
1736 EXPECT_EQ(extension,
1737 model()->FindTemplateURLForExtension(
1738 "extension_id", TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION));
1739
1740 // Test removing engines.
1741 // Remove omnibox api extension.
1742 model()->RemoveExtensionControlledTURL("omnibox_api",
1743 TemplateURL::OMNIBOX_API_EXTENSION);
1744 // Expect that keyword is now corresponds to extension search engine.
1745 EXPECT_EQ(extension,
1746 model()->GetTemplateURLForKeyword(ASCIIToUTF16("common_keyword")));
1747 // Remove extension engine.
1748 model()->RemoveExtensionControlledTURL(
1749 "extension_id", TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION);
1750 EXPECT_NE(extension, model()->GetDefaultSearchProvider());
1751 // Now latest user engine is returned for keyword.
1752 EXPECT_EQ(user2,
1753 model()->GetTemplateURLForKeyword(ASCIIToUTF16("common_keyword")));
1754 }
1755
1756 // Check that two extensions with same engine are handled corrected.
1757 TEST_F(TemplateURLServiceTest, ExtensionsWithSameKeywords) {
1758 test_util()->VerifyLoad();
1759
1760 // Add non default extension engine.
1761 const TemplateURL* extension1 =
1762 AddExtensionSearchEngine("common_keyword", "extension_id1", false);
1763
1764 // Check that GetTemplateURLForKeyword returns last installed extension.
1765 EXPECT_EQ(extension1,
1766 model()->GetTemplateURLForKeyword(ASCIIToUTF16("common_keyword")));
1767
1768 // Add default extension engine with the same keyword.
1769 const TemplateURL* extension2 =
1770 AddExtensionSearchEngine("common_keyword", "extension_id2", true);
vasilii 2017/02/20 15:30:08 I think here is the same flakiness as above regard
Alexander Yashkin 2017/02/20 19:52:47 Changed, now pass explicit time to AddExtensionSea
1771
1772 // Check that GetTemplateURLForKeyword now returns extension2 because it was
1773 // installed later.
1774 EXPECT_EQ(extension2,
1775 model()->GetTemplateURLForKeyword(ASCIIToUTF16("common_keyword")));
1776
1777 // Add another non default extension with same keyword. This action must not
1778 // change any keyword due to conflict.
1779 const TemplateURL* extension3 =
1780 AddExtensionSearchEngine("common_keyword", "extension_id3", false);
1781
1782 // Wait for any saves to finish.
1783 base::RunLoop().RunUntilIdle();
vasilii 2017/02/20 15:30:08 Why?
Alexander Yashkin 2017/02/20 19:52:47 Removed.
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
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 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698