| 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" |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 profile->GetDebugName(), profile, sync_prefs, invalidator_storage), | 38 profile->GetDebugName(), profile, sync_prefs, invalidator_storage), |
| 39 synchronous_init_(synchronous_init), | 39 synchronous_init_(synchronous_init), |
| 40 fail_initial_download_(fail_initial_download), | 40 fail_initial_download_(fail_initial_download), |
| 41 use_real_database_(use_real_database) {} | 41 use_real_database_(use_real_database) {} |
| 42 | 42 |
| 43 SyncBackendHostForProfileSyncTest::~SyncBackendHostForProfileSyncTest() {} | 43 SyncBackendHostForProfileSyncTest::~SyncBackendHostForProfileSyncTest() {} |
| 44 | 44 |
| 45 void SyncBackendHostForProfileSyncTest:: | 45 void SyncBackendHostForProfileSyncTest:: |
| 46 SimulateSyncCycleCompletedInitialSyncEnded( | 46 SimulateSyncCycleCompletedInitialSyncEnded( |
| 47 const tracked_objects::Location& location) { | 47 const tracked_objects::Location& location) { |
| 48 syncable::ModelTypeSet sync_ended; | 48 syncer::ModelTypeSet sync_ended; |
| 49 if (!fail_initial_download_) | 49 if (!fail_initial_download_) |
| 50 sync_ended = syncable::ModelTypeSet::All(); | 50 sync_ended = syncer::ModelTypeSet::All(); |
| 51 syncable::ModelTypePayloadMap download_progress_markers; | 51 syncer::ModelTypePayloadMap download_progress_markers; |
| 52 HandleSyncCycleCompletedOnFrontendLoop( | 52 HandleSyncCycleCompletedOnFrontendLoop( |
| 53 SyncSessionSnapshot( | 53 SyncSessionSnapshot( |
| 54 ModelNeutralState(), false, sync_ended, download_progress_markers, | 54 ModelNeutralState(), false, sync_ended, download_progress_markers, |
| 55 false, false, 0, 0, 0, 0, SyncSourceInfo(), false, 0, | 55 false, false, 0, 0, 0, 0, SyncSourceInfo(), false, 0, |
| 56 base::Time::Now(), false)); | 56 base::Time::Now(), false)); |
| 57 } | 57 } |
| 58 | 58 |
| 59 namespace { | 59 namespace { |
| 60 | 60 |
| 61 syncer::HttpPostProviderFactory* MakeTestHttpBridgeFactory() { | 61 syncer::HttpPostProviderFactory* MakeTestHttpBridgeFactory() { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 81 // The SyncBackend posts a task to the current loop when | 81 // The SyncBackend posts a task to the current loop when |
| 82 // initialization completes. | 82 // initialization completes. |
| 83 MessageLoop::current()->Run(); | 83 MessageLoop::current()->Run(); |
| 84 } | 84 } |
| 85 } | 85 } |
| 86 | 86 |
| 87 void SyncBackendHostForProfileSyncTest::StartConfiguration( | 87 void SyncBackendHostForProfileSyncTest::StartConfiguration( |
| 88 const base::Closure& callback) { | 88 const base::Closure& callback) { |
| 89 SyncBackendHost::FinishConfigureDataTypesOnFrontendLoop(); | 89 SyncBackendHost::FinishConfigureDataTypesOnFrontendLoop(); |
| 90 if (IsDownloadingNigoriForTest()) { | 90 if (IsDownloadingNigoriForTest()) { |
| 91 syncable::ModelTypeSet sync_ended; | 91 syncer::ModelTypeSet sync_ended; |
| 92 | 92 |
| 93 if (!fail_initial_download_) | 93 if (!fail_initial_download_) |
| 94 sync_ended.Put(syncable::NIGORI); | 94 sync_ended.Put(syncer::NIGORI); |
| 95 syncable::ModelTypePayloadMap download_progress_markers; | 95 syncer::ModelTypePayloadMap download_progress_markers; |
| 96 HandleSyncCycleCompletedOnFrontendLoop( | 96 HandleSyncCycleCompletedOnFrontendLoop( |
| 97 SyncSessionSnapshot( | 97 SyncSessionSnapshot( |
| 98 ModelNeutralState(), false, sync_ended, download_progress_markers, | 98 ModelNeutralState(), false, sync_ended, download_progress_markers, |
| 99 false, false, 0, 0, 0, 0, SyncSourceInfo(), false, 0, | 99 false, false, 0, 0, 0, 0, SyncSourceInfo(), false, 0, |
| 100 base::Time::Now(), false)); | 100 base::Time::Now(), false)); |
| 101 } | 101 } |
| 102 } | 102 } |
| 103 | 103 |
| 104 void SyncBackendHostForProfileSyncTest::SetHistoryServiceExpectations( | 104 void SyncBackendHostForProfileSyncTest::SetHistoryServiceExpectations( |
| 105 ProfileMock* profile) { | 105 ProfileMock* profile) { |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 SetSyncSetupCompleted(); | 140 SetSyncSetupCompleted(); |
| 141 } | 141 } |
| 142 | 142 |
| 143 TestProfileSyncService::~TestProfileSyncService() { | 143 TestProfileSyncService::~TestProfileSyncService() { |
| 144 } | 144 } |
| 145 | 145 |
| 146 void TestProfileSyncService::SetInitialSyncEndedForAllTypes() { | 146 void TestProfileSyncService::SetInitialSyncEndedForAllTypes() { |
| 147 UserShare* user_share = GetUserShare(); | 147 UserShare* user_share = GetUserShare(); |
| 148 Directory* directory = user_share->directory.get(); | 148 Directory* directory = user_share->directory.get(); |
| 149 | 149 |
| 150 for (int i = syncable::FIRST_REAL_MODEL_TYPE; | 150 for (int i = syncer::FIRST_REAL_MODEL_TYPE; |
| 151 i < syncable::MODEL_TYPE_COUNT; ++i) { | 151 i < syncer::MODEL_TYPE_COUNT; ++i) { |
| 152 directory->set_initial_sync_ended_for_type( | 152 directory->set_initial_sync_ended_for_type( |
| 153 syncable::ModelTypeFromInt(i), true); | 153 syncer::ModelTypeFromInt(i), true); |
| 154 } | 154 } |
| 155 } | 155 } |
| 156 | 156 |
| 157 void TestProfileSyncService::OnBackendInitialized( | 157 void TestProfileSyncService::OnBackendInitialized( |
| 158 const syncer::WeakHandle<syncer::JsBackend>& backend, | 158 const syncer::WeakHandle<syncer::JsBackend>& backend, |
| 159 bool success) { | 159 bool success) { |
| 160 bool send_passphrase_required = false; | 160 bool send_passphrase_required = false; |
| 161 if (success) { | 161 if (success) { |
| 162 // Set this so below code can access GetUserShare(). | 162 // Set this so below code can access GetUserShare(). |
| 163 backend_initialized_ = true; | 163 backend_initialized_ = true; |
| 164 | 164 |
| 165 // Set up any nodes the test wants around before model association. | 165 // Set up any nodes the test wants around before model association. |
| 166 if (!callback_.is_null()) { | 166 if (!callback_.is_null()) { |
| 167 callback_.Run(); | 167 callback_.Run(); |
| 168 callback_.Reset(); | 168 callback_.Reset(); |
| 169 } | 169 } |
| 170 | 170 |
| 171 // Pretend we downloaded initial updates and set initial sync ended bits | 171 // Pretend we downloaded initial updates and set initial sync ended bits |
| 172 // if we were asked to. | 172 // if we were asked to. |
| 173 if (set_initial_sync_ended_on_init_) { | 173 if (set_initial_sync_ended_on_init_) { |
| 174 UserShare* user_share = GetUserShare(); | 174 UserShare* user_share = GetUserShare(); |
| 175 Directory* directory = user_share->directory.get(); | 175 Directory* directory = user_share->directory.get(); |
| 176 | 176 |
| 177 if (!directory->initial_sync_ended_for_type(syncable::NIGORI)) { | 177 if (!directory->initial_sync_ended_for_type(syncer::NIGORI)) { |
| 178 ProfileSyncServiceTestHelper::CreateRoot( | 178 ProfileSyncServiceTestHelper::CreateRoot( |
| 179 syncable::NIGORI, GetUserShare(), | 179 syncer::NIGORI, GetUserShare(), |
| 180 id_factory()); | 180 id_factory()); |
| 181 | 181 |
| 182 // A side effect of adding the NIGORI mode (normally done by the | 182 // A side effect of adding the NIGORI mode (normally done by the |
| 183 // syncer) is a decryption attempt, which will fail the first time. | 183 // syncer) is a decryption attempt, which will fail the first time. |
| 184 send_passphrase_required = true; | 184 send_passphrase_required = true; |
| 185 } | 185 } |
| 186 | 186 |
| 187 SetInitialSyncEndedForAllTypes(); | 187 SetInitialSyncEndedForAllTypes(); |
| 188 } | 188 } |
| 189 } | 189 } |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 void TestProfileSyncService::CreateBackend() { | 225 void TestProfileSyncService::CreateBackend() { |
| 226 backend_.reset(new browser_sync::SyncBackendHostForProfileSyncTest( | 226 backend_.reset(new browser_sync::SyncBackendHostForProfileSyncTest( |
| 227 profile(), | 227 profile(), |
| 228 sync_prefs_.AsWeakPtr(), | 228 sync_prefs_.AsWeakPtr(), |
| 229 invalidator_storage_.AsWeakPtr(), | 229 invalidator_storage_.AsWeakPtr(), |
| 230 set_initial_sync_ended_on_init_, | 230 set_initial_sync_ended_on_init_, |
| 231 synchronous_backend_initialization_, | 231 synchronous_backend_initialization_, |
| 232 fail_initial_download_, | 232 fail_initial_download_, |
| 233 use_real_database_)); | 233 use_real_database_)); |
| 234 } | 234 } |
| OLD | NEW |