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 1585 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1596 // Bring down a copy of the prepopulate engine from Sync with the old values, | 1596 // Bring down a copy of the prepopulate engine from Sync with the old values, |
| 1597 // including the old timestamp and the same GUID. Ensure that it loses | 1597 // including the old timestamp and the same GUID. Ensure that it loses |
| 1598 // conflict resolution against the local value, and an update is sent to the | 1598 // conflict resolution against the local value, and an update is sent to the |
| 1599 // server. The new timestamp should be preserved. | 1599 // server. The new timestamp should be preserved. |
| 1600 SyncDataList initial_data; | 1600 SyncDataList initial_data; |
| 1601 data_copy.SetKeyword(original_keyword); | 1601 data_copy.SetKeyword(original_keyword); |
| 1602 data_copy.sync_guid = sync_guid; | 1602 data_copy.sync_guid = sync_guid; |
| 1603 scoped_ptr<TemplateURL> sync_turl( | 1603 scoped_ptr<TemplateURL> sync_turl( |
| 1604 new TemplateURL(prepop_turls[0]->profile(), data_copy)); | 1604 new TemplateURL(prepop_turls[0]->profile(), data_copy)); |
| 1605 initial_data.push_back( | 1605 initial_data.push_back( |
| 1606 TemplateURLService::CreateSyncDataFromTemplateURL(*sync_turl.get())); | 1606 TemplateURLService::CreateSyncDataFromTemplateURL(*sync_turl)); |
| 1607 | 1607 |
| 1608 model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, | 1608 model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, |
| 1609 initial_data, PassProcessor(), CreateAndPassSyncErrorFactory()); | 1609 initial_data, PassProcessor(), CreateAndPassSyncErrorFactory()); |
| 1610 | 1610 |
| 1611 ASSERT_EQ(added_turl, model()->GetTemplateURLForKeyword( | 1611 ASSERT_EQ(added_turl, model()->GetTemplateURLForKeyword( |
| 1612 ASCIIToUTF16(kNewKeyword))); | 1612 ASCIIToUTF16(kNewKeyword))); |
| 1613 EXPECT_EQ(new_timestamp, added_turl->last_modified()); | 1613 EXPECT_EQ(new_timestamp, added_turl->last_modified()); |
| 1614 SyncChange change = processor()->change_for_guid(sync_guid); | 1614 SyncChange change = processor()->change_for_guid(sync_guid); |
| 1615 EXPECT_EQ(SyncChange::ACTION_UPDATE, change.change_type()); | 1615 EXPECT_EQ(SyncChange::ACTION_UPDATE, change.change_type()); |
| 1616 EXPECT_EQ(kNewKeyword, | 1616 EXPECT_EQ(kNewKeyword, |
| 1617 change.sync_data().GetSpecifics().search_engine().keyword()); | 1617 change.sync_data().GetSpecifics().search_engine().keyword()); |
| 1618 EXPECT_EQ(new_timestamp, base::Time::FromInternalValue( | 1618 EXPECT_EQ(new_timestamp, base::Time::FromInternalValue( |
| 1619 change.sync_data().GetSpecifics().search_engine().last_modified())); | 1619 change.sync_data().GetSpecifics().search_engine().last_modified())); |
| 1620 } | 1620 } |
| 1621 | |
| 1622 TEST_F(TemplateURLServiceSyncTest, UpdatingBaseURLGeneratesSyncChange) { | |
| 1623 test_util_a_.SetGoogleBaseURL(GURL("http://google.com/")); | |
| 1624 SyncDataList initial_data; | |
| 1625 scoped_ptr<TemplateURL> turl(CreateTestTemplateURL(ASCIIToUTF16("google.com"), | |
| 1626 "{google:baseURL}search?q={searchTerms}", "guid")); | |
| 1627 initial_data.push_back( | |
| 1628 TemplateURLService::CreateSyncDataFromTemplateURL(*turl)); | |
| 1629 model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, initial_data, | |
| 1630 PassProcessor(), CreateAndPassSyncErrorFactory()); | |
|
SteveT
2012/06/05 15:11:42
Hm, are we missing something here that changes the
Peter Kasting
2012/06/05 20:49:03
Yeah, this fragment was a leftover from before I c
| |
| 1631 } | |
| 1632 | |
| 1633 TEST_F(TemplateURLServiceSyncTest, SyncBaseURLs) { | |
| 1634 // Verify that bringing in a remote TemplateURL that uses Google base URLs | |
| 1635 // causes it to get a local keyword that matches the local base URL. | |
| 1636 test_util_a_.SetGoogleBaseURL(GURL("http://google.com/")); | |
| 1637 SyncDataList initial_data; | |
| 1638 scoped_ptr<TemplateURL> turl(CreateTestTemplateURL( | |
| 1639 ASCIIToUTF16("google.co.uk"), "{google:baseURL}search?q={searchTerms}", | |
| 1640 "guid")); | |
| 1641 initial_data.push_back( | |
| 1642 TemplateURLService::CreateSyncDataFromTemplateURL(*turl)); | |
| 1643 model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, initial_data, | |
| 1644 PassProcessor(), CreateAndPassSyncErrorFactory()); | |
| 1645 TemplateURL* synced_turl = model()->GetTemplateURLForGUID("guid"); | |
| 1646 ASSERT_TRUE(synced_turl); | |
| 1647 EXPECT_EQ(ASCIIToUTF16("google.com"), synced_turl->keyword()); | |
| 1648 EXPECT_EQ(0U, processor()->change_list_size()); | |
| 1649 | |
| 1650 // Remote updates to this URL's keyword should be silently ignored. | |
| 1651 SyncChangeList changes; | |
| 1652 changes.push_back(CreateTestSyncChange(SyncChange::ACTION_UPDATE, | |
| 1653 CreateTestTemplateURL(ASCIIToUTF16("google.de"), | |
| 1654 "{google:baseURL}search?q={searchTerms}", "guid"))); | |
| 1655 model()->ProcessSyncChanges(FROM_HERE, changes); | |
| 1656 EXPECT_EQ(ASCIIToUTF16("google.com"), synced_turl->keyword()); | |
| 1657 EXPECT_EQ(0U, processor()->change_list_size()); | |
| 1658 | |
| 1659 // A local change to the Google base URL should update the keyword and | |
| 1660 // generate a sync change. | |
| 1661 test_util_a_.SetGoogleBaseURL(GURL("http://google.co.in/")); | |
| 1662 EXPECT_EQ(ASCIIToUTF16("google.co.in"), synced_turl->keyword()); | |
| 1663 EXPECT_EQ(1U, processor()->change_list_size()); | |
| 1664 ASSERT_TRUE(processor()->contains_guid("guid")); | |
| 1665 SyncChange change(processor()->change_for_guid("guid")); | |
| 1666 EXPECT_EQ(SyncChange::ACTION_UPDATE, change.change_type()); | |
| 1667 EXPECT_EQ("google.co.in", GetKeyword(change.sync_data())); | |
| 1668 } | |
| OLD | NEW |