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

Side by Side Diff: chrome/browser/sync/sessions/sessions_sync_manager_unittest.cc

Issue 1310373009: [Sync] Remove static methods on SyncedWindowDelegate. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix Android compile. Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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;
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
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 scoped_ptr<SyncedWindowDelegatesGetter>(
Nicolas Zea 2015/08/31 22:12:47 I think you can just return the pointer here? Alte
maxbogue 2015/09/01 17:29:27 Done.
241 new BrowserSyncedWindowDelegatesGetter());
242 }
243
233 } // namespace 244 } // namespace
234 245
235 class SessionsSyncManagerTest 246 class SessionsSyncManagerTest
236 : public BrowserWithTestWindowTest { 247 : public BrowserWithTestWindowTest {
237 public: 248 public:
238 SessionsSyncManagerTest() 249 SessionsSyncManagerTest()
239 : test_processor_(NULL) { 250 : test_processor_(NULL) {
240 local_device_.reset(new LocalDeviceInfoProviderMock( 251 local_device_.reset(new LocalDeviceInfoProviderMock(
241 "cache_guid", 252 "cache_guid",
242 "Wayne Gretzky's Hacking Box", 253 "Wayne Gretzky's Hacking Box",
243 "Chromium 10k", 254 "Chromium 10k",
244 "Chrome 10k", 255 "Chrome 10k",
245 sync_pb::SyncEnums_DeviceType_TYPE_LINUX, 256 sync_pb::SyncEnums_DeviceType_TYPE_LINUX,
246 "device_id")); 257 "device_id"));
247 } 258 }
248 259
249 void SetUp() override { 260 void SetUp() override {
250 BrowserWithTestWindowTest::SetUp(); 261 BrowserWithTestWindowTest::SetUp();
251 browser_sync::NotificationServiceSessionsRouter* router( 262 browser_sync::NotificationServiceSessionsRouter* router(
252 new browser_sync::NotificationServiceSessionsRouter( 263 new browser_sync::NotificationServiceSessionsRouter(
253 profile(), syncer::SyncableService::StartSyncFlare())); 264 profile(), syncer::SyncableService::StartSyncFlare()));
254 manager_.reset(new SessionsSyncManager(profile(), local_device_.get(), 265 manager_.reset(new SessionsSyncManager(
255 scoped_ptr<LocalSessionEventRouter>(router))); 266 profile(), local_device_.get(),
267 scoped_ptr<LocalSessionEventRouter>(router),
268 NewBrowserWindowGetter()));
256 } 269 }
257 270
258 void TearDown() override { 271 void TearDown() override {
259 test_processor_ = NULL; 272 test_processor_ = NULL;
260 helper()->Reset(); 273 helper()->Reset();
261 manager_.reset(); 274 manager_.reset();
262 BrowserWithTestWindowTest::TearDown(); 275 BrowserWithTestWindowTest::TearDown();
263 } 276 }
264 277
265 const DeviceInfo* GetLocalDeviceInfo() { 278 const DeviceInfo* GetLocalDeviceInfo() {
(...skipping 528 matching lines...) Expand 10 before | Expand all | Expand 10 after
794 807
795 // Now take that header node and feed it in as input. 808 // Now take that header node and feed it in as input.
796 SyncData d(SyncData::CreateRemoteData( 809 SyncData d(SyncData::CreateRemoteData(
797 1, 810 1,
798 data.GetSpecifics(), 811 data.GetSpecifics(),
799 base::Time(), 812 base::Time(),
800 syncer::AttachmentIdList(), 813 syncer::AttachmentIdList(),
801 syncer::AttachmentServiceProxyForTest::Create())); 814 syncer::AttachmentServiceProxyForTest::Create()));
802 syncer::SyncDataList in(&d, &d + 1); 815 syncer::SyncDataList in(&d, &d + 1);
803 out.clear(); 816 out.clear();
804 SessionsSyncManager manager2(profile(), local_device(), NewDummyRouter()); 817 SessionsSyncManager manager2(profile(), local_device(), NewDummyRouter(),
818 NewBrowserWindowGetter());
805 syncer::SyncMergeResult result = manager2.MergeDataAndStartSyncing( 819 syncer::SyncMergeResult result = manager2.MergeDataAndStartSyncing(
806 syncer::SESSIONS, in, 820 syncer::SESSIONS, in,
807 scoped_ptr<syncer::SyncChangeProcessor>( 821 scoped_ptr<syncer::SyncChangeProcessor>(
808 new TestSyncProcessorStub(&out)), 822 new TestSyncProcessorStub(&out)),
809 scoped_ptr<syncer::SyncErrorFactory>( 823 scoped_ptr<syncer::SyncErrorFactory>(
810 new syncer::SyncErrorFactoryMock())); 824 new syncer::SyncErrorFactoryMock()));
811 ASSERT_FALSE(result.error().IsSet()); 825 ASSERT_FALSE(result.error().IsSet());
812 826
813 EXPECT_EQ(1U, out.size()); 827 EXPECT_EQ(1U, out.size());
814 EXPECT_EQ(SyncChange::ACTION_UPDATE, out[0].change_type()); 828 EXPECT_EQ(SyncChange::ACTION_UPDATE, out[0].change_type());
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
857 base::Time(), 871 base::Time(),
858 syncer::AttachmentIdList(), 872 syncer::AttachmentIdList(),
859 syncer::AttachmentServiceProxyForTest::Create())); 873 syncer::AttachmentServiceProxyForTest::Create()));
860 in.push_back(t0); 874 in.push_back(t0);
861 in.push_back(t1); 875 in.push_back(t1);
862 in.push_back(t2); 876 in.push_back(t2);
863 out.clear(); 877 out.clear();
864 manager()->StopSyncing(syncer::SESSIONS); 878 manager()->StopSyncing(syncer::SESSIONS);
865 879
866 const std::set<const SyncedWindowDelegate*>& windows = 880 const std::set<const SyncedWindowDelegate*>& windows =
867 SyncedWindowDelegate::GetAll(); 881 manager()->GetSyncedWindowDelegatesGetter()->GetSyncedWindowDelegates();
868 ASSERT_EQ(1U, windows.size()); 882 ASSERT_EQ(1U, windows.size());
869 SyncedTabDelegateFake t1_override, t2_override; 883 SyncedTabDelegateFake t1_override, t2_override;
870 t1_override.SetSyncId(1); // No WebContents by default. 884 t1_override.SetSyncId(1); // No WebContents by default.
871 t2_override.SetSyncId(2); // No WebContents by default. 885 t2_override.SetSyncId(2); // No WebContents by default.
872 SyncedWindowDelegateOverride window_override(*windows.begin()); 886 SyncedWindowDelegateOverride window_override(*windows.begin());
873 window_override.OverrideTabAt(1, &t1_override, kNewTabId); 887 window_override.OverrideTabAt(1, &t1_override, kNewTabId);
874 window_override.OverrideTabAt(2, &t2_override, 888 window_override.OverrideTabAt(2, &t2_override,
875 t2.GetSpecifics().session().tab().tab_id()); 889 t2.GetSpecifics().session().tab().tab_id());
876 std::set<const SyncedWindowDelegate*> delegates; 890 std::set<const SyncedWindowDelegate*> delegates;
877 delegates.insert(&window_override); 891 delegates.insert(&window_override);
(...skipping 505 matching lines...) Expand 10 before | Expand all | Expand 10 after
1383 sync_pb::EntitySpecifics entity(changes[0].sync_data().GetSpecifics()); 1397 sync_pb::EntitySpecifics entity(changes[0].sync_data().GetSpecifics());
1384 entity.mutable_session()->mutable_tab()->set_tab_id(1); 1398 entity.mutable_session()->mutable_tab()->set_tab_id(1);
1385 SyncData d(SyncData::CreateRemoteData( 1399 SyncData d(SyncData::CreateRemoteData(
1386 1, 1400 1,
1387 entity, 1401 entity,
1388 base::Time(), 1402 base::Time(),
1389 syncer::AttachmentIdList(), 1403 syncer::AttachmentIdList(),
1390 syncer::AttachmentServiceProxyForTest::Create())); 1404 syncer::AttachmentServiceProxyForTest::Create()));
1391 syncer::SyncDataList in(&d, &d + 1); 1405 syncer::SyncDataList in(&d, &d + 1);
1392 changes.clear(); 1406 changes.clear();
1393 SessionsSyncManager manager2(profile(), local_device(), NewDummyRouter()); 1407 SessionsSyncManager manager2(profile(), local_device(), NewDummyRouter(),
1408 NewBrowserWindowGetter());
1394 syncer::SyncMergeResult result = manager2.MergeDataAndStartSyncing( 1409 syncer::SyncMergeResult result = manager2.MergeDataAndStartSyncing(
1395 syncer::SESSIONS, in, 1410 syncer::SESSIONS, in,
1396 scoped_ptr<syncer::SyncChangeProcessor>( 1411 scoped_ptr<syncer::SyncChangeProcessor>(
1397 new TestSyncProcessorStub(&changes)), 1412 new TestSyncProcessorStub(&changes)),
1398 scoped_ptr<syncer::SyncErrorFactory>( 1413 scoped_ptr<syncer::SyncErrorFactory>(
1399 new syncer::SyncErrorFactoryMock())); 1414 new syncer::SyncErrorFactoryMock()));
1400 ASSERT_FALSE(result.error().IsSet()); 1415 ASSERT_FALSE(result.error().IsSet());
1401 EXPECT_TRUE(FilterOutLocalHeaderChanges(&changes)->empty()); 1416 EXPECT_TRUE(FilterOutLocalHeaderChanges(&changes)->empty());
1402 } 1417 }
1403 1418
(...skipping 786 matching lines...) Expand 10 before | Expand all | Expand 10 after
2190 base::Time last_time; 2205 base::Time last_time;
2191 for (size_t i = 0; i < tabs.size(); ++i) { 2206 for (size_t i = 0; i < tabs.size(); ++i) {
2192 base::Time this_time = tabs[i]->timestamp; 2207 base::Time this_time = tabs[i]->timestamp;
2193 if (i > 0) 2208 if (i > 0)
2194 ASSERT_GE(last_time, this_time); 2209 ASSERT_GE(last_time, this_time);
2195 last_time = tabs[i]->timestamp; 2210 last_time = tabs[i]->timestamp;
2196 } 2211 }
2197 } 2212 }
2198 2213
2199 } // namespace browser_sync 2214 } // namespace browser_sync
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698