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 710 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
721 } | 721 } |
722 | 722 |
723 TEST_F(TemplateURLServiceSyncTest, MergeSyncAndLocalURLDuplicates) { | 723 TEST_F(TemplateURLServiceSyncTest, MergeSyncAndLocalURLDuplicates) { |
724 TemplateURL* original_turl = CreateTestTemplateURL(ASCIIToUTF16("key1"), | 724 TemplateURL* original_turl = CreateTestTemplateURL(ASCIIToUTF16("key1"), |
725 "http://key1.com", std::string(), 9000); | 725 "http://key1.com", std::string(), 9000); |
726 model()->Add(original_turl); | 726 model()->Add(original_turl); |
727 TemplateURL* sync_turl = CreateTestTemplateURL(ASCIIToUTF16("key1"), | 727 TemplateURL* sync_turl = CreateTestTemplateURL(ASCIIToUTF16("key1"), |
728 "http://key1.com", std::string(), 9001); | 728 "http://key1.com", std::string(), 9001); |
729 std::string original_guid = original_turl->sync_guid(); | 729 std::string original_guid = original_turl->sync_guid(); |
730 syncer::SyncChangeList changes; | 730 syncer::SyncChangeList changes; |
| 731 // TODO This test is broken until you pass in the correct SyncDataMap |
| 732 // to MergeSyncAndLocalURLDuplicates below. |
| 733 SyncDataMap map1 = |
| 734 TemplateURLService::CreateGUIDToSyncDataMap(CreateInitialSyncData()); |
| 735 SyncDataMap map2 = |
| 736 TemplateURLService::CreateGUIDToSyncDataMap(CreateInitialSyncData()); |
731 | 737 |
732 // The sync TemplateURL is newer. It should replace the original TemplateURL | 738 // The sync TemplateURL is newer. It should replace the original TemplateURL |
733 // and a syncer::SyncChange should be added to the list. | 739 // and a syncer::SyncChange should be added to the list. |
734 // Note that MergeSyncAndLocalURLDuplicates takes ownership of sync_turl. | 740 // Note that MergeSyncAndLocalURLDuplicates takes ownership of sync_turl. |
735 model()->MergeSyncAndLocalURLDuplicates(sync_turl, original_turl, &changes); | 741 model()->MergeSyncAndLocalURLDuplicates(sync_turl, original_turl, map1, |
| 742 &changes); |
736 TemplateURL* result = model()->GetTemplateURLForKeyword(ASCIIToUTF16("key1")); | 743 TemplateURL* result = model()->GetTemplateURLForKeyword(ASCIIToUTF16("key1")); |
737 ASSERT_TRUE(result); | 744 ASSERT_TRUE(result); |
738 EXPECT_EQ(9001, result->last_modified().ToTimeT()); | 745 EXPECT_EQ(9001, result->last_modified().ToTimeT()); |
739 EXPECT_EQ(1U, changes.size()); | 746 ASSERT_EQ(1U, changes.size()); |
740 // We expect a change to delete the local entry. | 747 // We expect a change to delete the local entry. |
741 syncer::SyncChange change = changes.at(0); | 748 syncer::SyncChange change = changes.at(0); |
742 EXPECT_EQ(syncer::SyncChange::ACTION_DELETE, change.change_type()); | 749 EXPECT_EQ(syncer::SyncChange::ACTION_DELETE, change.change_type()); |
743 EXPECT_EQ(original_guid, | 750 EXPECT_EQ(original_guid, |
744 change.sync_data().GetSpecifics().search_engine().sync_guid()); | 751 change.sync_data().GetSpecifics().search_engine().sync_guid()); |
745 changes.clear(); | 752 changes.clear(); |
746 | 753 |
747 // The sync TemplateURL is older. The existing TemplateURL should win and a | 754 // The sync TemplateURL is older. The existing TemplateURL should win and a |
748 // syncer::SyncChange should be added to the list. | 755 // syncer::SyncChange should be added to the list. |
749 TemplateURL* sync_turl2 = CreateTestTemplateURL(ASCIIToUTF16("key1"), | 756 TemplateURL* sync_turl2 = CreateTestTemplateURL(ASCIIToUTF16("key1"), |
750 "http://key1.com", std::string(), 8999); | 757 "http://key1.com", std::string(), 8999); |
751 std::string sync_guid = sync_turl2->sync_guid(); | 758 std::string sync_guid = sync_turl2->sync_guid(); |
752 model()->MergeSyncAndLocalURLDuplicates(sync_turl2, sync_turl, &changes); | 759 model()->MergeSyncAndLocalURLDuplicates(sync_turl2, sync_turl, map2, |
| 760 &changes); |
753 result = model()->GetTemplateURLForKeyword(ASCIIToUTF16("key1")); | 761 result = model()->GetTemplateURLForKeyword(ASCIIToUTF16("key1")); |
754 ASSERT_TRUE(result); | 762 ASSERT_TRUE(result); |
755 EXPECT_EQ(9001, result->last_modified().ToTimeT()); | 763 EXPECT_EQ(9001, result->last_modified().ToTimeT()); |
756 EXPECT_EQ(1U, changes.size()); | 764 EXPECT_EQ(1U, changes.size()); |
757 // We expect a change to update the sync entry. | 765 // We expect a change to update the sync entry. |
758 change = changes.at(0); | 766 change = changes.at(0); |
759 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, change.change_type()); | 767 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, change.change_type()); |
760 EXPECT_EQ(sync_guid, | 768 EXPECT_EQ(sync_guid, |
761 change.sync_data().GetSpecifics().search_engine().sync_guid()); | 769 change.sync_data().GetSpecifics().search_engine().sync_guid()); |
762 } | 770 } |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
908 // Check changes for the UPDATE. | 916 // Check changes for the UPDATE. |
909 ASSERT_TRUE(processor()->contains_guid("key1")); | 917 ASSERT_TRUE(processor()->contains_guid("key1")); |
910 syncer::SyncChange key1_change = processor()->change_for_guid("key1"); | 918 syncer::SyncChange key1_change = processor()->change_for_guid("key1"); |
911 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, key1_change.change_type()); | 919 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, key1_change.change_type()); |
912 EXPECT_FALSE(model()->GetTemplateURLForGUID("aaa")); | 920 EXPECT_FALSE(model()->GetTemplateURLForGUID("aaa")); |
913 | 921 |
914 // The key2 keyword conflict results in the local copy winning, so ensure it | 922 // The key2 keyword conflict results in the local copy winning, so ensure it |
915 // retains the original keyword, and that an update to the sync copy is pushed | 923 // retains the original keyword, and that an update to the sync copy is pushed |
916 // upstream to Sync. Both TemplateURLs should be found locally, however. | 924 // upstream to Sync. Both TemplateURLs should be found locally, however. |
917 const TemplateURL* key2 = model()->GetTemplateURLForGUID("bbb"); | 925 const TemplateURL* key2 = model()->GetTemplateURLForGUID("bbb"); |
918 EXPECT_TRUE(key2); | 926 ASSERT_TRUE(key2); |
919 EXPECT_EQ(ASCIIToUTF16("key2"), key2->keyword()); | 927 EXPECT_EQ(ASCIIToUTF16("key2"), key2->keyword()); |
920 EXPECT_TRUE(model()->GetTemplateURLForGUID("key2")); | 928 EXPECT_TRUE(model()->GetTemplateURLForGUID("key2")); |
921 // Check changes for the UPDATE. | 929 // Check changes for the UPDATE. |
922 ASSERT_TRUE(processor()->contains_guid("key2")); | 930 ASSERT_TRUE(processor()->contains_guid("key2")); |
923 syncer::SyncChange key2_change = processor()->change_for_guid("key2"); | 931 syncer::SyncChange key2_change = processor()->change_for_guid("key2"); |
924 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, key2_change.change_type()); | 932 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, key2_change.change_type()); |
925 EXPECT_EQ("key2.com", GetKeyword(key2_change.sync_data())); | 933 EXPECT_EQ("key2.com", GetKeyword(key2_change.sync_data())); |
926 | 934 |
927 // The last TemplateURL should have had no conflicts and was just added. It | 935 // The last TemplateURL should have had no conflicts and was just added. It |
928 // should not have replaced the third local TemplateURL. | 936 // should not have replaced the third local TemplateURL. |
(...skipping 1076 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2005 // A local change to the Google base URL should update the keyword and | 2013 // A local change to the Google base URL should update the keyword and |
2006 // generate a sync change. | 2014 // generate a sync change. |
2007 test_util_a_.SetGoogleBaseURL(GURL("http://google.co.in/")); | 2015 test_util_a_.SetGoogleBaseURL(GURL("http://google.co.in/")); |
2008 EXPECT_EQ(ASCIIToUTF16("google.co.in"), synced_turl->keyword()); | 2016 EXPECT_EQ(ASCIIToUTF16("google.co.in"), synced_turl->keyword()); |
2009 EXPECT_EQ(1U, processor()->change_list_size()); | 2017 EXPECT_EQ(1U, processor()->change_list_size()); |
2010 ASSERT_TRUE(processor()->contains_guid("guid")); | 2018 ASSERT_TRUE(processor()->contains_guid("guid")); |
2011 syncer::SyncChange change(processor()->change_for_guid("guid")); | 2019 syncer::SyncChange change(processor()->change_for_guid("guid")); |
2012 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, change.change_type()); | 2020 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, change.change_type()); |
2013 EXPECT_EQ("google.co.in", GetKeyword(change.sync_data())); | 2021 EXPECT_EQ("google.co.in", GetKeyword(change.sync_data())); |
2014 } | 2022 } |
OLD | NEW |