Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(143)

Side by Side Diff: chrome/browser/search_engines/template_url_service_sync_unittest.cc

Issue 10806065: Rewrite TemplateURLService's SyncableService implmentation to avoid sending ACTION_DELETEs to Sync. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Cleanup new code Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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, SyncKeywordConflictNeitherAutoreplace) {
475 // This tests cases where neither the sync nor the local TemplateURL are
476 // marked safe_for_autoreplace.
477
478 // Create a keyword that conflicts, and make it older. Sync keyword is
479 // uniquified, and a syncer::SyncChange is added.
480 string16 original_turl_keyword = ASCIIToUTF16("key1");
481 TemplateURL* original_turl = CreateTestTemplateURL(original_turl_keyword,
482 "http://key1.com", std::string(), 9000);
483 model()->Add(original_turl);
484 scoped_ptr<TemplateURL> sync_turl(CreateTestTemplateURL(original_turl_keyword,
485 "http://new.com", "remote", 8999));
486 syncer::SyncChangeList changes;
487 EXPECT_TRUE(model()->ResolveSyncKeywordConflict(sync_turl.get(),
488 original_turl, &changes));
489 EXPECT_NE(original_turl_keyword, sync_turl->keyword());
490 EXPECT_EQ(original_turl_keyword, original_turl->keyword());
491 ASSERT_EQ(1U, changes.size());
492 EXPECT_EQ("remote", GetGUID(changes[0].sync_data()));
493 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, changes[0].change_type());
494 changes.clear();
495 model()->Remove(original_turl);
496
497 // Sync is newer. Original TemplateURL keyword is uniquified. A SyncChange
498 // is added (which in a normal run would be deleted by PruneSyncChanges() when
499 // the local GUID doesn't appear in the sync GUID list). Also ensure that
500 // this does not change the safe_for_autoreplace flag or the TemplateURLID in
501 // the original.
502 original_turl = CreateTestTemplateURL(original_turl_keyword,
503 "http://key1.com", "local", 9000);
504 model()->Add(original_turl);
505 TemplateURLID original_id = original_turl->id();
506 sync_turl.reset(CreateTestTemplateURL(original_turl_keyword, "http://new.com",
507 std::string(), 9001));
508 EXPECT_TRUE(model()->ResolveSyncKeywordConflict(sync_turl.get(),
509 original_turl, &changes));
510 EXPECT_EQ(original_turl_keyword, sync_turl->keyword());
511 EXPECT_NE(original_turl_keyword, original_turl->keyword());
512 EXPECT_FALSE(original_turl->safe_for_autoreplace());
513 EXPECT_EQ(original_id, original_turl->id());
514 EXPECT_EQ(NULL, model()->GetTemplateURLForKeyword(original_turl_keyword));
515 ASSERT_EQ(1U, changes.size());
516 EXPECT_EQ("local", GetGUID(changes[0].sync_data()));
517 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, changes[0].change_type());
518 changes.clear();
519 model()->Remove(original_turl);
520
521 // Equal times. Same result as above. Sync left alone, original uniquified so
522 // sync_turl can fit.
523 original_turl = CreateTestTemplateURL(original_turl_keyword,
524 "http://key1.com", "local2", 9000);
525 model()->Add(original_turl);
526 sync_turl.reset(CreateTestTemplateURL(original_turl_keyword, "http://new.com",
527 std::string(), 9000));
528 EXPECT_TRUE(model()->ResolveSyncKeywordConflict(sync_turl.get(),
529 original_turl, &changes));
530 EXPECT_EQ(original_turl_keyword, sync_turl->keyword());
531 EXPECT_NE(original_turl_keyword, original_turl->keyword());
532 EXPECT_EQ(NULL, model()->GetTemplateURLForKeyword(original_turl_keyword));
533 ASSERT_EQ(1U, changes.size());
534 EXPECT_EQ("local2", GetGUID(changes[0].sync_data()));
535 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, changes[0].change_type());
536 changes.clear();
537 model()->Remove(original_turl);
538
539 // Sync is newer, but original TemplateURL is created by policy, so it wins.
540 // Sync keyword is uniquified, and a syncer::SyncChange is added.
541 original_turl = CreateTestTemplateURL(original_turl_keyword,
542 "http://key1.com", std::string(), 9000, false, true);
543 model()->Add(original_turl);
544 sync_turl.reset(CreateTestTemplateURL(original_turl_keyword, "http://new.com",
545 "remote2", 9999));
546 EXPECT_TRUE(model()->ResolveSyncKeywordConflict(sync_turl.get(),
547 original_turl, &changes));
548 EXPECT_NE(original_turl_keyword, sync_turl->keyword());
549 EXPECT_EQ(original_turl_keyword, original_turl->keyword());
550 EXPECT_EQ(NULL, model()->GetTemplateURLForKeyword(sync_turl->keyword()));
551 ASSERT_EQ(1U, changes.size());
552 EXPECT_EQ("remote2", GetGUID(changes[0].sync_data()));
553 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, changes[0].change_type());
554 changes.clear();
555 model()->Remove(original_turl);
556 }
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
764 TEST_F(TemplateURLServiceSyncTest, StartSyncEmpty) { 474 TEST_F(TemplateURLServiceSyncTest, StartSyncEmpty) {
765 model()->MergeDataAndStartSyncing( 475 model()->MergeDataAndStartSyncing(
766 syncer::SEARCH_ENGINES, syncer::SyncDataList(), 476 syncer::SEARCH_ENGINES, syncer::SyncDataList(),
767 PassProcessor(), CreateAndPassSyncErrorFactory()); 477 PassProcessor(), CreateAndPassSyncErrorFactory());
768 478
769 EXPECT_EQ(0U, model()->GetAllSyncData(syncer::SEARCH_ENGINES).size()); 479 EXPECT_EQ(0U, model()->GetAllSyncData(syncer::SEARCH_ENGINES).size());
770 EXPECT_EQ(0U, processor()->change_list_size()); 480 EXPECT_EQ(0U, processor()->change_list_size());
771 } 481 }
772 482
773 TEST_F(TemplateURLServiceSyncTest, MergeIntoEmpty) { 483 TEST_F(TemplateURLServiceSyncTest, MergeIntoEmpty) {
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
891 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("key2"), 601 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("key2"),
892 "http://expected.com", "bbb", 100)); // keyword conflict 602 "http://expected.com", "bbb", 100)); // keyword conflict
893 603
894 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("unique"), 604 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("unique"),
895 "http://unique.com", "ccc")); // add 605 "http://unique.com", "ccc")); // add
896 606
897 model()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES, 607 model()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES,
898 CreateInitialSyncData(), PassProcessor(), 608 CreateInitialSyncData(), PassProcessor(),
899 CreateAndPassSyncErrorFactory()); 609 CreateAndPassSyncErrorFactory());
900 610
901 // The dupe results in a merge. The other two should be added to the model. 611 // The dupe and conflict results in merges, as local values are always merged
902 EXPECT_EQ(5U, model()->GetAllSyncData(syncer::SEARCH_ENGINES).size()); 612 // with sync values if there is a keyword conflict. The unique keyword should
613 // be added.
614 EXPECT_EQ(4U, model()->GetAllSyncData(syncer::SEARCH_ENGINES).size());
903 615
904 // The key1 duplicate results in the local copy winning. Ensure that Sync's 616 // The key1 duplicate results in the local copy winning. Ensure that Sync's
905 // copy was not added, and the local copy is pushed upstream to Sync as an 617 // copy was not added, and the local copy is pushed upstream to Sync as an
906 // update. The local copy should have received the sync data's GUID. 618 // update. The local copy should have received the sync data's GUID.
907 EXPECT_TRUE(model()->GetTemplateURLForGUID("key1")); 619 EXPECT_TRUE(model()->GetTemplateURLForGUID("key1"));
908 // Check changes for the UPDATE. 620 // Check changes for the UPDATE.
909 ASSERT_TRUE(processor()->contains_guid("key1")); 621 ASSERT_TRUE(processor()->contains_guid("key1"));
910 syncer::SyncChange key1_change = processor()->change_for_guid("key1"); 622 syncer::SyncChange key1_change = processor()->change_for_guid("key1");
911 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, key1_change.change_type()); 623 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, key1_change.change_type());
624 // The local sync_guid should no longer be found.
912 EXPECT_FALSE(model()->GetTemplateURLForGUID("aaa")); 625 EXPECT_FALSE(model()->GetTemplateURLForGUID("aaa"));
913 626
914 // The key2 keyword conflict results in the local copy winning, so ensure it 627 // The key2 keyword conflict results in a merge, with the values of the local
915 // retains the original keyword, and that an update to the sync copy is pushed 628 // copy winning, so ensure it retains the original URL, and that an update to
916 // upstream to Sync. Both TemplateURLs should be found locally, however. 629 // the sync guid is pushed upstream to Sync.
917 const TemplateURL* key2 = model()->GetTemplateURLForGUID("bbb"); 630 const TemplateURL* key2 = model()->GetTemplateURLForGUID("key2");
918 EXPECT_TRUE(key2); 631 ASSERT_TRUE(key2);
919 EXPECT_EQ(ASCIIToUTF16("key2"), key2->keyword()); 632 EXPECT_EQ(ASCIIToUTF16("key2"), key2->keyword());
920 EXPECT_TRUE(model()->GetTemplateURLForGUID("key2"));
921 // Check changes for the UPDATE. 633 // Check changes for the UPDATE.
922 ASSERT_TRUE(processor()->contains_guid("key2")); 634 ASSERT_TRUE(processor()->contains_guid("key2"));
923 syncer::SyncChange key2_change = processor()->change_for_guid("key2"); 635 syncer::SyncChange key2_change = processor()->change_for_guid("key2");
924 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, key2_change.change_type()); 636 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, key2_change.change_type());
925 EXPECT_EQ("key2.com", GetKeyword(key2_change.sync_data())); 637 EXPECT_EQ("key2", GetKeyword(key2_change.sync_data()));
638 EXPECT_EQ("http://expected.com", GetURL(key2_change.sync_data()));
639 // The local sync_guid should no longer be found.
640 EXPECT_FALSE(model()->GetTemplateURLForGUID("bbb"));
926 641
927 // The last TemplateURL should have had no conflicts and was just added. It 642 // The last TemplateURL should have had no conflicts and was just added. It
928 // should not have replaced the third local TemplateURL. 643 // should not have replaced the third local TemplateURL.
929 EXPECT_TRUE(model()->GetTemplateURLForGUID("ccc")); 644 EXPECT_TRUE(model()->GetTemplateURLForGUID("ccc"));
930 EXPECT_TRUE(model()->GetTemplateURLForGUID("key3")); 645 EXPECT_TRUE(model()->GetTemplateURLForGUID("key3"));
931 646
932 // Two UPDATEs and two ADDs. 647 // Two UPDATEs and one ADD.
933 EXPECT_EQ(4U, processor()->change_list_size()); 648 EXPECT_EQ(3U, processor()->change_list_size());
934 // Two ADDs should be pushed up to Sync. 649 // One 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());
938 ASSERT_TRUE(processor()->contains_guid("ccc")); 650 ASSERT_TRUE(processor()->contains_guid("ccc"));
939 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, 651 EXPECT_EQ(syncer::SyncChange::ACTION_ADD,
940 processor()->change_for_guid("ccc").change_type()); 652 processor()->change_for_guid("ccc").change_type());
941 } 653 }
942 654
943 TEST_F(TemplateURLServiceSyncTest, MergeAddFromNewerSyncData) { 655 TEST_F(TemplateURLServiceSyncTest, MergeAddFromNewerSyncData) {
944 // GUIDs all differ, so this is data to be added from Sync, but the timestamps 656 // GUIDs all differ, so Sync may overtake some entries, but the timestamps
945 // from Sync are newer. Set up the local data so that one is a dupe, one has a 657 // from Sync are newer. Set up the local data so that one is a dupe, one has a
946 // conflicting keyword, and the last has no conflicts (a clean ADD). 658 // conflicting keyword, and the last has no conflicts (a clean ADD).
947 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("key1"), "http://key1.com", 659 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("key1"), "http://key1.com",
948 "aaa", 10)); // dupe 660 "aaa", 10)); // dupe
949 661
950 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("key2"), 662 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("key2"),
951 "http://expected.com", "bbb", 10)); // keyword conflict 663 "http://expected.com", "bbb", 10)); // keyword conflict
952 664
953 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("unique"), 665 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("unique"),
954 "http://unique.com", "ccc", 10)); // add 666 "http://unique.com", "ccc", 10)); // add
955 667
956 model()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES, 668 model()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES,
957 CreateInitialSyncData(), PassProcessor(), 669 CreateInitialSyncData(), PassProcessor(),
958 CreateAndPassSyncErrorFactory()); 670 CreateAndPassSyncErrorFactory());
959 671
960 // The dupe results in a merge. The other two should be added to the model. 672 // The dupe and keyword conflict results in merges. The unique keyword be
961 EXPECT_EQ(5U, model()->GetAllSyncData(syncer::SEARCH_ENGINES).size()); 673 // added to the model.
674 EXPECT_EQ(4U, model()->GetAllSyncData(syncer::SEARCH_ENGINES).size());
962 675
963 // The key1 duplicate results in Sync's copy winning. Ensure that Sync's 676 // The key1 duplicate results in Sync's copy winning. Ensure that Sync's
964 // copy replaced the local copy. 677 // copy replaced the local copy.
965 EXPECT_TRUE(model()->GetTemplateURLForGUID("key1")); 678 EXPECT_TRUE(model()->GetTemplateURLForGUID("key1"));
966 EXPECT_FALSE(model()->GetTemplateURLForGUID("aaa")); 679 EXPECT_FALSE(model()->GetTemplateURLForGUID("aaa"));
967 680
968 // The key2 keyword conflict results in Sync's copy winning, so ensure it 681 // The key2 keyword conflict results in Sync's copy winning, so ensure it
969 // retains the original keyword. The local copy should get a uniquified 682 // retains the original keyword and is added. The local copy should be
970 // keyword. Both TemplateURLs should be found locally. 683 // removed.
971 const TemplateURL* key2_sync = model()->GetTemplateURLForGUID("key2"); 684 const TemplateURL* key2_sync = model()->GetTemplateURLForGUID("key2");
972 ASSERT_TRUE(key2_sync); 685 ASSERT_TRUE(key2_sync);
973 EXPECT_EQ(ASCIIToUTF16("key2"), key2_sync->keyword()); 686 EXPECT_EQ(ASCIIToUTF16("key2"), key2_sync->keyword());
974 const TemplateURL* key2_local = model()->GetTemplateURLForGUID("bbb"); 687 EXPECT_FALSE(model()->GetTemplateURLForGUID("bbb"));
975 ASSERT_TRUE(key2_local);
976 EXPECT_EQ(ASCIIToUTF16("expected.com"), key2_local->keyword());
977 688
978 // The last TemplateURL should have had no conflicts and was just added. It 689 // The last TemplateURL should have had no conflicts and was just added. It
979 // should not have replaced the third local TemplateURL. 690 // should not have replaced the third local TemplateURL.
980 EXPECT_TRUE(model()->GetTemplateURLForGUID("ccc")); 691 EXPECT_TRUE(model()->GetTemplateURLForGUID("ccc"));
981 EXPECT_TRUE(model()->GetTemplateURLForGUID("key3")); 692 EXPECT_TRUE(model()->GetTemplateURLForGUID("key3"));
982 693
983 // Two ADDs. 694 // One ADD.
984 EXPECT_EQ(2U, processor()->change_list_size()); 695 EXPECT_EQ(1U, processor()->change_list_size());
985 // Two ADDs should be pushed up to Sync. 696 // One 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());
989 ASSERT_TRUE(processor()->contains_guid("ccc")); 697 ASSERT_TRUE(processor()->contains_guid("ccc"));
990 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, 698 EXPECT_EQ(syncer::SyncChange::ACTION_ADD,
991 processor()->change_for_guid("ccc").change_type()); 699 processor()->change_for_guid("ccc").change_type());
992 } 700 }
993 701
994 TEST_F(TemplateURLServiceSyncTest, ProcessChangesEmptyModel) { 702 TEST_F(TemplateURLServiceSyncTest, ProcessChangesEmptyModel) {
995 // We initially have no data. 703 // We initially have no data.
996 model()->MergeDataAndStartSyncing( 704 model()->MergeDataAndStartSyncing(
997 syncer::SEARCH_ENGINES, syncer::SyncDataList(), 705 syncer::SEARCH_ENGINES, syncer::SyncDataList(),
998 PassProcessor(), CreateAndPassSyncErrorFactory()); 706 PassProcessor(), CreateAndPassSyncErrorFactory());
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
1128 model()->GetTemplateURLForKeyword(ASCIIToUTF16("key3"))); 836 model()->GetTemplateURLForKeyword(ASCIIToUTF16("key3")));
1129 837
1130 ASSERT_TRUE(processor()->contains_guid("aaa")); 838 ASSERT_TRUE(processor()->contains_guid("aaa"));
1131 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, 839 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE,
1132 processor()->change_for_guid("aaa").change_type()); 840 processor()->change_for_guid("aaa").change_type());
1133 ASSERT_TRUE(processor()->contains_guid("key1")); 841 ASSERT_TRUE(processor()->contains_guid("key1"));
1134 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, 842 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE,
1135 processor()->change_for_guid("key1").change_type()); 843 processor()->change_for_guid("key1").change_type());
1136 } 844 }
1137 845
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
1169 TEST_F(TemplateURLServiceSyncTest, ProcessTemplateURLChange) { 846 TEST_F(TemplateURLServiceSyncTest, ProcessTemplateURLChange) {
1170 // Ensure that ProcessTemplateURLChange is called and pushes the correct 847 // Ensure that ProcessTemplateURLChange is called and pushes the correct
1171 // changes to Sync whenever local changes are made to TemplateURLs. 848 // changes to Sync whenever local changes are made to TemplateURLs.
1172 model()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES, 849 model()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES,
1173 CreateInitialSyncData(), PassProcessor(), 850 CreateInitialSyncData(), PassProcessor(),
1174 CreateAndPassSyncErrorFactory()); 851 CreateAndPassSyncErrorFactory());
1175 852
1176 // Add a new search engine. 853 // Add a new search engine.
1177 TemplateURL* new_turl = 854 TemplateURL* new_turl =
1178 CreateTestTemplateURL(ASCIIToUTF16("baidu"), "http://baidu.cn", "new"); 855 CreateTestTemplateURL(ASCIIToUTF16("baidu"), "http://baidu.cn", "new");
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
1284 syncer::SyncChange key2_change = processor()->change_for_guid("key2"); 961 syncer::SyncChange key2_change = processor()->change_for_guid("key2");
1285 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, key2_change.change_type()); 962 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, key2_change.change_type());
1286 EXPECT_EQ(google_keyword, UTF8ToUTF16(GetKeyword(key2_change.sync_data()))); 963 EXPECT_EQ(google_keyword, UTF8ToUTF16(GetKeyword(key2_change.sync_data())));
1287 } 964 }
1288 965
1289 TEST_F(TemplateURLServiceSyncTest, AutogeneratedKeywordConflicts) { 966 TEST_F(TemplateURLServiceSyncTest, AutogeneratedKeywordConflicts) {
1290 // Sync brings in some autogenerated keywords, but the generated keywords we 967 // Sync brings in some autogenerated keywords, but the generated keywords we
1291 // try to create conflict with ones in the model. 968 // try to create conflict with ones in the model.
1292 string16 google_keyword(net::StripWWW(ASCIIToUTF16(GURL( 969 string16 google_keyword(net::StripWWW(ASCIIToUTF16(GURL(
1293 UIThreadSearchTermsData(profile_a()).GoogleBaseURLValue()).host()))); 970 UIThreadSearchTermsData(profile_a()).GoogleBaseURLValue()).host())));
1294 TemplateURL* google = CreateTestTemplateURL(google_keyword, 971 const std::string local_google_url =
1295 "{google:baseURL}1/search?q={searchTerms}"); 972 "{google:baseURL}1/search?q={searchTerms}";
973 TemplateURL* google = CreateTestTemplateURL(google_keyword, local_google_url);
1296 model()->Add(google); 974 model()->Add(google);
1297 TemplateURL* other = 975 TemplateURL* other =
1298 CreateTestTemplateURL(ASCIIToUTF16("other.com"), "http://other.com/foo"); 976 CreateTestTemplateURL(ASCIIToUTF16("other.com"), "http://other.com/foo");
1299 model()->Add(other); 977 model()->Add(other);
1300 syncer::SyncDataList initial_data; 978 syncer::SyncDataList initial_data;
1301 scoped_ptr<TemplateURL> turl(CreateTestTemplateURL(ASCIIToUTF16("sync1"), 979 scoped_ptr<TemplateURL> turl(CreateTestTemplateURL(ASCIIToUTF16("sync1"),
1302 "{google:baseURL}2/search?q={searchTerms}", "sync1", 50)); 980 "{google:baseURL}2/search?q={searchTerms}", "sync1", 50));
1303 initial_data.push_back( 981 initial_data.push_back(
1304 CreateCustomSyncData(*turl, true, turl->url(), turl->sync_guid())); 982 CreateCustomSyncData(*turl, true, turl->url(), turl->sync_guid()));
983 const std::string synced_other_url = "http://other.com/search?q={searchTerms}" ;
1305 turl.reset(CreateTestTemplateURL(ASCIIToUTF16("sync2"), 984 turl.reset(CreateTestTemplateURL(ASCIIToUTF16("sync2"),
1306 "http://other.com/search?q={searchTerms}", "sync2", 150)); 985 synced_other_url, "sync2", 150));
1307 initial_data.push_back( 986 initial_data.push_back(
1308 CreateCustomSyncData(*turl, true, turl->url(), turl->sync_guid())); 987 CreateCustomSyncData(*turl, true, turl->url(), turl->sync_guid()));
988
989 // Before we merge the data, grab the local sync_guids so we can ensure that
990 // they've been replaced.
991 const std::string local_google_guid = google->sync_guid();
992 const std::string local_other_guid = other->sync_guid();
993
1309 model()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES, initial_data, 994 model()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES, initial_data,
1310 PassProcessor(), CreateAndPassSyncErrorFactory()); 995 PassProcessor(), CreateAndPassSyncErrorFactory());
1311 996
1312 // In this case, the conflicts should be handled just like any other keyword 997 // In this case, the conflicts should be handled just like any other keyword
1313 // conflicts -- the later-modified TemplateURL is assumed to be authoritative. 998 // conflicts -- the later-modified TemplateURL is assumed to be authoritative.
1314 EXPECT_EQ(google_keyword, google->keyword()); 999 // Since the initial TemplateURLs were local only, they should be merged with
1315 EXPECT_EQ(google_keyword + ASCIIToUTF16("_"), 1000 // the sync TemplateURLs (GUIDs transferred over).
1316 model()->GetTemplateURLForGUID("sync1")->keyword()); 1001 EXPECT_FALSE(model()->GetTemplateURLForGUID(local_google_guid));
1317 EXPECT_EQ(ASCIIToUTF16("other.com_"), other->keyword()); 1002 ASSERT_TRUE(model()->GetTemplateURLForGUID("sync1"));
1003 EXPECT_EQ(google_keyword, model()->GetTemplateURLForGUID("sync1")->keyword());
1004 EXPECT_FALSE(model()->GetTemplateURLForGUID(local_other_guid));
1005 ASSERT_TRUE(model()->GetTemplateURLForGUID("sync2"));
1318 EXPECT_EQ(ASCIIToUTF16("other.com"), 1006 EXPECT_EQ(ASCIIToUTF16("other.com"),
1319 model()->GetTemplateURLForGUID("sync2")->keyword()); 1007 model()->GetTemplateURLForGUID("sync2")->keyword());
1320 1008
1321 // Both synced URLs should have associated UPDATEs, since both needed their 1009 // Both synced URLs should have associated UPDATEs, since both needed their
1322 // keywords to be generated (and sync1 needed conflict resolution as well). 1010 // keywords to be generated.
1323 EXPECT_GE(processor()->change_list_size(), 2U); 1011 EXPECT_EQ(processor()->change_list_size(), 2U);
1324 ASSERT_TRUE(processor()->contains_guid("sync1")); 1012 ASSERT_TRUE(processor()->contains_guid("sync1"));
1325 syncer::SyncChange sync1_change = processor()->change_for_guid("sync1"); 1013 syncer::SyncChange sync1_change = processor()->change_for_guid("sync1");
1326 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, sync1_change.change_type()); 1014 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, sync1_change.change_type());
1327 EXPECT_EQ(google_keyword + ASCIIToUTF16("_"), 1015 EXPECT_EQ(google_keyword, UTF8ToUTF16(GetKeyword(sync1_change.sync_data())));
1328 UTF8ToUTF16(GetKeyword(sync1_change.sync_data()))); 1016 EXPECT_EQ(local_google_url, GetURL(sync1_change.sync_data()));
1329 ASSERT_TRUE(processor()->contains_guid("sync2")); 1017 ASSERT_TRUE(processor()->contains_guid("sync2"));
1330 syncer::SyncChange sync2_change = processor()->change_for_guid("sync2"); 1018 syncer::SyncChange sync2_change = processor()->change_for_guid("sync2");
1331 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, sync2_change.change_type()); 1019 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, sync2_change.change_type());
1332 EXPECT_EQ("other.com", GetKeyword(sync2_change.sync_data())); 1020 EXPECT_EQ("other.com", GetKeyword(sync2_change.sync_data()));
1021 EXPECT_EQ(synced_other_url, GetURL(sync2_change.sync_data()));
1333 } 1022 }
1334 1023
1335 TEST_F(TemplateURLServiceSyncTest, TwoAutogeneratedKeywordsUsingGoogleBaseURL) { 1024 TEST_F(TemplateURLServiceSyncTest, TwoAutogeneratedKeywordsUsingGoogleBaseURL) {
1336 // Sync brings in two autogenerated keywords and both use Google base URLs. 1025 // Sync brings in two autogenerated keywords and both use Google base URLs.
1337 // We make the first older so that it will get renamed once before the second 1026 // We make the first older so that it will get renamed once before the second
1338 // and then again once after (when we resolve conflicts for the second). 1027 // and then again once after (when we resolve conflicts for the second).
1339 syncer::SyncDataList initial_data; 1028 syncer::SyncDataList initial_data;
1340 scoped_ptr<TemplateURL> turl(CreateTestTemplateURL(ASCIIToUTF16("key1"), 1029 scoped_ptr<TemplateURL> turl(CreateTestTemplateURL(ASCIIToUTF16("key1"),
1341 "{google:baseURL}1/search?q={searchTerms}", "key1", 50)); 1030 "{google:baseURL}1/search?q={searchTerms}", "key1", 50));
1342 initial_data.push_back( 1031 initial_data.push_back(
1343 CreateCustomSyncData(*turl, true, turl->url(), turl->sync_guid())); 1032 CreateCustomSyncData(*turl, true, turl->url(), turl->sync_guid()));
1344 turl.reset(CreateTestTemplateURL(ASCIIToUTF16("key2"), 1033 turl.reset(CreateTestTemplateURL(ASCIIToUTF16("key2"),
1345 "{google:baseURL}2/search?q={searchTerms}", "key2")); 1034 "{google:baseURL}2/search?q={searchTerms}", "key2"));
1346 initial_data.push_back( 1035 initial_data.push_back(
1347 CreateCustomSyncData(*turl, true, turl->url(), turl->sync_guid())); 1036 CreateCustomSyncData(*turl, true, turl->url(), turl->sync_guid()));
1348 model()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES, initial_data, 1037 model()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES, initial_data,
1349 PassProcessor(), CreateAndPassSyncErrorFactory()); 1038 PassProcessor(), CreateAndPassSyncErrorFactory());
1350 1039
1351 // We should still have coalesced the updates to one each. 1040 // We should still have coalesced the updates to one each.
1352 string16 google_keyword(net::StripWWW(ASCIIToUTF16(GURL( 1041 string16 google_keyword(net::StripWWW(ASCIIToUTF16(GURL(
1353 UIThreadSearchTermsData(profile_a()).GoogleBaseURLValue()).host()))); 1042 UIThreadSearchTermsData(profile_a()).GoogleBaseURLValue()).host())));
1354 TemplateURL* keyword1 = 1043 TemplateURL* keyword1 =
1355 model()->GetTemplateURLForKeyword(google_keyword + ASCIIToUTF16("_")); 1044 model()->GetTemplateURLForKeyword(google_keyword + ASCIIToUTF16("_"));
1356 ASSERT_FALSE(keyword1 == NULL); 1045 ASSERT_FALSE(keyword1 == NULL);
1357 EXPECT_EQ("key1", keyword1->sync_guid()); 1046 EXPECT_EQ("key1", keyword1->sync_guid());
1358 TemplateURL* keyword2 = model()->GetTemplateURLForKeyword(google_keyword); 1047 TemplateURL* keyword2 = model()->GetTemplateURLForKeyword(google_keyword);
1359 ASSERT_FALSE(keyword2 == NULL); 1048 ASSERT_FALSE(keyword2 == NULL);
1360 EXPECT_EQ("key2", keyword2->sync_guid()); 1049 EXPECT_EQ("key2", keyword2->sync_guid());
1050
1361 EXPECT_GE(processor()->change_list_size(), 2U); 1051 EXPECT_GE(processor()->change_list_size(), 2U);
1362 ASSERT_TRUE(processor()->contains_guid("key1")); 1052 ASSERT_TRUE(processor()->contains_guid("key1"));
1363 syncer::SyncChange key1_change = processor()->change_for_guid("key1"); 1053 syncer::SyncChange key1_change = processor()->change_for_guid("key1");
1364 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, key1_change.change_type()); 1054 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, key1_change.change_type());
1365 EXPECT_EQ(keyword1->keyword(), 1055 EXPECT_EQ(keyword1->keyword(),
1366 UTF8ToUTF16(GetKeyword(key1_change.sync_data()))); 1056 UTF8ToUTF16(GetKeyword(key1_change.sync_data())));
1367 ASSERT_TRUE(processor()->contains_guid("key2")); 1057 ASSERT_TRUE(processor()->contains_guid("key2"));
1368 syncer::SyncChange key2_change = processor()->change_for_guid("key2"); 1058 syncer::SyncChange key2_change = processor()->change_for_guid("key2");
1369 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, key2_change.change_type()); 1059 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, key2_change.change_type());
1370 EXPECT_EQ(keyword2->keyword(), 1060 EXPECT_EQ(keyword2->keyword(),
(...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after
1844 syncer::SyncDataList initial_data = CreateInitialSyncData(); 1534 syncer::SyncDataList initial_data = CreateInitialSyncData();
1845 // The key1 entry should be different from the default but conflict in the 1535 // The key1 entry should be different from the default but conflict in the
1846 // keyword. 1536 // keyword.
1847 scoped_ptr<TemplateURL> turl(CreateTestTemplateURL(keyword, 1537 scoped_ptr<TemplateURL> turl(CreateTestTemplateURL(keyword,
1848 "http://key1.com/{searchTerms}", "key1", 90)); 1538 "http://key1.com/{searchTerms}", "key1", 90));
1849 initial_data[0] = TemplateURLService::CreateSyncDataFromTemplateURL(*turl); 1539 initial_data[0] = TemplateURLService::CreateSyncDataFromTemplateURL(*turl);
1850 1540
1851 model()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES, initial_data, 1541 model()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES, initial_data,
1852 PassProcessor(), CreateAndPassSyncErrorFactory()); 1542 PassProcessor(), CreateAndPassSyncErrorFactory());
1853 1543
1854 // The conflicting TemplateURL should be added, but it should have lost 1544 // Since the local default was not yet synced, it should be merged with the
1855 // conflict resolution against the default. 1545 // conflicting TemplateURL. However, it's values should have been preserved
1856 EXPECT_EQ(4U, model()->GetAllSyncData(syncer::SEARCH_ENGINES).size()); 1546 // since it would have won conflict resolution due to being the default.
1857 const TemplateURL* winner = model()->GetTemplateURLForGUID("whateverguid"); 1547 EXPECT_EQ(3U, model()->GetAllSyncData(syncer::SEARCH_ENGINES).size());
1548 const TemplateURL* winner = model()->GetTemplateURLForGUID("key1");
1858 ASSERT_TRUE(winner); 1549 ASSERT_TRUE(winner);
1859 EXPECT_EQ(model()->GetDefaultSearchProvider(), winner); 1550 EXPECT_EQ(model()->GetDefaultSearchProvider(), winner);
1860 EXPECT_EQ(keyword, winner->keyword()); 1551 EXPECT_EQ(keyword, winner->keyword());
1861 const TemplateURL* loser = model()->GetTemplateURLForGUID("key1"); 1552
1862 ASSERT_TRUE(loser); 1553 // There is no loser, as the two were merged together. The local sync_guid
1863 EXPECT_EQ(ASCIIToUTF16("key1.com"), loser->keyword()); 1554 // should no longer be found in the model.
1555 const TemplateURL* loser = model()->GetTemplateURLForGUID("whateverguid");
1556 ASSERT_FALSE(loser);
1864 } 1557 }
1865 1558
1866 TEST_F(TemplateURLServiceSyncTest, DeleteBogusData) { 1559 TEST_F(TemplateURLServiceSyncTest, DeleteBogusData) {
1867 // Create a couple of bogus entries to sync. 1560 // Create a couple of bogus entries to sync.
1868 syncer::SyncDataList initial_data; 1561 syncer::SyncDataList initial_data;
1869 scoped_ptr<TemplateURL> turl( 1562 scoped_ptr<TemplateURL> turl(
1870 CreateTestTemplateURL(ASCIIToUTF16("key1"), "http://key1.com", "key1")); 1563 CreateTestTemplateURL(ASCIIToUTF16("key1"), "http://key1.com", "key1"));
1871 initial_data.push_back( 1564 initial_data.push_back(
1872 CreateCustomSyncData(*turl, false, std::string(), turl->sync_guid())); 1565 CreateCustomSyncData(*turl, false, std::string(), turl->sync_guid()));
1873 turl.reset(CreateTestTemplateURL(ASCIIToUTF16("key2"), "http://key2.com")); 1566 turl.reset(CreateTestTemplateURL(ASCIIToUTF16("key2"), "http://key2.com"));
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
2005 // A local change to the Google base URL should update the keyword and 1698 // A local change to the Google base URL should update the keyword and
2006 // generate a sync change. 1699 // generate a sync change.
2007 test_util_a_.SetGoogleBaseURL(GURL("http://google.co.in/")); 1700 test_util_a_.SetGoogleBaseURL(GURL("http://google.co.in/"));
2008 EXPECT_EQ(ASCIIToUTF16("google.co.in"), synced_turl->keyword()); 1701 EXPECT_EQ(ASCIIToUTF16("google.co.in"), synced_turl->keyword());
2009 EXPECT_EQ(1U, processor()->change_list_size()); 1702 EXPECT_EQ(1U, processor()->change_list_size());
2010 ASSERT_TRUE(processor()->contains_guid("guid")); 1703 ASSERT_TRUE(processor()->contains_guid("guid"));
2011 syncer::SyncChange change(processor()->change_for_guid("guid")); 1704 syncer::SyncChange change(processor()->change_for_guid("guid"));
2012 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, change.change_type()); 1705 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, change.change_type());
2013 EXPECT_EQ("google.co.in", GetKeyword(change.sync_data())); 1706 EXPECT_EQ("google.co.in", GetKeyword(change.sync_data()));
2014 } 1707 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698