| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_impl.h" | 5 #include "chrome/browser/sync/glue/sync_backend_host_impl.h" |
| 6 | 6 |
| 7 #include <cstddef> | 7 #include <cstddef> |
| 8 | 8 |
| 9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
| 13 #include "base/synchronization/waitable_event.h" | 13 #include "base/synchronization/waitable_event.h" |
| 14 #include "base/test/test_timeouts.h" | 14 #include "base/test/test_timeouts.h" |
| 15 #include "chrome/browser/chrome_notification_types.h" | 15 #include "chrome/browser/chrome_notification_types.h" |
| 16 #include "chrome/browser/invalidation/invalidator_storage.h" | 16 #include "chrome/browser/invalidation/invalidator_storage.h" |
| 17 #include "chrome/browser/prefs/pref_service_syncable.h" | 17 #include "chrome/browser/prefs/pref_service_syncable.h" |
| 18 #include "chrome/browser/sync/glue/device_info.h" | 18 #include "chrome/browser/sync/glue/device_info.h" |
| 19 #include "chrome/browser/sync/glue/synced_device_tracker.h" | 19 #include "chrome/browser/sync/glue/synced_device_tracker.h" |
| 20 #include "chrome/test/base/testing_browser_process.h" |
| 20 #include "chrome/test/base/testing_profile.h" | 21 #include "chrome/test/base/testing_profile.h" |
| 22 #include "chrome/test/base/testing_profile_manager.h" |
| 21 #include "components/sync_driver/sync_frontend.h" | 23 #include "components/sync_driver/sync_frontend.h" |
| 22 #include "components/sync_driver/sync_prefs.h" | 24 #include "components/sync_driver/sync_prefs.h" |
| 23 #include "components/user_prefs/pref_registry_syncable.h" | 25 #include "components/user_prefs/pref_registry_syncable.h" |
| 24 #include "content/public/browser/notification_service.h" | 26 #include "content/public/browser/notification_service.h" |
| 25 #include "content/public/test/test_browser_thread_bundle.h" | 27 #include "content/public/test/test_browser_thread_bundle.h" |
| 26 #include "content/public/test/test_utils.h" | 28 #include "content/public/test/test_utils.h" |
| 27 #include "google/cacheinvalidation/include/types.h" | 29 #include "google/cacheinvalidation/include/types.h" |
| 28 #include "net/url_request/test_url_fetcher_factory.h" | 30 #include "net/url_request/test_url_fetcher_factory.h" |
| 29 #include "sync/internal_api/public/base/model_type.h" | 31 #include "sync/internal_api/public/base/model_type.h" |
| 30 #include "sync/internal_api/public/engine/model_safe_worker.h" | 32 #include "sync/internal_api/public/engine/model_safe_worker.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 45 using syncer::FakeSyncManager; | 47 using syncer::FakeSyncManager; |
| 46 using syncer::SyncManager; | 48 using syncer::SyncManager; |
| 47 using ::testing::InvokeWithoutArgs; | 49 using ::testing::InvokeWithoutArgs; |
| 48 using ::testing::StrictMock; | 50 using ::testing::StrictMock; |
| 49 using ::testing::_; | 51 using ::testing::_; |
| 50 | 52 |
| 51 namespace browser_sync { | 53 namespace browser_sync { |
| 52 | 54 |
| 53 namespace { | 55 namespace { |
| 54 | 56 |
| 57 const char kTestProfileName[] = "test-profile"; |
| 58 |
| 55 ACTION_P(Signal, event) { | 59 ACTION_P(Signal, event) { |
| 56 event->Signal(); | 60 event->Signal(); |
| 57 } | 61 } |
| 58 | 62 |
| 59 void QuitMessageLoop() { | 63 void QuitMessageLoop() { |
| 60 base::MessageLoop::current()->Quit(); | 64 base::MessageLoop::current()->Quit(); |
| 61 } | 65 } |
| 62 | 66 |
| 63 class MockSyncFrontend : public SyncFrontend { | 67 class MockSyncFrontend : public SyncFrontend { |
| 64 public: | 68 public: |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 syncer::ModelTypeSet initial_sync_ended_types_; | 127 syncer::ModelTypeSet initial_sync_ended_types_; |
| 124 syncer::ModelTypeSet progress_marker_types_; | 128 syncer::ModelTypeSet progress_marker_types_; |
| 125 syncer::ModelTypeSet configure_fail_types_; | 129 syncer::ModelTypeSet configure_fail_types_; |
| 126 FakeSyncManager** fake_manager_; | 130 FakeSyncManager** fake_manager_; |
| 127 }; | 131 }; |
| 128 | 132 |
| 129 class SyncBackendHostTest : public testing::Test { | 133 class SyncBackendHostTest : public testing::Test { |
| 130 protected: | 134 protected: |
| 131 SyncBackendHostTest() | 135 SyncBackendHostTest() |
| 132 : thread_bundle_(content::TestBrowserThreadBundle::REAL_IO_THREAD), | 136 : thread_bundle_(content::TestBrowserThreadBundle::REAL_IO_THREAD), |
| 137 profile_manager_(TestingBrowserProcess::GetGlobal()), |
| 133 fake_manager_(NULL) {} | 138 fake_manager_(NULL) {} |
| 134 | 139 |
| 135 virtual ~SyncBackendHostTest() {} | 140 virtual ~SyncBackendHostTest() {} |
| 136 | 141 |
| 137 virtual void SetUp() OVERRIDE { | 142 virtual void SetUp() OVERRIDE { |
| 138 profile_.reset(new TestingProfile()); | 143 ASSERT_TRUE(profile_manager_.SetUp()); |
| 144 profile_ = profile_manager_.CreateTestingProfile(kTestProfileName); |
| 139 sync_prefs_.reset(new sync_driver::SyncPrefs(profile_->GetPrefs())); | 145 sync_prefs_.reset(new sync_driver::SyncPrefs(profile_->GetPrefs())); |
| 140 backend_.reset(new SyncBackendHostImpl( | 146 backend_.reset(new SyncBackendHostImpl( |
| 141 profile_->GetDebugName(), | 147 profile_->GetDebugName(), |
| 142 profile_.get(), | 148 profile_, |
| 143 sync_prefs_->AsWeakPtr())); | 149 sync_prefs_->AsWeakPtr())); |
| 144 credentials_.email = "user@example.com"; | 150 credentials_.email = "user@example.com"; |
| 145 credentials_.sync_token = "sync_token"; | 151 credentials_.sync_token = "sync_token"; |
| 146 | 152 |
| 147 fake_manager_factory_.reset(new FakeSyncManagerFactory(&fake_manager_)); | 153 fake_manager_factory_.reset(new FakeSyncManagerFactory(&fake_manager_)); |
| 148 | 154 |
| 149 // These types are always implicitly enabled. | 155 // These types are always implicitly enabled. |
| 150 enabled_types_.PutAll(syncer::ControlTypes()); | 156 enabled_types_.PutAll(syncer::ControlTypes()); |
| 151 | 157 |
| 152 // NOTE: We can't include Passwords or Typed URLs due to the Sync Backend | 158 // NOTE: We can't include Passwords or Typed URLs due to the Sync Backend |
| (...skipping 10 matching lines...) Expand all Loading... |
| 163 network_resources_.reset(new syncer::HttpBridgeNetworkResources()); | 169 network_resources_.reset(new syncer::HttpBridgeNetworkResources()); |
| 164 } | 170 } |
| 165 | 171 |
| 166 virtual void TearDown() OVERRIDE { | 172 virtual void TearDown() OVERRIDE { |
| 167 if (backend_) { | 173 if (backend_) { |
| 168 backend_->StopSyncingForShutdown(); | 174 backend_->StopSyncingForShutdown(); |
| 169 backend_->Shutdown(SyncBackendHost::STOP); | 175 backend_->Shutdown(SyncBackendHost::STOP); |
| 170 } | 176 } |
| 171 backend_.reset(); | 177 backend_.reset(); |
| 172 sync_prefs_.reset(); | 178 sync_prefs_.reset(); |
| 173 profile_.reset(); | 179 profile_ = NULL; |
| 180 profile_manager_.DeleteTestingProfile(kTestProfileName); |
| 174 // Pump messages posted by the sync thread (which may end up | 181 // Pump messages posted by the sync thread (which may end up |
| 175 // posting on the IO thread). | 182 // posting on the IO thread). |
| 176 base::RunLoop().RunUntilIdle(); | 183 base::RunLoop().RunUntilIdle(); |
| 177 content::RunAllPendingInMessageLoop(BrowserThread::IO); | 184 content::RunAllPendingInMessageLoop(BrowserThread::IO); |
| 178 // Pump any messages posted by the IO thread. | 185 // Pump any messages posted by the IO thread. |
| 179 base::RunLoop().RunUntilIdle(); | 186 base::RunLoop().RunUntilIdle(); |
| 180 } | 187 } |
| 181 | 188 |
| 182 // Synchronously initializes the backend. | 189 // Synchronously initializes the backend. |
| 183 void InitializeBackend(bool expect_success) { | 190 void InitializeBackend(bool expect_success) { |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 run_loop.QuitClosure(), | 238 run_loop.QuitClosure(), |
| 232 TestTimeouts::action_timeout()); | 239 TestTimeouts::action_timeout()); |
| 233 run_loop.Run(); | 240 run_loop.Run(); |
| 234 } | 241 } |
| 235 | 242 |
| 236 void IssueRefreshRequest(syncer::ModelTypeSet types) { | 243 void IssueRefreshRequest(syncer::ModelTypeSet types) { |
| 237 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 244 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 238 | 245 |
| 239 content::NotificationService::current()->Notify( | 246 content::NotificationService::current()->Notify( |
| 240 chrome::NOTIFICATION_SYNC_REFRESH_LOCAL, | 247 chrome::NOTIFICATION_SYNC_REFRESH_LOCAL, |
| 241 content::Source<Profile>(profile_.get()), | 248 content::Source<Profile>(profile_), |
| 242 content::Details<syncer::ModelTypeSet>(&types)); | 249 content::Details<syncer::ModelTypeSet>(&types)); |
| 243 } | 250 } |
| 244 | 251 |
| 245 protected: | 252 protected: |
| 246 void DownloadReady(syncer::ModelTypeSet succeeded_types, | 253 void DownloadReady(syncer::ModelTypeSet succeeded_types, |
| 247 syncer::ModelTypeSet failed_types) { | 254 syncer::ModelTypeSet failed_types) { |
| 248 base::MessageLoop::current()->Quit(); | 255 base::MessageLoop::current()->Quit(); |
| 249 } | 256 } |
| 250 | 257 |
| 251 void OnDownloadRetry() { | 258 void OnDownloadRetry() { |
| 252 NOTIMPLEMENTED(); | 259 NOTIMPLEMENTED(); |
| 253 } | 260 } |
| 254 | 261 |
| 255 content::TestBrowserThreadBundle thread_bundle_; | 262 content::TestBrowserThreadBundle thread_bundle_; |
| 256 StrictMock<MockSyncFrontend> mock_frontend_; | 263 StrictMock<MockSyncFrontend> mock_frontend_; |
| 257 syncer::SyncCredentials credentials_; | 264 syncer::SyncCredentials credentials_; |
| 258 scoped_ptr<TestingProfile> profile_; | 265 TestingProfileManager profile_manager_; |
| 266 TestingProfile* profile_; |
| 259 scoped_ptr<sync_driver::SyncPrefs> sync_prefs_; | 267 scoped_ptr<sync_driver::SyncPrefs> sync_prefs_; |
| 260 scoped_ptr<SyncBackendHost> backend_; | 268 scoped_ptr<SyncBackendHost> backend_; |
| 261 scoped_ptr<FakeSyncManagerFactory> fake_manager_factory_; | 269 scoped_ptr<FakeSyncManagerFactory> fake_manager_factory_; |
| 262 FakeSyncManager* fake_manager_; | 270 FakeSyncManager* fake_manager_; |
| 263 syncer::ModelTypeSet enabled_types_; | 271 syncer::ModelTypeSet enabled_types_; |
| 264 scoped_ptr<syncer::NetworkResources> network_resources_; | 272 scoped_ptr<syncer::NetworkResources> network_resources_; |
| 265 }; | 273 }; |
| 266 | 274 |
| 267 // Test basic initialization with no initial types (first time initialization). | 275 // Test basic initialization with no initial types (first time initialization). |
| 268 // Only the nigori should be configured. | 276 // Only the nigori should be configured. |
| (...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 701 ASSERT_NE(-1, base::WriteFile(sync_file, nonsense, strlen(nonsense))); | 709 ASSERT_NE(-1, base::WriteFile(sync_file, nonsense, strlen(nonsense))); |
| 702 | 710 |
| 703 InitializeBackend(true); | 711 InitializeBackend(true); |
| 704 | 712 |
| 705 EXPECT_FALSE(base::PathExists(sync_file)); | 713 EXPECT_FALSE(base::PathExists(sync_file)); |
| 706 } | 714 } |
| 707 | 715 |
| 708 } // namespace | 716 } // namespace |
| 709 | 717 |
| 710 } // namespace browser_sync | 718 } // namespace browser_sync |
| OLD | NEW |