| 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" |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 } // namespace | 95 } // namespace |
| 96 | 96 |
| 97 class SessionsSyncManagerTest | 97 class SessionsSyncManagerTest |
| 98 : public BrowserWithTestWindowTest, | 98 : public BrowserWithTestWindowTest, |
| 99 public SessionsSyncManager::SyncInternalApiDelegate { | 99 public SessionsSyncManager::SyncInternalApiDelegate { |
| 100 public: | 100 public: |
| 101 SessionsSyncManagerTest() {} | 101 SessionsSyncManagerTest() {} |
| 102 | 102 |
| 103 virtual void SetUp() OVERRIDE { | 103 virtual void SetUp() OVERRIDE { |
| 104 BrowserWithTestWindowTest::SetUp(); | 104 BrowserWithTestWindowTest::SetUp(); |
| 105 manager_.reset(new SessionsSyncManager( | 105 manager_.reset(new SessionsSyncManager(profile(), this)); |
| 106 profile(), | |
| 107 scoped_ptr<SyncPrefs>(new SyncPrefs(profile()->GetPrefs())), | |
| 108 this)); | |
| 109 } | 106 } |
| 110 | 107 |
| 111 virtual void TearDown() OVERRIDE { | 108 virtual void TearDown() OVERRIDE { |
| 112 helper()->Reset(); | 109 helper()->Reset(); |
| 113 manager_.reset(); | 110 manager_.reset(); |
| 114 BrowserWithTestWindowTest::TearDown(); | 111 BrowserWithTestWindowTest::TearDown(); |
| 115 } | 112 } |
| 116 | 113 |
| 117 virtual scoped_ptr<DeviceInfo> GetLocalDeviceInfo() const OVERRIDE { | 114 virtual scoped_ptr<DeviceInfo> GetLocalDeviceInfo() const OVERRIDE { |
| 118 return scoped_ptr<DeviceInfo>( | 115 return scoped_ptr<DeviceInfo>( |
| 119 new DeviceInfo(GetCacheGuid(), | 116 new DeviceInfo(GetLocalDeviceGUID(), |
| 120 "Wayne Gretzky's Hacking Box", | 117 "Wayne Gretzky's Hacking Box", |
| 121 "Chromium 10k", | 118 "Chromium 10k", |
| 122 "Chrome 10k", | 119 "Chrome 10k", |
| 123 sync_pb::SyncEnums_DeviceType_TYPE_LINUX)); | 120 sync_pb::SyncEnums_DeviceType_TYPE_LINUX)); |
| 124 } | 121 } |
| 125 | 122 |
| 126 virtual std::string GetCacheGuid() const OVERRIDE { | 123 virtual std::string GetLocalDeviceGUID() const OVERRIDE { |
| 127 return "cache_guid"; | 124 return "cache_guid"; |
| 128 } | 125 } |
| 129 | 126 |
| 130 SessionsSyncManager* manager() { return manager_.get(); } | 127 SessionsSyncManager* manager() { return manager_.get(); } |
| 131 SessionSyncTestHelper* helper() { return &helper_; } | 128 SessionSyncTestHelper* helper() { return &helper_; } |
| 132 | 129 |
| 133 void InitWithSyncDataTakeOutput(const syncer::SyncDataList& initial_data, | 130 void InitWithSyncDataTakeOutput(const syncer::SyncDataList& initial_data, |
| 134 syncer::SyncChangeList* output) { | 131 syncer::SyncChangeList* output) { |
| 135 syncer::SyncMergeResult result = manager_->MergeDataAndStartSyncing( | 132 syncer::SyncMergeResult result = manager_->MergeDataAndStartSyncing( |
| 136 syncer::SESSIONS, initial_data, | 133 syncer::SESSIONS, initial_data, |
| (...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 515 const sync_pb::SessionSpecifics& specifics2(data_2.GetSpecifics().session()); | 512 const sync_pb::SessionSpecifics& specifics2(data_2.GetSpecifics().session()); |
| 516 EXPECT_EQ(manager()->current_machine_tag(), specifics2.session_tag()); | 513 EXPECT_EQ(manager()->current_machine_tag(), specifics2.session_tag()); |
| 517 EXPECT_TRUE(specifics2.has_header()); | 514 EXPECT_TRUE(specifics2.has_header()); |
| 518 const sync_pb::SessionHeader& header_s2 = specifics2.header(); | 515 const sync_pb::SessionHeader& header_s2 = specifics2.header(); |
| 519 EXPECT_EQ(0, header_s2.window_size()); | 516 EXPECT_EQ(0, header_s2.window_size()); |
| 520 | 517 |
| 521 // Now take that header node and feed it in as input. | 518 // Now take that header node and feed it in as input. |
| 522 SyncData d(SyncData::CreateRemoteData(1, data.GetSpecifics(), base::Time())); | 519 SyncData d(SyncData::CreateRemoteData(1, data.GetSpecifics(), base::Time())); |
| 523 syncer::SyncDataList in(&d, &d + 1); | 520 syncer::SyncDataList in(&d, &d + 1); |
| 524 out.clear(); | 521 out.clear(); |
| 525 SessionsSyncManager manager2( | 522 SessionsSyncManager manager2(profile(), this); |
| 526 profile(), | |
| 527 scoped_ptr<SyncPrefs>(new SyncPrefs(profile()->GetPrefs())), | |
| 528 this); | |
| 529 syncer::SyncMergeResult result = manager2.MergeDataAndStartSyncing( | 523 syncer::SyncMergeResult result = manager2.MergeDataAndStartSyncing( |
| 530 syncer::SESSIONS, in, | 524 syncer::SESSIONS, in, |
| 531 scoped_ptr<syncer::SyncChangeProcessor>( | 525 scoped_ptr<syncer::SyncChangeProcessor>( |
| 532 new TestSyncProcessorStub(&out)), | 526 new TestSyncProcessorStub(&out)), |
| 533 scoped_ptr<syncer::SyncErrorFactory>( | 527 scoped_ptr<syncer::SyncErrorFactory>( |
| 534 new syncer::SyncErrorFactoryMock())); | 528 new syncer::SyncErrorFactoryMock())); |
| 535 ASSERT_FALSE(result.error().IsSet()); | 529 ASSERT_FALSE(result.error().IsSet()); |
| 536 | 530 |
| 537 EXPECT_EQ(1U, out.size()); | 531 EXPECT_EQ(1U, out.size()); |
| 538 EXPECT_EQ(SyncChange::ACTION_UPDATE, out[0].change_type()); | 532 EXPECT_EQ(SyncChange::ACTION_UPDATE, out[0].change_type()); |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 747 helper()->VerifySyncedSession(tag1, meta1_reference, *(foreign_sessions[0])); | 741 helper()->VerifySyncedSession(tag1, meta1_reference, *(foreign_sessions[0])); |
| 748 } | 742 } |
| 749 | 743 |
| 750 TEST_F(SessionsSyncManagerTest, DeleteForeignSession) { | 744 TEST_F(SessionsSyncManagerTest, DeleteForeignSession) { |
| 751 InitWithNoSyncData(); | 745 InitWithNoSyncData(); |
| 752 std::string tag = "tag1"; | 746 std::string tag = "tag1"; |
| 753 syncer::SyncChangeList changes; | 747 syncer::SyncChangeList changes; |
| 754 | 748 |
| 755 std::vector<const SyncedSession*> foreign_sessions; | 749 std::vector<const SyncedSession*> foreign_sessions; |
| 756 ASSERT_FALSE(manager()->GetAllForeignSessions(&foreign_sessions)); | 750 ASSERT_FALSE(manager()->GetAllForeignSessions(&foreign_sessions)); |
| 757 manager()->DeleteForeignSession(tag, &changes); | 751 manager()->DeleteForeignSessionInternal(tag, &changes); |
| 758 ASSERT_FALSE(manager()->GetAllForeignSessions(&foreign_sessions)); | 752 ASSERT_FALSE(manager()->GetAllForeignSessions(&foreign_sessions)); |
| 759 EXPECT_TRUE(changes.empty()); | 753 EXPECT_TRUE(changes.empty()); |
| 760 | 754 |
| 761 // Fill an instance of session specifics with a foreign session's data. | 755 // Fill an instance of session specifics with a foreign session's data. |
| 762 std::vector<sync_pb::SessionSpecifics> tabs; | 756 std::vector<sync_pb::SessionSpecifics> tabs; |
| 763 SessionID::id_type n1[] = {5, 10, 13, 17}; | 757 SessionID::id_type n1[] = {5, 10, 13, 17}; |
| 764 std::vector<SessionID::id_type> tab_nums1(n1, n1 + arraysize(n1)); | 758 std::vector<SessionID::id_type> tab_nums1(n1, n1 + arraysize(n1)); |
| 765 sync_pb::SessionSpecifics meta(helper()->BuildForeignSession( | 759 sync_pb::SessionSpecifics meta(helper()->BuildForeignSession( |
| 766 tag, tab_nums1, &tabs)); | 760 tag, tab_nums1, &tabs)); |
| 767 | 761 |
| 768 // Update associator with the session's meta node, window, and tabs. | 762 // Update associator with the session's meta node, window, and tabs. |
| 769 manager()->UpdateTrackerWithForeignSession(meta, base::Time()); | 763 manager()->UpdateTrackerWithForeignSession(meta, base::Time()); |
| 770 for (std::vector<sync_pb::SessionSpecifics>::iterator iter = tabs.begin(); | 764 for (std::vector<sync_pb::SessionSpecifics>::iterator iter = tabs.begin(); |
| 771 iter != tabs.end(); ++iter) { | 765 iter != tabs.end(); ++iter) { |
| 772 manager()->UpdateTrackerWithForeignSession(*iter, base::Time()); | 766 manager()->UpdateTrackerWithForeignSession(*iter, base::Time()); |
| 773 } | 767 } |
| 774 ASSERT_TRUE(manager()->GetAllForeignSessions(&foreign_sessions)); | 768 ASSERT_TRUE(manager()->GetAllForeignSessions(&foreign_sessions)); |
| 775 ASSERT_EQ(1U, foreign_sessions.size()); | 769 ASSERT_EQ(1U, foreign_sessions.size()); |
| 776 | 770 |
| 777 // Now delete the foreign session. | 771 // Now delete the foreign session. |
| 778 manager()->DeleteForeignSession(tag, &changes); | 772 manager()->DeleteForeignSessionInternal(tag, &changes); |
| 779 EXPECT_FALSE(manager()->GetAllForeignSessions(&foreign_sessions)); | 773 EXPECT_FALSE(manager()->GetAllForeignSessions(&foreign_sessions)); |
| 780 | 774 |
| 781 EXPECT_EQ(5U, changes.size()); | 775 EXPECT_EQ(5U, changes.size()); |
| 782 std::set<std::string> expected_tags(&tag, &tag + 1); | 776 std::set<std::string> expected_tags(&tag, &tag + 1); |
| 783 for (int i = 0; i < 5; i++) | 777 for (int i = 0; i < 5; i++) |
| 784 expected_tags.insert(TabNodePool2::TabIdToTag(tag, i)); | 778 expected_tags.insert(TabNodePool2::TabIdToTag(tag, i)); |
| 785 | 779 |
| 786 for (int i = 0; i < 5; i++) { | 780 for (int i = 0; i < 5; i++) { |
| 787 SCOPED_TRACE(changes[i].ToString()); | 781 SCOPED_TRACE(changes[i].ToString()); |
| 788 EXPECT_TRUE(changes[i].IsValid()); | 782 EXPECT_TRUE(changes[i].IsValid()); |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 911 manager()->local_tab_pool_.GetFreeTabNode(&changes); | 905 manager()->local_tab_pool_.GetFreeTabNode(&changes); |
| 912 | 906 |
| 913 // Update the tab_id of the node, so that it is considered a valid | 907 // Update the tab_id of the node, so that it is considered a valid |
| 914 // unassociated node otherwise it will be mistaken for a corrupted node and | 908 // unassociated node otherwise it will be mistaken for a corrupted node and |
| 915 // will be deleted before being added to the tab node pool. | 909 // will be deleted before being added to the tab node pool. |
| 916 sync_pb::EntitySpecifics entity(changes[0].sync_data().GetSpecifics()); | 910 sync_pb::EntitySpecifics entity(changes[0].sync_data().GetSpecifics()); |
| 917 entity.mutable_session()->mutable_tab()->set_tab_id(1); | 911 entity.mutable_session()->mutable_tab()->set_tab_id(1); |
| 918 SyncData d(SyncData::CreateRemoteData(1, entity, base::Time())); | 912 SyncData d(SyncData::CreateRemoteData(1, entity, base::Time())); |
| 919 syncer::SyncDataList in(&d, &d + 1); | 913 syncer::SyncDataList in(&d, &d + 1); |
| 920 changes.clear(); | 914 changes.clear(); |
| 921 SessionsSyncManager manager2( | 915 SessionsSyncManager manager2(profile(), this); |
| 922 profile(), | |
| 923 scoped_ptr<SyncPrefs>(new SyncPrefs(profile()->GetPrefs())), | |
| 924 this); | |
| 925 syncer::SyncMergeResult result = manager2.MergeDataAndStartSyncing( | 916 syncer::SyncMergeResult result = manager2.MergeDataAndStartSyncing( |
| 926 syncer::SESSIONS, in, | 917 syncer::SESSIONS, in, |
| 927 scoped_ptr<syncer::SyncChangeProcessor>( | 918 scoped_ptr<syncer::SyncChangeProcessor>( |
| 928 new TestSyncProcessorStub(&changes)), | 919 new TestSyncProcessorStub(&changes)), |
| 929 scoped_ptr<syncer::SyncErrorFactory>( | 920 scoped_ptr<syncer::SyncErrorFactory>( |
| 930 new syncer::SyncErrorFactoryMock())); | 921 new syncer::SyncErrorFactoryMock())); |
| 931 ASSERT_FALSE(result.error().IsSet()); | 922 ASSERT_FALSE(result.error().IsSet()); |
| 932 EXPECT_TRUE(FilterOutLocalHeaderChanges(&changes)->empty()); | 923 EXPECT_TRUE(FilterOutLocalHeaderChanges(&changes)->empty()); |
| 933 } | 924 } |
| 934 | 925 |
| (...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1178 EXPECT_TRUE(observer.notified_of_update()); | 1169 EXPECT_TRUE(observer.notified_of_update()); |
| 1179 | 1170 |
| 1180 changes.clear(); | 1171 changes.clear(); |
| 1181 observer.Reset(); | 1172 observer.Reset(); |
| 1182 changes.push_back(MakeRemoteChange(1, meta, SyncChange::ACTION_DELETE)); | 1173 changes.push_back(MakeRemoteChange(1, meta, SyncChange::ACTION_DELETE)); |
| 1183 manager()->ProcessSyncChanges(FROM_HERE, changes); | 1174 manager()->ProcessSyncChanges(FROM_HERE, changes); |
| 1184 EXPECT_TRUE(observer.notified_of_update()); | 1175 EXPECT_TRUE(observer.notified_of_update()); |
| 1185 } | 1176 } |
| 1186 | 1177 |
| 1187 } // namespace browser_sync | 1178 } // namespace browser_sync |
| OLD | NEW |