Add ICU message format support
[chromium-blink-merge.git] / chrome / browser / sync / test_profile_sync_service.cc
blob1233540abb145be6df1b3336d49e9d0e5c9d82c0
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
3 // found in the LICENSE file.
5 #include "chrome/browser/sync/test_profile_sync_service.h"
7 #include "base/location.h"
8 #include "base/memory/scoped_ptr.h"
9 #include "base/single_thread_task_runner.h"
10 #include "base/thread_task_runner_handle.h"
11 #include "chrome/browser/chrome_notification_types.h"
12 #include "chrome/browser/invalidation/profile_invalidation_provider_factory.h"
13 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
15 #include "chrome/browser/signin/signin_manager_factory.h"
16 #include "chrome/browser/sync/glue/sync_backend_host.h"
17 #include "chrome/browser/sync/glue/sync_backend_host_core.h"
18 #include "chrome/browser/sync/profile_sync_components_factory.h"
19 #include "chrome/browser/sync/profile_sync_components_factory_mock.h"
20 #include "chrome/browser/sync/profile_sync_service_factory.h"
21 #include "chrome/browser/sync/supervised_user_signin_manager_wrapper.h"
22 #include "chrome/browser/sync/test/test_http_bridge_factory.h"
23 #include "components/invalidation/impl/profile_invalidation_provider.h"
24 #include "components/signin/core/browser/signin_manager.h"
25 #include "google_apis/gaia/gaia_constants.h"
26 #include "sync/internal_api/public/test/sync_manager_factory_for_profile_sync_test.h"
27 #include "sync/internal_api/public/test/test_internal_components_factory.h"
28 #include "sync/internal_api/public/user_share.h"
29 #include "sync/protocol/encryption.pb.h"
30 #include "testing/gmock/include/gmock/gmock.h"
32 using syncer::InternalComponentsFactory;
33 using syncer::TestInternalComponentsFactory;
34 using syncer::UserShare;
36 namespace browser_sync {
38 SyncBackendHostForProfileSyncTest::SyncBackendHostForProfileSyncTest(
39 Profile* profile,
40 invalidation::InvalidationService* invalidator,
41 const base::WeakPtr<sync_driver::SyncPrefs>& sync_prefs,
42 base::Closure callback)
43 : browser_sync::SyncBackendHostImpl(
44 profile->GetDebugName(), profile, invalidator,
45 sync_prefs, base::FilePath(FILE_PATH_LITERAL("test"))),
46 callback_(callback) {}
48 SyncBackendHostForProfileSyncTest::~SyncBackendHostForProfileSyncTest() {}
50 void SyncBackendHostForProfileSyncTest::InitCore(
51 scoped_ptr<DoInitializeOptions> options) {
52 options->http_bridge_factory =
53 scoped_ptr<syncer::HttpPostProviderFactory>(
54 new browser_sync::TestHttpBridgeFactory());
55 options->sync_manager_factory.reset(
56 new syncer::SyncManagerFactoryForProfileSyncTest(callback_));
57 options->credentials.email = "testuser@gmail.com";
58 options->credentials.sync_token = "token";
59 options->credentials.scope_set.insert(GaiaConstants::kChromeSyncOAuth2Scope);
60 options->restored_key_for_bootstrapping = "";
62 // It'd be nice if we avoided creating the InternalComponentsFactory in the
63 // first place, but SyncBackendHost will have created one by now so we must
64 // free it. Grab the switches to pass on first.
65 InternalComponentsFactory::Switches factory_switches =
66 options->internal_components_factory->GetSwitches();
67 options->internal_components_factory.reset(
68 new TestInternalComponentsFactory(
69 factory_switches, InternalComponentsFactory::STORAGE_IN_MEMORY,
70 NULL));
72 SyncBackendHostImpl::InitCore(options.Pass());
75 void SyncBackendHostForProfileSyncTest::RequestConfigureSyncer(
76 syncer::ConfigureReason reason,
77 syncer::ModelTypeSet to_download,
78 syncer::ModelTypeSet to_purge,
79 syncer::ModelTypeSet to_journal,
80 syncer::ModelTypeSet to_unapply,
81 syncer::ModelTypeSet to_ignore,
82 const syncer::ModelSafeRoutingInfo& routing_info,
83 const base::Callback<void(syncer::ModelTypeSet,
84 syncer::ModelTypeSet)>& ready_task,
85 const base::Closure& retry_callback) {
86 syncer::ModelTypeSet failed_configuration_types;
88 // The first parameter there should be the set of enabled types. That's not
89 // something we have access to from this strange test harness. We'll just
90 // send back the list of newly configured types instead and hope it doesn't
91 // break anything.
92 // Posted to avoid re-entrancy issues.
93 base::ThreadTaskRunnerHandle::Get()->PostTask(
94 FROM_HERE,
95 base::Bind(&SyncBackendHostForProfileSyncTest::
96 FinishConfigureDataTypesOnFrontendLoop,
97 base::Unretained(this),
98 syncer::Difference(to_download, failed_configuration_types),
99 syncer::Difference(to_download, failed_configuration_types),
100 failed_configuration_types, ready_task));
103 } // namespace browser_sync
105 syncer::TestIdFactory* TestProfileSyncService::id_factory() {
106 return &id_factory_;
109 syncer::WeakHandle<syncer::JsEventHandler>
110 TestProfileSyncService::GetJsEventHandler() {
111 return syncer::WeakHandle<syncer::JsEventHandler>();
114 TestProfileSyncService::TestProfileSyncService(
115 scoped_ptr<ProfileSyncComponentsFactory> factory,
116 Profile* profile,
117 SigninManagerBase* signin,
118 ProfileOAuth2TokenService* oauth2_token_service,
119 browser_sync::ProfileSyncServiceStartBehavior behavior)
120 : ProfileSyncService(
121 factory.Pass(),
122 profile,
123 make_scoped_ptr(new SupervisedUserSigninManagerWrapper(profile,
124 signin)),
125 oauth2_token_service,
126 behavior) {
127 SetSyncSetupCompleted();
130 TestProfileSyncService::~TestProfileSyncService() {
133 // static
134 scoped_ptr<KeyedService> TestProfileSyncService::TestFactoryFunction(
135 content::BrowserContext* context) {
136 Profile* profile = static_cast<Profile*>(context);
137 SigninManagerBase* signin =
138 SigninManagerFactory::GetForProfile(profile);
139 ProfileOAuth2TokenService* oauth2_token_service =
140 ProfileOAuth2TokenServiceFactory::GetForProfile(profile);
141 return make_scoped_ptr(new TestProfileSyncService(
142 scoped_ptr<ProfileSyncComponentsFactory>(
143 new ProfileSyncComponentsFactoryMock()),
144 profile, signin, oauth2_token_service, browser_sync::AUTO_START));
147 // static
148 TestProfileSyncService* TestProfileSyncService::BuildAutoStartAsyncInit(
149 Profile* profile, base::Closure callback) {
150 TestProfileSyncService* sync_service = static_cast<TestProfileSyncService*>(
151 ProfileSyncServiceFactory::GetInstance()->SetTestingFactoryAndUse(
152 profile, &TestProfileSyncService::TestFactoryFunction));
153 ProfileSyncComponentsFactoryMock* components =
154 sync_service->components_factory_mock();
155 // TODO(tim): Convert to a fake instead of mock.
156 EXPECT_CALL(*components,
157 CreateSyncBackendHost(testing::_,testing::_, testing::_,
158 testing::_, testing::_)).
159 WillOnce(testing::Return(
160 new browser_sync::SyncBackendHostForProfileSyncTest(
161 profile,
162 invalidation::ProfileInvalidationProviderFactory::GetForProfile(
163 profile)->GetInvalidationService(),
164 sync_service->sync_prefs_.AsWeakPtr(),
165 callback)));
166 return sync_service;
169 ProfileSyncComponentsFactoryMock*
170 TestProfileSyncService::components_factory_mock() {
171 // We always create a mock factory, see Build* routines.
172 return static_cast<ProfileSyncComponentsFactoryMock*>(factory());
175 void TestProfileSyncService::OnConfigureDone(
176 const sync_driver::DataTypeManager::ConfigureResult& result) {
177 ProfileSyncService::OnConfigureDone(result);
178 base::MessageLoop::current()->Quit();
181 UserShare* TestProfileSyncService::GetUserShare() const {
182 return backend_->GetUserShare();
185 bool TestProfileSyncService::NeedBackup() const {
186 return false;