OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #include "components/browser_sync/browser/profile_sync_service.h" | |
6 | |
7 #include <memory> | |
8 #include <utility> | |
9 #include <vector> | |
10 | |
11 #include "base/callback.h" | |
12 #include "base/command_line.h" | |
13 #include "base/compiler_specific.h" | |
14 #include "base/feature_list.h" | |
15 #include "base/location.h" | |
16 #include "base/run_loop.h" | |
17 #include "base/single_thread_task_runner.h" | |
18 #include "base/strings/string_number_conversions.h" | |
19 #include "base/strings/utf_string_conversions.h" | |
20 #include "base/test/scoped_feature_list.h" | |
21 #include "base/test/sequenced_worker_pool_owner.h" | |
22 #include "base/threading/thread_task_runner_handle.h" | |
23 #include "base/values.h" | |
24 #include "build/build_config.h" | |
25 #include "components/browser_sync/browser/profile_sync_test_util.h" | |
26 #include "components/browser_sync/common/browser_sync_switches.h" | |
27 #include "components/invalidation/impl/profile_invalidation_provider.h" | |
28 #include "components/invalidation/public/invalidation_service.h" | |
29 #include "components/signin/core/browser/account_tracker_service.h" | |
30 #include "components/signin/core/browser/fake_signin_manager.h" | |
31 #include "components/strings/grit/components_strings.h" | |
32 #include "components/sync/driver/data_type_manager.h" | |
33 #include "components/sync/driver/data_type_manager_observer.h" | |
34 #include "components/sync/driver/fake_data_type_controller.h" | |
35 #include "components/sync/driver/glue/sync_backend_host_mock.h" | |
36 #include "components/sync/driver/pref_names.h" | |
37 #include "components/sync/driver/sync_api_component_factory_mock.h" | |
38 #include "components/sync/driver/sync_driver_switches.h" | |
39 #include "components/sync/driver/sync_prefs.h" | |
40 #include "components/sync/driver/sync_service_observer.h" | |
41 #include "components/sync/driver/sync_util.h" | |
42 #include "components/syncable_prefs/testing_pref_service_syncable.h" | |
43 #include "components/version_info/version_info.h" | |
44 #include "components/version_info/version_info_values.h" | |
45 #include "google_apis/gaia/gaia_constants.h" | |
46 #include "testing/gmock/include/gmock/gmock.h" | |
47 #include "testing/gtest/include/gtest/gtest.h" | |
48 #include "ui/base/l10n/l10n_util.h" | |
49 | |
50 using testing::Return; | |
51 | |
52 namespace browser_sync { | |
53 | |
54 namespace { | |
55 | |
56 const char kGaiaId[] = "12345"; | |
57 const char kEmail[] = "test_user@gmail.com"; | |
58 | |
59 class FakeDataTypeManager : public sync_driver::DataTypeManager { | |
60 public: | |
61 typedef base::Callback<void(syncer::ConfigureReason)> ConfigureCalled; | |
62 | |
63 explicit FakeDataTypeManager(const ConfigureCalled& configure_called) | |
64 : configure_called_(configure_called) {} | |
65 | |
66 ~FakeDataTypeManager() override{}; | |
67 | |
68 void Configure(syncer::ModelTypeSet desired_types, | |
69 syncer::ConfigureReason reason) override { | |
70 DCHECK(!configure_called_.is_null()); | |
71 configure_called_.Run(reason); | |
72 } | |
73 | |
74 void ReenableType(syncer::ModelType type) override {} | |
75 void ResetDataTypeErrors() override {} | |
76 void PurgeForMigration(syncer::ModelTypeSet undesired_types, | |
77 syncer::ConfigureReason reason) override {} | |
78 void Stop() override{}; | |
79 State state() const override { | |
80 return sync_driver::DataTypeManager::CONFIGURED; | |
81 }; | |
82 | |
83 private: | |
84 ConfigureCalled configure_called_; | |
85 }; | |
86 | |
87 ACTION_P(ReturnNewDataTypeManager, configure_called) { | |
88 return new FakeDataTypeManager(configure_called); | |
89 } | |
90 | |
91 using testing::Return; | |
92 using testing::StrictMock; | |
93 using testing::_; | |
94 | |
95 class TestSyncServiceObserver : public sync_driver::SyncServiceObserver { | |
96 public: | |
97 explicit TestSyncServiceObserver(ProfileSyncService* service) | |
98 : service_(service), setup_in_progress_(false) {} | |
99 void OnStateChanged() override { | |
100 setup_in_progress_ = service_->IsSetupInProgress(); | |
101 } | |
102 bool setup_in_progress() const { return setup_in_progress_; } | |
103 | |
104 private: | |
105 ProfileSyncService* service_; | |
106 bool setup_in_progress_; | |
107 }; | |
108 | |
109 // A variant of the SyncBackendHostMock that won't automatically | |
110 // call back when asked to initialized. Allows us to test things | |
111 // that could happen while backend init is in progress. | |
112 class SyncBackendHostNoReturn : public SyncBackendHostMock { | |
113 void Initialize( | |
114 sync_driver::SyncFrontend* frontend, | |
115 std::unique_ptr<base::Thread> sync_thread, | |
116 const scoped_refptr<base::SingleThreadTaskRunner>& db_thread, | |
117 const scoped_refptr<base::SingleThreadTaskRunner>& file_thread, | |
118 const syncer::WeakHandle<syncer::JsEventHandler>& event_handler, | |
119 const GURL& service_url, | |
120 const std::string& sync_user_agent, | |
121 const syncer::SyncCredentials& credentials, | |
122 bool delete_sync_data_folder, | |
123 std::unique_ptr<syncer::SyncManagerFactory> sync_manager_factory, | |
124 const syncer::WeakHandle<syncer::UnrecoverableErrorHandler>& | |
125 unrecoverable_error_handler, | |
126 const base::Closure& report_unrecoverable_error_function, | |
127 const HttpPostProviderFactoryGetter& http_post_provider_factory_getter, | |
128 std::unique_ptr<syncer::SyncEncryptionHandler::NigoriState> | |
129 saved_nigori_state) override {} | |
130 }; | |
131 | |
132 class SyncBackendHostMockCollectDeleteDirParam : public SyncBackendHostMock { | |
133 public: | |
134 explicit SyncBackendHostMockCollectDeleteDirParam( | |
135 std::vector<bool>* delete_dir_param) | |
136 : delete_dir_param_(delete_dir_param) {} | |
137 | |
138 void Initialize( | |
139 sync_driver::SyncFrontend* frontend, | |
140 std::unique_ptr<base::Thread> sync_thread, | |
141 const scoped_refptr<base::SingleThreadTaskRunner>& db_thread, | |
142 const scoped_refptr<base::SingleThreadTaskRunner>& file_thread, | |
143 const syncer::WeakHandle<syncer::JsEventHandler>& event_handler, | |
144 const GURL& service_url, | |
145 const std::string& sync_user_agent, | |
146 const syncer::SyncCredentials& credentials, | |
147 bool delete_sync_data_folder, | |
148 std::unique_ptr<syncer::SyncManagerFactory> sync_manager_factory, | |
149 const syncer::WeakHandle<syncer::UnrecoverableErrorHandler>& | |
150 unrecoverable_error_handler, | |
151 const base::Closure& report_unrecoverable_error_function, | |
152 const HttpPostProviderFactoryGetter& http_post_provider_factory_getter, | |
153 std::unique_ptr<syncer::SyncEncryptionHandler::NigoriState> | |
154 saved_nigori_state) override { | |
155 delete_dir_param_->push_back(delete_sync_data_folder); | |
156 SyncBackendHostMock::Initialize( | |
157 frontend, std::move(sync_thread), db_thread, file_thread, event_handler, | |
158 service_url, sync_user_agent, credentials, delete_sync_data_folder, | |
159 std::move(sync_manager_factory), unrecoverable_error_handler, | |
160 report_unrecoverable_error_function, http_post_provider_factory_getter, | |
161 std::move(saved_nigori_state)); | |
162 } | |
163 | |
164 private: | |
165 std::vector<bool>* delete_dir_param_; | |
166 }; | |
167 | |
168 // SyncBackendHostMock that calls an external callback when ClearServerData is | |
169 // called. | |
170 class SyncBackendHostCaptureClearServerData : public SyncBackendHostMock { | |
171 public: | |
172 typedef base::Callback<void( | |
173 const syncer::SyncManager::ClearServerDataCallback&)> | |
174 ClearServerDataCalled; | |
175 explicit SyncBackendHostCaptureClearServerData( | |
176 const ClearServerDataCalled& clear_server_data_called) | |
177 : clear_server_data_called_(clear_server_data_called) {} | |
178 | |
179 void ClearServerData( | |
180 const syncer::SyncManager::ClearServerDataCallback& callback) override { | |
181 clear_server_data_called_.Run(callback); | |
182 } | |
183 | |
184 private: | |
185 ClearServerDataCalled clear_server_data_called_; | |
186 }; | |
187 | |
188 ACTION(ReturnNewSyncBackendHostMock) { | |
189 return new browser_sync::SyncBackendHostMock(); | |
190 } | |
191 | |
192 ACTION(ReturnNewSyncBackendHostNoReturn) { | |
193 return new browser_sync::SyncBackendHostNoReturn(); | |
194 } | |
195 | |
196 ACTION_P(ReturnNewMockHostCollectDeleteDirParam, delete_dir_param) { | |
197 return new browser_sync::SyncBackendHostMockCollectDeleteDirParam( | |
198 delete_dir_param); | |
199 } | |
200 | |
201 void OnClearServerDataCalled( | |
202 syncer::SyncManager::ClearServerDataCallback* captured_callback, | |
203 const syncer::SyncManager::ClearServerDataCallback& callback) { | |
204 *captured_callback = callback; | |
205 } | |
206 | |
207 ACTION_P(ReturnNewMockHostCaptureClearServerData, captured_callback) { | |
208 return new SyncBackendHostCaptureClearServerData(base::Bind( | |
209 &OnClearServerDataCalled, base::Unretained(captured_callback))); | |
210 } | |
211 | |
212 // A test harness that uses a real ProfileSyncService and in most cases a | |
213 // MockSyncBackendHost. | |
214 // | |
215 // This is useful if we want to test the ProfileSyncService and don't care about | |
216 // testing the SyncBackendHost. | |
217 class ProfileSyncServiceTest : public ::testing::Test { | |
218 protected: | |
219 ProfileSyncServiceTest() : component_factory_(nullptr) {} | |
220 ~ProfileSyncServiceTest() override {} | |
221 | |
222 void SetUp() override { | |
223 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( | |
224 switches::kSyncDeferredStartupTimeoutSeconds, "0"); | |
225 } | |
226 | |
227 void TearDown() override { | |
228 // Kill the service before the profile. | |
229 if (service_) | |
230 service_->Shutdown(); | |
231 | |
232 service_.reset(); | |
233 } | |
234 | |
235 void IssueTestTokens() { | |
236 std::string account_id = | |
237 account_tracker()->SeedAccountInfo(kGaiaId, kEmail); | |
238 auth_service()->UpdateCredentials(account_id, "oauth2_login_token"); | |
239 } | |
240 | |
241 void CreateService(ProfileSyncService::StartBehavior behavior) { | |
242 signin_manager()->SetAuthenticatedAccountInfo(kGaiaId, kEmail); | |
243 component_factory_ = profile_sync_service_bundle_.component_factory(); | |
244 ProfileSyncServiceBundle::SyncClientBuilder builder( | |
245 &profile_sync_service_bundle_); | |
246 ProfileSyncService::InitParams init_params = | |
247 profile_sync_service_bundle_.CreateBasicInitParams(behavior, | |
248 builder.Build()); | |
249 | |
250 service_.reset(new ProfileSyncService(std::move(init_params))); | |
251 service_->RegisterDataTypeController( | |
252 base::MakeUnique<sync_driver::FakeDataTypeController>( | |
253 syncer::BOOKMARKS)); | |
254 } | |
255 | |
256 #if defined(OS_WIN) || defined(OS_MACOSX) || \ | |
257 (defined(OS_LINUX) && !defined(OS_CHROMEOS)) | |
258 void CreateServiceWithoutSignIn() { | |
259 CreateService(ProfileSyncService::AUTO_START); | |
260 signin_manager()->SignOut(signin_metrics::SIGNOUT_TEST, | |
261 signin_metrics::SignoutDelete::IGNORE_METRIC); | |
262 } | |
263 #endif | |
264 | |
265 void ShutdownAndDeleteService() { | |
266 if (service_) | |
267 service_->Shutdown(); | |
268 service_.reset(); | |
269 } | |
270 | |
271 void InitializeForNthSync() { | |
272 // Set first sync time before initialize to simulate a complete sync setup. | |
273 sync_driver::SyncPrefs sync_prefs(prefs()); | |
274 sync_prefs.SetFirstSyncTime(base::Time::Now()); | |
275 sync_prefs.SetFirstSetupComplete(); | |
276 sync_prefs.SetKeepEverythingSynced(true); | |
277 service_->Initialize(); | |
278 } | |
279 | |
280 void InitializeForFirstSync() { | |
281 service_->Initialize(); | |
282 } | |
283 | |
284 void TriggerPassphraseRequired() { | |
285 service_->OnPassphraseRequired(syncer::REASON_DECRYPTION, | |
286 sync_pb::EncryptedData()); | |
287 } | |
288 | |
289 void TriggerDataTypeStartRequest() { | |
290 service_->OnDataTypeRequestsSyncStartup(syncer::BOOKMARKS); | |
291 } | |
292 | |
293 void OnConfigureCalled(syncer::ConfigureReason configure_reason) { | |
294 sync_driver::DataTypeManager::ConfigureResult result; | |
295 result.status = sync_driver::DataTypeManager::OK; | |
296 service()->OnConfigureDone(result); | |
297 } | |
298 | |
299 FakeDataTypeManager::ConfigureCalled GetDefaultConfigureCalledCallback() { | |
300 return base::Bind(&ProfileSyncServiceTest::OnConfigureCalled, | |
301 base::Unretained(this)); | |
302 } | |
303 | |
304 void OnConfigureCalledRecordReason(syncer::ConfigureReason* reason_dest, | |
305 syncer::ConfigureReason reason) { | |
306 DCHECK(reason_dest); | |
307 *reason_dest = reason; | |
308 } | |
309 | |
310 FakeDataTypeManager::ConfigureCalled GetRecordingConfigureCalledCallback( | |
311 syncer::ConfigureReason* reason) { | |
312 return base::Bind(&ProfileSyncServiceTest::OnConfigureCalledRecordReason, | |
313 base::Unretained(this), reason); | |
314 } | |
315 | |
316 void ExpectDataTypeManagerCreation( | |
317 int times, | |
318 const FakeDataTypeManager::ConfigureCalled& callback) { | |
319 EXPECT_CALL(*component_factory_, CreateDataTypeManager(_, _, _, _, _)) | |
320 .Times(times) | |
321 .WillRepeatedly(ReturnNewDataTypeManager(callback)); | |
322 } | |
323 | |
324 void ExpectSyncBackendHostCreation(int times) { | |
325 EXPECT_CALL(*component_factory_, CreateSyncBackendHost(_, _, _, _)) | |
326 .Times(times) | |
327 .WillRepeatedly(ReturnNewSyncBackendHostMock()); | |
328 } | |
329 | |
330 void ExpectSyncBackendHostCreationCollectDeleteDir( | |
331 int times, std::vector<bool> *delete_dir_param) { | |
332 EXPECT_CALL(*component_factory_, CreateSyncBackendHost(_, _, _, _)) | |
333 .Times(times) | |
334 .WillRepeatedly( | |
335 ReturnNewMockHostCollectDeleteDirParam(delete_dir_param)); | |
336 } | |
337 | |
338 void ExpectSyncBackendHostCreationCaptureClearServerData( | |
339 syncer::SyncManager::ClearServerDataCallback* captured_callback) { | |
340 EXPECT_CALL(*component_factory_, CreateSyncBackendHost(_, _, _, _)) | |
341 .Times(1) | |
342 .WillOnce(ReturnNewMockHostCaptureClearServerData(captured_callback)); | |
343 } | |
344 | |
345 void PrepareDelayedInitSyncBackendHost() { | |
346 EXPECT_CALL(*component_factory_, CreateSyncBackendHost(_, _, _, _)) | |
347 .WillOnce(ReturnNewSyncBackendHostNoReturn()); | |
348 } | |
349 | |
350 AccountTrackerService* account_tracker() { | |
351 return profile_sync_service_bundle_.account_tracker(); | |
352 } | |
353 | |
354 #if defined(OS_CHROMEOS) | |
355 SigninManagerBase* signin_manager() | |
356 #else | |
357 SigninManager* signin_manager() | |
358 #endif | |
359 // Opening brace is outside of macro to avoid confusing lint. | |
360 { | |
361 return profile_sync_service_bundle_.signin_manager(); | |
362 } | |
363 | |
364 ProfileOAuth2TokenService* auth_service() { | |
365 return profile_sync_service_bundle_.auth_service(); | |
366 } | |
367 | |
368 ProfileSyncService* service() { | |
369 return service_.get(); | |
370 } | |
371 | |
372 syncable_prefs::TestingPrefServiceSyncable* prefs() { | |
373 return profile_sync_service_bundle_.pref_service(); | |
374 } | |
375 | |
376 SyncApiComponentFactoryMock* component_factory() { | |
377 return component_factory_; | |
378 } | |
379 | |
380 protected: | |
381 void PumpLoop() { | |
382 base::RunLoop run_loop; | |
383 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, | |
384 run_loop.QuitClosure()); | |
385 run_loop.Run(); | |
386 } | |
387 | |
388 private: | |
389 base::MessageLoop message_loop_; | |
390 browser_sync::ProfileSyncServiceBundle profile_sync_service_bundle_; | |
391 std::unique_ptr<ProfileSyncService> service_; | |
392 | |
393 // The current component factory used by sync. May be null if the server | |
394 // hasn't been created yet. | |
395 SyncApiComponentFactoryMock* component_factory_; | |
396 }; | |
397 | |
398 // Verify that the server URLs are sane. | |
399 TEST_F(ProfileSyncServiceTest, InitialState) { | |
400 CreateService(ProfileSyncService::AUTO_START); | |
401 InitializeForNthSync(); | |
402 const std::string& url = service()->sync_service_url().spec(); | |
403 EXPECT_TRUE(url == internal::kSyncServerUrl || | |
404 url == internal::kSyncDevServerUrl); | |
405 } | |
406 | |
407 // Verify a successful initialization. | |
408 TEST_F(ProfileSyncServiceTest, SuccessfulInitialization) { | |
409 prefs()->SetManagedPref(sync_driver::prefs::kSyncManaged, | |
410 new base::FundamentalValue(false)); | |
411 IssueTestTokens(); | |
412 CreateService(ProfileSyncService::AUTO_START); | |
413 ExpectDataTypeManagerCreation(1, GetDefaultConfigureCalledCallback()); | |
414 ExpectSyncBackendHostCreation(1); | |
415 InitializeForNthSync(); | |
416 EXPECT_FALSE(service()->IsManaged()); | |
417 EXPECT_TRUE(service()->IsSyncActive()); | |
418 } | |
419 | |
420 // Verify that an initialization where first setup is not complete does not | |
421 // start up the backend. | |
422 TEST_F(ProfileSyncServiceTest, NeedsConfirmation) { | |
423 prefs()->SetManagedPref(sync_driver::prefs::kSyncManaged, | |
424 new base::FundamentalValue(false)); | |
425 IssueTestTokens(); | |
426 CreateService(ProfileSyncService::MANUAL_START); | |
427 sync_driver::SyncPrefs sync_prefs(prefs()); | |
428 base::Time now = base::Time::Now(); | |
429 sync_prefs.SetLastSyncedTime(now); | |
430 sync_prefs.SetKeepEverythingSynced(true); | |
431 service()->Initialize(); | |
432 EXPECT_FALSE(service()->IsSyncActive()); | |
433 | |
434 // The last sync time shouldn't be cleared. | |
435 // TODO(zea): figure out a way to check that the directory itself wasn't | |
436 // cleared. | |
437 EXPECT_EQ(now, sync_prefs.GetLastSyncedTime()); | |
438 } | |
439 | |
440 // Verify that the SetSetupInProgress function call updates state | |
441 // and notifies observers. | |
442 TEST_F(ProfileSyncServiceTest, SetupInProgress) { | |
443 CreateService(ProfileSyncService::AUTO_START); | |
444 InitializeForFirstSync(); | |
445 | |
446 TestSyncServiceObserver observer(service()); | |
447 service()->AddObserver(&observer); | |
448 | |
449 auto sync_blocker = service()->GetSetupInProgressHandle(); | |
450 EXPECT_TRUE(observer.setup_in_progress()); | |
451 sync_blocker.reset(); | |
452 EXPECT_FALSE(observer.setup_in_progress()); | |
453 | |
454 service()->RemoveObserver(&observer); | |
455 } | |
456 | |
457 // Verify that disable by enterprise policy works. | |
458 TEST_F(ProfileSyncServiceTest, DisabledByPolicyBeforeInit) { | |
459 prefs()->SetManagedPref(sync_driver::prefs::kSyncManaged, | |
460 new base::FundamentalValue(true)); | |
461 IssueTestTokens(); | |
462 CreateService(ProfileSyncService::AUTO_START); | |
463 InitializeForNthSync(); | |
464 EXPECT_TRUE(service()->IsManaged()); | |
465 EXPECT_FALSE(service()->IsSyncActive()); | |
466 } | |
467 | |
468 // Verify that disable by enterprise policy works even after the backend has | |
469 // been initialized. | |
470 TEST_F(ProfileSyncServiceTest, DisabledByPolicyAfterInit) { | |
471 IssueTestTokens(); | |
472 CreateService(ProfileSyncService::AUTO_START); | |
473 ExpectDataTypeManagerCreation(1, GetDefaultConfigureCalledCallback()); | |
474 ExpectSyncBackendHostCreation(1); | |
475 InitializeForNthSync(); | |
476 | |
477 EXPECT_FALSE(service()->IsManaged()); | |
478 EXPECT_TRUE(service()->IsSyncActive()); | |
479 | |
480 prefs()->SetManagedPref(sync_driver::prefs::kSyncManaged, | |
481 new base::FundamentalValue(true)); | |
482 | |
483 EXPECT_TRUE(service()->IsManaged()); | |
484 EXPECT_FALSE(service()->IsSyncActive()); | |
485 } | |
486 | |
487 // Exercies the ProfileSyncService's code paths related to getting shut down | |
488 // before the backend initialize call returns. | |
489 TEST_F(ProfileSyncServiceTest, AbortedByShutdown) { | |
490 CreateService(ProfileSyncService::AUTO_START); | |
491 PrepareDelayedInitSyncBackendHost(); | |
492 | |
493 IssueTestTokens(); | |
494 InitializeForNthSync(); | |
495 EXPECT_FALSE(service()->IsSyncActive()); | |
496 | |
497 ShutdownAndDeleteService(); | |
498 } | |
499 | |
500 // Test RequestStop() before we've initialized the backend. | |
501 TEST_F(ProfileSyncServiceTest, EarlyRequestStop) { | |
502 CreateService(ProfileSyncService::AUTO_START); | |
503 IssueTestTokens(); | |
504 ExpectDataTypeManagerCreation(1, GetDefaultConfigureCalledCallback()); | |
505 ExpectSyncBackendHostCreation(1); | |
506 | |
507 service()->RequestStop(ProfileSyncService::KEEP_DATA); | |
508 EXPECT_FALSE(service()->IsSyncRequested()); | |
509 | |
510 // Because sync is not requested, this should fail. | |
511 InitializeForNthSync(); | |
512 EXPECT_FALSE(service()->IsSyncRequested()); | |
513 EXPECT_FALSE(service()->IsSyncActive()); | |
514 | |
515 // Request start. This should be enough to allow init to happen. | |
516 service()->RequestStart(); | |
517 EXPECT_TRUE(service()->IsSyncRequested()); | |
518 EXPECT_TRUE(service()->IsSyncActive()); | |
519 } | |
520 | |
521 // Test RequestStop() after we've initialized the backend. | |
522 TEST_F(ProfileSyncServiceTest, DisableAndEnableSyncTemporarily) { | |
523 CreateService(ProfileSyncService::AUTO_START); | |
524 IssueTestTokens(); | |
525 ExpectDataTypeManagerCreation(1, GetDefaultConfigureCalledCallback()); | |
526 ExpectSyncBackendHostCreation(1); | |
527 InitializeForNthSync(); | |
528 | |
529 EXPECT_TRUE(service()->IsSyncActive()); | |
530 EXPECT_FALSE(prefs()->GetBoolean(sync_driver::prefs::kSyncSuppressStart)); | |
531 | |
532 testing::Mock::VerifyAndClearExpectations(component_factory()); | |
533 | |
534 service()->RequestStop(ProfileSyncService::KEEP_DATA); | |
535 EXPECT_FALSE(service()->IsSyncActive()); | |
536 EXPECT_TRUE(prefs()->GetBoolean(sync_driver::prefs::kSyncSuppressStart)); | |
537 | |
538 ExpectDataTypeManagerCreation(1, GetDefaultConfigureCalledCallback()); | |
539 ExpectSyncBackendHostCreation(1); | |
540 | |
541 service()->RequestStart(); | |
542 EXPECT_TRUE(service()->IsSyncActive()); | |
543 EXPECT_FALSE(prefs()->GetBoolean(sync_driver::prefs::kSyncSuppressStart)); | |
544 } | |
545 | |
546 // Certain ProfileSyncService tests don't apply to Chrome OS, for example | |
547 // things that deal with concepts like "signing out" and policy. | |
548 #if !defined (OS_CHROMEOS) | |
549 TEST_F(ProfileSyncServiceTest, EnableSyncAndSignOut) { | |
550 CreateService(ProfileSyncService::AUTO_START); | |
551 ExpectDataTypeManagerCreation(1, GetDefaultConfigureCalledCallback()); | |
552 ExpectSyncBackendHostCreation(1); | |
553 IssueTestTokens(); | |
554 InitializeForNthSync(); | |
555 | |
556 EXPECT_TRUE(service()->IsSyncActive()); | |
557 EXPECT_FALSE(prefs()->GetBoolean(sync_driver::prefs::kSyncSuppressStart)); | |
558 | |
559 signin_manager()->SignOut(signin_metrics::SIGNOUT_TEST, | |
560 signin_metrics::SignoutDelete::IGNORE_METRIC); | |
561 EXPECT_FALSE(service()->IsSyncActive()); | |
562 } | |
563 #endif // !defined(OS_CHROMEOS) | |
564 | |
565 TEST_F(ProfileSyncServiceTest, GetSyncTokenStatus) { | |
566 CreateService(ProfileSyncService::AUTO_START); | |
567 IssueTestTokens(); | |
568 ExpectDataTypeManagerCreation(1, GetDefaultConfigureCalledCallback()); | |
569 ExpectSyncBackendHostCreation(1); | |
570 InitializeForNthSync(); | |
571 | |
572 // Initial status. | |
573 ProfileSyncService::SyncTokenStatus token_status = | |
574 service()->GetSyncTokenStatus(); | |
575 EXPECT_EQ(syncer::CONNECTION_NOT_ATTEMPTED, token_status.connection_status); | |
576 EXPECT_TRUE(token_status.connection_status_update_time.is_null()); | |
577 EXPECT_TRUE(token_status.token_request_time.is_null()); | |
578 EXPECT_TRUE(token_status.token_receive_time.is_null()); | |
579 | |
580 // Simulate an auth error. | |
581 service()->OnConnectionStatusChange(syncer::CONNECTION_AUTH_ERROR); | |
582 | |
583 // The token request will take the form of a posted task. Run it. | |
584 base::RunLoop loop; | |
585 loop.RunUntilIdle(); | |
586 | |
587 token_status = service()->GetSyncTokenStatus(); | |
588 EXPECT_EQ(syncer::CONNECTION_AUTH_ERROR, token_status.connection_status); | |
589 EXPECT_FALSE(token_status.connection_status_update_time.is_null()); | |
590 EXPECT_FALSE(token_status.token_request_time.is_null()); | |
591 EXPECT_FALSE(token_status.token_receive_time.is_null()); | |
592 EXPECT_EQ(GoogleServiceAuthError::AuthErrorNone(), | |
593 token_status.last_get_token_error); | |
594 EXPECT_TRUE(token_status.next_token_request_time.is_null()); | |
595 | |
596 // Simulate successful connection. | |
597 service()->OnConnectionStatusChange(syncer::CONNECTION_OK); | |
598 token_status = service()->GetSyncTokenStatus(); | |
599 EXPECT_EQ(syncer::CONNECTION_OK, token_status.connection_status); | |
600 } | |
601 | |
602 TEST_F(ProfileSyncServiceTest, RevokeAccessTokenFromTokenService) { | |
603 CreateService(ProfileSyncService::AUTO_START); | |
604 IssueTestTokens(); | |
605 ExpectDataTypeManagerCreation(1, GetDefaultConfigureCalledCallback()); | |
606 ExpectSyncBackendHostCreation(1); | |
607 InitializeForNthSync(); | |
608 EXPECT_TRUE(service()->IsSyncActive()); | |
609 | |
610 std::string primary_account_id = | |
611 signin_manager()->GetAuthenticatedAccountId(); | |
612 auth_service()->LoadCredentials(primary_account_id); | |
613 base::RunLoop().RunUntilIdle(); | |
614 EXPECT_FALSE(service()->GetAccessTokenForTest().empty()); | |
615 | |
616 std::string secondary_account_gaiaid = "1234567"; | |
617 std::string secondary_account_name = "test_user2@gmail.com"; | |
618 std::string secondary_account_id = account_tracker()->SeedAccountInfo( | |
619 secondary_account_gaiaid, secondary_account_name); | |
620 auth_service()->UpdateCredentials(secondary_account_id, | |
621 "second_account_refresh_token"); | |
622 auth_service()->RevokeCredentials(secondary_account_id); | |
623 EXPECT_FALSE(service()->GetAccessTokenForTest().empty()); | |
624 | |
625 auth_service()->RevokeCredentials(primary_account_id); | |
626 EXPECT_TRUE(service()->GetAccessTokenForTest().empty()); | |
627 } | |
628 | |
629 // CrOS does not support signout. | |
630 #if !defined(OS_CHROMEOS) | |
631 TEST_F(ProfileSyncServiceTest, SignOutRevokeAccessToken) { | |
632 CreateService(ProfileSyncService::AUTO_START); | |
633 IssueTestTokens(); | |
634 ExpectDataTypeManagerCreation(1, GetDefaultConfigureCalledCallback()); | |
635 ExpectSyncBackendHostCreation(1); | |
636 InitializeForNthSync(); | |
637 EXPECT_TRUE(service()->IsSyncActive()); | |
638 | |
639 std::string primary_account_id = | |
640 signin_manager()->GetAuthenticatedAccountId(); | |
641 auth_service()->LoadCredentials(primary_account_id); | |
642 base::RunLoop().RunUntilIdle(); | |
643 EXPECT_FALSE(service()->GetAccessTokenForTest().empty()); | |
644 | |
645 signin_manager()->SignOut(signin_metrics::SIGNOUT_TEST, | |
646 signin_metrics::SignoutDelete::IGNORE_METRIC); | |
647 EXPECT_TRUE(service()->GetAccessTokenForTest().empty()); | |
648 } | |
649 #endif | |
650 | |
651 // Verify that LastSyncedTime and local DeviceInfo is cleared on sign out. | |
652 TEST_F(ProfileSyncServiceTest, ClearDataOnSignOut) { | |
653 IssueTestTokens(); | |
654 CreateService(ProfileSyncService::AUTO_START); | |
655 ExpectDataTypeManagerCreation(1, GetDefaultConfigureCalledCallback()); | |
656 ExpectSyncBackendHostCreation(1); | |
657 InitializeForNthSync(); | |
658 EXPECT_TRUE(service()->IsSyncActive()); | |
659 EXPECT_EQ(l10n_util::GetStringUTF16(IDS_SYNC_TIME_JUST_NOW), | |
660 service()->GetLastSyncedTimeString()); | |
661 EXPECT_TRUE(service()->GetLocalDeviceInfoProvider()->GetLocalDeviceInfo()); | |
662 | |
663 // Sign out. | |
664 service()->RequestStop(ProfileSyncService::CLEAR_DATA); | |
665 PumpLoop(); | |
666 | |
667 EXPECT_EQ(l10n_util::GetStringUTF16(IDS_SYNC_TIME_NEVER), | |
668 service()->GetLastSyncedTimeString()); | |
669 EXPECT_FALSE(service()->GetLocalDeviceInfoProvider()->GetLocalDeviceInfo()); | |
670 } | |
671 | |
672 // Verify that the disable sync flag disables sync. | |
673 TEST_F(ProfileSyncServiceTest, DisableSyncFlag) { | |
674 base::CommandLine::ForCurrentProcess()->AppendSwitch(switches::kDisableSync); | |
675 EXPECT_FALSE(ProfileSyncService::IsSyncAllowedByFlag()); | |
676 } | |
677 | |
678 // Verify that no disable sync flag enables sync. | |
679 TEST_F(ProfileSyncServiceTest, NoDisableSyncFlag) { | |
680 EXPECT_TRUE(ProfileSyncService::IsSyncAllowedByFlag()); | |
681 } | |
682 | |
683 // Test Sync will stop after receive memory pressure | |
684 TEST_F(ProfileSyncServiceTest, MemoryPressureRecording) { | |
685 CreateService(ProfileSyncService::AUTO_START); | |
686 IssueTestTokens(); | |
687 ExpectDataTypeManagerCreation(1, GetDefaultConfigureCalledCallback()); | |
688 ExpectSyncBackendHostCreation(1); | |
689 InitializeForNthSync(); | |
690 | |
691 EXPECT_TRUE(service()->IsSyncActive()); | |
692 EXPECT_FALSE(prefs()->GetBoolean(sync_driver::prefs::kSyncSuppressStart)); | |
693 | |
694 testing::Mock::VerifyAndClearExpectations(component_factory()); | |
695 | |
696 sync_driver::SyncPrefs sync_prefs( | |
697 service()->GetSyncClient()->GetPrefService()); | |
698 | |
699 EXPECT_EQ( | |
700 prefs()->GetInteger(sync_driver::prefs::kSyncMemoryPressureWarningCount), | |
701 0); | |
702 EXPECT_FALSE(sync_prefs.DidSyncShutdownCleanly()); | |
703 | |
704 // Simulate memory pressure notification. | |
705 base::MemoryPressureListener::NotifyMemoryPressure( | |
706 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); | |
707 base::RunLoop().RunUntilIdle(); | |
708 | |
709 // Verify memory pressure recorded. | |
710 EXPECT_EQ( | |
711 prefs()->GetInteger(sync_driver::prefs::kSyncMemoryPressureWarningCount), | |
712 1); | |
713 EXPECT_FALSE(sync_prefs.DidSyncShutdownCleanly()); | |
714 | |
715 // Simulate memory pressure notification. | |
716 base::MemoryPressureListener::NotifyMemoryPressure( | |
717 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); | |
718 base::RunLoop().RunUntilIdle(); | |
719 ShutdownAndDeleteService(); | |
720 | |
721 // Verify memory pressure and shutdown recorded. | |
722 EXPECT_EQ( | |
723 prefs()->GetInteger(sync_driver::prefs::kSyncMemoryPressureWarningCount), | |
724 2); | |
725 EXPECT_TRUE(sync_prefs.DidSyncShutdownCleanly()); | |
726 } | |
727 | |
728 // Verify that OnLocalSetPassphraseEncryption triggers catch up configure sync | |
729 // cycle, calls ClearServerData, shuts down and restarts sync. | |
730 TEST_F(ProfileSyncServiceTest, OnLocalSetPassphraseEncryption) { | |
731 base::test::ScopedFeatureList scoped_feature_list; | |
732 scoped_feature_list.InitAndEnableFeature( | |
733 switches::kSyncClearDataOnPassphraseEncryption); | |
734 IssueTestTokens(); | |
735 CreateService(ProfileSyncService::AUTO_START); | |
736 | |
737 syncer::SyncManager::ClearServerDataCallback captured_callback; | |
738 syncer::ConfigureReason configure_reason = syncer::CONFIGURE_REASON_UNKNOWN; | |
739 | |
740 // Initialize sync, ensure that both DataTypeManager and SyncBackendHost are | |
741 // initialized and DTM::Configure is called with | |
742 // CONFIGURE_REASON_NEWLY_ENABLED_DATA_TYPE. | |
743 ExpectSyncBackendHostCreationCaptureClearServerData(&captured_callback); | |
744 ExpectDataTypeManagerCreation( | |
745 1, GetRecordingConfigureCalledCallback(&configure_reason)); | |
746 InitializeForNthSync(); | |
747 EXPECT_TRUE(service()->IsSyncActive()); | |
748 testing::Mock::VerifyAndClearExpectations(component_factory()); | |
749 EXPECT_EQ(syncer::CONFIGURE_REASON_NEWLY_ENABLED_DATA_TYPE, configure_reason); | |
750 sync_driver::DataTypeManager::ConfigureResult result; | |
751 result.status = sync_driver::DataTypeManager::OK; | |
752 service()->OnConfigureDone(result); | |
753 | |
754 // Simulate user entering encryption passphrase. Ensure that catch up | |
755 // configure cycle is started (DTM::Configure is called with | |
756 // CONFIGURE_REASON_CATCH_UP). | |
757 const syncer::SyncEncryptionHandler::NigoriState nigori_state; | |
758 service()->OnLocalSetPassphraseEncryption(nigori_state); | |
759 EXPECT_EQ(syncer::CONFIGURE_REASON_CATCH_UP, configure_reason); | |
760 EXPECT_TRUE(captured_callback.is_null()); | |
761 | |
762 // Simulate configure successful. Ensure that SBH::ClearServerData is called. | |
763 service()->OnConfigureDone(result); | |
764 EXPECT_FALSE(captured_callback.is_null()); | |
765 | |
766 // Once SBH::ClearServerData finishes successfully ensure that sync is | |
767 // restarted. | |
768 configure_reason = syncer::CONFIGURE_REASON_UNKNOWN; | |
769 ExpectSyncBackendHostCreation(1); | |
770 ExpectDataTypeManagerCreation( | |
771 1, GetRecordingConfigureCalledCallback(&configure_reason)); | |
772 captured_callback.Run(); | |
773 testing::Mock::VerifyAndClearExpectations(component_factory()); | |
774 EXPECT_EQ(syncer::CONFIGURE_REASON_NEWLY_ENABLED_DATA_TYPE, configure_reason); | |
775 service()->OnConfigureDone(result); | |
776 } | |
777 | |
778 // Verify that if after OnLocalSetPassphraseEncryption catch up configure sync | |
779 // cycle gets interrupted, it starts again after browser restart. | |
780 TEST_F(ProfileSyncServiceTest, | |
781 OnLocalSetPassphraseEncryption_RestartDuringCatchUp) { | |
782 syncer::ConfigureReason configure_reason = syncer::CONFIGURE_REASON_UNKNOWN; | |
783 base::test::ScopedFeatureList scoped_feature_list; | |
784 scoped_feature_list.InitAndEnableFeature( | |
785 switches::kSyncClearDataOnPassphraseEncryption); | |
786 IssueTestTokens(); | |
787 CreateService(ProfileSyncService::AUTO_START); | |
788 ExpectSyncBackendHostCreation(1); | |
789 ExpectDataTypeManagerCreation( | |
790 1, GetRecordingConfigureCalledCallback(&configure_reason)); | |
791 InitializeForNthSync(); | |
792 testing::Mock::VerifyAndClearExpectations(component_factory()); | |
793 EXPECT_EQ(syncer::CONFIGURE_REASON_NEWLY_ENABLED_DATA_TYPE, configure_reason); | |
794 sync_driver::DataTypeManager::ConfigureResult result; | |
795 result.status = sync_driver::DataTypeManager::OK; | |
796 service()->OnConfigureDone(result); | |
797 | |
798 // Simulate user entering encryption passphrase. Ensure Configure was called | |
799 // but don't let it continue. | |
800 const syncer::SyncEncryptionHandler::NigoriState nigori_state; | |
801 service()->OnLocalSetPassphraseEncryption(nigori_state); | |
802 EXPECT_EQ(syncer::CONFIGURE_REASON_CATCH_UP, configure_reason); | |
803 | |
804 // Simulate browser restart. First configuration is a regular one. | |
805 service()->Shutdown(); | |
806 syncer::SyncManager::ClearServerDataCallback captured_callback; | |
807 ExpectSyncBackendHostCreationCaptureClearServerData(&captured_callback); | |
808 ExpectDataTypeManagerCreation( | |
809 1, GetRecordingConfigureCalledCallback(&configure_reason)); | |
810 service()->RequestStart(); | |
811 testing::Mock::VerifyAndClearExpectations(component_factory()); | |
812 EXPECT_EQ(syncer::CONFIGURE_REASON_NEWLY_ENABLED_DATA_TYPE, configure_reason); | |
813 EXPECT_TRUE(captured_callback.is_null()); | |
814 | |
815 // Simulate configure successful. This time it should be catch up. | |
816 service()->OnConfigureDone(result); | |
817 EXPECT_EQ(syncer::CONFIGURE_REASON_CATCH_UP, configure_reason); | |
818 EXPECT_TRUE(captured_callback.is_null()); | |
819 | |
820 // Simulate catch up configure successful. Ensure that SBH::ClearServerData is | |
821 // called. | |
822 service()->OnConfigureDone(result); | |
823 EXPECT_FALSE(captured_callback.is_null()); | |
824 | |
825 ExpectSyncBackendHostCreation(1); | |
826 ExpectDataTypeManagerCreation( | |
827 1, GetRecordingConfigureCalledCallback(&configure_reason)); | |
828 captured_callback.Run(); | |
829 testing::Mock::VerifyAndClearExpectations(component_factory()); | |
830 EXPECT_EQ(syncer::CONFIGURE_REASON_NEWLY_ENABLED_DATA_TYPE, configure_reason); | |
831 } | |
832 | |
833 // Verify that if after OnLocalSetPassphraseEncryption ClearServerData gets | |
834 // interrupted, transition again from catch up sync cycle after browser restart. | |
835 TEST_F(ProfileSyncServiceTest, | |
836 OnLocalSetPassphraseEncryption_RestartDuringClearServerData) { | |
837 syncer::SyncManager::ClearServerDataCallback captured_callback; | |
838 syncer::ConfigureReason configure_reason = syncer::CONFIGURE_REASON_UNKNOWN; | |
839 base::test::ScopedFeatureList scoped_feature_list; | |
840 scoped_feature_list.InitAndEnableFeature( | |
841 switches::kSyncClearDataOnPassphraseEncryption); | |
842 IssueTestTokens(); | |
843 CreateService(ProfileSyncService::AUTO_START); | |
844 ExpectSyncBackendHostCreationCaptureClearServerData(&captured_callback); | |
845 ExpectDataTypeManagerCreation(1, GetDefaultConfigureCalledCallback()); | |
846 InitializeForNthSync(); | |
847 testing::Mock::VerifyAndClearExpectations(component_factory()); | |
848 | |
849 // Simulate user entering encryption passphrase. | |
850 const syncer::SyncEncryptionHandler::NigoriState nigori_state; | |
851 service()->OnLocalSetPassphraseEncryption(nigori_state); | |
852 EXPECT_FALSE(captured_callback.is_null()); | |
853 captured_callback.Reset(); | |
854 | |
855 // Simulate browser restart. First configuration is a regular one. | |
856 service()->Shutdown(); | |
857 ExpectSyncBackendHostCreationCaptureClearServerData(&captured_callback); | |
858 ExpectDataTypeManagerCreation( | |
859 1, GetRecordingConfigureCalledCallback(&configure_reason)); | |
860 service()->RequestStart(); | |
861 testing::Mock::VerifyAndClearExpectations(component_factory()); | |
862 EXPECT_EQ(syncer::CONFIGURE_REASON_NEWLY_ENABLED_DATA_TYPE, configure_reason); | |
863 EXPECT_TRUE(captured_callback.is_null()); | |
864 | |
865 // Simulate configure successful. This time it should be catch up. | |
866 sync_driver::DataTypeManager::ConfigureResult result; | |
867 result.status = sync_driver::DataTypeManager::OK; | |
868 service()->OnConfigureDone(result); | |
869 EXPECT_EQ(syncer::CONFIGURE_REASON_CATCH_UP, configure_reason); | |
870 EXPECT_TRUE(captured_callback.is_null()); | |
871 | |
872 // Simulate catch up configure successful. Ensure that SBH::ClearServerData is | |
873 // called. | |
874 service()->OnConfigureDone(result); | |
875 EXPECT_FALSE(captured_callback.is_null()); | |
876 | |
877 ExpectSyncBackendHostCreation(1); | |
878 ExpectDataTypeManagerCreation( | |
879 1, GetRecordingConfigureCalledCallback(&configure_reason)); | |
880 captured_callback.Run(); | |
881 testing::Mock::VerifyAndClearExpectations(component_factory()); | |
882 EXPECT_EQ(syncer::CONFIGURE_REASON_NEWLY_ENABLED_DATA_TYPE, configure_reason); | |
883 } | |
884 | |
885 // Test that the passphrase prompt due to version change logic gets triggered | |
886 // on a datatype type requesting startup, but only happens once. | |
887 TEST_F(ProfileSyncServiceTest, PassphrasePromptDueToVersion) { | |
888 IssueTestTokens(); | |
889 CreateService(ProfileSyncService::AUTO_START); | |
890 ExpectDataTypeManagerCreation(1, GetDefaultConfigureCalledCallback()); | |
891 ExpectSyncBackendHostCreation(1); | |
892 InitializeForNthSync(); | |
893 | |
894 sync_driver::SyncPrefs sync_prefs( | |
895 service()->GetSyncClient()->GetPrefService()); | |
896 EXPECT_EQ(PRODUCT_VERSION, sync_prefs.GetLastRunVersion()); | |
897 | |
898 sync_prefs.SetPassphrasePrompted(true); | |
899 | |
900 // Until a datatype requests startup while a passphrase is required the | |
901 // passphrase prompt bit should remain set. | |
902 EXPECT_TRUE(sync_prefs.IsPassphrasePrompted()); | |
903 TriggerPassphraseRequired(); | |
904 EXPECT_TRUE(sync_prefs.IsPassphrasePrompted()); | |
905 | |
906 // Because the last version was unset, this run should be treated as a new | |
907 // version and force a prompt. | |
908 TriggerDataTypeStartRequest(); | |
909 EXPECT_FALSE(sync_prefs.IsPassphrasePrompted()); | |
910 | |
911 // At this point further datatype startup request should have no effect. | |
912 sync_prefs.SetPassphrasePrompted(true); | |
913 TriggerDataTypeStartRequest(); | |
914 EXPECT_TRUE(sync_prefs.IsPassphrasePrompted()); | |
915 } | |
916 | |
917 // Test that when ProfileSyncService receives actionable error | |
918 // RESET_LOCAL_SYNC_DATA it restarts sync. | |
919 TEST_F(ProfileSyncServiceTest, ResetSyncData) { | |
920 IssueTestTokens(); | |
921 CreateService(ProfileSyncService::AUTO_START); | |
922 // Backend should get initialized two times: once during initialization and | |
923 // once when handling actionable error. | |
924 ExpectDataTypeManagerCreation(2, GetDefaultConfigureCalledCallback()); | |
925 ExpectSyncBackendHostCreation(2); | |
926 InitializeForNthSync(); | |
927 | |
928 syncer::SyncProtocolError client_cmd; | |
929 client_cmd.action = syncer::RESET_LOCAL_SYNC_DATA; | |
930 service()->OnActionableError(client_cmd); | |
931 } | |
932 | |
933 // Test that when ProfileSyncService receives actionable error | |
934 // DISABLE_SYNC_ON_CLIENT it disables sync and signs out. | |
935 TEST_F(ProfileSyncServiceTest, DisableSyncOnClient) { | |
936 IssueTestTokens(); | |
937 CreateService(ProfileSyncService::AUTO_START); | |
938 ExpectDataTypeManagerCreation(1, GetDefaultConfigureCalledCallback()); | |
939 ExpectSyncBackendHostCreation(1); | |
940 InitializeForNthSync(); | |
941 | |
942 EXPECT_TRUE(service()->IsSyncActive()); | |
943 EXPECT_EQ(l10n_util::GetStringUTF16(IDS_SYNC_TIME_JUST_NOW), | |
944 service()->GetLastSyncedTimeString()); | |
945 EXPECT_TRUE(service()->GetLocalDeviceInfoProvider()->GetLocalDeviceInfo()); | |
946 | |
947 syncer::SyncProtocolError client_cmd; | |
948 client_cmd.action = syncer::DISABLE_SYNC_ON_CLIENT; | |
949 service()->OnActionableError(client_cmd); | |
950 | |
951 // CrOS does not support signout. | |
952 #if !defined(OS_CHROMEOS) | |
953 EXPECT_TRUE(signin_manager()->GetAuthenticatedAccountId().empty()); | |
954 #else | |
955 EXPECT_FALSE(signin_manager()->GetAuthenticatedAccountId().empty()); | |
956 #endif | |
957 | |
958 EXPECT_FALSE(service()->IsSyncActive()); | |
959 EXPECT_EQ(l10n_util::GetStringUTF16(IDS_SYNC_TIME_NEVER), | |
960 service()->GetLastSyncedTimeString()); | |
961 EXPECT_FALSE(service()->GetLocalDeviceInfoProvider()->GetLocalDeviceInfo()); | |
962 } | |
963 | |
964 // Regression test for crbug/555434. The issue is that check for sessions DTC in | |
965 // OnSessionRestoreComplete was creating map entry with nullptr which later was | |
966 // dereferenced in OnSyncCycleCompleted. The fix is to use find() to check if | |
967 // entry for sessions exists in map. | |
968 TEST_F(ProfileSyncServiceTest, ValidPointersInDTCMap) { | |
969 CreateService(ProfileSyncService::AUTO_START); | |
970 service()->OnSessionRestoreComplete(); | |
971 service()->OnSyncCycleCompleted(); | |
972 } | |
973 | |
974 } // namespace | |
975 } // namespace browser_sync | |
OLD | NEW |