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