Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/memory/scoped_ptr.h" | 5 #include "base/memory/scoped_ptr.h" |
| 6 #include "base/memory/scoped_vector.h" | 6 #include "base/memory/scoped_vector.h" |
| 7 #include "base/string_util.h" | 7 #include "base/string_util.h" |
| 8 #include "base/time.h" | 8 #include "base/time.h" |
| 9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "chrome/browser/search_engines/search_terms_data.h" | 10 #include "chrome/browser/search_engines/search_terms_data.h" |
| (...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 431 ASSERT_FALSE(service_turl->created_by_policy()); | 431 ASSERT_FALSE(service_turl->created_by_policy()); |
| 432 AssertEquals(*service_turl, *deserialized); | 432 AssertEquals(*service_turl, *deserialized); |
| 433 } | 433 } |
| 434 } | 434 } |
| 435 | 435 |
| 436 TEST_F(TemplateURLServiceSyncTest, UniquifyKeyword) { | 436 TEST_F(TemplateURLServiceSyncTest, UniquifyKeyword) { |
| 437 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("key1"), "http://key1.com")); | 437 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("key1"), "http://key1.com")); |
| 438 // Create a key that conflicts with something in the model. | 438 // Create a key that conflicts with something in the model. |
| 439 scoped_ptr<TemplateURL> turl(CreateTestTemplateURL(ASCIIToUTF16("key1"), | 439 scoped_ptr<TemplateURL> turl(CreateTestTemplateURL(ASCIIToUTF16("key1"), |
| 440 "http://new.com", "xyz")); | 440 "http://new.com", "xyz")); |
| 441 string16 new_keyword = model()->UniquifyKeyword(*turl); | 441 string16 new_keyword = model()->UniquifyKeyword(*turl, false); |
| 442 EXPECT_EQ(ASCIIToUTF16("new.com"), new_keyword); | 442 EXPECT_EQ(ASCIIToUTF16("new.com"), new_keyword); |
| 443 EXPECT_EQ(NULL, model()->GetTemplateURLForKeyword(new_keyword)); | 443 EXPECT_EQ(NULL, model()->GetTemplateURLForKeyword(new_keyword)); |
| 444 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("new.com"), "http://new.com", | 444 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("new.com"), "http://new.com", |
| 445 "xyz")); | 445 "xyz")); |
| 446 | 446 |
| 447 // Test a second collision. This time it should be resolved by actually | 447 // Test a second collision. This time it should be resolved by actually |
| 448 // modifying the original keyword, since the autogenerated keyword is already | 448 // modifying the original keyword, since the autogenerated keyword is already |
| 449 // used. | 449 // used. |
| 450 turl.reset(CreateTestTemplateURL(ASCIIToUTF16("key1"), "http://new.com")); | 450 turl.reset(CreateTestTemplateURL(ASCIIToUTF16("key1"), "http://new.com")); |
| 451 new_keyword = model()->UniquifyKeyword(*turl); | 451 new_keyword = model()->UniquifyKeyword(*turl, false); |
| 452 EXPECT_EQ(ASCIIToUTF16("key1_"), new_keyword); | 452 EXPECT_EQ(ASCIIToUTF16("key1_"), new_keyword); |
| 453 EXPECT_EQ(NULL, model()->GetTemplateURLForKeyword(new_keyword)); | 453 EXPECT_EQ(NULL, model()->GetTemplateURLForKeyword(new_keyword)); |
| 454 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("key1_"), "http://new.com")); | 454 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("key1_"), "http://new.com")); |
| 455 | 455 |
| 456 // Test a third collision. This should collide on both the autogenerated | 456 // Test a third collision. This should collide on both the autogenerated |
| 457 // keyword and the first uniquification attempt. | 457 // keyword and the first uniquification attempt. |
| 458 turl.reset(CreateTestTemplateURL(ASCIIToUTF16("key1"), "http://new.com")); | 458 turl.reset(CreateTestTemplateURL(ASCIIToUTF16("key1"), "http://new.com")); |
| 459 new_keyword = model()->UniquifyKeyword(*turl); | 459 new_keyword = model()->UniquifyKeyword(*turl, false); |
| 460 EXPECT_EQ(ASCIIToUTF16("key1__"), new_keyword); | 460 EXPECT_EQ(ASCIIToUTF16("key1__"), new_keyword); |
| 461 EXPECT_EQ(NULL, model()->GetTemplateURLForKeyword(new_keyword)); | 461 EXPECT_EQ(NULL, model()->GetTemplateURLForKeyword(new_keyword)); |
| 462 | |
| 463 // If we force the method, it should uniquify the keyword even if it is | |
| 464 // currently unique, and skip the host-based autogenerated keyword. | |
| 465 turl.reset( | |
| 466 CreateTestTemplateURL(ASCIIToUTF16("unique"), "http://unique.com")); | |
| 467 new_keyword = model()->UniquifyKeyword(*turl, true); | |
| 468 EXPECT_EQ(ASCIIToUTF16("unique_"), new_keyword); | |
| 469 EXPECT_EQ(NULL, model()->GetTemplateURLForKeyword(new_keyword)); | |
| 462 } | 470 } |
| 463 | 471 |
| 464 TEST_F(TemplateURLServiceSyncTest, SyncKeywordConflictNeitherAutoreplace) { | 472 TEST_F(TemplateURLServiceSyncTest, SyncKeywordConflictNeitherAutoreplace) { |
| 465 // This tests cases where neither the sync nor the local TemplateURL are | 473 // This tests cases where neither the sync nor the local TemplateURL are |
| 466 // marked safe_for_autoreplace. | 474 // marked safe_for_autoreplace. |
| 467 | 475 |
| 468 // Create a keyword that conflicts, and make it older. Sync keyword is | 476 // Create a keyword that conflicts, and make it older. Sync keyword is |
| 469 // uniquified, and a syncer::SyncChange is added. | 477 // uniquified, and a syncer::SyncChange is added. |
| 470 string16 original_turl_keyword = ASCIIToUTF16("key1"); | 478 string16 original_turl_keyword = ASCIIToUTF16("key1"); |
| 471 TemplateURL* original_turl = CreateTestTemplateURL(original_turl_keyword, | 479 TemplateURL* original_turl = CreateTestTemplateURL(original_turl_keyword, |
| (...skipping 1127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1599 changes2.push_back(CreateTestSyncChange(syncer::SyncChange::ACTION_ADD, | 1607 changes2.push_back(CreateTestSyncChange(syncer::SyncChange::ACTION_ADD, |
| 1600 CreateTestTemplateURL(ASCIIToUTF16("new"), "http://new.com/{searchTerms}", | 1608 CreateTestTemplateURL(ASCIIToUTF16("new"), "http://new.com/{searchTerms}", |
| 1601 "newdefault"))); | 1609 "newdefault"))); |
| 1602 model()->ProcessSyncChanges(FROM_HERE, changes2); | 1610 model()->ProcessSyncChanges(FROM_HERE, changes2); |
| 1603 | 1611 |
| 1604 EXPECT_EQ(5U, model()->GetAllSyncData(syncer::SEARCH_ENGINES).size()); | 1612 EXPECT_EQ(5U, model()->GetAllSyncData(syncer::SEARCH_ENGINES).size()); |
| 1605 ASSERT_NE(default_search, model()->GetDefaultSearchProvider()); | 1613 ASSERT_NE(default_search, model()->GetDefaultSearchProvider()); |
| 1606 ASSERT_EQ("newdefault", model()->GetDefaultSearchProvider()->sync_guid()); | 1614 ASSERT_EQ("newdefault", model()->GetDefaultSearchProvider()->sync_guid()); |
| 1607 } | 1615 } |
| 1608 | 1616 |
| 1609 TEST_F(TemplateURLServiceSyncTest, DefaultGuidDeletedAndReplaced) { | 1617 TEST_F(TemplateURLServiceSyncTest, DefaultGuidDeletedBeforeNewDSPArrives) { |
| 1610 syncer::SyncDataList initial_data; | 1618 syncer::SyncDataList initial_data; |
| 1611 // The default search provider should support replacement. | 1619 // The default search provider should support replacement. |
| 1612 scoped_ptr<TemplateURL> turl1(CreateTestTemplateURL(ASCIIToUTF16("key1"), | 1620 scoped_ptr<TemplateURL> turl1(CreateTestTemplateURL(ASCIIToUTF16("key1"), |
| 1613 "http://key1.com/{searchTerms}", "key1", 90)); | 1621 "http://key1.com/{searchTerms}", "key1", 90)); |
| 1614 // Create a second default search provider for the | 1622 // Create a second default search provider for the |
| 1615 // FindNewDefaultSearchProvider method to find. | 1623 // FindNewDefaultSearchProvider method to find. |
| 1616 TemplateURLData data; | 1624 TemplateURLData data; |
| 1617 data.short_name = ASCIIToUTF16("unittest"); | 1625 data.short_name = ASCIIToUTF16("unittest"); |
| 1618 data.SetKeyword(ASCIIToUTF16("key2")); | 1626 data.SetKeyword(ASCIIToUTF16("key2")); |
| 1619 data.SetURL("http://key2.com/{searchTerms}"); | 1627 data.SetURL("http://key2.com/{searchTerms}"); |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 1632 *turl2)); | 1640 *turl2)); |
| 1633 model()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES, initial_data, | 1641 model()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES, initial_data, |
| 1634 PassProcessor(), CreateAndPassSyncErrorFactory()); | 1642 PassProcessor(), CreateAndPassSyncErrorFactory()); |
| 1635 model()->SetDefaultSearchProvider(model()->GetTemplateURLForGUID("key1")); | 1643 model()->SetDefaultSearchProvider(model()->GetTemplateURLForGUID("key1")); |
| 1636 ASSERT_EQ("key1", model()->GetDefaultSearchProvider()->sync_guid()); | 1644 ASSERT_EQ("key1", model()->GetDefaultSearchProvider()->sync_guid()); |
| 1637 | 1645 |
| 1638 EXPECT_EQ(2U, model()->GetAllSyncData(syncer::SEARCH_ENGINES).size()); | 1646 EXPECT_EQ(2U, model()->GetAllSyncData(syncer::SEARCH_ENGINES).size()); |
| 1639 const TemplateURL* default_search = model()->GetDefaultSearchProvider(); | 1647 const TemplateURL* default_search = model()->GetDefaultSearchProvider(); |
| 1640 ASSERT_TRUE(default_search); | 1648 ASSERT_TRUE(default_search); |
| 1641 | 1649 |
| 1642 // Delete the old default. This will change the default to the next available | |
| 1643 // (turl2), but should not affect the synced preference. | |
| 1644 syncer::SyncChangeList changes1; | |
| 1645 changes1.push_back(CreateTestSyncChange(syncer::SyncChange::ACTION_DELETE, | |
| 1646 turl1.release())); | |
| 1647 model()->ProcessSyncChanges(FROM_HERE, changes1); | |
| 1648 | |
| 1649 EXPECT_EQ(1U, model()->GetAllSyncData(syncer::SEARCH_ENGINES).size()); | |
| 1650 EXPECT_EQ("key2", model()->GetDefaultSearchProvider()->sync_guid()); | |
| 1651 EXPECT_EQ("key1", profile_a()->GetTestingPrefService()->GetString( | |
| 1652 prefs::kSyncedDefaultSearchProviderGUID)); | |
| 1653 | |
| 1654 // Change kSyncedDefaultSearchProviderGUID to a GUID that does not exist in | 1650 // Change kSyncedDefaultSearchProviderGUID to a GUID that does not exist in |
| 1655 // the model yet. Ensure that the default has not changed in any way. | 1651 // the model yet. Ensure that the default has not changed in any way. |
| 1656 profile_a()->GetTestingPrefService()->SetString( | 1652 profile_a()->GetTestingPrefService()->SetString( |
| 1657 prefs::kSyncedDefaultSearchProviderGUID, "newdefault"); | 1653 prefs::kSyncedDefaultSearchProviderGUID, "newdefault"); |
| 1658 | 1654 |
| 1659 ASSERT_EQ("key2", model()->GetDefaultSearchProvider()->sync_guid()); | 1655 ASSERT_EQ("key1", model()->GetDefaultSearchProvider()->sync_guid()); |
| 1660 EXPECT_EQ("newdefault", profile_a()->GetTestingPrefService()->GetString( | 1656 EXPECT_EQ("newdefault", profile_a()->GetTestingPrefService()->GetString( |
| 1661 prefs::kSyncedDefaultSearchProviderGUID)); | 1657 prefs::kSyncedDefaultSearchProviderGUID)); |
| 1662 | 1658 |
| 1659 // Simulate a situation where an ACTION_DELETE on the default arrives before | |
| 1660 // the new default search provider entry. This should fail to delete the | |
| 1661 // target entry, and instead send up an "undelete" to the server, after | |
| 1662 // further uniquifying the keyword to avoid infinite sync loops. The synced | |
| 1663 // default GUID should not be changed so that when the expected default entry | |
| 1664 // arrives, it can still be set as the default. | |
| 1665 syncer::SyncChangeList changes1; | |
| 1666 changes1.push_back(CreateTestSyncChange(syncer::SyncChange::ACTION_DELETE, | |
| 1667 turl1.release())); | |
| 1668 model()->ProcessSyncChanges(FROM_HERE, changes1); | |
| 1669 | |
| 1670 EXPECT_TRUE(model()->GetTemplateURLForKeyword(ASCIIToUTF16("key1_"))); | |
| 1671 EXPECT_EQ(2U, model()->GetAllSyncData(syncer::SEARCH_ENGINES).size()); | |
| 1672 EXPECT_EQ("key1", model()->GetDefaultSearchProvider()->sync_guid()); | |
| 1673 EXPECT_EQ("newdefault", profile_a()->GetTestingPrefService()->GetString( | |
| 1674 prefs::kSyncedDefaultSearchProviderGUID)); | |
| 1675 syncer::SyncChange undelete = processor()->change_for_guid("key1"); | |
| 1676 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, undelete.change_type()); | |
| 1677 EXPECT_EQ("key1_", | |
| 1678 undelete.sync_data().GetSpecifics().search_engine().keyword()); | |
|
Nicolas Zea
2012/07/10 17:07:47
verify that the sync guid stayed the same?
SteveT
2012/07/10 17:58:35
This was done above in 1673. Did you mean somethin
Nicolas Zea
2012/07/10 19:10:12
Ah, I just realized you're doing a lookup based on
| |
| 1679 | |
| 1663 // Finally, bring in the expected entry with the right GUID. Ensure that | 1680 // Finally, bring in the expected entry with the right GUID. Ensure that |
| 1664 // the default has changed to the new search engine. | 1681 // the default has changed to the new search engine. |
| 1665 syncer::SyncChangeList changes2; | 1682 syncer::SyncChangeList changes2; |
| 1666 changes2.push_back(CreateTestSyncChange(syncer::SyncChange::ACTION_ADD, | 1683 changes2.push_back(CreateTestSyncChange(syncer::SyncChange::ACTION_ADD, |
| 1667 CreateTestTemplateURL(ASCIIToUTF16("new"), "http://new.com/{searchTerms}", | 1684 CreateTestTemplateURL(ASCIIToUTF16("new"), "http://new.com/{searchTerms}", |
| 1668 "newdefault"))); | 1685 "newdefault"))); |
| 1669 model()->ProcessSyncChanges(FROM_HERE, changes2); | 1686 model()->ProcessSyncChanges(FROM_HERE, changes2); |
| 1670 | 1687 |
| 1671 EXPECT_EQ(2U, model()->GetAllSyncData(syncer::SEARCH_ENGINES).size()); | 1688 EXPECT_EQ(3U, model()->GetAllSyncData(syncer::SEARCH_ENGINES).size()); |
| 1672 EXPECT_EQ("newdefault", model()->GetDefaultSearchProvider()->sync_guid()); | 1689 EXPECT_EQ("newdefault", model()->GetDefaultSearchProvider()->sync_guid()); |
| 1673 EXPECT_EQ("newdefault", profile_a()->GetTestingPrefService()->GetString( | 1690 EXPECT_EQ("newdefault", profile_a()->GetTestingPrefService()->GetString( |
| 1674 prefs::kSyncedDefaultSearchProviderGUID)); | 1691 prefs::kSyncedDefaultSearchProviderGUID)); |
| 1675 } | 1692 } |
| 1676 | 1693 |
| 1677 TEST_F(TemplateURLServiceSyncTest, SyncedDefaultArrivesAfterStartup) { | 1694 TEST_F(TemplateURLServiceSyncTest, SyncedDefaultArrivesAfterStartup) { |
| 1678 // Start with the default set to something in the model before we start | 1695 // Start with the default set to something in the model before we start |
| 1679 // syncing. | 1696 // syncing. |
| 1680 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("what"), | 1697 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("what"), |
| 1681 "http://thewhat.com/{searchTerms}", | 1698 "http://thewhat.com/{searchTerms}", |
| (...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1986 // A local change to the Google base URL should update the keyword and | 2003 // A local change to the Google base URL should update the keyword and |
| 1987 // generate a sync change. | 2004 // generate a sync change. |
| 1988 test_util_a_.SetGoogleBaseURL(GURL("http://google.co.in/")); | 2005 test_util_a_.SetGoogleBaseURL(GURL("http://google.co.in/")); |
| 1989 EXPECT_EQ(ASCIIToUTF16("google.co.in"), synced_turl->keyword()); | 2006 EXPECT_EQ(ASCIIToUTF16("google.co.in"), synced_turl->keyword()); |
| 1990 EXPECT_EQ(1U, processor()->change_list_size()); | 2007 EXPECT_EQ(1U, processor()->change_list_size()); |
| 1991 ASSERT_TRUE(processor()->contains_guid("guid")); | 2008 ASSERT_TRUE(processor()->contains_guid("guid")); |
| 1992 syncer::SyncChange change(processor()->change_for_guid("guid")); | 2009 syncer::SyncChange change(processor()->change_for_guid("guid")); |
| 1993 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, change.change_type()); | 2010 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, change.change_type()); |
| 1994 EXPECT_EQ("google.co.in", GetKeyword(change.sync_data())); | 2011 EXPECT_EQ("google.co.in", GetKeyword(change.sync_data())); |
| 1995 } | 2012 } |
| OLD | NEW |