Index: chrome/browser/sync/test_profile_sync_service.cc |
diff --git a/chrome/browser/sync/test_profile_sync_service.cc b/chrome/browser/sync/test_profile_sync_service.cc |
index bab5d7dc968f8a2830305aa89012e4debda5cf10..6e346d9e06adec218d062883164d35733d0992e3 100644 |
--- a/chrome/browser/sync/test_profile_sync_service.cc |
+++ b/chrome/browser/sync/test_profile_sync_service.cc |
@@ -5,22 +5,42 @@ |
#include "chrome/browser/sync/test_profile_sync_service.h" |
#include "chrome/browser/sync/abstract_profile_sync_service_test.h" |
+#include "chrome/browser/sync/engine/syncapi.h" |
+#include "chrome/browser/sync/glue/data_type_controller.h" |
+#include "chrome/browser/sync/glue/sync_backend_host.h" |
+#include "chrome/browser/sync/profile_sync_factory.h" |
+#include "chrome/browser/sync/sessions/session_state.h" |
+#include "chrome/browser/sync/syncable/directory_manager.h" |
+#include "chrome/browser/sync/syncable/syncable.h" |
+#include "chrome/test/sync/test_http_bridge_factory.h" |
+ |
+using browser_sync::ModelSafeRoutingInfo; |
+using browser_sync::sessions::ErrorCounters; |
+using browser_sync::sessions::SyncerStatus; |
+using browser_sync::sessions::SyncSessionSnapshot; |
+using syncable::DirectoryManager; |
+using syncable::ModelType; |
+using syncable::ScopedDirLookup; |
+using sync_api::UserShare; |
+ |
+ACTION_P(CallOnPaused, core) { |
+ core->OnPaused(); |
+}; |
+ |
+ACTION_P(CallOnResumed, core) { |
+ core->OnResumed(); |
+} |
namespace browser_sync { |
SyncBackendHostForProfileSyncTest::SyncBackendHostForProfileSyncTest( |
- TestProfileSyncService* service, |
Profile* profile, |
- Task* initial_condition_setup_task, |
int num_expected_resumes, |
int num_expected_pauses, |
bool set_initial_sync_ended_on_init, |
bool synchronous_init) |
- : browser_sync::SyncBackendHost(service, profile), |
- initial_condition_setup_task_(initial_condition_setup_task), |
- set_initial_sync_ended_on_init_(set_initial_sync_ended_on_init), |
- synchronous_init_(synchronous_init), |
- test_service_(service) { |
+ : browser_sync::SyncBackendHost(profile), |
+ synchronous_init_(synchronous_init) { |
// By default, the RequestPause and RequestResume methods will |
// send the confirmation notification and return true. |
ON_CALL(*this, RequestPause()). |
@@ -40,20 +60,129 @@ SyncBackendHostForProfileSyncTest::SyncBackendHostForProfileSyncTest( |
RequestNudge()).Times(set_initial_sync_ended_on_init ? 0 : 1); |
} |
-void |
-SyncBackendHostForProfileSyncTest:: |
- HandleInitializationCompletedOnFrontendLoop() { |
- set_syncapi_initialized(); // Need to do this asap so task below works. |
+void SyncBackendHostForProfileSyncTest::ConfigureDataTypes( |
+ const DataTypeController::TypeMap& data_type_controllers, |
+ const syncable::ModelTypeSet& types, |
+ CancelableTask* ready_task) { |
+ SetAutofillMigrationState(syncable::MIGRATED); |
+ SyncBackendHost::ConfigureDataTypes( |
+ data_type_controllers, types, ready_task); |
+} |
+ |
+void SyncBackendHostForProfileSyncTest:: |
+ SimulateSyncCycleCompletedInitialSyncEnded() { |
+ syncable::ModelTypeBitSet sync_ended; |
+ ModelSafeRoutingInfo enabled_types; |
+ GetModelSafeRoutingInfo(&enabled_types); |
+ std::string download_progress_markers[syncable::MODEL_TYPE_COUNT]; |
+ for (ModelSafeRoutingInfo::const_iterator i = enabled_types.begin(); |
+ i != enabled_types.end(); ++i) { |
+ sync_ended.set(i->first); |
+ } |
+ core_->HandleSyncCycleCompletedOnFrontendLoop(new SyncSessionSnapshot( |
+ SyncerStatus(), ErrorCounters(), 0, false, |
+ sync_ended, download_progress_markers, false, false, 0, 0, false)); |
+} |
+ |
+sync_api::HttpPostProviderFactory* |
+ SyncBackendHostForProfileSyncTest::MakeHttpBridgeFactory( |
+ URLRequestContextGetter* getter) { |
+ return new browser_sync::TestHttpBridgeFactory; |
+} |
+ |
+void SyncBackendHostForProfileSyncTest::InitCore( |
+ const Core::DoInitializeOptions& options) { |
+ std::wstring user = L"testuser"; |
+ core_loop()->PostTask( |
+ FROM_HERE, |
+ NewRunnableMethod(core_.get(), |
+ &SyncBackendHost::Core::DoInitializeForTest, |
+ user, |
+ options.http_bridge_factory, |
+ options.delete_sync_data_folder)); |
+ |
+ // TODO(akalin): Figure out a better way to do this. |
+ if (synchronous_init_) { |
+ // The SyncBackend posts a task to the current loop when |
+ // initialization completes. |
+ MessageLoop::current()->Run(); |
+ } |
+} |
+ |
+void SyncBackendHostForProfileSyncTest:: |
+ SetDefaultExpectationsForWorkerCreation(ProfileMock* profile) { |
+ EXPECT_CALL(*profile, GetPasswordStore(testing::_)). |
+ WillOnce(testing::Return((PasswordStore*)NULL)); |
+} |
+ |
+void SyncBackendHostForProfileSyncTest::SetHistoryServiceExpectations( |
+ ProfileMock* profile) { |
+ EXPECT_CALL(*profile, GetHistoryService(testing::_)). |
+ WillOnce(testing::Return((HistoryService*)NULL)); |
+} |
+ |
+} // namespace browser_sync |
+ |
+browser_sync::TestIdFactory* TestProfileSyncService::id_factory() { |
+ return &id_factory_; |
+} |
+ |
+browser_sync::SyncBackendHostForProfileSyncTest* |
+ TestProfileSyncService::GetTestBackend() { |
+ return static_cast<browser_sync::SyncBackendHostForProfileSyncTest*>( |
+ GetBackendForTest()); |
+} |
+ |
+TestProfileSyncService::TestProfileSyncService( |
+ ProfileSyncFactory* factory, |
+ Profile* profile, |
+ const std::string& test_user, |
+ bool synchronous_backend_initialization, |
+ Task* initial_condition_setup_task) |
+ : ProfileSyncService(factory, profile, test_user), |
+ synchronous_backend_initialization_( |
+ synchronous_backend_initialization), |
+ synchronous_sync_configuration_(false), |
+ num_expected_resumes_(1), |
+ num_expected_pauses_(1), |
+ initial_condition_setup_task_(initial_condition_setup_task), |
+ set_initial_sync_ended_on_init_(true) { |
+ RegisterPreferences(); |
+ SetSyncSetupCompleted(); |
+} |
+ |
+TestProfileSyncService::~TestProfileSyncService() {} |
+ |
+void TestProfileSyncService::SetInitialSyncEndedForEnabledTypes() { |
+ UserShare* user_share = GetUserShareHandle(); |
+ DirectoryManager* dir_manager = user_share->dir_manager.get(); |
+ |
+ ScopedDirLookup dir(dir_manager, user_share->name); |
+ if (!dir.good()) |
+ FAIL(); |
+ |
+ ModelSafeRoutingInfo enabled_types; |
+ backend_->GetModelSafeRoutingInfo(&enabled_types); |
+ for (ModelSafeRoutingInfo::const_iterator i = enabled_types.begin(); |
+ i != enabled_types.end(); ++i) { |
+ dir->set_initial_sync_ended_for_type(i->first, true); |
+ } |
+} |
+ |
+void TestProfileSyncService::OnBackendInitialized() { |
+ // Set this so below code can access GetUserShare(). |
+ backend_initialized_ = true; |
// Set up any nodes the test wants around before model association. |
if (initial_condition_setup_task_) { |
initial_condition_setup_task_->Run(); |
+ initial_condition_setup_task_ = NULL; |
} |
// Pretend we downloaded initial updates and set initial sync ended bits |
// if we were asked to. |
if (set_initial_sync_ended_on_init_) { |
- UserShare* user_share = core_->syncapi()->GetUserShare(); |
+ UserShare* user_share = GetUserShareHandle(); |
DirectoryManager* dir_manager = user_share->dir_manager.get(); |
ScopedDirLookup dir(dir_manager, user_share->name); |
@@ -62,22 +191,52 @@ SyncBackendHostForProfileSyncTest:: |
if (!dir->initial_sync_ended_for_type(syncable::NIGORI)) { |
ProfileSyncServiceTestHelper::CreateRoot( |
- syncable::NIGORI, test_service_, test_service_->id_factory()); |
+ syncable::NIGORI, GetUserShareHandle(), |
+ id_factory()); |
} |
SetInitialSyncEndedForEnabledTypes(); |
} |
- SyncBackendHost::HandleInitializationCompletedOnFrontendLoop(); |
+ ProfileSyncService::OnBackendInitialized(); |
+ |
+ // TODO(akalin): Figure out a better way to do this. |
+ if (synchronous_backend_initialization_) { |
+ MessageLoop::current()->Quit(); |
+ } |
} |
-} // namespace browser_sync |
+void TestProfileSyncService::Observe(NotificationType type, |
+ const NotificationSource& source, |
+ const NotificationDetails& details) { |
+ ProfileSyncService::Observe(type, source, details); |
+ if (type == NotificationType::SYNC_CONFIGURE_DONE && |
+ !synchronous_sync_configuration_) { |
+ MessageLoop::current()->Quit(); |
+ } |
+} |
+ |
+void TestProfileSyncService::set_num_expected_resumes(int times) { |
+ num_expected_resumes_ = times; |
+} |
+void TestProfileSyncService::set_num_expected_pauses(int num) { |
+ num_expected_pauses_ = num; |
+} |
+void TestProfileSyncService::dont_set_initial_sync_ended_on_init() { |
+ set_initial_sync_ended_on_init_ = false; |
+} |
+void TestProfileSyncService::set_synchronous_sync_configuration() { |
+ synchronous_sync_configuration_ = true; |
+} |
void TestProfileSyncService::CreateBackend() { |
backend_.reset(new browser_sync::SyncBackendHostForProfileSyncTest( |
- this, profile(), |
- initial_condition_setup_task_.release(), |
+ profile(), |
num_expected_resumes_, num_expected_pauses_, |
set_initial_sync_ended_on_init_, |
synchronous_backend_initialization_)); |
} |
+ |
+std::string TestProfileSyncService::GetLsidForAuthBootstraping() { |
+ return "foo"; |
+} |