| 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 <stddef.h> | 5 #include <stddef.h> |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 1146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1157 model()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES, initial_data, | 1157 model()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES, initial_data, |
| 1158 PassProcessor(), CreateAndPassSyncErrorFactory()); | 1158 PassProcessor(), CreateAndPassSyncErrorFactory()); |
| 1159 | 1159 |
| 1160 // Both entries should have been added, with explicit keywords. | 1160 // Both entries should have been added, with explicit keywords. |
| 1161 TemplateURL* key1 = model()->GetTemplateURLForHost("key1.com"); | 1161 TemplateURL* key1 = model()->GetTemplateURLForHost("key1.com"); |
| 1162 ASSERT_FALSE(key1 == NULL); | 1162 ASSERT_FALSE(key1 == NULL); |
| 1163 EXPECT_EQ(ASCIIToUTF16("key1.com"), key1->keyword()); | 1163 EXPECT_EQ(ASCIIToUTF16("key1.com"), key1->keyword()); |
| 1164 GURL google_url(model()->search_terms_data().GoogleBaseURLValue()); | 1164 GURL google_url(model()->search_terms_data().GoogleBaseURLValue()); |
| 1165 TemplateURL* key2 = model()->GetTemplateURLForHost(google_url.host()); | 1165 TemplateURL* key2 = model()->GetTemplateURLForHost(google_url.host()); |
| 1166 ASSERT_FALSE(key2 == NULL); | 1166 ASSERT_FALSE(key2 == NULL); |
| 1167 base::string16 google_keyword(url_formatter::StripWWWFromHost(google_url)); | 1167 base::string16 google_keyword(UTF8ToUTF16( |
| 1168 url_formatter::StripSubdomains(google_url, url_formatter::kStripWWW))); |
| 1168 EXPECT_EQ(google_keyword, key2->keyword()); | 1169 EXPECT_EQ(google_keyword, key2->keyword()); |
| 1169 | 1170 |
| 1170 // We should also have gotten some corresponding UPDATEs pushed upstream. | 1171 // We should also have gotten some corresponding UPDATEs pushed upstream. |
| 1171 EXPECT_GE(processor()->change_list_size(), 2U); | 1172 EXPECT_GE(processor()->change_list_size(), 2U); |
| 1172 ASSERT_TRUE(processor()->contains_guid("key1")); | 1173 ASSERT_TRUE(processor()->contains_guid("key1")); |
| 1173 syncer::SyncChange key1_change = processor()->change_for_guid("key1"); | 1174 syncer::SyncChange key1_change = processor()->change_for_guid("key1"); |
| 1174 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, key1_change.change_type()); | 1175 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, key1_change.change_type()); |
| 1175 EXPECT_EQ("key1.com", GetKeyword(key1_change.sync_data())); | 1176 EXPECT_EQ("key1.com", GetKeyword(key1_change.sync_data())); |
| 1176 ASSERT_TRUE(processor()->contains_guid("key2")); | 1177 ASSERT_TRUE(processor()->contains_guid("key2")); |
| 1177 syncer::SyncChange key2_change = processor()->change_for_guid("key2"); | 1178 syncer::SyncChange key2_change = processor()->change_for_guid("key2"); |
| 1178 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, key2_change.change_type()); | 1179 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, key2_change.change_type()); |
| 1179 EXPECT_EQ(google_keyword, UTF8ToUTF16(GetKeyword(key2_change.sync_data()))); | 1180 EXPECT_EQ(google_keyword, UTF8ToUTF16(GetKeyword(key2_change.sync_data()))); |
| 1180 } | 1181 } |
| 1181 | 1182 |
| 1182 TEST_F(TemplateURLServiceSyncTest, AutogeneratedKeywordConflicts) { | 1183 TEST_F(TemplateURLServiceSyncTest, AutogeneratedKeywordConflicts) { |
| 1183 // Sync brings in some autogenerated keywords, but the generated keywords we | 1184 // Sync brings in some autogenerated keywords, but the generated keywords we |
| 1184 // try to create conflict with ones in the model. | 1185 // try to create conflict with ones in the model. |
| 1185 base::string16 google_keyword(url_formatter::StripWWWFromHost(GURL( | 1186 base::string16 google_keyword(UTF8ToUTF16(url_formatter::StripSubdomains( |
| 1186 model()->search_terms_data().GoogleBaseURLValue()))); | 1187 GURL(model()->search_terms_data().GoogleBaseURLValue()), |
| 1188 url_formatter::kStripWWW))); |
| 1187 const std::string local_google_url = | 1189 const std::string local_google_url = |
| 1188 "{google:baseURL}1/search?q={searchTerms}"; | 1190 "{google:baseURL}1/search?q={searchTerms}"; |
| 1189 TemplateURL* google = | 1191 TemplateURL* google = |
| 1190 model()->Add(CreateTestTemplateURL(google_keyword, local_google_url)); | 1192 model()->Add(CreateTestTemplateURL(google_keyword, local_google_url)); |
| 1191 TemplateURL* other = model()->Add( | 1193 TemplateURL* other = model()->Add( |
| 1192 CreateTestTemplateURL(ASCIIToUTF16("other.com"), "http://other.com/foo")); | 1194 CreateTestTemplateURL(ASCIIToUTF16("other.com"), "http://other.com/foo")); |
| 1193 syncer::SyncDataList initial_data; | 1195 syncer::SyncDataList initial_data; |
| 1194 std::unique_ptr<TemplateURL> turl = CreateTestTemplateURL( | 1196 std::unique_ptr<TemplateURL> turl = CreateTestTemplateURL( |
| 1195 ASCIIToUTF16("sync1"), "{google:baseURL}2/search?q={searchTerms}", | 1197 ASCIIToUTF16("sync1"), "{google:baseURL}2/search?q={searchTerms}", |
| 1196 "sync1", 50); | 1198 "sync1", 50); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1249 initial_data.push_back( | 1251 initial_data.push_back( |
| 1250 CreateCustomSyncData(*turl, true, turl->url(), turl->sync_guid())); | 1252 CreateCustomSyncData(*turl, true, turl->url(), turl->sync_guid())); |
| 1251 turl = CreateTestTemplateURL( | 1253 turl = CreateTestTemplateURL( |
| 1252 ASCIIToUTF16("key2"), "{google:baseURL}2/search?q={searchTerms}", "key2"); | 1254 ASCIIToUTF16("key2"), "{google:baseURL}2/search?q={searchTerms}", "key2"); |
| 1253 initial_data.push_back( | 1255 initial_data.push_back( |
| 1254 CreateCustomSyncData(*turl, true, turl->url(), turl->sync_guid())); | 1256 CreateCustomSyncData(*turl, true, turl->url(), turl->sync_guid())); |
| 1255 model()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES, initial_data, | 1257 model()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES, initial_data, |
| 1256 PassProcessor(), CreateAndPassSyncErrorFactory()); | 1258 PassProcessor(), CreateAndPassSyncErrorFactory()); |
| 1257 | 1259 |
| 1258 // We should still have coalesced the updates to one each. | 1260 // We should still have coalesced the updates to one each. |
| 1259 base::string16 google_keyword(url_formatter::StripWWWFromHost(GURL( | 1261 base::string16 google_keyword(UTF8ToUTF16(url_formatter::StripSubdomains( |
| 1260 model()->search_terms_data().GoogleBaseURLValue()))); | 1262 GURL(model()->search_terms_data().GoogleBaseURLValue()), |
| 1263 url_formatter::kStripWWW))); |
| 1261 TemplateURL* keyword1 = | 1264 TemplateURL* keyword1 = |
| 1262 model()->GetTemplateURLForKeyword(google_keyword + ASCIIToUTF16("_")); | 1265 model()->GetTemplateURLForKeyword(google_keyword + ASCIIToUTF16("_")); |
| 1263 ASSERT_FALSE(keyword1 == NULL); | 1266 ASSERT_FALSE(keyword1 == NULL); |
| 1264 EXPECT_EQ("key1", keyword1->sync_guid()); | 1267 EXPECT_EQ("key1", keyword1->sync_guid()); |
| 1265 TemplateURL* keyword2 = model()->GetTemplateURLForKeyword(google_keyword); | 1268 TemplateURL* keyword2 = model()->GetTemplateURLForKeyword(google_keyword); |
| 1266 ASSERT_FALSE(keyword2 == NULL); | 1269 ASSERT_FALSE(keyword2 == NULL); |
| 1267 EXPECT_EQ("key2", keyword2->sync_guid()); | 1270 EXPECT_EQ("key2", keyword2->sync_guid()); |
| 1268 | 1271 |
| 1269 EXPECT_GE(processor()->change_list_size(), 2U); | 1272 EXPECT_GE(processor()->change_list_size(), 2U); |
| 1270 ASSERT_TRUE(processor()->contains_guid("key1")); | 1273 ASSERT_TRUE(processor()->contains_guid("key1")); |
| (...skipping 1213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2484 | 2487 |
| 2485 TEST_F(TemplateURLServiceSyncTest, NonAsciiKeywordDoesNotCrash) { | 2488 TEST_F(TemplateURLServiceSyncTest, NonAsciiKeywordDoesNotCrash) { |
| 2486 model()->Add(CreateTestTemplateURL(UTF8ToUTF16("\xf0\xaf\xa6\x8d"), | 2489 model()->Add(CreateTestTemplateURL(UTF8ToUTF16("\xf0\xaf\xa6\x8d"), |
| 2487 "http://key1.com")); | 2490 "http://key1.com")); |
| 2488 syncer::SyncDataList initial_data = CreateInitialSyncData(); | 2491 syncer::SyncDataList initial_data = CreateInitialSyncData(); |
| 2489 | 2492 |
| 2490 model()->MergeDataAndStartSyncing( | 2493 model()->MergeDataAndStartSyncing( |
| 2491 syncer::SEARCH_ENGINES, initial_data, PassProcessor(), | 2494 syncer::SEARCH_ENGINES, initial_data, PassProcessor(), |
| 2492 CreateAndPassSyncErrorFactory()); | 2495 CreateAndPassSyncErrorFactory()); |
| 2493 } | 2496 } |
| OLD | NEW |