| 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/test_profile_sync_service.h" | 5 #include "chrome/browser/sync/test_profile_sync_service.h" |
| 6 | 6 |
| 7 #include "chrome/browser/signin/signin_manager.h" | 7 #include "chrome/browser/signin/signin_manager.h" |
| 8 #include "chrome/browser/sync/abstract_profile_sync_service_test.h" | 8 #include "chrome/browser/sync/abstract_profile_sync_service_test.h" |
| 9 #include "chrome/browser/sync/glue/data_type_controller.h" | 9 #include "chrome/browser/sync/glue/data_type_controller.h" |
| 10 #include "chrome/browser/sync/glue/sync_backend_host.h" | 10 #include "chrome/browser/sync/glue/sync_backend_host.h" |
| 11 #include "chrome/browser/sync/profile_sync_components_factory.h" | 11 #include "chrome/browser/sync/profile_sync_components_factory.h" |
| 12 #include "chrome/browser/sync/test/test_http_bridge_factory.h" | 12 #include "chrome/browser/sync/test/test_http_bridge_factory.h" |
| 13 #include "chrome/common/chrome_notification_types.h" | 13 #include "chrome/common/chrome_notification_types.h" |
| 14 #include "sync/internal_api/user_share.h" | 14 #include "sync/internal_api/user_share.h" |
| 15 #include "sync/js/js_reply_handler.h" | 15 #include "sync/js/js_reply_handler.h" |
| 16 #include "sync/protocol/encryption.pb.h" | 16 #include "sync/protocol/encryption.pb.h" |
| 17 #include "sync/sessions/session_state.h" | 17 #include "sync/sessions/session_state.h" |
| 18 #include "sync/syncable/syncable.h" | 18 #include "sync/syncable/syncable.h" |
| 19 | 19 |
| 20 #include "chrome/browser/sync/glue/sync_backend_registrar.h" |
| 21 |
| 20 using browser_sync::ModelSafeRoutingInfo; | 22 using browser_sync::ModelSafeRoutingInfo; |
| 21 using browser_sync::sessions::ErrorCounters; | 23 using browser_sync::sessions::ErrorCounters; |
| 22 using browser_sync::sessions::SyncSourceInfo; | 24 using browser_sync::sessions::SyncSourceInfo; |
| 23 using browser_sync::sessions::SyncerStatus; | 25 using browser_sync::sessions::SyncerStatus; |
| 24 using browser_sync::sessions::SyncSessionSnapshot; | 26 using browser_sync::sessions::SyncSessionSnapshot; |
| 25 using syncable::Directory; | 27 using syncable::Directory; |
| 26 using syncable::ModelType; | 28 using syncable::ModelType; |
| 27 using sync_api::UserShare; | 29 using sync_api::UserShare; |
| 28 | 30 |
| 29 namespace browser_sync { | 31 namespace browser_sync { |
| 30 | 32 |
| 31 SyncBackendHostForProfileSyncTest::SyncBackendHostForProfileSyncTest( | 33 SyncBackendHostForProfileSyncTest::SyncBackendHostForProfileSyncTest( |
| 32 Profile* profile, | 34 Profile* profile, |
| 33 const base::WeakPtr<SyncPrefs>& sync_prefs, | 35 const base::WeakPtr<SyncPrefs>& sync_prefs, |
| 34 const base::WeakPtr<InvalidatorStorage>& invalidator_storage, | 36 const base::WeakPtr<InvalidatorStorage>& invalidator_storage, |
| 35 bool set_initial_sync_ended_on_init, | |
| 36 bool synchronous_init, | 37 bool synchronous_init, |
| 37 bool fail_initial_download, | 38 bool fail_all_downloads, |
| 38 bool use_real_database) | 39 bool use_real_database) |
| 39 : browser_sync::SyncBackendHost( | 40 : browser_sync::SyncBackendHost( |
| 40 profile->GetDebugName(), profile, sync_prefs, invalidator_storage), | 41 profile->GetDebugName(), profile, sync_prefs, invalidator_storage), |
| 41 synchronous_init_(synchronous_init), | 42 synchronous_init_(synchronous_init), |
| 42 fail_initial_download_(fail_initial_download), | 43 fail_all_downloads_(fail_all_downloads), |
| 43 use_real_database_(use_real_database) {} | 44 use_real_database_(use_real_database) {} |
| 44 | 45 |
| 45 SyncBackendHostForProfileSyncTest::~SyncBackendHostForProfileSyncTest() {} | 46 SyncBackendHostForProfileSyncTest::~SyncBackendHostForProfileSyncTest() {} |
| 46 | 47 |
| 47 void SyncBackendHostForProfileSyncTest:: | |
| 48 SimulateSyncCycleCompletedInitialSyncEnded( | |
| 49 const tracked_objects::Location& location) { | |
| 50 syncable::ModelTypeSet sync_ended; | |
| 51 if (!fail_initial_download_) | |
| 52 sync_ended = syncable::ModelTypeSet::All(); | |
| 53 syncable::ModelTypePayloadMap download_progress_markers; | |
| 54 HandleSyncCycleCompletedOnFrontendLoop(SyncSessionSnapshot( | |
| 55 SyncerStatus(), ErrorCounters(), 0, false, | |
| 56 sync_ended, download_progress_markers, false, false, 0, 0, 0, 0, | |
| 57 SyncSourceInfo(), false, 0, base::Time::Now(), false)); | |
| 58 } | |
| 59 | |
| 60 namespace { | 48 namespace { |
| 61 | 49 |
| 62 sync_api::HttpPostProviderFactory* MakeTestHttpBridgeFactory() { | 50 sync_api::HttpPostProviderFactory* MakeTestHttpBridgeFactory() { |
| 63 return new browser_sync::TestHttpBridgeFactory(); | 51 return new browser_sync::TestHttpBridgeFactory(); |
| 64 } | 52 } |
| 65 | 53 |
| 66 } // namespace | 54 } // namespace |
| 67 | 55 |
| 68 void SyncBackendHostForProfileSyncTest::InitCore( | 56 void SyncBackendHostForProfileSyncTest::InitCore( |
| 69 const DoInitializeOptions& options) { | 57 const DoInitializeOptions& options) { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 81 if (synchronous_init_) { | 69 if (synchronous_init_) { |
| 82 // The SyncBackend posts a task to the current loop when | 70 // The SyncBackend posts a task to the current loop when |
| 83 // initialization completes. | 71 // initialization completes. |
| 84 MessageLoop::current()->Run(); | 72 MessageLoop::current()->Run(); |
| 85 } | 73 } |
| 86 } | 74 } |
| 87 | 75 |
| 88 void SyncBackendHostForProfileSyncTest::StartConfiguration( | 76 void SyncBackendHostForProfileSyncTest::StartConfiguration( |
| 89 const base::Closure& callback) { | 77 const base::Closure& callback) { |
| 90 SyncBackendHost::FinishConfigureDataTypesOnFrontendLoop(); | 78 SyncBackendHost::FinishConfigureDataTypesOnFrontendLoop(); |
| 91 if (IsDownloadingNigoriForTest()) { | |
| 92 syncable::ModelTypeSet sync_ended; | |
| 93 | 79 |
| 94 if (!fail_initial_download_) | 80 if (!fail_all_downloads_ && pending_download_state_.get()) { |
| 95 sync_ended.Put(syncable::NIGORI); | 81 // Give the SBH the callback it is waiting for. |
| 96 syncable::ModelTypePayloadMap download_progress_markers; | 82 syncable::ModelTypePayloadMap download_progress_markers; |
| 97 HandleSyncCycleCompletedOnFrontendLoop(SyncSessionSnapshot( | 83 HandleSyncCycleCompletedOnFrontendLoop(SyncSessionSnapshot( |
| 98 SyncerStatus(), ErrorCounters(), 0, false, | 84 SyncerStatus(), ErrorCounters(), 0, false, |
| 99 sync_ended, download_progress_markers, false, false, 0, 0, 0, 0, | 85 pending_download_state_->types_to_add, |
| 86 download_progress_markers, false, false, 0, 0, 0, 0, |
| 100 SyncSourceInfo(), false, 0, base::Time::Now(), false)); | 87 SyncSourceInfo(), false, 0, base::Time::Now(), false)); |
| 101 } | 88 } |
| 102 } | 89 } |
| 103 | 90 |
| 104 void SyncBackendHostForProfileSyncTest::SetHistoryServiceExpectations( | 91 void SyncBackendHostForProfileSyncTest::SetHistoryServiceExpectations( |
| 105 ProfileMock* profile) { | 92 ProfileMock* profile) { |
| 106 EXPECT_CALL(*profile, GetHistoryService(testing::_)). | 93 EXPECT_CALL(*profile, GetHistoryService(testing::_)). |
| 107 WillOnce(testing::Return((HistoryService*)NULL)); | 94 WillOnce(testing::Return((HistoryService*)NULL)); |
| 108 } | 95 } |
| 109 | 96 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 128 const base::Closure& callback) | 115 const base::Closure& callback) |
| 129 : ProfileSyncService(factory, | 116 : ProfileSyncService(factory, |
| 130 profile, | 117 profile, |
| 131 signin, | 118 signin, |
| 132 behavior), | 119 behavior), |
| 133 synchronous_backend_initialization_( | 120 synchronous_backend_initialization_( |
| 134 synchronous_backend_initialization), | 121 synchronous_backend_initialization), |
| 135 synchronous_sync_configuration_(false), | 122 synchronous_sync_configuration_(false), |
| 136 callback_(callback), | 123 callback_(callback), |
| 137 set_initial_sync_ended_on_init_(true), | 124 set_initial_sync_ended_on_init_(true), |
| 138 fail_initial_download_(false), | 125 fail_all_downloads_(false), |
| 139 use_real_database_(false) { | 126 use_real_database_(false) { |
| 140 SetSyncSetupCompleted(); | 127 SetSyncSetupCompleted(); |
| 141 } | 128 } |
| 142 | 129 |
| 143 TestProfileSyncService::~TestProfileSyncService() { | 130 TestProfileSyncService::~TestProfileSyncService() { |
| 144 } | 131 } |
| 145 | 132 |
| 146 void TestProfileSyncService::SetInitialSyncEndedForAllTypes() { | 133 void TestProfileSyncService::SetInitialSyncEndedForAllTypes() { |
| 147 UserShare* user_share = GetUserShare(); | 134 UserShare* user_share = GetUserShare(); |
| 148 Directory* directory = user_share->directory.get(); | 135 Directory* directory = user_share->directory.get(); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 MessageLoop::current()->Quit(); | 195 MessageLoop::current()->Quit(); |
| 209 } | 196 } |
| 210 } | 197 } |
| 211 | 198 |
| 212 void TestProfileSyncService::dont_set_initial_sync_ended_on_init() { | 199 void TestProfileSyncService::dont_set_initial_sync_ended_on_init() { |
| 213 set_initial_sync_ended_on_init_ = false; | 200 set_initial_sync_ended_on_init_ = false; |
| 214 } | 201 } |
| 215 void TestProfileSyncService::set_synchronous_sync_configuration() { | 202 void TestProfileSyncService::set_synchronous_sync_configuration() { |
| 216 synchronous_sync_configuration_ = true; | 203 synchronous_sync_configuration_ = true; |
| 217 } | 204 } |
| 218 void TestProfileSyncService::fail_initial_download() { | 205 void TestProfileSyncService::fail_all_downloads() { |
| 219 fail_initial_download_ = true; | 206 fail_all_downloads_ = true; |
| 220 } | 207 } |
| 221 void TestProfileSyncService::set_use_real_database() { | 208 void TestProfileSyncService::set_use_real_database() { |
| 222 use_real_database_ = true; | 209 use_real_database_ = true; |
| 223 } | 210 } |
| 224 | 211 |
| 225 void TestProfileSyncService::CreateBackend() { | 212 void TestProfileSyncService::CreateBackend() { |
| 226 backend_.reset(new browser_sync::SyncBackendHostForProfileSyncTest( | 213 backend_.reset(new browser_sync::SyncBackendHostForProfileSyncTest( |
| 227 profile(), | 214 profile(), |
| 228 sync_prefs_.AsWeakPtr(), | 215 sync_prefs_.AsWeakPtr(), |
| 229 invalidator_storage_.AsWeakPtr(), | 216 invalidator_storage_.AsWeakPtr(), |
| 230 set_initial_sync_ended_on_init_, | |
| 231 synchronous_backend_initialization_, | 217 synchronous_backend_initialization_, |
| 232 fail_initial_download_, | 218 fail_all_downloads_, |
| 233 use_real_database_)); | 219 use_real_database_)); |
| 234 } | 220 } |
| OLD | NEW |