| 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 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 408 | 408 |
| 409 for (syncer::SyncDataList::const_iterator iter = all_sync_data.begin(); | 409 for (syncer::SyncDataList::const_iterator iter = all_sync_data.begin(); |
| 410 iter != all_sync_data.end(); ++iter) { | 410 iter != all_sync_data.end(); ++iter) { |
| 411 std::string guid = GetGUID(*iter); | 411 std::string guid = GetGUID(*iter); |
| 412 const TemplateURL* service_turl = model()->GetTemplateURLForGUID(guid); | 412 const TemplateURL* service_turl = model()->GetTemplateURLForGUID(guid); |
| 413 scoped_ptr<TemplateURL> deserialized(Deserialize(*iter)); | 413 scoped_ptr<TemplateURL> deserialized(Deserialize(*iter)); |
| 414 AssertEquals(*service_turl, *deserialized); | 414 AssertEquals(*service_turl, *deserialized); |
| 415 } | 415 } |
| 416 } | 416 } |
| 417 | 417 |
| 418 TEST_F(TemplateURLServiceSyncTest, GetAllSyncDataNoExtensions) { | 418 TEST_F(TemplateURLServiceSyncTest, GetAllSyncDataWithExtension) { |
| 419 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("key1"), "http://key1.com")); | 419 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("key1"), "http://key1.com")); |
| 420 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("key2"), "http://key2.com")); | 420 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("key2"), "http://key2.com")); |
| 421 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("key3"), | 421 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("key3"), |
| 422 std::string(extensions::kExtensionScheme) + "://blahblahblah")); | 422 std::string(extensions::kExtensionScheme) + "://blahblahblah")); |
| 423 syncer::SyncDataList all_sync_data = | 423 syncer::SyncDataList all_sync_data = |
| 424 model()->GetAllSyncData(syncer::SEARCH_ENGINES); | 424 model()->GetAllSyncData(syncer::SEARCH_ENGINES); |
| 425 | 425 |
| 426 EXPECT_EQ(2U, all_sync_data.size()); | 426 EXPECT_EQ(3U, all_sync_data.size()); |
| 427 | 427 |
| 428 for (syncer::SyncDataList::const_iterator iter = all_sync_data.begin(); | 428 for (syncer::SyncDataList::const_iterator iter = all_sync_data.begin(); |
| 429 iter != all_sync_data.end(); ++iter) { | 429 iter != all_sync_data.end(); ++iter) { |
| 430 std::string guid = GetGUID(*iter); | 430 std::string guid = GetGUID(*iter); |
| 431 const TemplateURL* service_turl = model()->GetTemplateURLForGUID(guid); | 431 const TemplateURL* service_turl = model()->GetTemplateURLForGUID(guid); |
| 432 scoped_ptr<TemplateURL> deserialized(Deserialize(*iter)); | 432 scoped_ptr<TemplateURL> deserialized(Deserialize(*iter)); |
| 433 AssertEquals(*service_turl, *deserialized); | 433 AssertEquals(*service_turl, *deserialized); |
| 434 } | 434 } |
| 435 } | 435 } |
| 436 | 436 |
| (...skipping 639 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1076 ASSERT_TRUE(processor()->contains_guid("key2")); | 1076 ASSERT_TRUE(processor()->contains_guid("key2")); |
| 1077 change = processor()->change_for_guid("key2"); | 1077 change = processor()->change_for_guid("key2"); |
| 1078 EXPECT_EQ(syncer::SyncChange::ACTION_DELETE, change.change_type()); | 1078 EXPECT_EQ(syncer::SyncChange::ACTION_DELETE, change.change_type()); |
| 1079 } | 1079 } |
| 1080 | 1080 |
| 1081 TEST_F(TemplateURLServiceSyncTest, ProcessChangesWithLocalExtensions) { | 1081 TEST_F(TemplateURLServiceSyncTest, ProcessChangesWithLocalExtensions) { |
| 1082 model()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES, | 1082 model()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES, |
| 1083 CreateInitialSyncData(), PassProcessor(), | 1083 CreateInitialSyncData(), PassProcessor(), |
| 1084 CreateAndPassSyncErrorFactory()); | 1084 CreateAndPassSyncErrorFactory()); |
| 1085 | 1085 |
| 1086 // Add some extension keywords locally. These shouldn't be synced. | 1086 // Add some extension keywords locally. |
| 1087 TemplateURL* extension1 = CreateTestTemplateURL(ASCIIToUTF16("keyword1"), | 1087 TemplateURL* extension1 = CreateTestTemplateURL(ASCIIToUTF16("keyword1"), |
| 1088 std::string(extensions::kExtensionScheme) + "://extension1"); | 1088 std::string(extensions::kExtensionScheme) + "://extension1"); |
| 1089 model()->Add(extension1); | 1089 model()->Add(extension1); |
| 1090 EXPECT_EQ(1U, processor()->change_list_size()); |
| 1090 TemplateURL* extension2 = CreateTestTemplateURL(ASCIIToUTF16("keyword2"), | 1091 TemplateURL* extension2 = CreateTestTemplateURL(ASCIIToUTF16("keyword2"), |
| 1091 std::string(extensions::kExtensionScheme) + "://extension2"); | 1092 std::string(extensions::kExtensionScheme) + "://extension2"); |
| 1092 model()->Add(extension2); | 1093 model()->Add(extension2); |
| 1093 EXPECT_EQ(0U, processor()->change_list_size()); | 1094 EXPECT_EQ(1U, processor()->change_list_size()); |
| 1094 | 1095 |
| 1095 // Create some sync changes that will conflict with the extension keywords. | 1096 // Create some sync changes that will conflict with the extension keywords. |
| 1096 syncer::SyncChangeList changes; | 1097 syncer::SyncChangeList changes; |
| 1097 changes.push_back(CreateTestSyncChange(syncer::SyncChange::ACTION_ADD, | 1098 changes.push_back(CreateTestSyncChange(syncer::SyncChange::ACTION_ADD, |
| 1098 CreateTestTemplateURL(ASCIIToUTF16("keyword1"), "http://aaa.com", | 1099 CreateTestTemplateURL(ASCIIToUTF16("keyword1"), "http://aaa.com", |
| 1099 std::string(), 100, true))); | 1100 std::string(), 100, true))); |
| 1100 changes.push_back(CreateTestSyncChange(syncer::SyncChange::ACTION_ADD, | 1101 changes.push_back(CreateTestSyncChange(syncer::SyncChange::ACTION_ADD, |
| 1101 CreateTestTemplateURL(ASCIIToUTF16("keyword2"), "http://bbb.com"))); | 1102 CreateTestTemplateURL(ASCIIToUTF16("keyword2"), "http://bbb.com"))); |
| 1102 model()->ProcessSyncChanges(FROM_HERE, changes); | 1103 model()->ProcessSyncChanges(FROM_HERE, changes); |
| 1103 | 1104 |
| 1104 // The synced keywords should be added unchanged, and the result of | 1105 // The existing extension keywords should be uniquified. |
| 1105 // GetTemplateURLForKeyword() for each keyword should depend on whether the | 1106 EXPECT_FALSE(model()->GetTemplateURLForHost("aaa.com") == NULL); |
| 1106 // synced keyword is replaceable or not. | 1107 EXPECT_EQ(model()->GetTemplateURLForHost("aaa.com"), |
| 1107 EXPECT_EQ(extension1, | |
| 1108 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword1"))); | 1108 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword1"))); |
| 1109 EXPECT_FALSE(model()->GetTemplateURLForHost("aaa.com") == NULL); | |
| 1110 TemplateURL* url_for_keyword2 = | 1109 TemplateURL* url_for_keyword2 = |
| 1111 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword2")); | 1110 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword2")); |
| 1112 EXPECT_NE(extension2, url_for_keyword2); | 1111 EXPECT_NE(extension2, url_for_keyword2); |
| 1113 EXPECT_EQ("http://bbb.com", url_for_keyword2->url()); | 1112 EXPECT_EQ("http://bbb.com", url_for_keyword2->url()); |
| 1114 // Note that extensions don't use host-based keywords, so we can't check that | 1113 |
| 1115 // |extension2| is still in the model using GetTemplateURLForHost(); and we | 1114 // Replaced extension keywords should be uniquified. |
| 1116 // have to create a full-fledged Extension to use | 1115 EXPECT_EQ(extension1, |
| 1117 // GetTemplateURLForExtension(), which is annoying, so just grab all the URLs | 1116 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword1_"))); |
| 1118 // from the model and search for |extension2| within them. | 1117 EXPECT_EQ(extension2, |
| 1119 TemplateURLService::TemplateURLVector template_urls( | 1118 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword2_"))); |
| 1120 model()->GetTemplateURLs()); | |
| 1121 EXPECT_FALSE(std::find(template_urls.begin(), template_urls.end(), | |
| 1122 extension2) == template_urls.end()); | |
| 1123 } | 1119 } |
| 1124 | 1120 |
| 1125 TEST_F(TemplateURLServiceSyncTest, AutogeneratedKeywordMigrated) { | 1121 TEST_F(TemplateURLServiceSyncTest, AutogeneratedKeywordMigrated) { |
| 1126 // Create a couple of sync entries with autogenerated keywords. | 1122 // Create a couple of sync entries with autogenerated keywords. |
| 1127 syncer::SyncDataList initial_data; | 1123 syncer::SyncDataList initial_data; |
| 1128 scoped_ptr<TemplateURL> turl( | 1124 scoped_ptr<TemplateURL> turl( |
| 1129 CreateTestTemplateURL(ASCIIToUTF16("key1"), "http://key1.com", "key1")); | 1125 CreateTestTemplateURL(ASCIIToUTF16("key1"), "http://key1.com", "key1")); |
| 1130 initial_data.push_back( | 1126 initial_data.push_back( |
| 1131 CreateCustomSyncData(*turl, true, turl->url(), turl->sync_guid())); | 1127 CreateCustomSyncData(*turl, true, turl->url(), turl->sync_guid())); |
| 1132 turl.reset(CreateTestTemplateURL(ASCIIToUTF16("key2"), | 1128 turl.reset(CreateTestTemplateURL(ASCIIToUTF16("key2"), |
| (...skipping 1132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2265 syncer::SyncMergeResult merge_result = model()->MergeDataAndStartSyncing( | 2261 syncer::SyncMergeResult merge_result = model()->MergeDataAndStartSyncing( |
| 2266 syncer::SEARCH_ENGINES, list, PassProcessor(), | 2262 syncer::SEARCH_ENGINES, list, PassProcessor(), |
| 2267 CreateAndPassSyncErrorFactory()); | 2263 CreateAndPassSyncErrorFactory()); |
| 2268 | 2264 |
| 2269 const TemplateURL* result_turl = model()->GetTemplateURLForGUID("default"); | 2265 const TemplateURL* result_turl = model()->GetTemplateURLForGUID("default"); |
| 2270 EXPECT_TRUE(result_turl); | 2266 EXPECT_TRUE(result_turl); |
| 2271 EXPECT_EQ(default_turl->keyword(), result_turl->keyword()); | 2267 EXPECT_EQ(default_turl->keyword(), result_turl->keyword()); |
| 2272 EXPECT_EQ(default_turl->short_name(), result_turl->short_name()); | 2268 EXPECT_EQ(default_turl->short_name(), result_turl->short_name()); |
| 2273 EXPECT_EQ(default_turl->url(), result_turl->url()); | 2269 EXPECT_EQ(default_turl->url(), result_turl->url()); |
| 2274 } | 2270 } |
| OLD | NEW |