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 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
199 // involve syncing two models. | 199 // involve syncing two models. |
200 TemplateURLService* model_a() { return test_util_a_->model(); } | 200 TemplateURLService* model_a() { return test_util_a_->model(); } |
201 TemplateURLService* model_b() { return test_util_b_->model(); } | 201 TemplateURLService* model_b() { return test_util_b_->model(); } |
202 TestingProfile* profile_a() { return test_util_a_->profile(); } | 202 TestingProfile* profile_a() { return test_util_a_->profile(); } |
203 TestChangeProcessor* processor() { return sync_processor_.get(); } | 203 TestChangeProcessor* processor() { return sync_processor_.get(); } |
204 std::unique_ptr<syncer::SyncChangeProcessor> PassProcessor(); | 204 std::unique_ptr<syncer::SyncChangeProcessor> PassProcessor(); |
205 std::unique_ptr<syncer::SyncErrorFactory> CreateAndPassSyncErrorFactory(); | 205 std::unique_ptr<syncer::SyncErrorFactory> CreateAndPassSyncErrorFactory(); |
206 | 206 |
207 // Creates a TemplateURL with some test values. The caller owns the returned | 207 // Creates a TemplateURL with some test values. The caller owns the returned |
208 // TemplateURL*. | 208 // TemplateURL*. |
209 TemplateURL* CreateTestTemplateURL(const base::string16& keyword, | 209 std::unique_ptr<TemplateURL> CreateTestTemplateURL( |
210 const std::string& url, | 210 const base::string16& keyword, |
211 const std::string& guid = std::string(), | 211 const std::string& url, |
212 time_t last_mod = 100, | 212 const std::string& guid = std::string(), |
213 bool safe_for_autoreplace = false, | 213 time_t last_mod = 100, |
214 bool created_by_policy = false, | 214 bool safe_for_autoreplace = false, |
215 int prepopulate_id = 999999) const; | 215 bool created_by_policy = false, |
216 int prepopulate_id = 999999) const; | |
216 | 217 |
217 // Verifies the two TemplateURLs are equal. | 218 // Verifies the two TemplateURLs are equal. |
218 // TODO(stevet): Share this with TemplateURLServiceTest. | 219 // TODO(stevet): Share this with TemplateURLServiceTest. |
219 void AssertEquals(const TemplateURL& expected, | 220 void AssertEquals(const TemplateURL& expected, |
220 const TemplateURL& actual) const; | 221 const TemplateURL& actual) const; |
221 | 222 |
222 // Expect that two syncer::SyncDataLists have equal contents, in terms of the | 223 // Expect that two syncer::SyncDataLists have equal contents, in terms of the |
223 // sync_guid, keyword, and url fields. | 224 // sync_guid, keyword, and url fields. |
224 void AssertEquals(const syncer::SyncDataList& data1, | 225 void AssertEquals(const syncer::SyncDataList& data1, |
225 const syncer::SyncDataList& data2) const; | 226 const syncer::SyncDataList& data2) const; |
226 | 227 |
227 // Convenience helper for creating SyncChanges. Takes ownership of |turl|. | 228 // Convenience helper for creating SyncChanges. Takes ownership of |turl|. |
228 syncer::SyncChange CreateTestSyncChange( | 229 syncer::SyncChange CreateTestSyncChange( |
229 syncer::SyncChange::SyncChangeType type, | 230 syncer::SyncChange::SyncChangeType type, |
230 TemplateURL* turl) const; | 231 std::unique_ptr<TemplateURL> turl) const; |
231 | 232 |
232 // Helper that creates some initial sync data. We cheat a little by specifying | 233 // Helper that creates some initial sync data. We cheat a little by specifying |
233 // GUIDs for easy identification later. We also make the last_modified times | 234 // GUIDs for easy identification later. We also make the last_modified times |
234 // slightly older than CreateTestTemplateURL's default, to test conflict | 235 // slightly older than CreateTestTemplateURL's default, to test conflict |
235 // resolution. | 236 // resolution. |
236 syncer::SyncDataList CreateInitialSyncData() const; | 237 syncer::SyncDataList CreateInitialSyncData() const; |
237 | 238 |
238 // Syntactic sugar. | 239 // Syntactic sugar. |
239 std::unique_ptr<TemplateURL> Deserialize(const syncer::SyncData& sync_data); | 240 std::unique_ptr<TemplateURL> Deserialize(const syncer::SyncData& sync_data); |
240 | 241 |
241 // Creates a new TemplateURL copying the fields of |turl| but replacing | 242 // Creates a new TemplateURL copying the fields of |turl| but replacing |
242 // the |url| and |guid| and initializing the date_created and last_modified | 243 // the |url| and |guid| and initializing the date_created and last_modified |
243 // timestamps to a default value of 100. The caller owns the returned | 244 // timestamps to a default value of 100. |
244 // TemplateURL*. | 245 std::unique_ptr<TemplateURL> CopyTemplateURL(const TemplateURLData* turl, |
245 TemplateURL* CopyTemplateURL(const TemplateURLData* turl, | 246 const std::string& url, |
246 const std::string& url, | 247 const std::string& guid); |
247 const std::string& guid); | |
248 | 248 |
249 protected: | 249 protected: |
250 content::TestBrowserThreadBundle thread_bundle_; | 250 content::TestBrowserThreadBundle thread_bundle_; |
251 // We keep two TemplateURLServices to test syncing between them. | 251 // We keep two TemplateURLServices to test syncing between them. |
252 std::unique_ptr<TemplateURLServiceTestUtil> test_util_a_; | 252 std::unique_ptr<TemplateURLServiceTestUtil> test_util_a_; |
253 std::unique_ptr<TemplateURLServiceTestUtil> test_util_b_; | 253 std::unique_ptr<TemplateURLServiceTestUtil> test_util_b_; |
254 | 254 |
255 // Our dummy ChangeProcessor used to inspect changes pushed to Sync. | 255 // Our dummy ChangeProcessor used to inspect changes pushed to Sync. |
256 std::unique_ptr<TestChangeProcessor> sync_processor_; | 256 std::unique_ptr<TestChangeProcessor> sync_processor_; |
257 std::unique_ptr<syncer::SyncChangeProcessorWrapperForTest> | 257 std::unique_ptr<syncer::SyncChangeProcessorWrapperForTest> |
(...skipping 28 matching lines...) Expand all Loading... | |
286 TemplateURLServiceSyncTest::PassProcessor() { | 286 TemplateURLServiceSyncTest::PassProcessor() { |
287 return std::move(sync_processor_wrapper_); | 287 return std::move(sync_processor_wrapper_); |
288 } | 288 } |
289 | 289 |
290 std::unique_ptr<syncer::SyncErrorFactory> | 290 std::unique_ptr<syncer::SyncErrorFactory> |
291 TemplateURLServiceSyncTest::CreateAndPassSyncErrorFactory() { | 291 TemplateURLServiceSyncTest::CreateAndPassSyncErrorFactory() { |
292 return std::unique_ptr<syncer::SyncErrorFactory>( | 292 return std::unique_ptr<syncer::SyncErrorFactory>( |
293 new syncer::SyncErrorFactoryMock()); | 293 new syncer::SyncErrorFactoryMock()); |
294 } | 294 } |
295 | 295 |
296 TemplateURL* TemplateURLServiceSyncTest::CreateTestTemplateURL( | 296 std::unique_ptr<TemplateURL> TemplateURLServiceSyncTest::CreateTestTemplateURL( |
297 const base::string16& keyword, | 297 const base::string16& keyword, |
298 const std::string& url, | 298 const std::string& url, |
299 const std::string& guid, | 299 const std::string& guid, |
300 time_t last_mod, | 300 time_t last_mod, |
301 bool safe_for_autoreplace, | 301 bool safe_for_autoreplace, |
302 bool created_by_policy, | 302 bool created_by_policy, |
303 int prepopulate_id) const { | 303 int prepopulate_id) const { |
304 TemplateURLData data; | 304 TemplateURLData data; |
305 data.SetShortName(ASCIIToUTF16("unittest")); | 305 data.SetShortName(ASCIIToUTF16("unittest")); |
306 data.SetKeyword(keyword); | 306 data.SetKeyword(keyword); |
307 data.SetURL(url); | 307 data.SetURL(url); |
308 data.favicon_url = GURL("http://favicon.url"); | 308 data.favicon_url = GURL("http://favicon.url"); |
309 data.safe_for_autoreplace = safe_for_autoreplace; | 309 data.safe_for_autoreplace = safe_for_autoreplace; |
310 data.date_created = Time::FromTimeT(100); | 310 data.date_created = Time::FromTimeT(100); |
311 data.last_modified = Time::FromTimeT(last_mod); | 311 data.last_modified = Time::FromTimeT(last_mod); |
312 data.created_by_policy = created_by_policy; | 312 data.created_by_policy = created_by_policy; |
313 data.prepopulate_id = prepopulate_id; | 313 data.prepopulate_id = prepopulate_id; |
314 if (!guid.empty()) | 314 if (!guid.empty()) |
315 data.sync_guid = guid; | 315 data.sync_guid = guid; |
316 return new TemplateURL(data); | 316 return base::MakeUnique<TemplateURL>(data); |
317 } | 317 } |
318 | 318 |
319 void TemplateURLServiceSyncTest::AssertEquals(const TemplateURL& expected, | 319 void TemplateURLServiceSyncTest::AssertEquals(const TemplateURL& expected, |
320 const TemplateURL& actual) const { | 320 const TemplateURL& actual) const { |
321 ASSERT_EQ(expected.short_name(), actual.short_name()); | 321 ASSERT_EQ(expected.short_name(), actual.short_name()); |
322 ASSERT_EQ(expected.keyword(), actual.keyword()); | 322 ASSERT_EQ(expected.keyword(), actual.keyword()); |
323 ASSERT_EQ(expected.url(), actual.url()); | 323 ASSERT_EQ(expected.url(), actual.url()); |
324 ASSERT_EQ(expected.suggestions_url(), actual.suggestions_url()); | 324 ASSERT_EQ(expected.suggestions_url(), actual.suggestions_url()); |
325 ASSERT_EQ(expected.favicon_url(), actual.favicon_url()); | 325 ASSERT_EQ(expected.favicon_url(), actual.favicon_url()); |
326 ASSERT_EQ(expected.show_in_default_list(), actual.show_in_default_list()); | 326 ASSERT_EQ(expected.show_in_default_list(), actual.show_in_default_list()); |
(...skipping 16 matching lines...) Expand all Loading... | |
343 ASSERT_EQ(GetKeyword(iter1->second), GetKeyword(iter2->second)); | 343 ASSERT_EQ(GetKeyword(iter1->second), GetKeyword(iter2->second)); |
344 ASSERT_EQ(GetURL(iter1->second), GetURL(iter2->second)); | 344 ASSERT_EQ(GetURL(iter1->second), GetURL(iter2->second)); |
345 map2.erase(iter2); | 345 map2.erase(iter2); |
346 } | 346 } |
347 } | 347 } |
348 EXPECT_EQ(0U, map2.size()); | 348 EXPECT_EQ(0U, map2.size()); |
349 } | 349 } |
350 | 350 |
351 syncer::SyncChange TemplateURLServiceSyncTest::CreateTestSyncChange( | 351 syncer::SyncChange TemplateURLServiceSyncTest::CreateTestSyncChange( |
352 syncer::SyncChange::SyncChangeType type, | 352 syncer::SyncChange::SyncChangeType type, |
353 TemplateURL* turl) const { | 353 std::unique_ptr<TemplateURL> turl) const { |
354 // We take control of the TemplateURL so make sure it's cleaned up after | |
355 // we create data out of it. | |
356 std::unique_ptr<TemplateURL> scoped_turl(turl); | |
357 return syncer::SyncChange( | 354 return syncer::SyncChange( |
358 FROM_HERE, | 355 FROM_HERE, type, |
359 type, | 356 TemplateURLService::CreateSyncDataFromTemplateURL(*turl)); |
360 TemplateURLService::CreateSyncDataFromTemplateURL(*scoped_turl)); | |
361 } | 357 } |
362 | 358 |
363 syncer::SyncDataList TemplateURLServiceSyncTest::CreateInitialSyncData() const { | 359 syncer::SyncDataList TemplateURLServiceSyncTest::CreateInitialSyncData() const { |
364 syncer::SyncDataList list; | 360 syncer::SyncDataList list; |
365 | 361 |
366 std::unique_ptr<TemplateURL> turl(CreateTestTemplateURL( | 362 std::unique_ptr<TemplateURL> turl = CreateTestTemplateURL( |
367 ASCIIToUTF16("key1"), "http://key1.com", "key1", 90)); | 363 ASCIIToUTF16("key1"), "http://key1.com", "key1", 90); |
368 list.push_back(TemplateURLService::CreateSyncDataFromTemplateURL(*turl)); | 364 list.push_back( |
369 turl.reset(CreateTestTemplateURL(ASCIIToUTF16("key2"), "http://key2.com", | 365 TemplateURLService::CreateSyncDataFromTemplateURL(*turl.get())); |
370 "key2", 90)); | 366 turl = CreateTestTemplateURL(ASCIIToUTF16("key2"), "http://key2.com", "key2", |
371 list.push_back(TemplateURLService::CreateSyncDataFromTemplateURL(*turl)); | 367 90); |
372 turl.reset(CreateTestTemplateURL(ASCIIToUTF16("key3"), "http://key3.com", | 368 list.push_back( |
373 "key3", 90)); | 369 TemplateURLService::CreateSyncDataFromTemplateURL(*turl.get())); |
374 list.push_back(TemplateURLService::CreateSyncDataFromTemplateURL(*turl)); | 370 turl = CreateTestTemplateURL(ASCIIToUTF16("key3"), "http://key3.com", "key3", |
371 90); | |
372 list.push_back( | |
373 TemplateURLService::CreateSyncDataFromTemplateURL(*turl.get())); | |
375 | 374 |
376 return list; | 375 return list; |
377 } | 376 } |
378 | 377 |
379 std::unique_ptr<TemplateURL> TemplateURLServiceSyncTest::Deserialize( | 378 std::unique_ptr<TemplateURL> TemplateURLServiceSyncTest::Deserialize( |
380 const syncer::SyncData& sync_data) { | 379 const syncer::SyncData& sync_data) { |
381 syncer::SyncChangeList dummy; | 380 syncer::SyncChangeList dummy; |
382 TestTemplateURLServiceClient client; | 381 TestTemplateURLServiceClient client; |
383 return TemplateURLService::CreateTemplateURLFromTemplateURLAndSyncData( | 382 return TemplateURLService::CreateTemplateURLFromTemplateURLAndSyncData( |
384 &client, NULL, SearchTermsData(), NULL, sync_data, &dummy); | 383 &client, NULL, SearchTermsData(), NULL, sync_data, &dummy); |
385 } | 384 } |
386 | 385 |
387 TemplateURL* TemplateURLServiceSyncTest::CopyTemplateURL( | 386 std::unique_ptr<TemplateURL> TemplateURLServiceSyncTest::CopyTemplateURL( |
388 const TemplateURLData* turl, | 387 const TemplateURLData* turl, |
389 const std::string& url, | 388 const std::string& url, |
390 const std::string& guid) { | 389 const std::string& guid) { |
391 TemplateURLData data = *turl; | 390 TemplateURLData data = *turl; |
392 data.SetURL(url); | 391 data.SetURL(url); |
393 data.date_created = Time::FromTimeT(100); | 392 data.date_created = Time::FromTimeT(100); |
394 data.last_modified = Time::FromTimeT(100); | 393 data.last_modified = Time::FromTimeT(100); |
395 data.sync_guid = guid; | 394 data.sync_guid = guid; |
396 return new TemplateURL(data); | 395 return base::MakeUnique<TemplateURL>(data); |
397 } | 396 } |
398 | 397 |
399 // Actual tests --------------------------------------------------------------- | 398 // Actual tests --------------------------------------------------------------- |
400 | 399 |
401 TEST_F(TemplateURLServiceSyncTest, SerializeDeserialize) { | 400 TEST_F(TemplateURLServiceSyncTest, SerializeDeserialize) { |
402 // Create a TemplateURL and convert it into a sync specific type. | 401 // Create a TemplateURL and convert it into a sync specific type. |
403 std::unique_ptr<TemplateURL> turl(CreateTestTemplateURL( | 402 std::unique_ptr<TemplateURL> turl(CreateTestTemplateURL( |
404 ASCIIToUTF16("unittest"), "http://www.unittest.com/")); | 403 ASCIIToUTF16("unittest"), "http://www.unittest.com/")); |
405 syncer::SyncData sync_data = | 404 syncer::SyncData sync_data = |
406 TemplateURLService::CreateSyncDataFromTemplateURL(*turl); | 405 TemplateURLService::CreateSyncDataFromTemplateURL(*turl); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
445 std::string guid = GetGUID(*iter); | 444 std::string guid = GetGUID(*iter); |
446 const TemplateURL* service_turl = model()->GetTemplateURLForGUID(guid); | 445 const TemplateURL* service_turl = model()->GetTemplateURLForGUID(guid); |
447 std::unique_ptr<TemplateURL> deserialized(Deserialize(*iter)); | 446 std::unique_ptr<TemplateURL> deserialized(Deserialize(*iter)); |
448 AssertEquals(*service_turl, *deserialized); | 447 AssertEquals(*service_turl, *deserialized); |
449 } | 448 } |
450 } | 449 } |
451 | 450 |
452 TEST_F(TemplateURLServiceSyncTest, GetAllSyncDataNoManagedEngines) { | 451 TEST_F(TemplateURLServiceSyncTest, GetAllSyncDataNoManagedEngines) { |
453 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("key1"), "http://key1.com")); | 452 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("key1"), "http://key1.com")); |
454 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("key2"), "http://key2.com")); | 453 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("key2"), "http://key2.com")); |
455 TemplateURL* managed_turl = CreateTestTemplateURL(ASCIIToUTF16("key3"), | 454 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("key3"), "http://key3.com", |
456 "http://key3.com", std::string(), 100, false, true); | 455 std::string(), 100, false, true)); |
457 model()->Add(managed_turl); | |
458 syncer::SyncDataList all_sync_data = | 456 syncer::SyncDataList all_sync_data = |
459 model()->GetAllSyncData(syncer::SEARCH_ENGINES); | 457 model()->GetAllSyncData(syncer::SEARCH_ENGINES); |
460 | 458 |
461 EXPECT_EQ(2U, all_sync_data.size()); | 459 EXPECT_EQ(2U, all_sync_data.size()); |
462 | 460 |
463 for (syncer::SyncDataList::const_iterator iter = all_sync_data.begin(); | 461 for (syncer::SyncDataList::const_iterator iter = all_sync_data.begin(); |
464 iter != all_sync_data.end(); ++iter) { | 462 iter != all_sync_data.end(); ++iter) { |
465 std::string guid = GetGUID(*iter); | 463 std::string guid = GetGUID(*iter); |
466 TemplateURL* service_turl = model()->GetTemplateURLForGUID(guid); | 464 TemplateURL* service_turl = model()->GetTemplateURLForGUID(guid); |
467 std::unique_ptr<TemplateURL> deserialized(Deserialize(*iter)); | 465 std::unique_ptr<TemplateURL> deserialized(Deserialize(*iter)); |
468 ASSERT_FALSE(service_turl->created_by_policy()); | 466 ASSERT_FALSE(service_turl->created_by_policy()); |
469 AssertEquals(*service_turl, *deserialized); | 467 AssertEquals(*service_turl, *deserialized); |
470 } | 468 } |
471 } | 469 } |
472 | 470 |
473 TEST_F(TemplateURLServiceSyncTest, UniquifyKeyword) { | 471 TEST_F(TemplateURLServiceSyncTest, UniquifyKeyword) { |
474 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("key1"), "http://key1.com")); | 472 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("key1"), "http://key1.com")); |
475 // Create a key that conflicts with something in the model. | 473 // Create a key that conflicts with something in the model. |
476 std::unique_ptr<TemplateURL> turl( | 474 std::unique_ptr<TemplateURL> turl = |
477 CreateTestTemplateURL(ASCIIToUTF16("key1"), "http://new.com", "xyz")); | 475 CreateTestTemplateURL(ASCIIToUTF16("key1"), "http://new.com", "xyz"); |
478 base::string16 new_keyword = model()->UniquifyKeyword(*turl, false); | 476 base::string16 new_keyword = model()->UniquifyKeyword(*turl, false); |
479 EXPECT_EQ(ASCIIToUTF16("new.com"), new_keyword); | 477 EXPECT_EQ(ASCIIToUTF16("new.com"), new_keyword); |
480 EXPECT_EQ(NULL, model()->GetTemplateURLForKeyword(new_keyword)); | 478 EXPECT_EQ(NULL, model()->GetTemplateURLForKeyword(new_keyword)); |
481 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("new.com"), "http://new.com", | 479 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("new.com"), "http://new.com", |
482 "xyz")); | 480 "xyz")); |
483 | 481 |
484 // Test a second collision. This time it should be resolved by actually | 482 // Test a second collision. This time it should be resolved by actually |
485 // modifying the original keyword, since the autogenerated keyword is already | 483 // modifying the original keyword, since the autogenerated keyword is already |
486 // used. | 484 // used. |
487 turl.reset(CreateTestTemplateURL(ASCIIToUTF16("key1"), "http://new.com")); | 485 turl = CreateTestTemplateURL(ASCIIToUTF16("key1"), "http://new.com"); |
488 new_keyword = model()->UniquifyKeyword(*turl, false); | 486 new_keyword = model()->UniquifyKeyword(*turl, false); |
489 EXPECT_EQ(ASCIIToUTF16("key1_"), new_keyword); | 487 EXPECT_EQ(ASCIIToUTF16("key1_"), new_keyword); |
490 EXPECT_EQ(NULL, model()->GetTemplateURLForKeyword(new_keyword)); | 488 EXPECT_EQ(NULL, model()->GetTemplateURLForKeyword(new_keyword)); |
491 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("key1_"), "http://new.com")); | 489 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("key1_"), "http://new.com")); |
492 | 490 |
493 // Test a third collision. This should collide on both the autogenerated | 491 // Test a third collision. This should collide on both the autogenerated |
494 // keyword and the first uniquification attempt. | 492 // keyword and the first uniquification attempt. |
495 turl.reset(CreateTestTemplateURL(ASCIIToUTF16("key1"), "http://new.com")); | 493 turl = CreateTestTemplateURL(ASCIIToUTF16("key1"), "http://new.com"); |
496 new_keyword = model()->UniquifyKeyword(*turl, false); | 494 new_keyword = model()->UniquifyKeyword(*turl, false); |
497 EXPECT_EQ(ASCIIToUTF16("key1__"), new_keyword); | 495 EXPECT_EQ(ASCIIToUTF16("key1__"), new_keyword); |
498 EXPECT_EQ(NULL, model()->GetTemplateURLForKeyword(new_keyword)); | 496 EXPECT_EQ(NULL, model()->GetTemplateURLForKeyword(new_keyword)); |
499 | 497 |
500 // If we force the method, it should uniquify the keyword even if it is | 498 // If we force the method, it should uniquify the keyword even if it is |
501 // currently unique, and skip the host-based autogenerated keyword. | 499 // currently unique, and skip the host-based autogenerated keyword. |
502 turl.reset( | 500 turl = CreateTestTemplateURL(ASCIIToUTF16("unique"), "http://unique.com"); |
503 CreateTestTemplateURL(ASCIIToUTF16("unique"), "http://unique.com")); | |
504 new_keyword = model()->UniquifyKeyword(*turl, true); | 501 new_keyword = model()->UniquifyKeyword(*turl, true); |
505 EXPECT_EQ(ASCIIToUTF16("unique_"), new_keyword); | 502 EXPECT_EQ(ASCIIToUTF16("unique_"), new_keyword); |
506 EXPECT_EQ(NULL, model()->GetTemplateURLForKeyword(new_keyword)); | 503 EXPECT_EQ(NULL, model()->GetTemplateURLForKeyword(new_keyword)); |
507 } | 504 } |
508 | 505 |
509 TEST_F(TemplateURLServiceSyncTest, IsLocalTemplateURLBetter) { | 506 TEST_F(TemplateURLServiceSyncTest, IsLocalTemplateURLBetter) { |
510 // Test some edge cases of this function. | 507 // Test some edge cases of this function. |
511 const struct { | 508 const struct { |
512 time_t local_time; | 509 time_t local_time; |
513 time_t sync_time; | 510 time_t sync_time; |
514 bool local_is_default; | 511 bool local_is_default; |
515 bool local_created_by_policy; | 512 bool local_created_by_policy; |
516 bool expected_result; | 513 bool expected_result; |
517 } test_cases[] = { | 514 } test_cases[] = { |
518 // Sync is better by timestamp but local is Default. | 515 // Sync is better by timestamp but local is Default. |
519 {10, 100, true, false, true}, | 516 {10, 100, true, false, true}, |
520 // Sync is better by timestamp but local is Create by Policy. | 517 // Sync is better by timestamp but local is Create by Policy. |
521 {10, 100, false, true, true}, | 518 {10, 100, false, true, true}, |
522 // Tie. Sync wins. | 519 // Tie. Sync wins. |
523 {100, 100, false, false, false}, | 520 {100, 100, false, false, false}, |
524 }; | 521 }; |
525 | 522 |
526 for (size_t i = 0; i < arraysize(test_cases); ++i) { | 523 for (size_t i = 0; i < arraysize(test_cases); ++i) { |
527 TemplateURL* local_turl = CreateTestTemplateURL( | 524 std::unique_ptr<TemplateURL> local_turl_ptr = CreateTestTemplateURL( |
Peter Kasting
2016/08/31 04:12:55
Nit: It's not a big deal, but in places like this,
Avi (use Gerrit)
2016/09/01 00:34:26
Fixed.
| |
528 ASCIIToUTF16("localkey"), "www.local.com", "localguid", | 525 ASCIIToUTF16("localkey"), "www.local.com", "localguid", |
529 test_cases[i].local_time, true, test_cases[i].local_created_by_policy); | 526 test_cases[i].local_time, true, test_cases[i].local_created_by_policy); |
530 model()->Add(local_turl); | 527 TemplateURL* local_turl = local_turl_ptr.get(); |
528 model()->Add(std::move(local_turl_ptr)); | |
531 if (test_cases[i].local_is_default) | 529 if (test_cases[i].local_is_default) |
532 model()->SetUserSelectedDefaultSearchProvider(local_turl); | 530 model()->SetUserSelectedDefaultSearchProvider(local_turl); |
533 | 531 |
534 std::unique_ptr<TemplateURL> sync_turl( | 532 std::unique_ptr<TemplateURL> sync_turl( |
535 CreateTestTemplateURL(ASCIIToUTF16("synckey"), "www.sync.com", | 533 CreateTestTemplateURL(ASCIIToUTF16("synckey"), "www.sync.com", |
536 "syncguid", test_cases[i].sync_time)); | 534 "syncguid", test_cases[i].sync_time)); |
537 EXPECT_EQ(test_cases[i].expected_result, | 535 EXPECT_EQ(test_cases[i].expected_result, |
538 model()->IsLocalTemplateURLBetter(local_turl, sync_turl.get())); | 536 model()->IsLocalTemplateURLBetter(local_turl, sync_turl.get())); |
539 | 537 |
540 // Undo the changes. | 538 // Undo the changes. |
541 if (test_cases[i].local_is_default) | 539 if (test_cases[i].local_is_default) |
542 model()->SetUserSelectedDefaultSearchProvider(NULL); | 540 model()->SetUserSelectedDefaultSearchProvider(NULL); |
543 model()->Remove(local_turl); | 541 model()->Remove(local_turl); |
544 } | 542 } |
545 } | 543 } |
546 | 544 |
547 TEST_F(TemplateURLServiceSyncTest, ResolveSyncKeywordConflict) { | 545 TEST_F(TemplateURLServiceSyncTest, ResolveSyncKeywordConflict) { |
548 // This tests cases where neither the sync nor the local TemplateURL are | 546 // This tests cases where neither the sync nor the local TemplateURL are |
549 // marked safe_for_autoreplace. | 547 // marked safe_for_autoreplace. |
550 | 548 |
551 // Create a keyword that conflicts, and make it older. Sync keyword is | 549 // Create a keyword that conflicts, and make it older. Sync keyword is |
552 // uniquified, and a syncer::SyncChange is added. | 550 // uniquified, and a syncer::SyncChange is added. |
553 base::string16 original_turl_keyword = ASCIIToUTF16("key1"); | 551 base::string16 original_turl_keyword = ASCIIToUTF16("key1"); |
554 TemplateURL* original_turl = CreateTestTemplateURL(original_turl_keyword, | 552 std::unique_ptr<TemplateURL> original_turl_ptr = CreateTestTemplateURL( |
555 "http://key1.com", std::string(), 9000); | 553 original_turl_keyword, "http://key1.com", std::string(), 9000); |
556 model()->Add(original_turl); | 554 TemplateURL* original_turl = original_turl_ptr.get(); |
555 model()->Add(std::move(original_turl_ptr)); | |
557 std::unique_ptr<TemplateURL> sync_turl(CreateTestTemplateURL( | 556 std::unique_ptr<TemplateURL> sync_turl(CreateTestTemplateURL( |
558 original_turl_keyword, "http://new.com", "remote", 8999)); | 557 original_turl_keyword, "http://new.com", "remote", 8999)); |
559 syncer::SyncChangeList changes; | 558 syncer::SyncChangeList changes; |
560 model()->ResolveSyncKeywordConflict(sync_turl.get(), original_turl, &changes); | 559 model()->ResolveSyncKeywordConflict(sync_turl.get(), original_turl, &changes); |
561 EXPECT_NE(original_turl_keyword, sync_turl->keyword()); | 560 EXPECT_NE(original_turl_keyword, sync_turl->keyword()); |
562 EXPECT_EQ(original_turl_keyword, original_turl->keyword()); | 561 EXPECT_EQ(original_turl_keyword, original_turl->keyword()); |
563 ASSERT_EQ(1U, changes.size()); | 562 ASSERT_EQ(1U, changes.size()); |
564 EXPECT_EQ("remote", GetGUID(changes[0].sync_data())); | 563 EXPECT_EQ("remote", GetGUID(changes[0].sync_data())); |
565 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, changes[0].change_type()); | 564 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, changes[0].change_type()); |
566 changes.clear(); | 565 changes.clear(); |
567 model()->Remove(original_turl); | 566 model()->Remove(original_turl); |
568 | 567 |
569 // Sync is newer. Original TemplateURL keyword is uniquified. A SyncChange | 568 // Sync is newer. Original TemplateURL keyword is uniquified. A SyncChange |
570 // is added (which in a normal run would be deleted by PruneSyncChanges() when | 569 // is added (which in a normal run would be deleted by PruneSyncChanges() when |
571 // the local GUID doesn't appear in the sync GUID list). Also ensure that | 570 // the local GUID doesn't appear in the sync GUID list). Also ensure that |
572 // this does not change the safe_for_autoreplace flag or the TemplateURLID in | 571 // this does not change the safe_for_autoreplace flag or the TemplateURLID in |
573 // the original. | 572 // the original. |
574 original_turl = CreateTestTemplateURL(original_turl_keyword, | 573 original_turl_ptr = CreateTestTemplateURL(original_turl_keyword, |
575 "http://key1.com", "local", 9000); | 574 "http://key1.com", "local", 9000); |
576 model()->Add(original_turl); | 575 original_turl = original_turl_ptr.get(); |
576 model()->Add(std::move(original_turl_ptr)); | |
577 TemplateURLID original_id = original_turl->id(); | 577 TemplateURLID original_id = original_turl->id(); |
578 sync_turl.reset(CreateTestTemplateURL(original_turl_keyword, "http://new.com", | 578 sync_turl = CreateTestTemplateURL(original_turl_keyword, "http://new.com", |
579 std::string(), 9001)); | 579 std::string(), 9001); |
580 model()->ResolveSyncKeywordConflict(sync_turl.get(), original_turl, &changes); | 580 model()->ResolveSyncKeywordConflict(sync_turl.get(), original_turl, &changes); |
581 EXPECT_EQ(original_turl_keyword, sync_turl->keyword()); | 581 EXPECT_EQ(original_turl_keyword, sync_turl->keyword()); |
582 EXPECT_NE(original_turl_keyword, original_turl->keyword()); | 582 EXPECT_NE(original_turl_keyword, original_turl->keyword()); |
583 EXPECT_FALSE(original_turl->safe_for_autoreplace()); | 583 EXPECT_FALSE(original_turl->safe_for_autoreplace()); |
584 EXPECT_EQ(original_id, original_turl->id()); | 584 EXPECT_EQ(original_id, original_turl->id()); |
585 EXPECT_EQ(NULL, model()->GetTemplateURLForKeyword(original_turl_keyword)); | 585 EXPECT_EQ(NULL, model()->GetTemplateURLForKeyword(original_turl_keyword)); |
586 ASSERT_EQ(1U, changes.size()); | 586 ASSERT_EQ(1U, changes.size()); |
587 EXPECT_EQ("local", GetGUID(changes[0].sync_data())); | 587 EXPECT_EQ("local", GetGUID(changes[0].sync_data())); |
588 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, changes[0].change_type()); | 588 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, changes[0].change_type()); |
589 changes.clear(); | 589 changes.clear(); |
590 model()->Remove(original_turl); | 590 model()->Remove(original_turl); |
591 | 591 |
592 // Equal times. Same result as above. Sync left alone, original uniquified so | 592 // Equal times. Same result as above. Sync left alone, original uniquified so |
593 // sync_turl can fit. | 593 // sync_turl can fit. |
594 original_turl = CreateTestTemplateURL(original_turl_keyword, | 594 original_turl_ptr = CreateTestTemplateURL(original_turl_keyword, |
595 "http://key1.com", "local2", 9000); | 595 "http://key1.com", "local2", 9000); |
596 model()->Add(original_turl); | 596 original_turl = original_turl_ptr.get(); |
597 sync_turl.reset(CreateTestTemplateURL(original_turl_keyword, "http://new.com", | 597 model()->Add(std::move(original_turl_ptr)); |
598 std::string(), 9000)); | 598 sync_turl = CreateTestTemplateURL(original_turl_keyword, "http://new.com", |
599 std::string(), 9000); | |
599 model()->ResolveSyncKeywordConflict(sync_turl.get(), original_turl, &changes); | 600 model()->ResolveSyncKeywordConflict(sync_turl.get(), original_turl, &changes); |
600 EXPECT_EQ(original_turl_keyword, sync_turl->keyword()); | 601 EXPECT_EQ(original_turl_keyword, sync_turl->keyword()); |
601 EXPECT_NE(original_turl_keyword, original_turl->keyword()); | 602 EXPECT_NE(original_turl_keyword, original_turl->keyword()); |
602 EXPECT_EQ(NULL, model()->GetTemplateURLForKeyword(original_turl_keyword)); | 603 EXPECT_EQ(NULL, model()->GetTemplateURLForKeyword(original_turl_keyword)); |
603 ASSERT_EQ(1U, changes.size()); | 604 ASSERT_EQ(1U, changes.size()); |
604 EXPECT_EQ("local2", GetGUID(changes[0].sync_data())); | 605 EXPECT_EQ("local2", GetGUID(changes[0].sync_data())); |
605 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, changes[0].change_type()); | 606 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, changes[0].change_type()); |
606 changes.clear(); | 607 changes.clear(); |
607 model()->Remove(original_turl); | 608 model()->Remove(original_turl); |
608 | 609 |
609 // Sync is newer, but original TemplateURL is created by policy, so it wins. | 610 // Sync is newer, but original TemplateURL is created by policy, so it wins. |
610 // Sync keyword is uniquified, and a syncer::SyncChange is added. | 611 // Sync keyword is uniquified, and a syncer::SyncChange is added. |
611 original_turl = CreateTestTemplateURL(original_turl_keyword, | 612 original_turl_ptr = |
612 "http://key1.com", std::string(), 9000, false, true); | 613 CreateTestTemplateURL(original_turl_keyword, "http://key1.com", |
613 model()->Add(original_turl); | 614 std::string(), 9000, false, true); |
614 sync_turl.reset(CreateTestTemplateURL(original_turl_keyword, "http://new.com", | 615 original_turl = original_turl_ptr.get(); |
615 "remote2", 9999)); | 616 model()->Add(std::move(original_turl_ptr)); |
617 sync_turl = CreateTestTemplateURL(original_turl_keyword, "http://new.com", | |
618 "remote2", 9999); | |
616 model()->ResolveSyncKeywordConflict(sync_turl.get(), original_turl, &changes); | 619 model()->ResolveSyncKeywordConflict(sync_turl.get(), original_turl, &changes); |
617 EXPECT_NE(original_turl_keyword, sync_turl->keyword()); | 620 EXPECT_NE(original_turl_keyword, sync_turl->keyword()); |
618 EXPECT_EQ(original_turl_keyword, original_turl->keyword()); | 621 EXPECT_EQ(original_turl_keyword, original_turl->keyword()); |
619 EXPECT_EQ(NULL, model()->GetTemplateURLForKeyword(sync_turl->keyword())); | 622 EXPECT_EQ(NULL, model()->GetTemplateURLForKeyword(sync_turl->keyword())); |
620 ASSERT_EQ(1U, changes.size()); | 623 ASSERT_EQ(1U, changes.size()); |
621 EXPECT_EQ("remote2", GetGUID(changes[0].sync_data())); | 624 EXPECT_EQ("remote2", GetGUID(changes[0].sync_data())); |
622 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, changes[0].change_type()); | 625 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, changes[0].change_type()); |
623 changes.clear(); | 626 changes.clear(); |
624 model()->Remove(original_turl); | 627 model()->Remove(original_turl); |
625 } | 628 } |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
703 EXPECT_EQ(6, merge_result.num_items_after_association()); | 706 EXPECT_EQ(6, merge_result.num_items_after_association()); |
704 } | 707 } |
705 | 708 |
706 TEST_F(TemplateURLServiceSyncTest, MergeSyncIsTheSame) { | 709 TEST_F(TemplateURLServiceSyncTest, MergeSyncIsTheSame) { |
707 // The local data is the same as the sync data merged in. i.e. - There have | 710 // The local data is the same as the sync data merged in. i.e. - There have |
708 // been no changes since the last time we synced. Even the last_modified | 711 // been no changes since the last time we synced. Even the last_modified |
709 // timestamps are the same. | 712 // timestamps are the same. |
710 syncer::SyncDataList initial_data = CreateInitialSyncData(); | 713 syncer::SyncDataList initial_data = CreateInitialSyncData(); |
711 for (syncer::SyncDataList::const_iterator iter = initial_data.begin(); | 714 for (syncer::SyncDataList::const_iterator iter = initial_data.begin(); |
712 iter != initial_data.end(); ++iter) { | 715 iter != initial_data.end(); ++iter) { |
713 std::unique_ptr<TemplateURL> converted(Deserialize(*iter)); | 716 model()->Add(Deserialize(*iter)); |
714 model()->Add(converted.release()); | |
715 } | 717 } |
716 | 718 |
717 syncer::SyncMergeResult merge_result = model()->MergeDataAndStartSyncing( | 719 syncer::SyncMergeResult merge_result = model()->MergeDataAndStartSyncing( |
718 syncer::SEARCH_ENGINES, initial_data, | 720 syncer::SEARCH_ENGINES, initial_data, |
719 PassProcessor(), CreateAndPassSyncErrorFactory()); | 721 PassProcessor(), CreateAndPassSyncErrorFactory()); |
720 | 722 |
721 EXPECT_EQ(3U, model()->GetAllSyncData(syncer::SEARCH_ENGINES).size()); | 723 EXPECT_EQ(3U, model()->GetAllSyncData(syncer::SEARCH_ENGINES).size()); |
722 for (syncer::SyncDataList::const_iterator iter = initial_data.begin(); | 724 for (syncer::SyncDataList::const_iterator iter = initial_data.begin(); |
723 iter != initial_data.end(); ++iter) { | 725 iter != initial_data.end(); ++iter) { |
724 std::string guid = GetGUID(*iter); | 726 std::string guid = GetGUID(*iter); |
725 EXPECT_TRUE(model()->GetTemplateURLForGUID(guid)); | 727 EXPECT_TRUE(model()->GetTemplateURLForGUID(guid)); |
726 } | 728 } |
727 EXPECT_EQ(0U, processor()->change_list_size()); | 729 EXPECT_EQ(0U, processor()->change_list_size()); |
728 | 730 |
729 // Locally everything should remain the same. | 731 // Locally everything should remain the same. |
730 EXPECT_EQ(0, merge_result.num_items_added()); | 732 EXPECT_EQ(0, merge_result.num_items_added()); |
731 EXPECT_EQ(0, merge_result.num_items_modified()); | 733 EXPECT_EQ(0, merge_result.num_items_modified()); |
732 EXPECT_EQ(0, merge_result.num_items_deleted()); | 734 EXPECT_EQ(0, merge_result.num_items_deleted()); |
733 EXPECT_EQ(3, merge_result.num_items_before_association()); | 735 EXPECT_EQ(3, merge_result.num_items_before_association()); |
734 EXPECT_EQ(3, merge_result.num_items_after_association()); | 736 EXPECT_EQ(3, merge_result.num_items_after_association()); |
735 } | 737 } |
736 | 738 |
737 TEST_F(TemplateURLServiceSyncTest, MergeUpdateFromSync) { | 739 TEST_F(TemplateURLServiceSyncTest, MergeUpdateFromSync) { |
738 // The local data is the same as the sync data merged in, but timestamps have | 740 // The local data is the same as the sync data merged in, but timestamps have |
739 // changed. Ensure the right fields are merged in. | 741 // changed. Ensure the right fields are merged in. |
740 syncer::SyncDataList initial_data; | 742 syncer::SyncDataList initial_data; |
741 TemplateURL* turl1 = CreateTestTemplateURL(ASCIIToUTF16("abc.com"), | 743 std::unique_ptr<TemplateURL> turl1_ptr = CreateTestTemplateURL( |
742 "http://abc.com", "abc", 9000); | 744 ASCIIToUTF16("abc.com"), "http://abc.com", "abc", 9000); |
743 model()->Add(turl1); | 745 TemplateURL* turl1 = turl1_ptr.get(); |
744 TemplateURL* turl2 = CreateTestTemplateURL(ASCIIToUTF16("xyz.com"), | 746 model()->Add(std::move(turl1_ptr)); |
745 "http://xyz.com", "xyz", 9000); | 747 std::unique_ptr<TemplateURL> turl2_ptr = CreateTestTemplateURL( |
746 model()->Add(turl2); | 748 ASCIIToUTF16("xyz.com"), "http://xyz.com", "xyz", 9000); |
749 model()->Add(std::move(turl2_ptr)); | |
Peter Kasting
2016/08/31 04:12:55
Nit: Can just call Add() on the result of CreateTe
Avi (use Gerrit)
2016/09/01 00:34:26
Done.
| |
747 | 750 |
748 std::unique_ptr<TemplateURL> turl1_newer(CreateTestTemplateURL( | 751 std::unique_ptr<TemplateURL> turl1_newer = CreateTestTemplateURL( |
749 ASCIIToUTF16("abc.com"), "http://abc.ca", "abc", 9999)); | 752 ASCIIToUTF16("abc.com"), "http://abc.ca", "abc", 9999); |
750 initial_data.push_back( | 753 initial_data.push_back( |
751 TemplateURLService::CreateSyncDataFromTemplateURL(*turl1_newer)); | 754 TemplateURLService::CreateSyncDataFromTemplateURL(*turl1_newer)); |
752 | 755 |
753 std::unique_ptr<TemplateURL> turl2_older(CreateTestTemplateURL( | 756 std::unique_ptr<TemplateURL> turl2_older = CreateTestTemplateURL( |
754 ASCIIToUTF16("xyz.com"), "http://xyz.ca", "xyz", 8888)); | 757 ASCIIToUTF16("xyz.com"), "http://xyz.ca", "xyz", 8888); |
755 initial_data.push_back( | 758 initial_data.push_back( |
756 TemplateURLService::CreateSyncDataFromTemplateURL(*turl2_older)); | 759 TemplateURLService::CreateSyncDataFromTemplateURL(*turl2_older)); |
757 | 760 |
758 syncer::SyncMergeResult merge_result = model()->MergeDataAndStartSyncing( | 761 syncer::SyncMergeResult merge_result = model()->MergeDataAndStartSyncing( |
759 syncer::SEARCH_ENGINES, initial_data, | 762 syncer::SEARCH_ENGINES, initial_data, |
760 PassProcessor(), CreateAndPassSyncErrorFactory()); | 763 PassProcessor(), CreateAndPassSyncErrorFactory()); |
761 | 764 |
762 // Both were local updates, so we expect the same count. | 765 // Both were local updates, so we expect the same count. |
763 EXPECT_EQ(2U, model()->GetAllSyncData(syncer::SEARCH_ENGINES).size()); | 766 EXPECT_EQ(2U, model()->GetAllSyncData(syncer::SEARCH_ENGINES).size()); |
764 | 767 |
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1059 } | 1062 } |
1060 | 1063 |
1061 TEST_F(TemplateURLServiceSyncTest, ProcessTemplateURLChange) { | 1064 TEST_F(TemplateURLServiceSyncTest, ProcessTemplateURLChange) { |
1062 // Ensure that ProcessTemplateURLChange is called and pushes the correct | 1065 // Ensure that ProcessTemplateURLChange is called and pushes the correct |
1063 // changes to Sync whenever local changes are made to TemplateURLs. | 1066 // changes to Sync whenever local changes are made to TemplateURLs. |
1064 model()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES, | 1067 model()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES, |
1065 CreateInitialSyncData(), PassProcessor(), | 1068 CreateInitialSyncData(), PassProcessor(), |
1066 CreateAndPassSyncErrorFactory()); | 1069 CreateAndPassSyncErrorFactory()); |
1067 | 1070 |
1068 // Add a new search engine. | 1071 // Add a new search engine. |
1069 TemplateURL* new_turl = | 1072 model()->Add( |
1070 CreateTestTemplateURL(ASCIIToUTF16("baidu"), "http://baidu.cn", "new"); | 1073 CreateTestTemplateURL(ASCIIToUTF16("baidu"), "http://baidu.cn", "new")); |
1071 model()->Add(new_turl); | |
1072 EXPECT_EQ(1U, processor()->change_list_size()); | 1074 EXPECT_EQ(1U, processor()->change_list_size()); |
1073 ASSERT_TRUE(processor()->contains_guid("new")); | 1075 ASSERT_TRUE(processor()->contains_guid("new")); |
1074 syncer::SyncChange change = processor()->change_for_guid("new"); | 1076 syncer::SyncChange change = processor()->change_for_guid("new"); |
1075 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, change.change_type()); | 1077 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, change.change_type()); |
1076 EXPECT_EQ("baidu", GetKeyword(change.sync_data())); | 1078 EXPECT_EQ("baidu", GetKeyword(change.sync_data())); |
1077 EXPECT_EQ("http://baidu.cn", GetURL(change.sync_data())); | 1079 EXPECT_EQ("http://baidu.cn", GetURL(change.sync_data())); |
1078 | 1080 |
1079 // Change a keyword. | 1081 // Change a keyword. |
1080 TemplateURL* existing_turl = model()->GetTemplateURLForGUID("key1"); | 1082 TemplateURL* existing_turl = model()->GetTemplateURLForGUID("key1"); |
1081 model()->ResetTemplateURL(existing_turl, existing_turl->short_name(), | 1083 model()->ResetTemplateURL(existing_turl, existing_turl->short_name(), |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1134 | 1136 |
1135 EXPECT_EQ(extension1, | 1137 EXPECT_EQ(extension1, |
1136 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword1"))); | 1138 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword1"))); |
1137 EXPECT_EQ(model()->GetTemplateURLForHost("bbb.com"), | 1139 EXPECT_EQ(model()->GetTemplateURLForHost("bbb.com"), |
1138 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword2"))); | 1140 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword2"))); |
1139 } | 1141 } |
1140 | 1142 |
1141 TEST_F(TemplateURLServiceSyncTest, AutogeneratedKeywordMigrated) { | 1143 TEST_F(TemplateURLServiceSyncTest, AutogeneratedKeywordMigrated) { |
1142 // Create a couple of sync entries with autogenerated keywords. | 1144 // Create a couple of sync entries with autogenerated keywords. |
1143 syncer::SyncDataList initial_data; | 1145 syncer::SyncDataList initial_data; |
1144 std::unique_ptr<TemplateURL> turl( | 1146 std::unique_ptr<TemplateURL> turl = |
1145 CreateTestTemplateURL(ASCIIToUTF16("key1"), "http://key1.com", "key1")); | 1147 CreateTestTemplateURL(ASCIIToUTF16("key1"), "http://key1.com", "key1"); |
1146 initial_data.push_back( | 1148 initial_data.push_back( |
1147 CreateCustomSyncData(*turl, true, turl->url(), turl->sync_guid())); | 1149 CreateCustomSyncData(*turl, true, turl->url(), turl->sync_guid())); |
1148 turl.reset(CreateTestTemplateURL(ASCIIToUTF16("key2"), | 1150 turl = CreateTestTemplateURL( |
1149 "{google:baseURL}search?q={searchTerms}", "key2")); | 1151 ASCIIToUTF16("key2"), "{google:baseURL}search?q={searchTerms}", "key2"); |
1150 initial_data.push_back( | 1152 initial_data.push_back( |
1151 CreateCustomSyncData(*turl, true, turl->url(), turl->sync_guid(), 99)); | 1153 CreateCustomSyncData(*turl, true, turl->url(), turl->sync_guid(), 99)); |
1152 | 1154 |
1153 // Now try to sync the data locally. | 1155 // Now try to sync the data locally. |
1154 model()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES, initial_data, | 1156 model()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES, initial_data, |
1155 PassProcessor(), CreateAndPassSyncErrorFactory()); | 1157 PassProcessor(), CreateAndPassSyncErrorFactory()); |
1156 | 1158 |
1157 // Both entries should have been added, with explicit keywords. | 1159 // Both entries should have been added, with explicit keywords. |
1158 TemplateURL* key1 = model()->GetTemplateURLForHost("key1.com"); | 1160 TemplateURL* key1 = model()->GetTemplateURLForHost("key1.com"); |
1159 ASSERT_FALSE(key1 == NULL); | 1161 ASSERT_FALSE(key1 == NULL); |
(...skipping 16 matching lines...) Expand all Loading... | |
1176 EXPECT_EQ(google_keyword, UTF8ToUTF16(GetKeyword(key2_change.sync_data()))); | 1178 EXPECT_EQ(google_keyword, UTF8ToUTF16(GetKeyword(key2_change.sync_data()))); |
1177 } | 1179 } |
1178 | 1180 |
1179 TEST_F(TemplateURLServiceSyncTest, AutogeneratedKeywordConflicts) { | 1181 TEST_F(TemplateURLServiceSyncTest, AutogeneratedKeywordConflicts) { |
1180 // Sync brings in some autogenerated keywords, but the generated keywords we | 1182 // Sync brings in some autogenerated keywords, but the generated keywords we |
1181 // try to create conflict with ones in the model. | 1183 // try to create conflict with ones in the model. |
1182 base::string16 google_keyword(url_formatter::StripWWWFromHost(GURL( | 1184 base::string16 google_keyword(url_formatter::StripWWWFromHost(GURL( |
1183 model()->search_terms_data().GoogleBaseURLValue()))); | 1185 model()->search_terms_data().GoogleBaseURLValue()))); |
1184 const std::string local_google_url = | 1186 const std::string local_google_url = |
1185 "{google:baseURL}1/search?q={searchTerms}"; | 1187 "{google:baseURL}1/search?q={searchTerms}"; |
1186 TemplateURL* google = CreateTestTemplateURL(google_keyword, local_google_url); | 1188 std::unique_ptr<TemplateURL> google_ptr = |
1187 model()->Add(google); | 1189 CreateTestTemplateURL(google_keyword, local_google_url); |
1188 TemplateURL* other = | 1190 TemplateURL* google = google_ptr.get(); |
1191 model()->Add(std::move(google_ptr)); | |
1192 std::unique_ptr<TemplateURL> other_ptr = | |
1189 CreateTestTemplateURL(ASCIIToUTF16("other.com"), "http://other.com/foo"); | 1193 CreateTestTemplateURL(ASCIIToUTF16("other.com"), "http://other.com/foo"); |
1190 model()->Add(other); | 1194 TemplateURL* other = other_ptr.get(); |
1195 model()->Add(std::move(other_ptr)); | |
1191 syncer::SyncDataList initial_data; | 1196 syncer::SyncDataList initial_data; |
1192 std::unique_ptr<TemplateURL> turl(CreateTestTemplateURL( | 1197 std::unique_ptr<TemplateURL> turl = CreateTestTemplateURL( |
1193 ASCIIToUTF16("sync1"), "{google:baseURL}2/search?q={searchTerms}", | 1198 ASCIIToUTF16("sync1"), "{google:baseURL}2/search?q={searchTerms}", |
1194 "sync1", 50)); | 1199 "sync1", 50); |
1195 initial_data.push_back( | 1200 initial_data.push_back( |
1196 CreateCustomSyncData(*turl, true, turl->url(), turl->sync_guid())); | 1201 CreateCustomSyncData(*turl, true, turl->url(), turl->sync_guid())); |
1197 const std::string synced_other_url = | 1202 const std::string synced_other_url = |
1198 "http://other.com/search?q={searchTerms}"; | 1203 "http://other.com/search?q={searchTerms}"; |
1199 turl.reset(CreateTestTemplateURL(ASCIIToUTF16("sync2"), | 1204 turl = CreateTestTemplateURL(ASCIIToUTF16("sync2"), synced_other_url, "sync2", |
1200 synced_other_url, "sync2", 150)); | 1205 150); |
1201 initial_data.push_back( | 1206 initial_data.push_back( |
1202 CreateCustomSyncData(*turl, true, turl->url(), turl->sync_guid())); | 1207 CreateCustomSyncData(*turl, true, turl->url(), turl->sync_guid())); |
1203 | 1208 |
1204 // Before we merge the data, grab the local sync_guids so we can ensure that | 1209 // Before we merge the data, grab the local sync_guids so we can ensure that |
1205 // they've been replaced. | 1210 // they've been replaced. |
1206 const std::string local_google_guid = google->sync_guid(); | 1211 const std::string local_google_guid = google->sync_guid(); |
1207 const std::string local_other_guid = other->sync_guid(); | 1212 const std::string local_other_guid = other->sync_guid(); |
1208 | 1213 |
1209 model()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES, initial_data, | 1214 model()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES, initial_data, |
1210 PassProcessor(), CreateAndPassSyncErrorFactory()); | 1215 PassProcessor(), CreateAndPassSyncErrorFactory()); |
(...skipping 23 matching lines...) Expand all Loading... | |
1234 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, sync2_change.change_type()); | 1239 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, sync2_change.change_type()); |
1235 EXPECT_EQ("other.com", GetKeyword(sync2_change.sync_data())); | 1240 EXPECT_EQ("other.com", GetKeyword(sync2_change.sync_data())); |
1236 EXPECT_EQ(synced_other_url, GetURL(sync2_change.sync_data())); | 1241 EXPECT_EQ(synced_other_url, GetURL(sync2_change.sync_data())); |
1237 } | 1242 } |
1238 | 1243 |
1239 TEST_F(TemplateURLServiceSyncTest, TwoAutogeneratedKeywordsUsingGoogleBaseURL) { | 1244 TEST_F(TemplateURLServiceSyncTest, TwoAutogeneratedKeywordsUsingGoogleBaseURL) { |
1240 // Sync brings in two autogenerated keywords and both use Google base URLs. | 1245 // Sync brings in two autogenerated keywords and both use Google base URLs. |
1241 // We make the first older so that it will get renamed once before the second | 1246 // We make the first older so that it will get renamed once before the second |
1242 // and then again once after (when we resolve conflicts for the second). | 1247 // and then again once after (when we resolve conflicts for the second). |
1243 syncer::SyncDataList initial_data; | 1248 syncer::SyncDataList initial_data; |
1244 std::unique_ptr<TemplateURL> turl(CreateTestTemplateURL( | 1249 std::unique_ptr<TemplateURL> turl = CreateTestTemplateURL( |
1245 ASCIIToUTF16("key1"), "{google:baseURL}1/search?q={searchTerms}", "key1", | 1250 ASCIIToUTF16("key1"), "{google:baseURL}1/search?q={searchTerms}", "key1", |
1246 50)); | 1251 50); |
1247 initial_data.push_back( | 1252 initial_data.push_back( |
1248 CreateCustomSyncData(*turl, true, turl->url(), turl->sync_guid())); | 1253 CreateCustomSyncData(*turl, true, turl->url(), turl->sync_guid())); |
1249 turl.reset(CreateTestTemplateURL(ASCIIToUTF16("key2"), | 1254 turl = CreateTestTemplateURL( |
1250 "{google:baseURL}2/search?q={searchTerms}", "key2")); | 1255 ASCIIToUTF16("key2"), "{google:baseURL}2/search?q={searchTerms}", "key2"); |
1251 initial_data.push_back( | 1256 initial_data.push_back( |
1252 CreateCustomSyncData(*turl, true, turl->url(), turl->sync_guid())); | 1257 CreateCustomSyncData(*turl, true, turl->url(), turl->sync_guid())); |
1253 model()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES, initial_data, | 1258 model()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES, initial_data, |
1254 PassProcessor(), CreateAndPassSyncErrorFactory()); | 1259 PassProcessor(), CreateAndPassSyncErrorFactory()); |
1255 | 1260 |
1256 // We should still have coalesced the updates to one each. | 1261 // We should still have coalesced the updates to one each. |
1257 base::string16 google_keyword(url_formatter::StripWWWFromHost(GURL( | 1262 base::string16 google_keyword(url_formatter::StripWWWFromHost(GURL( |
1258 model()->search_terms_data().GoogleBaseURLValue()))); | 1263 model()->search_terms_data().GoogleBaseURLValue()))); |
1259 TemplateURL* keyword1 = | 1264 TemplateURL* keyword1 = |
1260 model()->GetTemplateURLForKeyword(google_keyword + ASCIIToUTF16("_")); | 1265 model()->GetTemplateURLForKeyword(google_keyword + ASCIIToUTF16("_")); |
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1528 model()->ProcessSyncChanges(FROM_HERE, changes2); | 1533 model()->ProcessSyncChanges(FROM_HERE, changes2); |
1529 | 1534 |
1530 EXPECT_EQ(5U, model()->GetAllSyncData(syncer::SEARCH_ENGINES).size()); | 1535 EXPECT_EQ(5U, model()->GetAllSyncData(syncer::SEARCH_ENGINES).size()); |
1531 ASSERT_NE(default_search, model()->GetDefaultSearchProvider()); | 1536 ASSERT_NE(default_search, model()->GetDefaultSearchProvider()); |
1532 ASSERT_EQ("newdefault", model()->GetDefaultSearchProvider()->sync_guid()); | 1537 ASSERT_EQ("newdefault", model()->GetDefaultSearchProvider()->sync_guid()); |
1533 } | 1538 } |
1534 | 1539 |
1535 TEST_F(TemplateURLServiceSyncTest, DefaultGuidDeletedBeforeNewDSPArrives) { | 1540 TEST_F(TemplateURLServiceSyncTest, DefaultGuidDeletedBeforeNewDSPArrives) { |
1536 syncer::SyncDataList initial_data; | 1541 syncer::SyncDataList initial_data; |
1537 // The default search provider should support replacement. | 1542 // The default search provider should support replacement. |
1538 std::unique_ptr<TemplateURL> turl1(CreateTestTemplateURL( | 1543 std::unique_ptr<TemplateURL> turl1 = CreateTestTemplateURL( |
1539 ASCIIToUTF16("key1"), "http://key1.com/{searchTerms}", "key1", 90)); | 1544 ASCIIToUTF16("key1"), "http://key1.com/{searchTerms}", "key1", 90); |
1540 // Create a second default search provider for the | 1545 // Create a second default search provider for the |
1541 // FindNewDefaultSearchProvider method to find. | 1546 // FindNewDefaultSearchProvider method to find. |
1542 TemplateURLData data; | 1547 TemplateURLData data; |
1543 data.SetShortName(ASCIIToUTF16("unittest")); | 1548 data.SetShortName(ASCIIToUTF16("unittest")); |
1544 data.SetKeyword(ASCIIToUTF16("key2")); | 1549 data.SetKeyword(ASCIIToUTF16("key2")); |
1545 data.SetURL("http://key2.com/{searchTerms}"); | 1550 data.SetURL("http://key2.com/{searchTerms}"); |
1546 data.favicon_url = GURL("http://favicon.url"); | 1551 data.favicon_url = GURL("http://favicon.url"); |
1547 data.safe_for_autoreplace = false; | 1552 data.safe_for_autoreplace = false; |
1548 data.date_created = Time::FromTimeT(100); | 1553 data.date_created = Time::FromTimeT(100); |
1549 data.last_modified = Time::FromTimeT(100); | 1554 data.last_modified = Time::FromTimeT(100); |
(...skipping 26 matching lines...) Expand all Loading... | |
1576 prefs::kSyncedDefaultSearchProviderGUID)); | 1581 prefs::kSyncedDefaultSearchProviderGUID)); |
1577 | 1582 |
1578 // Simulate a situation where an ACTION_DELETE on the default arrives before | 1583 // Simulate a situation where an ACTION_DELETE on the default arrives before |
1579 // the new default search provider entry. This should fail to delete the | 1584 // the new default search provider entry. This should fail to delete the |
1580 // target entry, and instead send up an "undelete" to the server, after | 1585 // target entry, and instead send up an "undelete" to the server, after |
1581 // further uniquifying the keyword to avoid infinite sync loops. The synced | 1586 // further uniquifying the keyword to avoid infinite sync loops. The synced |
1582 // default GUID should not be changed so that when the expected default entry | 1587 // default GUID should not be changed so that when the expected default entry |
1583 // arrives, it can still be set as the default. | 1588 // arrives, it can still be set as the default. |
1584 syncer::SyncChangeList changes1; | 1589 syncer::SyncChangeList changes1; |
1585 changes1.push_back(CreateTestSyncChange(syncer::SyncChange::ACTION_DELETE, | 1590 changes1.push_back(CreateTestSyncChange(syncer::SyncChange::ACTION_DELETE, |
1586 turl1.release())); | 1591 std::move(turl1))); |
1587 model()->ProcessSyncChanges(FROM_HERE, changes1); | 1592 model()->ProcessSyncChanges(FROM_HERE, changes1); |
1588 | 1593 |
1589 EXPECT_TRUE(model()->GetTemplateURLForKeyword(ASCIIToUTF16("key1_"))); | 1594 EXPECT_TRUE(model()->GetTemplateURLForKeyword(ASCIIToUTF16("key1_"))); |
1590 EXPECT_EQ(2U, model()->GetAllSyncData(syncer::SEARCH_ENGINES).size()); | 1595 EXPECT_EQ(2U, model()->GetAllSyncData(syncer::SEARCH_ENGINES).size()); |
1591 EXPECT_EQ("key1", model()->GetDefaultSearchProvider()->sync_guid()); | 1596 EXPECT_EQ("key1", model()->GetDefaultSearchProvider()->sync_guid()); |
1592 EXPECT_EQ("newdefault", profile_a()->GetTestingPrefService()->GetString( | 1597 EXPECT_EQ("newdefault", profile_a()->GetTestingPrefService()->GetString( |
1593 prefs::kSyncedDefaultSearchProviderGUID)); | 1598 prefs::kSyncedDefaultSearchProviderGUID)); |
1594 syncer::SyncChange undelete = processor()->change_for_guid("key1"); | 1599 syncer::SyncChange undelete = processor()->change_for_guid("key1"); |
1595 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, undelete.change_type()); | 1600 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, undelete.change_type()); |
1596 EXPECT_EQ("key1_", | 1601 EXPECT_EQ("key1_", |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1729 const TemplateURL* expected_default = | 1734 const TemplateURL* expected_default = |
1730 model()->GetTemplateURLForGUID("newdefault"); | 1735 model()->GetTemplateURLForGUID("newdefault"); |
1731 test_util_a_->RemoveManagedDefaultSearchPreferences(); | 1736 test_util_a_->RemoveManagedDefaultSearchPreferences(); |
1732 | 1737 |
1733 EXPECT_EQ(expected_default, model()->GetDefaultSearchProvider()); | 1738 EXPECT_EQ(expected_default, model()->GetDefaultSearchProvider()); |
1734 } | 1739 } |
1735 | 1740 |
1736 TEST_F(TemplateURLServiceSyncTest, SyncMergeDeletesDefault) { | 1741 TEST_F(TemplateURLServiceSyncTest, SyncMergeDeletesDefault) { |
1737 // If the value from Sync is a duplicate of the local default and is newer, it | 1742 // If the value from Sync is a duplicate of the local default and is newer, it |
1738 // should safely replace the local value and set as the new default. | 1743 // should safely replace the local value and set as the new default. |
1739 TemplateURL* default_turl = CreateTestTemplateURL(ASCIIToUTF16("key1"), | 1744 std::unique_ptr<TemplateURL> default_turl_ptr = CreateTestTemplateURL( |
1740 "http://key1.com/{searchTerms}", "whateverguid", 10); | 1745 ASCIIToUTF16("key1"), "http://key1.com/{searchTerms}", "whateverguid", |
1741 model()->Add(default_turl); | 1746 10); |
1747 TemplateURL* default_turl = default_turl_ptr.get(); | |
1748 model()->Add(std::move(default_turl_ptr)); | |
1742 model()->SetUserSelectedDefaultSearchProvider(default_turl); | 1749 model()->SetUserSelectedDefaultSearchProvider(default_turl); |
1743 | 1750 |
1744 syncer::SyncDataList initial_data = CreateInitialSyncData(); | 1751 syncer::SyncDataList initial_data = CreateInitialSyncData(); |
1745 // The key1 entry should be a duplicate of the default. | 1752 // The key1 entry should be a duplicate of the default. |
1746 std::unique_ptr<TemplateURL> turl(CreateTestTemplateURL( | 1753 std::unique_ptr<TemplateURL> turl(CreateTestTemplateURL( |
1747 ASCIIToUTF16("key1"), "http://key1.com/{searchTerms}", "key1", 90)); | 1754 ASCIIToUTF16("key1"), "http://key1.com/{searchTerms}", "key1", 90)); |
1748 initial_data[0] = TemplateURLService::CreateSyncDataFromTemplateURL(*turl); | 1755 initial_data[0] = TemplateURLService::CreateSyncDataFromTemplateURL(*turl); |
1749 | 1756 |
1750 model()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES, initial_data, | 1757 model()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES, initial_data, |
1751 PassProcessor(), CreateAndPassSyncErrorFactory()); | 1758 PassProcessor(), CreateAndPassSyncErrorFactory()); |
1752 | 1759 |
1753 EXPECT_EQ(3U, model()->GetAllSyncData(syncer::SEARCH_ENGINES).size()); | 1760 EXPECT_EQ(3U, model()->GetAllSyncData(syncer::SEARCH_ENGINES).size()); |
1754 EXPECT_FALSE(model()->GetTemplateURLForGUID("whateverguid")); | 1761 EXPECT_FALSE(model()->GetTemplateURLForGUID("whateverguid")); |
1755 EXPECT_EQ(model()->GetDefaultSearchProvider(), | 1762 EXPECT_EQ(model()->GetDefaultSearchProvider(), |
1756 model()->GetTemplateURLForGUID("key1")); | 1763 model()->GetTemplateURLForGUID("key1")); |
1757 } | 1764 } |
1758 | 1765 |
1759 TEST_F(TemplateURLServiceSyncTest, LocalDefaultWinsConflict) { | 1766 TEST_F(TemplateURLServiceSyncTest, LocalDefaultWinsConflict) { |
1760 // We expect that the local default always wins keyword conflict resolution. | 1767 // We expect that the local default always wins keyword conflict resolution. |
1761 const base::string16 keyword(ASCIIToUTF16("key1")); | 1768 const base::string16 keyword(ASCIIToUTF16("key1")); |
1762 const std::string url("http://whatever.com/{searchTerms}"); | 1769 const std::string url("http://whatever.com/{searchTerms}"); |
1763 TemplateURL* default_turl = CreateTestTemplateURL(keyword, | 1770 std::unique_ptr<TemplateURL> default_turl_ptr = |
1764 url, | 1771 CreateTestTemplateURL(keyword, url, "whateverguid", 10); |
1765 "whateverguid", | 1772 TemplateURL* default_turl = default_turl_ptr.get(); |
1766 10); | 1773 model()->Add(std::move(default_turl_ptr)); |
1767 model()->Add(default_turl); | |
1768 model()->SetUserSelectedDefaultSearchProvider(default_turl); | 1774 model()->SetUserSelectedDefaultSearchProvider(default_turl); |
1769 | 1775 |
1770 syncer::SyncDataList initial_data = CreateInitialSyncData(); | 1776 syncer::SyncDataList initial_data = CreateInitialSyncData(); |
1771 // The key1 entry should be different from the default but conflict in the | 1777 // The key1 entry should be different from the default but conflict in the |
1772 // keyword. | 1778 // keyword. |
1773 std::unique_ptr<TemplateURL> turl(CreateTestTemplateURL( | 1779 std::unique_ptr<TemplateURL> turl = CreateTestTemplateURL( |
1774 keyword, "http://key1.com/{searchTerms}", "key1", 90)); | 1780 keyword, "http://key1.com/{searchTerms}", "key1", 90); |
1775 initial_data[0] = TemplateURLService::CreateSyncDataFromTemplateURL(*turl); | 1781 initial_data[0] = TemplateURLService::CreateSyncDataFromTemplateURL(*turl); |
1776 | 1782 |
1777 model()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES, initial_data, | 1783 model()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES, initial_data, |
1778 PassProcessor(), CreateAndPassSyncErrorFactory()); | 1784 PassProcessor(), CreateAndPassSyncErrorFactory()); |
1779 | 1785 |
1780 // Since the local default was not yet synced, it should be merged with the | 1786 // Since the local default was not yet synced, it should be merged with the |
1781 // conflicting TemplateURL. However, its values should have been preserved | 1787 // conflicting TemplateURL. However, its values should have been preserved |
1782 // since it would have won conflict resolution due to being the default. | 1788 // since it would have won conflict resolution due to being the default. |
1783 EXPECT_EQ(3U, model()->GetAllSyncData(syncer::SEARCH_ENGINES).size()); | 1789 EXPECT_EQ(3U, model()->GetAllSyncData(syncer::SEARCH_ENGINES).size()); |
1784 const TemplateURL* winner = model()->GetTemplateURLForGUID("key1"); | 1790 const TemplateURL* winner = model()->GetTemplateURLForGUID("key1"); |
1785 ASSERT_TRUE(winner); | 1791 ASSERT_TRUE(winner); |
1786 EXPECT_EQ(model()->GetDefaultSearchProvider(), winner); | 1792 EXPECT_EQ(model()->GetDefaultSearchProvider(), winner); |
1787 EXPECT_EQ(keyword, winner->keyword()); | 1793 EXPECT_EQ(keyword, winner->keyword()); |
1788 EXPECT_EQ(url, winner->url()); | 1794 EXPECT_EQ(url, winner->url()); |
1789 ASSERT_TRUE(processor()->contains_guid("key1")); | 1795 ASSERT_TRUE(processor()->contains_guid("key1")); |
1790 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, | 1796 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, |
1791 processor()->change_for_guid("key1").change_type()); | 1797 processor()->change_for_guid("key1").change_type()); |
1792 EXPECT_EQ(url, GetURL(processor()->change_for_guid("key1").sync_data())); | 1798 EXPECT_EQ(url, GetURL(processor()->change_for_guid("key1").sync_data())); |
1793 | 1799 |
1794 // There is no loser, as the two were merged together. The local sync_guid | 1800 // There is no loser, as the two were merged together. The local sync_guid |
1795 // should no longer be found in the model. | 1801 // should no longer be found in the model. |
1796 const TemplateURL* loser = model()->GetTemplateURLForGUID("whateverguid"); | 1802 const TemplateURL* loser = model()->GetTemplateURLForGUID("whateverguid"); |
1797 ASSERT_FALSE(loser); | 1803 ASSERT_FALSE(loser); |
1798 } | 1804 } |
1799 | 1805 |
1800 TEST_F(TemplateURLServiceSyncTest, DeleteBogusData) { | 1806 TEST_F(TemplateURLServiceSyncTest, DeleteBogusData) { |
1801 // Create a couple of bogus entries to sync. | 1807 // Create a couple of bogus entries to sync. |
1802 syncer::SyncDataList initial_data; | 1808 syncer::SyncDataList initial_data; |
1803 std::unique_ptr<TemplateURL> turl( | 1809 std::unique_ptr<TemplateURL> turl = |
1804 CreateTestTemplateURL(ASCIIToUTF16("key1"), "http://key1.com", "key1")); | 1810 CreateTestTemplateURL(ASCIIToUTF16("key1"), "http://key1.com", "key1"); |
1805 initial_data.push_back( | 1811 initial_data.push_back( |
1806 CreateCustomSyncData(*turl, false, std::string(), turl->sync_guid())); | 1812 CreateCustomSyncData(*turl, false, std::string(), turl->sync_guid())); |
1807 turl.reset(CreateTestTemplateURL(ASCIIToUTF16("key2"), "http://key2.com")); | 1813 turl = CreateTestTemplateURL(ASCIIToUTF16("key2"), "http://key2.com"); |
1808 initial_data.push_back( | 1814 initial_data.push_back( |
1809 CreateCustomSyncData(*turl, false, turl->url(), std::string())); | 1815 CreateCustomSyncData(*turl, false, turl->url(), std::string())); |
1810 | 1816 |
1811 // Now try to sync the data locally. | 1817 // Now try to sync the data locally. |
1812 model()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES, initial_data, | 1818 model()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES, initial_data, |
1813 PassProcessor(), CreateAndPassSyncErrorFactory()); | 1819 PassProcessor(), CreateAndPassSyncErrorFactory()); |
1814 | 1820 |
1815 // Nothing should have been added, and both bogus entries should be marked for | 1821 // Nothing should have been added, and both bogus entries should be marked for |
1816 // deletion. | 1822 // deletion. |
1817 EXPECT_EQ(0U, model()->GetTemplateURLs().size()); | 1823 EXPECT_EQ(0U, model()->GetTemplateURLs().size()); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1870 ASSERT_FALSE(prepop_turls.empty()); | 1876 ASSERT_FALSE(prepop_turls.empty()); |
1871 | 1877 |
1872 // Create a copy of the first TemplateURL with a really old timestamp and a | 1878 // Create a copy of the first TemplateURL with a really old timestamp and a |
1873 // new keyword. Add it to the model. | 1879 // new keyword. Add it to the model. |
1874 TemplateURLData data_copy(*prepop_turls[0]); | 1880 TemplateURLData data_copy(*prepop_turls[0]); |
1875 data_copy.last_modified = Time::FromTimeT(10); | 1881 data_copy.last_modified = Time::FromTimeT(10); |
1876 base::string16 original_keyword = data_copy.keyword(); | 1882 base::string16 original_keyword = data_copy.keyword(); |
1877 data_copy.SetKeyword(ASCIIToUTF16(kNewKeyword)); | 1883 data_copy.SetKeyword(ASCIIToUTF16(kNewKeyword)); |
1878 // Set safe_for_autoreplace to false so our keyword survives. | 1884 // Set safe_for_autoreplace to false so our keyword survives. |
1879 data_copy.safe_for_autoreplace = false; | 1885 data_copy.safe_for_autoreplace = false; |
1880 model()->Add(new TemplateURL(data_copy)); | 1886 model()->Add(base::MakeUnique<TemplateURL>(data_copy)); |
1881 | 1887 |
1882 // Merge the prepopulate search engines. | 1888 // Merge the prepopulate search engines. |
1883 base::Time pre_merge_time = base::Time::Now(); | 1889 base::Time pre_merge_time = base::Time::Now(); |
1884 base::RunLoop().RunUntilIdle(); | 1890 base::RunLoop().RunUntilIdle(); |
1885 test_util_a_->ResetModel(true); | 1891 test_util_a_->ResetModel(true); |
1886 | 1892 |
1887 // The newly added search engine should have been safely merged, with an | 1893 // The newly added search engine should have been safely merged, with an |
1888 // updated time. | 1894 // updated time. |
1889 TemplateURL* added_turl = model()->GetTemplateURLForKeyword( | 1895 TemplateURL* added_turl = model()->GetTemplateURLForKeyword( |
1890 ASCIIToUTF16(kNewKeyword)); | 1896 ASCIIToUTF16(kNewKeyword)); |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2034 const time_t sync_last_modified = | 2040 const time_t sync_last_modified = |
2035 test_cases[i].conflict_winner == SYNC ? 110 : 90; | 2041 test_cases[i].conflict_winner == SYNC ? 110 : 90; |
2036 const std::string local_guid = "local_guid"; | 2042 const std::string local_guid = "local_guid"; |
2037 const std::string sync_guid = "sync_guid"; | 2043 const std::string sync_guid = "sync_guid"; |
2038 | 2044 |
2039 // Initialize expectations. | 2045 // Initialize expectations. |
2040 base::string16 expected_local_keyword = local_keyword; | 2046 base::string16 expected_local_keyword = local_keyword; |
2041 base::string16 expected_sync_keyword = sync_keyword; | 2047 base::string16 expected_sync_keyword = sync_keyword; |
2042 | 2048 |
2043 // Create the data and run the actual test. | 2049 // Create the data and run the actual test. |
2044 TemplateURL* local_turl = CreateTestTemplateURL( | 2050 std::unique_ptr<TemplateURL> local_turl_ptr = CreateTestTemplateURL( |
2045 local_keyword, local_url, local_guid, local_last_modified); | 2051 local_keyword, local_url, local_guid, local_last_modified); |
2046 model()->Add(local_turl); | 2052 TemplateURL* local_turl = local_turl_ptr.get(); |
2053 model()->Add(std::move(local_turl_ptr)); | |
2047 std::unique_ptr<TemplateURL> sync_turl(CreateTestTemplateURL( | 2054 std::unique_ptr<TemplateURL> sync_turl(CreateTestTemplateURL( |
2048 sync_keyword, sync_url, sync_guid, sync_last_modified)); | 2055 sync_keyword, sync_url, sync_guid, sync_last_modified)); |
2049 | 2056 |
2050 SyncDataMap sync_data; | 2057 SyncDataMap sync_data; |
2051 if (test_cases[i].synced_at_start == SYNC || | 2058 if (test_cases[i].synced_at_start == SYNC || |
2052 test_cases[i].synced_at_start == BOTH) { | 2059 test_cases[i].synced_at_start == BOTH) { |
2053 sync_data[sync_turl->sync_guid()] = | 2060 sync_data[sync_turl->sync_guid()] = |
2054 TemplateURLService::CreateSyncDataFromTemplateURL(*sync_turl); | 2061 TemplateURLService::CreateSyncDataFromTemplateURL(*sync_turl); |
2055 } | 2062 } |
2056 if (test_cases[i].synced_at_start == BOTH) { | 2063 if (test_cases[i].synced_at_start == BOTH) { |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2123 } // for | 2130 } // for |
2124 } | 2131 } |
2125 | 2132 |
2126 TEST_F(TemplateURLServiceSyncTest, MergePrepopulatedEngine) { | 2133 TEST_F(TemplateURLServiceSyncTest, MergePrepopulatedEngine) { |
2127 std::unique_ptr<TemplateURLData> default_turl( | 2134 std::unique_ptr<TemplateURLData> default_turl( |
2128 TemplateURLPrepopulateData::GetPrepopulatedDefaultSearch(NULL)); | 2135 TemplateURLPrepopulateData::GetPrepopulatedDefaultSearch(NULL)); |
2129 | 2136 |
2130 // Merge with an initial list containing a prepopulated engine with a wrong | 2137 // Merge with an initial list containing a prepopulated engine with a wrong |
2131 // URL. | 2138 // URL. |
2132 syncer::SyncDataList list; | 2139 syncer::SyncDataList list; |
2133 std::unique_ptr<TemplateURL> sync_turl(CopyTemplateURL( | 2140 std::unique_ptr<TemplateURL> sync_turl = CopyTemplateURL( |
2134 default_turl.get(), "http://wrong.url.com?q={searchTerms}", "default")); | 2141 default_turl.get(), "http://wrong.url.com?q={searchTerms}", "default"); |
2135 list.push_back(TemplateURLService::CreateSyncDataFromTemplateURL(*sync_turl)); | 2142 list.push_back(TemplateURLService::CreateSyncDataFromTemplateURL(*sync_turl)); |
2136 syncer::SyncMergeResult merge_result = model()->MergeDataAndStartSyncing( | 2143 syncer::SyncMergeResult merge_result = model()->MergeDataAndStartSyncing( |
2137 syncer::SEARCH_ENGINES, list, PassProcessor(), | 2144 syncer::SEARCH_ENGINES, list, PassProcessor(), |
2138 CreateAndPassSyncErrorFactory()); | 2145 CreateAndPassSyncErrorFactory()); |
2139 | 2146 |
2140 const TemplateURL* result_turl = model()->GetTemplateURLForGUID("default"); | 2147 const TemplateURL* result_turl = model()->GetTemplateURLForGUID("default"); |
2141 EXPECT_TRUE(result_turl); | 2148 EXPECT_TRUE(result_turl); |
2142 EXPECT_EQ(default_turl->keyword(), result_turl->keyword()); | 2149 EXPECT_EQ(default_turl->keyword(), result_turl->keyword()); |
2143 EXPECT_EQ(default_turl->short_name(), result_turl->short_name()); | 2150 EXPECT_EQ(default_turl->short_name(), result_turl->short_name()); |
2144 EXPECT_EQ(default_turl->url(), result_turl->url()); | 2151 EXPECT_EQ(default_turl->url(), result_turl->url()); |
2145 } | 2152 } |
2146 | 2153 |
2147 TEST_F(TemplateURLServiceSyncTest, AddPrepopulatedEngine) { | 2154 TEST_F(TemplateURLServiceSyncTest, AddPrepopulatedEngine) { |
2148 syncer::SyncMergeResult merge_result = model()->MergeDataAndStartSyncing( | 2155 syncer::SyncMergeResult merge_result = model()->MergeDataAndStartSyncing( |
2149 syncer::SEARCH_ENGINES, syncer::SyncDataList(), PassProcessor(), | 2156 syncer::SEARCH_ENGINES, syncer::SyncDataList(), PassProcessor(), |
2150 CreateAndPassSyncErrorFactory()); | 2157 CreateAndPassSyncErrorFactory()); |
2151 | 2158 |
2152 std::unique_ptr<TemplateURLData> default_turl( | 2159 std::unique_ptr<TemplateURLData> default_turl( |
2153 TemplateURLPrepopulateData::GetPrepopulatedDefaultSearch(NULL)); | 2160 TemplateURLPrepopulateData::GetPrepopulatedDefaultSearch(NULL)); |
2154 TemplateURL* sync_turl = CopyTemplateURL(default_turl.get(), | 2161 std::unique_ptr<TemplateURL> sync_turl = CopyTemplateURL( |
2155 "http://wrong.url.com?q={searchTerms}", "default"); | 2162 default_turl.get(), "http://wrong.url.com?q={searchTerms}", "default"); |
2156 | 2163 |
2157 // Add a prepopulated engine with a wrong URL. | 2164 // Add a prepopulated engine with a wrong URL. |
2158 syncer::SyncChangeList changes; | 2165 syncer::SyncChangeList changes; |
2159 changes.push_back(CreateTestSyncChange(syncer::SyncChange::ACTION_ADD, | 2166 changes.push_back(CreateTestSyncChange(syncer::SyncChange::ACTION_ADD, |
2160 sync_turl)); | 2167 std::move(sync_turl))); |
2161 model()->ProcessSyncChanges(FROM_HERE, changes); | 2168 model()->ProcessSyncChanges(FROM_HERE, changes); |
2162 | 2169 |
2163 const TemplateURL* result_turl = model()->GetTemplateURLForGUID("default"); | 2170 const TemplateURL* result_turl = model()->GetTemplateURLForGUID("default"); |
2164 EXPECT_TRUE(result_turl); | 2171 EXPECT_TRUE(result_turl); |
2165 EXPECT_EQ(default_turl->keyword(), result_turl->keyword()); | 2172 EXPECT_EQ(default_turl->keyword(), result_turl->keyword()); |
2166 EXPECT_EQ(default_turl->short_name(), result_turl->short_name()); | 2173 EXPECT_EQ(default_turl->short_name(), result_turl->short_name()); |
2167 EXPECT_EQ(default_turl->url(), result_turl->url()); | 2174 EXPECT_EQ(default_turl->url(), result_turl->url()); |
2168 } | 2175 } |
2169 | 2176 |
2170 TEST_F(TemplateURLServiceSyncTest, UpdatePrepopulatedEngine) { | 2177 TEST_F(TemplateURLServiceSyncTest, UpdatePrepopulatedEngine) { |
2171 std::unique_ptr<TemplateURLData> default_turl( | 2178 std::unique_ptr<TemplateURLData> default_turl( |
2172 TemplateURLPrepopulateData::GetPrepopulatedDefaultSearch(NULL)); | 2179 TemplateURLPrepopulateData::GetPrepopulatedDefaultSearch(NULL)); |
2173 | 2180 |
2174 TemplateURLData data = *default_turl; | 2181 TemplateURLData data = *default_turl; |
2175 data.SetURL("http://old.wrong.url.com?q={searchTerms}"); | 2182 data.SetURL("http://old.wrong.url.com?q={searchTerms}"); |
2176 data.sync_guid = "default"; | 2183 data.sync_guid = "default"; |
2177 model()->Add(new TemplateURL(data)); | 2184 model()->Add(base::MakeUnique<TemplateURL>(data)); |
2178 | 2185 |
2179 syncer::SyncMergeResult merge_result = model()->MergeDataAndStartSyncing( | 2186 syncer::SyncMergeResult merge_result = model()->MergeDataAndStartSyncing( |
2180 syncer::SEARCH_ENGINES, syncer::SyncDataList(), PassProcessor(), | 2187 syncer::SEARCH_ENGINES, syncer::SyncDataList(), PassProcessor(), |
2181 CreateAndPassSyncErrorFactory()); | 2188 CreateAndPassSyncErrorFactory()); |
2182 | 2189 |
2183 TemplateURL* sync_turl = CopyTemplateURL(default_turl.get(), | 2190 std::unique_ptr<TemplateURL> sync_turl = |
2184 "http://new.wrong.url.com?q={searchTerms}", "default"); | 2191 CopyTemplateURL(default_turl.get(), |
2192 "http://new.wrong.url.com?q={searchTerms}", "default"); | |
2185 | 2193 |
2186 // Update the engine in the model, which is prepopulated, with a new one. | 2194 // Update the engine in the model, which is prepopulated, with a new one. |
2187 // Both have wrong URLs, but it should still get corrected. | 2195 // Both have wrong URLs, but it should still get corrected. |
2188 syncer::SyncChangeList changes; | 2196 syncer::SyncChangeList changes; |
2189 changes.push_back(CreateTestSyncChange(syncer::SyncChange::ACTION_UPDATE, | 2197 changes.push_back(CreateTestSyncChange(syncer::SyncChange::ACTION_UPDATE, |
2190 sync_turl)); | 2198 std::move(sync_turl))); |
2191 model()->ProcessSyncChanges(FROM_HERE, changes); | 2199 model()->ProcessSyncChanges(FROM_HERE, changes); |
2192 | 2200 |
2193 const TemplateURL* result_turl = model()->GetTemplateURLForGUID("default"); | 2201 const TemplateURL* result_turl = model()->GetTemplateURLForGUID("default"); |
2194 EXPECT_TRUE(result_turl); | 2202 EXPECT_TRUE(result_turl); |
2195 EXPECT_EQ(default_turl->keyword(), result_turl->keyword()); | 2203 EXPECT_EQ(default_turl->keyword(), result_turl->keyword()); |
2196 EXPECT_EQ(default_turl->short_name(), result_turl->short_name()); | 2204 EXPECT_EQ(default_turl->short_name(), result_turl->short_name()); |
2197 EXPECT_EQ(default_turl->url(), result_turl->url()); | 2205 EXPECT_EQ(default_turl->url(), result_turl->url()); |
2198 } | 2206 } |
2199 | 2207 |
2200 TEST_F(TemplateURLServiceSyncTest, MergeEditedPrepopulatedEngine) { | 2208 TEST_F(TemplateURLServiceSyncTest, MergeEditedPrepopulatedEngine) { |
2201 std::unique_ptr<TemplateURLData> default_turl( | 2209 std::unique_ptr<TemplateURLData> default_turl( |
2202 TemplateURLPrepopulateData::GetPrepopulatedDefaultSearch(NULL)); | 2210 TemplateURLPrepopulateData::GetPrepopulatedDefaultSearch(NULL)); |
2203 | 2211 |
2204 TemplateURLData data(*default_turl); | 2212 TemplateURLData data(*default_turl); |
2205 data.safe_for_autoreplace = false; | 2213 data.safe_for_autoreplace = false; |
2206 data.SetKeyword(ASCIIToUTF16("new_kw")); | 2214 data.SetKeyword(ASCIIToUTF16("new_kw")); |
2207 data.SetShortName(ASCIIToUTF16("my name")); | 2215 data.SetShortName(ASCIIToUTF16("my name")); |
2208 data.SetURL("http://wrong.url.com?q={searchTerms}"); | 2216 data.SetURL("http://wrong.url.com?q={searchTerms}"); |
2209 data.date_created = Time::FromTimeT(50); | 2217 data.date_created = Time::FromTimeT(50); |
2210 data.last_modified = Time::FromTimeT(50); | 2218 data.last_modified = Time::FromTimeT(50); |
2211 data.sync_guid = "default"; | 2219 data.sync_guid = "default"; |
2212 model()->Add(new TemplateURL(data)); | 2220 model()->Add(base::MakeUnique<TemplateURL>(data)); |
2213 | 2221 |
2214 data.date_created = Time::FromTimeT(100); | 2222 data.date_created = Time::FromTimeT(100); |
2215 data.last_modified = Time::FromTimeT(100); | 2223 data.last_modified = Time::FromTimeT(100); |
2216 std::unique_ptr<TemplateURL> sync_turl(new TemplateURL(data)); | 2224 std::unique_ptr<TemplateURL> sync_turl(new TemplateURL(data)); |
2217 syncer::SyncDataList list; | 2225 syncer::SyncDataList list; |
2218 list.push_back(TemplateURLService::CreateSyncDataFromTemplateURL(*sync_turl)); | 2226 list.push_back(TemplateURLService::CreateSyncDataFromTemplateURL(*sync_turl)); |
2219 syncer::SyncMergeResult merge_result = model()->MergeDataAndStartSyncing( | 2227 syncer::SyncMergeResult merge_result = model()->MergeDataAndStartSyncing( |
2220 syncer::SEARCH_ENGINES, list, PassProcessor(), | 2228 syncer::SEARCH_ENGINES, list, PassProcessor(), |
2221 CreateAndPassSyncErrorFactory()); | 2229 CreateAndPassSyncErrorFactory()); |
2222 | 2230 |
(...skipping 10 matching lines...) Expand all Loading... | |
2233 | 2241 |
2234 TemplateURLData data(*default_turl); | 2242 TemplateURLData data(*default_turl); |
2235 data.SetKeyword(ASCIIToUTF16("old_kw")); | 2243 data.SetKeyword(ASCIIToUTF16("old_kw")); |
2236 data.SetShortName(ASCIIToUTF16("my name")); | 2244 data.SetShortName(ASCIIToUTF16("my name")); |
2237 data.SetURL("http://wrong.url.com?q={searchTerms}"); | 2245 data.SetURL("http://wrong.url.com?q={searchTerms}"); |
2238 data.safe_for_autoreplace = true; | 2246 data.safe_for_autoreplace = true; |
2239 data.date_created = Time::FromTimeT(50); | 2247 data.date_created = Time::FromTimeT(50); |
2240 data.last_modified = Time::FromTimeT(50); | 2248 data.last_modified = Time::FromTimeT(50); |
2241 data.prepopulate_id = 1; | 2249 data.prepopulate_id = 1; |
2242 data.sync_guid = "default"; | 2250 data.sync_guid = "default"; |
2243 model()->Add(new TemplateURL(data)); | 2251 model()->Add(base::MakeUnique<TemplateURL>(data)); |
2244 | 2252 |
2245 TemplateURLData new_data(*default_turl); | 2253 TemplateURLData new_data(*default_turl); |
2246 new_data.SetKeyword(ASCIIToUTF16("new_kw")); | 2254 new_data.SetKeyword(ASCIIToUTF16("new_kw")); |
2247 new_data.SetShortName(ASCIIToUTF16("my name")); | 2255 new_data.SetShortName(ASCIIToUTF16("my name")); |
2248 new_data.SetURL("http://wrong.url.com?q={searchTerms}"); | 2256 new_data.SetURL("http://wrong.url.com?q={searchTerms}"); |
2249 new_data.safe_for_autoreplace = false; | 2257 new_data.safe_for_autoreplace = false; |
2250 new_data.date_created = Time::FromTimeT(100); | 2258 new_data.date_created = Time::FromTimeT(100); |
2251 new_data.last_modified = Time::FromTimeT(100); | 2259 new_data.last_modified = Time::FromTimeT(100); |
2252 new_data.prepopulate_id = 1; | 2260 new_data.prepopulate_id = 1; |
2253 new_data.sync_guid = "different_guid"; | 2261 new_data.sync_guid = "different_guid"; |
(...skipping 16 matching lines...) Expand all Loading... | |
2270 | 2278 |
2271 // Reset the state of the service. | 2279 // Reset the state of the service. |
2272 model()->Remove(result_turl); | 2280 model()->Remove(result_turl); |
2273 model()->StopSyncing(syncer::SEARCH_ENGINES); | 2281 model()->StopSyncing(syncer::SEARCH_ENGINES); |
2274 sync_processor_wrapper_.reset( | 2282 sync_processor_wrapper_.reset( |
2275 new syncer::SyncChangeProcessorWrapperForTest(sync_processor_.get())); | 2283 new syncer::SyncChangeProcessorWrapperForTest(sync_processor_.get())); |
2276 | 2284 |
2277 // Now test that a remote TemplateURL can override the attributes of the local | 2285 // Now test that a remote TemplateURL can override the attributes of the local |
2278 // default search provider. | 2286 // default search provider. |
2279 TemplateURL* existing_default = new TemplateURL(data); | 2287 TemplateURL* existing_default = new TemplateURL(data); |
2280 model()->Add(existing_default); | 2288 model()->Add(base::WrapUnique(existing_default)); |
2281 model()->SetUserSelectedDefaultSearchProvider(existing_default); | 2289 model()->SetUserSelectedDefaultSearchProvider(existing_default); |
2282 | 2290 |
2283 merge_result = model()->MergeDataAndStartSyncing( | 2291 merge_result = model()->MergeDataAndStartSyncing( |
2284 syncer::SEARCH_ENGINES, list, PassProcessor(), | 2292 syncer::SEARCH_ENGINES, list, PassProcessor(), |
2285 CreateAndPassSyncErrorFactory()); | 2293 CreateAndPassSyncErrorFactory()); |
2286 | 2294 |
2287 result_turl = model()->GetDefaultSearchProvider(); | 2295 result_turl = model()->GetDefaultSearchProvider(); |
2288 EXPECT_TRUE(result_turl); | 2296 EXPECT_TRUE(result_turl); |
2289 EXPECT_EQ(ASCIIToUTF16("new_kw"), result_turl->keyword()); | 2297 EXPECT_EQ(ASCIIToUTF16("new_kw"), result_turl->keyword()); |
2290 EXPECT_EQ(ASCIIToUTF16("my name"), result_turl->short_name()); | 2298 EXPECT_EQ(ASCIIToUTF16("my name"), result_turl->short_name()); |
2291 EXPECT_EQ(default_turl->url(), result_turl->url()); | 2299 EXPECT_EQ(default_turl->url(), result_turl->url()); |
2292 } | 2300 } |
2293 | 2301 |
2294 TEST_F(TemplateURLServiceSyncTest, MergeNonEditedPrepopulatedEngine) { | 2302 TEST_F(TemplateURLServiceSyncTest, MergeNonEditedPrepopulatedEngine) { |
2295 std::unique_ptr<TemplateURLData> default_turl( | 2303 std::unique_ptr<TemplateURLData> default_turl( |
2296 TemplateURLPrepopulateData::GetPrepopulatedDefaultSearch(NULL)); | 2304 TemplateURLPrepopulateData::GetPrepopulatedDefaultSearch(NULL)); |
2297 | 2305 |
2298 TemplateURLData data(*default_turl); | 2306 TemplateURLData data(*default_turl); |
2299 data.safe_for_autoreplace = true; // Can be replaced with built-in values. | 2307 data.safe_for_autoreplace = true; // Can be replaced with built-in values. |
2300 data.SetKeyword(ASCIIToUTF16("new_kw")); | 2308 data.SetKeyword(ASCIIToUTF16("new_kw")); |
2301 data.SetShortName(ASCIIToUTF16("my name")); | 2309 data.SetShortName(ASCIIToUTF16("my name")); |
2302 data.SetURL("http://wrong.url.com?q={searchTerms}"); | 2310 data.SetURL("http://wrong.url.com?q={searchTerms}"); |
2303 data.date_created = Time::FromTimeT(50); | 2311 data.date_created = Time::FromTimeT(50); |
2304 data.last_modified = Time::FromTimeT(50); | 2312 data.last_modified = Time::FromTimeT(50); |
2305 data.sync_guid = "default"; | 2313 data.sync_guid = "default"; |
2306 model()->Add(new TemplateURL(data)); | 2314 model()->Add(base::MakeUnique<TemplateURL>(data)); |
2307 | 2315 |
2308 data.date_created = Time::FromTimeT(100); | 2316 data.date_created = Time::FromTimeT(100); |
2309 data.last_modified = Time::FromTimeT(100); | 2317 data.last_modified = Time::FromTimeT(100); |
2310 std::unique_ptr<TemplateURL> sync_turl(new TemplateURL(data)); | 2318 std::unique_ptr<TemplateURL> sync_turl(new TemplateURL(data)); |
2311 syncer::SyncDataList list; | 2319 syncer::SyncDataList list; |
2312 list.push_back(TemplateURLService::CreateSyncDataFromTemplateURL(*sync_turl)); | 2320 list.push_back(TemplateURLService::CreateSyncDataFromTemplateURL(*sync_turl)); |
2313 syncer::SyncMergeResult merge_result = model()->MergeDataAndStartSyncing( | 2321 syncer::SyncMergeResult merge_result = model()->MergeDataAndStartSyncing( |
2314 syncer::SEARCH_ENGINES, list, PassProcessor(), | 2322 syncer::SEARCH_ENGINES, list, PassProcessor(), |
2315 CreateAndPassSyncErrorFactory()); | 2323 CreateAndPassSyncErrorFactory()); |
2316 | 2324 |
(...skipping 28 matching lines...) Expand all Loading... | |
2345 | 2353 |
2346 TEST_F(TemplateURLServiceSyncTest, NonAsciiKeywordDoesNotCrash) { | 2354 TEST_F(TemplateURLServiceSyncTest, NonAsciiKeywordDoesNotCrash) { |
2347 model()->Add(CreateTestTemplateURL(UTF8ToUTF16("\xf0\xaf\xa6\x8d"), | 2355 model()->Add(CreateTestTemplateURL(UTF8ToUTF16("\xf0\xaf\xa6\x8d"), |
2348 "http://key1.com")); | 2356 "http://key1.com")); |
2349 syncer::SyncDataList initial_data = CreateInitialSyncData(); | 2357 syncer::SyncDataList initial_data = CreateInitialSyncData(); |
2350 | 2358 |
2351 model()->MergeDataAndStartSyncing( | 2359 model()->MergeDataAndStartSyncing( |
2352 syncer::SEARCH_ENGINES, initial_data, PassProcessor(), | 2360 syncer::SEARCH_ENGINES, initial_data, PassProcessor(), |
2353 CreateAndPassSyncErrorFactory()); | 2361 CreateAndPassSyncErrorFactory()); |
2354 } | 2362 } |
OLD | NEW |