OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/glue/sync_backend_host.h" | 5 #include "chrome/browser/sync/glue/sync_backend_host.h" |
6 | 6 |
7 #include <cstddef> | 7 #include <cstddef> |
8 | 8 |
9 #include "base/location.h" | 9 #include "base/location.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 io_thread_(BrowserThread::IO), | 139 io_thread_(BrowserThread::IO), |
140 fake_manager_(NULL) {} | 140 fake_manager_(NULL) {} |
141 | 141 |
142 virtual ~SyncBackendHostTest() {} | 142 virtual ~SyncBackendHostTest() {} |
143 | 143 |
144 virtual void SetUp() OVERRIDE { | 144 virtual void SetUp() OVERRIDE { |
145 io_thread_.StartIOThread(); | 145 io_thread_.StartIOThread(); |
146 profile_.reset(new TestingProfile()); | 146 profile_.reset(new TestingProfile()); |
147 profile_->CreateRequestContext(); | 147 profile_->CreateRequestContext(); |
148 sync_prefs_.reset(new SyncPrefs(profile_->GetPrefs())); | 148 sync_prefs_.reset(new SyncPrefs(profile_->GetPrefs())); |
149 invalidator_storage_.reset(new invalidation::InvalidatorStorage( | |
150 profile_->GetPrefs())); | |
151 backend_.reset(new SyncBackendHost( | 149 backend_.reset(new SyncBackendHost( |
152 profile_->GetDebugName(), | 150 profile_->GetDebugName(), |
153 profile_.get(), | 151 profile_.get(), |
154 sync_prefs_->AsWeakPtr(), | 152 sync_prefs_->AsWeakPtr())); |
155 invalidator_storage_->AsWeakPtr())); | |
156 credentials_.email = "user@example.com"; | 153 credentials_.email = "user@example.com"; |
157 credentials_.sync_token = "sync_token"; | 154 credentials_.sync_token = "sync_token"; |
158 | 155 |
159 // These types are always implicitly enabled. | 156 // These types are always implicitly enabled. |
160 enabled_types_.PutAll(syncer::ControlTypes()); | 157 enabled_types_.PutAll(syncer::ControlTypes()); |
161 | 158 |
162 // NOTE: We can't include Passwords or Typed URLs due to the Sync Backend | 159 // NOTE: We can't include Passwords or Typed URLs due to the Sync Backend |
163 // Registrar removing them if it can't find their model workers. | 160 // Registrar removing them if it can't find their model workers. |
164 enabled_types_.Put(syncer::BOOKMARKS); | 161 enabled_types_.Put(syncer::BOOKMARKS); |
165 enabled_types_.Put(syncer::NIGORI); | 162 enabled_types_.Put(syncer::NIGORI); |
166 enabled_types_.Put(syncer::DEVICE_INFO); | 163 enabled_types_.Put(syncer::DEVICE_INFO); |
167 enabled_types_.Put(syncer::PREFERENCES); | 164 enabled_types_.Put(syncer::PREFERENCES); |
168 enabled_types_.Put(syncer::SESSIONS); | 165 enabled_types_.Put(syncer::SESSIONS); |
169 enabled_types_.Put(syncer::SEARCH_ENGINES); | 166 enabled_types_.Put(syncer::SEARCH_ENGINES); |
170 enabled_types_.Put(syncer::AUTOFILL); | 167 enabled_types_.Put(syncer::AUTOFILL); |
171 enabled_types_.Put(syncer::EXPERIMENTS); | 168 enabled_types_.Put(syncer::EXPERIMENTS); |
172 } | 169 } |
173 | 170 |
174 virtual void TearDown() OVERRIDE { | 171 virtual void TearDown() OVERRIDE { |
175 if (backend_) { | 172 if (backend_) { |
176 backend_->StopSyncingForShutdown(); | 173 backend_->StopSyncingForShutdown(); |
177 backend_->Shutdown(false); | 174 backend_->Shutdown(false); |
178 } | 175 } |
179 backend_.reset(); | 176 backend_.reset(); |
180 sync_prefs_.reset(); | 177 sync_prefs_.reset(); |
181 invalidator_storage_.reset(); | |
182 profile_.reset(); | 178 profile_.reset(); |
183 // Pump messages posted by the sync thread (which may end up | 179 // Pump messages posted by the sync thread (which may end up |
184 // posting on the IO thread). | 180 // posting on the IO thread). |
185 ui_loop_.RunUntilIdle(); | 181 ui_loop_.RunUntilIdle(); |
186 io_thread_.Stop(); | 182 io_thread_.Stop(); |
187 // Pump any messages posted by the IO thread. | 183 // Pump any messages posted by the IO thread. |
188 ui_loop_.RunUntilIdle(); | 184 ui_loop_.RunUntilIdle(); |
189 } | 185 } |
190 | 186 |
191 // Synchronously initializes the backend. | 187 // Synchronously initializes the backend. |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 } | 255 } |
260 | 256 |
261 base::MessageLoop ui_loop_; | 257 base::MessageLoop ui_loop_; |
262 content::TestBrowserThread ui_thread_; | 258 content::TestBrowserThread ui_thread_; |
263 content::TestBrowserThread io_thread_; | 259 content::TestBrowserThread io_thread_; |
264 StrictMock<MockSyncFrontend> mock_frontend_; | 260 StrictMock<MockSyncFrontend> mock_frontend_; |
265 syncer::SyncCredentials credentials_; | 261 syncer::SyncCredentials credentials_; |
266 syncer::TestUnrecoverableErrorHandler handler_; | 262 syncer::TestUnrecoverableErrorHandler handler_; |
267 scoped_ptr<TestingProfile> profile_; | 263 scoped_ptr<TestingProfile> profile_; |
268 scoped_ptr<SyncPrefs> sync_prefs_; | 264 scoped_ptr<SyncPrefs> sync_prefs_; |
269 scoped_ptr<invalidation::InvalidatorStorage> invalidator_storage_; | |
270 scoped_ptr<SyncBackendHost> backend_; | 265 scoped_ptr<SyncBackendHost> backend_; |
271 FakeSyncManager* fake_manager_; | 266 FakeSyncManager* fake_manager_; |
272 FakeSyncManagerFactory fake_manager_factory_; | 267 FakeSyncManagerFactory fake_manager_factory_; |
273 syncer::ModelTypeSet enabled_types_; | 268 syncer::ModelTypeSet enabled_types_; |
274 }; | 269 }; |
275 | 270 |
276 // Test basic initialization with no initial types (first time initialization). | 271 // Test basic initialization with no initial types (first time initialization). |
277 // Only the nigori should be configured. | 272 // Only the nigori should be configured. |
278 TEST_F(SyncBackendHostTest, InitShutdown) { | 273 TEST_F(SyncBackendHostTest, InitShutdown) { |
279 InitializeBackend(true); | 274 InitializeBackend(true); |
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
587 EXPECT_TRUE(fake_manager_->GetAndResetDownloadedTypes().Equals( | 582 EXPECT_TRUE(fake_manager_->GetAndResetDownloadedTypes().Equals( |
588 Union(new_types, partial_types))); | 583 Union(new_types, partial_types))); |
589 EXPECT_TRUE(Intersection(fake_manager_->GetAndResetCleanedTypes(), | 584 EXPECT_TRUE(Intersection(fake_manager_->GetAndResetCleanedTypes(), |
590 enabled_types_).Empty()); | 585 enabled_types_).Empty()); |
591 EXPECT_TRUE(fake_manager_->InitialSyncEndedTypes().Equals(enabled_types_)); | 586 EXPECT_TRUE(fake_manager_->InitialSyncEndedTypes().Equals(enabled_types_)); |
592 EXPECT_TRUE(fake_manager_->GetAndResetEnabledTypes().Equals(enabled_types_)); | 587 EXPECT_TRUE(fake_manager_->GetAndResetEnabledTypes().Equals(enabled_types_)); |
593 EXPECT_TRUE(fake_manager_->GetTypesWithEmptyProgressMarkerToken( | 588 EXPECT_TRUE(fake_manager_->GetTypesWithEmptyProgressMarkerToken( |
594 enabled_types_).Empty()); | 589 enabled_types_).Empty()); |
595 } | 590 } |
596 | 591 |
597 // Register for some IDs and trigger an invalidation. This should | |
598 // propagate all the way to the frontend. | |
599 TEST_F(SyncBackendHostTest, Invalidate) { | |
600 InitializeBackend(true); | |
601 | |
602 syncer::ObjectIdSet ids; | |
603 ids.insert(invalidation::ObjectId(1, "id1")); | |
604 ids.insert(invalidation::ObjectId(2, "id2")); | |
605 const syncer::ObjectIdInvalidationMap& invalidation_map = | |
606 syncer::ObjectIdSetToInvalidationMap(ids, "payload"); | |
607 | |
608 EXPECT_CALL( | |
609 mock_frontend_, | |
610 OnIncomingInvalidation(invalidation_map)) | |
611 .WillOnce(InvokeWithoutArgs(QuitMessageLoop)); | |
612 | |
613 backend_->UpdateRegisteredInvalidationIds(ids); | |
614 fake_manager_->Invalidate(invalidation_map); | |
615 ui_loop_.PostDelayedTask( | |
616 FROM_HERE, ui_loop_.QuitClosure(), TestTimeouts::action_timeout()); | |
617 ui_loop_.Run(); | |
618 } | |
619 | |
620 // Register for some IDs and update the invalidator state. This | |
621 // should propagate all the way to the frontend. | |
622 TEST_F(SyncBackendHostTest, UpdateInvalidatorState) { | |
623 InitializeBackend(true); | |
624 | |
625 EXPECT_CALL(mock_frontend_, | |
626 OnInvalidatorStateChange(syncer::INVALIDATIONS_ENABLED)) | |
627 .WillOnce(InvokeWithoutArgs(QuitMessageLoop)); | |
628 | |
629 syncer::ObjectIdSet ids; | |
630 ids.insert(invalidation::ObjectId(3, "id3")); | |
631 backend_->UpdateRegisteredInvalidationIds(ids); | |
632 fake_manager_->UpdateInvalidatorState(syncer::INVALIDATIONS_ENABLED); | |
633 ui_loop_.PostDelayedTask( | |
634 FROM_HERE, ui_loop_.QuitClosure(), TestTimeouts::action_timeout()); | |
635 ui_loop_.Run(); | |
636 } | |
637 | |
638 // Call StopSyncingForShutdown() on the backend and fire some invalidations | |
639 // before calling Shutdown(). Then start up and shut down the backend again. | |
640 // Those notifications shouldn't propagate to the frontend. | |
641 TEST_F(SyncBackendHostTest, InvalidationsAfterStopSyncingForShutdown) { | |
642 InitializeBackend(true); | |
643 | |
644 syncer::ObjectIdSet ids; | |
645 ids.insert(invalidation::ObjectId(5, "id5")); | |
646 backend_->UpdateRegisteredInvalidationIds(ids); | |
647 | |
648 backend_->StopSyncingForShutdown(); | |
649 | |
650 // Should not trigger anything. | |
651 fake_manager_->UpdateInvalidatorState(syncer::TRANSIENT_INVALIDATION_ERROR); | |
652 fake_manager_->UpdateInvalidatorState(syncer::INVALIDATIONS_ENABLED); | |
653 const syncer::ObjectIdInvalidationMap& invalidation_map = | |
654 syncer::ObjectIdSetToInvalidationMap(ids, "payload"); | |
655 fake_manager_->Invalidate(invalidation_map); | |
656 | |
657 // Make sure the above calls take effect before we continue. | |
658 fake_manager_->WaitForSyncThread(); | |
659 | |
660 backend_->Shutdown(false); | |
661 backend_.reset(); | |
662 | |
663 TearDown(); | |
664 SetUp(); | |
665 } | |
666 | |
667 // Ensure the device info tracker is initialized properly on startup. | 592 // Ensure the device info tracker is initialized properly on startup. |
668 TEST_F(SyncBackendHostTest, InitializeDeviceInfo) { | 593 TEST_F(SyncBackendHostTest, InitializeDeviceInfo) { |
669 ASSERT_EQ(NULL, backend_->GetSyncedDeviceTracker()); | 594 ASSERT_EQ(NULL, backend_->GetSyncedDeviceTracker()); |
670 | 595 |
671 InitializeBackend(true); | 596 InitializeBackend(true); |
672 const SyncedDeviceTracker* device_tracker = | 597 const SyncedDeviceTracker* device_tracker = |
673 backend_->GetSyncedDeviceTracker(); | 598 backend_->GetSyncedDeviceTracker(); |
674 ASSERT_TRUE(device_tracker->ReadLocalDeviceInfo()); | 599 ASSERT_TRUE(device_tracker->ReadLocalDeviceInfo()); |
675 } | 600 } |
676 | 601 |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
763 TEST_F(SyncBackendHostTest, DownloadControlTypesRestart) { | 688 TEST_F(SyncBackendHostTest, DownloadControlTypesRestart) { |
764 sync_prefs_->SetSyncSetupCompleted(); | 689 sync_prefs_->SetSyncSetupCompleted(); |
765 InitializeBackend(true); | 690 InitializeBackend(true); |
766 EXPECT_EQ(syncer::CONFIGURE_REASON_NEWLY_ENABLED_DATA_TYPE, | 691 EXPECT_EQ(syncer::CONFIGURE_REASON_NEWLY_ENABLED_DATA_TYPE, |
767 fake_manager_->GetAndResetConfigureReason()); | 692 fake_manager_->GetAndResetConfigureReason()); |
768 } | 693 } |
769 | 694 |
770 } // namespace | 695 } // namespace |
771 | 696 |
772 } // namespace browser_sync | 697 } // namespace browser_sync |
OLD | NEW |