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 "components/sync_sessions/sessions_sync_manager.h" | 5 #include "components/sync_sessions/sessions_sync_manager.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 int http_count = 0; | 204 int http_count = 0; |
205 for (auto& entry : entries_) { | 205 for (auto& entry : entries_) { |
206 if (!entry->virtual_url().is_valid()) | 206 if (!entry->virtual_url().is_valid()) |
207 return false; | 207 return false; |
208 if (entry->virtual_url().SchemeIsHTTPOrHTTPS()) | 208 if (entry->virtual_url().SchemeIsHTTPOrHTTPS()) |
209 http_count++; | 209 http_count++; |
210 } | 210 } |
211 return http_count > 0; | 211 return http_count > 0; |
212 } | 212 } |
213 | 213 |
| 214 SessionID::id_type GetSourceTabID() const override { return kInvalidTabID; } |
| 215 |
214 void AppendEntry(std::unique_ptr<sessions::SerializedNavigationEntry> entry) { | 216 void AppendEntry(std::unique_ptr<sessions::SerializedNavigationEntry> entry) { |
215 entries_.push_back(std::move(entry)); | 217 entries_.push_back(std::move(entry)); |
216 } | 218 } |
217 | 219 |
218 void set_current_entry_index(int i) { current_entry_index_ = i; } | 220 void set_current_entry_index(int i) { current_entry_index_ = i; } |
219 | 221 |
220 void SetWindowId(SessionID::id_type window_id) { | 222 void SetWindowId(SessionID::id_type window_id) { |
221 window_id_.set_id(window_id); | 223 window_id_.set_id(window_id); |
222 } | 224 } |
223 | 225 |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
315 const std::vector<std::unique_ptr<const sessions::SerializedNavigationEntry>>* | 317 const std::vector<std::unique_ptr<const sessions::SerializedNavigationEntry>>* |
316 GetBlockedNavigations() const override { | 318 GetBlockedNavigations() const override { |
317 NOTREACHED(); | 319 NOTREACHED(); |
318 return nullptr; | 320 return nullptr; |
319 } | 321 } |
320 bool ShouldSync(SyncSessionsClient* sessions_client) override { | 322 bool ShouldSync(SyncSessionsClient* sessions_client) override { |
321 NOTREACHED(); | 323 NOTREACHED(); |
322 return false; | 324 return false; |
323 } | 325 } |
324 | 326 |
| 327 SessionID::id_type GetSourceTabID() const override { return kInvalidTabID; } |
| 328 |
325 private: | 329 private: |
326 SessionID::id_type session_id_; | 330 SessionID::id_type session_id_; |
327 int sync_id_; | 331 int sync_id_; |
328 }; | 332 }; |
329 | 333 |
330 class TestSyncedWindowDelegate : public SyncedWindowDelegate { | 334 class TestSyncedWindowDelegate : public SyncedWindowDelegate { |
331 public: | 335 public: |
332 TestSyncedWindowDelegate() {} | 336 TestSyncedWindowDelegate() {} |
333 ~TestSyncedWindowDelegate() override {} | 337 ~TestSyncedWindowDelegate() override {} |
334 | 338 |
(...skipping 28 matching lines...) Expand all Loading... |
363 | 367 |
364 void OverrideWindowId(SessionID::id_type id) { window_id_.set_id(id); } | 368 void OverrideWindowId(SessionID::id_type id) { window_id_.set_id(id); } |
365 | 369 |
366 void OverrideTabAt(int index, SyncedTabDelegate* delegate) { | 370 void OverrideTabAt(int index, SyncedTabDelegate* delegate) { |
367 tab_delegates_[index] = delegate; | 371 tab_delegates_[index] = delegate; |
368 } | 372 } |
369 | 373 |
370 SessionID::id_type GetTabIdAt(int index) const override { | 374 SessionID::id_type GetTabIdAt(int index) const override { |
371 SyncedTabDelegate* delegate = GetTabAt(index); | 375 SyncedTabDelegate* delegate = GetTabAt(index); |
372 if (!delegate) | 376 if (!delegate) |
373 return TabNodePool::kInvalidTabID; | 377 return kInvalidTabID; |
374 return delegate->GetSessionId(); | 378 return delegate->GetSessionId(); |
375 } | 379 } |
376 | 380 |
377 bool IsSessionRestoreInProgress() const override { return false; } | 381 bool IsSessionRestoreInProgress() const override { return false; } |
378 | 382 |
379 bool ShouldSync() const override { return true; } | 383 bool ShouldSync() const override { return true; } |
380 | 384 |
381 private: | 385 private: |
382 std::map<int, SyncedTabDelegate*> tab_delegates_; | 386 std::map<int, SyncedTabDelegate*> tab_delegates_; |
383 SessionID window_id_; | 387 SessionID window_id_; |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
505 | 509 |
506 void SetUp() override { | 510 void SetUp() override { |
507 local_device_ = base::MakeUnique<LocalDeviceInfoProviderMock>( | 511 local_device_ = base::MakeUnique<LocalDeviceInfoProviderMock>( |
508 "cache_guid", "Wayne Gretzky's Hacking Box", "Chromium 10k", | 512 "cache_guid", "Wayne Gretzky's Hacking Box", "Chromium 10k", |
509 "Chrome 10k", sync_pb::SyncEnums_DeviceType_TYPE_LINUX, "device_id"); | 513 "Chrome 10k", sync_pb::SyncEnums_DeviceType_TYPE_LINUX, "device_id"); |
510 sync_client_ = base::MakeUnique<syncer::FakeSyncClient>(); | 514 sync_client_ = base::MakeUnique<syncer::FakeSyncClient>(); |
511 sessions_client_shim_ = | 515 sessions_client_shim_ = |
512 base::MakeUnique<SyncSessionsClientShim>(&window_getter_); | 516 base::MakeUnique<SyncSessionsClientShim>(&window_getter_); |
513 sync_prefs_ = | 517 sync_prefs_ = |
514 base::MakeUnique<syncer::SyncPrefs>(sync_client_->GetPrefService()); | 518 base::MakeUnique<syncer::SyncPrefs>(sync_client_->GetPrefService()); |
| 519 router_ = base::MakeUnique<DummyRouter>(); |
515 manager_ = base::MakeUnique<SessionsSyncManager>( | 520 manager_ = base::MakeUnique<SessionsSyncManager>( |
516 sessions_client_shim(), sync_prefs_.get(), local_device_.get(), | 521 sessions_client_shim(), sync_prefs_.get(), local_device_.get(), |
517 std::unique_ptr<LocalSessionEventRouter>(NewDummyRouter()), | 522 router_.get(), |
518 base::Bind(&SessionNotificationObserver::NotifyOfUpdate, | 523 base::Bind(&SessionNotificationObserver::NotifyOfUpdate, |
519 base::Unretained(&observer_)), | 524 base::Unretained(&observer_)), |
520 base::Bind(&SessionNotificationObserver::NotifyOfRefresh, | 525 base::Bind(&SessionNotificationObserver::NotifyOfRefresh, |
521 base::Unretained(&observer_))); | 526 base::Unretained(&observer_))); |
522 } | 527 } |
523 | 528 |
524 void TearDown() override { | 529 void TearDown() override { |
525 test_processor_ = nullptr; | 530 test_processor_ = nullptr; |
526 helper()->Reset(); | 531 helper()->Reset(); |
527 sync_prefs_.reset(); | 532 sync_prefs_.reset(); |
(...skipping 11 matching lines...) Expand all Loading... |
539 SessionsSyncManager* manager() { return manager_.get(); } | 544 SessionsSyncManager* manager() { return manager_.get(); } |
540 SessionSyncTestHelper* helper() { return &helper_; } | 545 SessionSyncTestHelper* helper() { return &helper_; } |
541 LocalDeviceInfoProvider* local_device() { return local_device_.get(); } | 546 LocalDeviceInfoProvider* local_device() { return local_device_.get(); } |
542 SessionNotificationObserver* observer() { return &observer_; } | 547 SessionNotificationObserver* observer() { return &observer_; } |
543 syncer::SyncPrefs* sync_prefs() { return sync_prefs_.get(); } | 548 syncer::SyncPrefs* sync_prefs() { return sync_prefs_.get(); } |
544 SyncSessionsClient* sessions_client_shim() { | 549 SyncSessionsClient* sessions_client_shim() { |
545 return sessions_client_shim_.get(); | 550 return sessions_client_shim_.get(); |
546 } | 551 } |
547 SyncedWindowDelegatesGetter* window_getter() { return &window_getter_; } | 552 SyncedWindowDelegatesGetter* window_getter() { return &window_getter_; } |
548 | 553 |
549 std::unique_ptr<LocalSessionEventRouter> NewDummyRouter() { | |
550 std::unique_ptr<DummyRouter> router(new DummyRouter()); | |
551 router_ = router.get(); | |
552 return std::unique_ptr<LocalSessionEventRouter>(std::move(router)); | |
553 } | |
554 | |
555 void InitWithSyncDataTakeOutput(const SyncDataList& initial_data, | 554 void InitWithSyncDataTakeOutput(const SyncDataList& initial_data, |
556 SyncChangeList* output) { | 555 SyncChangeList* output) { |
557 test_processor_ = new TestSyncChangeProcessor(output); | 556 test_processor_ = new TestSyncChangeProcessor(output); |
558 syncer::SyncMergeResult result = manager_->MergeDataAndStartSyncing( | 557 syncer::SyncMergeResult result = manager_->MergeDataAndStartSyncing( |
559 syncer::SESSIONS, initial_data, | 558 syncer::SESSIONS, initial_data, |
560 std::unique_ptr<syncer::SyncChangeProcessor>(test_processor_), | 559 std::unique_ptr<syncer::SyncChangeProcessor>(test_processor_), |
561 std::unique_ptr<syncer::SyncErrorFactory>( | 560 std::unique_ptr<syncer::SyncErrorFactory>( |
562 new syncer::SyncErrorFactoryMock())); | 561 new syncer::SyncErrorFactoryMock())); |
563 EXPECT_FALSE(result.error().IsSet()); | 562 EXPECT_FALSE(result.error().IsSet()); |
564 } | 563 } |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
721 windows_.push_back(base::MakeUnique<TestSyncedWindowDelegate>()); | 720 windows_.push_back(base::MakeUnique<TestSyncedWindowDelegate>()); |
722 window_getter_.AddSyncedWindowDelegate(windows_.back().get()); | 721 window_getter_.AddSyncedWindowDelegate(windows_.back().get()); |
723 return windows_.back().get(); | 722 return windows_.back().get(); |
724 } | 723 } |
725 | 724 |
726 private: | 725 private: |
727 std::unique_ptr<syncer::FakeSyncClient> sync_client_; | 726 std::unique_ptr<syncer::FakeSyncClient> sync_client_; |
728 std::unique_ptr<SyncSessionsClientShim> sessions_client_shim_; | 727 std::unique_ptr<SyncSessionsClientShim> sessions_client_shim_; |
729 std::unique_ptr<syncer::SyncPrefs> sync_prefs_; | 728 std::unique_ptr<syncer::SyncPrefs> sync_prefs_; |
730 SessionNotificationObserver observer_; | 729 SessionNotificationObserver observer_; |
731 DummyRouter* router_ = nullptr; | 730 std::unique_ptr<DummyRouter> router_; |
732 std::unique_ptr<SessionsSyncManager> manager_; | 731 std::unique_ptr<SessionsSyncManager> manager_; |
733 SessionSyncTestHelper helper_; | 732 SessionSyncTestHelper helper_; |
734 TestSyncChangeProcessor* test_processor_ = nullptr; | 733 TestSyncChangeProcessor* test_processor_ = nullptr; |
735 TestSyncedWindowDelegatesGetter window_getter_; | 734 TestSyncedWindowDelegatesGetter window_getter_; |
736 std::vector<std::unique_ptr<TestSyncedWindowDelegate>> windows_; | 735 std::vector<std::unique_ptr<TestSyncedWindowDelegate>> windows_; |
737 std::vector<std::unique_ptr<TestSyncedTabDelegate>> tabs_; | 736 std::vector<std::unique_ptr<TestSyncedTabDelegate>> tabs_; |
738 std::unique_ptr<LocalDeviceInfoProviderMock> local_device_; | 737 std::unique_ptr<LocalDeviceInfoProviderMock> local_device_; |
739 }; | 738 }; |
740 | 739 |
741 // Test that the SyncSessionManager can properly fill in a SessionHeader. | 740 // Test that the SyncSessionManager can properly fill in a SessionHeader. |
(...skipping 1655 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2397 // Because tab 2 is a placeholder, tab 1's URL will be preserved. | 2396 // Because tab 2 is a placeholder, tab 1's URL will be preserved. |
2398 VerifyLocalTabChange(out[1], 1, kFoo1); | 2397 VerifyLocalTabChange(out[1], 1, kFoo1); |
2399 EXPECT_EQ(sync_id, out[1].sync_data().GetSpecifics().session().tab_node_id()); | 2398 EXPECT_EQ(sync_id, out[1].sync_data().GetSpecifics().session().tab_node_id()); |
2400 EXPECT_EQ(tab2.GetSessionId(), | 2399 EXPECT_EQ(tab2.GetSessionId(), |
2401 out[1].sync_data().GetSpecifics().session().tab().tab_id()); | 2400 out[1].sync_data().GetSpecifics().session().tab().tab_id()); |
2402 EXPECT_EQ(window2->GetSessionId(), | 2401 EXPECT_EQ(window2->GetSessionId(), |
2403 out[1].sync_data().GetSpecifics().session().tab().window_id()); | 2402 out[1].sync_data().GetSpecifics().session().tab().window_id()); |
2404 } | 2403 } |
2405 | 2404 |
2406 } // namespace sync_sessions | 2405 } // namespace sync_sessions |
OLD | NEW |