OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "chrome/browser/sync/sessions2/sessions_sync_manager.h" | 5 #include "chrome/browser/sync/sessions2/sessions_sync_manager.h" |
6 | 6 |
7 #include "base/strings/string_util.h" | 7 #include "base/strings/string_util.h" |
8 #include "chrome/browser/chrome_notification_types.h" | 8 #include "chrome/browser/chrome_notification_types.h" |
9 #include "chrome/browser/sessions/session_id.h" | 9 #include "chrome/browser/sessions/session_id.h" |
10 #include "chrome/browser/sessions/session_tab_helper.h" | 10 #include "chrome/browser/sessions/session_tab_helper.h" |
11 #include "chrome/browser/sessions/session_types.h" | 11 #include "chrome/browser/sessions/session_types.h" |
12 #include "chrome/browser/sync/glue/device_info.h" | 12 #include "chrome/browser/sync/glue/device_info.h" |
13 #include "chrome/browser/sync/glue/session_sync_test_helper.h" | 13 #include "chrome/browser/sync/glue/session_sync_test_helper.h" |
14 #include "chrome/browser/sync/glue/synced_tab_delegate.h" | 14 #include "chrome/browser/sync/glue/synced_tab_delegate.h" |
15 #include "chrome/browser/sync/glue/synced_window_delegate.h" | 15 #include "chrome/browser/sync/glue/synced_window_delegate.h" |
16 #include "chrome/browser/sync/sessions2/notification_service_sessions_router.h" | 16 #include "chrome/browser/sync/sessions2/notification_service_sessions_router.h" |
17 #include "chrome/browser/sync/sessions2/sessions_util.h" | 17 #include "chrome/browser/sync/sessions2/sessions_util.h" |
18 #include "chrome/browser/sync/sessions2/synced_window_delegates_getter.h" | 18 #include "chrome/browser/sync/sessions2/synced_window_delegates_getter.h" |
19 #include "chrome/browser/ui/sync/tab_contents_synced_tab_delegate.h" | 19 #include "chrome/browser/ui/sync/tab_contents_synced_tab_delegate.h" |
20 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 20 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
21 #include "chrome/test/base/browser_with_test_window_test.h" | 21 #include "chrome/test/base/browser_with_test_window_test.h" |
22 #include "components/sessions/serialized_navigation_entry_test_helper.h" | 22 #include "components/sessions/serialized_navigation_entry_test_helper.h" |
23 #include "content/public/browser/navigation_entry.h" | 23 #include "content/public/browser/navigation_entry.h" |
24 #include "content/public/browser/notification_details.h" | 24 #include "content/public/browser/notification_details.h" |
25 #include "content/public/browser/notification_service.h" | 25 #include "content/public/browser/notification_service.h" |
26 #include "content/public/browser/notification_source.h" | 26 #include "content/public/browser/notification_source.h" |
27 #include "content/public/browser/web_contents.h" | 27 #include "content/public/browser/web_contents.h" |
| 28 #include "sync/api/attachments/attachment_id.h" |
| 29 #include "sync/api/attachments/attachment_service_proxy_for_test.h" |
28 #include "sync/api/sync_error_factory_mock.h" | 30 #include "sync/api/sync_error_factory_mock.h" |
29 #include "testing/gmock/include/gmock/gmock.h" | 31 #include "testing/gmock/include/gmock/gmock.h" |
30 #include "testing/gtest/include/gtest/gtest.h" | 32 #include "testing/gtest/include/gtest/gtest.h" |
31 | 33 |
32 using content::WebContents; | 34 using content::WebContents; |
33 using sessions::SerializedNavigationEntry; | 35 using sessions::SerializedNavigationEntry; |
34 using sessions::SerializedNavigationEntryTestHelper; | 36 using sessions::SerializedNavigationEntryTestHelper; |
35 using syncer::SyncChange; | 37 using syncer::SyncChange; |
36 using syncer::SyncData; | 38 using syncer::SyncData; |
37 | 39 |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 syncer::SyncChangeList* output_; | 161 syncer::SyncChangeList* output_; |
160 syncer::SyncDataList sync_data_to_return_; | 162 syncer::SyncDataList sync_data_to_return_; |
161 }; | 163 }; |
162 | 164 |
163 syncer::SyncChange MakeRemoteChange( | 165 syncer::SyncChange MakeRemoteChange( |
164 int64 id, | 166 int64 id, |
165 const sync_pb::SessionSpecifics& specifics, | 167 const sync_pb::SessionSpecifics& specifics, |
166 SyncChange::SyncChangeType type) { | 168 SyncChange::SyncChangeType type) { |
167 sync_pb::EntitySpecifics entity; | 169 sync_pb::EntitySpecifics entity; |
168 entity.mutable_session()->CopyFrom(specifics); | 170 entity.mutable_session()->CopyFrom(specifics); |
169 return syncer::SyncChange( | 171 return syncer::SyncChange(FROM_HERE, |
170 FROM_HERE, type, | 172 type, |
171 syncer::SyncData::CreateRemoteData(id, entity, base::Time())); | 173 syncer::SyncData::CreateRemoteData( |
| 174 id, |
| 175 entity, |
| 176 base::Time(), |
| 177 syncer::AttachmentIdList(), |
| 178 syncer::AttachmentServiceProxyForTest())); |
172 } | 179 } |
173 | 180 |
174 void AddTabsToChangeList( | 181 void AddTabsToChangeList( |
175 const std::vector<sync_pb::SessionSpecifics>& batch, | 182 const std::vector<sync_pb::SessionSpecifics>& batch, |
176 SyncChange::SyncChangeType type, | 183 SyncChange::SyncChangeType type, |
177 syncer::SyncChangeList* change_list) { | 184 syncer::SyncChangeList* change_list) { |
178 std::vector<sync_pb::SessionSpecifics>::const_iterator iter; | 185 std::vector<sync_pb::SessionSpecifics>::const_iterator iter; |
179 for (iter = batch.begin(); | 186 for (iter = batch.begin(); |
180 iter != batch.end(); ++iter) { | 187 iter != batch.end(); ++iter) { |
181 sync_pb::EntitySpecifics entity; | 188 sync_pb::EntitySpecifics entity; |
182 entity.mutable_session()->CopyFrom(*iter); | 189 entity.mutable_session()->CopyFrom(*iter); |
183 change_list->push_back(syncer::SyncChange( | 190 change_list->push_back( |
184 FROM_HERE, type, | 191 syncer::SyncChange(FROM_HERE, |
185 syncer::SyncData::CreateRemoteData(iter->tab_node_id(), | 192 type, |
186 entity, base::Time()))); | 193 syncer::SyncData::CreateRemoteData( |
| 194 iter->tab_node_id(), |
| 195 entity, |
| 196 base::Time(), |
| 197 syncer::AttachmentIdList(), |
| 198 syncer::AttachmentServiceProxyForTest()))); |
187 } | 199 } |
188 } | 200 } |
189 | 201 |
190 void AddTabsToSyncDataList(const std::vector<sync_pb::SessionSpecifics> tabs, | 202 void AddTabsToSyncDataList(const std::vector<sync_pb::SessionSpecifics> tabs, |
191 syncer::SyncDataList* list) { | 203 syncer::SyncDataList* list) { |
192 for (size_t i = 0; i < tabs.size(); i++) { | 204 for (size_t i = 0; i < tabs.size(); i++) { |
193 sync_pb::EntitySpecifics entity; | 205 sync_pb::EntitySpecifics entity; |
194 entity.mutable_session()->CopyFrom(tabs[i]); | 206 entity.mutable_session()->CopyFrom(tabs[i]); |
195 list->push_back(SyncData::CreateRemoteData( | 207 list->push_back( |
196 i + 2, entity, base::Time())); | 208 SyncData::CreateRemoteData(i + 2, |
| 209 entity, |
| 210 base::Time(), |
| 211 syncer::AttachmentIdList(), |
| 212 syncer::AttachmentServiceProxyForTest())); |
197 } | 213 } |
198 } | 214 } |
199 | 215 |
200 class DummyRouter : public LocalSessionEventRouter { | 216 class DummyRouter : public LocalSessionEventRouter { |
201 public: | 217 public: |
202 virtual ~DummyRouter() {} | 218 virtual ~DummyRouter() {} |
203 virtual void StartRoutingTo(LocalSessionEventHandler* handler) OVERRIDE {} | 219 virtual void StartRoutingTo(LocalSessionEventHandler* handler) OVERRIDE {} |
204 virtual void Stop() OVERRIDE {} | 220 virtual void Stop() OVERRIDE {} |
205 }; | 221 }; |
206 | 222 |
(...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
653 const SyncData data_2(out[1].sync_data()); | 669 const SyncData data_2(out[1].sync_data()); |
654 EXPECT_EQ(manager()->current_machine_tag(), | 670 EXPECT_EQ(manager()->current_machine_tag(), |
655 syncer::SyncDataLocal(data_2).GetTag()); | 671 syncer::SyncDataLocal(data_2).GetTag()); |
656 const sync_pb::SessionSpecifics& specifics2(data_2.GetSpecifics().session()); | 672 const sync_pb::SessionSpecifics& specifics2(data_2.GetSpecifics().session()); |
657 EXPECT_EQ(manager()->current_machine_tag(), specifics2.session_tag()); | 673 EXPECT_EQ(manager()->current_machine_tag(), specifics2.session_tag()); |
658 EXPECT_TRUE(specifics2.has_header()); | 674 EXPECT_TRUE(specifics2.has_header()); |
659 const sync_pb::SessionHeader& header_s2 = specifics2.header(); | 675 const sync_pb::SessionHeader& header_s2 = specifics2.header(); |
660 EXPECT_EQ(0, header_s2.window_size()); | 676 EXPECT_EQ(0, header_s2.window_size()); |
661 | 677 |
662 // Now take that header node and feed it in as input. | 678 // Now take that header node and feed it in as input. |
663 SyncData d(SyncData::CreateRemoteData(1, data.GetSpecifics(), base::Time())); | 679 SyncData d( |
| 680 SyncData::CreateRemoteData(1, |
| 681 data.GetSpecifics(), |
| 682 base::Time(), |
| 683 syncer::AttachmentIdList(), |
| 684 syncer::AttachmentServiceProxyForTest())); |
664 syncer::SyncDataList in(&d, &d + 1); | 685 syncer::SyncDataList in(&d, &d + 1); |
665 out.clear(); | 686 out.clear(); |
666 SessionsSyncManager manager2(profile(), this, NewDummyRouter()); | 687 SessionsSyncManager manager2(profile(), this, NewDummyRouter()); |
667 syncer::SyncMergeResult result = manager2.MergeDataAndStartSyncing( | 688 syncer::SyncMergeResult result = manager2.MergeDataAndStartSyncing( |
668 syncer::SESSIONS, in, | 689 syncer::SESSIONS, in, |
669 scoped_ptr<syncer::SyncChangeProcessor>( | 690 scoped_ptr<syncer::SyncChangeProcessor>( |
670 new TestSyncProcessorStub(&out)), | 691 new TestSyncProcessorStub(&out)), |
671 scoped_ptr<syncer::SyncErrorFactory>( | 692 scoped_ptr<syncer::SyncErrorFactory>( |
672 new syncer::SyncErrorFactoryMock())); | 693 new syncer::SyncErrorFactoryMock())); |
673 ASSERT_FALSE(result.error().IsSet()); | 694 ASSERT_FALSE(result.error().IsSet()); |
(...skipping 18 matching lines...) Expand all Loading... |
692 syncer::SyncChangeList out; | 713 syncer::SyncChangeList out; |
693 InitWithSyncDataTakeOutput(in, &out); | 714 InitWithSyncDataTakeOutput(in, &out); |
694 | 715 |
695 // Should be one header add, 3 tab add/update pairs, one header update. | 716 // Should be one header add, 3 tab add/update pairs, one header update. |
696 ASSERT_EQ(8U, out.size()); | 717 ASSERT_EQ(8U, out.size()); |
697 | 718 |
698 // For input, we set up: | 719 // For input, we set up: |
699 // * one "normal" fully loaded tab | 720 // * one "normal" fully loaded tab |
700 // * one "frozen" tab with no WebContents and a tab_id change | 721 // * one "frozen" tab with no WebContents and a tab_id change |
701 // * one "frozen" tab with no WebContents and no tab_id change | 722 // * one "frozen" tab with no WebContents and no tab_id change |
702 SyncData t0(SyncData::CreateRemoteData(1, out[2].sync_data().GetSpecifics(), | 723 SyncData t0( |
703 base::Time())); | 724 SyncData::CreateRemoteData(1, |
| 725 out[2].sync_data().GetSpecifics(), |
| 726 base::Time(), |
| 727 syncer::AttachmentIdList(), |
| 728 syncer::AttachmentServiceProxyForTest())); |
704 sync_pb::EntitySpecifics entity(out[4].sync_data().GetSpecifics()); | 729 sync_pb::EntitySpecifics entity(out[4].sync_data().GetSpecifics()); |
705 entity.mutable_session()->mutable_tab()->set_tab_id(kRestoredTabId); | 730 entity.mutable_session()->mutable_tab()->set_tab_id(kRestoredTabId); |
706 SyncData t1(SyncData::CreateRemoteData(2, entity, base::Time())); | 731 SyncData t1( |
707 SyncData t2(SyncData::CreateRemoteData(3, out[6].sync_data().GetSpecifics(), | 732 SyncData::CreateRemoteData(2, |
708 base::Time())); | 733 entity, |
| 734 base::Time(), |
| 735 syncer::AttachmentIdList(), |
| 736 syncer::AttachmentServiceProxyForTest())); |
| 737 SyncData t2( |
| 738 SyncData::CreateRemoteData(3, |
| 739 out[6].sync_data().GetSpecifics(), |
| 740 base::Time(), |
| 741 syncer::AttachmentIdList(), |
| 742 syncer::AttachmentServiceProxyForTest())); |
709 in.push_back(t0); | 743 in.push_back(t0); |
710 in.push_back(t1); | 744 in.push_back(t1); |
711 in.push_back(t2); | 745 in.push_back(t2); |
712 out.clear(); | 746 out.clear(); |
713 manager()->StopSyncing(syncer::SESSIONS); | 747 manager()->StopSyncing(syncer::SESSIONS); |
714 | 748 |
715 const std::set<SyncedWindowDelegate*> windows( | 749 const std::set<SyncedWindowDelegate*> windows( |
716 SyncedWindowDelegate::GetSyncedWindowDelegates()); | 750 SyncedWindowDelegate::GetSyncedWindowDelegates()); |
717 ASSERT_EQ(1U, windows.size()); | 751 ASSERT_EQ(1U, windows.size()); |
718 SyncedTabDelegateFake t1_override, t2_override; | 752 SyncedTabDelegateFake t1_override, t2_override; |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
768 tag, tab_list1, &tabs1)); | 802 tag, tab_list1, &tabs1)); |
769 // Add a second window. | 803 // Add a second window. |
770 SessionID::id_type n2[] = {7, 15, 18, 20}; | 804 SessionID::id_type n2[] = {7, 15, 18, 20}; |
771 std::vector<SessionID::id_type> tab_list2(n2, n2 + arraysize(n2)); | 805 std::vector<SessionID::id_type> tab_list2(n2, n2 + arraysize(n2)); |
772 helper()->AddWindowSpecifics(1, tab_list2, &meta); | 806 helper()->AddWindowSpecifics(1, tab_list2, &meta); |
773 | 807 |
774 // Set up initial data. | 808 // Set up initial data. |
775 syncer::SyncDataList initial_data; | 809 syncer::SyncDataList initial_data; |
776 sync_pb::EntitySpecifics entity; | 810 sync_pb::EntitySpecifics entity; |
777 entity.mutable_session()->CopyFrom(meta); | 811 entity.mutable_session()->CopyFrom(meta); |
778 initial_data.push_back(SyncData::CreateRemoteData(1, entity, base::Time())); | 812 initial_data.push_back( |
| 813 SyncData::CreateRemoteData(1, |
| 814 entity, |
| 815 base::Time(), |
| 816 syncer::AttachmentIdList(), |
| 817 syncer::AttachmentServiceProxyForTest())); |
779 AddTabsToSyncDataList(tabs1, &initial_data); | 818 AddTabsToSyncDataList(tabs1, &initial_data); |
780 | 819 |
781 for (size_t i = 0; i < tab_list2.size(); ++i) { | 820 for (size_t i = 0; i < tab_list2.size(); ++i) { |
782 sync_pb::EntitySpecifics entity; | 821 sync_pb::EntitySpecifics entity; |
783 helper()->BuildTabSpecifics(tag, 0, tab_list2[i], | 822 helper()->BuildTabSpecifics(tag, 0, tab_list2[i], |
784 entity.mutable_session()); | 823 entity.mutable_session()); |
785 initial_data.push_back( | 824 initial_data.push_back( |
786 SyncData::CreateRemoteData(i + 10, entity, base::Time())); | 825 SyncData::CreateRemoteData(i + 10, |
| 826 entity, |
| 827 base::Time(), |
| 828 syncer::AttachmentIdList(), |
| 829 syncer::AttachmentServiceProxyForTest())); |
787 } | 830 } |
788 | 831 |
789 syncer::SyncChangeList output; | 832 syncer::SyncChangeList output; |
790 InitWithSyncDataTakeOutput(initial_data, &output); | 833 InitWithSyncDataTakeOutput(initial_data, &output); |
791 EXPECT_TRUE(FilterOutLocalHeaderChanges(&output)->empty()); | 834 EXPECT_TRUE(FilterOutLocalHeaderChanges(&output)->empty()); |
792 | 835 |
793 std::vector<const SyncedSession*> foreign_sessions; | 836 std::vector<const SyncedSession*> foreign_sessions; |
794 ASSERT_TRUE(manager()->GetAllForeignSessions(&foreign_sessions)); | 837 ASSERT_TRUE(manager()->GetAllForeignSessions(&foreign_sessions)); |
795 ASSERT_EQ(1U, foreign_sessions.size()); | 838 ASSERT_EQ(1U, foreign_sessions.size()); |
796 std::vector<std::vector<SessionID::id_type> > session_reference; | 839 std::vector<std::vector<SessionID::id_type> > session_reference; |
(...skipping 13 matching lines...) Expand all Loading... |
810 // Foreign. | 853 // Foreign. |
811 std::string tag = "tag1"; | 854 std::string tag = "tag1"; |
812 SessionID::id_type n1[] = {5, 10, 13, 17}; | 855 SessionID::id_type n1[] = {5, 10, 13, 17}; |
813 std::vector<SessionID::id_type> tab_list1(n1, n1 + arraysize(n1)); | 856 std::vector<SessionID::id_type> tab_list1(n1, n1 + arraysize(n1)); |
814 std::vector<sync_pb::SessionSpecifics> tabs1; | 857 std::vector<sync_pb::SessionSpecifics> tabs1; |
815 sync_pb::SessionSpecifics meta(helper()->BuildForeignSession( | 858 sync_pb::SessionSpecifics meta(helper()->BuildForeignSession( |
816 tag, tab_list1, &tabs1)); | 859 tag, tab_list1, &tabs1)); |
817 syncer::SyncDataList foreign_data; | 860 syncer::SyncDataList foreign_data; |
818 sync_pb::EntitySpecifics entity; | 861 sync_pb::EntitySpecifics entity; |
819 entity.mutable_session()->CopyFrom(meta); | 862 entity.mutable_session()->CopyFrom(meta); |
820 foreign_data.push_back(SyncData::CreateRemoteData(1, entity, base::Time())); | 863 foreign_data.push_back( |
| 864 SyncData::CreateRemoteData(1, |
| 865 entity, |
| 866 base::Time(), |
| 867 syncer::AttachmentIdList(), |
| 868 syncer::AttachmentServiceProxyForTest())); |
821 AddTabsToSyncDataList(tabs1, &foreign_data); | 869 AddTabsToSyncDataList(tabs1, &foreign_data); |
822 | 870 |
823 syncer::SyncChangeList output; | 871 syncer::SyncChangeList output; |
824 InitWithSyncDataTakeOutput(foreign_data, &output); | 872 InitWithSyncDataTakeOutput(foreign_data, &output); |
825 ASSERT_EQ(4U, output.size()); | 873 ASSERT_EQ(4U, output.size()); |
826 | 874 |
827 // Verify the local header. | 875 // Verify the local header. |
828 EXPECT_TRUE(output[0].IsValid()); | 876 EXPECT_TRUE(output[0].IsValid()); |
829 EXPECT_EQ(SyncChange::ACTION_ADD, output[0].change_type()); | 877 EXPECT_EQ(SyncChange::ACTION_ADD, output[0].change_type()); |
830 const SyncData data(output[0].sync_data()); | 878 const SyncData data(output[0].sync_data()); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
887 std::vector<std::vector<SessionID::id_type> > meta1_reference; | 935 std::vector<std::vector<SessionID::id_type> > meta1_reference; |
888 sync_pb::SessionSpecifics meta1; | 936 sync_pb::SessionSpecifics meta1; |
889 | 937 |
890 SessionID::id_type n1[] = {5, 10, 13, 17}; | 938 SessionID::id_type n1[] = {5, 10, 13, 17}; |
891 std::vector<SessionID::id_type> tab_list1(n1, n1 + arraysize(n1)); | 939 std::vector<SessionID::id_type> tab_list1(n1, n1 + arraysize(n1)); |
892 meta1_reference.push_back(tab_list1); | 940 meta1_reference.push_back(tab_list1); |
893 std::vector<sync_pb::SessionSpecifics> tabs1; | 941 std::vector<sync_pb::SessionSpecifics> tabs1; |
894 meta1 = helper()->BuildForeignSession(tag1, tab_list1, &tabs1); | 942 meta1 = helper()->BuildForeignSession(tag1, tab_list1, &tabs1); |
895 sync_pb::EntitySpecifics entity; | 943 sync_pb::EntitySpecifics entity; |
896 entity.mutable_session()->CopyFrom(meta1); | 944 entity.mutable_session()->CopyFrom(meta1); |
897 foreign_data1.push_back(SyncData::CreateRemoteData( | 945 foreign_data1.push_back( |
898 1, entity, base::Time())); | 946 SyncData::CreateRemoteData(1, |
| 947 entity, |
| 948 base::Time(), |
| 949 syncer::AttachmentIdList(), |
| 950 syncer::AttachmentServiceProxyForTest())); |
899 AddTabsToSyncDataList(tabs1, &foreign_data1); | 951 AddTabsToSyncDataList(tabs1, &foreign_data1); |
900 | 952 |
901 syncer::SyncChangeList output1; | 953 syncer::SyncChangeList output1; |
902 InitWithSyncDataTakeOutput(foreign_data1, &output1); | 954 InitWithSyncDataTakeOutput(foreign_data1, &output1); |
903 ASSERT_EQ(4U, output1.size()); | 955 ASSERT_EQ(4U, output1.size()); |
904 | 956 |
905 // Add a second window to the foreign session. | 957 // Add a second window to the foreign session. |
906 // TODO(tim): Bug 98892. Add local window too when observers are hooked up. | 958 // TODO(tim): Bug 98892. Add local window too when observers are hooked up. |
907 SessionID::id_type tab_nums2[] = {7, 15, 18, 20}; | 959 SessionID::id_type tab_nums2[] = {7, 15, 18, 20}; |
908 std::vector<SessionID::id_type> tab_list2( | 960 std::vector<SessionID::id_type> tab_list2( |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1102 helper()->VerifySyncedSession(tag, session_reference, *(foreign_sessions[0])); | 1154 helper()->VerifySyncedSession(tag, session_reference, *(foreign_sessions[0])); |
1103 } | 1155 } |
1104 | 1156 |
1105 // Tests that the SessionsSyncManager can handle a remote client deleting | 1157 // Tests that the SessionsSyncManager can handle a remote client deleting |
1106 // sync nodes that belong to this local session. | 1158 // sync nodes that belong to this local session. |
1107 TEST_F(SessionsSyncManagerTest, ProcessRemoteDeleteOfLocalSession) { | 1159 TEST_F(SessionsSyncManagerTest, ProcessRemoteDeleteOfLocalSession) { |
1108 syncer::SyncChangeList out; | 1160 syncer::SyncChangeList out; |
1109 InitWithSyncDataTakeOutput(syncer::SyncDataList(), &out); | 1161 InitWithSyncDataTakeOutput(syncer::SyncDataList(), &out); |
1110 ASSERT_EQ(2U, out.size()); | 1162 ASSERT_EQ(2U, out.size()); |
1111 sync_pb::EntitySpecifics entity(out[0].sync_data().GetSpecifics()); | 1163 sync_pb::EntitySpecifics entity(out[0].sync_data().GetSpecifics()); |
1112 SyncData d(SyncData::CreateRemoteData(1, entity, base::Time())); | 1164 SyncData d( |
| 1165 SyncData::CreateRemoteData(1, |
| 1166 entity, |
| 1167 base::Time(), |
| 1168 syncer::AttachmentIdList(), |
| 1169 syncer::AttachmentServiceProxyForTest())); |
1113 SetSyncData(syncer::SyncDataList(&d, &d + 1)); | 1170 SetSyncData(syncer::SyncDataList(&d, &d + 1)); |
1114 out.clear(); | 1171 out.clear(); |
1115 | 1172 |
1116 syncer::SyncChangeList changes; | 1173 syncer::SyncChangeList changes; |
1117 changes.push_back( | 1174 changes.push_back( |
1118 MakeRemoteChange(1, entity.session(), SyncChange::ACTION_DELETE)); | 1175 MakeRemoteChange(1, entity.session(), SyncChange::ACTION_DELETE)); |
1119 manager()->ProcessSyncChanges(FROM_HERE, changes); | 1176 manager()->ProcessSyncChanges(FROM_HERE, changes); |
1120 EXPECT_TRUE(manager()->local_tab_pool_out_of_sync_); | 1177 EXPECT_TRUE(manager()->local_tab_pool_out_of_sync_); |
1121 EXPECT_TRUE(out.empty()); // ChangeProcessor shouldn't see any activity. | 1178 EXPECT_TRUE(out.empty()); // ChangeProcessor shouldn't see any activity. |
1122 | 1179 |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1200 std::string local_tag = manager()->current_machine_tag(); | 1257 std::string local_tag = manager()->current_machine_tag(); |
1201 // Create a free node and then dissassociate sessions so that it ends up | 1258 // Create a free node and then dissassociate sessions so that it ends up |
1202 // unassociated. | 1259 // unassociated. |
1203 manager()->local_tab_pool_.GetFreeTabNode(&changes); | 1260 manager()->local_tab_pool_.GetFreeTabNode(&changes); |
1204 | 1261 |
1205 // Update the tab_id of the node, so that it is considered a valid | 1262 // Update the tab_id of the node, so that it is considered a valid |
1206 // unassociated node otherwise it will be mistaken for a corrupted node and | 1263 // unassociated node otherwise it will be mistaken for a corrupted node and |
1207 // will be deleted before being added to the tab node pool. | 1264 // will be deleted before being added to the tab node pool. |
1208 sync_pb::EntitySpecifics entity(changes[0].sync_data().GetSpecifics()); | 1265 sync_pb::EntitySpecifics entity(changes[0].sync_data().GetSpecifics()); |
1209 entity.mutable_session()->mutable_tab()->set_tab_id(1); | 1266 entity.mutable_session()->mutable_tab()->set_tab_id(1); |
1210 SyncData d(SyncData::CreateRemoteData(1, entity, base::Time())); | 1267 SyncData d( |
| 1268 SyncData::CreateRemoteData(1, |
| 1269 entity, |
| 1270 base::Time(), |
| 1271 syncer::AttachmentIdList(), |
| 1272 syncer::AttachmentServiceProxyForTest())); |
1211 syncer::SyncDataList in(&d, &d + 1); | 1273 syncer::SyncDataList in(&d, &d + 1); |
1212 changes.clear(); | 1274 changes.clear(); |
1213 SessionsSyncManager manager2(profile(), this, NewDummyRouter()); | 1275 SessionsSyncManager manager2(profile(), this, NewDummyRouter()); |
1214 syncer::SyncMergeResult result = manager2.MergeDataAndStartSyncing( | 1276 syncer::SyncMergeResult result = manager2.MergeDataAndStartSyncing( |
1215 syncer::SESSIONS, in, | 1277 syncer::SESSIONS, in, |
1216 scoped_ptr<syncer::SyncChangeProcessor>( | 1278 scoped_ptr<syncer::SyncChangeProcessor>( |
1217 new TestSyncProcessorStub(&changes)), | 1279 new TestSyncProcessorStub(&changes)), |
1218 scoped_ptr<syncer::SyncErrorFactory>( | 1280 scoped_ptr<syncer::SyncErrorFactory>( |
1219 new syncer::SyncErrorFactoryMock())); | 1281 new syncer::SyncErrorFactoryMock())); |
1220 ASSERT_FALSE(result.error().IsSet()); | 1282 ASSERT_FALSE(result.error().IsSet()); |
1221 EXPECT_TRUE(FilterOutLocalHeaderChanges(&changes)->empty()); | 1283 EXPECT_TRUE(FilterOutLocalHeaderChanges(&changes)->empty()); |
1222 } | 1284 } |
1223 | 1285 |
1224 TEST_F(SessionsSyncManagerTest, MergeDeletesCorruptNode) { | 1286 TEST_F(SessionsSyncManagerTest, MergeDeletesCorruptNode) { |
1225 syncer::SyncChangeList changes; | 1287 syncer::SyncChangeList changes; |
1226 InitWithNoSyncData(); | 1288 InitWithNoSyncData(); |
1227 | 1289 |
1228 std::string local_tag = manager()->current_machine_tag(); | 1290 std::string local_tag = manager()->current_machine_tag(); |
1229 int tab_node_id = manager()->local_tab_pool_.GetFreeTabNode(&changes); | 1291 int tab_node_id = manager()->local_tab_pool_.GetFreeTabNode(&changes); |
1230 SyncData d(SyncData::CreateRemoteData( | 1292 SyncData d( |
1231 1, changes[0].sync_data().GetSpecifics(), base::Time())); | 1293 SyncData::CreateRemoteData(1, |
| 1294 changes[0].sync_data().GetSpecifics(), |
| 1295 base::Time(), |
| 1296 syncer::AttachmentIdList(), |
| 1297 syncer::AttachmentServiceProxyForTest())); |
1232 syncer::SyncDataList in(&d, &d + 1); | 1298 syncer::SyncDataList in(&d, &d + 1); |
1233 changes.clear(); | 1299 changes.clear(); |
1234 TearDown(); | 1300 TearDown(); |
1235 SetUp(); | 1301 SetUp(); |
1236 InitWithSyncDataTakeOutput(in, &changes); | 1302 InitWithSyncDataTakeOutput(in, &changes); |
1237 EXPECT_EQ(1U, FilterOutLocalHeaderChanges(&changes)->size()); | 1303 EXPECT_EQ(1U, FilterOutLocalHeaderChanges(&changes)->size()); |
1238 EXPECT_EQ(SyncChange::ACTION_DELETE, changes[0].change_type()); | 1304 EXPECT_EQ(SyncChange::ACTION_DELETE, changes[0].change_type()); |
1239 EXPECT_EQ(TabNodePool2::TabIdToTag(local_tag, tab_node_id), | 1305 EXPECT_EQ(TabNodePool2::TabIdToTag(local_tag, tab_node_id), |
1240 syncer::SyncDataLocal(changes[0].sync_data()).GetTag()); | 1306 syncer::SyncDataLocal(changes[0].sync_data()).GetTag()); |
1241 } | 1307 } |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1489 sync_pb::SessionSpecifics meta2(helper()->BuildForeignSession( | 1555 sync_pb::SessionSpecifics meta2(helper()->BuildForeignSession( |
1490 tag2, tab_list2, &tabs2)); | 1556 tag2, tab_list2, &tabs2)); |
1491 // Set the modification time for tag1 to be 21 days ago, tag2 to 5 days ago. | 1557 // Set the modification time for tag1 to be 21 days ago, tag2 to 5 days ago. |
1492 base::Time tag1_time = base::Time::Now() - base::TimeDelta::FromDays(21); | 1558 base::Time tag1_time = base::Time::Now() - base::TimeDelta::FromDays(21); |
1493 base::Time tag2_time = base::Time::Now() - base::TimeDelta::FromDays(5); | 1559 base::Time tag2_time = base::Time::Now() - base::TimeDelta::FromDays(5); |
1494 | 1560 |
1495 syncer::SyncDataList foreign_data; | 1561 syncer::SyncDataList foreign_data; |
1496 sync_pb::EntitySpecifics entity1, entity2; | 1562 sync_pb::EntitySpecifics entity1, entity2; |
1497 entity1.mutable_session()->CopyFrom(meta); | 1563 entity1.mutable_session()->CopyFrom(meta); |
1498 entity2.mutable_session()->CopyFrom(meta2); | 1564 entity2.mutable_session()->CopyFrom(meta2); |
1499 foreign_data.push_back(SyncData::CreateRemoteData(1, entity1, tag1_time)); | 1565 foreign_data.push_back( |
1500 foreign_data.push_back(SyncData::CreateRemoteData(1, entity2, tag2_time)); | 1566 SyncData::CreateRemoteData(1, |
| 1567 entity1, |
| 1568 tag1_time, |
| 1569 syncer::AttachmentIdList(), |
| 1570 syncer::AttachmentServiceProxyForTest())); |
| 1571 foreign_data.push_back( |
| 1572 SyncData::CreateRemoteData(1, |
| 1573 entity2, |
| 1574 tag2_time, |
| 1575 syncer::AttachmentIdList(), |
| 1576 syncer::AttachmentServiceProxyForTest())); |
1501 AddTabsToSyncDataList(tabs1, &foreign_data); | 1577 AddTabsToSyncDataList(tabs1, &foreign_data); |
1502 AddTabsToSyncDataList(tabs2, &foreign_data); | 1578 AddTabsToSyncDataList(tabs2, &foreign_data); |
1503 | 1579 |
1504 syncer::SyncChangeList output; | 1580 syncer::SyncChangeList output; |
1505 InitWithSyncDataTakeOutput(foreign_data, &output); | 1581 InitWithSyncDataTakeOutput(foreign_data, &output); |
1506 ASSERT_EQ(2U, output.size()); | 1582 ASSERT_EQ(2U, output.size()); |
1507 output.clear(); | 1583 output.clear(); |
1508 | 1584 |
1509 // Check that the foreign session was associated and retrieve the data. | 1585 // Check that the foreign session was associated and retrieve the data. |
1510 std::vector<const SyncedSession*> foreign_sessions; | 1586 std::vector<const SyncedSession*> foreign_sessions; |
(...skipping 28 matching lines...) Expand all Loading... |
1539 std::string tag1 = "tag1"; | 1615 std::string tag1 = "tag1"; |
1540 SessionID::id_type n1[] = {5, 10, 13, 17}; | 1616 SessionID::id_type n1[] = {5, 10, 13, 17}; |
1541 std::vector<SessionID::id_type> tab_list1(n1, n1 + arraysize(n1)); | 1617 std::vector<SessionID::id_type> tab_list1(n1, n1 + arraysize(n1)); |
1542 std::vector<sync_pb::SessionSpecifics> tabs1; | 1618 std::vector<sync_pb::SessionSpecifics> tabs1; |
1543 sync_pb::SessionSpecifics meta(helper()->BuildForeignSession( | 1619 sync_pb::SessionSpecifics meta(helper()->BuildForeignSession( |
1544 tag1, tab_list1, &tabs1)); | 1620 tag1, tab_list1, &tabs1)); |
1545 syncer::SyncDataList foreign_data; | 1621 syncer::SyncDataList foreign_data; |
1546 sync_pb::EntitySpecifics entity1; | 1622 sync_pb::EntitySpecifics entity1; |
1547 base::Time tag1_time = base::Time::Now() - base::TimeDelta::FromDays(21); | 1623 base::Time tag1_time = base::Time::Now() - base::TimeDelta::FromDays(21); |
1548 entity1.mutable_session()->CopyFrom(meta); | 1624 entity1.mutable_session()->CopyFrom(meta); |
1549 foreign_data.push_back(SyncData::CreateRemoteData(1, entity1, tag1_time)); | 1625 foreign_data.push_back( |
| 1626 SyncData::CreateRemoteData(1, |
| 1627 entity1, |
| 1628 tag1_time, |
| 1629 syncer::AttachmentIdList(), |
| 1630 syncer::AttachmentServiceProxyForTest())); |
1550 AddTabsToSyncDataList(tabs1, &foreign_data); | 1631 AddTabsToSyncDataList(tabs1, &foreign_data); |
1551 syncer::SyncChangeList output; | 1632 syncer::SyncChangeList output; |
1552 InitWithSyncDataTakeOutput(foreign_data, &output); | 1633 InitWithSyncDataTakeOutput(foreign_data, &output); |
1553 ASSERT_EQ(2U, output.size()); | 1634 ASSERT_EQ(2U, output.size()); |
1554 | 1635 |
1555 // Update to a non-stale time. | 1636 // Update to a non-stale time. |
1556 sync_pb::EntitySpecifics update_entity; | 1637 sync_pb::EntitySpecifics update_entity; |
1557 update_entity.mutable_session()->CopyFrom(tabs1[0]); | 1638 update_entity.mutable_session()->CopyFrom(tabs1[0]); |
1558 syncer::SyncChangeList changes; | 1639 syncer::SyncChangeList changes; |
1559 changes.push_back(syncer::SyncChange( | 1640 changes.push_back( |
1560 FROM_HERE, | 1641 syncer::SyncChange(FROM_HERE, |
1561 SyncChange::ACTION_UPDATE, | 1642 SyncChange::ACTION_UPDATE, |
1562 syncer::SyncData::CreateRemoteData(1, update_entity, | 1643 syncer::SyncData::CreateRemoteData( |
1563 base::Time::Now()))); | 1644 1, |
| 1645 update_entity, |
| 1646 base::Time::Now(), |
| 1647 syncer::AttachmentIdList(), |
| 1648 syncer::AttachmentServiceProxyForTest()))); |
1564 manager()->ProcessSyncChanges(FROM_HERE, changes); | 1649 manager()->ProcessSyncChanges(FROM_HERE, changes); |
1565 | 1650 |
1566 // Check that the foreign session was associated and retrieve the data. | 1651 // Check that the foreign session was associated and retrieve the data. |
1567 std::vector<const SyncedSession*> foreign_sessions; | 1652 std::vector<const SyncedSession*> foreign_sessions; |
1568 ASSERT_TRUE(manager()->GetAllForeignSessions(&foreign_sessions)); | 1653 ASSERT_TRUE(manager()->GetAllForeignSessions(&foreign_sessions)); |
1569 ASSERT_EQ(1U, foreign_sessions.size()); | 1654 ASSERT_EQ(1U, foreign_sessions.size()); |
1570 foreign_sessions.clear(); | 1655 foreign_sessions.clear(); |
1571 | 1656 |
1572 // Verify the now non-stale session does not get deleted. | 1657 // Verify the now non-stale session does not get deleted. |
1573 manager()->DoGarbageCollection(); | 1658 manager()->DoGarbageCollection(); |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1727 ASSERT_FALSE(observer.notified_of_refresh()); | 1812 ASSERT_FALSE(observer.notified_of_refresh()); |
1728 InitWithNoSyncData(); | 1813 InitWithNoSyncData(); |
1729 AddTab(browser(), GURL("http://foo1")); | 1814 AddTab(browser(), GURL("http://foo1")); |
1730 EXPECT_FALSE(observer.notified_of_refresh()); | 1815 EXPECT_FALSE(observer.notified_of_refresh()); |
1731 NavigateAndCommitActiveTab(GURL("chrome://newtab/#open_tabs")); | 1816 NavigateAndCommitActiveTab(GURL("chrome://newtab/#open_tabs")); |
1732 EXPECT_TRUE(observer.notified_of_refresh()); | 1817 EXPECT_TRUE(observer.notified_of_refresh()); |
1733 } | 1818 } |
1734 #endif // defined(OS_ANDROID) || defined(OS_IOS) | 1819 #endif // defined(OS_ANDROID) || defined(OS_IOS) |
1735 | 1820 |
1736 } // namespace browser_sync | 1821 } // namespace browser_sync |
OLD | NEW |