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

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

Issue 401433003: Revert of Sync: Refactoring of DEVICE_INFO syncable type - Part 1 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 5 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_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/local_device_info_provider_mock.h"
14 #include "chrome/browser/sync/glue/session_sync_test_helper.h" 13 #include "chrome/browser/sync/glue/session_sync_test_helper.h"
15 #include "chrome/browser/sync/glue/synced_tab_delegate.h" 14 #include "chrome/browser/sync/glue/synced_tab_delegate.h"
16 #include "chrome/browser/sync/glue/synced_window_delegate.h" 15 #include "chrome/browser/sync/glue/synced_window_delegate.h"
17 #include "chrome/browser/sync/sessions/notification_service_sessions_router.h" 16 #include "chrome/browser/sync/sessions/notification_service_sessions_router.h"
18 #include "chrome/browser/sync/sessions/sessions_util.h" 17 #include "chrome/browser/sync/sessions/sessions_util.h"
19 #include "chrome/browser/sync/sessions/synced_window_delegates_getter.h" 18 #include "chrome/browser/sync/sessions/synced_window_delegates_getter.h"
20 #include "chrome/browser/ui/sync/tab_contents_synced_tab_delegate.h" 19 #include "chrome/browser/ui/sync/tab_contents_synced_tab_delegate.h"
21 #include "chrome/browser/ui/tabs/tab_strip_model.h" 20 #include "chrome/browser/ui/tabs/tab_strip_model.h"
22 #include "chrome/test/base/browser_with_test_window_test.h" 21 #include "chrome/test/base/browser_with_test_window_test.h"
23 #include "components/sessions/serialized_navigation_entry_test_helper.h" 22 #include "components/sessions/serialized_navigation_entry_test_helper.h"
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 virtual void Stop() OVERRIDE {} 221 virtual void Stop() OVERRIDE {}
223 }; 222 };
224 223
225 scoped_ptr<LocalSessionEventRouter> NewDummyRouter() { 224 scoped_ptr<LocalSessionEventRouter> NewDummyRouter() {
226 return scoped_ptr<LocalSessionEventRouter>(new DummyRouter()); 225 return scoped_ptr<LocalSessionEventRouter>(new DummyRouter());
227 } 226 }
228 227
229 } // namespace 228 } // namespace
230 229
231 class SessionsSyncManagerTest 230 class SessionsSyncManagerTest
232 : public BrowserWithTestWindowTest { 231 : public BrowserWithTestWindowTest,
232 public SessionsSyncManager::SyncInternalApiDelegate {
233 public: 233 public:
234 SessionsSyncManagerTest() 234 SessionsSyncManagerTest() : test_processor_(NULL) {}
235 : test_processor_(NULL) {
236 local_device_.reset(new LocalDeviceInfoProviderMock(
237 "cache_guid",
238 "Wayne Gretzky's Hacking Box",
239 "Chromium 10k",
240 "Chrome 10k",
241 sync_pb::SyncEnums_DeviceType_TYPE_LINUX));
242 }
243 235
244 virtual void SetUp() OVERRIDE { 236 virtual void SetUp() OVERRIDE {
245 BrowserWithTestWindowTest::SetUp(); 237 BrowserWithTestWindowTest::SetUp();
246 browser_sync::NotificationServiceSessionsRouter* router( 238 browser_sync::NotificationServiceSessionsRouter* router(
247 new browser_sync::NotificationServiceSessionsRouter( 239 new browser_sync::NotificationServiceSessionsRouter(
248 profile(), syncer::SyncableService::StartSyncFlare())); 240 profile(), syncer::SyncableService::StartSyncFlare()));
249 manager_.reset(new SessionsSyncManager(profile(), local_device_.get(), 241 manager_.reset(new SessionsSyncManager(profile(), this,
250 scoped_ptr<LocalSessionEventRouter>(router))); 242 scoped_ptr<LocalSessionEventRouter>(router)));
251 } 243 }
252 244
253 virtual void TearDown() OVERRIDE { 245 virtual void TearDown() OVERRIDE {
254 test_processor_ = NULL; 246 test_processor_ = NULL;
255 helper()->Reset(); 247 helper()->Reset();
256 manager_.reset(); 248 manager_.reset();
257 BrowserWithTestWindowTest::TearDown(); 249 BrowserWithTestWindowTest::TearDown();
258 } 250 }
259 251
260 const DeviceInfo* GetLocalDeviceInfo() { 252 virtual scoped_ptr<DeviceInfo> GetLocalDeviceInfo() const OVERRIDE {
261 return local_device_->GetLocalDeviceInfo(); 253 return scoped_ptr<DeviceInfo>(
254 new DeviceInfo(GetLocalSyncCacheGUID(),
255 "Wayne Gretzky's Hacking Box",
256 "Chromium 10k",
257 "Chrome 10k",
258 sync_pb::SyncEnums_DeviceType_TYPE_LINUX));
259 }
260
261 virtual std::string GetLocalSyncCacheGUID() const OVERRIDE {
262 return "cache_guid";
262 } 263 }
263 264
264 SessionsSyncManager* manager() { return manager_.get(); } 265 SessionsSyncManager* manager() { return manager_.get(); }
265 SessionSyncTestHelper* helper() { return &helper_; } 266 SessionSyncTestHelper* helper() { return &helper_; }
266 LocalDeviceInfoProvider* local_device() { return local_device_.get(); }
267 267
268 void InitWithSyncDataTakeOutput(const syncer::SyncDataList& initial_data, 268 void InitWithSyncDataTakeOutput(const syncer::SyncDataList& initial_data,
269 syncer::SyncChangeList* output) { 269 syncer::SyncChangeList* output) {
270 test_processor_ = new TestSyncProcessorStub(output); 270 test_processor_ = new TestSyncProcessorStub(output);
271 syncer::SyncMergeResult result = manager_->MergeDataAndStartSyncing( 271 syncer::SyncMergeResult result = manager_->MergeDataAndStartSyncing(
272 syncer::SESSIONS, initial_data, 272 syncer::SESSIONS, initial_data,
273 scoped_ptr<syncer::SyncChangeProcessor>(test_processor_), 273 scoped_ptr<syncer::SyncChangeProcessor>(test_processor_),
274 scoped_ptr<syncer::SyncErrorFactory>( 274 scoped_ptr<syncer::SyncErrorFactory>(
275 new syncer::SyncErrorFactoryMock())); 275 new syncer::SyncErrorFactoryMock()));
276 EXPECT_FALSE(result.error().IsSet()); 276 EXPECT_FALSE(result.error().IsSet());
(...skipping 29 matching lines...) Expand all
306 } 306 }
307 } 307 }
308 EXPECT_TRUE(found); 308 EXPECT_TRUE(found);
309 return list; 309 return list;
310 } 310 }
311 311
312 private: 312 private:
313 scoped_ptr<SessionsSyncManager> manager_; 313 scoped_ptr<SessionsSyncManager> manager_;
314 SessionSyncTestHelper helper_; 314 SessionSyncTestHelper helper_;
315 TestSyncProcessorStub* test_processor_; 315 TestSyncProcessorStub* test_processor_;
316 scoped_ptr<LocalDeviceInfoProviderMock> local_device_;
317 }; 316 };
318 317
319 // Test that the SyncSessionManager can properly fill in a SessionHeader. 318 // Test that the SyncSessionManager can properly fill in a SessionHeader.
320 TEST_F(SessionsSyncManagerTest, PopulateSessionHeader) { 319 TEST_F(SessionsSyncManagerTest, PopulateSessionHeader) {
321 sync_pb::SessionHeader header_s; 320 sync_pb::SessionHeader header_s;
322 header_s.set_client_name("Client 1"); 321 header_s.set_client_name("Client 1");
323 header_s.set_device_type(sync_pb::SyncEnums_DeviceType_TYPE_WIN); 322 header_s.set_device_type(sync_pb::SyncEnums_DeviceType_TYPE_WIN);
324 323
325 SyncedSession session; 324 SyncedSession session;
326 base::Time time = base::Time::Now(); 325 base::Time time = base::Time::Now();
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after
679 678
680 // Now take that header node and feed it in as input. 679 // Now take that header node and feed it in as input.
681 SyncData d(SyncData::CreateRemoteData( 680 SyncData d(SyncData::CreateRemoteData(
682 1, 681 1,
683 data.GetSpecifics(), 682 data.GetSpecifics(),
684 base::Time(), 683 base::Time(),
685 syncer::AttachmentIdList(), 684 syncer::AttachmentIdList(),
686 syncer::AttachmentServiceProxyForTest::Create())); 685 syncer::AttachmentServiceProxyForTest::Create()));
687 syncer::SyncDataList in(&d, &d + 1); 686 syncer::SyncDataList in(&d, &d + 1);
688 out.clear(); 687 out.clear();
689 SessionsSyncManager manager2(profile(), local_device(), NewDummyRouter()); 688 SessionsSyncManager manager2(profile(), this, NewDummyRouter());
690 syncer::SyncMergeResult result = manager2.MergeDataAndStartSyncing( 689 syncer::SyncMergeResult result = manager2.MergeDataAndStartSyncing(
691 syncer::SESSIONS, in, 690 syncer::SESSIONS, in,
692 scoped_ptr<syncer::SyncChangeProcessor>( 691 scoped_ptr<syncer::SyncChangeProcessor>(
693 new TestSyncProcessorStub(&out)), 692 new TestSyncProcessorStub(&out)),
694 scoped_ptr<syncer::SyncErrorFactory>( 693 scoped_ptr<syncer::SyncErrorFactory>(
695 new syncer::SyncErrorFactoryMock())); 694 new syncer::SyncErrorFactoryMock()));
696 ASSERT_FALSE(result.error().IsSet()); 695 ASSERT_FALSE(result.error().IsSet());
697 696
698 EXPECT_EQ(1U, out.size()); 697 EXPECT_EQ(1U, out.size());
699 EXPECT_EQ(SyncChange::ACTION_UPDATE, out[0].change_type()); 698 EXPECT_EQ(SyncChange::ACTION_UPDATE, out[0].change_type());
(...skipping 567 matching lines...) Expand 10 before | Expand all | Expand 10 after
1267 sync_pb::EntitySpecifics entity(changes[0].sync_data().GetSpecifics()); 1266 sync_pb::EntitySpecifics entity(changes[0].sync_data().GetSpecifics());
1268 entity.mutable_session()->mutable_tab()->set_tab_id(1); 1267 entity.mutable_session()->mutable_tab()->set_tab_id(1);
1269 SyncData d(SyncData::CreateRemoteData( 1268 SyncData d(SyncData::CreateRemoteData(
1270 1, 1269 1,
1271 entity, 1270 entity,
1272 base::Time(), 1271 base::Time(),
1273 syncer::AttachmentIdList(), 1272 syncer::AttachmentIdList(),
1274 syncer::AttachmentServiceProxyForTest::Create())); 1273 syncer::AttachmentServiceProxyForTest::Create()));
1275 syncer::SyncDataList in(&d, &d + 1); 1274 syncer::SyncDataList in(&d, &d + 1);
1276 changes.clear(); 1275 changes.clear();
1277 SessionsSyncManager manager2(profile(), local_device(), NewDummyRouter()); 1276 SessionsSyncManager manager2(profile(), this, NewDummyRouter());
1278 syncer::SyncMergeResult result = manager2.MergeDataAndStartSyncing( 1277 syncer::SyncMergeResult result = manager2.MergeDataAndStartSyncing(
1279 syncer::SESSIONS, in, 1278 syncer::SESSIONS, in,
1280 scoped_ptr<syncer::SyncChangeProcessor>( 1279 scoped_ptr<syncer::SyncChangeProcessor>(
1281 new TestSyncProcessorStub(&changes)), 1280 new TestSyncProcessorStub(&changes)),
1282 scoped_ptr<syncer::SyncErrorFactory>( 1281 scoped_ptr<syncer::SyncErrorFactory>(
1283 new syncer::SyncErrorFactoryMock())); 1282 new syncer::SyncErrorFactoryMock()));
1284 ASSERT_FALSE(result.error().IsSet()); 1283 ASSERT_FALSE(result.error().IsSet());
1285 EXPECT_TRUE(FilterOutLocalHeaderChanges(&changes)->empty()); 1284 EXPECT_TRUE(FilterOutLocalHeaderChanges(&changes)->empty());
1286 } 1285 }
1287 1286
(...skipping 526 matching lines...) Expand 10 before | Expand all | Expand 10 after
1814 ASSERT_FALSE(observer.notified_of_refresh()); 1813 ASSERT_FALSE(observer.notified_of_refresh());
1815 InitWithNoSyncData(); 1814 InitWithNoSyncData();
1816 AddTab(browser(), GURL("http://foo1")); 1815 AddTab(browser(), GURL("http://foo1"));
1817 EXPECT_FALSE(observer.notified_of_refresh()); 1816 EXPECT_FALSE(observer.notified_of_refresh());
1818 NavigateAndCommitActiveTab(GURL("chrome://newtab/#open_tabs")); 1817 NavigateAndCommitActiveTab(GURL("chrome://newtab/#open_tabs"));
1819 EXPECT_TRUE(observer.notified_of_refresh()); 1818 EXPECT_TRUE(observer.notified_of_refresh());
1820 } 1819 }
1821 #endif // defined(OS_ANDROID) || defined(OS_IOS) 1820 #endif // defined(OS_ANDROID) || defined(OS_IOS)
1822 1821
1823 } // namespace browser_sync 1822 } // namespace browser_sync
OLDNEW
« no previous file with comments | « chrome/browser/sync/sessions/sessions_sync_manager.cc ('k') | chrome/browser/sync/test_profile_sync_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698