| 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 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 } | 116 } |
| 117 | 117 |
| 118 TestChangeProcessor::~TestChangeProcessor() { | 118 TestChangeProcessor::~TestChangeProcessor() { |
| 119 } | 119 } |
| 120 | 120 |
| 121 syncer::SyncError TestChangeProcessor::ProcessSyncChanges( | 121 syncer::SyncError TestChangeProcessor::ProcessSyncChanges( |
| 122 const tracked_objects::Location& from_here, | 122 const tracked_objects::Location& from_here, |
| 123 const syncer::SyncChangeList& change_list) { | 123 const syncer::SyncChangeList& change_list) { |
| 124 if (erroneous_) | 124 if (erroneous_) |
| 125 return syncer::SyncError( | 125 return syncer::SyncError( |
| 126 FROM_HERE, "Some error.", syncable::SEARCH_ENGINES); | 126 FROM_HERE, "Some error.", syncer::SEARCH_ENGINES); |
| 127 | 127 |
| 128 change_map_.erase(change_map_.begin(), change_map_.end()); | 128 change_map_.erase(change_map_.begin(), change_map_.end()); |
| 129 for (syncer::SyncChangeList::const_iterator iter = change_list.begin(); | 129 for (syncer::SyncChangeList::const_iterator iter = change_list.begin(); |
| 130 iter != change_list.end(); ++iter) | 130 iter != change_list.end(); ++iter) |
| 131 change_map_[GetGUID(iter->sync_data())] = *iter; | 131 change_map_[GetGUID(iter->sync_data())] = *iter; |
| 132 return syncer::SyncError(); | 132 return syncer::SyncError(); |
| 133 } | 133 } |
| 134 | 134 |
| 135 | 135 |
| 136 // SyncChangeProcessorDelegate ------------------------------------------------ | 136 // SyncChangeProcessorDelegate ------------------------------------------------ |
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 373 EXPECT_TRUE(deserialized.get()); | 373 EXPECT_TRUE(deserialized.get()); |
| 374 // Ensure that the original and the deserialized TURLs are equal in values. | 374 // Ensure that the original and the deserialized TURLs are equal in values. |
| 375 AssertEquals(*turl, *deserialized); | 375 AssertEquals(*turl, *deserialized); |
| 376 } | 376 } |
| 377 | 377 |
| 378 TEST_F(TemplateURLServiceSyncTest, GetAllSyncDataBasic) { | 378 TEST_F(TemplateURLServiceSyncTest, GetAllSyncDataBasic) { |
| 379 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("key1"), "http://key1.com")); | 379 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("key1"), "http://key1.com")); |
| 380 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("key2"), "http://key2.com")); | 380 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("key2"), "http://key2.com")); |
| 381 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("key3"), "http://key3.com")); | 381 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("key3"), "http://key3.com")); |
| 382 syncer::SyncDataList all_sync_data = | 382 syncer::SyncDataList all_sync_data = |
| 383 model()->GetAllSyncData(syncable::SEARCH_ENGINES); | 383 model()->GetAllSyncData(syncer::SEARCH_ENGINES); |
| 384 | 384 |
| 385 EXPECT_EQ(3U, all_sync_data.size()); | 385 EXPECT_EQ(3U, all_sync_data.size()); |
| 386 | 386 |
| 387 for (syncer::SyncDataList::const_iterator iter = all_sync_data.begin(); | 387 for (syncer::SyncDataList::const_iterator iter = all_sync_data.begin(); |
| 388 iter != all_sync_data.end(); ++iter) { | 388 iter != all_sync_data.end(); ++iter) { |
| 389 std::string guid = GetGUID(*iter); | 389 std::string guid = GetGUID(*iter); |
| 390 const TemplateURL* service_turl = model()->GetTemplateURLForGUID(guid); | 390 const TemplateURL* service_turl = model()->GetTemplateURLForGUID(guid); |
| 391 scoped_ptr<TemplateURL> deserialized(Deserialize(*iter)); | 391 scoped_ptr<TemplateURL> deserialized(Deserialize(*iter)); |
| 392 AssertEquals(*service_turl, *deserialized); | 392 AssertEquals(*service_turl, *deserialized); |
| 393 } | 393 } |
| 394 } | 394 } |
| 395 | 395 |
| 396 TEST_F(TemplateURLServiceSyncTest, GetAllSyncDataNoExtensions) { | 396 TEST_F(TemplateURLServiceSyncTest, GetAllSyncDataNoExtensions) { |
| 397 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("key1"), "http://key1.com")); | 397 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("key1"), "http://key1.com")); |
| 398 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("key2"), "http://key2.com")); | 398 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("key2"), "http://key2.com")); |
| 399 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("key3"), | 399 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("key3"), |
| 400 std::string(chrome::kExtensionScheme) + "://blahblahblah")); | 400 std::string(chrome::kExtensionScheme) + "://blahblahblah")); |
| 401 syncer::SyncDataList all_sync_data = | 401 syncer::SyncDataList all_sync_data = |
| 402 model()->GetAllSyncData(syncable::SEARCH_ENGINES); | 402 model()->GetAllSyncData(syncer::SEARCH_ENGINES); |
| 403 | 403 |
| 404 EXPECT_EQ(2U, all_sync_data.size()); | 404 EXPECT_EQ(2U, all_sync_data.size()); |
| 405 | 405 |
| 406 for (syncer::SyncDataList::const_iterator iter = all_sync_data.begin(); | 406 for (syncer::SyncDataList::const_iterator iter = all_sync_data.begin(); |
| 407 iter != all_sync_data.end(); ++iter) { | 407 iter != all_sync_data.end(); ++iter) { |
| 408 std::string guid = GetGUID(*iter); | 408 std::string guid = GetGUID(*iter); |
| 409 const TemplateURL* service_turl = model()->GetTemplateURLForGUID(guid); | 409 const TemplateURL* service_turl = model()->GetTemplateURLForGUID(guid); |
| 410 scoped_ptr<TemplateURL> deserialized(Deserialize(*iter)); | 410 scoped_ptr<TemplateURL> deserialized(Deserialize(*iter)); |
| 411 AssertEquals(*service_turl, *deserialized); | 411 AssertEquals(*service_turl, *deserialized); |
| 412 } | 412 } |
| 413 } | 413 } |
| 414 | 414 |
| 415 TEST_F(TemplateURLServiceSyncTest, GetAllSyncDataNoManagedEngines) { | 415 TEST_F(TemplateURLServiceSyncTest, GetAllSyncDataNoManagedEngines) { |
| 416 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("key1"), "http://key1.com")); | 416 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("key1"), "http://key1.com")); |
| 417 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("key2"), "http://key2.com")); | 417 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("key2"), "http://key2.com")); |
| 418 TemplateURL* managed_turl = CreateTestTemplateURL(ASCIIToUTF16("key3"), | 418 TemplateURL* managed_turl = CreateTestTemplateURL(ASCIIToUTF16("key3"), |
| 419 "http://key3.com", std::string(), 100, false, true); | 419 "http://key3.com", std::string(), 100, false, true); |
| 420 model()->Add(managed_turl); | 420 model()->Add(managed_turl); |
| 421 syncer::SyncDataList all_sync_data = | 421 syncer::SyncDataList all_sync_data = |
| 422 model()->GetAllSyncData(syncable::SEARCH_ENGINES); | 422 model()->GetAllSyncData(syncer::SEARCH_ENGINES); |
| 423 | 423 |
| 424 EXPECT_EQ(2U, all_sync_data.size()); | 424 EXPECT_EQ(2U, all_sync_data.size()); |
| 425 | 425 |
| 426 for (syncer::SyncDataList::const_iterator iter = all_sync_data.begin(); | 426 for (syncer::SyncDataList::const_iterator iter = all_sync_data.begin(); |
| 427 iter != all_sync_data.end(); ++iter) { | 427 iter != all_sync_data.end(); ++iter) { |
| 428 std::string guid = GetGUID(*iter); | 428 std::string guid = GetGUID(*iter); |
| 429 TemplateURL* service_turl = model()->GetTemplateURLForGUID(guid); | 429 TemplateURL* service_turl = model()->GetTemplateURLForGUID(guid); |
| 430 scoped_ptr<TemplateURL> deserialized(Deserialize(*iter)); | 430 scoped_ptr<TemplateURL> deserialized(Deserialize(*iter)); |
| 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); |
| (...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 746 EXPECT_EQ(1U, changes.size()); | 746 EXPECT_EQ(1U, changes.size()); |
| 747 // We expect a change to update the sync entry. | 747 // We expect a change to update the sync entry. |
| 748 change = changes.at(0); | 748 change = changes.at(0); |
| 749 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, change.change_type()); | 749 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, change.change_type()); |
| 750 EXPECT_EQ(sync_guid, | 750 EXPECT_EQ(sync_guid, |
| 751 change.sync_data().GetSpecifics().search_engine().sync_guid()); | 751 change.sync_data().GetSpecifics().search_engine().sync_guid()); |
| 752 } | 752 } |
| 753 | 753 |
| 754 TEST_F(TemplateURLServiceSyncTest, StartSyncEmpty) { | 754 TEST_F(TemplateURLServiceSyncTest, StartSyncEmpty) { |
| 755 model()->MergeDataAndStartSyncing( | 755 model()->MergeDataAndStartSyncing( |
| 756 syncable::SEARCH_ENGINES, syncer::SyncDataList(), | 756 syncer::SEARCH_ENGINES, syncer::SyncDataList(), |
| 757 PassProcessor(), CreateAndPassSyncErrorFactory()); | 757 PassProcessor(), CreateAndPassSyncErrorFactory()); |
| 758 | 758 |
| 759 EXPECT_EQ(0U, model()->GetAllSyncData(syncable::SEARCH_ENGINES).size()); | 759 EXPECT_EQ(0U, model()->GetAllSyncData(syncer::SEARCH_ENGINES).size()); |
| 760 EXPECT_EQ(0U, processor()->change_list_size()); | 760 EXPECT_EQ(0U, processor()->change_list_size()); |
| 761 } | 761 } |
| 762 | 762 |
| 763 TEST_F(TemplateURLServiceSyncTest, MergeIntoEmpty) { | 763 TEST_F(TemplateURLServiceSyncTest, MergeIntoEmpty) { |
| 764 syncer::SyncDataList initial_data = CreateInitialSyncData(); | 764 syncer::SyncDataList initial_data = CreateInitialSyncData(); |
| 765 | 765 |
| 766 model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, initial_data, | 766 model()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES, initial_data, |
| 767 PassProcessor(), CreateAndPassSyncErrorFactory()); | 767 PassProcessor(), CreateAndPassSyncErrorFactory()); |
| 768 | 768 |
| 769 EXPECT_EQ(3U, model()->GetAllSyncData(syncable::SEARCH_ENGINES).size()); | 769 EXPECT_EQ(3U, model()->GetAllSyncData(syncer::SEARCH_ENGINES).size()); |
| 770 // We expect the model to have accepted all of the initial sync data. Search | 770 // We expect the model to have accepted all of the initial sync data. Search |
| 771 // through the model using the GUIDs to ensure that they're present. | 771 // through the model using the GUIDs to ensure that they're present. |
| 772 for (syncer::SyncDataList::const_iterator iter = initial_data.begin(); | 772 for (syncer::SyncDataList::const_iterator iter = initial_data.begin(); |
| 773 iter != initial_data.end(); ++iter) { | 773 iter != initial_data.end(); ++iter) { |
| 774 std::string guid = GetGUID(*iter); | 774 std::string guid = GetGUID(*iter); |
| 775 EXPECT_TRUE(model()->GetTemplateURLForGUID(guid)); | 775 EXPECT_TRUE(model()->GetTemplateURLForGUID(guid)); |
| 776 } | 776 } |
| 777 | 777 |
| 778 EXPECT_EQ(0U, processor()->change_list_size()); | 778 EXPECT_EQ(0U, processor()->change_list_size()); |
| 779 } | 779 } |
| 780 | 780 |
| 781 TEST_F(TemplateURLServiceSyncTest, MergeInAllNewData) { | 781 TEST_F(TemplateURLServiceSyncTest, MergeInAllNewData) { |
| 782 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("abc.com"), "http://abc.com", | 782 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("abc.com"), "http://abc.com", |
| 783 "abc")); | 783 "abc")); |
| 784 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("def.com"), "http://def.com", | 784 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("def.com"), "http://def.com", |
| 785 "def")); | 785 "def")); |
| 786 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("xyz.com"), "http://xyz.com", | 786 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("xyz.com"), "http://xyz.com", |
| 787 "xyz")); | 787 "xyz")); |
| 788 syncer::SyncDataList initial_data = CreateInitialSyncData(); | 788 syncer::SyncDataList initial_data = CreateInitialSyncData(); |
| 789 | 789 |
| 790 model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, initial_data, | 790 model()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES, initial_data, |
| 791 PassProcessor(), CreateAndPassSyncErrorFactory()); | 791 PassProcessor(), CreateAndPassSyncErrorFactory()); |
| 792 | 792 |
| 793 EXPECT_EQ(6U, model()->GetAllSyncData(syncable::SEARCH_ENGINES).size()); | 793 EXPECT_EQ(6U, model()->GetAllSyncData(syncer::SEARCH_ENGINES).size()); |
| 794 // We expect the model to have accepted all of the initial sync data. Search | 794 // We expect the model to have accepted all of the initial sync data. Search |
| 795 // through the model using the GUIDs to ensure that they're present. | 795 // through the model using the GUIDs to ensure that they're present. |
| 796 for (syncer::SyncDataList::const_iterator iter = initial_data.begin(); | 796 for (syncer::SyncDataList::const_iterator iter = initial_data.begin(); |
| 797 iter != initial_data.end(); ++iter) { | 797 iter != initial_data.end(); ++iter) { |
| 798 std::string guid = GetGUID(*iter); | 798 std::string guid = GetGUID(*iter); |
| 799 EXPECT_TRUE(model()->GetTemplateURLForGUID(guid)); | 799 EXPECT_TRUE(model()->GetTemplateURLForGUID(guid)); |
| 800 } | 800 } |
| 801 // All the original TemplateURLs should also remain in the model. | 801 // All the original TemplateURLs should also remain in the model. |
| 802 EXPECT_TRUE(model()->GetTemplateURLForKeyword(ASCIIToUTF16("abc.com"))); | 802 EXPECT_TRUE(model()->GetTemplateURLForKeyword(ASCIIToUTF16("abc.com"))); |
| 803 EXPECT_TRUE(model()->GetTemplateURLForKeyword(ASCIIToUTF16("def.com"))); | 803 EXPECT_TRUE(model()->GetTemplateURLForKeyword(ASCIIToUTF16("def.com"))); |
| 804 EXPECT_TRUE(model()->GetTemplateURLForKeyword(ASCIIToUTF16("xyz.com"))); | 804 EXPECT_TRUE(model()->GetTemplateURLForKeyword(ASCIIToUTF16("xyz.com"))); |
| 805 // Ensure that Sync received the expected changes. | 805 // Ensure that Sync received the expected changes. |
| 806 EXPECT_EQ(3U, processor()->change_list_size()); | 806 EXPECT_EQ(3U, processor()->change_list_size()); |
| 807 EXPECT_TRUE(processor()->contains_guid("abc")); | 807 EXPECT_TRUE(processor()->contains_guid("abc")); |
| 808 EXPECT_TRUE(processor()->contains_guid("def")); | 808 EXPECT_TRUE(processor()->contains_guid("def")); |
| 809 EXPECT_TRUE(processor()->contains_guid("xyz")); | 809 EXPECT_TRUE(processor()->contains_guid("xyz")); |
| 810 } | 810 } |
| 811 | 811 |
| 812 TEST_F(TemplateURLServiceSyncTest, MergeSyncIsTheSame) { | 812 TEST_F(TemplateURLServiceSyncTest, MergeSyncIsTheSame) { |
| 813 // The local data is the same as the sync data merged in. i.e. - There have | 813 // The local data is the same as the sync data merged in. i.e. - There have |
| 814 // been no changes since the last time we synced. Even the last_modified | 814 // been no changes since the last time we synced. Even the last_modified |
| 815 // timestamps are the same. | 815 // timestamps are the same. |
| 816 syncer::SyncDataList initial_data = CreateInitialSyncData(); | 816 syncer::SyncDataList initial_data = CreateInitialSyncData(); |
| 817 for (syncer::SyncDataList::const_iterator iter = initial_data.begin(); | 817 for (syncer::SyncDataList::const_iterator iter = initial_data.begin(); |
| 818 iter != initial_data.end(); ++iter) { | 818 iter != initial_data.end(); ++iter) { |
| 819 TemplateURL* converted = Deserialize(*iter); | 819 TemplateURL* converted = Deserialize(*iter); |
| 820 model()->Add(converted); | 820 model()->Add(converted); |
| 821 } | 821 } |
| 822 | 822 |
| 823 model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, initial_data, | 823 model()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES, initial_data, |
| 824 PassProcessor(), CreateAndPassSyncErrorFactory()); | 824 PassProcessor(), CreateAndPassSyncErrorFactory()); |
| 825 | 825 |
| 826 EXPECT_EQ(3U, model()->GetAllSyncData(syncable::SEARCH_ENGINES).size()); | 826 EXPECT_EQ(3U, model()->GetAllSyncData(syncer::SEARCH_ENGINES).size()); |
| 827 for (syncer::SyncDataList::const_iterator iter = initial_data.begin(); | 827 for (syncer::SyncDataList::const_iterator iter = initial_data.begin(); |
| 828 iter != initial_data.end(); ++iter) { | 828 iter != initial_data.end(); ++iter) { |
| 829 std::string guid = GetGUID(*iter); | 829 std::string guid = GetGUID(*iter); |
| 830 EXPECT_TRUE(model()->GetTemplateURLForGUID(guid)); | 830 EXPECT_TRUE(model()->GetTemplateURLForGUID(guid)); |
| 831 } | 831 } |
| 832 EXPECT_EQ(0U, processor()->change_list_size()); | 832 EXPECT_EQ(0U, processor()->change_list_size()); |
| 833 } | 833 } |
| 834 | 834 |
| 835 TEST_F(TemplateURLServiceSyncTest, MergeUpdateFromSync) { | 835 TEST_F(TemplateURLServiceSyncTest, MergeUpdateFromSync) { |
| 836 // The local data is the same as the sync data merged in, but timestamps have | 836 // The local data is the same as the sync data merged in, but timestamps have |
| 837 // changed. Ensure the right fields are merged in. | 837 // changed. Ensure the right fields are merged in. |
| 838 syncer::SyncDataList initial_data; | 838 syncer::SyncDataList initial_data; |
| 839 TemplateURL* turl1 = CreateTestTemplateURL(ASCIIToUTF16("abc.com"), | 839 TemplateURL* turl1 = CreateTestTemplateURL(ASCIIToUTF16("abc.com"), |
| 840 "http://abc.com", "abc", 9000); | 840 "http://abc.com", "abc", 9000); |
| 841 model()->Add(turl1); | 841 model()->Add(turl1); |
| 842 TemplateURL* turl2 = CreateTestTemplateURL(ASCIIToUTF16("xyz.com"), | 842 TemplateURL* turl2 = CreateTestTemplateURL(ASCIIToUTF16("xyz.com"), |
| 843 "http://xyz.com", "xyz", 9000); | 843 "http://xyz.com", "xyz", 9000); |
| 844 model()->Add(turl2); | 844 model()->Add(turl2); |
| 845 | 845 |
| 846 scoped_ptr<TemplateURL> turl1_newer(CreateTestTemplateURL( | 846 scoped_ptr<TemplateURL> turl1_newer(CreateTestTemplateURL( |
| 847 ASCIIToUTF16("abc.com"), "http://abc.ca", "abc", 9999)); | 847 ASCIIToUTF16("abc.com"), "http://abc.ca", "abc", 9999)); |
| 848 initial_data.push_back( | 848 initial_data.push_back( |
| 849 TemplateURLService::CreateSyncDataFromTemplateURL(*turl1_newer)); | 849 TemplateURLService::CreateSyncDataFromTemplateURL(*turl1_newer)); |
| 850 | 850 |
| 851 scoped_ptr<TemplateURL> turl2_older(CreateTestTemplateURL( | 851 scoped_ptr<TemplateURL> turl2_older(CreateTestTemplateURL( |
| 852 ASCIIToUTF16("xyz.com"), "http://xyz.ca", "xyz", 8888)); | 852 ASCIIToUTF16("xyz.com"), "http://xyz.ca", "xyz", 8888)); |
| 853 initial_data.push_back( | 853 initial_data.push_back( |
| 854 TemplateURLService::CreateSyncDataFromTemplateURL(*turl2_older)); | 854 TemplateURLService::CreateSyncDataFromTemplateURL(*turl2_older)); |
| 855 | 855 |
| 856 model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, initial_data, | 856 model()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES, initial_data, |
| 857 PassProcessor(), CreateAndPassSyncErrorFactory()); | 857 PassProcessor(), CreateAndPassSyncErrorFactory()); |
| 858 | 858 |
| 859 // Both were local updates, so we expect the same count. | 859 // Both were local updates, so we expect the same count. |
| 860 EXPECT_EQ(2U, model()->GetAllSyncData(syncable::SEARCH_ENGINES).size()); | 860 EXPECT_EQ(2U, model()->GetAllSyncData(syncer::SEARCH_ENGINES).size()); |
| 861 | 861 |
| 862 // Check that the first replaced the initial abc TemplateURL. | 862 // Check that the first replaced the initial abc TemplateURL. |
| 863 EXPECT_EQ(turl1, model()->GetTemplateURLForGUID("abc")); | 863 EXPECT_EQ(turl1, model()->GetTemplateURLForGUID("abc")); |
| 864 EXPECT_EQ("http://abc.ca", turl1->url()); | 864 EXPECT_EQ("http://abc.ca", turl1->url()); |
| 865 | 865 |
| 866 // Check that the second produced an upstream update to the xyz TemplateURL. | 866 // Check that the second produced an upstream update to the xyz TemplateURL. |
| 867 EXPECT_EQ(1U, processor()->change_list_size()); | 867 EXPECT_EQ(1U, processor()->change_list_size()); |
| 868 ASSERT_TRUE(processor()->contains_guid("xyz")); | 868 ASSERT_TRUE(processor()->contains_guid("xyz")); |
| 869 syncer::SyncChange change = processor()->change_for_guid("xyz"); | 869 syncer::SyncChange change = processor()->change_for_guid("xyz"); |
| 870 EXPECT_TRUE(change.change_type() == syncer::SyncChange::ACTION_UPDATE); | 870 EXPECT_TRUE(change.change_type() == syncer::SyncChange::ACTION_UPDATE); |
| 871 EXPECT_EQ("http://xyz.com", GetURL(change.sync_data())); | 871 EXPECT_EQ("http://xyz.com", GetURL(change.sync_data())); |
| 872 } | 872 } |
| 873 | 873 |
| 874 TEST_F(TemplateURLServiceSyncTest, MergeAddFromOlderSyncData) { | 874 TEST_F(TemplateURLServiceSyncTest, MergeAddFromOlderSyncData) { |
| 875 // GUIDs all differ, so this is data to be added from Sync, but the timestamps | 875 // GUIDs all differ, so this is data to be added from Sync, but the timestamps |
| 876 // from Sync are older. Set up the local data so that one is a dupe, one has a | 876 // from Sync are older. Set up the local data so that one is a dupe, one has a |
| 877 // conflicting keyword, and the last has no conflicts (a clean ADD). | 877 // conflicting keyword, and the last has no conflicts (a clean ADD). |
| 878 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("key1"), "http://key1.com", | 878 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("key1"), "http://key1.com", |
| 879 "aaa", 100)); // dupe | 879 "aaa", 100)); // dupe |
| 880 | 880 |
| 881 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("key2"), | 881 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("key2"), |
| 882 "http://expected.com", "bbb", 100)); // keyword conflict | 882 "http://expected.com", "bbb", 100)); // keyword conflict |
| 883 | 883 |
| 884 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("unique"), | 884 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("unique"), |
| 885 "http://unique.com", "ccc")); // add | 885 "http://unique.com", "ccc")); // add |
| 886 | 886 |
| 887 model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, | 887 model()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES, |
| 888 CreateInitialSyncData(), PassProcessor(), | 888 CreateInitialSyncData(), PassProcessor(), |
| 889 CreateAndPassSyncErrorFactory()); | 889 CreateAndPassSyncErrorFactory()); |
| 890 | 890 |
| 891 // The dupe results in a merge. The other two should be added to the model. | 891 // The dupe results in a merge. The other two should be added to the model. |
| 892 EXPECT_EQ(5U, model()->GetAllSyncData(syncable::SEARCH_ENGINES).size()); | 892 EXPECT_EQ(5U, model()->GetAllSyncData(syncer::SEARCH_ENGINES).size()); |
| 893 | 893 |
| 894 // The key1 duplicate results in the local copy winning. Ensure that Sync's | 894 // The key1 duplicate results in the local copy winning. Ensure that Sync's |
| 895 // copy was not added, and the local copy is pushed upstream to Sync as an | 895 // copy was not added, and the local copy is pushed upstream to Sync as an |
| 896 // update. The local copy should have received the sync data's GUID. | 896 // update. The local copy should have received the sync data's GUID. |
| 897 EXPECT_TRUE(model()->GetTemplateURLForGUID("key1")); | 897 EXPECT_TRUE(model()->GetTemplateURLForGUID("key1")); |
| 898 // Check changes for the UPDATE. | 898 // Check changes for the UPDATE. |
| 899 ASSERT_TRUE(processor()->contains_guid("key1")); | 899 ASSERT_TRUE(processor()->contains_guid("key1")); |
| 900 syncer::SyncChange key1_change = processor()->change_for_guid("key1"); | 900 syncer::SyncChange key1_change = processor()->change_for_guid("key1"); |
| 901 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, key1_change.change_type()); | 901 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, key1_change.change_type()); |
| 902 EXPECT_FALSE(model()->GetTemplateURLForGUID("aaa")); | 902 EXPECT_FALSE(model()->GetTemplateURLForGUID("aaa")); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 936 // conflicting keyword, and the last has no conflicts (a clean ADD). | 936 // conflicting keyword, and the last has no conflicts (a clean ADD). |
| 937 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("key1"), "http://key1.com", | 937 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("key1"), "http://key1.com", |
| 938 "aaa", 10)); // dupe | 938 "aaa", 10)); // dupe |
| 939 | 939 |
| 940 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("key2"), | 940 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("key2"), |
| 941 "http://expected.com", "bbb", 10)); // keyword conflict | 941 "http://expected.com", "bbb", 10)); // keyword conflict |
| 942 | 942 |
| 943 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("unique"), | 943 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("unique"), |
| 944 "http://unique.com", "ccc", 10)); // add | 944 "http://unique.com", "ccc", 10)); // add |
| 945 | 945 |
| 946 model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, | 946 model()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES, |
| 947 CreateInitialSyncData(), PassProcessor(), | 947 CreateInitialSyncData(), PassProcessor(), |
| 948 CreateAndPassSyncErrorFactory()); | 948 CreateAndPassSyncErrorFactory()); |
| 949 | 949 |
| 950 // The dupe results in a merge. The other two should be added to the model. | 950 // The dupe results in a merge. The other two should be added to the model. |
| 951 EXPECT_EQ(5U, model()->GetAllSyncData(syncable::SEARCH_ENGINES).size()); | 951 EXPECT_EQ(5U, model()->GetAllSyncData(syncer::SEARCH_ENGINES).size()); |
| 952 | 952 |
| 953 // The key1 duplicate results in Sync's copy winning. Ensure that Sync's | 953 // The key1 duplicate results in Sync's copy winning. Ensure that Sync's |
| 954 // copy replaced the local copy. | 954 // copy replaced the local copy. |
| 955 EXPECT_TRUE(model()->GetTemplateURLForGUID("key1")); | 955 EXPECT_TRUE(model()->GetTemplateURLForGUID("key1")); |
| 956 EXPECT_FALSE(model()->GetTemplateURLForGUID("aaa")); | 956 EXPECT_FALSE(model()->GetTemplateURLForGUID("aaa")); |
| 957 | 957 |
| 958 // The key2 keyword conflict results in Sync's copy winning, so ensure it | 958 // The key2 keyword conflict results in Sync's copy winning, so ensure it |
| 959 // retains the original keyword. The local copy should get a uniquified | 959 // retains the original keyword. The local copy should get a uniquified |
| 960 // keyword. Both TemplateURLs should be found locally. | 960 // keyword. Both TemplateURLs should be found locally. |
| 961 const TemplateURL* key2_sync = model()->GetTemplateURLForGUID("key2"); | 961 const TemplateURL* key2_sync = model()->GetTemplateURLForGUID("key2"); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 977 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, | 977 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, |
| 978 processor()->change_for_guid("bbb").change_type()); | 978 processor()->change_for_guid("bbb").change_type()); |
| 979 ASSERT_TRUE(processor()->contains_guid("ccc")); | 979 ASSERT_TRUE(processor()->contains_guid("ccc")); |
| 980 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, | 980 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, |
| 981 processor()->change_for_guid("ccc").change_type()); | 981 processor()->change_for_guid("ccc").change_type()); |
| 982 } | 982 } |
| 983 | 983 |
| 984 TEST_F(TemplateURLServiceSyncTest, ProcessChangesEmptyModel) { | 984 TEST_F(TemplateURLServiceSyncTest, ProcessChangesEmptyModel) { |
| 985 // We initially have no data. | 985 // We initially have no data. |
| 986 model()->MergeDataAndStartSyncing( | 986 model()->MergeDataAndStartSyncing( |
| 987 syncable::SEARCH_ENGINES, syncer::SyncDataList(), | 987 syncer::SEARCH_ENGINES, syncer::SyncDataList(), |
| 988 PassProcessor(), CreateAndPassSyncErrorFactory()); | 988 PassProcessor(), CreateAndPassSyncErrorFactory()); |
| 989 | 989 |
| 990 // Set up a bunch of ADDs. | 990 // Set up a bunch of ADDs. |
| 991 syncer::SyncChangeList changes; | 991 syncer::SyncChangeList changes; |
| 992 changes.push_back(CreateTestSyncChange(syncer::SyncChange::ACTION_ADD, | 992 changes.push_back(CreateTestSyncChange(syncer::SyncChange::ACTION_ADD, |
| 993 CreateTestTemplateURL(ASCIIToUTF16("key1"), "http://key1.com", "key1"))); | 993 CreateTestTemplateURL(ASCIIToUTF16("key1"), "http://key1.com", "key1"))); |
| 994 changes.push_back(CreateTestSyncChange(syncer::SyncChange::ACTION_ADD, | 994 changes.push_back(CreateTestSyncChange(syncer::SyncChange::ACTION_ADD, |
| 995 CreateTestTemplateURL(ASCIIToUTF16("key2"), "http://key2.com", "key2"))); | 995 CreateTestTemplateURL(ASCIIToUTF16("key2"), "http://key2.com", "key2"))); |
| 996 changes.push_back(CreateTestSyncChange(syncer::SyncChange::ACTION_ADD, | 996 changes.push_back(CreateTestSyncChange(syncer::SyncChange::ACTION_ADD, |
| 997 CreateTestTemplateURL(ASCIIToUTF16("key3"), "http://key3.com", "key3"))); | 997 CreateTestTemplateURL(ASCIIToUTF16("key3"), "http://key3.com", "key3"))); |
| 998 | 998 |
| 999 model()->ProcessSyncChanges(FROM_HERE, changes); | 999 model()->ProcessSyncChanges(FROM_HERE, changes); |
| 1000 | 1000 |
| 1001 EXPECT_EQ(3U, model()->GetAllSyncData(syncable::SEARCH_ENGINES).size()); | 1001 EXPECT_EQ(3U, model()->GetAllSyncData(syncer::SEARCH_ENGINES).size()); |
| 1002 EXPECT_EQ(0U, processor()->change_list_size()); | 1002 EXPECT_EQ(0U, processor()->change_list_size()); |
| 1003 EXPECT_TRUE(model()->GetTemplateURLForGUID("key1")); | 1003 EXPECT_TRUE(model()->GetTemplateURLForGUID("key1")); |
| 1004 EXPECT_TRUE(model()->GetTemplateURLForGUID("key2")); | 1004 EXPECT_TRUE(model()->GetTemplateURLForGUID("key2")); |
| 1005 EXPECT_TRUE(model()->GetTemplateURLForGUID("key3")); | 1005 EXPECT_TRUE(model()->GetTemplateURLForGUID("key3")); |
| 1006 } | 1006 } |
| 1007 | 1007 |
| 1008 TEST_F(TemplateURLServiceSyncTest, ProcessChangesNoConflicts) { | 1008 TEST_F(TemplateURLServiceSyncTest, ProcessChangesNoConflicts) { |
| 1009 model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, | 1009 model()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES, |
| 1010 CreateInitialSyncData(), PassProcessor(), | 1010 CreateInitialSyncData(), PassProcessor(), |
| 1011 CreateAndPassSyncErrorFactory()); | 1011 CreateAndPassSyncErrorFactory()); |
| 1012 | 1012 |
| 1013 // Process different types of changes, without conflicts. | 1013 // Process different types of changes, without conflicts. |
| 1014 syncer::SyncChangeList changes; | 1014 syncer::SyncChangeList changes; |
| 1015 changes.push_back(CreateTestSyncChange(syncer::SyncChange::ACTION_ADD, | 1015 changes.push_back(CreateTestSyncChange(syncer::SyncChange::ACTION_ADD, |
| 1016 CreateTestTemplateURL(ASCIIToUTF16("key4"), "http://key4.com", "key4"))); | 1016 CreateTestTemplateURL(ASCIIToUTF16("key4"), "http://key4.com", "key4"))); |
| 1017 changes.push_back(CreateTestSyncChange(syncer::SyncChange::ACTION_UPDATE, | 1017 changes.push_back(CreateTestSyncChange(syncer::SyncChange::ACTION_UPDATE, |
| 1018 CreateTestTemplateURL(ASCIIToUTF16("newkeyword"), "http://new.com", | 1018 CreateTestTemplateURL(ASCIIToUTF16("newkeyword"), "http://new.com", |
| 1019 "key2"))); | 1019 "key2"))); |
| 1020 changes.push_back(CreateTestSyncChange(syncer::SyncChange::ACTION_DELETE, | 1020 changes.push_back(CreateTestSyncChange(syncer::SyncChange::ACTION_DELETE, |
| 1021 CreateTestTemplateURL(ASCIIToUTF16("key3"), "http://key3.com", "key3"))); | 1021 CreateTestTemplateURL(ASCIIToUTF16("key3"), "http://key3.com", "key3"))); |
| 1022 | 1022 |
| 1023 model()->ProcessSyncChanges(FROM_HERE, changes); | 1023 model()->ProcessSyncChanges(FROM_HERE, changes); |
| 1024 | 1024 |
| 1025 // Add one, remove one, update one, so the number shouldn't change. | 1025 // Add one, remove one, update one, so the number shouldn't change. |
| 1026 EXPECT_EQ(3U, model()->GetAllSyncData(syncable::SEARCH_ENGINES).size()); | 1026 EXPECT_EQ(3U, model()->GetAllSyncData(syncer::SEARCH_ENGINES).size()); |
| 1027 EXPECT_EQ(0U, processor()->change_list_size()); | 1027 EXPECT_EQ(0U, processor()->change_list_size()); |
| 1028 EXPECT_TRUE(model()->GetTemplateURLForGUID("key1")); | 1028 EXPECT_TRUE(model()->GetTemplateURLForGUID("key1")); |
| 1029 EXPECT_TRUE(model()->GetTemplateURLForGUID("key2")); | 1029 EXPECT_TRUE(model()->GetTemplateURLForGUID("key2")); |
| 1030 const TemplateURL* turl = model()->GetTemplateURLForGUID("key2"); | 1030 const TemplateURL* turl = model()->GetTemplateURLForGUID("key2"); |
| 1031 EXPECT_TRUE(turl); | 1031 EXPECT_TRUE(turl); |
| 1032 EXPECT_EQ(ASCIIToUTF16("newkeyword"), turl->keyword()); | 1032 EXPECT_EQ(ASCIIToUTF16("newkeyword"), turl->keyword()); |
| 1033 EXPECT_EQ("http://new.com", turl->url()); | 1033 EXPECT_EQ("http://new.com", turl->url()); |
| 1034 EXPECT_FALSE(model()->GetTemplateURLForGUID("key3")); | 1034 EXPECT_FALSE(model()->GetTemplateURLForGUID("key3")); |
| 1035 EXPECT_TRUE(model()->GetTemplateURLForGUID("key4")); | 1035 EXPECT_TRUE(model()->GetTemplateURLForGUID("key4")); |
| 1036 } | 1036 } |
| 1037 | 1037 |
| 1038 TEST_F(TemplateURLServiceSyncTest, ProcessChangesWithConflictsSyncWins) { | 1038 TEST_F(TemplateURLServiceSyncTest, ProcessChangesWithConflictsSyncWins) { |
| 1039 model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, | 1039 model()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES, |
| 1040 CreateInitialSyncData(), PassProcessor(), | 1040 CreateInitialSyncData(), PassProcessor(), |
| 1041 CreateAndPassSyncErrorFactory()); | 1041 CreateAndPassSyncErrorFactory()); |
| 1042 | 1042 |
| 1043 // Process different types of changes, with conflicts. Note that all this data | 1043 // Process different types of changes, with conflicts. Note that all this data |
| 1044 // has a newer timestamp, so Sync will win in these scenarios. | 1044 // has a newer timestamp, so Sync will win in these scenarios. |
| 1045 syncer::SyncChangeList changes; | 1045 syncer::SyncChangeList changes; |
| 1046 changes.push_back(CreateTestSyncChange(syncer::SyncChange::ACTION_ADD, | 1046 changes.push_back(CreateTestSyncChange(syncer::SyncChange::ACTION_ADD, |
| 1047 CreateTestTemplateURL(ASCIIToUTF16("key2"), "http://new.com", "aaa"))); | 1047 CreateTestTemplateURL(ASCIIToUTF16("key2"), "http://new.com", "aaa"))); |
| 1048 changes.push_back(CreateTestSyncChange(syncer::SyncChange::ACTION_UPDATE, | 1048 changes.push_back(CreateTestSyncChange(syncer::SyncChange::ACTION_UPDATE, |
| 1049 CreateTestTemplateURL(ASCIIToUTF16("key3"), "http://key3.com", "key1"))); | 1049 CreateTestTemplateURL(ASCIIToUTF16("key3"), "http://key3.com", "key1"))); |
| 1050 | 1050 |
| 1051 model()->ProcessSyncChanges(FROM_HERE, changes); | 1051 model()->ProcessSyncChanges(FROM_HERE, changes); |
| 1052 | 1052 |
| 1053 // Add one, update one, so we're up to 4. | 1053 // Add one, update one, so we're up to 4. |
| 1054 EXPECT_EQ(4U, model()->GetAllSyncData(syncable::SEARCH_ENGINES).size()); | 1054 EXPECT_EQ(4U, model()->GetAllSyncData(syncer::SEARCH_ENGINES).size()); |
| 1055 // Sync is always newer here, so it should always win. We should create | 1055 // Sync is always newer here, so it should always win. We should create |
| 1056 // SyncChanges for the changes to the local entities, since they're synced | 1056 // SyncChanges for the changes to the local entities, since they're synced |
| 1057 // too. | 1057 // too. |
| 1058 EXPECT_EQ(2U, processor()->change_list_size()); | 1058 EXPECT_EQ(2U, processor()->change_list_size()); |
| 1059 ASSERT_TRUE(processor()->contains_guid("key2")); | 1059 ASSERT_TRUE(processor()->contains_guid("key2")); |
| 1060 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, | 1060 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, |
| 1061 processor()->change_for_guid("key2").change_type()); | 1061 processor()->change_for_guid("key2").change_type()); |
| 1062 ASSERT_TRUE(processor()->contains_guid("key3")); | 1062 ASSERT_TRUE(processor()->contains_guid("key3")); |
| 1063 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, | 1063 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, |
| 1064 processor()->change_for_guid("key3").change_type()); | 1064 processor()->change_for_guid("key3").change_type()); |
| 1065 | 1065 |
| 1066 // aaa conflicts with key2 and wins, forcing key2's keyword to update. | 1066 // aaa conflicts with key2 and wins, forcing key2's keyword to update. |
| 1067 EXPECT_TRUE(model()->GetTemplateURLForGUID("aaa")); | 1067 EXPECT_TRUE(model()->GetTemplateURLForGUID("aaa")); |
| 1068 EXPECT_EQ(model()->GetTemplateURLForGUID("aaa"), | 1068 EXPECT_EQ(model()->GetTemplateURLForGUID("aaa"), |
| 1069 model()->GetTemplateURLForKeyword(ASCIIToUTF16("key2"))); | 1069 model()->GetTemplateURLForKeyword(ASCIIToUTF16("key2"))); |
| 1070 EXPECT_TRUE(model()->GetTemplateURLForGUID("key2")); | 1070 EXPECT_TRUE(model()->GetTemplateURLForGUID("key2")); |
| 1071 EXPECT_EQ(model()->GetTemplateURLForGUID("key2"), | 1071 EXPECT_EQ(model()->GetTemplateURLForGUID("key2"), |
| 1072 model()->GetTemplateURLForKeyword(ASCIIToUTF16("key2.com"))); | 1072 model()->GetTemplateURLForKeyword(ASCIIToUTF16("key2.com"))); |
| 1073 // key1 update conflicts with key3 and wins, forcing key3's keyword to update. | 1073 // key1 update conflicts with key3 and wins, forcing key3's keyword to update. |
| 1074 EXPECT_TRUE(model()->GetTemplateURLForGUID("key1")); | 1074 EXPECT_TRUE(model()->GetTemplateURLForGUID("key1")); |
| 1075 EXPECT_EQ(model()->GetTemplateURLForGUID("key1"), | 1075 EXPECT_EQ(model()->GetTemplateURLForGUID("key1"), |
| 1076 model()->GetTemplateURLForKeyword(ASCIIToUTF16("key3"))); | 1076 model()->GetTemplateURLForKeyword(ASCIIToUTF16("key3"))); |
| 1077 EXPECT_TRUE(model()->GetTemplateURLForGUID("key3")); | 1077 EXPECT_TRUE(model()->GetTemplateURLForGUID("key3")); |
| 1078 EXPECT_EQ(model()->GetTemplateURLForGUID("key3"), | 1078 EXPECT_EQ(model()->GetTemplateURLForGUID("key3"), |
| 1079 model()->GetTemplateURLForKeyword(ASCIIToUTF16("key3.com"))); | 1079 model()->GetTemplateURLForKeyword(ASCIIToUTF16("key3.com"))); |
| 1080 } | 1080 } |
| 1081 | 1081 |
| 1082 TEST_F(TemplateURLServiceSyncTest, ProcessChangesWithConflictsLocalWins) { | 1082 TEST_F(TemplateURLServiceSyncTest, ProcessChangesWithConflictsLocalWins) { |
| 1083 model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, | 1083 model()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES, |
| 1084 CreateInitialSyncData(), PassProcessor(), | 1084 CreateInitialSyncData(), PassProcessor(), |
| 1085 CreateAndPassSyncErrorFactory()); | 1085 CreateAndPassSyncErrorFactory()); |
| 1086 | 1086 |
| 1087 // Process different types of changes, with conflicts. Note that all this data | 1087 // Process different types of changes, with conflicts. Note that all this data |
| 1088 // has an older timestamp, so the local data will win in these scenarios. | 1088 // has an older timestamp, so the local data will win in these scenarios. |
| 1089 syncer::SyncChangeList changes; | 1089 syncer::SyncChangeList changes; |
| 1090 changes.push_back(CreateTestSyncChange(syncer::SyncChange::ACTION_ADD, | 1090 changes.push_back(CreateTestSyncChange(syncer::SyncChange::ACTION_ADD, |
| 1091 CreateTestTemplateURL(ASCIIToUTF16("key2"), "http://new.com", "aaa", | 1091 CreateTestTemplateURL(ASCIIToUTF16("key2"), "http://new.com", "aaa", |
| 1092 10))); | 1092 10))); |
| 1093 changes.push_back(CreateTestSyncChange(syncer::SyncChange::ACTION_UPDATE, | 1093 changes.push_back(CreateTestSyncChange(syncer::SyncChange::ACTION_UPDATE, |
| 1094 CreateTestTemplateURL(ASCIIToUTF16("key3"), "http://key3.com", "key1", | 1094 CreateTestTemplateURL(ASCIIToUTF16("key3"), "http://key3.com", "key1", |
| 1095 10))); | 1095 10))); |
| 1096 | 1096 |
| 1097 model()->ProcessSyncChanges(FROM_HERE, changes); | 1097 model()->ProcessSyncChanges(FROM_HERE, changes); |
| 1098 | 1098 |
| 1099 // Add one, update one, so we're up to 4. | 1099 // Add one, update one, so we're up to 4. |
| 1100 EXPECT_EQ(4U, model()->GetAllSyncData(syncable::SEARCH_ENGINES).size()); | 1100 EXPECT_EQ(4U, model()->GetAllSyncData(syncer::SEARCH_ENGINES).size()); |
| 1101 // Local data wins twice so two updates are pushed up to Sync. | 1101 // Local data wins twice so two updates are pushed up to Sync. |
| 1102 EXPECT_EQ(2U, processor()->change_list_size()); | 1102 EXPECT_EQ(2U, processor()->change_list_size()); |
| 1103 | 1103 |
| 1104 // aaa conflicts with key2 and loses, forcing it's keyword to update. | 1104 // aaa conflicts with key2 and loses, forcing it's keyword to update. |
| 1105 EXPECT_TRUE(model()->GetTemplateURLForGUID("aaa")); | 1105 EXPECT_TRUE(model()->GetTemplateURLForGUID("aaa")); |
| 1106 EXPECT_EQ(model()->GetTemplateURLForGUID("aaa"), | 1106 EXPECT_EQ(model()->GetTemplateURLForGUID("aaa"), |
| 1107 model()->GetTemplateURLForKeyword(ASCIIToUTF16("new.com"))); | 1107 model()->GetTemplateURLForKeyword(ASCIIToUTF16("new.com"))); |
| 1108 EXPECT_TRUE(model()->GetTemplateURLForGUID("key2")); | 1108 EXPECT_TRUE(model()->GetTemplateURLForGUID("key2")); |
| 1109 EXPECT_EQ(model()->GetTemplateURLForGUID("key2"), | 1109 EXPECT_EQ(model()->GetTemplateURLForGUID("key2"), |
| 1110 model()->GetTemplateURLForKeyword(ASCIIToUTF16("key2"))); | 1110 model()->GetTemplateURLForKeyword(ASCIIToUTF16("key2"))); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1127 | 1127 |
| 1128 TEST_F(TemplateURLServiceSyncTest, RemoveUpdatedURLOnConflict) { | 1128 TEST_F(TemplateURLServiceSyncTest, RemoveUpdatedURLOnConflict) { |
| 1129 // Updating a local replaceable URL to have the same keyword as a local | 1129 // Updating a local replaceable URL to have the same keyword as a local |
| 1130 // non-replaceable URL should result in the former being removed from the | 1130 // non-replaceable URL should result in the former being removed from the |
| 1131 // model entirely. | 1131 // model entirely. |
| 1132 syncer::SyncDataList initial_data; | 1132 syncer::SyncDataList initial_data; |
| 1133 scoped_ptr<TemplateURL> turl(CreateTestTemplateURL(ASCIIToUTF16("sync"), | 1133 scoped_ptr<TemplateURL> turl(CreateTestTemplateURL(ASCIIToUTF16("sync"), |
| 1134 "http://sync.com", "sync", 100, true)); | 1134 "http://sync.com", "sync", 100, true)); |
| 1135 initial_data.push_back( | 1135 initial_data.push_back( |
| 1136 TemplateURLService::CreateSyncDataFromTemplateURL(*turl)); | 1136 TemplateURLService::CreateSyncDataFromTemplateURL(*turl)); |
| 1137 model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, initial_data, | 1137 model()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES, initial_data, |
| 1138 PassProcessor(), CreateAndPassSyncErrorFactory()); | 1138 PassProcessor(), CreateAndPassSyncErrorFactory()); |
| 1139 | 1139 |
| 1140 TemplateURL* new_turl = | 1140 TemplateURL* new_turl = |
| 1141 CreateTestTemplateURL(ASCIIToUTF16("local"), "http://local.com", "local"); | 1141 CreateTestTemplateURL(ASCIIToUTF16("local"), "http://local.com", "local"); |
| 1142 model()->Add(new_turl); | 1142 model()->Add(new_turl); |
| 1143 | 1143 |
| 1144 syncer::SyncChangeList changes; | 1144 syncer::SyncChangeList changes; |
| 1145 changes.push_back(CreateTestSyncChange(syncer::SyncChange::ACTION_UPDATE, | 1145 changes.push_back(CreateTestSyncChange(syncer::SyncChange::ACTION_UPDATE, |
| 1146 CreateTestTemplateURL(ASCIIToUTF16("local"), "http://sync.com", "sync", | 1146 CreateTestTemplateURL(ASCIIToUTF16("local"), "http://sync.com", "sync", |
| 1147 110, true))); | 1147 110, true))); |
| 1148 model()->ProcessSyncChanges(FROM_HERE, changes); | 1148 model()->ProcessSyncChanges(FROM_HERE, changes); |
| 1149 | 1149 |
| 1150 EXPECT_EQ(1U, model()->GetTemplateURLs().size()); | 1150 EXPECT_EQ(1U, model()->GetTemplateURLs().size()); |
| 1151 EXPECT_EQ("local", | 1151 EXPECT_EQ("local", |
| 1152 model()->GetTemplateURLForKeyword(ASCIIToUTF16("local"))->sync_guid()); | 1152 model()->GetTemplateURLForKeyword(ASCIIToUTF16("local"))->sync_guid()); |
| 1153 EXPECT_EQ(1U, processor()->change_list_size()); | 1153 EXPECT_EQ(1U, processor()->change_list_size()); |
| 1154 ASSERT_TRUE(processor()->contains_guid("sync")); | 1154 ASSERT_TRUE(processor()->contains_guid("sync")); |
| 1155 EXPECT_EQ(syncer::SyncChange::ACTION_DELETE, | 1155 EXPECT_EQ(syncer::SyncChange::ACTION_DELETE, |
| 1156 processor()->change_for_guid("sync").change_type()); | 1156 processor()->change_for_guid("sync").change_type()); |
| 1157 } | 1157 } |
| 1158 | 1158 |
| 1159 TEST_F(TemplateURLServiceSyncTest, ProcessTemplateURLChange) { | 1159 TEST_F(TemplateURLServiceSyncTest, ProcessTemplateURLChange) { |
| 1160 // Ensure that ProcessTemplateURLChange is called and pushes the correct | 1160 // Ensure that ProcessTemplateURLChange is called and pushes the correct |
| 1161 // changes to Sync whenever local changes are made to TemplateURLs. | 1161 // changes to Sync whenever local changes are made to TemplateURLs. |
| 1162 model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, | 1162 model()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES, |
| 1163 CreateInitialSyncData(), PassProcessor(), | 1163 CreateInitialSyncData(), PassProcessor(), |
| 1164 CreateAndPassSyncErrorFactory()); | 1164 CreateAndPassSyncErrorFactory()); |
| 1165 | 1165 |
| 1166 // Add a new search engine. | 1166 // Add a new search engine. |
| 1167 TemplateURL* new_turl = | 1167 TemplateURL* new_turl = |
| 1168 CreateTestTemplateURL(ASCIIToUTF16("baidu"), "http://baidu.cn", "new"); | 1168 CreateTestTemplateURL(ASCIIToUTF16("baidu"), "http://baidu.cn", "new"); |
| 1169 model()->Add(new_turl); | 1169 model()->Add(new_turl); |
| 1170 EXPECT_EQ(1U, processor()->change_list_size()); | 1170 EXPECT_EQ(1U, processor()->change_list_size()); |
| 1171 ASSERT_TRUE(processor()->contains_guid("new")); | 1171 ASSERT_TRUE(processor()->contains_guid("new")); |
| 1172 syncer::SyncChange change = processor()->change_for_guid("new"); | 1172 syncer::SyncChange change = processor()->change_for_guid("new"); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1187 // Remove an existing search engine. | 1187 // Remove an existing search engine. |
| 1188 existing_turl = model()->GetTemplateURLForGUID("key2"); | 1188 existing_turl = model()->GetTemplateURLForGUID("key2"); |
| 1189 model()->Remove(existing_turl); | 1189 model()->Remove(existing_turl); |
| 1190 EXPECT_EQ(1U, processor()->change_list_size()); | 1190 EXPECT_EQ(1U, processor()->change_list_size()); |
| 1191 ASSERT_TRUE(processor()->contains_guid("key2")); | 1191 ASSERT_TRUE(processor()->contains_guid("key2")); |
| 1192 change = processor()->change_for_guid("key2"); | 1192 change = processor()->change_for_guid("key2"); |
| 1193 EXPECT_EQ(syncer::SyncChange::ACTION_DELETE, change.change_type()); | 1193 EXPECT_EQ(syncer::SyncChange::ACTION_DELETE, change.change_type()); |
| 1194 } | 1194 } |
| 1195 | 1195 |
| 1196 TEST_F(TemplateURLServiceSyncTest, ProcessChangesWithLocalExtensions) { | 1196 TEST_F(TemplateURLServiceSyncTest, ProcessChangesWithLocalExtensions) { |
| 1197 model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, | 1197 model()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES, |
| 1198 CreateInitialSyncData(), PassProcessor(), | 1198 CreateInitialSyncData(), PassProcessor(), |
| 1199 CreateAndPassSyncErrorFactory()); | 1199 CreateAndPassSyncErrorFactory()); |
| 1200 | 1200 |
| 1201 // Add some extension keywords locally. These shouldn't be synced. | 1201 // Add some extension keywords locally. These shouldn't be synced. |
| 1202 TemplateURL* extension1 = CreateTestTemplateURL(ASCIIToUTF16("keyword1"), | 1202 TemplateURL* extension1 = CreateTestTemplateURL(ASCIIToUTF16("keyword1"), |
| 1203 std::string(chrome::kExtensionScheme) + "://extension1"); | 1203 std::string(chrome::kExtensionScheme) + "://extension1"); |
| 1204 model()->Add(extension1); | 1204 model()->Add(extension1); |
| 1205 TemplateURL* extension2 = CreateTestTemplateURL(ASCIIToUTF16("keyword2"), | 1205 TemplateURL* extension2 = CreateTestTemplateURL(ASCIIToUTF16("keyword2"), |
| 1206 std::string(chrome::kExtensionScheme) + "://extension2"); | 1206 std::string(chrome::kExtensionScheme) + "://extension2"); |
| 1207 model()->Add(extension2); | 1207 model()->Add(extension2); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1243 scoped_ptr<TemplateURL> turl( | 1243 scoped_ptr<TemplateURL> turl( |
| 1244 CreateTestTemplateURL(ASCIIToUTF16("key1"), "http://key1.com", "key1")); | 1244 CreateTestTemplateURL(ASCIIToUTF16("key1"), "http://key1.com", "key1")); |
| 1245 initial_data.push_back( | 1245 initial_data.push_back( |
| 1246 CreateCustomSyncData(*turl, true, turl->url(), turl->sync_guid())); | 1246 CreateCustomSyncData(*turl, true, turl->url(), turl->sync_guid())); |
| 1247 turl.reset(CreateTestTemplateURL(ASCIIToUTF16("key2"), | 1247 turl.reset(CreateTestTemplateURL(ASCIIToUTF16("key2"), |
| 1248 "{google:baseURL}search?q={searchTerms}", "key2")); | 1248 "{google:baseURL}search?q={searchTerms}", "key2")); |
| 1249 initial_data.push_back( | 1249 initial_data.push_back( |
| 1250 CreateCustomSyncData(*turl, true, turl->url(), turl->sync_guid())); | 1250 CreateCustomSyncData(*turl, true, turl->url(), turl->sync_guid())); |
| 1251 | 1251 |
| 1252 // Now try to sync the data locally. | 1252 // Now try to sync the data locally. |
| 1253 model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, initial_data, | 1253 model()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES, initial_data, |
| 1254 PassProcessor(), CreateAndPassSyncErrorFactory()); | 1254 PassProcessor(), CreateAndPassSyncErrorFactory()); |
| 1255 | 1255 |
| 1256 // Both entries should have been added, with explicit keywords. | 1256 // Both entries should have been added, with explicit keywords. |
| 1257 TemplateURL* key1 = model()->GetTemplateURLForHost("key1.com"); | 1257 TemplateURL* key1 = model()->GetTemplateURLForHost("key1.com"); |
| 1258 ASSERT_FALSE(key1 == NULL); | 1258 ASSERT_FALSE(key1 == NULL); |
| 1259 EXPECT_EQ(ASCIIToUTF16("key1.com"), key1->keyword()); | 1259 EXPECT_EQ(ASCIIToUTF16("key1.com"), key1->keyword()); |
| 1260 std::string google_hostname( | 1260 std::string google_hostname( |
| 1261 GURL(UIThreadSearchTermsData(profile_a()).GoogleBaseURLValue()).host()); | 1261 GURL(UIThreadSearchTermsData(profile_a()).GoogleBaseURLValue()).host()); |
| 1262 TemplateURL* key2 = model()->GetTemplateURLForHost(google_hostname); | 1262 TemplateURL* key2 = model()->GetTemplateURLForHost(google_hostname); |
| 1263 ASSERT_FALSE(key2 == NULL); | 1263 ASSERT_FALSE(key2 == NULL); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 1289 model()->Add(other); | 1289 model()->Add(other); |
| 1290 syncer::SyncDataList initial_data; | 1290 syncer::SyncDataList initial_data; |
| 1291 scoped_ptr<TemplateURL> turl(CreateTestTemplateURL(ASCIIToUTF16("sync1"), | 1291 scoped_ptr<TemplateURL> turl(CreateTestTemplateURL(ASCIIToUTF16("sync1"), |
| 1292 "{google:baseURL}2/search?q={searchTerms}", "sync1", 50)); | 1292 "{google:baseURL}2/search?q={searchTerms}", "sync1", 50)); |
| 1293 initial_data.push_back( | 1293 initial_data.push_back( |
| 1294 CreateCustomSyncData(*turl, true, turl->url(), turl->sync_guid())); | 1294 CreateCustomSyncData(*turl, true, turl->url(), turl->sync_guid())); |
| 1295 turl.reset(CreateTestTemplateURL(ASCIIToUTF16("sync2"), | 1295 turl.reset(CreateTestTemplateURL(ASCIIToUTF16("sync2"), |
| 1296 "http://other.com/search?q={searchTerms}", "sync2", 150)); | 1296 "http://other.com/search?q={searchTerms}", "sync2", 150)); |
| 1297 initial_data.push_back( | 1297 initial_data.push_back( |
| 1298 CreateCustomSyncData(*turl, true, turl->url(), turl->sync_guid())); | 1298 CreateCustomSyncData(*turl, true, turl->url(), turl->sync_guid())); |
| 1299 model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, initial_data, | 1299 model()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES, initial_data, |
| 1300 PassProcessor(), CreateAndPassSyncErrorFactory()); | 1300 PassProcessor(), CreateAndPassSyncErrorFactory()); |
| 1301 | 1301 |
| 1302 // In this case, the conflicts should be handled just like any other keyword | 1302 // In this case, the conflicts should be handled just like any other keyword |
| 1303 // conflicts -- the later-modified TemplateURL is assumed to be authoritative. | 1303 // conflicts -- the later-modified TemplateURL is assumed to be authoritative. |
| 1304 EXPECT_EQ(google_keyword, google->keyword()); | 1304 EXPECT_EQ(google_keyword, google->keyword()); |
| 1305 EXPECT_EQ(google_keyword + ASCIIToUTF16("_"), | 1305 EXPECT_EQ(google_keyword + ASCIIToUTF16("_"), |
| 1306 model()->GetTemplateURLForGUID("sync1")->keyword()); | 1306 model()->GetTemplateURLForGUID("sync1")->keyword()); |
| 1307 EXPECT_EQ(ASCIIToUTF16("other.com_"), other->keyword()); | 1307 EXPECT_EQ(ASCIIToUTF16("other.com_"), other->keyword()); |
| 1308 EXPECT_EQ(ASCIIToUTF16("other.com"), | 1308 EXPECT_EQ(ASCIIToUTF16("other.com"), |
| 1309 model()->GetTemplateURLForGUID("sync2")->keyword()); | 1309 model()->GetTemplateURLForGUID("sync2")->keyword()); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1328 // and then again once after (when we resolve conflicts for the second). | 1328 // and then again once after (when we resolve conflicts for the second). |
| 1329 syncer::SyncDataList initial_data; | 1329 syncer::SyncDataList initial_data; |
| 1330 scoped_ptr<TemplateURL> turl(CreateTestTemplateURL(ASCIIToUTF16("key1"), | 1330 scoped_ptr<TemplateURL> turl(CreateTestTemplateURL(ASCIIToUTF16("key1"), |
| 1331 "{google:baseURL}1/search?q={searchTerms}", "key1", 50)); | 1331 "{google:baseURL}1/search?q={searchTerms}", "key1", 50)); |
| 1332 initial_data.push_back( | 1332 initial_data.push_back( |
| 1333 CreateCustomSyncData(*turl, true, turl->url(), turl->sync_guid())); | 1333 CreateCustomSyncData(*turl, true, turl->url(), turl->sync_guid())); |
| 1334 turl.reset(CreateTestTemplateURL(ASCIIToUTF16("key2"), | 1334 turl.reset(CreateTestTemplateURL(ASCIIToUTF16("key2"), |
| 1335 "{google:baseURL}2/search?q={searchTerms}", "key2")); | 1335 "{google:baseURL}2/search?q={searchTerms}", "key2")); |
| 1336 initial_data.push_back( | 1336 initial_data.push_back( |
| 1337 CreateCustomSyncData(*turl, true, turl->url(), turl->sync_guid())); | 1337 CreateCustomSyncData(*turl, true, turl->url(), turl->sync_guid())); |
| 1338 model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, initial_data, | 1338 model()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES, initial_data, |
| 1339 PassProcessor(), CreateAndPassSyncErrorFactory()); | 1339 PassProcessor(), CreateAndPassSyncErrorFactory()); |
| 1340 | 1340 |
| 1341 // We should still have coalesced the updates to one each. | 1341 // We should still have coalesced the updates to one each. |
| 1342 string16 google_keyword(net::StripWWW(ASCIIToUTF16(GURL( | 1342 string16 google_keyword(net::StripWWW(ASCIIToUTF16(GURL( |
| 1343 UIThreadSearchTermsData(profile_a()).GoogleBaseURLValue()).host()))); | 1343 UIThreadSearchTermsData(profile_a()).GoogleBaseURLValue()).host()))); |
| 1344 TemplateURL* keyword1 = | 1344 TemplateURL* keyword1 = |
| 1345 model()->GetTemplateURLForKeyword(google_keyword + ASCIIToUTF16("_")); | 1345 model()->GetTemplateURLForKeyword(google_keyword + ASCIIToUTF16("_")); |
| 1346 ASSERT_FALSE(keyword1 == NULL); | 1346 ASSERT_FALSE(keyword1 == NULL); |
| 1347 EXPECT_EQ("key1", keyword1->sync_guid()); | 1347 EXPECT_EQ("key1", keyword1->sync_guid()); |
| 1348 TemplateURL* keyword2 = model()->GetTemplateURLForKeyword(google_keyword); | 1348 TemplateURL* keyword2 = model()->GetTemplateURLForKeyword(google_keyword); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 1378 data.input_encodings.push_back("Big5"); | 1378 data.input_encodings.push_back("Big5"); |
| 1379 data.input_encodings.push_back("Windows-1252"); | 1379 data.input_encodings.push_back("Windows-1252"); |
| 1380 data.date_created = Time::FromTimeT(100); | 1380 data.date_created = Time::FromTimeT(100); |
| 1381 data.last_modified = Time::FromTimeT(100); | 1381 data.last_modified = Time::FromTimeT(100); |
| 1382 data.sync_guid = "keyword"; | 1382 data.sync_guid = "keyword"; |
| 1383 scoped_ptr<TemplateURL> turl(new TemplateURL(NULL, data)); | 1383 scoped_ptr<TemplateURL> turl(new TemplateURL(NULL, data)); |
| 1384 initial_data.push_back( | 1384 initial_data.push_back( |
| 1385 TemplateURLService::CreateSyncDataFromTemplateURL(*turl)); | 1385 TemplateURLService::CreateSyncDataFromTemplateURL(*turl)); |
| 1386 | 1386 |
| 1387 // Now try to sync the data locally. | 1387 // Now try to sync the data locally. |
| 1388 model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, initial_data, | 1388 model()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES, initial_data, |
| 1389 PassProcessor(), CreateAndPassSyncErrorFactory()); | 1389 PassProcessor(), CreateAndPassSyncErrorFactory()); |
| 1390 | 1390 |
| 1391 // The entry should have been added, with duplicate encodings removed. | 1391 // The entry should have been added, with duplicate encodings removed. |
| 1392 TemplateURL* keyword = | 1392 TemplateURL* keyword = |
| 1393 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword")); | 1393 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword")); |
| 1394 ASSERT_FALSE(keyword == NULL); | 1394 ASSERT_FALSE(keyword == NULL); |
| 1395 EXPECT_EQ(4U, keyword->input_encodings().size()); | 1395 EXPECT_EQ(4U, keyword->input_encodings().size()); |
| 1396 | 1396 |
| 1397 // We should also have gotten a corresponding UPDATE pushed upstream. | 1397 // We should also have gotten a corresponding UPDATE pushed upstream. |
| 1398 EXPECT_GE(processor()->change_list_size(), 1U); | 1398 EXPECT_GE(processor()->change_list_size(), 1U); |
| 1399 ASSERT_TRUE(processor()->contains_guid("keyword")); | 1399 ASSERT_TRUE(processor()->contains_guid("keyword")); |
| 1400 syncer::SyncChange keyword_change = processor()->change_for_guid("keyword"); | 1400 syncer::SyncChange keyword_change = processor()->change_for_guid("keyword"); |
| 1401 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, keyword_change.change_type()); | 1401 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, keyword_change.change_type()); |
| 1402 EXPECT_EQ("UTF-8;UTF-16;Big5;Windows-1252", keyword_change.sync_data(). | 1402 EXPECT_EQ("UTF-8;UTF-16;Big5;Windows-1252", keyword_change.sync_data(). |
| 1403 GetSpecifics().search_engine().input_encodings()); | 1403 GetSpecifics().search_engine().input_encodings()); |
| 1404 } | 1404 } |
| 1405 | 1405 |
| 1406 TEST_F(TemplateURLServiceSyncTest, MergeTwoClientsBasic) { | 1406 TEST_F(TemplateURLServiceSyncTest, MergeTwoClientsBasic) { |
| 1407 // Start off B with some empty data. | 1407 // Start off B with some empty data. |
| 1408 model_b()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, | 1408 model_b()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES, |
| 1409 CreateInitialSyncData(), PassProcessor(), | 1409 CreateInitialSyncData(), PassProcessor(), |
| 1410 CreateAndPassSyncErrorFactory()); | 1410 CreateAndPassSyncErrorFactory()); |
| 1411 | 1411 |
| 1412 // Merge A and B. All of B's data should transfer over to A, which initially | 1412 // Merge A and B. All of B's data should transfer over to A, which initially |
| 1413 // has no data. | 1413 // has no data. |
| 1414 scoped_ptr<SyncChangeProcessorDelegate> delegate_b( | 1414 scoped_ptr<SyncChangeProcessorDelegate> delegate_b( |
| 1415 new SyncChangeProcessorDelegate(model_b())); | 1415 new SyncChangeProcessorDelegate(model_b())); |
| 1416 model_a()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, | 1416 model_a()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES, |
| 1417 model_b()->GetAllSyncData(syncable::SEARCH_ENGINES), | 1417 model_b()->GetAllSyncData(syncer::SEARCH_ENGINES), |
| 1418 delegate_b.PassAs<syncer::SyncChangeProcessor>(), | 1418 delegate_b.PassAs<syncer::SyncChangeProcessor>(), |
| 1419 CreateAndPassSyncErrorFactory()); | 1419 CreateAndPassSyncErrorFactory()); |
| 1420 | 1420 |
| 1421 // They should be consistent. | 1421 // They should be consistent. |
| 1422 AssertEquals(model_a()->GetAllSyncData(syncable::SEARCH_ENGINES), | 1422 AssertEquals(model_a()->GetAllSyncData(syncer::SEARCH_ENGINES), |
| 1423 model_b()->GetAllSyncData(syncable::SEARCH_ENGINES)); | 1423 model_b()->GetAllSyncData(syncer::SEARCH_ENGINES)); |
| 1424 } | 1424 } |
| 1425 | 1425 |
| 1426 TEST_F(TemplateURLServiceSyncTest, MergeTwoClientsDupesAndConflicts) { | 1426 TEST_F(TemplateURLServiceSyncTest, MergeTwoClientsDupesAndConflicts) { |
| 1427 // Start off B with some empty data. | 1427 // Start off B with some empty data. |
| 1428 model_b()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, | 1428 model_b()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES, |
| 1429 CreateInitialSyncData(), PassProcessor(), | 1429 CreateInitialSyncData(), PassProcessor(), |
| 1430 CreateAndPassSyncErrorFactory()); | 1430 CreateAndPassSyncErrorFactory()); |
| 1431 | 1431 |
| 1432 // Set up A so we have some interesting duplicates and conflicts. | 1432 // Set up A so we have some interesting duplicates and conflicts. |
| 1433 model_a()->Add(CreateTestTemplateURL(ASCIIToUTF16("key4"), "http://key4.com", | 1433 model_a()->Add(CreateTestTemplateURL(ASCIIToUTF16("key4"), "http://key4.com", |
| 1434 "key4")); // Added | 1434 "key4")); // Added |
| 1435 model_a()->Add(CreateTestTemplateURL(ASCIIToUTF16("key2"), "http://key2.com", | 1435 model_a()->Add(CreateTestTemplateURL(ASCIIToUTF16("key2"), "http://key2.com", |
| 1436 "key2")); // Merge - Copy of key2. | 1436 "key2")); // Merge - Copy of key2. |
| 1437 model_a()->Add(CreateTestTemplateURL(ASCIIToUTF16("key3"), "http://key3.com", | 1437 model_a()->Add(CreateTestTemplateURL(ASCIIToUTF16("key3"), "http://key3.com", |
| 1438 "key5", 10)); // Merge - Dupe of key3. | 1438 "key5", 10)); // Merge - Dupe of key3. |
| 1439 model_a()->Add(CreateTestTemplateURL(ASCIIToUTF16("key1"), "http://key6.com", | 1439 model_a()->Add(CreateTestTemplateURL(ASCIIToUTF16("key1"), "http://key6.com", |
| 1440 "key6", 10)); // Conflict with key1 | 1440 "key6", 10)); // Conflict with key1 |
| 1441 | 1441 |
| 1442 // Merge A and B. | 1442 // Merge A and B. |
| 1443 scoped_ptr<SyncChangeProcessorDelegate> delegate_b( | 1443 scoped_ptr<SyncChangeProcessorDelegate> delegate_b( |
| 1444 new SyncChangeProcessorDelegate(model_b())); | 1444 new SyncChangeProcessorDelegate(model_b())); |
| 1445 model_a()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, | 1445 model_a()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES, |
| 1446 model_b()->GetAllSyncData(syncable::SEARCH_ENGINES), | 1446 model_b()->GetAllSyncData(syncer::SEARCH_ENGINES), |
| 1447 delegate_b.PassAs<syncer::SyncChangeProcessor>(), | 1447 delegate_b.PassAs<syncer::SyncChangeProcessor>(), |
| 1448 CreateAndPassSyncErrorFactory()); | 1448 CreateAndPassSyncErrorFactory()); |
| 1449 | 1449 |
| 1450 // They should be consistent. | 1450 // They should be consistent. |
| 1451 AssertEquals(model_a()->GetAllSyncData(syncable::SEARCH_ENGINES), | 1451 AssertEquals(model_a()->GetAllSyncData(syncer::SEARCH_ENGINES), |
| 1452 model_b()->GetAllSyncData(syncable::SEARCH_ENGINES)); | 1452 model_b()->GetAllSyncData(syncer::SEARCH_ENGINES)); |
| 1453 } | 1453 } |
| 1454 | 1454 |
| 1455 TEST_F(TemplateURLServiceSyncTest, StopSyncing) { | 1455 TEST_F(TemplateURLServiceSyncTest, StopSyncing) { |
| 1456 syncer::SyncError error = | 1456 syncer::SyncError error = |
| 1457 model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, | 1457 model()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES, |
| 1458 CreateInitialSyncData(), PassProcessor(), | 1458 CreateInitialSyncData(), PassProcessor(), |
| 1459 CreateAndPassSyncErrorFactory()); | 1459 CreateAndPassSyncErrorFactory()); |
| 1460 ASSERT_FALSE(error.IsSet()); | 1460 ASSERT_FALSE(error.IsSet()); |
| 1461 model()->StopSyncing(syncable::SEARCH_ENGINES); | 1461 model()->StopSyncing(syncer::SEARCH_ENGINES); |
| 1462 | 1462 |
| 1463 syncer::SyncChangeList changes; | 1463 syncer::SyncChangeList changes; |
| 1464 changes.push_back(CreateTestSyncChange(syncer::SyncChange::ACTION_UPDATE, | 1464 changes.push_back(CreateTestSyncChange(syncer::SyncChange::ACTION_UPDATE, |
| 1465 CreateTestTemplateURL(ASCIIToUTF16("newkeyword"), "http://new.com", | 1465 CreateTestTemplateURL(ASCIIToUTF16("newkeyword"), "http://new.com", |
| 1466 "key2"))); | 1466 "key2"))); |
| 1467 error = model()->ProcessSyncChanges(FROM_HERE, changes); | 1467 error = model()->ProcessSyncChanges(FROM_HERE, changes); |
| 1468 EXPECT_TRUE(error.IsSet()); | 1468 EXPECT_TRUE(error.IsSet()); |
| 1469 | 1469 |
| 1470 // Ensure that the sync changes were not accepted. | 1470 // Ensure that the sync changes were not accepted. |
| 1471 EXPECT_TRUE(model()->GetTemplateURLForGUID("key2")); | 1471 EXPECT_TRUE(model()->GetTemplateURLForGUID("key2")); |
| 1472 EXPECT_FALSE(model()->GetTemplateURLForKeyword(ASCIIToUTF16("newkeyword"))); | 1472 EXPECT_FALSE(model()->GetTemplateURLForKeyword(ASCIIToUTF16("newkeyword"))); |
| 1473 } | 1473 } |
| 1474 | 1474 |
| 1475 TEST_F(TemplateURLServiceSyncTest, SyncErrorOnInitialSync) { | 1475 TEST_F(TemplateURLServiceSyncTest, SyncErrorOnInitialSync) { |
| 1476 processor()->set_erroneous(true); | 1476 processor()->set_erroneous(true); |
| 1477 syncer::SyncError error = | 1477 syncer::SyncError error = |
| 1478 model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, | 1478 model()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES, |
| 1479 CreateInitialSyncData(), PassProcessor(), | 1479 CreateInitialSyncData(), PassProcessor(), |
| 1480 CreateAndPassSyncErrorFactory()); | 1480 CreateAndPassSyncErrorFactory()); |
| 1481 EXPECT_TRUE(error.IsSet()); | 1481 EXPECT_TRUE(error.IsSet()); |
| 1482 | 1482 |
| 1483 // Ensure that if the initial merge was erroneous, then subsequence attempts | 1483 // Ensure that if the initial merge was erroneous, then subsequence attempts |
| 1484 // to push data into the local model are rejected, since the model was never | 1484 // to push data into the local model are rejected, since the model was never |
| 1485 // successfully associated with Sync in the first place. | 1485 // successfully associated with Sync in the first place. |
| 1486 syncer::SyncChangeList changes; | 1486 syncer::SyncChangeList changes; |
| 1487 changes.push_back(CreateTestSyncChange(syncer::SyncChange::ACTION_UPDATE, | 1487 changes.push_back(CreateTestSyncChange(syncer::SyncChange::ACTION_UPDATE, |
| 1488 CreateTestTemplateURL(ASCIIToUTF16("newkeyword"), "http://new.com", | 1488 CreateTestTemplateURL(ASCIIToUTF16("newkeyword"), "http://new.com", |
| 1489 "key2"))); | 1489 "key2"))); |
| 1490 processor()->set_erroneous(false); | 1490 processor()->set_erroneous(false); |
| 1491 error = model()->ProcessSyncChanges(FROM_HERE, changes); | 1491 error = model()->ProcessSyncChanges(FROM_HERE, changes); |
| 1492 EXPECT_TRUE(error.IsSet()); | 1492 EXPECT_TRUE(error.IsSet()); |
| 1493 | 1493 |
| 1494 // Ensure that the sync changes were not accepted. | 1494 // Ensure that the sync changes were not accepted. |
| 1495 EXPECT_TRUE(model()->GetTemplateURLForGUID("key2")); | 1495 EXPECT_TRUE(model()->GetTemplateURLForGUID("key2")); |
| 1496 EXPECT_FALSE(model()->GetTemplateURLForKeyword(ASCIIToUTF16("newkeyword"))); | 1496 EXPECT_FALSE(model()->GetTemplateURLForKeyword(ASCIIToUTF16("newkeyword"))); |
| 1497 } | 1497 } |
| 1498 | 1498 |
| 1499 TEST_F(TemplateURLServiceSyncTest, SyncErrorOnLaterSync) { | 1499 TEST_F(TemplateURLServiceSyncTest, SyncErrorOnLaterSync) { |
| 1500 // Ensure that if the SyncProcessor succeeds in the initial merge, but fails | 1500 // Ensure that if the SyncProcessor succeeds in the initial merge, but fails |
| 1501 // in future ProcessSyncChanges, we still return an error. | 1501 // in future ProcessSyncChanges, we still return an error. |
| 1502 syncer::SyncError error = | 1502 syncer::SyncError error = |
| 1503 model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, | 1503 model()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES, |
| 1504 CreateInitialSyncData(), PassProcessor(), | 1504 CreateInitialSyncData(), PassProcessor(), |
| 1505 CreateAndPassSyncErrorFactory()); | 1505 CreateAndPassSyncErrorFactory()); |
| 1506 ASSERT_FALSE(error.IsSet()); | 1506 ASSERT_FALSE(error.IsSet()); |
| 1507 | 1507 |
| 1508 syncer::SyncChangeList changes; | 1508 syncer::SyncChangeList changes; |
| 1509 changes.push_back(CreateTestSyncChange(syncer::SyncChange::ACTION_UPDATE, | 1509 changes.push_back(CreateTestSyncChange(syncer::SyncChange::ACTION_UPDATE, |
| 1510 CreateTestTemplateURL(ASCIIToUTF16("newkeyword"), "http://new.com", | 1510 CreateTestTemplateURL(ASCIIToUTF16("newkeyword"), "http://new.com", |
| 1511 "key2"))); | 1511 "key2"))); |
| 1512 processor()->set_erroneous(true); | 1512 processor()->set_erroneous(true); |
| 1513 error = model()->ProcessSyncChanges(FROM_HERE, changes); | 1513 error = model()->ProcessSyncChanges(FROM_HERE, changes); |
| 1514 EXPECT_TRUE(error.IsSet()); | 1514 EXPECT_TRUE(error.IsSet()); |
| 1515 } | 1515 } |
| 1516 | 1516 |
| 1517 TEST_F(TemplateURLServiceSyncTest, MergeTwiceWithSameSyncData) { | 1517 TEST_F(TemplateURLServiceSyncTest, MergeTwiceWithSameSyncData) { |
| 1518 // Ensure that a second merge with the same data as the first does not | 1518 // Ensure that a second merge with the same data as the first does not |
| 1519 // actually update the local data. | 1519 // actually update the local data. |
| 1520 syncer::SyncDataList initial_data; | 1520 syncer::SyncDataList initial_data; |
| 1521 initial_data.push_back(CreateInitialSyncData()[0]); | 1521 initial_data.push_back(CreateInitialSyncData()[0]); |
| 1522 | 1522 |
| 1523 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("key1"), "http://key1.com", | 1523 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("key1"), "http://key1.com", |
| 1524 "key1", 10)); // earlier | 1524 "key1", 10)); // earlier |
| 1525 | 1525 |
| 1526 syncer::SyncError error = | 1526 syncer::SyncError error = |
| 1527 model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, | 1527 model()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES, |
| 1528 initial_data, PassProcessor(), CreateAndPassSyncErrorFactory()); | 1528 initial_data, PassProcessor(), CreateAndPassSyncErrorFactory()); |
| 1529 ASSERT_FALSE(error.IsSet()); | 1529 ASSERT_FALSE(error.IsSet()); |
| 1530 | 1530 |
| 1531 // We should have updated the original TemplateURL with Sync's version. | 1531 // We should have updated the original TemplateURL with Sync's version. |
| 1532 // Keep a copy of it so we can compare it after we re-merge. | 1532 // Keep a copy of it so we can compare it after we re-merge. |
| 1533 TemplateURL* key1_url = model()->GetTemplateURLForGUID("key1"); | 1533 TemplateURL* key1_url = model()->GetTemplateURLForGUID("key1"); |
| 1534 ASSERT_TRUE(key1_url); | 1534 ASSERT_TRUE(key1_url); |
| 1535 scoped_ptr<TemplateURL> updated_turl(new TemplateURL(key1_url->profile(), | 1535 scoped_ptr<TemplateURL> updated_turl(new TemplateURL(key1_url->profile(), |
| 1536 key1_url->data())); | 1536 key1_url->data())); |
| 1537 EXPECT_EQ(Time::FromTimeT(90), updated_turl->last_modified()); | 1537 EXPECT_EQ(Time::FromTimeT(90), updated_turl->last_modified()); |
| 1538 | 1538 |
| 1539 // Modify a single field of the initial data. This should not be updated in | 1539 // Modify a single field of the initial data. This should not be updated in |
| 1540 // the second merge, as the last_modified timestamp remains the same. | 1540 // the second merge, as the last_modified timestamp remains the same. |
| 1541 scoped_ptr<TemplateURL> temp_turl(Deserialize(initial_data[0])); | 1541 scoped_ptr<TemplateURL> temp_turl(Deserialize(initial_data[0])); |
| 1542 TemplateURLData data(temp_turl->data()); | 1542 TemplateURLData data(temp_turl->data()); |
| 1543 data.short_name = ASCIIToUTF16("SomethingDifferent"); | 1543 data.short_name = ASCIIToUTF16("SomethingDifferent"); |
| 1544 temp_turl.reset(new TemplateURL(temp_turl->profile(), data)); | 1544 temp_turl.reset(new TemplateURL(temp_turl->profile(), data)); |
| 1545 initial_data.clear(); | 1545 initial_data.clear(); |
| 1546 initial_data.push_back( | 1546 initial_data.push_back( |
| 1547 TemplateURLService::CreateSyncDataFromTemplateURL(*temp_turl)); | 1547 TemplateURLService::CreateSyncDataFromTemplateURL(*temp_turl)); |
| 1548 | 1548 |
| 1549 // Remerge the data again. This simulates shutting down and syncing again | 1549 // Remerge the data again. This simulates shutting down and syncing again |
| 1550 // at a different time, but the cloud data has not changed. | 1550 // at a different time, but the cloud data has not changed. |
| 1551 model()->StopSyncing(syncable::SEARCH_ENGINES); | 1551 model()->StopSyncing(syncer::SEARCH_ENGINES); |
| 1552 sync_processor_delegate_.reset(new SyncChangeProcessorDelegate( | 1552 sync_processor_delegate_.reset(new SyncChangeProcessorDelegate( |
| 1553 sync_processor_.get())); | 1553 sync_processor_.get())); |
| 1554 error = model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, | 1554 error = model()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES, |
| 1555 initial_data, PassProcessor(), CreateAndPassSyncErrorFactory()); | 1555 initial_data, PassProcessor(), CreateAndPassSyncErrorFactory()); |
| 1556 ASSERT_FALSE(error.IsSet()); | 1556 ASSERT_FALSE(error.IsSet()); |
| 1557 | 1557 |
| 1558 // Check that the TemplateURL was not modified. | 1558 // Check that the TemplateURL was not modified. |
| 1559 const TemplateURL* reupdated_turl = model()->GetTemplateURLForGUID("key1"); | 1559 const TemplateURL* reupdated_turl = model()->GetTemplateURLForGUID("key1"); |
| 1560 ASSERT_TRUE(reupdated_turl); | 1560 ASSERT_TRUE(reupdated_turl); |
| 1561 AssertEquals(*updated_turl, *reupdated_turl); | 1561 AssertEquals(*updated_turl, *reupdated_turl); |
| 1562 } | 1562 } |
| 1563 | 1563 |
| 1564 TEST_F(TemplateURLServiceSyncTest, SyncedDefaultGUIDArrivesFirst) { | 1564 TEST_F(TemplateURLServiceSyncTest, SyncedDefaultGUIDArrivesFirst) { |
| 1565 syncer::SyncDataList initial_data = CreateInitialSyncData(); | 1565 syncer::SyncDataList initial_data = CreateInitialSyncData(); |
| 1566 // The default search provider should support replacement. | 1566 // The default search provider should support replacement. |
| 1567 scoped_ptr<TemplateURL> turl(CreateTestTemplateURL(ASCIIToUTF16("key2"), | 1567 scoped_ptr<TemplateURL> turl(CreateTestTemplateURL(ASCIIToUTF16("key2"), |
| 1568 "http://key2.com/{searchTerms}", "key2", 90)); | 1568 "http://key2.com/{searchTerms}", "key2", 90)); |
| 1569 initial_data[1] = TemplateURLService::CreateSyncDataFromTemplateURL(*turl); | 1569 initial_data[1] = TemplateURLService::CreateSyncDataFromTemplateURL(*turl); |
| 1570 model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, initial_data, | 1570 model()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES, initial_data, |
| 1571 PassProcessor(), CreateAndPassSyncErrorFactory()); | 1571 PassProcessor(), CreateAndPassSyncErrorFactory()); |
| 1572 model()->SetDefaultSearchProvider(model()->GetTemplateURLForGUID("key2")); | 1572 model()->SetDefaultSearchProvider(model()->GetTemplateURLForGUID("key2")); |
| 1573 | 1573 |
| 1574 EXPECT_EQ(3U, model()->GetAllSyncData(syncable::SEARCH_ENGINES).size()); | 1574 EXPECT_EQ(3U, model()->GetAllSyncData(syncer::SEARCH_ENGINES).size()); |
| 1575 const TemplateURL* default_search = model()->GetDefaultSearchProvider(); | 1575 const TemplateURL* default_search = model()->GetDefaultSearchProvider(); |
| 1576 ASSERT_TRUE(default_search); | 1576 ASSERT_TRUE(default_search); |
| 1577 | 1577 |
| 1578 // Change kSyncedDefaultSearchProviderGUID to a GUID that does not exist in | 1578 // Change kSyncedDefaultSearchProviderGUID to a GUID that does not exist in |
| 1579 // the model yet. Ensure that the default has not changed in any way. | 1579 // the model yet. Ensure that the default has not changed in any way. |
| 1580 profile_a()->GetTestingPrefService()->SetString( | 1580 profile_a()->GetTestingPrefService()->SetString( |
| 1581 prefs::kSyncedDefaultSearchProviderGUID, "newdefault"); | 1581 prefs::kSyncedDefaultSearchProviderGUID, "newdefault"); |
| 1582 | 1582 |
| 1583 ASSERT_EQ(default_search, model()->GetDefaultSearchProvider()); | 1583 ASSERT_EQ(default_search, model()->GetDefaultSearchProvider()); |
| 1584 | 1584 |
| 1585 // Bring in a random new search engine with a different GUID. Ensure that | 1585 // Bring in a random new search engine with a different GUID. Ensure that |
| 1586 // it doesn't change the default. | 1586 // it doesn't change the default. |
| 1587 syncer::SyncChangeList changes1; | 1587 syncer::SyncChangeList changes1; |
| 1588 changes1.push_back(CreateTestSyncChange(syncer::SyncChange::ACTION_ADD, | 1588 changes1.push_back(CreateTestSyncChange(syncer::SyncChange::ACTION_ADD, |
| 1589 CreateTestTemplateURL(ASCIIToUTF16("random"), "http://random.com", | 1589 CreateTestTemplateURL(ASCIIToUTF16("random"), "http://random.com", |
| 1590 "random"))); | 1590 "random"))); |
| 1591 model()->ProcessSyncChanges(FROM_HERE, changes1); | 1591 model()->ProcessSyncChanges(FROM_HERE, changes1); |
| 1592 | 1592 |
| 1593 EXPECT_EQ(4U, model()->GetAllSyncData(syncable::SEARCH_ENGINES).size()); | 1593 EXPECT_EQ(4U, model()->GetAllSyncData(syncer::SEARCH_ENGINES).size()); |
| 1594 ASSERT_EQ(default_search, model()->GetDefaultSearchProvider()); | 1594 ASSERT_EQ(default_search, model()->GetDefaultSearchProvider()); |
| 1595 | 1595 |
| 1596 // Finally, bring in the expected entry with the right GUID. Ensure that | 1596 // Finally, bring in the expected entry with the right GUID. Ensure that |
| 1597 // the default has changed to the new search engine. | 1597 // the default has changed to the new search engine. |
| 1598 syncer::SyncChangeList changes2; | 1598 syncer::SyncChangeList changes2; |
| 1599 changes2.push_back(CreateTestSyncChange(syncer::SyncChange::ACTION_ADD, | 1599 changes2.push_back(CreateTestSyncChange(syncer::SyncChange::ACTION_ADD, |
| 1600 CreateTestTemplateURL(ASCIIToUTF16("new"), "http://new.com/{searchTerms}", | 1600 CreateTestTemplateURL(ASCIIToUTF16("new"), "http://new.com/{searchTerms}", |
| 1601 "newdefault"))); | 1601 "newdefault"))); |
| 1602 model()->ProcessSyncChanges(FROM_HERE, changes2); | 1602 model()->ProcessSyncChanges(FROM_HERE, changes2); |
| 1603 | 1603 |
| 1604 EXPECT_EQ(5U, model()->GetAllSyncData(syncable::SEARCH_ENGINES).size()); | 1604 EXPECT_EQ(5U, model()->GetAllSyncData(syncer::SEARCH_ENGINES).size()); |
| 1605 ASSERT_NE(default_search, model()->GetDefaultSearchProvider()); | 1605 ASSERT_NE(default_search, model()->GetDefaultSearchProvider()); |
| 1606 ASSERT_EQ("newdefault", model()->GetDefaultSearchProvider()->sync_guid()); | 1606 ASSERT_EQ("newdefault", model()->GetDefaultSearchProvider()->sync_guid()); |
| 1607 } | 1607 } |
| 1608 | 1608 |
| 1609 TEST_F(TemplateURLServiceSyncTest, DefaultGuidDeletedAndReplaced) { | 1609 TEST_F(TemplateURLServiceSyncTest, DefaultGuidDeletedAndReplaced) { |
| 1610 syncer::SyncDataList initial_data; | 1610 syncer::SyncDataList initial_data; |
| 1611 // The default search provider should support replacement. | 1611 // The default search provider should support replacement. |
| 1612 scoped_ptr<TemplateURL> turl1(CreateTestTemplateURL(ASCIIToUTF16("key1"), | 1612 scoped_ptr<TemplateURL> turl1(CreateTestTemplateURL(ASCIIToUTF16("key1"), |
| 1613 "http://key1.com/{searchTerms}", "key1", 90)); | 1613 "http://key1.com/{searchTerms}", "key1", 90)); |
| 1614 // Create a second default search provider for the | 1614 // Create a second default search provider for the |
| 1615 // FindNewDefaultSearchProvider method to find. | 1615 // FindNewDefaultSearchProvider method to find. |
| 1616 TemplateURLData data; | 1616 TemplateURLData data; |
| 1617 data.short_name = ASCIIToUTF16("unittest"); | 1617 data.short_name = ASCIIToUTF16("unittest"); |
| 1618 data.SetKeyword(ASCIIToUTF16("key2")); | 1618 data.SetKeyword(ASCIIToUTF16("key2")); |
| 1619 data.SetURL("http://key2.com/{searchTerms}"); | 1619 data.SetURL("http://key2.com/{searchTerms}"); |
| 1620 data.favicon_url = GURL("http://favicon.url"); | 1620 data.favicon_url = GURL("http://favicon.url"); |
| 1621 data.safe_for_autoreplace = false; | 1621 data.safe_for_autoreplace = false; |
| 1622 data.date_created = Time::FromTimeT(100); | 1622 data.date_created = Time::FromTimeT(100); |
| 1623 data.last_modified = Time::FromTimeT(100); | 1623 data.last_modified = Time::FromTimeT(100); |
| 1624 data.created_by_policy = false; | 1624 data.created_by_policy = false; |
| 1625 data.prepopulate_id = 999999; | 1625 data.prepopulate_id = 999999; |
| 1626 data.sync_guid = "key2"; | 1626 data.sync_guid = "key2"; |
| 1627 data.show_in_default_list = true; | 1627 data.show_in_default_list = true; |
| 1628 scoped_ptr<TemplateURL> turl2(new TemplateURL(NULL, data)); | 1628 scoped_ptr<TemplateURL> turl2(new TemplateURL(NULL, data)); |
| 1629 initial_data.push_back(TemplateURLService::CreateSyncDataFromTemplateURL( | 1629 initial_data.push_back(TemplateURLService::CreateSyncDataFromTemplateURL( |
| 1630 *turl1)); | 1630 *turl1)); |
| 1631 initial_data.push_back(TemplateURLService::CreateSyncDataFromTemplateURL( | 1631 initial_data.push_back(TemplateURLService::CreateSyncDataFromTemplateURL( |
| 1632 *turl2)); | 1632 *turl2)); |
| 1633 model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, initial_data, | 1633 model()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES, initial_data, |
| 1634 PassProcessor(), CreateAndPassSyncErrorFactory()); | 1634 PassProcessor(), CreateAndPassSyncErrorFactory()); |
| 1635 model()->SetDefaultSearchProvider(model()->GetTemplateURLForGUID("key1")); | 1635 model()->SetDefaultSearchProvider(model()->GetTemplateURLForGUID("key1")); |
| 1636 ASSERT_EQ("key1", model()->GetDefaultSearchProvider()->sync_guid()); | 1636 ASSERT_EQ("key1", model()->GetDefaultSearchProvider()->sync_guid()); |
| 1637 | 1637 |
| 1638 EXPECT_EQ(2U, model()->GetAllSyncData(syncable::SEARCH_ENGINES).size()); | 1638 EXPECT_EQ(2U, model()->GetAllSyncData(syncer::SEARCH_ENGINES).size()); |
| 1639 const TemplateURL* default_search = model()->GetDefaultSearchProvider(); | 1639 const TemplateURL* default_search = model()->GetDefaultSearchProvider(); |
| 1640 ASSERT_TRUE(default_search); | 1640 ASSERT_TRUE(default_search); |
| 1641 | 1641 |
| 1642 // Delete the old default. This will change the default to the next available | 1642 // Delete the old default. This will change the default to the next available |
| 1643 // (turl2), but should not affect the synced preference. | 1643 // (turl2), but should not affect the synced preference. |
| 1644 syncer::SyncChangeList changes1; | 1644 syncer::SyncChangeList changes1; |
| 1645 changes1.push_back(CreateTestSyncChange(syncer::SyncChange::ACTION_DELETE, | 1645 changes1.push_back(CreateTestSyncChange(syncer::SyncChange::ACTION_DELETE, |
| 1646 turl1.release())); | 1646 turl1.release())); |
| 1647 model()->ProcessSyncChanges(FROM_HERE, changes1); | 1647 model()->ProcessSyncChanges(FROM_HERE, changes1); |
| 1648 | 1648 |
| 1649 EXPECT_EQ(1U, model()->GetAllSyncData(syncable::SEARCH_ENGINES).size()); | 1649 EXPECT_EQ(1U, model()->GetAllSyncData(syncer::SEARCH_ENGINES).size()); |
| 1650 EXPECT_EQ("key2", model()->GetDefaultSearchProvider()->sync_guid()); | 1650 EXPECT_EQ("key2", model()->GetDefaultSearchProvider()->sync_guid()); |
| 1651 EXPECT_EQ("key1", profile_a()->GetTestingPrefService()->GetString( | 1651 EXPECT_EQ("key1", profile_a()->GetTestingPrefService()->GetString( |
| 1652 prefs::kSyncedDefaultSearchProviderGUID)); | 1652 prefs::kSyncedDefaultSearchProviderGUID)); |
| 1653 | 1653 |
| 1654 // Change kSyncedDefaultSearchProviderGUID to a GUID that does not exist in | 1654 // Change kSyncedDefaultSearchProviderGUID to a GUID that does not exist in |
| 1655 // the model yet. Ensure that the default has not changed in any way. | 1655 // the model yet. Ensure that the default has not changed in any way. |
| 1656 profile_a()->GetTestingPrefService()->SetString( | 1656 profile_a()->GetTestingPrefService()->SetString( |
| 1657 prefs::kSyncedDefaultSearchProviderGUID, "newdefault"); | 1657 prefs::kSyncedDefaultSearchProviderGUID, "newdefault"); |
| 1658 | 1658 |
| 1659 ASSERT_EQ("key2", model()->GetDefaultSearchProvider()->sync_guid()); | 1659 ASSERT_EQ("key2", model()->GetDefaultSearchProvider()->sync_guid()); |
| 1660 EXPECT_EQ("newdefault", profile_a()->GetTestingPrefService()->GetString( | 1660 EXPECT_EQ("newdefault", profile_a()->GetTestingPrefService()->GetString( |
| 1661 prefs::kSyncedDefaultSearchProviderGUID)); | 1661 prefs::kSyncedDefaultSearchProviderGUID)); |
| 1662 | 1662 |
| 1663 // Finally, bring in the expected entry with the right GUID. Ensure that | 1663 // Finally, bring in the expected entry with the right GUID. Ensure that |
| 1664 // the default has changed to the new search engine. | 1664 // the default has changed to the new search engine. |
| 1665 syncer::SyncChangeList changes2; | 1665 syncer::SyncChangeList changes2; |
| 1666 changes2.push_back(CreateTestSyncChange(syncer::SyncChange::ACTION_ADD, | 1666 changes2.push_back(CreateTestSyncChange(syncer::SyncChange::ACTION_ADD, |
| 1667 CreateTestTemplateURL(ASCIIToUTF16("new"), "http://new.com/{searchTerms}", | 1667 CreateTestTemplateURL(ASCIIToUTF16("new"), "http://new.com/{searchTerms}", |
| 1668 "newdefault"))); | 1668 "newdefault"))); |
| 1669 model()->ProcessSyncChanges(FROM_HERE, changes2); | 1669 model()->ProcessSyncChanges(FROM_HERE, changes2); |
| 1670 | 1670 |
| 1671 EXPECT_EQ(2U, model()->GetAllSyncData(syncable::SEARCH_ENGINES).size()); | 1671 EXPECT_EQ(2U, model()->GetAllSyncData(syncer::SEARCH_ENGINES).size()); |
| 1672 EXPECT_EQ("newdefault", model()->GetDefaultSearchProvider()->sync_guid()); | 1672 EXPECT_EQ("newdefault", model()->GetDefaultSearchProvider()->sync_guid()); |
| 1673 EXPECT_EQ("newdefault", profile_a()->GetTestingPrefService()->GetString( | 1673 EXPECT_EQ("newdefault", profile_a()->GetTestingPrefService()->GetString( |
| 1674 prefs::kSyncedDefaultSearchProviderGUID)); | 1674 prefs::kSyncedDefaultSearchProviderGUID)); |
| 1675 } | 1675 } |
| 1676 | 1676 |
| 1677 TEST_F(TemplateURLServiceSyncTest, SyncedDefaultArrivesAfterStartup) { | 1677 TEST_F(TemplateURLServiceSyncTest, SyncedDefaultArrivesAfterStartup) { |
| 1678 // Start with the default set to something in the model before we start | 1678 // Start with the default set to something in the model before we start |
| 1679 // syncing. | 1679 // syncing. |
| 1680 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("what"), | 1680 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("what"), |
| 1681 "http://thewhat.com/{searchTerms}", | 1681 "http://thewhat.com/{searchTerms}", |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1695 EXPECT_EQ(default_search, model()->GetDefaultSearchProvider()); | 1695 EXPECT_EQ(default_search, model()->GetDefaultSearchProvider()); |
| 1696 | 1696 |
| 1697 // Now sync the initial data, which will include the search engine entry | 1697 // Now sync the initial data, which will include the search engine entry |
| 1698 // destined to become the new default. | 1698 // destined to become the new default. |
| 1699 syncer::SyncDataList initial_data = CreateInitialSyncData(); | 1699 syncer::SyncDataList initial_data = CreateInitialSyncData(); |
| 1700 // The default search provider should support replacement. | 1700 // The default search provider should support replacement. |
| 1701 scoped_ptr<TemplateURL> turl(CreateTestTemplateURL(ASCIIToUTF16("key2"), | 1701 scoped_ptr<TemplateURL> turl(CreateTestTemplateURL(ASCIIToUTF16("key2"), |
| 1702 "http://key2.com/{searchTerms}", "key2", 90)); | 1702 "http://key2.com/{searchTerms}", "key2", 90)); |
| 1703 initial_data[1] = TemplateURLService::CreateSyncDataFromTemplateURL(*turl); | 1703 initial_data[1] = TemplateURLService::CreateSyncDataFromTemplateURL(*turl); |
| 1704 | 1704 |
| 1705 model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, initial_data, | 1705 model()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES, initial_data, |
| 1706 PassProcessor(), CreateAndPassSyncErrorFactory()); | 1706 PassProcessor(), CreateAndPassSyncErrorFactory()); |
| 1707 | 1707 |
| 1708 // Ensure that the new default has been set. | 1708 // Ensure that the new default has been set. |
| 1709 EXPECT_EQ(4U, model()->GetAllSyncData(syncable::SEARCH_ENGINES).size()); | 1709 EXPECT_EQ(4U, model()->GetAllSyncData(syncer::SEARCH_ENGINES).size()); |
| 1710 ASSERT_NE(default_search, model()->GetDefaultSearchProvider()); | 1710 ASSERT_NE(default_search, model()->GetDefaultSearchProvider()); |
| 1711 ASSERT_EQ("key2", model()->GetDefaultSearchProvider()->sync_guid()); | 1711 ASSERT_EQ("key2", model()->GetDefaultSearchProvider()->sync_guid()); |
| 1712 } | 1712 } |
| 1713 | 1713 |
| 1714 TEST_F(TemplateURLServiceSyncTest, SyncedDefaultAlreadySetOnStartup) { | 1714 TEST_F(TemplateURLServiceSyncTest, SyncedDefaultAlreadySetOnStartup) { |
| 1715 // Start with the default set to something in the model before we start | 1715 // Start with the default set to something in the model before we start |
| 1716 // syncing. | 1716 // syncing. |
| 1717 const char kGUID[] = "initdefault"; | 1717 const char kGUID[] = "initdefault"; |
| 1718 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("what"), | 1718 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("what"), |
| 1719 "http://thewhat.com/{searchTerms}", | 1719 "http://thewhat.com/{searchTerms}", |
| 1720 kGUID)); | 1720 kGUID)); |
| 1721 model()->SetDefaultSearchProvider(model()->GetTemplateURLForGUID(kGUID)); | 1721 model()->SetDefaultSearchProvider(model()->GetTemplateURLForGUID(kGUID)); |
| 1722 | 1722 |
| 1723 const TemplateURL* default_search = model()->GetDefaultSearchProvider(); | 1723 const TemplateURL* default_search = model()->GetDefaultSearchProvider(); |
| 1724 ASSERT_TRUE(default_search); | 1724 ASSERT_TRUE(default_search); |
| 1725 | 1725 |
| 1726 // Set kSyncedDefaultSearchProviderGUID to the current default. | 1726 // Set kSyncedDefaultSearchProviderGUID to the current default. |
| 1727 profile_a()->GetTestingPrefService()->SetString( | 1727 profile_a()->GetTestingPrefService()->SetString( |
| 1728 prefs::kSyncedDefaultSearchProviderGUID, kGUID); | 1728 prefs::kSyncedDefaultSearchProviderGUID, kGUID); |
| 1729 | 1729 |
| 1730 EXPECT_EQ(default_search, model()->GetDefaultSearchProvider()); | 1730 EXPECT_EQ(default_search, model()->GetDefaultSearchProvider()); |
| 1731 | 1731 |
| 1732 // Now sync the initial data. | 1732 // Now sync the initial data. |
| 1733 syncer::SyncDataList initial_data = CreateInitialSyncData(); | 1733 syncer::SyncDataList initial_data = CreateInitialSyncData(); |
| 1734 model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, initial_data, | 1734 model()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES, initial_data, |
| 1735 PassProcessor(), CreateAndPassSyncErrorFactory()); | 1735 PassProcessor(), CreateAndPassSyncErrorFactory()); |
| 1736 | 1736 |
| 1737 // Ensure that the new entries were added and the default has not changed. | 1737 // Ensure that the new entries were added and the default has not changed. |
| 1738 EXPECT_EQ(4U, model()->GetAllSyncData(syncable::SEARCH_ENGINES).size()); | 1738 EXPECT_EQ(4U, model()->GetAllSyncData(syncer::SEARCH_ENGINES).size()); |
| 1739 ASSERT_EQ(default_search, model()->GetDefaultSearchProvider()); | 1739 ASSERT_EQ(default_search, model()->GetDefaultSearchProvider()); |
| 1740 } | 1740 } |
| 1741 | 1741 |
| 1742 TEST_F(TemplateURLServiceSyncTest, SyncWithManagedDefaultSearch) { | 1742 TEST_F(TemplateURLServiceSyncTest, SyncWithManagedDefaultSearch) { |
| 1743 // First start off with a few entries and make sure we can set an unmanaged | 1743 // First start off with a few entries and make sure we can set an unmanaged |
| 1744 // default search provider. | 1744 // default search provider. |
| 1745 syncer::SyncDataList initial_data = CreateInitialSyncData(); | 1745 syncer::SyncDataList initial_data = CreateInitialSyncData(); |
| 1746 model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, initial_data, | 1746 model()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES, initial_data, |
| 1747 PassProcessor(), CreateAndPassSyncErrorFactory()); | 1747 PassProcessor(), CreateAndPassSyncErrorFactory()); |
| 1748 model()->SetDefaultSearchProvider(model()->GetTemplateURLForGUID("key2")); | 1748 model()->SetDefaultSearchProvider(model()->GetTemplateURLForGUID("key2")); |
| 1749 | 1749 |
| 1750 EXPECT_EQ(3U, model()->GetAllSyncData(syncable::SEARCH_ENGINES).size()); | 1750 EXPECT_EQ(3U, model()->GetAllSyncData(syncer::SEARCH_ENGINES).size()); |
| 1751 ASSERT_FALSE(model()->is_default_search_managed()); | 1751 ASSERT_FALSE(model()->is_default_search_managed()); |
| 1752 ASSERT_TRUE(model()->GetDefaultSearchProvider()); | 1752 ASSERT_TRUE(model()->GetDefaultSearchProvider()); |
| 1753 | 1753 |
| 1754 // Change the default search provider to a managed one. | 1754 // Change the default search provider to a managed one. |
| 1755 const char kName[] = "manageddefault"; | 1755 const char kName[] = "manageddefault"; |
| 1756 const char kSearchURL[] = "http://manageddefault.com/search?t={searchTerms}"; | 1756 const char kSearchURL[] = "http://manageddefault.com/search?t={searchTerms}"; |
| 1757 const char kIconURL[] = "http://manageddefault.com/icon.jpg"; | 1757 const char kIconURL[] = "http://manageddefault.com/icon.jpg"; |
| 1758 const char kEncodings[] = "UTF-16;UTF-32"; | 1758 const char kEncodings[] = "UTF-16;UTF-32"; |
| 1759 test_util_a_.SetManagedDefaultSearchPreferences(true, kName, kName, | 1759 test_util_a_.SetManagedDefaultSearchPreferences(true, kName, kName, |
| 1760 kSearchURL, std::string(), kIconURL, kEncodings); | 1760 kSearchURL, std::string(), kIconURL, kEncodings); |
| 1761 const TemplateURL* dsp_turl = model()->GetDefaultSearchProvider(); | 1761 const TemplateURL* dsp_turl = model()->GetDefaultSearchProvider(); |
| 1762 | 1762 |
| 1763 EXPECT_TRUE(model()->is_default_search_managed()); | 1763 EXPECT_TRUE(model()->is_default_search_managed()); |
| 1764 | 1764 |
| 1765 // Add a new entry from Sync. It should still sync in despite the default | 1765 // Add a new entry from Sync. It should still sync in despite the default |
| 1766 // being managed. | 1766 // being managed. |
| 1767 syncer::SyncChangeList changes; | 1767 syncer::SyncChangeList changes; |
| 1768 changes.push_back(CreateTestSyncChange(syncer::SyncChange::ACTION_ADD, | 1768 changes.push_back(CreateTestSyncChange(syncer::SyncChange::ACTION_ADD, |
| 1769 CreateTestTemplateURL(ASCIIToUTF16("newkeyword"), | 1769 CreateTestTemplateURL(ASCIIToUTF16("newkeyword"), |
| 1770 "http://new.com/{searchTerms}", | 1770 "http://new.com/{searchTerms}", |
| 1771 "newdefault"))); | 1771 "newdefault"))); |
| 1772 model()->ProcessSyncChanges(FROM_HERE, changes); | 1772 model()->ProcessSyncChanges(FROM_HERE, changes); |
| 1773 | 1773 |
| 1774 EXPECT_EQ(4U, model()->GetAllSyncData(syncable::SEARCH_ENGINES).size()); | 1774 EXPECT_EQ(4U, model()->GetAllSyncData(syncer::SEARCH_ENGINES).size()); |
| 1775 | 1775 |
| 1776 // Change kSyncedDefaultSearchProviderGUID to point to the new entry and | 1776 // Change kSyncedDefaultSearchProviderGUID to point to the new entry and |
| 1777 // ensure that the DSP remains managed. | 1777 // ensure that the DSP remains managed. |
| 1778 profile_a()->GetTestingPrefService()->SetString( | 1778 profile_a()->GetTestingPrefService()->SetString( |
| 1779 prefs::kSyncedDefaultSearchProviderGUID, | 1779 prefs::kSyncedDefaultSearchProviderGUID, |
| 1780 "newdefault"); | 1780 "newdefault"); |
| 1781 | 1781 |
| 1782 EXPECT_EQ(dsp_turl, model()->GetDefaultSearchProvider()); | 1782 EXPECT_EQ(dsp_turl, model()->GetDefaultSearchProvider()); |
| 1783 EXPECT_TRUE(model()->is_default_search_managed()); | 1783 EXPECT_TRUE(model()->is_default_search_managed()); |
| 1784 | 1784 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1798 "http://key1.com/{searchTerms}", "whateverguid", 10); | 1798 "http://key1.com/{searchTerms}", "whateverguid", 10); |
| 1799 model()->Add(default_turl); | 1799 model()->Add(default_turl); |
| 1800 model()->SetDefaultSearchProvider(default_turl); | 1800 model()->SetDefaultSearchProvider(default_turl); |
| 1801 | 1801 |
| 1802 syncer::SyncDataList initial_data = CreateInitialSyncData(); | 1802 syncer::SyncDataList initial_data = CreateInitialSyncData(); |
| 1803 // The key1 entry should be a duplicate of the default. | 1803 // The key1 entry should be a duplicate of the default. |
| 1804 scoped_ptr<TemplateURL> turl(CreateTestTemplateURL(ASCIIToUTF16("key1"), | 1804 scoped_ptr<TemplateURL> turl(CreateTestTemplateURL(ASCIIToUTF16("key1"), |
| 1805 "http://key1.com/{searchTerms}", "key1", 90)); | 1805 "http://key1.com/{searchTerms}", "key1", 90)); |
| 1806 initial_data[0] = TemplateURLService::CreateSyncDataFromTemplateURL(*turl); | 1806 initial_data[0] = TemplateURLService::CreateSyncDataFromTemplateURL(*turl); |
| 1807 | 1807 |
| 1808 model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, initial_data, | 1808 model()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES, initial_data, |
| 1809 PassProcessor(), CreateAndPassSyncErrorFactory()); | 1809 PassProcessor(), CreateAndPassSyncErrorFactory()); |
| 1810 | 1810 |
| 1811 EXPECT_EQ(3U, model()->GetAllSyncData(syncable::SEARCH_ENGINES).size()); | 1811 EXPECT_EQ(3U, model()->GetAllSyncData(syncer::SEARCH_ENGINES).size()); |
| 1812 EXPECT_FALSE(model()->GetTemplateURLForGUID("whateverguid")); | 1812 EXPECT_FALSE(model()->GetTemplateURLForGUID("whateverguid")); |
| 1813 EXPECT_EQ(model()->GetDefaultSearchProvider(), | 1813 EXPECT_EQ(model()->GetDefaultSearchProvider(), |
| 1814 model()->GetTemplateURLForGUID("key1")); | 1814 model()->GetTemplateURLForGUID("key1")); |
| 1815 } | 1815 } |
| 1816 | 1816 |
| 1817 TEST_F(TemplateURLServiceSyncTest, LocalDefaultWinsConflict) { | 1817 TEST_F(TemplateURLServiceSyncTest, LocalDefaultWinsConflict) { |
| 1818 // We expect that the local default always wins keyword conflict resolution. | 1818 // We expect that the local default always wins keyword conflict resolution. |
| 1819 const string16 keyword(ASCIIToUTF16("key1")); | 1819 const string16 keyword(ASCIIToUTF16("key1")); |
| 1820 TemplateURL* default_turl = CreateTestTemplateURL(keyword, | 1820 TemplateURL* default_turl = CreateTestTemplateURL(keyword, |
| 1821 "http://whatever.com/{searchTerms}", "whateverguid", 10); | 1821 "http://whatever.com/{searchTerms}", "whateverguid", 10); |
| 1822 model()->Add(default_turl); | 1822 model()->Add(default_turl); |
| 1823 model()->SetDefaultSearchProvider(default_turl); | 1823 model()->SetDefaultSearchProvider(default_turl); |
| 1824 | 1824 |
| 1825 syncer::SyncDataList initial_data = CreateInitialSyncData(); | 1825 syncer::SyncDataList initial_data = CreateInitialSyncData(); |
| 1826 // The key1 entry should be different from the default but conflict in the | 1826 // The key1 entry should be different from the default but conflict in the |
| 1827 // keyword. | 1827 // keyword. |
| 1828 scoped_ptr<TemplateURL> turl(CreateTestTemplateURL(keyword, | 1828 scoped_ptr<TemplateURL> turl(CreateTestTemplateURL(keyword, |
| 1829 "http://key1.com/{searchTerms}", "key1", 90)); | 1829 "http://key1.com/{searchTerms}", "key1", 90)); |
| 1830 initial_data[0] = TemplateURLService::CreateSyncDataFromTemplateURL(*turl); | 1830 initial_data[0] = TemplateURLService::CreateSyncDataFromTemplateURL(*turl); |
| 1831 | 1831 |
| 1832 model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, initial_data, | 1832 model()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES, initial_data, |
| 1833 PassProcessor(), CreateAndPassSyncErrorFactory()); | 1833 PassProcessor(), CreateAndPassSyncErrorFactory()); |
| 1834 | 1834 |
| 1835 // The conflicting TemplateURL should be added, but it should have lost | 1835 // The conflicting TemplateURL should be added, but it should have lost |
| 1836 // conflict resolution against the default. | 1836 // conflict resolution against the default. |
| 1837 EXPECT_EQ(4U, model()->GetAllSyncData(syncable::SEARCH_ENGINES).size()); | 1837 EXPECT_EQ(4U, model()->GetAllSyncData(syncer::SEARCH_ENGINES).size()); |
| 1838 const TemplateURL* winner = model()->GetTemplateURLForGUID("whateverguid"); | 1838 const TemplateURL* winner = model()->GetTemplateURLForGUID("whateverguid"); |
| 1839 ASSERT_TRUE(winner); | 1839 ASSERT_TRUE(winner); |
| 1840 EXPECT_EQ(model()->GetDefaultSearchProvider(), winner); | 1840 EXPECT_EQ(model()->GetDefaultSearchProvider(), winner); |
| 1841 EXPECT_EQ(keyword, winner->keyword()); | 1841 EXPECT_EQ(keyword, winner->keyword()); |
| 1842 const TemplateURL* loser = model()->GetTemplateURLForGUID("key1"); | 1842 const TemplateURL* loser = model()->GetTemplateURLForGUID("key1"); |
| 1843 ASSERT_TRUE(loser); | 1843 ASSERT_TRUE(loser); |
| 1844 EXPECT_EQ(ASCIIToUTF16("key1.com"), loser->keyword()); | 1844 EXPECT_EQ(ASCIIToUTF16("key1.com"), loser->keyword()); |
| 1845 } | 1845 } |
| 1846 | 1846 |
| 1847 TEST_F(TemplateURLServiceSyncTest, DeleteBogusData) { | 1847 TEST_F(TemplateURLServiceSyncTest, DeleteBogusData) { |
| 1848 // Create a couple of bogus entries to sync. | 1848 // Create a couple of bogus entries to sync. |
| 1849 syncer::SyncDataList initial_data; | 1849 syncer::SyncDataList initial_data; |
| 1850 scoped_ptr<TemplateURL> turl( | 1850 scoped_ptr<TemplateURL> turl( |
| 1851 CreateTestTemplateURL(ASCIIToUTF16("key1"), "http://key1.com", "key1")); | 1851 CreateTestTemplateURL(ASCIIToUTF16("key1"), "http://key1.com", "key1")); |
| 1852 initial_data.push_back( | 1852 initial_data.push_back( |
| 1853 CreateCustomSyncData(*turl, false, std::string(), turl->sync_guid())); | 1853 CreateCustomSyncData(*turl, false, std::string(), turl->sync_guid())); |
| 1854 turl.reset(CreateTestTemplateURL(ASCIIToUTF16("key2"), "http://key2.com")); | 1854 turl.reset(CreateTestTemplateURL(ASCIIToUTF16("key2"), "http://key2.com")); |
| 1855 initial_data.push_back( | 1855 initial_data.push_back( |
| 1856 CreateCustomSyncData(*turl, false, turl->url(), std::string())); | 1856 CreateCustomSyncData(*turl, false, turl->url(), std::string())); |
| 1857 | 1857 |
| 1858 // Now try to sync the data locally. | 1858 // Now try to sync the data locally. |
| 1859 model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, initial_data, | 1859 model()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES, initial_data, |
| 1860 PassProcessor(), CreateAndPassSyncErrorFactory()); | 1860 PassProcessor(), CreateAndPassSyncErrorFactory()); |
| 1861 | 1861 |
| 1862 // Nothing should have been added, and both bogus entries should be marked for | 1862 // Nothing should have been added, and both bogus entries should be marked for |
| 1863 // deletion. | 1863 // deletion. |
| 1864 EXPECT_EQ(0U, model()->GetTemplateURLs().size()); | 1864 EXPECT_EQ(0U, model()->GetTemplateURLs().size()); |
| 1865 EXPECT_EQ(2U, processor()->change_list_size()); | 1865 EXPECT_EQ(2U, processor()->change_list_size()); |
| 1866 ASSERT_TRUE(processor()->contains_guid("key1")); | 1866 ASSERT_TRUE(processor()->contains_guid("key1")); |
| 1867 EXPECT_EQ(syncer::SyncChange::ACTION_DELETE, | 1867 EXPECT_EQ(syncer::SyncChange::ACTION_DELETE, |
| 1868 processor()->change_for_guid("key1").change_type()); | 1868 processor()->change_for_guid("key1").change_type()); |
| 1869 ASSERT_TRUE(processor()->contains_guid(std::string())); | 1869 ASSERT_TRUE(processor()->contains_guid(std::string())); |
| 1870 EXPECT_EQ(syncer::SyncChange::ACTION_DELETE, | 1870 EXPECT_EQ(syncer::SyncChange::ACTION_DELETE, |
| 1871 processor()->change_for_guid(std::string()).change_type()); | 1871 processor()->change_for_guid(std::string()).change_type()); |
| 1872 } | 1872 } |
| 1873 | 1873 |
| 1874 TEST_F(TemplateURLServiceSyncTest, PreSyncDeletes) { | 1874 TEST_F(TemplateURLServiceSyncTest, PreSyncDeletes) { |
| 1875 model()->pre_sync_deletes_.insert("key1"); | 1875 model()->pre_sync_deletes_.insert("key1"); |
| 1876 model()->pre_sync_deletes_.insert("key2"); | 1876 model()->pre_sync_deletes_.insert("key2"); |
| 1877 model()->pre_sync_deletes_.insert("aaa"); | 1877 model()->pre_sync_deletes_.insert("aaa"); |
| 1878 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("whatever"), | 1878 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("whatever"), |
| 1879 "http://key1.com", "bbb")); | 1879 "http://key1.com", "bbb")); |
| 1880 model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, | 1880 model()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES, |
| 1881 CreateInitialSyncData(), PassProcessor(), | 1881 CreateInitialSyncData(), PassProcessor(), |
| 1882 CreateAndPassSyncErrorFactory()); | 1882 CreateAndPassSyncErrorFactory()); |
| 1883 | 1883 |
| 1884 // We expect the model to have GUIDs {bbb, key3} after our initial merge. | 1884 // We expect the model to have GUIDs {bbb, key3} after our initial merge. |
| 1885 EXPECT_TRUE(model()->GetTemplateURLForGUID("bbb")); | 1885 EXPECT_TRUE(model()->GetTemplateURLForGUID("bbb")); |
| 1886 EXPECT_TRUE(model()->GetTemplateURLForGUID("key3")); | 1886 EXPECT_TRUE(model()->GetTemplateURLForGUID("key3")); |
| 1887 syncer::SyncChange change = processor()->change_for_guid("key1"); | 1887 syncer::SyncChange change = processor()->change_for_guid("key1"); |
| 1888 EXPECT_EQ(syncer::SyncChange::ACTION_DELETE, change.change_type()); | 1888 EXPECT_EQ(syncer::SyncChange::ACTION_DELETE, change.change_type()); |
| 1889 change = processor()->change_for_guid("key2"); | 1889 change = processor()->change_for_guid("key2"); |
| 1890 EXPECT_EQ(syncer::SyncChange::ACTION_DELETE, change.change_type()); | 1890 EXPECT_EQ(syncer::SyncChange::ACTION_DELETE, change.change_type()); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1936 // conflict resolution against the local value, and an update is sent to the | 1936 // conflict resolution against the local value, and an update is sent to the |
| 1937 // server. The new timestamp should be preserved. | 1937 // server. The new timestamp should be preserved. |
| 1938 syncer::SyncDataList initial_data; | 1938 syncer::SyncDataList initial_data; |
| 1939 data_copy.SetKeyword(original_keyword); | 1939 data_copy.SetKeyword(original_keyword); |
| 1940 data_copy.sync_guid = sync_guid; | 1940 data_copy.sync_guid = sync_guid; |
| 1941 scoped_ptr<TemplateURL> sync_turl( | 1941 scoped_ptr<TemplateURL> sync_turl( |
| 1942 new TemplateURL(prepop_turls[0]->profile(), data_copy)); | 1942 new TemplateURL(prepop_turls[0]->profile(), data_copy)); |
| 1943 initial_data.push_back( | 1943 initial_data.push_back( |
| 1944 TemplateURLService::CreateSyncDataFromTemplateURL(*sync_turl)); | 1944 TemplateURLService::CreateSyncDataFromTemplateURL(*sync_turl)); |
| 1945 | 1945 |
| 1946 model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, | 1946 model()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES, |
| 1947 initial_data, PassProcessor(), CreateAndPassSyncErrorFactory()); | 1947 initial_data, PassProcessor(), CreateAndPassSyncErrorFactory()); |
| 1948 | 1948 |
| 1949 ASSERT_EQ(added_turl, model()->GetTemplateURLForKeyword( | 1949 ASSERT_EQ(added_turl, model()->GetTemplateURLForKeyword( |
| 1950 ASCIIToUTF16(kNewKeyword))); | 1950 ASCIIToUTF16(kNewKeyword))); |
| 1951 EXPECT_EQ(new_timestamp, added_turl->last_modified()); | 1951 EXPECT_EQ(new_timestamp, added_turl->last_modified()); |
| 1952 syncer::SyncChange change = processor()->change_for_guid(sync_guid); | 1952 syncer::SyncChange change = processor()->change_for_guid(sync_guid); |
| 1953 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, change.change_type()); | 1953 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, change.change_type()); |
| 1954 EXPECT_EQ(kNewKeyword, | 1954 EXPECT_EQ(kNewKeyword, |
| 1955 change.sync_data().GetSpecifics().search_engine().keyword()); | 1955 change.sync_data().GetSpecifics().search_engine().keyword()); |
| 1956 EXPECT_EQ(new_timestamp, base::Time::FromInternalValue( | 1956 EXPECT_EQ(new_timestamp, base::Time::FromInternalValue( |
| 1957 change.sync_data().GetSpecifics().search_engine().last_modified())); | 1957 change.sync_data().GetSpecifics().search_engine().last_modified())); |
| 1958 } | 1958 } |
| 1959 | 1959 |
| 1960 TEST_F(TemplateURLServiceSyncTest, SyncBaseURLs) { | 1960 TEST_F(TemplateURLServiceSyncTest, SyncBaseURLs) { |
| 1961 // Verify that bringing in a remote TemplateURL that uses Google base URLs | 1961 // Verify that bringing in a remote TemplateURL that uses Google base URLs |
| 1962 // causes it to get a local keyword that matches the local base URL. | 1962 // causes it to get a local keyword that matches the local base URL. |
| 1963 test_util_a_.SetGoogleBaseURL(GURL("http://google.com/")); | 1963 test_util_a_.SetGoogleBaseURL(GURL("http://google.com/")); |
| 1964 syncer::SyncDataList initial_data; | 1964 syncer::SyncDataList initial_data; |
| 1965 scoped_ptr<TemplateURL> turl(CreateTestTemplateURL( | 1965 scoped_ptr<TemplateURL> turl(CreateTestTemplateURL( |
| 1966 ASCIIToUTF16("google.co.uk"), "{google:baseURL}search?q={searchTerms}", | 1966 ASCIIToUTF16("google.co.uk"), "{google:baseURL}search?q={searchTerms}", |
| 1967 "guid")); | 1967 "guid")); |
| 1968 initial_data.push_back( | 1968 initial_data.push_back( |
| 1969 TemplateURLService::CreateSyncDataFromTemplateURL(*turl)); | 1969 TemplateURLService::CreateSyncDataFromTemplateURL(*turl)); |
| 1970 model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, initial_data, | 1970 model()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES, initial_data, |
| 1971 PassProcessor(), CreateAndPassSyncErrorFactory()); | 1971 PassProcessor(), CreateAndPassSyncErrorFactory()); |
| 1972 TemplateURL* synced_turl = model()->GetTemplateURLForGUID("guid"); | 1972 TemplateURL* synced_turl = model()->GetTemplateURLForGUID("guid"); |
| 1973 ASSERT_TRUE(synced_turl); | 1973 ASSERT_TRUE(synced_turl); |
| 1974 EXPECT_EQ(ASCIIToUTF16("google.com"), synced_turl->keyword()); | 1974 EXPECT_EQ(ASCIIToUTF16("google.com"), synced_turl->keyword()); |
| 1975 EXPECT_EQ(0U, processor()->change_list_size()); | 1975 EXPECT_EQ(0U, processor()->change_list_size()); |
| 1976 | 1976 |
| 1977 // Remote updates to this URL's keyword should be silently ignored. | 1977 // Remote updates to this URL's keyword should be silently ignored. |
| 1978 syncer::SyncChangeList changes; | 1978 syncer::SyncChangeList changes; |
| 1979 changes.push_back(CreateTestSyncChange(syncer::SyncChange::ACTION_UPDATE, | 1979 changes.push_back(CreateTestSyncChange(syncer::SyncChange::ACTION_UPDATE, |
| 1980 CreateTestTemplateURL(ASCIIToUTF16("google.de"), | 1980 CreateTestTemplateURL(ASCIIToUTF16("google.de"), |
| 1981 "{google:baseURL}search?q={searchTerms}", "guid"))); | 1981 "{google:baseURL}search?q={searchTerms}", "guid"))); |
| 1982 model()->ProcessSyncChanges(FROM_HERE, changes); | 1982 model()->ProcessSyncChanges(FROM_HERE, changes); |
| 1983 EXPECT_EQ(ASCIIToUTF16("google.com"), synced_turl->keyword()); | 1983 EXPECT_EQ(ASCIIToUTF16("google.com"), synced_turl->keyword()); |
| 1984 EXPECT_EQ(0U, processor()->change_list_size()); | 1984 EXPECT_EQ(0U, processor()->change_list_size()); |
| 1985 | 1985 |
| 1986 // A local change to the Google base URL should update the keyword and | 1986 // A local change to the Google base URL should update the keyword and |
| 1987 // generate a sync change. | 1987 // generate a sync change. |
| 1988 test_util_a_.SetGoogleBaseURL(GURL("http://google.co.in/")); | 1988 test_util_a_.SetGoogleBaseURL(GURL("http://google.co.in/")); |
| 1989 EXPECT_EQ(ASCIIToUTF16("google.co.in"), synced_turl->keyword()); | 1989 EXPECT_EQ(ASCIIToUTF16("google.co.in"), synced_turl->keyword()); |
| 1990 EXPECT_EQ(1U, processor()->change_list_size()); | 1990 EXPECT_EQ(1U, processor()->change_list_size()); |
| 1991 ASSERT_TRUE(processor()->contains_guid("guid")); | 1991 ASSERT_TRUE(processor()->contains_guid("guid")); |
| 1992 syncer::SyncChange change(processor()->change_for_guid("guid")); | 1992 syncer::SyncChange change(processor()->change_for_guid("guid")); |
| 1993 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, change.change_type()); | 1993 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, change.change_type()); |
| 1994 EXPECT_EQ("google.co.in", GetKeyword(change.sync_data())); | 1994 EXPECT_EQ("google.co.in", GetKeyword(change.sync_data())); |
| 1995 } | 1995 } |
| OLD | NEW |