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/run_loop.h" | 7 #include "base/run_loop.h" |
8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 | 223 |
224 DISALLOW_COPY_AND_ASSIGN(TemplateURLServiceSyncTest); | 224 DISALLOW_COPY_AND_ASSIGN(TemplateURLServiceSyncTest); |
225 }; | 225 }; |
226 | 226 |
227 TemplateURLServiceSyncTest::TemplateURLServiceSyncTest() | 227 TemplateURLServiceSyncTest::TemplateURLServiceSyncTest() |
228 : sync_processor_(new TestChangeProcessor), | 228 : sync_processor_(new TestChangeProcessor), |
229 sync_processor_wrapper_(new syncer::SyncChangeProcessorWrapperForTest( | 229 sync_processor_wrapper_(new syncer::SyncChangeProcessorWrapperForTest( |
230 sync_processor_.get())) {} | 230 sync_processor_.get())) {} |
231 | 231 |
232 void TemplateURLServiceSyncTest::SetUp() { | 232 void TemplateURLServiceSyncTest::SetUp() { |
| 233 TemplateURLService::DisableFallbackSearchEngines(); |
233 test_util_a_.SetUp(); | 234 test_util_a_.SetUp(); |
234 // Use ChangeToLoadState() instead of VerifyLoad() so we don't actually pull | 235 // Use ChangeToLoadState() instead of VerifyLoad() so we don't actually pull |
235 // in the prepopulate data, which the sync tests don't care about (and would | 236 // in the prepopulate data, which the sync tests don't care about (and would |
236 // just foul them up). | 237 // just foul them up). |
237 test_util_a_.ChangeModelToLoadState(); | 238 test_util_a_.ChangeModelToLoadState(); |
238 profile_b_.reset(new TestingProfile); | 239 profile_b_.reset(new TestingProfile); |
239 TemplateURLServiceFactory::GetInstance()-> | 240 TemplateURLServiceFactory::GetInstance()-> |
240 RegisterUserPrefsOnBrowserContextForTest(profile_b_.get()); | 241 RegisterUserPrefsOnBrowserContextForTest(profile_b_.get()); |
241 model_b_.reset(new TemplateURLService(profile_b_.get())); | 242 model_b_.reset(new TemplateURLService(profile_b_.get())); |
242 model_b_->Load(); | 243 model_b_->Load(); |
(...skipping 1194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1437 PassProcessor(), | 1438 PassProcessor(), |
1438 CreateAndPassSyncErrorFactory()).error(); | 1439 CreateAndPassSyncErrorFactory()).error(); |
1439 ASSERT_FALSE(error.IsSet()); | 1440 ASSERT_FALSE(error.IsSet()); |
1440 | 1441 |
1441 // Check that the TemplateURL was not modified. | 1442 // Check that the TemplateURL was not modified. |
1442 const TemplateURL* reupdated_turl = model()->GetTemplateURLForGUID("key1"); | 1443 const TemplateURL* reupdated_turl = model()->GetTemplateURLForGUID("key1"); |
1443 ASSERT_TRUE(reupdated_turl); | 1444 ASSERT_TRUE(reupdated_turl); |
1444 AssertEquals(*updated_turl, *reupdated_turl); | 1445 AssertEquals(*updated_turl, *reupdated_turl); |
1445 } | 1446 } |
1446 | 1447 |
1447 TEST_F(TemplateURLServiceSyncTest, SyncedDefaultGUIDArrivesFirst) { | |
1448 syncer::SyncDataList initial_data = CreateInitialSyncData(); | |
1449 // The default search provider should support replacement. | |
1450 scoped_ptr<TemplateURL> turl(CreateTestTemplateURL(ASCIIToUTF16("key2"), | |
1451 "http://key2.com/{searchTerms}", "key2", 90)); | |
1452 initial_data[1] = TemplateURLService::CreateSyncDataFromTemplateURL(*turl); | |
1453 model()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES, initial_data, | |
1454 PassProcessor(), CreateAndPassSyncErrorFactory()); | |
1455 model()->SetUserSelectedDefaultSearchProvider( | |
1456 model()->GetTemplateURLForGUID("key2")); | |
1457 | |
1458 EXPECT_EQ(3U, model()->GetAllSyncData(syncer::SEARCH_ENGINES).size()); | |
1459 const TemplateURL* default_search = model()->GetDefaultSearchProvider(); | |
1460 ASSERT_TRUE(default_search); | |
1461 | |
1462 // Change kSyncedDefaultSearchProviderGUID to a GUID that does not exist in | |
1463 // the model yet. Ensure that the default has not changed in any way. | |
1464 profile_a()->GetTestingPrefService()->SetString( | |
1465 prefs::kSyncedDefaultSearchProviderGUID, "newdefault"); | |
1466 | |
1467 ASSERT_EQ(default_search, model()->GetDefaultSearchProvider()); | |
1468 | |
1469 // Bring in a random new search engine with a different GUID. Ensure that | |
1470 // it doesn't change the default. | |
1471 syncer::SyncChangeList changes1; | |
1472 changes1.push_back(CreateTestSyncChange(syncer::SyncChange::ACTION_ADD, | |
1473 CreateTestTemplateURL(ASCIIToUTF16("random"), "http://random.com", | |
1474 "random"))); | |
1475 model()->ProcessSyncChanges(FROM_HERE, changes1); | |
1476 | |
1477 EXPECT_EQ(4U, model()->GetAllSyncData(syncer::SEARCH_ENGINES).size()); | |
1478 ASSERT_EQ(default_search, model()->GetDefaultSearchProvider()); | |
1479 | |
1480 // Finally, bring in the expected entry with the right GUID. Ensure that | |
1481 // the default has changed to the new search engine. | |
1482 syncer::SyncChangeList changes2; | |
1483 changes2.push_back(CreateTestSyncChange(syncer::SyncChange::ACTION_ADD, | |
1484 CreateTestTemplateURL(ASCIIToUTF16("new"), "http://new.com/{searchTerms}", | |
1485 "newdefault"))); | |
1486 model()->ProcessSyncChanges(FROM_HERE, changes2); | |
1487 | |
1488 EXPECT_EQ(5U, model()->GetAllSyncData(syncer::SEARCH_ENGINES).size()); | |
1489 ASSERT_NE(default_search, model()->GetDefaultSearchProvider()); | |
1490 ASSERT_EQ("newdefault", model()->GetDefaultSearchProvider()->sync_guid()); | |
1491 } | |
1492 | |
1493 TEST_F(TemplateURLServiceSyncTest, DefaultGuidDeletedBeforeNewDSPArrives) { | |
1494 syncer::SyncDataList initial_data; | |
1495 // The default search provider should support replacement. | |
1496 scoped_ptr<TemplateURL> turl1(CreateTestTemplateURL(ASCIIToUTF16("key1"), | |
1497 "http://key1.com/{searchTerms}", "key1", 90)); | |
1498 // Create a second default search provider for the | |
1499 // FindNewDefaultSearchProvider method to find. | |
1500 TemplateURLData data; | |
1501 data.short_name = ASCIIToUTF16("unittest"); | |
1502 data.SetKeyword(ASCIIToUTF16("key2")); | |
1503 data.SetURL("http://key2.com/{searchTerms}"); | |
1504 data.favicon_url = GURL("http://favicon.url"); | |
1505 data.safe_for_autoreplace = false; | |
1506 data.date_created = Time::FromTimeT(100); | |
1507 data.last_modified = Time::FromTimeT(100); | |
1508 data.created_by_policy = false; | |
1509 data.prepopulate_id = 999999; | |
1510 data.sync_guid = "key2"; | |
1511 data.show_in_default_list = true; | |
1512 scoped_ptr<TemplateURL> turl2(new TemplateURL(NULL, data)); | |
1513 initial_data.push_back(TemplateURLService::CreateSyncDataFromTemplateURL( | |
1514 *turl1)); | |
1515 initial_data.push_back(TemplateURLService::CreateSyncDataFromTemplateURL( | |
1516 *turl2)); | |
1517 model()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES, initial_data, | |
1518 PassProcessor(), CreateAndPassSyncErrorFactory()); | |
1519 model()->SetUserSelectedDefaultSearchProvider( | |
1520 model()->GetTemplateURLForGUID("key1")); | |
1521 ASSERT_EQ("key1", model()->GetDefaultSearchProvider()->sync_guid()); | |
1522 | |
1523 EXPECT_EQ(2U, model()->GetAllSyncData(syncer::SEARCH_ENGINES).size()); | |
1524 const TemplateURL* default_search = model()->GetDefaultSearchProvider(); | |
1525 ASSERT_TRUE(default_search); | |
1526 | |
1527 // Change kSyncedDefaultSearchProviderGUID to a GUID that does not exist in | |
1528 // the model yet. Ensure that the default has not changed in any way. | |
1529 profile_a()->GetTestingPrefService()->SetString( | |
1530 prefs::kSyncedDefaultSearchProviderGUID, "newdefault"); | |
1531 | |
1532 ASSERT_EQ("key1", model()->GetDefaultSearchProvider()->sync_guid()); | |
1533 EXPECT_EQ("newdefault", profile_a()->GetTestingPrefService()->GetString( | |
1534 prefs::kSyncedDefaultSearchProviderGUID)); | |
1535 | |
1536 // Simulate a situation where an ACTION_DELETE on the default arrives before | |
1537 // the new default search provider entry. This should fail to delete the | |
1538 // target entry, and instead send up an "undelete" to the server, after | |
1539 // further uniquifying the keyword to avoid infinite sync loops. The synced | |
1540 // default GUID should not be changed so that when the expected default entry | |
1541 // arrives, it can still be set as the default. | |
1542 syncer::SyncChangeList changes1; | |
1543 changes1.push_back(CreateTestSyncChange(syncer::SyncChange::ACTION_DELETE, | |
1544 turl1.release())); | |
1545 model()->ProcessSyncChanges(FROM_HERE, changes1); | |
1546 | |
1547 EXPECT_TRUE(model()->GetTemplateURLForKeyword(ASCIIToUTF16("key1_"))); | |
1548 EXPECT_EQ(2U, model()->GetAllSyncData(syncer::SEARCH_ENGINES).size()); | |
1549 EXPECT_EQ("key1", model()->GetDefaultSearchProvider()->sync_guid()); | |
1550 EXPECT_EQ("newdefault", profile_a()->GetTestingPrefService()->GetString( | |
1551 prefs::kSyncedDefaultSearchProviderGUID)); | |
1552 syncer::SyncChange undelete = processor()->change_for_guid("key1"); | |
1553 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, undelete.change_type()); | |
1554 EXPECT_EQ("key1_", | |
1555 undelete.sync_data().GetSpecifics().search_engine().keyword()); | |
1556 | |
1557 // Finally, bring in the expected entry with the right GUID. Ensure that | |
1558 // the default has changed to the new search engine. | |
1559 syncer::SyncChangeList changes2; | |
1560 changes2.push_back(CreateTestSyncChange(syncer::SyncChange::ACTION_ADD, | |
1561 CreateTestTemplateURL(ASCIIToUTF16("new"), "http://new.com/{searchTerms}", | |
1562 "newdefault"))); | |
1563 model()->ProcessSyncChanges(FROM_HERE, changes2); | |
1564 | |
1565 EXPECT_EQ(3U, model()->GetAllSyncData(syncer::SEARCH_ENGINES).size()); | |
1566 EXPECT_EQ("newdefault", model()->GetDefaultSearchProvider()->sync_guid()); | |
1567 EXPECT_EQ("newdefault", profile_a()->GetTestingPrefService()->GetString( | |
1568 prefs::kSyncedDefaultSearchProviderGUID)); | |
1569 } | |
1570 | |
1571 TEST_F(TemplateURLServiceSyncTest, SyncedDefaultArrivesAfterStartup) { | |
1572 // Start with the default set to something in the model before we start | |
1573 // syncing. | |
1574 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("what"), | |
1575 "http://thewhat.com/{searchTerms}", | |
1576 "initdefault")); | |
1577 model()->SetUserSelectedDefaultSearchProvider( | |
1578 model()->GetTemplateURLForGUID("initdefault")); | |
1579 | |
1580 const TemplateURL* default_search = model()->GetDefaultSearchProvider(); | |
1581 ASSERT_TRUE(default_search); | |
1582 | |
1583 // Set kSyncedDefaultSearchProviderGUID to something that is not yet in | |
1584 // the model but is expected in the initial sync. Ensure that this doesn't | |
1585 // change our default since we're not quite syncing yet. | |
1586 profile_a()->GetTestingPrefService()->SetString( | |
1587 prefs::kSyncedDefaultSearchProviderGUID, "key2"); | |
1588 | |
1589 EXPECT_EQ(default_search, model()->GetDefaultSearchProvider()); | |
1590 | |
1591 // Now sync the initial data, which will include the search engine entry | |
1592 // destined to become the new default. | |
1593 syncer::SyncDataList initial_data = CreateInitialSyncData(); | |
1594 // The default search provider should support replacement. | |
1595 scoped_ptr<TemplateURL> turl(CreateTestTemplateURL(ASCIIToUTF16("key2"), | |
1596 "http://key2.com/{searchTerms}", "key2", 90)); | |
1597 initial_data[1] = TemplateURLService::CreateSyncDataFromTemplateURL(*turl); | |
1598 | |
1599 model()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES, initial_data, | |
1600 PassProcessor(), CreateAndPassSyncErrorFactory()); | |
1601 | |
1602 // Ensure that the new default has been set. | |
1603 EXPECT_EQ(4U, model()->GetAllSyncData(syncer::SEARCH_ENGINES).size()); | |
1604 ASSERT_NE(default_search, model()->GetDefaultSearchProvider()); | |
1605 ASSERT_EQ("key2", model()->GetDefaultSearchProvider()->sync_guid()); | |
1606 } | |
1607 | |
1608 TEST_F(TemplateURLServiceSyncTest, SyncedDefaultAlreadySetOnStartup) { | |
1609 // Start with the default set to something in the model before we start | |
1610 // syncing. | |
1611 const char kGUID[] = "initdefault"; | |
1612 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("what"), | |
1613 "http://thewhat.com/{searchTerms}", | |
1614 kGUID)); | |
1615 model()->SetUserSelectedDefaultSearchProvider( | |
1616 model()->GetTemplateURLForGUID(kGUID)); | |
1617 | |
1618 const TemplateURL* default_search = model()->GetDefaultSearchProvider(); | |
1619 ASSERT_TRUE(default_search); | |
1620 | |
1621 // Set kSyncedDefaultSearchProviderGUID to the current default. | |
1622 profile_a()->GetTestingPrefService()->SetString( | |
1623 prefs::kSyncedDefaultSearchProviderGUID, kGUID); | |
1624 | |
1625 EXPECT_EQ(default_search, model()->GetDefaultSearchProvider()); | |
1626 | |
1627 // Now sync the initial data. | |
1628 syncer::SyncDataList initial_data = CreateInitialSyncData(); | |
1629 model()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES, initial_data, | |
1630 PassProcessor(), CreateAndPassSyncErrorFactory()); | |
1631 | |
1632 // Ensure that the new entries were added and the default has not changed. | |
1633 EXPECT_EQ(4U, model()->GetAllSyncData(syncer::SEARCH_ENGINES).size()); | |
1634 ASSERT_EQ(default_search, model()->GetDefaultSearchProvider()); | |
1635 } | |
1636 | |
1637 TEST_F(TemplateURLServiceSyncTest, NewDefaultIsAlreadySynced) { | |
1638 // Ensure that if the synced DSP pref changed to another synced entry (as | |
1639 // opposed to coming in as a new entry), it gets reset correctly. | |
1640 // Start by setting kSyncedDefaultSearchProviderGUID to the entry that should | |
1641 // end up as the default. Note that this must be done before the initial | |
1642 // entries are added as otherwise this call will set the DSP immediately. | |
1643 profile_a()->GetTestingPrefService()->SetString( | |
1644 prefs::kSyncedDefaultSearchProviderGUID, "key2"); | |
1645 | |
1646 syncer::SyncDataList initial_data = CreateInitialSyncData(); | |
1647 // Ensure that our candidate default supports replacement. | |
1648 scoped_ptr<TemplateURL> turl(CreateTestTemplateURL(ASCIIToUTF16("key2"), | |
1649 "http://key2.com/{searchTerms}", "key2", 90)); | |
1650 initial_data[1] = TemplateURLService::CreateSyncDataFromTemplateURL(*turl); | |
1651 for (syncer::SyncDataList::const_iterator iter = initial_data.begin(); | |
1652 iter != initial_data.end(); ++iter) { | |
1653 TemplateURL* converted = Deserialize(*iter); | |
1654 model()->Add(converted); | |
1655 } | |
1656 | |
1657 // Set the initial default to something other than the desired default. | |
1658 model()->SetUserSelectedDefaultSearchProvider( | |
1659 model()->GetTemplateURLForGUID("key1")); | |
1660 | |
1661 // Merge in the same data (i.e. already synced entries). | |
1662 model()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES, initial_data, | |
1663 PassProcessor(), CreateAndPassSyncErrorFactory()); | |
1664 | |
1665 EXPECT_EQ(3U, model()->GetAllSyncData(syncer::SEARCH_ENGINES).size()); | |
1666 TemplateURL* current_default = model()->GetDefaultSearchProvider(); | |
1667 ASSERT_TRUE(current_default); | |
1668 EXPECT_EQ("key2", current_default->sync_guid()); | |
1669 EXPECT_EQ(ASCIIToUTF16("key2"), current_default->keyword()); | |
1670 } | |
1671 | |
1672 TEST_F(TemplateURLServiceSyncTest, SyncWithManagedDefaultSearch) { | |
1673 // First start off with a few entries and make sure we can set an unmanaged | |
1674 // default search provider. | |
1675 syncer::SyncDataList initial_data = CreateInitialSyncData(); | |
1676 model()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES, initial_data, | |
1677 PassProcessor(), CreateAndPassSyncErrorFactory()); | |
1678 model()->SetUserSelectedDefaultSearchProvider( | |
1679 model()->GetTemplateURLForGUID("key2")); | |
1680 | |
1681 EXPECT_EQ(3U, model()->GetAllSyncData(syncer::SEARCH_ENGINES).size()); | |
1682 ASSERT_FALSE(model()->is_default_search_managed()); | |
1683 ASSERT_TRUE(model()->GetDefaultSearchProvider()); | |
1684 | |
1685 // Change the default search provider to a managed one. | |
1686 const char kName[] = "manageddefault"; | |
1687 const char kSearchURL[] = "http://manageddefault.com/search?t={searchTerms}"; | |
1688 const char kIconURL[] = "http://manageddefault.com/icon.jpg"; | |
1689 const char kEncodings[] = "UTF-16;UTF-32"; | |
1690 const char kAlternateURL[] = | |
1691 "http://manageddefault.com/search#t={searchTerms}"; | |
1692 const char kSearchTermsReplacementKey[] = "espv"; | |
1693 test_util_a_.SetManagedDefaultSearchPreferences(true, kName, kName, | |
1694 kSearchURL, std::string(), kIconURL, kEncodings, kAlternateURL, | |
1695 kSearchTermsReplacementKey); | |
1696 const TemplateURL* dsp_turl = model()->GetDefaultSearchProvider(); | |
1697 | |
1698 EXPECT_TRUE(model()->is_default_search_managed()); | |
1699 | |
1700 // Add a new entry from Sync. It should still sync in despite the default | |
1701 // being managed. | |
1702 syncer::SyncChangeList changes; | |
1703 changes.push_back(CreateTestSyncChange(syncer::SyncChange::ACTION_ADD, | |
1704 CreateTestTemplateURL(ASCIIToUTF16("newkeyword"), | |
1705 "http://new.com/{searchTerms}", | |
1706 "newdefault"))); | |
1707 model()->ProcessSyncChanges(FROM_HERE, changes); | |
1708 | |
1709 EXPECT_EQ(4U, model()->GetAllSyncData(syncer::SEARCH_ENGINES).size()); | |
1710 | |
1711 // Change kSyncedDefaultSearchProviderGUID to point to the new entry and | |
1712 // ensure that the DSP remains managed. | |
1713 profile_a()->GetTestingPrefService()->SetString( | |
1714 prefs::kSyncedDefaultSearchProviderGUID, | |
1715 "newdefault"); | |
1716 | |
1717 EXPECT_EQ(dsp_turl, model()->GetDefaultSearchProvider()); | |
1718 EXPECT_TRUE(model()->is_default_search_managed()); | |
1719 | |
1720 // Go unmanaged. Ensure that the DSP changes to the expected pending entry | |
1721 // from Sync. | |
1722 const TemplateURL* expected_default = | |
1723 model()->GetTemplateURLForGUID("newdefault"); | |
1724 test_util_a_.RemoveManagedDefaultSearchPreferences(); | |
1725 | |
1726 EXPECT_EQ(expected_default, model()->GetDefaultSearchProvider()); | |
1727 } | |
1728 | |
1729 TEST_F(TemplateURLServiceSyncTest, SyncMergeDeletesDefault) { | 1448 TEST_F(TemplateURLServiceSyncTest, SyncMergeDeletesDefault) { |
1730 // If the value from Sync is a duplicate of the local default and is newer, it | 1449 // If the value from Sync is a duplicate of the local default and is newer, it |
1731 // should safely replace the local value and set as the new default. | 1450 // should safely replace the local value and set as the new default. |
1732 TemplateURL* default_turl = CreateTestTemplateURL(ASCIIToUTF16("key1"), | 1451 TemplateURL* default_turl = CreateTestTemplateURL(ASCIIToUTF16("key1"), |
1733 "http://key1.com/{searchTerms}", "whateverguid", 10); | 1452 "http://key1.com/{searchTerms}", "whateverguid", 10); |
1734 model()->Add(default_turl); | 1453 model()->Add(default_turl); |
1735 model()->SetUserSelectedDefaultSearchProvider(default_turl); | 1454 model()->SetUserSelectedDefaultSearchProvider(default_turl); |
1736 | 1455 |
1737 syncer::SyncDataList initial_data = CreateInitialSyncData(); | 1456 syncer::SyncDataList initial_data = CreateInitialSyncData(); |
1738 // The key1 entry should be a duplicate of the default. | 1457 // The key1 entry should be a duplicate of the default. |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1874 | 1593 |
1875 // Merge the prepopulate search engines. | 1594 // Merge the prepopulate search engines. |
1876 base::Time pre_merge_time = base::Time::Now(); | 1595 base::Time pre_merge_time = base::Time::Now(); |
1877 base::RunLoop().RunUntilIdle(); | 1596 base::RunLoop().RunUntilIdle(); |
1878 test_util_a_.ResetModel(true); | 1597 test_util_a_.ResetModel(true); |
1879 | 1598 |
1880 // The newly added search engine should have been safely merged, with an | 1599 // The newly added search engine should have been safely merged, with an |
1881 // updated time. | 1600 // updated time. |
1882 TemplateURL* added_turl = model()->GetTemplateURLForKeyword( | 1601 TemplateURL* added_turl = model()->GetTemplateURLForKeyword( |
1883 ASCIIToUTF16(kNewKeyword)); | 1602 ASCIIToUTF16(kNewKeyword)); |
| 1603 ASSERT_TRUE(added_turl); |
1884 base::Time new_timestamp = added_turl->last_modified(); | 1604 base::Time new_timestamp = added_turl->last_modified(); |
1885 EXPECT_GE(new_timestamp, pre_merge_time); | 1605 EXPECT_GE(new_timestamp, pre_merge_time); |
1886 ASSERT_TRUE(added_turl); | |
1887 std::string sync_guid = added_turl->sync_guid(); | 1606 std::string sync_guid = added_turl->sync_guid(); |
1888 | 1607 |
1889 // Bring down a copy of the prepopulate engine from Sync with the old values, | 1608 // Bring down a copy of the prepopulate engine from Sync with the old values, |
1890 // including the old timestamp and the same GUID. Ensure that it loses | 1609 // including the old timestamp and the same GUID. Ensure that it loses |
1891 // conflict resolution against the local value, and an update is sent to the | 1610 // conflict resolution against the local value, and an update is sent to the |
1892 // server. The new timestamp should be preserved. | 1611 // server. The new timestamp should be preserved. |
1893 syncer::SyncDataList initial_data; | 1612 syncer::SyncDataList initial_data; |
1894 data_copy.SetKeyword(original_keyword); | 1613 data_copy.SetKeyword(original_keyword); |
1895 data_copy.sync_guid = sync_guid; | 1614 data_copy.sync_guid = sync_guid; |
1896 scoped_ptr<TemplateURL> sync_turl(new TemplateURL(profile_a(), data_copy)); | 1615 scoped_ptr<TemplateURL> sync_turl(new TemplateURL(profile_a(), data_copy)); |
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2242 syncer::SyncMergeResult merge_result = model()->MergeDataAndStartSyncing( | 1961 syncer::SyncMergeResult merge_result = model()->MergeDataAndStartSyncing( |
2243 syncer::SEARCH_ENGINES, list, PassProcessor(), | 1962 syncer::SEARCH_ENGINES, list, PassProcessor(), |
2244 CreateAndPassSyncErrorFactory()); | 1963 CreateAndPassSyncErrorFactory()); |
2245 | 1964 |
2246 const TemplateURL* result_turl = model()->GetTemplateURLForGUID("default"); | 1965 const TemplateURL* result_turl = model()->GetTemplateURLForGUID("default"); |
2247 EXPECT_TRUE(result_turl); | 1966 EXPECT_TRUE(result_turl); |
2248 EXPECT_EQ(default_turl->keyword(), result_turl->keyword()); | 1967 EXPECT_EQ(default_turl->keyword(), result_turl->keyword()); |
2249 EXPECT_EQ(default_turl->short_name, result_turl->short_name()); | 1968 EXPECT_EQ(default_turl->short_name, result_turl->short_name()); |
2250 EXPECT_EQ(default_turl->url(), result_turl->url()); | 1969 EXPECT_EQ(default_turl->url(), result_turl->url()); |
2251 } | 1970 } |
| 1971 |
| 1972 TEST_F(TemplateURLServiceSyncTest, GUIDUpdatedOnDefaultSearchChange) { |
| 1973 const char kGUID[] = "initdefault"; |
| 1974 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("what"), |
| 1975 "http://thewhat.com/{searchTerms}", |
| 1976 kGUID)); |
| 1977 model()->SetUserSelectedDefaultSearchProvider( |
| 1978 model()->GetTemplateURLForGUID(kGUID)); |
| 1979 |
| 1980 const TemplateURL* default_search = model()->GetDefaultSearchProvider(); |
| 1981 ASSERT_TRUE(default_search); |
| 1982 |
| 1983 const char kNewGUID[] = "newdefault"; |
| 1984 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("what"), |
| 1985 "http://thewhat.com/{searchTerms}", |
| 1986 kNewGUID)); |
| 1987 model()->SetUserSelectedDefaultSearchProvider( |
| 1988 model()->GetTemplateURLForGUID(kNewGUID)); |
| 1989 |
| 1990 EXPECT_EQ(kNewGUID, profile_a()->GetTestingPrefService()->GetString( |
| 1991 prefs::kSyncedDefaultSearchProviderGUID)); |
| 1992 } |
OLD | NEW |