OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/memory/scoped_ptr.h" | 5 #include "base/memory/scoped_ptr.h" |
6 #include "base/memory/scoped_vector.h" | 6 #include "base/memory/scoped_vector.h" |
7 #include "base/string_util.h" | 7 #include "base/string_util.h" |
8 #include "base/time.h" | 8 #include "base/time.h" |
9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "chrome/browser/search_engines/search_terms_data.h" | 10 #include "chrome/browser/search_engines/search_terms_data.h" |
(...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
464 | 464 |
465 // If we force the method, it should uniquify the keyword even if it is | 465 // If we force the method, it should uniquify the keyword even if it is |
466 // currently unique, and skip the host-based autogenerated keyword. | 466 // currently unique, and skip the host-based autogenerated keyword. |
467 turl.reset( | 467 turl.reset( |
468 CreateTestTemplateURL(ASCIIToUTF16("unique"), "http://unique.com")); | 468 CreateTestTemplateURL(ASCIIToUTF16("unique"), "http://unique.com")); |
469 new_keyword = model()->UniquifyKeyword(*turl, true); | 469 new_keyword = model()->UniquifyKeyword(*turl, true); |
470 EXPECT_EQ(ASCIIToUTF16("unique_"), new_keyword); | 470 EXPECT_EQ(ASCIIToUTF16("unique_"), new_keyword); |
471 EXPECT_EQ(NULL, model()->GetTemplateURLForKeyword(new_keyword)); | 471 EXPECT_EQ(NULL, model()->GetTemplateURLForKeyword(new_keyword)); |
472 } | 472 } |
473 | 473 |
474 TEST_F(TemplateURLServiceSyncTest, IsLocalTemplateURLBetter) { | 474 TEST_F(TemplateURLServiceSyncTest, SyncKeywordConflictNeitherAutoreplace) { |
475 // Test some edge cases of this function. | |
476 const struct { | |
477 time_t local_time; | |
478 time_t sync_time; | |
479 bool local_is_default; | |
480 bool local_created_by_policy; | |
481 bool expected_result; | |
482 } test_cases[] = { | |
483 // Sync is better by timestamp but local is Default. | |
484 {10, 100, true, false, true}, | |
485 // Sync is better by timestamp but local is Create by Policy. | |
486 {10, 100, false, true, true}, | |
487 // Tie. Sync wins. | |
488 {100, 100, false, false, false}, | |
489 }; | |
490 | |
491 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); ++i) { | |
492 TemplateURL* local_turl = CreateTestTemplateURL( | |
493 ASCIIToUTF16("localkey"), "www.local.com", "localguid", | |
494 test_cases[i].local_time, true, test_cases[i].local_created_by_policy); | |
495 model()->Add(local_turl); | |
496 if (test_cases[i].local_is_default) | |
497 model()->SetDefaultSearchProvider(local_turl); | |
498 | |
499 scoped_ptr<TemplateURL> sync_turl(CreateTestTemplateURL( | |
500 ASCIIToUTF16("synckey"), "www.sync.com", "syncguid", | |
501 test_cases[i].sync_time)); | |
502 EXPECT_EQ(test_cases[i].expected_result, | |
503 model()->IsLocalTemplateURLBetter(local_turl, sync_turl.get())); | |
504 | |
505 // Undo the changes. | |
506 if (test_cases[i].local_is_default) | |
507 model()->SetDefaultSearchProvider(NULL); | |
508 model()->Remove(local_turl); | |
509 } | |
510 } | |
511 | |
512 TEST_F(TemplateURLServiceSyncTest, ResolveSyncKeywordConflict) { | |
513 // This tests cases where neither the sync nor the local TemplateURL are | 475 // This tests cases where neither the sync nor the local TemplateURL are |
514 // marked safe_for_autoreplace. | 476 // marked safe_for_autoreplace. |
515 | 477 |
516 // Create a keyword that conflicts, and make it older. Sync keyword is | 478 // Create a keyword that conflicts, and make it older. Sync keyword is |
517 // uniquified, and a syncer::SyncChange is added. | 479 // uniquified, and a syncer::SyncChange is added. |
518 string16 original_turl_keyword = ASCIIToUTF16("key1"); | 480 string16 original_turl_keyword = ASCIIToUTF16("key1"); |
519 TemplateURL* original_turl = CreateTestTemplateURL(original_turl_keyword, | 481 TemplateURL* original_turl = CreateTestTemplateURL(original_turl_keyword, |
520 "http://key1.com", std::string(), 9000); | 482 "http://key1.com", std::string(), 9000); |
521 model()->Add(original_turl); | 483 model()->Add(original_turl); |
522 scoped_ptr<TemplateURL> sync_turl(CreateTestTemplateURL(original_turl_keyword, | 484 scoped_ptr<TemplateURL> sync_turl(CreateTestTemplateURL(original_turl_keyword, |
523 "http://new.com", "remote", 8999)); | 485 "http://new.com", "remote", 8999)); |
524 syncer::SyncChangeList changes; | 486 syncer::SyncChangeList changes; |
525 model()->ResolveSyncKeywordConflict(sync_turl.get(), original_turl, &changes); | 487 EXPECT_TRUE(model()->ResolveSyncKeywordConflict(sync_turl.get(), |
| 488 original_turl, &changes)); |
526 EXPECT_NE(original_turl_keyword, sync_turl->keyword()); | 489 EXPECT_NE(original_turl_keyword, sync_turl->keyword()); |
527 EXPECT_EQ(original_turl_keyword, original_turl->keyword()); | 490 EXPECT_EQ(original_turl_keyword, original_turl->keyword()); |
528 ASSERT_EQ(1U, changes.size()); | 491 ASSERT_EQ(1U, changes.size()); |
529 EXPECT_EQ("remote", GetGUID(changes[0].sync_data())); | 492 EXPECT_EQ("remote", GetGUID(changes[0].sync_data())); |
530 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, changes[0].change_type()); | 493 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, changes[0].change_type()); |
531 changes.clear(); | 494 changes.clear(); |
532 model()->Remove(original_turl); | 495 model()->Remove(original_turl); |
533 | 496 |
534 // Sync is newer. Original TemplateURL keyword is uniquified. A SyncChange | 497 // Sync is newer. Original TemplateURL keyword is uniquified. A SyncChange |
535 // is added (which in a normal run would be deleted by PruneSyncChanges() when | 498 // is added (which in a normal run would be deleted by PruneSyncChanges() when |
536 // the local GUID doesn't appear in the sync GUID list). Also ensure that | 499 // the local GUID doesn't appear in the sync GUID list). Also ensure that |
537 // this does not change the safe_for_autoreplace flag or the TemplateURLID in | 500 // this does not change the safe_for_autoreplace flag or the TemplateURLID in |
538 // the original. | 501 // the original. |
539 original_turl = CreateTestTemplateURL(original_turl_keyword, | 502 original_turl = CreateTestTemplateURL(original_turl_keyword, |
540 "http://key1.com", "local", 9000); | 503 "http://key1.com", "local", 9000); |
541 model()->Add(original_turl); | 504 model()->Add(original_turl); |
542 TemplateURLID original_id = original_turl->id(); | 505 TemplateURLID original_id = original_turl->id(); |
543 sync_turl.reset(CreateTestTemplateURL(original_turl_keyword, "http://new.com", | 506 sync_turl.reset(CreateTestTemplateURL(original_turl_keyword, "http://new.com", |
544 std::string(), 9001)); | 507 std::string(), 9001)); |
545 model()->ResolveSyncKeywordConflict(sync_turl.get(), original_turl, &changes); | 508 EXPECT_TRUE(model()->ResolveSyncKeywordConflict(sync_turl.get(), |
| 509 original_turl, &changes)); |
546 EXPECT_EQ(original_turl_keyword, sync_turl->keyword()); | 510 EXPECT_EQ(original_turl_keyword, sync_turl->keyword()); |
547 EXPECT_NE(original_turl_keyword, original_turl->keyword()); | 511 EXPECT_NE(original_turl_keyword, original_turl->keyword()); |
548 EXPECT_FALSE(original_turl->safe_for_autoreplace()); | 512 EXPECT_FALSE(original_turl->safe_for_autoreplace()); |
549 EXPECT_EQ(original_id, original_turl->id()); | 513 EXPECT_EQ(original_id, original_turl->id()); |
550 EXPECT_EQ(NULL, model()->GetTemplateURLForKeyword(original_turl_keyword)); | 514 EXPECT_EQ(NULL, model()->GetTemplateURLForKeyword(original_turl_keyword)); |
551 ASSERT_EQ(1U, changes.size()); | 515 ASSERT_EQ(1U, changes.size()); |
552 EXPECT_EQ("local", GetGUID(changes[0].sync_data())); | 516 EXPECT_EQ("local", GetGUID(changes[0].sync_data())); |
553 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, changes[0].change_type()); | 517 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, changes[0].change_type()); |
554 changes.clear(); | 518 changes.clear(); |
555 model()->Remove(original_turl); | 519 model()->Remove(original_turl); |
556 | 520 |
557 // Equal times. Same result as above. Sync left alone, original uniquified so | 521 // Equal times. Same result as above. Sync left alone, original uniquified so |
558 // sync_turl can fit. | 522 // sync_turl can fit. |
559 original_turl = CreateTestTemplateURL(original_turl_keyword, | 523 original_turl = CreateTestTemplateURL(original_turl_keyword, |
560 "http://key1.com", "local2", 9000); | 524 "http://key1.com", "local2", 9000); |
561 model()->Add(original_turl); | 525 model()->Add(original_turl); |
562 sync_turl.reset(CreateTestTemplateURL(original_turl_keyword, "http://new.com", | 526 sync_turl.reset(CreateTestTemplateURL(original_turl_keyword, "http://new.com", |
563 std::string(), 9000)); | 527 std::string(), 9000)); |
564 model()->ResolveSyncKeywordConflict(sync_turl.get(), original_turl, &changes); | 528 EXPECT_TRUE(model()->ResolveSyncKeywordConflict(sync_turl.get(), |
| 529 original_turl, &changes)); |
565 EXPECT_EQ(original_turl_keyword, sync_turl->keyword()); | 530 EXPECT_EQ(original_turl_keyword, sync_turl->keyword()); |
566 EXPECT_NE(original_turl_keyword, original_turl->keyword()); | 531 EXPECT_NE(original_turl_keyword, original_turl->keyword()); |
567 EXPECT_EQ(NULL, model()->GetTemplateURLForKeyword(original_turl_keyword)); | 532 EXPECT_EQ(NULL, model()->GetTemplateURLForKeyword(original_turl_keyword)); |
568 ASSERT_EQ(1U, changes.size()); | 533 ASSERT_EQ(1U, changes.size()); |
569 EXPECT_EQ("local2", GetGUID(changes[0].sync_data())); | 534 EXPECT_EQ("local2", GetGUID(changes[0].sync_data())); |
570 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, changes[0].change_type()); | 535 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, changes[0].change_type()); |
571 changes.clear(); | 536 changes.clear(); |
572 model()->Remove(original_turl); | 537 model()->Remove(original_turl); |
573 | 538 |
574 // Sync is newer, but original TemplateURL is created by policy, so it wins. | 539 // Sync is newer, but original TemplateURL is created by policy, so it wins. |
575 // Sync keyword is uniquified, and a syncer::SyncChange is added. | 540 // Sync keyword is uniquified, and a syncer::SyncChange is added. |
576 original_turl = CreateTestTemplateURL(original_turl_keyword, | 541 original_turl = CreateTestTemplateURL(original_turl_keyword, |
577 "http://key1.com", std::string(), 9000, false, true); | 542 "http://key1.com", std::string(), 9000, false, true); |
578 model()->Add(original_turl); | 543 model()->Add(original_turl); |
579 sync_turl.reset(CreateTestTemplateURL(original_turl_keyword, "http://new.com", | 544 sync_turl.reset(CreateTestTemplateURL(original_turl_keyword, "http://new.com", |
580 "remote2", 9999)); | 545 "remote2", 9999)); |
581 model()->ResolveSyncKeywordConflict(sync_turl.get(), original_turl, &changes); | 546 EXPECT_TRUE(model()->ResolveSyncKeywordConflict(sync_turl.get(), |
| 547 original_turl, &changes)); |
582 EXPECT_NE(original_turl_keyword, sync_turl->keyword()); | 548 EXPECT_NE(original_turl_keyword, sync_turl->keyword()); |
583 EXPECT_EQ(original_turl_keyword, original_turl->keyword()); | 549 EXPECT_EQ(original_turl_keyword, original_turl->keyword()); |
584 EXPECT_EQ(NULL, model()->GetTemplateURLForKeyword(sync_turl->keyword())); | 550 EXPECT_EQ(NULL, model()->GetTemplateURLForKeyword(sync_turl->keyword())); |
585 ASSERT_EQ(1U, changes.size()); | 551 ASSERT_EQ(1U, changes.size()); |
586 EXPECT_EQ("remote2", GetGUID(changes[0].sync_data())); | 552 EXPECT_EQ("remote2", GetGUID(changes[0].sync_data())); |
587 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, changes[0].change_type()); | 553 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, changes[0].change_type()); |
588 changes.clear(); | 554 changes.clear(); |
589 model()->Remove(original_turl); | 555 model()->Remove(original_turl); |
590 } | 556 } |
591 | 557 |
| 558 TEST_F(TemplateURLServiceSyncTest, SyncKeywordConflictBothAutoreplace) { |
| 559 // This tests cases where both the sync and the local TemplateURL are marked |
| 560 // safe_for_autoreplace. |
| 561 |
| 562 // Create a keyword that conflicts, and make it older. SyncChange is added, |
| 563 // function returns false. |
| 564 string16 original_turl_keyword = ASCIIToUTF16("key1"); |
| 565 TemplateURL* original_turl = CreateTestTemplateURL(original_turl_keyword, |
| 566 "http://key1.com", std::string(), 9000, true); |
| 567 model()->Add(original_turl); |
| 568 scoped_ptr<TemplateURL> sync_turl(CreateTestTemplateURL(original_turl_keyword, |
| 569 "http://new.com", "remote", 8999, true)); |
| 570 syncer::SyncChangeList changes; |
| 571 EXPECT_FALSE(model()->ResolveSyncKeywordConflict(sync_turl.get(), |
| 572 original_turl, &changes)); |
| 573 EXPECT_EQ(original_turl, |
| 574 model()->GetTemplateURLForKeyword(original_turl_keyword)); |
| 575 ASSERT_EQ(1U, changes.size()); |
| 576 EXPECT_EQ("remote", GetGUID(changes[0].sync_data())); |
| 577 EXPECT_EQ(syncer::SyncChange::ACTION_DELETE, changes[0].change_type()); |
| 578 changes.clear(); |
| 579 model()->Remove(original_turl); |
| 580 |
| 581 // Sync is newer. Original TemplateURL is removed from the model. A |
| 582 // syncer::SyncChange is added (which in a normal run would be deleted by |
| 583 // PruneSyncChanges() when the local GUID doesn't appear in the sync GUID |
| 584 // list). |
| 585 original_turl = CreateTestTemplateURL(original_turl_keyword, |
| 586 "http://key1.com", "local", 9000, true); |
| 587 model()->Add(original_turl); |
| 588 sync_turl.reset(CreateTestTemplateURL(original_turl_keyword, "http://new.com", |
| 589 std::string(), 9001, true)); |
| 590 EXPECT_TRUE(model()->ResolveSyncKeywordConflict(sync_turl.get(), |
| 591 original_turl, &changes)); |
| 592 EXPECT_EQ(original_turl_keyword, sync_turl->keyword()); |
| 593 EXPECT_TRUE(model()->GetTemplateURLs().empty()); |
| 594 ASSERT_EQ(1U, changes.size()); |
| 595 EXPECT_EQ("local", GetGUID(changes[0].sync_data())); |
| 596 EXPECT_EQ(syncer::SyncChange::ACTION_DELETE, changes[0].change_type()); |
| 597 changes.clear(); |
| 598 |
| 599 // Equal times. Same result as above. Sync left alone, original removed so |
| 600 // sync_turl can fit. |
| 601 original_turl = CreateTestTemplateURL(original_turl_keyword, |
| 602 "http://key1.com", "local2", 9000, true); |
| 603 model()->Add(original_turl); |
| 604 sync_turl.reset(CreateTestTemplateURL(original_turl_keyword, "http://new.com", |
| 605 std::string(), 9000, true)); |
| 606 EXPECT_TRUE(model()->ResolveSyncKeywordConflict(sync_turl.get(), |
| 607 original_turl, &changes)); |
| 608 EXPECT_EQ(original_turl_keyword, sync_turl->keyword()); |
| 609 EXPECT_TRUE(model()->GetTemplateURLs().empty()); |
| 610 ASSERT_EQ(1U, changes.size()); |
| 611 EXPECT_EQ("local2", GetGUID(changes[0].sync_data())); |
| 612 EXPECT_EQ(syncer::SyncChange::ACTION_DELETE, changes[0].change_type()); |
| 613 changes.clear(); |
| 614 |
| 615 // Sync is newer, but original TemplateURL is created by policy, so it wins. |
| 616 // syncer::SyncChange is added, function returns false. |
| 617 original_turl = CreateTestTemplateURL(original_turl_keyword, |
| 618 "http://key1.com", std::string(), 9000, true, true); |
| 619 model()->Add(original_turl); |
| 620 sync_turl.reset(CreateTestTemplateURL(original_turl_keyword, "http://new.com", |
| 621 "remote2", 9999, true)); |
| 622 EXPECT_FALSE(model()->ResolveSyncKeywordConflict(sync_turl.get(), |
| 623 original_turl, &changes)); |
| 624 EXPECT_EQ(original_turl, |
| 625 model()->GetTemplateURLForKeyword(original_turl_keyword)); |
| 626 ASSERT_EQ(1U, changes.size()); |
| 627 EXPECT_EQ("remote2", GetGUID(changes[0].sync_data())); |
| 628 EXPECT_EQ(syncer::SyncChange::ACTION_DELETE, changes[0].change_type()); |
| 629 changes.clear(); |
| 630 model()->Remove(original_turl); |
| 631 } |
| 632 |
| 633 TEST_F(TemplateURLServiceSyncTest, SyncKeywordConflictOneAutoreplace) { |
| 634 // This tests cases where either the sync or the local TemplateURL is marked |
| 635 // safe_for_autoreplace, but the other is not. Basically, we run the same |
| 636 // tests as in SyncKeywordConflictBothAutoreplace, but mark the keywords so as |
| 637 // to reverse the outcome of each test. |
| 638 |
| 639 // Create a keyword that conflicts, and make it older. Normally the local |
| 640 // TemplateURL would win this. |
| 641 string16 original_turl_keyword = ASCIIToUTF16("key1"); |
| 642 TemplateURL* original_turl = CreateTestTemplateURL(original_turl_keyword, |
| 643 "http://key1.com", "local", 9000, true); |
| 644 model()->Add(original_turl); |
| 645 scoped_ptr<TemplateURL> sync_turl(CreateTestTemplateURL(original_turl_keyword, |
| 646 "http://new.com", std::string(), 8999)); |
| 647 syncer::SyncChangeList changes; |
| 648 EXPECT_TRUE(model()->ResolveSyncKeywordConflict(sync_turl.get(), |
| 649 original_turl, &changes)); |
| 650 EXPECT_EQ(original_turl_keyword, sync_turl->keyword()); |
| 651 EXPECT_TRUE(model()->GetTemplateURLs().empty()); |
| 652 ASSERT_EQ(1U, changes.size()); |
| 653 EXPECT_EQ("local", GetGUID(changes[0].sync_data())); |
| 654 EXPECT_EQ(syncer::SyncChange::ACTION_DELETE, changes[0].change_type()); |
| 655 changes.clear(); |
| 656 |
| 657 // Sync is newer. Normally the sync TemplateURL would win this. |
| 658 original_turl = CreateTestTemplateURL(original_turl_keyword, |
| 659 "http://key1.com", std::string(), 9000); |
| 660 model()->Add(original_turl); |
| 661 sync_turl.reset(CreateTestTemplateURL(original_turl_keyword, "http://new.com", |
| 662 "remote", 9001, true)); |
| 663 EXPECT_FALSE(model()->ResolveSyncKeywordConflict(sync_turl.get(), |
| 664 original_turl, &changes)); |
| 665 EXPECT_EQ(original_turl, |
| 666 model()->GetTemplateURLForKeyword(original_turl_keyword)); |
| 667 ASSERT_EQ(1U, changes.size()); |
| 668 EXPECT_EQ("remote", GetGUID(changes[0].sync_data())); |
| 669 EXPECT_EQ(syncer::SyncChange::ACTION_DELETE, changes[0].change_type()); |
| 670 changes.clear(); |
| 671 model()->Remove(original_turl); |
| 672 |
| 673 // Equal times. Same result as above. |
| 674 original_turl = CreateTestTemplateURL(original_turl_keyword, |
| 675 "http://key1.com", std::string(), 9000); |
| 676 model()->Add(original_turl); |
| 677 sync_turl.reset(CreateTestTemplateURL(original_turl_keyword, "http://new.com", |
| 678 "remote2", 9000, true)); |
| 679 EXPECT_FALSE(model()->ResolveSyncKeywordConflict(sync_turl.get(), |
| 680 original_turl, &changes)); |
| 681 EXPECT_EQ(original_turl, |
| 682 model()->GetTemplateURLForKeyword(original_turl_keyword)); |
| 683 ASSERT_EQ(1U, changes.size()); |
| 684 EXPECT_EQ("remote2", GetGUID(changes[0].sync_data())); |
| 685 EXPECT_EQ(syncer::SyncChange::ACTION_DELETE, changes[0].change_type()); |
| 686 changes.clear(); |
| 687 model()->Remove(original_turl); |
| 688 |
| 689 // We don't run the "created by policy" test since URLs created by policy are |
| 690 // never safe_for_autoreplace. |
| 691 } |
| 692 |
| 693 TEST_F(TemplateURLServiceSyncTest, FindDuplicateOfSyncTemplateURL) { |
| 694 TemplateURL* original_turl = |
| 695 CreateTestTemplateURL(ASCIIToUTF16("key1"), "http://key1.com"); |
| 696 model()->Add(original_turl); |
| 697 |
| 698 // No matches at all. |
| 699 scoped_ptr<TemplateURL> sync_turl(CreateTestTemplateURL(ASCIIToUTF16("key2"), |
| 700 "http://key2.com")); |
| 701 EXPECT_EQ(NULL, model()->FindDuplicateOfSyncTemplateURL(*sync_turl)); |
| 702 |
| 703 // URL matches, but not keyword. No dupe. |
| 704 sync_turl.reset(CreateTestTemplateURL(ASCIIToUTF16("key2"), |
| 705 "http://key1.com")); |
| 706 EXPECT_EQ(NULL, model()->FindDuplicateOfSyncTemplateURL(*sync_turl)); |
| 707 |
| 708 // Keyword matches, but not URL. No dupe. |
| 709 sync_turl.reset(CreateTestTemplateURL(ASCIIToUTF16("key1"), |
| 710 "http://key2.com")); |
| 711 EXPECT_EQ(NULL, model()->FindDuplicateOfSyncTemplateURL(*sync_turl)); |
| 712 |
| 713 // Duplicate. |
| 714 sync_turl.reset(CreateTestTemplateURL(ASCIIToUTF16("key1"), |
| 715 "http://key1.com")); |
| 716 const TemplateURL* dupe_turl = |
| 717 model()->FindDuplicateOfSyncTemplateURL(*sync_turl); |
| 718 ASSERT_TRUE(dupe_turl); |
| 719 EXPECT_EQ(dupe_turl->keyword(), sync_turl->keyword()); |
| 720 EXPECT_EQ(dupe_turl->url(), sync_turl->url()); |
| 721 } |
| 722 |
| 723 TEST_F(TemplateURLServiceSyncTest, MergeSyncAndLocalURLDuplicates) { |
| 724 TemplateURL* original_turl = CreateTestTemplateURL(ASCIIToUTF16("key1"), |
| 725 "http://key1.com", std::string(), 9000); |
| 726 model()->Add(original_turl); |
| 727 TemplateURL* sync_turl = CreateTestTemplateURL(ASCIIToUTF16("key1"), |
| 728 "http://key1.com", std::string(), 9001); |
| 729 std::string original_guid = original_turl->sync_guid(); |
| 730 syncer::SyncChangeList changes; |
| 731 |
| 732 // The sync TemplateURL is newer. It should replace the original TemplateURL |
| 733 // and a syncer::SyncChange should be added to the list. |
| 734 // Note that MergeSyncAndLocalURLDuplicates takes ownership of sync_turl. |
| 735 model()->MergeSyncAndLocalURLDuplicates(sync_turl, original_turl, &changes); |
| 736 TemplateURL* result = model()->GetTemplateURLForKeyword(ASCIIToUTF16("key1")); |
| 737 ASSERT_TRUE(result); |
| 738 EXPECT_EQ(9001, result->last_modified().ToTimeT()); |
| 739 EXPECT_EQ(1U, changes.size()); |
| 740 // We expect a change to delete the local entry. |
| 741 syncer::SyncChange change = changes.at(0); |
| 742 EXPECT_EQ(syncer::SyncChange::ACTION_DELETE, change.change_type()); |
| 743 EXPECT_EQ(original_guid, |
| 744 change.sync_data().GetSpecifics().search_engine().sync_guid()); |
| 745 changes.clear(); |
| 746 |
| 747 // The sync TemplateURL is older. The existing TemplateURL should win and a |
| 748 // syncer::SyncChange should be added to the list. |
| 749 TemplateURL* sync_turl2 = CreateTestTemplateURL(ASCIIToUTF16("key1"), |
| 750 "http://key1.com", std::string(), 8999); |
| 751 std::string sync_guid = sync_turl2->sync_guid(); |
| 752 model()->MergeSyncAndLocalURLDuplicates(sync_turl2, sync_turl, &changes); |
| 753 result = model()->GetTemplateURLForKeyword(ASCIIToUTF16("key1")); |
| 754 ASSERT_TRUE(result); |
| 755 EXPECT_EQ(9001, result->last_modified().ToTimeT()); |
| 756 EXPECT_EQ(1U, changes.size()); |
| 757 // We expect a change to update the sync entry. |
| 758 change = changes.at(0); |
| 759 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, change.change_type()); |
| 760 EXPECT_EQ(sync_guid, |
| 761 change.sync_data().GetSpecifics().search_engine().sync_guid()); |
| 762 } |
| 763 |
592 TEST_F(TemplateURLServiceSyncTest, StartSyncEmpty) { | 764 TEST_F(TemplateURLServiceSyncTest, StartSyncEmpty) { |
593 model()->MergeDataAndStartSyncing( | 765 model()->MergeDataAndStartSyncing( |
594 syncer::SEARCH_ENGINES, syncer::SyncDataList(), | 766 syncer::SEARCH_ENGINES, syncer::SyncDataList(), |
595 PassProcessor(), CreateAndPassSyncErrorFactory()); | 767 PassProcessor(), CreateAndPassSyncErrorFactory()); |
596 | 768 |
597 EXPECT_EQ(0U, model()->GetAllSyncData(syncer::SEARCH_ENGINES).size()); | 769 EXPECT_EQ(0U, model()->GetAllSyncData(syncer::SEARCH_ENGINES).size()); |
598 EXPECT_EQ(0U, processor()->change_list_size()); | 770 EXPECT_EQ(0U, processor()->change_list_size()); |
599 } | 771 } |
600 | 772 |
601 TEST_F(TemplateURLServiceSyncTest, MergeIntoEmpty) { | 773 TEST_F(TemplateURLServiceSyncTest, MergeIntoEmpty) { |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
719 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("key2"), | 891 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("key2"), |
720 "http://expected.com", "bbb", 100)); // keyword conflict | 892 "http://expected.com", "bbb", 100)); // keyword conflict |
721 | 893 |
722 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("unique"), | 894 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("unique"), |
723 "http://unique.com", "ccc")); // add | 895 "http://unique.com", "ccc")); // add |
724 | 896 |
725 model()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES, | 897 model()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES, |
726 CreateInitialSyncData(), PassProcessor(), | 898 CreateInitialSyncData(), PassProcessor(), |
727 CreateAndPassSyncErrorFactory()); | 899 CreateAndPassSyncErrorFactory()); |
728 | 900 |
729 // The dupe and conflict results in merges, as local values are always merged | 901 // The dupe results in a merge. The other two should be added to the model. |
730 // with sync values if there is a keyword conflict. The unique keyword should | 902 EXPECT_EQ(5U, model()->GetAllSyncData(syncer::SEARCH_ENGINES).size()); |
731 // be added. | |
732 EXPECT_EQ(4U, model()->GetAllSyncData(syncer::SEARCH_ENGINES).size()); | |
733 | 903 |
734 // The key1 duplicate results in the local copy winning. Ensure that Sync's | 904 // The key1 duplicate results in the local copy winning. Ensure that Sync's |
735 // copy was not added, and the local copy is pushed upstream to Sync as an | 905 // copy was not added, and the local copy is pushed upstream to Sync as an |
736 // update. The local copy should have received the sync data's GUID. | 906 // update. The local copy should have received the sync data's GUID. |
737 EXPECT_TRUE(model()->GetTemplateURLForGUID("key1")); | 907 EXPECT_TRUE(model()->GetTemplateURLForGUID("key1")); |
738 // Check changes for the UPDATE. | 908 // Check changes for the UPDATE. |
739 ASSERT_TRUE(processor()->contains_guid("key1")); | 909 ASSERT_TRUE(processor()->contains_guid("key1")); |
740 syncer::SyncChange key1_change = processor()->change_for_guid("key1"); | 910 syncer::SyncChange key1_change = processor()->change_for_guid("key1"); |
741 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, key1_change.change_type()); | 911 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, key1_change.change_type()); |
742 // The local sync_guid should no longer be found. | |
743 EXPECT_FALSE(model()->GetTemplateURLForGUID("aaa")); | 912 EXPECT_FALSE(model()->GetTemplateURLForGUID("aaa")); |
744 | 913 |
745 // The key2 keyword conflict results in a merge, with the values of the local | 914 // The key2 keyword conflict results in the local copy winning, so ensure it |
746 // copy winning, so ensure it retains the original URL, and that an update to | 915 // retains the original keyword, and that an update to the sync copy is pushed |
747 // the sync guid is pushed upstream to Sync. | 916 // upstream to Sync. Both TemplateURLs should be found locally, however. |
748 const TemplateURL* key2 = model()->GetTemplateURLForGUID("key2"); | 917 const TemplateURL* key2 = model()->GetTemplateURLForGUID("bbb"); |
749 ASSERT_TRUE(key2); | 918 EXPECT_TRUE(key2); |
750 EXPECT_EQ(ASCIIToUTF16("key2"), key2->keyword()); | 919 EXPECT_EQ(ASCIIToUTF16("key2"), key2->keyword()); |
751 EXPECT_EQ("http://expected.com", key2->url()); | 920 EXPECT_TRUE(model()->GetTemplateURLForGUID("key2")); |
752 // Check changes for the UPDATE. | 921 // Check changes for the UPDATE. |
753 ASSERT_TRUE(processor()->contains_guid("key2")); | 922 ASSERT_TRUE(processor()->contains_guid("key2")); |
754 syncer::SyncChange key2_change = processor()->change_for_guid("key2"); | 923 syncer::SyncChange key2_change = processor()->change_for_guid("key2"); |
755 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, key2_change.change_type()); | 924 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, key2_change.change_type()); |
756 EXPECT_EQ("key2", GetKeyword(key2_change.sync_data())); | 925 EXPECT_EQ("key2.com", GetKeyword(key2_change.sync_data())); |
757 EXPECT_EQ("http://expected.com", GetURL(key2_change.sync_data())); | |
758 // The local sync_guid should no longer be found. | |
759 EXPECT_FALSE(model()->GetTemplateURLForGUID("bbb")); | |
760 | 926 |
761 // The last TemplateURL should have had no conflicts and was just added. It | 927 // The last TemplateURL should have had no conflicts and was just added. It |
762 // should not have replaced the third local TemplateURL. | 928 // should not have replaced the third local TemplateURL. |
763 EXPECT_TRUE(model()->GetTemplateURLForGUID("ccc")); | 929 EXPECT_TRUE(model()->GetTemplateURLForGUID("ccc")); |
764 EXPECT_TRUE(model()->GetTemplateURLForGUID("key3")); | 930 EXPECT_TRUE(model()->GetTemplateURLForGUID("key3")); |
765 | 931 |
766 // Two UPDATEs and one ADD. | 932 // Two UPDATEs and two ADDs. |
767 EXPECT_EQ(3U, processor()->change_list_size()); | 933 EXPECT_EQ(4U, processor()->change_list_size()); |
768 // One ADDs should be pushed up to Sync. | 934 // Two ADDs should be pushed up to Sync. |
| 935 ASSERT_TRUE(processor()->contains_guid("bbb")); |
| 936 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, |
| 937 processor()->change_for_guid("bbb").change_type()); |
769 ASSERT_TRUE(processor()->contains_guid("ccc")); | 938 ASSERT_TRUE(processor()->contains_guid("ccc")); |
770 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, | 939 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, |
771 processor()->change_for_guid("ccc").change_type()); | 940 processor()->change_for_guid("ccc").change_type()); |
772 } | 941 } |
773 | 942 |
774 TEST_F(TemplateURLServiceSyncTest, MergeAddFromNewerSyncData) { | 943 TEST_F(TemplateURLServiceSyncTest, MergeAddFromNewerSyncData) { |
775 // GUIDs all differ, so Sync may overtake some entries, but the timestamps | 944 // GUIDs all differ, so this is data to be added from Sync, but the timestamps |
776 // from Sync are newer. Set up the local data so that one is a dupe, one has a | 945 // from Sync are newer. Set up the local data so that one is a dupe, one has a |
777 // conflicting keyword, and the last has no conflicts (a clean ADD). | 946 // conflicting keyword, and the last has no conflicts (a clean ADD). |
778 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("key1"), "http://key1.com", | 947 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("key1"), "http://key1.com", |
779 "aaa", 10)); // dupe | 948 "aaa", 10)); // dupe |
780 | 949 |
781 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("key2"), | 950 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("key2"), |
782 "http://expected.com", "bbb", 10)); // keyword conflict | 951 "http://expected.com", "bbb", 10)); // keyword conflict |
783 | 952 |
784 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("unique"), | 953 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("unique"), |
785 "http://unique.com", "ccc", 10)); // add | 954 "http://unique.com", "ccc", 10)); // add |
786 | 955 |
787 model()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES, | 956 model()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES, |
788 CreateInitialSyncData(), PassProcessor(), | 957 CreateInitialSyncData(), PassProcessor(), |
789 CreateAndPassSyncErrorFactory()); | 958 CreateAndPassSyncErrorFactory()); |
790 | 959 |
791 // The dupe and keyword conflict results in merges. The unique keyword be | 960 // The dupe results in a merge. The other two should be added to the model. |
792 // added to the model. | 961 EXPECT_EQ(5U, model()->GetAllSyncData(syncer::SEARCH_ENGINES).size()); |
793 EXPECT_EQ(4U, model()->GetAllSyncData(syncer::SEARCH_ENGINES).size()); | |
794 | 962 |
795 // The key1 duplicate results in Sync's copy winning. Ensure that Sync's | 963 // The key1 duplicate results in Sync's copy winning. Ensure that Sync's |
796 // copy replaced the local copy. | 964 // copy replaced the local copy. |
797 EXPECT_TRUE(model()->GetTemplateURLForGUID("key1")); | 965 EXPECT_TRUE(model()->GetTemplateURLForGUID("key1")); |
798 EXPECT_FALSE(model()->GetTemplateURLForGUID("aaa")); | 966 EXPECT_FALSE(model()->GetTemplateURLForGUID("aaa")); |
799 EXPECT_FALSE(processor()->contains_guid("key1")); | |
800 EXPECT_FALSE(processor()->contains_guid("aaa")); | |
801 | 967 |
802 // The key2 keyword conflict results in Sync's copy winning, so ensure it | 968 // The key2 keyword conflict results in Sync's copy winning, so ensure it |
803 // retains the original keyword and is added. The local copy should be | 969 // retains the original keyword. The local copy should get a uniquified |
804 // removed. | 970 // keyword. Both TemplateURLs should be found locally. |
805 const TemplateURL* key2_sync = model()->GetTemplateURLForGUID("key2"); | 971 const TemplateURL* key2_sync = model()->GetTemplateURLForGUID("key2"); |
806 ASSERT_TRUE(key2_sync); | 972 ASSERT_TRUE(key2_sync); |
807 EXPECT_EQ(ASCIIToUTF16("key2"), key2_sync->keyword()); | 973 EXPECT_EQ(ASCIIToUTF16("key2"), key2_sync->keyword()); |
808 EXPECT_FALSE(model()->GetTemplateURLForGUID("bbb")); | 974 const TemplateURL* key2_local = model()->GetTemplateURLForGUID("bbb"); |
| 975 ASSERT_TRUE(key2_local); |
| 976 EXPECT_EQ(ASCIIToUTF16("expected.com"), key2_local->keyword()); |
809 | 977 |
810 // The last TemplateURL should have had no conflicts and was just added. It | 978 // The last TemplateURL should have had no conflicts and was just added. It |
811 // should not have replaced the third local TemplateURL. | 979 // should not have replaced the third local TemplateURL. |
812 EXPECT_TRUE(model()->GetTemplateURLForGUID("ccc")); | 980 EXPECT_TRUE(model()->GetTemplateURLForGUID("ccc")); |
813 EXPECT_TRUE(model()->GetTemplateURLForGUID("key3")); | 981 EXPECT_TRUE(model()->GetTemplateURLForGUID("key3")); |
814 | 982 |
815 // One ADD. | 983 // Two ADDs. |
816 EXPECT_EQ(1U, processor()->change_list_size()); | 984 EXPECT_EQ(2U, processor()->change_list_size()); |
817 // One ADDs should be pushed up to Sync. | 985 // Two ADDs should be pushed up to Sync. |
| 986 ASSERT_TRUE(processor()->contains_guid("bbb")); |
| 987 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, |
| 988 processor()->change_for_guid("bbb").change_type()); |
818 ASSERT_TRUE(processor()->contains_guid("ccc")); | 989 ASSERT_TRUE(processor()->contains_guid("ccc")); |
819 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, | 990 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, |
820 processor()->change_for_guid("ccc").change_type()); | 991 processor()->change_for_guid("ccc").change_type()); |
821 } | 992 } |
822 | 993 |
823 TEST_F(TemplateURLServiceSyncTest, ProcessChangesEmptyModel) { | 994 TEST_F(TemplateURLServiceSyncTest, ProcessChangesEmptyModel) { |
824 // We initially have no data. | 995 // We initially have no data. |
825 model()->MergeDataAndStartSyncing( | 996 model()->MergeDataAndStartSyncing( |
826 syncer::SEARCH_ENGINES, syncer::SyncDataList(), | 997 syncer::SEARCH_ENGINES, syncer::SyncDataList(), |
827 PassProcessor(), CreateAndPassSyncErrorFactory()); | 998 PassProcessor(), CreateAndPassSyncErrorFactory()); |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
957 model()->GetTemplateURLForKeyword(ASCIIToUTF16("key3"))); | 1128 model()->GetTemplateURLForKeyword(ASCIIToUTF16("key3"))); |
958 | 1129 |
959 ASSERT_TRUE(processor()->contains_guid("aaa")); | 1130 ASSERT_TRUE(processor()->contains_guid("aaa")); |
960 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, | 1131 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, |
961 processor()->change_for_guid("aaa").change_type()); | 1132 processor()->change_for_guid("aaa").change_type()); |
962 ASSERT_TRUE(processor()->contains_guid("key1")); | 1133 ASSERT_TRUE(processor()->contains_guid("key1")); |
963 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, | 1134 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, |
964 processor()->change_for_guid("key1").change_type()); | 1135 processor()->change_for_guid("key1").change_type()); |
965 } | 1136 } |
966 | 1137 |
| 1138 TEST_F(TemplateURLServiceSyncTest, RemoveUpdatedURLOnConflict) { |
| 1139 // Updating a local replaceable URL to have the same keyword as a local |
| 1140 // non-replaceable URL should result in the former being removed from the |
| 1141 // model entirely. |
| 1142 syncer::SyncDataList initial_data; |
| 1143 scoped_ptr<TemplateURL> turl(CreateTestTemplateURL(ASCIIToUTF16("sync"), |
| 1144 "http://sync.com", "sync", 100, true)); |
| 1145 initial_data.push_back( |
| 1146 TemplateURLService::CreateSyncDataFromTemplateURL(*turl)); |
| 1147 model()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES, initial_data, |
| 1148 PassProcessor(), CreateAndPassSyncErrorFactory()); |
| 1149 |
| 1150 TemplateURL* new_turl = |
| 1151 CreateTestTemplateURL(ASCIIToUTF16("local"), "http://local.com", "local"); |
| 1152 model()->Add(new_turl); |
| 1153 |
| 1154 syncer::SyncChangeList changes; |
| 1155 changes.push_back(CreateTestSyncChange(syncer::SyncChange::ACTION_UPDATE, |
| 1156 CreateTestTemplateURL(ASCIIToUTF16("local"), "http://sync.com", "sync", |
| 1157 110, true))); |
| 1158 model()->ProcessSyncChanges(FROM_HERE, changes); |
| 1159 |
| 1160 EXPECT_EQ(1U, model()->GetTemplateURLs().size()); |
| 1161 EXPECT_EQ("local", |
| 1162 model()->GetTemplateURLForKeyword(ASCIIToUTF16("local"))->sync_guid()); |
| 1163 EXPECT_EQ(1U, processor()->change_list_size()); |
| 1164 ASSERT_TRUE(processor()->contains_guid("sync")); |
| 1165 EXPECT_EQ(syncer::SyncChange::ACTION_DELETE, |
| 1166 processor()->change_for_guid("sync").change_type()); |
| 1167 } |
| 1168 |
967 TEST_F(TemplateURLServiceSyncTest, ProcessTemplateURLChange) { | 1169 TEST_F(TemplateURLServiceSyncTest, ProcessTemplateURLChange) { |
968 // Ensure that ProcessTemplateURLChange is called and pushes the correct | 1170 // Ensure that ProcessTemplateURLChange is called and pushes the correct |
969 // changes to Sync whenever local changes are made to TemplateURLs. | 1171 // changes to Sync whenever local changes are made to TemplateURLs. |
970 model()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES, | 1172 model()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES, |
971 CreateInitialSyncData(), PassProcessor(), | 1173 CreateInitialSyncData(), PassProcessor(), |
972 CreateAndPassSyncErrorFactory()); | 1174 CreateAndPassSyncErrorFactory()); |
973 | 1175 |
974 // Add a new search engine. | 1176 // Add a new search engine. |
975 TemplateURL* new_turl = | 1177 TemplateURL* new_turl = |
976 CreateTestTemplateURL(ASCIIToUTF16("baidu"), "http://baidu.cn", "new"); | 1178 CreateTestTemplateURL(ASCIIToUTF16("baidu"), "http://baidu.cn", "new"); |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1082 syncer::SyncChange key2_change = processor()->change_for_guid("key2"); | 1284 syncer::SyncChange key2_change = processor()->change_for_guid("key2"); |
1083 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, key2_change.change_type()); | 1285 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, key2_change.change_type()); |
1084 EXPECT_EQ(google_keyword, UTF8ToUTF16(GetKeyword(key2_change.sync_data()))); | 1286 EXPECT_EQ(google_keyword, UTF8ToUTF16(GetKeyword(key2_change.sync_data()))); |
1085 } | 1287 } |
1086 | 1288 |
1087 TEST_F(TemplateURLServiceSyncTest, AutogeneratedKeywordConflicts) { | 1289 TEST_F(TemplateURLServiceSyncTest, AutogeneratedKeywordConflicts) { |
1088 // Sync brings in some autogenerated keywords, but the generated keywords we | 1290 // Sync brings in some autogenerated keywords, but the generated keywords we |
1089 // try to create conflict with ones in the model. | 1291 // try to create conflict with ones in the model. |
1090 string16 google_keyword(net::StripWWW(ASCIIToUTF16(GURL( | 1292 string16 google_keyword(net::StripWWW(ASCIIToUTF16(GURL( |
1091 UIThreadSearchTermsData(profile_a()).GoogleBaseURLValue()).host()))); | 1293 UIThreadSearchTermsData(profile_a()).GoogleBaseURLValue()).host()))); |
1092 const std::string local_google_url = | 1294 TemplateURL* google = CreateTestTemplateURL(google_keyword, |
1093 "{google:baseURL}1/search?q={searchTerms}"; | 1295 "{google:baseURL}1/search?q={searchTerms}"); |
1094 TemplateURL* google = CreateTestTemplateURL(google_keyword, local_google_url); | |
1095 model()->Add(google); | 1296 model()->Add(google); |
1096 TemplateURL* other = | 1297 TemplateURL* other = |
1097 CreateTestTemplateURL(ASCIIToUTF16("other.com"), "http://other.com/foo"); | 1298 CreateTestTemplateURL(ASCIIToUTF16("other.com"), "http://other.com/foo"); |
1098 model()->Add(other); | 1299 model()->Add(other); |
1099 syncer::SyncDataList initial_data; | 1300 syncer::SyncDataList initial_data; |
1100 scoped_ptr<TemplateURL> turl(CreateTestTemplateURL(ASCIIToUTF16("sync1"), | 1301 scoped_ptr<TemplateURL> turl(CreateTestTemplateURL(ASCIIToUTF16("sync1"), |
1101 "{google:baseURL}2/search?q={searchTerms}", "sync1", 50)); | 1302 "{google:baseURL}2/search?q={searchTerms}", "sync1", 50)); |
1102 initial_data.push_back( | 1303 initial_data.push_back( |
1103 CreateCustomSyncData(*turl, true, turl->url(), turl->sync_guid())); | 1304 CreateCustomSyncData(*turl, true, turl->url(), turl->sync_guid())); |
1104 const std::string synced_other_url = | |
1105 "http://other.com/search?q={searchTerms}"; | |
1106 turl.reset(CreateTestTemplateURL(ASCIIToUTF16("sync2"), | 1305 turl.reset(CreateTestTemplateURL(ASCIIToUTF16("sync2"), |
1107 synced_other_url, "sync2", 150)); | 1306 "http://other.com/search?q={searchTerms}", "sync2", 150)); |
1108 initial_data.push_back( | 1307 initial_data.push_back( |
1109 CreateCustomSyncData(*turl, true, turl->url(), turl->sync_guid())); | 1308 CreateCustomSyncData(*turl, true, turl->url(), turl->sync_guid())); |
1110 | |
1111 // Before we merge the data, grab the local sync_guids so we can ensure that | |
1112 // they've been replaced. | |
1113 const std::string local_google_guid = google->sync_guid(); | |
1114 const std::string local_other_guid = other->sync_guid(); | |
1115 | |
1116 model()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES, initial_data, | 1309 model()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES, initial_data, |
1117 PassProcessor(), CreateAndPassSyncErrorFactory()); | 1310 PassProcessor(), CreateAndPassSyncErrorFactory()); |
1118 | 1311 |
1119 // In this case, the conflicts should be handled just like any other keyword | 1312 // In this case, the conflicts should be handled just like any other keyword |
1120 // conflicts -- the later-modified TemplateURL is assumed to be authoritative. | 1313 // conflicts -- the later-modified TemplateURL is assumed to be authoritative. |
1121 // Since the initial TemplateURLs were local only, they should be merged with | 1314 EXPECT_EQ(google_keyword, google->keyword()); |
1122 // the sync TemplateURLs (GUIDs transferred over). | 1315 EXPECT_EQ(google_keyword + ASCIIToUTF16("_"), |
1123 EXPECT_FALSE(model()->GetTemplateURLForGUID(local_google_guid)); | 1316 model()->GetTemplateURLForGUID("sync1")->keyword()); |
1124 ASSERT_TRUE(model()->GetTemplateURLForGUID("sync1")); | 1317 EXPECT_EQ(ASCIIToUTF16("other.com_"), other->keyword()); |
1125 EXPECT_EQ(google_keyword, model()->GetTemplateURLForGUID("sync1")->keyword()); | |
1126 EXPECT_FALSE(model()->GetTemplateURLForGUID(local_other_guid)); | |
1127 ASSERT_TRUE(model()->GetTemplateURLForGUID("sync2")); | |
1128 EXPECT_EQ(ASCIIToUTF16("other.com"), | 1318 EXPECT_EQ(ASCIIToUTF16("other.com"), |
1129 model()->GetTemplateURLForGUID("sync2")->keyword()); | 1319 model()->GetTemplateURLForGUID("sync2")->keyword()); |
1130 | 1320 |
1131 // Both synced URLs should have associated UPDATEs, since both needed their | 1321 // Both synced URLs should have associated UPDATEs, since both needed their |
1132 // keywords to be generated. | 1322 // keywords to be generated (and sync1 needed conflict resolution as well). |
1133 EXPECT_EQ(processor()->change_list_size(), 2U); | 1323 EXPECT_GE(processor()->change_list_size(), 2U); |
1134 ASSERT_TRUE(processor()->contains_guid("sync1")); | 1324 ASSERT_TRUE(processor()->contains_guid("sync1")); |
1135 syncer::SyncChange sync1_change = processor()->change_for_guid("sync1"); | 1325 syncer::SyncChange sync1_change = processor()->change_for_guid("sync1"); |
1136 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, sync1_change.change_type()); | 1326 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, sync1_change.change_type()); |
1137 EXPECT_EQ(google_keyword, UTF8ToUTF16(GetKeyword(sync1_change.sync_data()))); | 1327 EXPECT_EQ(google_keyword + ASCIIToUTF16("_"), |
1138 EXPECT_EQ(local_google_url, GetURL(sync1_change.sync_data())); | 1328 UTF8ToUTF16(GetKeyword(sync1_change.sync_data()))); |
1139 ASSERT_TRUE(processor()->contains_guid("sync2")); | 1329 ASSERT_TRUE(processor()->contains_guid("sync2")); |
1140 syncer::SyncChange sync2_change = processor()->change_for_guid("sync2"); | 1330 syncer::SyncChange sync2_change = processor()->change_for_guid("sync2"); |
1141 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, sync2_change.change_type()); | 1331 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, sync2_change.change_type()); |
1142 EXPECT_EQ("other.com", GetKeyword(sync2_change.sync_data())); | 1332 EXPECT_EQ("other.com", GetKeyword(sync2_change.sync_data())); |
1143 EXPECT_EQ(synced_other_url, GetURL(sync2_change.sync_data())); | |
1144 } | 1333 } |
1145 | 1334 |
1146 TEST_F(TemplateURLServiceSyncTest, TwoAutogeneratedKeywordsUsingGoogleBaseURL) { | 1335 TEST_F(TemplateURLServiceSyncTest, TwoAutogeneratedKeywordsUsingGoogleBaseURL) { |
1147 // Sync brings in two autogenerated keywords and both use Google base URLs. | 1336 // Sync brings in two autogenerated keywords and both use Google base URLs. |
1148 // We make the first older so that it will get renamed once before the second | 1337 // We make the first older so that it will get renamed once before the second |
1149 // and then again once after (when we resolve conflicts for the second). | 1338 // and then again once after (when we resolve conflicts for the second). |
1150 syncer::SyncDataList initial_data; | 1339 syncer::SyncDataList initial_data; |
1151 scoped_ptr<TemplateURL> turl(CreateTestTemplateURL(ASCIIToUTF16("key1"), | 1340 scoped_ptr<TemplateURL> turl(CreateTestTemplateURL(ASCIIToUTF16("key1"), |
1152 "{google:baseURL}1/search?q={searchTerms}", "key1", 50)); | 1341 "{google:baseURL}1/search?q={searchTerms}", "key1", 50)); |
1153 initial_data.push_back( | 1342 initial_data.push_back( |
1154 CreateCustomSyncData(*turl, true, turl->url(), turl->sync_guid())); | 1343 CreateCustomSyncData(*turl, true, turl->url(), turl->sync_guid())); |
1155 turl.reset(CreateTestTemplateURL(ASCIIToUTF16("key2"), | 1344 turl.reset(CreateTestTemplateURL(ASCIIToUTF16("key2"), |
1156 "{google:baseURL}2/search?q={searchTerms}", "key2")); | 1345 "{google:baseURL}2/search?q={searchTerms}", "key2")); |
1157 initial_data.push_back( | 1346 initial_data.push_back( |
1158 CreateCustomSyncData(*turl, true, turl->url(), turl->sync_guid())); | 1347 CreateCustomSyncData(*turl, true, turl->url(), turl->sync_guid())); |
1159 model()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES, initial_data, | 1348 model()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES, initial_data, |
1160 PassProcessor(), CreateAndPassSyncErrorFactory()); | 1349 PassProcessor(), CreateAndPassSyncErrorFactory()); |
1161 | 1350 |
1162 // We should still have coalesced the updates to one each. | 1351 // We should still have coalesced the updates to one each. |
1163 string16 google_keyword(net::StripWWW(ASCIIToUTF16(GURL( | 1352 string16 google_keyword(net::StripWWW(ASCIIToUTF16(GURL( |
1164 UIThreadSearchTermsData(profile_a()).GoogleBaseURLValue()).host()))); | 1353 UIThreadSearchTermsData(profile_a()).GoogleBaseURLValue()).host()))); |
1165 TemplateURL* keyword1 = | 1354 TemplateURL* keyword1 = |
1166 model()->GetTemplateURLForKeyword(google_keyword + ASCIIToUTF16("_")); | 1355 model()->GetTemplateURLForKeyword(google_keyword + ASCIIToUTF16("_")); |
1167 ASSERT_FALSE(keyword1 == NULL); | 1356 ASSERT_FALSE(keyword1 == NULL); |
1168 EXPECT_EQ("key1", keyword1->sync_guid()); | 1357 EXPECT_EQ("key1", keyword1->sync_guid()); |
1169 TemplateURL* keyword2 = model()->GetTemplateURLForKeyword(google_keyword); | 1358 TemplateURL* keyword2 = model()->GetTemplateURLForKeyword(google_keyword); |
1170 ASSERT_FALSE(keyword2 == NULL); | 1359 ASSERT_FALSE(keyword2 == NULL); |
1171 EXPECT_EQ("key2", keyword2->sync_guid()); | 1360 EXPECT_EQ("key2", keyword2->sync_guid()); |
1172 | |
1173 EXPECT_GE(processor()->change_list_size(), 2U); | 1361 EXPECT_GE(processor()->change_list_size(), 2U); |
1174 ASSERT_TRUE(processor()->contains_guid("key1")); | 1362 ASSERT_TRUE(processor()->contains_guid("key1")); |
1175 syncer::SyncChange key1_change = processor()->change_for_guid("key1"); | 1363 syncer::SyncChange key1_change = processor()->change_for_guid("key1"); |
1176 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, key1_change.change_type()); | 1364 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, key1_change.change_type()); |
1177 EXPECT_EQ(keyword1->keyword(), | 1365 EXPECT_EQ(keyword1->keyword(), |
1178 UTF8ToUTF16(GetKeyword(key1_change.sync_data()))); | 1366 UTF8ToUTF16(GetKeyword(key1_change.sync_data()))); |
1179 ASSERT_TRUE(processor()->contains_guid("key2")); | 1367 ASSERT_TRUE(processor()->contains_guid("key2")); |
1180 syncer::SyncChange key2_change = processor()->change_for_guid("key2"); | 1368 syncer::SyncChange key2_change = processor()->change_for_guid("key2"); |
1181 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, key2_change.change_type()); | 1369 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, key2_change.change_type()); |
1182 EXPECT_EQ(keyword2->keyword(), | 1370 EXPECT_EQ(keyword2->keyword(), |
(...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1641 | 1829 |
1642 EXPECT_EQ(3U, model()->GetAllSyncData(syncer::SEARCH_ENGINES).size()); | 1830 EXPECT_EQ(3U, model()->GetAllSyncData(syncer::SEARCH_ENGINES).size()); |
1643 EXPECT_FALSE(model()->GetTemplateURLForGUID("whateverguid")); | 1831 EXPECT_FALSE(model()->GetTemplateURLForGUID("whateverguid")); |
1644 EXPECT_EQ(model()->GetDefaultSearchProvider(), | 1832 EXPECT_EQ(model()->GetDefaultSearchProvider(), |
1645 model()->GetTemplateURLForGUID("key1")); | 1833 model()->GetTemplateURLForGUID("key1")); |
1646 } | 1834 } |
1647 | 1835 |
1648 TEST_F(TemplateURLServiceSyncTest, LocalDefaultWinsConflict) { | 1836 TEST_F(TemplateURLServiceSyncTest, LocalDefaultWinsConflict) { |
1649 // We expect that the local default always wins keyword conflict resolution. | 1837 // We expect that the local default always wins keyword conflict resolution. |
1650 const string16 keyword(ASCIIToUTF16("key1")); | 1838 const string16 keyword(ASCIIToUTF16("key1")); |
1651 const std::string url("http://whatever.com/{searchTerms}"); | |
1652 TemplateURL* default_turl = CreateTestTemplateURL(keyword, | 1839 TemplateURL* default_turl = CreateTestTemplateURL(keyword, |
1653 url, | 1840 "http://whatever.com/{searchTerms}", "whateverguid", 10); |
1654 "whateverguid", | |
1655 10); | |
1656 model()->Add(default_turl); | 1841 model()->Add(default_turl); |
1657 model()->SetDefaultSearchProvider(default_turl); | 1842 model()->SetDefaultSearchProvider(default_turl); |
1658 | 1843 |
1659 syncer::SyncDataList initial_data = CreateInitialSyncData(); | 1844 syncer::SyncDataList initial_data = CreateInitialSyncData(); |
1660 // The key1 entry should be different from the default but conflict in the | 1845 // The key1 entry should be different from the default but conflict in the |
1661 // keyword. | 1846 // keyword. |
1662 scoped_ptr<TemplateURL> turl(CreateTestTemplateURL(keyword, | 1847 scoped_ptr<TemplateURL> turl(CreateTestTemplateURL(keyword, |
1663 "http://key1.com/{searchTerms}", "key1", 90)); | 1848 "http://key1.com/{searchTerms}", "key1", 90)); |
1664 initial_data[0] = TemplateURLService::CreateSyncDataFromTemplateURL(*turl); | 1849 initial_data[0] = TemplateURLService::CreateSyncDataFromTemplateURL(*turl); |
1665 | 1850 |
1666 model()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES, initial_data, | 1851 model()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES, initial_data, |
1667 PassProcessor(), CreateAndPassSyncErrorFactory()); | 1852 PassProcessor(), CreateAndPassSyncErrorFactory()); |
1668 | 1853 |
1669 // Since the local default was not yet synced, it should be merged with the | 1854 // The conflicting TemplateURL should be added, but it should have lost |
1670 // conflicting TemplateURL. However, its values should have been preserved | 1855 // conflict resolution against the default. |
1671 // since it would have won conflict resolution due to being the default. | 1856 EXPECT_EQ(4U, model()->GetAllSyncData(syncer::SEARCH_ENGINES).size()); |
1672 EXPECT_EQ(3U, model()->GetAllSyncData(syncer::SEARCH_ENGINES).size()); | 1857 const TemplateURL* winner = model()->GetTemplateURLForGUID("whateverguid"); |
1673 const TemplateURL* winner = model()->GetTemplateURLForGUID("key1"); | |
1674 ASSERT_TRUE(winner); | 1858 ASSERT_TRUE(winner); |
1675 EXPECT_EQ(model()->GetDefaultSearchProvider(), winner); | 1859 EXPECT_EQ(model()->GetDefaultSearchProvider(), winner); |
1676 EXPECT_EQ(keyword, winner->keyword()); | 1860 EXPECT_EQ(keyword, winner->keyword()); |
1677 EXPECT_EQ(url, winner->url()); | 1861 const TemplateURL* loser = model()->GetTemplateURLForGUID("key1"); |
1678 ASSERT_TRUE(processor()->contains_guid("key1")); | 1862 ASSERT_TRUE(loser); |
1679 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, | 1863 EXPECT_EQ(ASCIIToUTF16("key1.com"), loser->keyword()); |
1680 processor()->change_for_guid("key1").change_type()); | |
1681 EXPECT_EQ(url, GetURL(processor()->change_for_guid("key1").sync_data())); | |
1682 | |
1683 // There is no loser, as the two were merged together. The local sync_guid | |
1684 // should no longer be found in the model. | |
1685 const TemplateURL* loser = model()->GetTemplateURLForGUID("whateverguid"); | |
1686 ASSERT_FALSE(loser); | |
1687 } | 1864 } |
1688 | 1865 |
1689 TEST_F(TemplateURLServiceSyncTest, DeleteBogusData) { | 1866 TEST_F(TemplateURLServiceSyncTest, DeleteBogusData) { |
1690 // Create a couple of bogus entries to sync. | 1867 // Create a couple of bogus entries to sync. |
1691 syncer::SyncDataList initial_data; | 1868 syncer::SyncDataList initial_data; |
1692 scoped_ptr<TemplateURL> turl( | 1869 scoped_ptr<TemplateURL> turl( |
1693 CreateTestTemplateURL(ASCIIToUTF16("key1"), "http://key1.com", "key1")); | 1870 CreateTestTemplateURL(ASCIIToUTF16("key1"), "http://key1.com", "key1")); |
1694 initial_data.push_back( | 1871 initial_data.push_back( |
1695 CreateCustomSyncData(*turl, false, std::string(), turl->sync_guid())); | 1872 CreateCustomSyncData(*turl, false, std::string(), turl->sync_guid())); |
1696 turl.reset(CreateTestTemplateURL(ASCIIToUTF16("key2"), "http://key2.com")); | 1873 turl.reset(CreateTestTemplateURL(ASCIIToUTF16("key2"), "http://key2.com")); |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1828 // A local change to the Google base URL should update the keyword and | 2005 // A local change to the Google base URL should update the keyword and |
1829 // generate a sync change. | 2006 // generate a sync change. |
1830 test_util_a_.SetGoogleBaseURL(GURL("http://google.co.in/")); | 2007 test_util_a_.SetGoogleBaseURL(GURL("http://google.co.in/")); |
1831 EXPECT_EQ(ASCIIToUTF16("google.co.in"), synced_turl->keyword()); | 2008 EXPECT_EQ(ASCIIToUTF16("google.co.in"), synced_turl->keyword()); |
1832 EXPECT_EQ(1U, processor()->change_list_size()); | 2009 EXPECT_EQ(1U, processor()->change_list_size()); |
1833 ASSERT_TRUE(processor()->contains_guid("guid")); | 2010 ASSERT_TRUE(processor()->contains_guid("guid")); |
1834 syncer::SyncChange change(processor()->change_for_guid("guid")); | 2011 syncer::SyncChange change(processor()->change_for_guid("guid")); |
1835 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, change.change_type()); | 2012 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, change.change_type()); |
1836 EXPECT_EQ("google.co.in", GetKeyword(change.sync_data())); | 2013 EXPECT_EQ("google.co.in", GetKeyword(change.sync_data())); |
1837 } | 2014 } |
1838 | |
1839 TEST_F(TemplateURLServiceSyncTest, MergeInSyncTemplateURL) { | |
1840 // An enumeration used to indicate which TemplateURL test value is expected | |
1841 // for a particular test result. | |
1842 enum ExpectedTemplateURL { | |
1843 LOCAL, | |
1844 SYNC, | |
1845 BOTH, | |
1846 NEITHER, | |
1847 }; | |
1848 | |
1849 // Sets up and executes a MergeInSyncTemplateURL test given a number of | |
1850 // expected start and end states: | |
1851 // * |conflict_winner| denotes which TemplateURL should win the | |
1852 // conflict. | |
1853 // * |synced_at_start| denotes which of the TemplateURLs should known | |
1854 // to Sync. | |
1855 // * |update_sent| denotes which TemplateURL should have an | |
1856 // ACTION_UPDATE sent to the server after the merge. | |
1857 // * |turl_uniquified| denotes which TemplateURL should have its | |
1858 // keyword updated after the merge. | |
1859 // * |present_in_model| denotes which TemplateURL should be found in | |
1860 // the model after the merge. | |
1861 // * If |keywords_conflict| is true, the TemplateURLs are set up with | |
1862 // the same keyword. | |
1863 const struct { | |
1864 ExpectedTemplateURL conflict_winner; | |
1865 ExpectedTemplateURL synced_at_start; | |
1866 ExpectedTemplateURL update_sent; | |
1867 ExpectedTemplateURL turl_uniquified; | |
1868 ExpectedTemplateURL present_in_model; | |
1869 bool keywords_conflict; | |
1870 } test_cases[] = { | |
1871 // Both are synced and the new sync entry is better: Local is uniquified and | |
1872 // UPDATE sent. Sync is added. | |
1873 {SYNC, BOTH, LOCAL, LOCAL, BOTH, true}, | |
1874 // Both are synced and the local entry is better: Sync is uniquified and | |
1875 // added to the model. An UPDATE is sent for it. | |
1876 {LOCAL, BOTH, SYNC, SYNC, BOTH, true}, | |
1877 // Local was not known to Sync and the new sync entry is better: Sync is | |
1878 // added. Local is removed. No updates. | |
1879 {SYNC, SYNC, NEITHER, NEITHER, SYNC, true}, | |
1880 // Local was not known to sync and the local entry is better: Local is | |
1881 // updated with sync GUID, Sync is not added. UPDATE sent for Sync. | |
1882 {LOCAL, SYNC, SYNC, NEITHER, SYNC, true}, | |
1883 // No conflicting keyword. Both should be added with their original | |
1884 // keywords, with no updates sent. Note that MergeDataAndStartSyncing is | |
1885 // responsible for creating the ACTION_ADD for the local TemplateURL. | |
1886 {NEITHER, SYNC, NEITHER, NEITHER, BOTH, false}, | |
1887 }; | |
1888 | |
1889 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); ++i) { | |
1890 // Assert all the valid states of ExpectedTemplateURLs. | |
1891 ASSERT_FALSE(test_cases[i].conflict_winner == BOTH); | |
1892 ASSERT_FALSE(test_cases[i].synced_at_start == NEITHER); | |
1893 ASSERT_FALSE(test_cases[i].synced_at_start == LOCAL); | |
1894 ASSERT_FALSE(test_cases[i].update_sent == BOTH); | |
1895 ASSERT_FALSE(test_cases[i].turl_uniquified == BOTH); | |
1896 ASSERT_FALSE(test_cases[i].present_in_model == NEITHER); | |
1897 | |
1898 const string16 local_keyword = ASCIIToUTF16("localkeyword"); | |
1899 const string16 sync_keyword = test_cases[i].keywords_conflict ? | |
1900 local_keyword : ASCIIToUTF16("synckeyword"); | |
1901 const std::string local_url = "www.localurl.com"; | |
1902 const std::string sync_url = "www.syncurl.com"; | |
1903 const time_t local_last_modified = 100; | |
1904 const time_t sync_last_modified = | |
1905 test_cases[i].conflict_winner == SYNC ? 110 : 90; | |
1906 const std::string local_guid = "local_guid"; | |
1907 const std::string sync_guid = "sync_guid"; | |
1908 | |
1909 // Initialize expectations. | |
1910 string16 expected_local_keyword = local_keyword; | |
1911 string16 expected_sync_keyword = sync_keyword; | |
1912 | |
1913 // Create the data and run the actual test. | |
1914 TemplateURL* local_turl = CreateTestTemplateURL( | |
1915 local_keyword, local_url, local_guid, local_last_modified); | |
1916 model()->Add(local_turl); | |
1917 TemplateURL* sync_turl = CreateTestTemplateURL( | |
1918 sync_keyword, sync_url, sync_guid, sync_last_modified); | |
1919 | |
1920 SyncDataMap sync_data; | |
1921 if (test_cases[i].synced_at_start == SYNC || | |
1922 test_cases[i].synced_at_start == BOTH) { | |
1923 sync_data[sync_turl->sync_guid()] = | |
1924 TemplateURLService::CreateSyncDataFromTemplateURL(*sync_turl); | |
1925 } | |
1926 if (test_cases[i].synced_at_start == BOTH) { | |
1927 sync_data[local_turl->sync_guid()] = | |
1928 TemplateURLService::CreateSyncDataFromTemplateURL(*local_turl); | |
1929 } | |
1930 SyncDataMap initial_data; | |
1931 initial_data[local_turl->sync_guid()] = | |
1932 TemplateURLService::CreateSyncDataFromTemplateURL(*local_turl); | |
1933 | |
1934 syncer::SyncChangeList change_list; | |
1935 model()->MergeInSyncTemplateURL(sync_turl, sync_data, &change_list, | |
1936 &initial_data); | |
1937 | |
1938 // Check for expected updates, if any. | |
1939 std::string expected_update_guid; | |
1940 if (test_cases[i].update_sent == LOCAL) | |
1941 expected_update_guid = local_guid; | |
1942 else if (test_cases[i].update_sent == SYNC) | |
1943 expected_update_guid = sync_guid; | |
1944 if (!expected_update_guid.empty()) { | |
1945 ASSERT_EQ(1U, change_list.size()); | |
1946 EXPECT_EQ(expected_update_guid, GetGUID(change_list[0].sync_data())); | |
1947 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, | |
1948 change_list[0].change_type()); | |
1949 } else { | |
1950 EXPECT_EQ(0U, change_list.size()); | |
1951 } | |
1952 | |
1953 // Adjust the expectations based on the expectation enums. | |
1954 if (test_cases[i].turl_uniquified == LOCAL) { | |
1955 DCHECK(test_cases[i].keywords_conflict); | |
1956 expected_local_keyword = ASCIIToUTF16("localkeyword_"); | |
1957 } | |
1958 if (test_cases[i].turl_uniquified == SYNC) { | |
1959 DCHECK(test_cases[i].keywords_conflict); | |
1960 expected_sync_keyword = ASCIIToUTF16("localkeyword_"); | |
1961 } | |
1962 | |
1963 // Check for TemplateURLs expected in the model. Note that this is checked | |
1964 // by GUID rather than the initial pointer, as a merge could occur (the | |
1965 // Sync TemplateURL overtakes the local one). Also remove the present | |
1966 // TemplateURL when done so the next test case starts with a clean slate. | |
1967 if (test_cases[i].present_in_model == LOCAL || | |
1968 test_cases[i].present_in_model == BOTH) { | |
1969 ASSERT_TRUE(model()->GetTemplateURLForGUID(local_guid)); | |
1970 EXPECT_EQ(expected_local_keyword, local_turl->keyword()); | |
1971 EXPECT_EQ(local_url, local_turl->url()); | |
1972 EXPECT_EQ(local_last_modified, local_turl->last_modified().ToTimeT()); | |
1973 model()->Remove(model()->GetTemplateURLForGUID(local_guid)); | |
1974 } | |
1975 if (test_cases[i].present_in_model == SYNC || | |
1976 test_cases[i].present_in_model == BOTH) { | |
1977 ASSERT_TRUE(model()->GetTemplateURLForGUID(sync_guid)); | |
1978 EXPECT_EQ(expected_sync_keyword, sync_turl->keyword()); | |
1979 EXPECT_EQ(sync_url, sync_turl->url()); | |
1980 EXPECT_EQ(sync_last_modified, sync_turl->last_modified().ToTimeT()); | |
1981 model()->Remove(model()->GetTemplateURLForGUID(sync_guid)); | |
1982 } | |
1983 } // for | |
1984 } | |
OLD | NEW |