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

Side by Side Diff: chrome/browser/sync/glue/session_model_associator_unittest.cc

Issue 10698014: [Sync] Rename csync namespace to syncer (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments Created 8 years, 5 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 | Annotate | Revision Log
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 <string> 5 #include <string>
6 #include <vector> 6 #include <vector>
7 7
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "chrome/browser/sessions/session_types.h" 10 #include "chrome/browser/sessions/session_types.h"
(...skipping 578 matching lines...) Expand 10 before | Expand all | Expand 10 after
589 Return(entry3.get())); 589 Return(entry3.get()));
590 EXPECT_CALL(tab_mock, GetEntryCount()).WillRepeatedly(Return(3)); 590 EXPECT_CALL(tab_mock, GetEntryCount()).WillRepeatedly(Return(3));
591 EXPECT_CALL(tab_mock, GetPendingEntryIndex()).WillRepeatedly(Return(-1)); 591 EXPECT_CALL(tab_mock, GetPendingEntryIndex()).WillRepeatedly(Return(-1));
592 592
593 // This tab is new, so prev_tab is the default SyncedSessionTab object. 593 // This tab is new, so prev_tab is the default SyncedSessionTab object.
594 SyncedSessionTab prev_tab; 594 SyncedSessionTab prev_tab;
595 prev_tab.tab_id.set_id(0); 595 prev_tab.tab_id.set_id(0);
596 596
597 sync_pb::SessionTab sync_tab; 597 sync_pb::SessionTab sync_tab;
598 GURL new_url; 598 GURL new_url;
599 int64 now = csync::TimeToProtoTime(base::Time::Now()); 599 int64 now = syncer::TimeToProtoTime(base::Time::Now());
600 AssociateTabContents(window_mock, tab_mock, &prev_tab, &sync_tab, &new_url); 600 AssociateTabContents(window_mock, tab_mock, &prev_tab, &sync_tab, &new_url);
601 601
602 EXPECT_EQ(new_url, entry3->GetVirtualURL()); 602 EXPECT_EQ(new_url, entry3->GetVirtualURL());
603 ASSERT_EQ(3, sync_tab.navigation_size()); 603 ASSERT_EQ(3, sync_tab.navigation_size());
604 EXPECT_EQ(entry1->GetVirtualURL().spec(), 604 EXPECT_EQ(entry1->GetVirtualURL().spec(),
605 sync_tab.navigation(0).virtual_url()); 605 sync_tab.navigation(0).virtual_url());
606 EXPECT_EQ(entry2->GetVirtualURL().spec(), 606 EXPECT_EQ(entry2->GetVirtualURL().spec(),
607 sync_tab.navigation(1).virtual_url()); 607 sync_tab.navigation(1).virtual_url());
608 EXPECT_EQ(entry3->GetVirtualURL().spec(), 608 EXPECT_EQ(entry3->GetVirtualURL().spec(),
609 sync_tab.navigation(2).virtual_url()); 609 sync_tab.navigation(2).virtual_url());
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
643 // This tab is new, so prev_tab is the default SyncedSessionTab object. 643 // This tab is new, so prev_tab is the default SyncedSessionTab object.
644 SyncedSessionTab prev_tab; 644 SyncedSessionTab prev_tab;
645 prev_tab.tab_id.set_id(0); 645 prev_tab.tab_id.set_id(0);
646 646
647 // The initial AssociateTabContents call builds the prev_tab. 647 // The initial AssociateTabContents call builds the prev_tab.
648 sync_pb::SessionTab sync_tab; 648 sync_pb::SessionTab sync_tab;
649 GURL new_url; 649 GURL new_url;
650 AssociateTabContents(window_mock, tab_mock, &prev_tab, &sync_tab, &new_url); 650 AssociateTabContents(window_mock, tab_mock, &prev_tab, &sync_tab, &new_url);
651 651
652 // Override the timestamps to arbitrary old values we can compare against. 652 // Override the timestamps to arbitrary old values we can compare against.
653 prev_tab.synced_tab_navigations[0].set_timestamp(csync::ProtoTimeToTime(1)); 653 prev_tab.synced_tab_navigations[0].set_timestamp(syncer::ProtoTimeToTime(1));
654 prev_tab.synced_tab_navigations[1].set_timestamp(csync::ProtoTimeToTime(2)); 654 prev_tab.synced_tab_navigations[1].set_timestamp(syncer::ProtoTimeToTime(2));
655 prev_tab.synced_tab_navigations[2].set_timestamp(csync::ProtoTimeToTime(3)); 655 prev_tab.synced_tab_navigations[2].set_timestamp(syncer::ProtoTimeToTime(3));
656 656
657 // Now re-associate with the same data. 657 // Now re-associate with the same data.
658 AssociateTabContents(window_mock, tab_mock, &prev_tab, &sync_tab, &new_url); 658 AssociateTabContents(window_mock, tab_mock, &prev_tab, &sync_tab, &new_url);
659 659
660 EXPECT_EQ(new_url, entry3->GetVirtualURL()); 660 EXPECT_EQ(new_url, entry3->GetVirtualURL());
661 ASSERT_EQ(3, sync_tab.navigation_size()); 661 ASSERT_EQ(3, sync_tab.navigation_size());
662 EXPECT_EQ(entry1->GetVirtualURL().spec(), 662 EXPECT_EQ(entry1->GetVirtualURL().spec(),
663 sync_tab.navigation(0).virtual_url()); 663 sync_tab.navigation(0).virtual_url());
664 EXPECT_EQ(entry2->GetVirtualURL().spec(), 664 EXPECT_EQ(entry2->GetVirtualURL().spec(),
665 sync_tab.navigation(1).virtual_url()); 665 sync_tab.navigation(1).virtual_url());
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
703 // This tab is new, so prev_tab is the default SyncedSessionTab object. 703 // This tab is new, so prev_tab is the default SyncedSessionTab object.
704 SyncedSessionTab prev_tab; 704 SyncedSessionTab prev_tab;
705 prev_tab.tab_id.set_id(0); 705 prev_tab.tab_id.set_id(0);
706 706
707 // The initial AssociateTabContents call builds the prev_tab. 707 // The initial AssociateTabContents call builds the prev_tab.
708 sync_pb::SessionTab sync_tab; 708 sync_pb::SessionTab sync_tab;
709 GURL new_url; 709 GURL new_url;
710 AssociateTabContents(window_mock, tab_mock, &prev_tab, &sync_tab, &new_url); 710 AssociateTabContents(window_mock, tab_mock, &prev_tab, &sync_tab, &new_url);
711 711
712 // Override the timestamps to arbitrary old values we can compare against. 712 // Override the timestamps to arbitrary old values we can compare against.
713 prev_tab.synced_tab_navigations[0].set_timestamp(csync::ProtoTimeToTime(1)); 713 prev_tab.synced_tab_navigations[0].set_timestamp(syncer::ProtoTimeToTime(1));
714 prev_tab.synced_tab_navigations[1].set_timestamp(csync::ProtoTimeToTime(2)); 714 prev_tab.synced_tab_navigations[1].set_timestamp(syncer::ProtoTimeToTime(2));
715 prev_tab.synced_tab_navigations[2].set_timestamp(csync::ProtoTimeToTime(3)); 715 prev_tab.synced_tab_navigations[2].set_timestamp(syncer::ProtoTimeToTime(3));
716 716
717 // Add a new entry and change the current navigation index. 717 // Add a new entry and change the current navigation index.
718 scoped_ptr<content::NavigationEntry> entry4( 718 scoped_ptr<content::NavigationEntry> entry4(
719 content::NavigationEntry::Create()); 719 content::NavigationEntry::Create());
720 entry4->SetVirtualURL(GURL("http://www.poodle.com")); 720 entry4->SetVirtualURL(GURL("http://www.poodle.com"));
721 EXPECT_CALL(tab_mock, GetEntryAtIndex(3)).WillRepeatedly( 721 EXPECT_CALL(tab_mock, GetEntryAtIndex(3)).WillRepeatedly(
722 Return(entry4.get())); 722 Return(entry4.get()));
723 EXPECT_CALL(tab_mock, GetEntryCount()).WillRepeatedly(Return(4)); 723 EXPECT_CALL(tab_mock, GetEntryCount()).WillRepeatedly(Return(4));
724 EXPECT_CALL(tab_mock, GetCurrentEntryIndex()).WillRepeatedly(Return(3)); 724 EXPECT_CALL(tab_mock, GetCurrentEntryIndex()).WillRepeatedly(Return(3));
725 725
726 // The new entry should have a timestamp later than this. 726 // The new entry should have a timestamp later than this.
727 int64 now = csync::TimeToProtoTime(base::Time::Now()); 727 int64 now = syncer::TimeToProtoTime(base::Time::Now());
728 728
729 // Now re-associate with the new version. 729 // Now re-associate with the new version.
730 AssociateTabContents(window_mock, tab_mock, &prev_tab, &sync_tab, &new_url); 730 AssociateTabContents(window_mock, tab_mock, &prev_tab, &sync_tab, &new_url);
731 731
732 EXPECT_EQ(new_url, entry4->GetVirtualURL()); 732 EXPECT_EQ(new_url, entry4->GetVirtualURL());
733 ASSERT_EQ(4, sync_tab.navigation_size()); 733 ASSERT_EQ(4, sync_tab.navigation_size());
734 EXPECT_EQ(entry1->GetVirtualURL().spec(), 734 EXPECT_EQ(entry1->GetVirtualURL().spec(),
735 sync_tab.navigation(0).virtual_url()); 735 sync_tab.navigation(0).virtual_url());
736 EXPECT_EQ(entry2->GetVirtualURL().spec(), 736 EXPECT_EQ(entry2->GetVirtualURL().spec(),
737 sync_tab.navigation(1).virtual_url()); 737 sync_tab.navigation(1).virtual_url());
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
785 // This tab is new, so prev_tab is the default SyncedSessionTab object. 785 // This tab is new, so prev_tab is the default SyncedSessionTab object.
786 SyncedSessionTab prev_tab; 786 SyncedSessionTab prev_tab;
787 prev_tab.tab_id.set_id(0); 787 prev_tab.tab_id.set_id(0);
788 788
789 // The initial AssociateTabContents call builds the prev_tab. 789 // The initial AssociateTabContents call builds the prev_tab.
790 sync_pb::SessionTab sync_tab; 790 sync_pb::SessionTab sync_tab;
791 GURL new_url; 791 GURL new_url;
792 AssociateTabContents(window_mock, tab_mock, &prev_tab, &sync_tab, &new_url); 792 AssociateTabContents(window_mock, tab_mock, &prev_tab, &sync_tab, &new_url);
793 793
794 // Override the timestamps to arbitrary old values we can compare against. 794 // Override the timestamps to arbitrary old values we can compare against.
795 prev_tab.synced_tab_navigations[0].set_timestamp(csync::ProtoTimeToTime(1)); 795 prev_tab.synced_tab_navigations[0].set_timestamp(syncer::ProtoTimeToTime(1));
796 prev_tab.synced_tab_navigations[1].set_timestamp(csync::ProtoTimeToTime(2)); 796 prev_tab.synced_tab_navigations[1].set_timestamp(syncer::ProtoTimeToTime(2));
797 prev_tab.synced_tab_navigations[2].set_timestamp(csync::ProtoTimeToTime(3)); 797 prev_tab.synced_tab_navigations[2].set_timestamp(syncer::ProtoTimeToTime(3));
798 prev_tab.synced_tab_navigations[2].set_timestamp(csync::ProtoTimeToTime(4)); 798 prev_tab.synced_tab_navigations[2].set_timestamp(syncer::ProtoTimeToTime(4));
799 799
800 // Reset new tab to have the oldest entry pruned, the current navigation 800 // Reset new tab to have the oldest entry pruned, the current navigation
801 // set to entry3, and a new entry added in place of entry4. 801 // set to entry3, and a new entry added in place of entry4.
802 testing::Mock::VerifyAndClearExpectations(&tab_mock); 802 testing::Mock::VerifyAndClearExpectations(&tab_mock);
803 EXPECT_CALL(tab_mock, GetCurrentEntryIndex()).WillRepeatedly(Return(1)); 803 EXPECT_CALL(tab_mock, GetCurrentEntryIndex()).WillRepeatedly(Return(1));
804 EXPECT_CALL(tab_mock, GetEntryAtIndex(0)).WillRepeatedly( 804 EXPECT_CALL(tab_mock, GetEntryAtIndex(0)).WillRepeatedly(
805 Return(entry2.get())); 805 Return(entry2.get()));
806 EXPECT_CALL(tab_mock, GetEntryAtIndex(1)).WillRepeatedly( 806 EXPECT_CALL(tab_mock, GetEntryAtIndex(1)).WillRepeatedly(
807 Return(entry3.get())); 807 Return(entry3.get()));
808 scoped_ptr<content::NavigationEntry> entry5( 808 scoped_ptr<content::NavigationEntry> entry5(
809 content::NavigationEntry::Create()); 809 content::NavigationEntry::Create());
810 entry5->SetVirtualURL(GURL("http://www.noogle.com")); 810 entry5->SetVirtualURL(GURL("http://www.noogle.com"));
811 EXPECT_CALL(tab_mock, GetEntryAtIndex(2)).WillRepeatedly( 811 EXPECT_CALL(tab_mock, GetEntryAtIndex(2)).WillRepeatedly(
812 Return(entry5.get())); 812 Return(entry5.get()));
813 EXPECT_CALL(tab_mock, GetEntryCount()).WillRepeatedly(Return(3)); 813 EXPECT_CALL(tab_mock, GetEntryCount()).WillRepeatedly(Return(3));
814 EXPECT_CALL(tab_mock, GetPendingEntryIndex()).WillRepeatedly(Return(-1)); 814 EXPECT_CALL(tab_mock, GetPendingEntryIndex()).WillRepeatedly(Return(-1));
815 815
816 // The new entry should have a timestamp later than this. 816 // The new entry should have a timestamp later than this.
817 int64 now = csync::TimeToProtoTime(base::Time::Now()); 817 int64 now = syncer::TimeToProtoTime(base::Time::Now());
818 818
819 // Now re-associate with the new version. 819 // Now re-associate with the new version.
820 AssociateTabContents(window_mock, tab_mock, &prev_tab, &sync_tab, &new_url); 820 AssociateTabContents(window_mock, tab_mock, &prev_tab, &sync_tab, &new_url);
821 821
822 // Only entry2's timestamp should be preserved. The new entry should have a 822 // Only entry2's timestamp should be preserved. The new entry should have a
823 // new timestamp. 823 // new timestamp.
824 EXPECT_EQ(new_url, entry3->GetVirtualURL()); 824 EXPECT_EQ(new_url, entry3->GetVirtualURL());
825 ASSERT_EQ(3, sync_tab.navigation_size()); 825 ASSERT_EQ(3, sync_tab.navigation_size());
826 EXPECT_EQ(entry2->GetVirtualURL().spec(), 826 EXPECT_EQ(entry2->GetVirtualURL().spec(),
827 sync_tab.navigation(0).virtual_url()); 827 sync_tab.navigation(0).virtual_url());
828 EXPECT_EQ(entry3->GetVirtualURL().spec(), 828 EXPECT_EQ(entry3->GetVirtualURL().spec(),
829 sync_tab.navigation(1).virtual_url()); 829 sync_tab.navigation(1).virtual_url());
830 EXPECT_EQ(entry5->GetVirtualURL().spec(), 830 EXPECT_EQ(entry5->GetVirtualURL().spec(),
831 sync_tab.navigation(2).virtual_url()); 831 sync_tab.navigation(2).virtual_url());
832 EXPECT_EQ(1, sync_tab.current_navigation_index()); 832 EXPECT_EQ(1, sync_tab.current_navigation_index());
833 EXPECT_EQ(2, sync_tab.navigation(0).timestamp()); 833 EXPECT_EQ(2, sync_tab.navigation(0).timestamp());
834 EXPECT_LE(now, sync_tab.navigation(1).timestamp()); 834 EXPECT_LE(now, sync_tab.navigation(1).timestamp());
835 EXPECT_LE(now, sync_tab.navigation(2).timestamp()); 835 EXPECT_LE(now, sync_tab.navigation(2).timestamp());
836 EXPECT_EQ(3U, prev_tab.navigations.size()); 836 EXPECT_EQ(3U, prev_tab.navigations.size());
837 EXPECT_EQ(3U, prev_tab.synced_tab_navigations.size()); 837 EXPECT_EQ(3U, prev_tab.synced_tab_navigations.size());
838 } 838 }
839 839
840 } // namespace browser_sync 840 } // namespace browser_sync
OLDNEW
« no previous file with comments | « chrome/browser/sync/glue/session_model_associator.cc ('k') | chrome/browser/sync/glue/shared_change_processor.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698