Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/sessions/sessions_sync_manager.h" | 5 #include "chrome/browser/sync/sessions/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_tab_helper.h" | 9 #include "chrome/browser/sessions/session_tab_helper.h" |
| 10 #include "chrome/browser/sync/glue/session_sync_test_helper.h" | 10 #include "chrome/browser/sync/glue/session_sync_test_helper.h" |
| 11 #include "chrome/browser/sync/glue/synced_tab_delegate.h" | 11 #include "chrome/browser/sync/glue/synced_tab_delegate.h" |
| 12 #include "chrome/browser/sync/glue/synced_window_delegate.h" | 12 #include "chrome/browser/sync/glue/synced_window_delegate.h" |
| 13 #include "chrome/browser/sync/sessions/notification_service_sessions_router.h" | 13 #include "chrome/browser/sync/sessions/notification_service_sessions_router.h" |
| 14 #include "chrome/browser/sync/sessions/synced_window_delegates_getter.h" | 14 #include "chrome/browser/sync/sessions/synced_window_delegates_getter.h" |
| 15 #include "chrome/browser/ui/sync/browser_synced_window_delegates_getter.h" | |
| 15 #include "chrome/browser/ui/sync/tab_contents_synced_tab_delegate.h" | 16 #include "chrome/browser/ui/sync/tab_contents_synced_tab_delegate.h" |
| 16 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 17 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 17 #include "chrome/test/base/browser_with_test_window_test.h" | 18 #include "chrome/test/base/browser_with_test_window_test.h" |
| 18 #include "components/sessions/serialized_navigation_entry_test_helper.h" | 19 #include "components/sessions/serialized_navigation_entry_test_helper.h" |
| 19 #include "components/sessions/session_id.h" | 20 #include "components/sessions/session_id.h" |
| 20 #include "components/sessions/session_types.h" | 21 #include "components/sessions/session_types.h" |
| 21 #include "components/sync_driver/device_info.h" | 22 #include "components/sync_driver/device_info.h" |
| 22 #include "components/sync_driver/local_device_info_provider_mock.h" | 23 #include "components/sync_driver/local_device_info_provider_mock.h" |
| 23 #include "content/public/browser/navigation_entry.h" | 24 #include "content/public/browser/navigation_entry.h" |
| 24 #include "content/public/browser/notification_details.h" | 25 #include "content/public/browser/notification_details.h" |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 106 | 107 |
| 107 class TestSyncedWindowDelegatesGetter : public SyncedWindowDelegatesGetter { | 108 class TestSyncedWindowDelegatesGetter : public SyncedWindowDelegatesGetter { |
| 108 public: | 109 public: |
| 109 TestSyncedWindowDelegatesGetter( | 110 TestSyncedWindowDelegatesGetter( |
| 110 const std::set<const SyncedWindowDelegate*>& delegates) | 111 const std::set<const SyncedWindowDelegate*>& delegates) |
| 111 : delegates_(delegates) {} | 112 : delegates_(delegates) {} |
| 112 | 113 |
| 113 std::set<const SyncedWindowDelegate*> GetSyncedWindowDelegates() override { | 114 std::set<const SyncedWindowDelegate*> GetSyncedWindowDelegates() override { |
| 114 return delegates_; | 115 return delegates_; |
| 115 } | 116 } |
| 117 | |
| 118 const SyncedWindowDelegate* FindById(SessionID::id_type id) override { | |
| 119 return NULL; | |
|
Nicolas Zea
2015/09/02 21:19:44
nit: nullptr here too
maxbogue
2015/09/02 23:05:40
Done.
| |
| 120 } | |
| 121 | |
| 116 private: | 122 private: |
| 117 const std::set<const SyncedWindowDelegate*> delegates_; | 123 const std::set<const SyncedWindowDelegate*> delegates_; |
| 118 }; | 124 }; |
| 119 | 125 |
| 120 class TestSyncProcessorStub : public syncer::SyncChangeProcessor { | 126 class TestSyncProcessorStub : public syncer::SyncChangeProcessor { |
| 121 public: | 127 public: |
| 122 explicit TestSyncProcessorStub(syncer::SyncChangeList* output) | 128 explicit TestSyncProcessorStub(syncer::SyncChangeList* output) |
| 123 : output_(output) {} | 129 : output_(output) {} |
| 124 syncer::SyncError ProcessSyncChanges( | 130 syncer::SyncError ProcessSyncChanges( |
| 125 const tracked_objects::Location& from_here, | 131 const tracked_objects::Location& from_here, |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 223 public: | 229 public: |
| 224 ~DummyRouter() override {} | 230 ~DummyRouter() override {} |
| 225 void StartRoutingTo(LocalSessionEventHandler* handler) override {} | 231 void StartRoutingTo(LocalSessionEventHandler* handler) override {} |
| 226 void Stop() override {} | 232 void Stop() override {} |
| 227 }; | 233 }; |
| 228 | 234 |
| 229 scoped_ptr<LocalSessionEventRouter> NewDummyRouter() { | 235 scoped_ptr<LocalSessionEventRouter> NewDummyRouter() { |
| 230 return scoped_ptr<LocalSessionEventRouter>(new DummyRouter()); | 236 return scoped_ptr<LocalSessionEventRouter>(new DummyRouter()); |
| 231 } | 237 } |
| 232 | 238 |
| 239 scoped_ptr<SyncedWindowDelegatesGetter> NewBrowserWindowGetter() { | |
| 240 return make_scoped_ptr(new BrowserSyncedWindowDelegatesGetter()); | |
| 241 } | |
| 242 | |
| 233 } // namespace | 243 } // namespace |
| 234 | 244 |
| 235 class SessionsSyncManagerTest | 245 class SessionsSyncManagerTest |
| 236 : public BrowserWithTestWindowTest { | 246 : public BrowserWithTestWindowTest { |
| 237 public: | 247 public: |
| 238 SessionsSyncManagerTest() | 248 SessionsSyncManagerTest() |
| 239 : test_processor_(NULL) { | 249 : test_processor_(NULL) { |
| 240 local_device_.reset(new LocalDeviceInfoProviderMock( | 250 local_device_.reset(new LocalDeviceInfoProviderMock( |
| 241 "cache_guid", | 251 "cache_guid", |
| 242 "Wayne Gretzky's Hacking Box", | 252 "Wayne Gretzky's Hacking Box", |
| 243 "Chromium 10k", | 253 "Chromium 10k", |
| 244 "Chrome 10k", | 254 "Chrome 10k", |
| 245 sync_pb::SyncEnums_DeviceType_TYPE_LINUX, | 255 sync_pb::SyncEnums_DeviceType_TYPE_LINUX, |
| 246 "device_id")); | 256 "device_id")); |
| 247 } | 257 } |
| 248 | 258 |
| 249 void SetUp() override { | 259 void SetUp() override { |
| 250 BrowserWithTestWindowTest::SetUp(); | 260 BrowserWithTestWindowTest::SetUp(); |
| 251 browser_sync::NotificationServiceSessionsRouter* router( | 261 browser_sync::NotificationServiceSessionsRouter* router( |
| 252 new browser_sync::NotificationServiceSessionsRouter( | 262 new browser_sync::NotificationServiceSessionsRouter( |
| 253 profile(), syncer::SyncableService::StartSyncFlare())); | 263 profile(), syncer::SyncableService::StartSyncFlare())); |
| 254 manager_.reset(new SessionsSyncManager(profile(), local_device_.get(), | 264 manager_.reset(new SessionsSyncManager( |
| 255 scoped_ptr<LocalSessionEventRouter>(router))); | 265 profile(), local_device_.get(), |
| 266 scoped_ptr<LocalSessionEventRouter>(router), | |
| 267 NewBrowserWindowGetter())); | |
| 256 } | 268 } |
| 257 | 269 |
| 258 void TearDown() override { | 270 void TearDown() override { |
| 259 test_processor_ = NULL; | 271 test_processor_ = NULL; |
| 260 helper()->Reset(); | 272 helper()->Reset(); |
| 261 manager_.reset(); | 273 manager_.reset(); |
| 262 BrowserWithTestWindowTest::TearDown(); | 274 BrowserWithTestWindowTest::TearDown(); |
| 263 } | 275 } |
| 264 | 276 |
| 265 const DeviceInfo* GetLocalDeviceInfo() { | 277 const DeviceInfo* GetLocalDeviceInfo() { |
| (...skipping 528 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 794 | 806 |
| 795 // Now take that header node and feed it in as input. | 807 // Now take that header node and feed it in as input. |
| 796 SyncData d(SyncData::CreateRemoteData( | 808 SyncData d(SyncData::CreateRemoteData( |
| 797 1, | 809 1, |
| 798 data.GetSpecifics(), | 810 data.GetSpecifics(), |
| 799 base::Time(), | 811 base::Time(), |
| 800 syncer::AttachmentIdList(), | 812 syncer::AttachmentIdList(), |
| 801 syncer::AttachmentServiceProxyForTest::Create())); | 813 syncer::AttachmentServiceProxyForTest::Create())); |
| 802 syncer::SyncDataList in(&d, &d + 1); | 814 syncer::SyncDataList in(&d, &d + 1); |
| 803 out.clear(); | 815 out.clear(); |
| 804 SessionsSyncManager manager2(profile(), local_device(), NewDummyRouter()); | 816 SessionsSyncManager manager2(profile(), local_device(), NewDummyRouter(), |
| 817 NewBrowserWindowGetter()); | |
| 805 syncer::SyncMergeResult result = manager2.MergeDataAndStartSyncing( | 818 syncer::SyncMergeResult result = manager2.MergeDataAndStartSyncing( |
| 806 syncer::SESSIONS, in, | 819 syncer::SESSIONS, in, |
| 807 scoped_ptr<syncer::SyncChangeProcessor>( | 820 scoped_ptr<syncer::SyncChangeProcessor>( |
| 808 new TestSyncProcessorStub(&out)), | 821 new TestSyncProcessorStub(&out)), |
| 809 scoped_ptr<syncer::SyncErrorFactory>( | 822 scoped_ptr<syncer::SyncErrorFactory>( |
| 810 new syncer::SyncErrorFactoryMock())); | 823 new syncer::SyncErrorFactoryMock())); |
| 811 ASSERT_FALSE(result.error().IsSet()); | 824 ASSERT_FALSE(result.error().IsSet()); |
| 812 | 825 |
| 813 EXPECT_EQ(1U, out.size()); | 826 EXPECT_EQ(1U, out.size()); |
| 814 EXPECT_EQ(SyncChange::ACTION_UPDATE, out[0].change_type()); | 827 EXPECT_EQ(SyncChange::ACTION_UPDATE, out[0].change_type()); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 857 base::Time(), | 870 base::Time(), |
| 858 syncer::AttachmentIdList(), | 871 syncer::AttachmentIdList(), |
| 859 syncer::AttachmentServiceProxyForTest::Create())); | 872 syncer::AttachmentServiceProxyForTest::Create())); |
| 860 in.push_back(t0); | 873 in.push_back(t0); |
| 861 in.push_back(t1); | 874 in.push_back(t1); |
| 862 in.push_back(t2); | 875 in.push_back(t2); |
| 863 out.clear(); | 876 out.clear(); |
| 864 manager()->StopSyncing(syncer::SESSIONS); | 877 manager()->StopSyncing(syncer::SESSIONS); |
| 865 | 878 |
| 866 const std::set<const SyncedWindowDelegate*>& windows = | 879 const std::set<const SyncedWindowDelegate*>& windows = |
| 867 SyncedWindowDelegate::GetAll(); | 880 manager()->GetSyncedWindowDelegatesGetter()->GetSyncedWindowDelegates(); |
| 868 ASSERT_EQ(1U, windows.size()); | 881 ASSERT_EQ(1U, windows.size()); |
| 869 SyncedTabDelegateFake t1_override, t2_override; | 882 SyncedTabDelegateFake t1_override, t2_override; |
| 870 t1_override.SetSyncId(1); // No WebContents by default. | 883 t1_override.SetSyncId(1); // No WebContents by default. |
| 871 t2_override.SetSyncId(2); // No WebContents by default. | 884 t2_override.SetSyncId(2); // No WebContents by default. |
| 872 SyncedWindowDelegateOverride window_override(*windows.begin()); | 885 SyncedWindowDelegateOverride window_override(*windows.begin()); |
| 873 window_override.OverrideTabAt(1, &t1_override, kNewTabId); | 886 window_override.OverrideTabAt(1, &t1_override, kNewTabId); |
| 874 window_override.OverrideTabAt(2, &t2_override, | 887 window_override.OverrideTabAt(2, &t2_override, |
| 875 t2.GetSpecifics().session().tab().tab_id()); | 888 t2.GetSpecifics().session().tab().tab_id()); |
| 876 std::set<const SyncedWindowDelegate*> delegates; | 889 std::set<const SyncedWindowDelegate*> delegates; |
| 877 delegates.insert(&window_override); | 890 delegates.insert(&window_override); |
| (...skipping 505 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1383 sync_pb::EntitySpecifics entity(changes[0].sync_data().GetSpecifics()); | 1396 sync_pb::EntitySpecifics entity(changes[0].sync_data().GetSpecifics()); |
| 1384 entity.mutable_session()->mutable_tab()->set_tab_id(1); | 1397 entity.mutable_session()->mutable_tab()->set_tab_id(1); |
| 1385 SyncData d(SyncData::CreateRemoteData( | 1398 SyncData d(SyncData::CreateRemoteData( |
| 1386 1, | 1399 1, |
| 1387 entity, | 1400 entity, |
| 1388 base::Time(), | 1401 base::Time(), |
| 1389 syncer::AttachmentIdList(), | 1402 syncer::AttachmentIdList(), |
| 1390 syncer::AttachmentServiceProxyForTest::Create())); | 1403 syncer::AttachmentServiceProxyForTest::Create())); |
| 1391 syncer::SyncDataList in(&d, &d + 1); | 1404 syncer::SyncDataList in(&d, &d + 1); |
| 1392 changes.clear(); | 1405 changes.clear(); |
| 1393 SessionsSyncManager manager2(profile(), local_device(), NewDummyRouter()); | 1406 SessionsSyncManager manager2(profile(), local_device(), NewDummyRouter(), |
| 1407 NewBrowserWindowGetter()); | |
| 1394 syncer::SyncMergeResult result = manager2.MergeDataAndStartSyncing( | 1408 syncer::SyncMergeResult result = manager2.MergeDataAndStartSyncing( |
| 1395 syncer::SESSIONS, in, | 1409 syncer::SESSIONS, in, |
| 1396 scoped_ptr<syncer::SyncChangeProcessor>( | 1410 scoped_ptr<syncer::SyncChangeProcessor>( |
| 1397 new TestSyncProcessorStub(&changes)), | 1411 new TestSyncProcessorStub(&changes)), |
| 1398 scoped_ptr<syncer::SyncErrorFactory>( | 1412 scoped_ptr<syncer::SyncErrorFactory>( |
| 1399 new syncer::SyncErrorFactoryMock())); | 1413 new syncer::SyncErrorFactoryMock())); |
| 1400 ASSERT_FALSE(result.error().IsSet()); | 1414 ASSERT_FALSE(result.error().IsSet()); |
| 1401 EXPECT_TRUE(FilterOutLocalHeaderChanges(&changes)->empty()); | 1415 EXPECT_TRUE(FilterOutLocalHeaderChanges(&changes)->empty()); |
| 1402 } | 1416 } |
| 1403 | 1417 |
| (...skipping 786 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2190 base::Time last_time; | 2204 base::Time last_time; |
| 2191 for (size_t i = 0; i < tabs.size(); ++i) { | 2205 for (size_t i = 0; i < tabs.size(); ++i) { |
| 2192 base::Time this_time = tabs[i]->timestamp; | 2206 base::Time this_time = tabs[i]->timestamp; |
| 2193 if (i > 0) | 2207 if (i > 0) |
| 2194 ASSERT_GE(last_time, this_time); | 2208 ASSERT_GE(last_time, this_time); |
| 2195 last_time = tabs[i]->timestamp; | 2209 last_time = tabs[i]->timestamp; |
| 2196 } | 2210 } |
| 2197 } | 2211 } |
| 2198 | 2212 |
| 2199 } // namespace browser_sync | 2213 } // namespace browser_sync |
| OLD | NEW |