Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(334)

Side by Side Diff: components/browser_sync/profile_sync_service_startup_unittest.cc

Issue 2388163002: [Sync] Move //components/sync to the syncer namespace, take 2. (Closed)
Patch Set: Rebase. Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <memory> 5 #include <memory>
6 #include <utility> 6 #include <utility>
7 7
8 #include "base/files/file_util.h" 8 #include "base/files/file_util.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "base/threading/thread_task_runner_handle.h" 10 #include "base/threading/thread_task_runner_handle.h"
(...skipping 15 matching lines...) Expand all
26 #include "components/sync/driver/sync_prefs.h" 26 #include "components/sync/driver/sync_prefs.h"
27 #include "components/sync/driver/sync_service_observer.h" 27 #include "components/sync/driver/sync_service_observer.h"
28 #include "components/syncable_prefs/pref_service_syncable.h" 28 #include "components/syncable_prefs/pref_service_syncable.h"
29 #include "google_apis/gaia/gaia_auth_consumer.h" 29 #include "google_apis/gaia/gaia_auth_consumer.h"
30 #include "google_apis/gaia/gaia_constants.h" 30 #include "google_apis/gaia/gaia_constants.h"
31 #include "google_apis/gaia/oauth2_token_service.h" 31 #include "google_apis/gaia/oauth2_token_service.h"
32 #include "net/url_request/url_request_test_util.h" 32 #include "net/url_request/url_request_test_util.h"
33 #include "testing/gmock/include/gmock/gmock.h" 33 #include "testing/gmock/include/gmock/gmock.h"
34 #include "testing/gtest/include/gtest/gtest.h" 34 #include "testing/gtest/include/gtest/gtest.h"
35 35
36 using sync_driver::DataTypeManager; 36 using syncer::DataTypeManager;
37 using sync_driver::DataTypeManagerMock; 37 using syncer::DataTypeManagerMock;
38 using syncer::SyncBackendHostMock;
38 using testing::_; 39 using testing::_;
39 using testing::AnyNumber; 40 using testing::AnyNumber;
40 using testing::DoAll; 41 using testing::DoAll;
41 using testing::Mock; 42 using testing::Mock;
42 using testing::Return; 43 using testing::Return;
43 44
44 namespace browser_sync { 45 namespace browser_sync {
45 46
46 namespace { 47 namespace {
47 48
48 const char kGaiaId[] = "12345"; 49 const char kGaiaId[] = "12345";
49 const char kEmail[] = "test_user@gmail.com"; 50 const char kEmail[] = "test_user@gmail.com";
50 const char kDummyPassword[] = ""; 51 const char kDummyPassword[] = "";
51 52
52 class SyncServiceObserverMock : public sync_driver::SyncServiceObserver { 53 class SyncServiceObserverMock : public syncer::SyncServiceObserver {
53 public: 54 public:
54 SyncServiceObserverMock(); 55 SyncServiceObserverMock();
55 virtual ~SyncServiceObserverMock(); 56 virtual ~SyncServiceObserverMock();
56 57
57 MOCK_METHOD0(OnStateChanged, void()); 58 MOCK_METHOD0(OnStateChanged, void());
58 }; 59 };
59 60
60 SyncServiceObserverMock::SyncServiceObserverMock() {} 61 SyncServiceObserverMock::SyncServiceObserverMock() {}
61 62
62 SyncServiceObserverMock::~SyncServiceObserverMock() {} 63 SyncServiceObserverMock::~SyncServiceObserverMock() {}
63 64
64 } // namespace 65 } // namespace
65 66
66 ACTION_P(InvokeOnConfigureStart, sync_service) { 67 ACTION_P(InvokeOnConfigureStart, sync_service) {
67 sync_service->OnConfigureStart(); 68 sync_service->OnConfigureStart();
68 } 69 }
69 70
70 ACTION_P3(InvokeOnConfigureDone, sync_service, error_callback, result) { 71 ACTION_P3(InvokeOnConfigureDone, sync_service, error_callback, result) {
71 DataTypeManager::ConfigureResult configure_result = 72 DataTypeManager::ConfigureResult configure_result =
72 static_cast<DataTypeManager::ConfigureResult>(result); 73 static_cast<DataTypeManager::ConfigureResult>(result);
73 if (result.status == sync_driver::DataTypeManager::ABORTED) 74 if (result.status == syncer::DataTypeManager::ABORTED)
74 error_callback.Run(&configure_result); 75 error_callback.Run(&configure_result);
75 sync_service->OnConfigureDone(configure_result); 76 sync_service->OnConfigureDone(configure_result);
76 } 77 }
77 78
78 class ProfileSyncServiceStartupTest : public testing::Test { 79 class ProfileSyncServiceStartupTest : public testing::Test {
79 public: 80 public:
80 ProfileSyncServiceStartupTest() { 81 ProfileSyncServiceStartupTest() {
81 profile_sync_service_bundle_.auth_service() 82 profile_sync_service_bundle_.auth_service()
82 ->set_auto_post_fetch_response_on_message_loop(true); 83 ->set_auto_post_fetch_response_on_message_loop(true);
83 } 84 }
84 85
85 ~ProfileSyncServiceStartupTest() override { 86 ~ProfileSyncServiceStartupTest() override {
86 sync_service_->RemoveObserver(&observer_); 87 sync_service_->RemoveObserver(&observer_);
87 sync_service_->Shutdown(); 88 sync_service_->Shutdown();
88 } 89 }
89 90
90 void CreateSyncService(ProfileSyncService::StartBehavior start_behavior) { 91 void CreateSyncService(ProfileSyncService::StartBehavior start_behavior) {
91 component_factory_ = profile_sync_service_bundle_.component_factory(); 92 component_factory_ = profile_sync_service_bundle_.component_factory();
92 ProfileSyncServiceBundle::SyncClientBuilder builder( 93 ProfileSyncServiceBundle::SyncClientBuilder builder(
93 &profile_sync_service_bundle_); 94 &profile_sync_service_bundle_);
94 ProfileSyncService::InitParams init_params = 95 ProfileSyncService::InitParams init_params =
95 profile_sync_service_bundle_.CreateBasicInitParams(start_behavior, 96 profile_sync_service_bundle_.CreateBasicInitParams(start_behavior,
96 builder.Build()); 97 builder.Build());
97 98
98 sync_service_.reset(new ProfileSyncService(std::move(init_params))); 99 sync_service_.reset(new ProfileSyncService(std::move(init_params)));
99 sync_service_->RegisterDataTypeController( 100 sync_service_->RegisterDataTypeController(
100 base::MakeUnique<sync_driver::FakeDataTypeController>( 101 base::MakeUnique<syncer::FakeDataTypeController>(syncer::BOOKMARKS));
101 syncer::BOOKMARKS));
102 sync_service_->AddObserver(&observer_); 102 sync_service_->AddObserver(&observer_);
103 } 103 }
104 104
105 void IssueTestTokens(const std::string& account_id) { 105 void IssueTestTokens(const std::string& account_id) {
106 profile_sync_service_bundle_.auth_service()->UpdateCredentials( 106 profile_sync_service_bundle_.auth_service()->UpdateCredentials(
107 account_id, "oauth2_login_token"); 107 account_id, "oauth2_login_token");
108 } 108 }
109 109
110 void SetError(DataTypeManager::ConfigureResult* result) { 110 void SetError(DataTypeManager::ConfigureResult* result) {
111 sync_driver::DataTypeStatusTable::TypeErrorMap errors; 111 syncer::DataTypeStatusTable::TypeErrorMap errors;
112 errors[syncer::BOOKMARKS] = 112 errors[syncer::BOOKMARKS] =
113 syncer::SyncError(FROM_HERE, syncer::SyncError::UNRECOVERABLE_ERROR, 113 syncer::SyncError(FROM_HERE, syncer::SyncError::UNRECOVERABLE_ERROR,
114 "Error", syncer::BOOKMARKS); 114 "Error", syncer::BOOKMARKS);
115 result->data_type_status_table.UpdateFailedDataTypes(errors); 115 result->data_type_status_table.UpdateFailedDataTypes(errors);
116 } 116 }
117 117
118 protected: 118 protected:
119 std::string SimulateTestUserSignin(ProfileSyncService* sync_service) { 119 std::string SimulateTestUserSignin(ProfileSyncService* sync_service) {
120 std::string account_id = 120 std::string account_id =
121 profile_sync_service_bundle_.account_tracker()->SeedAccountInfo(kGaiaId, 121 profile_sync_service_bundle_.account_tracker()->SeedAccountInfo(kGaiaId,
(...skipping 26 matching lines...) Expand all
148 } 148 }
149 149
150 PrefService* pref_service() { 150 PrefService* pref_service() {
151 return profile_sync_service_bundle_.pref_service(); 151 return profile_sync_service_bundle_.pref_service();
152 } 152 }
153 153
154 base::MessageLoop message_loop_; 154 base::MessageLoop message_loop_;
155 ProfileSyncServiceBundle profile_sync_service_bundle_; 155 ProfileSyncServiceBundle profile_sync_service_bundle_;
156 std::unique_ptr<ProfileSyncService> sync_service_; 156 std::unique_ptr<ProfileSyncService> sync_service_;
157 SyncServiceObserverMock observer_; 157 SyncServiceObserverMock observer_;
158 sync_driver::DataTypeStatusTable data_type_status_table_; 158 syncer::DataTypeStatusTable data_type_status_table_;
159 SyncApiComponentFactoryMock* component_factory_ = nullptr; 159 syncer::SyncApiComponentFactoryMock* component_factory_ = nullptr;
160 }; 160 };
161 161
162 class ProfileSyncServiceStartupCrosTest : public ProfileSyncServiceStartupTest { 162 class ProfileSyncServiceStartupCrosTest : public ProfileSyncServiceStartupTest {
163 public: 163 public:
164 ProfileSyncServiceStartupCrosTest() { 164 ProfileSyncServiceStartupCrosTest() {
165 CreateSyncService(ProfileSyncService::AUTO_START); 165 CreateSyncService(ProfileSyncService::AUTO_START);
166 SimulateTestUserSignin(nullptr); 166 SimulateTestUserSignin(nullptr);
167 EXPECT_TRUE( 167 EXPECT_TRUE(
168 profile_sync_service_bundle_.signin_manager()->IsAuthenticated()); 168 profile_sync_service_bundle_.signin_manager()->IsAuthenticated());
169 } 169 }
170 }; 170 };
171 171
172 TEST_F(ProfileSyncServiceStartupTest, StartFirstTime) { 172 TEST_F(ProfileSyncServiceStartupTest, StartFirstTime) {
173 // We've never completed startup. 173 // We've never completed startup.
174 pref_service()->ClearPref(sync_driver::prefs::kSyncFirstSetupComplete); 174 pref_service()->ClearPref(syncer::prefs::kSyncFirstSetupComplete);
175 CreateSyncService(ProfileSyncService::MANUAL_START); 175 CreateSyncService(ProfileSyncService::MANUAL_START);
176 SetUpSyncBackendHost(); 176 SetUpSyncBackendHost();
177 DataTypeManagerMock* data_type_manager = SetUpDataTypeManager(); 177 DataTypeManagerMock* data_type_manager = SetUpDataTypeManager();
178 EXPECT_CALL(*data_type_manager, Configure(_, _)).Times(0); 178 EXPECT_CALL(*data_type_manager, Configure(_, _)).Times(0);
179 179
180 // Should not actually start, rather just clean things up and wait 180 // Should not actually start, rather just clean things up and wait
181 // to be enabled. 181 // to be enabled.
182 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); 182 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber());
183 sync_service_->Initialize(); 183 sync_service_->Initialize();
184 184
185 // Preferences should be back to defaults. 185 // Preferences should be back to defaults.
186 EXPECT_EQ(0, 186 EXPECT_EQ(0, pref_service()->GetInt64(syncer::prefs::kSyncLastSyncedTime));
187 pref_service()->GetInt64(sync_driver::prefs::kSyncLastSyncedTime));
188 EXPECT_FALSE( 187 EXPECT_FALSE(
189 pref_service()->GetBoolean(sync_driver::prefs::kSyncFirstSetupComplete)); 188 pref_service()->GetBoolean(syncer::prefs::kSyncFirstSetupComplete));
190 Mock::VerifyAndClearExpectations(data_type_manager); 189 Mock::VerifyAndClearExpectations(data_type_manager);
191 190
192 // Then start things up. 191 // Then start things up.
193 EXPECT_CALL(*data_type_manager, Configure(_, _)).Times(1); 192 EXPECT_CALL(*data_type_manager, Configure(_, _)).Times(1);
194 EXPECT_CALL(*data_type_manager, state()) 193 EXPECT_CALL(*data_type_manager, state())
195 .WillOnce(Return(DataTypeManager::CONFIGURED)) 194 .WillOnce(Return(DataTypeManager::CONFIGURED))
196 .WillOnce(Return(DataTypeManager::CONFIGURED)); 195 .WillOnce(Return(DataTypeManager::CONFIGURED));
197 EXPECT_CALL(*data_type_manager, Stop()).Times(1); 196 EXPECT_CALL(*data_type_manager, Stop()).Times(1);
198 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); 197 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber());
199 198
200 auto sync_blocker = sync_service_->GetSetupInProgressHandle(); 199 auto sync_blocker = sync_service_->GetSetupInProgressHandle();
201 200
202 // Simulate successful signin as test_user. 201 // Simulate successful signin as test_user.
203 std::string account_id = SimulateTestUserSignin(sync_service_.get()); 202 std::string account_id = SimulateTestUserSignin(sync_service_.get());
204 // Create some tokens in the token service. 203 // Create some tokens in the token service.
205 IssueTestTokens(account_id); 204 IssueTestTokens(account_id);
206 205
207 // Simulate the UI telling sync it has finished setting up. 206 // Simulate the UI telling sync it has finished setting up.
208 sync_blocker.reset(); 207 sync_blocker.reset();
209 sync_service_->SetFirstSetupComplete(); 208 sync_service_->SetFirstSetupComplete();
210 EXPECT_TRUE(sync_service_->IsSyncActive()); 209 EXPECT_TRUE(sync_service_->IsSyncActive());
211 } 210 }
212 211
213 // TODO(pavely): Reenable test once android is switched to oauth2. 212 // TODO(pavely): Reenable test once android is switched to oauth2.
214 TEST_F(ProfileSyncServiceStartupTest, DISABLED_StartNoCredentials) { 213 TEST_F(ProfileSyncServiceStartupTest, DISABLED_StartNoCredentials) {
215 // We've never completed startup. 214 // We've never completed startup.
216 pref_service()->ClearPref(sync_driver::prefs::kSyncFirstSetupComplete); 215 pref_service()->ClearPref(syncer::prefs::kSyncFirstSetupComplete);
217 CreateSyncService(ProfileSyncService::MANUAL_START); 216 CreateSyncService(ProfileSyncService::MANUAL_START);
218 217
219 // Should not actually start, rather just clean things up and wait 218 // Should not actually start, rather just clean things up and wait
220 // to be enabled. 219 // to be enabled.
221 EXPECT_CALL(*component_factory_, CreateDataTypeManager(_, _, _, _, _)) 220 EXPECT_CALL(*component_factory_, CreateDataTypeManager(_, _, _, _, _))
222 .Times(0); 221 .Times(0);
223 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); 222 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber());
224 sync_service_->Initialize(); 223 sync_service_->Initialize();
225 224
226 // Preferences should be back to defaults. 225 // Preferences should be back to defaults.
227 EXPECT_EQ(0, 226 EXPECT_EQ(0, pref_service()->GetInt64(syncer::prefs::kSyncLastSyncedTime));
228 pref_service()->GetInt64(sync_driver::prefs::kSyncLastSyncedTime));
229 EXPECT_FALSE( 227 EXPECT_FALSE(
230 pref_service()->GetBoolean(sync_driver::prefs::kSyncFirstSetupComplete)); 228 pref_service()->GetBoolean(syncer::prefs::kSyncFirstSetupComplete));
231 229
232 // Then start things up. 230 // Then start things up.
233 auto sync_blocker = sync_service_->GetSetupInProgressHandle(); 231 auto sync_blocker = sync_service_->GetSetupInProgressHandle();
234 232
235 // Simulate successful signin as test_user. 233 // Simulate successful signin as test_user.
236 std::string account_id = SimulateTestUserSignin(sync_service_.get()); 234 std::string account_id = SimulateTestUserSignin(sync_service_.get());
237 235
238 profile_sync_service_bundle_.auth_service()->LoadCredentials(account_id); 236 profile_sync_service_bundle_.auth_service()->LoadCredentials(account_id);
239 237
240 sync_blocker.reset(); 238 sync_blocker.reset();
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 sync_blocker.reset(); 275 sync_blocker.reset();
278 276
279 // Verify we successfully finish startup and configuration. 277 // Verify we successfully finish startup and configuration.
280 EXPECT_TRUE(sync_service_->IsSyncActive()); 278 EXPECT_TRUE(sync_service_->IsSyncActive());
281 } 279 }
282 280
283 TEST_F(ProfileSyncServiceStartupCrosTest, StartCrosNoCredentials) { 281 TEST_F(ProfileSyncServiceStartupCrosTest, StartCrosNoCredentials) {
284 EXPECT_CALL(*component_factory_, CreateDataTypeManager(_, _, _, _, _)) 282 EXPECT_CALL(*component_factory_, CreateDataTypeManager(_, _, _, _, _))
285 .Times(0); 283 .Times(0);
286 EXPECT_CALL(*component_factory_, CreateSyncBackendHost(_, _, _, _)).Times(0); 284 EXPECT_CALL(*component_factory_, CreateSyncBackendHost(_, _, _, _)).Times(0);
287 pref_service()->ClearPref(sync_driver::prefs::kSyncFirstSetupComplete); 285 pref_service()->ClearPref(syncer::prefs::kSyncFirstSetupComplete);
288 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); 286 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber());
289 287
290 sync_service_->Initialize(); 288 sync_service_->Initialize();
291 // Sync should not start because there are no tokens yet. 289 // Sync should not start because there are no tokens yet.
292 EXPECT_FALSE(sync_service_->IsSyncActive()); 290 EXPECT_FALSE(sync_service_->IsSyncActive());
293 sync_service_->SetFirstSetupComplete(); 291 sync_service_->SetFirstSetupComplete();
294 292
295 // Sync should not start because there are still no tokens. 293 // Sync should not start because there are still no tokens.
296 EXPECT_FALSE(sync_service_->IsSyncActive()); 294 EXPECT_FALSE(sync_service_->IsSyncActive());
297 } 295 }
298 296
299 TEST_F(ProfileSyncServiceStartupCrosTest, StartFirstTime) { 297 TEST_F(ProfileSyncServiceStartupCrosTest, StartFirstTime) {
300 SetUpSyncBackendHost(); 298 SetUpSyncBackendHost();
301 DataTypeManagerMock* data_type_manager = SetUpDataTypeManager(); 299 DataTypeManagerMock* data_type_manager = SetUpDataTypeManager();
302 pref_service()->ClearPref(sync_driver::prefs::kSyncFirstSetupComplete); 300 pref_service()->ClearPref(syncer::prefs::kSyncFirstSetupComplete);
303 EXPECT_CALL(*data_type_manager, Configure(_, _)); 301 EXPECT_CALL(*data_type_manager, Configure(_, _));
304 EXPECT_CALL(*data_type_manager, state()) 302 EXPECT_CALL(*data_type_manager, state())
305 .WillRepeatedly(Return(DataTypeManager::CONFIGURED)); 303 .WillRepeatedly(Return(DataTypeManager::CONFIGURED));
306 EXPECT_CALL(*data_type_manager, Stop()); 304 EXPECT_CALL(*data_type_manager, Stop());
307 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); 305 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber());
308 306
309 IssueTestTokens( 307 IssueTestTokens(
310 profile_sync_service_bundle_.account_tracker()->PickAccountIdForAccount( 308 profile_sync_service_bundle_.account_tracker()->PickAccountIdForAccount(
311 "12345", kEmail)); 309 "12345", kEmail));
312 sync_service_->Initialize(); 310 sync_service_->Initialize();
(...skipping 16 matching lines...) Expand all
329 IssueTestTokens(account_id); 327 IssueTestTokens(account_id);
330 328
331 sync_service_->Initialize(); 329 sync_service_->Initialize();
332 } 330 }
333 331
334 // Test that we can recover from a case where a bug in the code resulted in 332 // Test that we can recover from a case where a bug in the code resulted in
335 // OnUserChoseDatatypes not being properly called and datatype preferences 333 // OnUserChoseDatatypes not being properly called and datatype preferences
336 // therefore being left unset. 334 // therefore being left unset.
337 TEST_F(ProfileSyncServiceStartupTest, StartRecoverDatatypePrefs) { 335 TEST_F(ProfileSyncServiceStartupTest, StartRecoverDatatypePrefs) {
338 // Clear the datatype preference fields (simulating bug 154940). 336 // Clear the datatype preference fields (simulating bug 154940).
339 pref_service()->ClearPref(sync_driver::prefs::kSyncKeepEverythingSynced); 337 pref_service()->ClearPref(syncer::prefs::kSyncKeepEverythingSynced);
340 syncer::ModelTypeSet user_types = syncer::UserTypes(); 338 syncer::ModelTypeSet user_types = syncer::UserTypes();
341 for (syncer::ModelTypeSet::Iterator iter = user_types.First(); iter.Good(); 339 for (syncer::ModelTypeSet::Iterator iter = user_types.First(); iter.Good();
342 iter.Inc()) { 340 iter.Inc()) {
343 pref_service()->ClearPref( 341 pref_service()->ClearPref(
344 sync_driver::SyncPrefs::GetPrefNameForDataType(iter.Get())); 342 syncer::SyncPrefs::GetPrefNameForDataType(iter.Get()));
345 } 343 }
346 344
347 // Pre load the tokens 345 // Pre load the tokens
348 CreateSyncService(ProfileSyncService::MANUAL_START); 346 CreateSyncService(ProfileSyncService::MANUAL_START);
349 std::string account_id = SimulateTestUserSignin(sync_service_.get()); 347 std::string account_id = SimulateTestUserSignin(sync_service_.get());
350 sync_service_->SetFirstSetupComplete(); 348 sync_service_->SetFirstSetupComplete();
351 SetUpSyncBackendHost(); 349 SetUpSyncBackendHost();
352 DataTypeManagerMock* data_type_manager = SetUpDataTypeManager(); 350 DataTypeManagerMock* data_type_manager = SetUpDataTypeManager();
353 EXPECT_CALL(*data_type_manager, Configure(_, _)); 351 EXPECT_CALL(*data_type_manager, Configure(_, _));
354 EXPECT_CALL(*data_type_manager, state()) 352 EXPECT_CALL(*data_type_manager, state())
355 .WillRepeatedly(Return(DataTypeManager::CONFIGURED)); 353 .WillRepeatedly(Return(DataTypeManager::CONFIGURED));
356 EXPECT_CALL(*data_type_manager, Stop()).Times(1); 354 EXPECT_CALL(*data_type_manager, Stop()).Times(1);
357 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); 355 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber());
358 356
359 IssueTestTokens(account_id); 357 IssueTestTokens(account_id);
360 sync_service_->Initialize(); 358 sync_service_->Initialize();
361 359
362 EXPECT_TRUE(pref_service()->GetBoolean( 360 EXPECT_TRUE(
363 sync_driver::prefs::kSyncKeepEverythingSynced)); 361 pref_service()->GetBoolean(syncer::prefs::kSyncKeepEverythingSynced));
364 } 362 }
365 363
366 // Verify that the recovery of datatype preferences doesn't overwrite a valid 364 // Verify that the recovery of datatype preferences doesn't overwrite a valid
367 // case where only bookmarks are enabled. 365 // case where only bookmarks are enabled.
368 TEST_F(ProfileSyncServiceStartupTest, StartDontRecoverDatatypePrefs) { 366 TEST_F(ProfileSyncServiceStartupTest, StartDontRecoverDatatypePrefs) {
369 // Explicitly set Keep Everything Synced to false and have only bookmarks 367 // Explicitly set Keep Everything Synced to false and have only bookmarks
370 // enabled. 368 // enabled.
371 pref_service()->SetBoolean(sync_driver::prefs::kSyncKeepEverythingSynced, 369 pref_service()->SetBoolean(syncer::prefs::kSyncKeepEverythingSynced, false);
372 false);
373 370
374 // Pre load the tokens 371 // Pre load the tokens
375 CreateSyncService(ProfileSyncService::MANUAL_START); 372 CreateSyncService(ProfileSyncService::MANUAL_START);
376 std::string account_id = SimulateTestUserSignin(sync_service_.get()); 373 std::string account_id = SimulateTestUserSignin(sync_service_.get());
377 sync_service_->SetFirstSetupComplete(); 374 sync_service_->SetFirstSetupComplete();
378 SetUpSyncBackendHost(); 375 SetUpSyncBackendHost();
379 DataTypeManagerMock* data_type_manager = SetUpDataTypeManager(); 376 DataTypeManagerMock* data_type_manager = SetUpDataTypeManager();
380 EXPECT_CALL(*data_type_manager, Configure(_, _)); 377 EXPECT_CALL(*data_type_manager, Configure(_, _));
381 EXPECT_CALL(*data_type_manager, state()) 378 EXPECT_CALL(*data_type_manager, state())
382 .WillRepeatedly(Return(DataTypeManager::CONFIGURED)); 379 .WillRepeatedly(Return(DataTypeManager::CONFIGURED));
383 EXPECT_CALL(*data_type_manager, Stop()).Times(1); 380 EXPECT_CALL(*data_type_manager, Stop()).Times(1);
384 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); 381 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber());
385 IssueTestTokens(account_id); 382 IssueTestTokens(account_id);
386 sync_service_->Initialize(); 383 sync_service_->Initialize();
387 384
388 EXPECT_FALSE(pref_service()->GetBoolean( 385 EXPECT_FALSE(
389 sync_driver::prefs::kSyncKeepEverythingSynced)); 386 pref_service()->GetBoolean(syncer::prefs::kSyncKeepEverythingSynced));
390 } 387 }
391 388
392 TEST_F(ProfileSyncServiceStartupTest, ManagedStartup) { 389 TEST_F(ProfileSyncServiceStartupTest, ManagedStartup) {
393 // Service should not be started by Initialize() since it's managed. 390 // Service should not be started by Initialize() since it's managed.
394 pref_service()->SetString(prefs::kGoogleServicesAccountId, kEmail); 391 pref_service()->SetString(prefs::kGoogleServicesAccountId, kEmail);
395 CreateSyncService(ProfileSyncService::MANUAL_START); 392 CreateSyncService(ProfileSyncService::MANUAL_START);
396 393
397 // Disable sync through policy. 394 // Disable sync through policy.
398 pref_service()->SetBoolean(sync_driver::prefs::kSyncManaged, true); 395 pref_service()->SetBoolean(syncer::prefs::kSyncManaged, true);
399 EXPECT_CALL(*component_factory_, CreateDataTypeManager(_, _, _, _, _)) 396 EXPECT_CALL(*component_factory_, CreateDataTypeManager(_, _, _, _, _))
400 .Times(0); 397 .Times(0);
401 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); 398 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber());
402 399
403 sync_service_->Initialize(); 400 sync_service_->Initialize();
404 } 401 }
405 402
406 TEST_F(ProfileSyncServiceStartupTest, SwitchManaged) { 403 TEST_F(ProfileSyncServiceStartupTest, SwitchManaged) {
407 CreateSyncService(ProfileSyncService::MANUAL_START); 404 CreateSyncService(ProfileSyncService::MANUAL_START);
408 std::string account_id = SimulateTestUserSignin(sync_service_.get()); 405 std::string account_id = SimulateTestUserSignin(sync_service_.get());
409 sync_service_->SetFirstSetupComplete(); 406 sync_service_->SetFirstSetupComplete();
410 SetUpSyncBackendHost(); 407 SetUpSyncBackendHost();
411 DataTypeManagerMock* data_type_manager = SetUpDataTypeManager(); 408 DataTypeManagerMock* data_type_manager = SetUpDataTypeManager();
412 EXPECT_CALL(*data_type_manager, Configure(_, _)); 409 EXPECT_CALL(*data_type_manager, Configure(_, _));
413 EXPECT_CALL(*data_type_manager, state()) 410 EXPECT_CALL(*data_type_manager, state())
414 .WillRepeatedly(Return(DataTypeManager::CONFIGURED)); 411 .WillRepeatedly(Return(DataTypeManager::CONFIGURED));
415 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); 412 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber());
416 IssueTestTokens(account_id); 413 IssueTestTokens(account_id);
417 sync_service_->Initialize(); 414 sync_service_->Initialize();
418 EXPECT_TRUE(sync_service_->IsBackendInitialized()); 415 EXPECT_TRUE(sync_service_->IsBackendInitialized());
419 EXPECT_TRUE(sync_service_->IsSyncActive()); 416 EXPECT_TRUE(sync_service_->IsSyncActive());
420 417
421 // The service should stop when switching to managed mode. 418 // The service should stop when switching to managed mode.
422 Mock::VerifyAndClearExpectations(data_type_manager); 419 Mock::VerifyAndClearExpectations(data_type_manager);
423 EXPECT_CALL(*data_type_manager, state()) 420 EXPECT_CALL(*data_type_manager, state())
424 .WillOnce(Return(DataTypeManager::CONFIGURED)); 421 .WillOnce(Return(DataTypeManager::CONFIGURED));
425 EXPECT_CALL(*data_type_manager, Stop()).Times(1); 422 EXPECT_CALL(*data_type_manager, Stop()).Times(1);
426 pref_service()->SetBoolean(sync_driver::prefs::kSyncManaged, true); 423 pref_service()->SetBoolean(syncer::prefs::kSyncManaged, true);
427 EXPECT_FALSE(sync_service_->IsBackendInitialized()); 424 EXPECT_FALSE(sync_service_->IsBackendInitialized());
428 // Note that PSS no longer references |data_type_manager| after stopping. 425 // Note that PSS no longer references |data_type_manager| after stopping.
429 426
430 // When switching back to unmanaged, the state should change but sync should 427 // When switching back to unmanaged, the state should change but sync should
431 // not start automatically because IsFirstSetupComplete() will be false. 428 // not start automatically because IsFirstSetupComplete() will be false.
432 // A new DataTypeManager should not be created. 429 // A new DataTypeManager should not be created.
433 Mock::VerifyAndClearExpectations(data_type_manager); 430 Mock::VerifyAndClearExpectations(data_type_manager);
434 EXPECT_CALL(*component_factory_, CreateDataTypeManager(_, _, _, _, _)) 431 EXPECT_CALL(*component_factory_, CreateDataTypeManager(_, _, _, _, _))
435 .Times(0); 432 .Times(0);
436 pref_service()->ClearPref(sync_driver::prefs::kSyncManaged); 433 pref_service()->ClearPref(syncer::prefs::kSyncManaged);
437 EXPECT_FALSE(sync_service_->IsBackendInitialized()); 434 EXPECT_FALSE(sync_service_->IsBackendInitialized());
438 EXPECT_FALSE(sync_service_->IsSyncActive()); 435 EXPECT_FALSE(sync_service_->IsSyncActive());
439 } 436 }
440 437
441 TEST_F(ProfileSyncServiceStartupTest, StartFailure) { 438 TEST_F(ProfileSyncServiceStartupTest, StartFailure) {
442 CreateSyncService(ProfileSyncService::MANUAL_START); 439 CreateSyncService(ProfileSyncService::MANUAL_START);
443 std::string account_id = SimulateTestUserSignin(sync_service_.get()); 440 std::string account_id = SimulateTestUserSignin(sync_service_.get());
444 sync_service_->SetFirstSetupComplete(); 441 sync_service_->SetFirstSetupComplete();
445 SetUpSyncBackendHost(); 442 SetUpSyncBackendHost();
446 DataTypeManagerMock* data_type_manager = SetUpDataTypeManager(); 443 DataTypeManagerMock* data_type_manager = SetUpDataTypeManager();
(...skipping 15 matching lines...) Expand all
462 EXPECT_TRUE(sync_service_->HasUnrecoverableError()); 459 EXPECT_TRUE(sync_service_->HasUnrecoverableError());
463 } 460 }
464 461
465 TEST_F(ProfileSyncServiceStartupTest, StartDownloadFailed) { 462 TEST_F(ProfileSyncServiceStartupTest, StartDownloadFailed) {
466 // Pre load the tokens 463 // Pre load the tokens
467 CreateSyncService(ProfileSyncService::MANUAL_START); 464 CreateSyncService(ProfileSyncService::MANUAL_START);
468 std::string account_id = SimulateTestUserSignin(sync_service_.get()); 465 std::string account_id = SimulateTestUserSignin(sync_service_.get());
469 SyncBackendHostMock* mock_sbh = SetUpSyncBackendHost(); 466 SyncBackendHostMock* mock_sbh = SetUpSyncBackendHost();
470 mock_sbh->set_fail_initial_download(true); 467 mock_sbh->set_fail_initial_download(true);
471 468
472 pref_service()->ClearPref(sync_driver::prefs::kSyncFirstSetupComplete); 469 pref_service()->ClearPref(syncer::prefs::kSyncFirstSetupComplete);
473 470
474 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); 471 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber());
475 sync_service_->Initialize(); 472 sync_service_->Initialize();
476 473
477 auto sync_blocker = sync_service_->GetSetupInProgressHandle(); 474 auto sync_blocker = sync_service_->GetSetupInProgressHandle();
478 IssueTestTokens(account_id); 475 IssueTestTokens(account_id);
479 sync_blocker.reset(); 476 sync_blocker.reset();
480 EXPECT_FALSE(sync_service_->IsSyncActive()); 477 EXPECT_FALSE(sync_service_->IsSyncActive());
481 } 478 }
482 479
483 } // namespace browser_sync 480 } // namespace browser_sync
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698