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

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

Issue 2533083002: [Sync] SyncEngine refactor part 1: interfaces. (Closed)
Patch Set: Rebase. Created 4 years 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 "components/browser_sync/profile_sync_service.h" 5 #include "components/browser_sync/profile_sync_service.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/feature_list.h" 11 #include "base/feature_list.h"
12 #include "base/memory/ptr_util.h" 12 #include "base/memory/ptr_util.h"
13 #include "base/run_loop.h" 13 #include "base/run_loop.h"
14 #include "base/single_thread_task_runner.h" 14 #include "base/single_thread_task_runner.h"
15 #include "base/strings/string_number_conversions.h" 15 #include "base/strings/string_number_conversions.h"
16 #include "base/strings/utf_string_conversions.h" 16 #include "base/strings/utf_string_conversions.h"
17 #include "base/test/scoped_feature_list.h" 17 #include "base/test/scoped_feature_list.h"
18 #include "base/test/sequenced_worker_pool_owner.h" 18 #include "base/test/sequenced_worker_pool_owner.h"
19 #include "base/threading/thread_task_runner_handle.h" 19 #include "base/threading/thread_task_runner_handle.h"
20 #include "base/values.h" 20 #include "base/values.h"
21 #include "components/browser_sync/browser_sync_switches.h" 21 #include "components/browser_sync/browser_sync_switches.h"
22 #include "components/browser_sync/profile_sync_test_util.h" 22 #include "components/browser_sync/profile_sync_test_util.h"
23 #include "components/invalidation/impl/profile_invalidation_provider.h" 23 #include "components/invalidation/impl/profile_invalidation_provider.h"
24 #include "components/invalidation/public/invalidation_service.h" 24 #include "components/invalidation/public/invalidation_service.h"
25 #include "components/signin/core/browser/account_tracker_service.h" 25 #include "components/signin/core/browser/account_tracker_service.h"
26 #include "components/signin/core/browser/fake_signin_manager.h" 26 #include "components/signin/core/browser/fake_signin_manager.h"
27 #include "components/strings/grit/components_strings.h" 27 #include "components/strings/grit/components_strings.h"
28 #include "components/sync/base/pref_names.h" 28 #include "components/sync/base/pref_names.h"
29 #include "components/sync/driver/fake_data_type_controller.h" 29 #include "components/sync/driver/fake_data_type_controller.h"
30 #include "components/sync/driver/glue/sync_backend_host_mock.h"
31 #include "components/sync/driver/sync_api_component_factory_mock.h" 30 #include "components/sync/driver/sync_api_component_factory_mock.h"
32 #include "components/sync/driver/sync_driver_switches.h" 31 #include "components/sync/driver/sync_driver_switches.h"
33 #include "components/sync/driver/sync_service_observer.h" 32 #include "components/sync/driver/sync_service_observer.h"
34 #include "components/sync/driver/sync_util.h" 33 #include "components/sync/driver/sync_util.h"
34 #include "components/sync/engine/fake_sync_engine.h"
35 #include "components/sync_preferences/testing_pref_service_syncable.h" 35 #include "components/sync_preferences/testing_pref_service_syncable.h"
36 #include "components/version_info/version_info_values.h" 36 #include "components/version_info/version_info_values.h"
37 #include "google_apis/gaia/gaia_constants.h" 37 #include "google_apis/gaia/gaia_constants.h"
38 #include "testing/gmock/include/gmock/gmock.h" 38 #include "testing/gmock/include/gmock/gmock.h"
39 #include "testing/gtest/include/gtest/gtest.h" 39 #include "testing/gtest/include/gtest/gtest.h"
40 #include "ui/base/l10n/l10n_util.h" 40 #include "ui/base/l10n/l10n_util.h"
41 41
42 using syncer::DataTypeController; 42 using syncer::DataTypeController;
43 using syncer::SyncBackendHostMock; 43 using syncer::FakeSyncEngine;
44 using syncer::SyncMergeResult; 44 using syncer::SyncMergeResult;
45 using testing::Return; 45 using testing::Return;
46 46
47 namespace browser_sync { 47 namespace browser_sync {
48 48
49 namespace { 49 namespace {
50 50
51 const char kGaiaId[] = "12345"; 51 const char kGaiaId[] = "12345";
52 const char kEmail[] = "test_user@gmail.com"; 52 const char kEmail[] = "test_user@gmail.com";
53 53
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 void OnStateChanged() override { 92 void OnStateChanged() override {
93 setup_in_progress_ = service_->IsSetupInProgress(); 93 setup_in_progress_ = service_->IsSetupInProgress();
94 } 94 }
95 bool setup_in_progress() const { return setup_in_progress_; } 95 bool setup_in_progress() const { return setup_in_progress_; }
96 96
97 private: 97 private:
98 ProfileSyncService* service_; 98 ProfileSyncService* service_;
99 bool setup_in_progress_; 99 bool setup_in_progress_;
100 }; 100 };
101 101
102 // A variant of the SyncBackendHostMock that won't automatically 102 // A variant of the FakeSyncEngine that won't automatically call back when asked
103 // call back when asked to initialized. Allows us to test things 103 // to initialized. Allows us to test things that could happen while backend init
104 // that could happen while backend init is in progress. 104 // is in progress.
105 class SyncBackendHostNoReturn : public SyncBackendHostMock { 105 class SyncEngineNoReturn : public FakeSyncEngine {
106 void Initialize( 106 void Initialize(
107 syncer::SyncFrontend* frontend, 107 syncer::SyncEngineHost* host,
108 scoped_refptr<base::SingleThreadTaskRunner> sync_task_runner, 108 scoped_refptr<base::SingleThreadTaskRunner> sync_task_runner,
109 const syncer::WeakHandle<syncer::JsEventHandler>& event_handler, 109 const syncer::WeakHandle<syncer::JsEventHandler>& event_handler,
110 const GURL& service_url, 110 const GURL& service_url,
111 const std::string& sync_user_agent, 111 const std::string& sync_user_agent,
112 const syncer::SyncCredentials& credentials, 112 const syncer::SyncCredentials& credentials,
113 bool delete_sync_data_folder, 113 bool delete_sync_data_folder,
114 bool enable_local_sync_backend, 114 bool enable_local_sync_backend,
115 const base::FilePath& local_sync_backend_folder, 115 const base::FilePath& local_sync_backend_folder,
116 std::unique_ptr<syncer::SyncManagerFactory> sync_manager_factory, 116 std::unique_ptr<syncer::SyncManagerFactory> sync_manager_factory,
117 const syncer::WeakHandle<syncer::UnrecoverableErrorHandler>& 117 const syncer::WeakHandle<syncer::UnrecoverableErrorHandler>&
118 unrecoverable_error_handler, 118 unrecoverable_error_handler,
119 const base::Closure& report_unrecoverable_error_function, 119 const base::Closure& report_unrecoverable_error_function,
120 const HttpPostProviderFactoryGetter& http_post_provider_factory_getter, 120 const HttpPostProviderFactoryGetter& http_post_provider_factory_getter,
121 std::unique_ptr<syncer::SyncEncryptionHandler::NigoriState> 121 std::unique_ptr<syncer::SyncEncryptionHandler::NigoriState>
122 saved_nigori_state) override {} 122 saved_nigori_state) override {}
123 }; 123 };
124 124
125 class SyncBackendHostMockCollectDeleteDirParam : public SyncBackendHostMock { 125 class FakeSyncEngineCollectDeleteDirParam : public FakeSyncEngine {
126 public: 126 public:
127 explicit SyncBackendHostMockCollectDeleteDirParam( 127 explicit FakeSyncEngineCollectDeleteDirParam(
128 std::vector<bool>* delete_dir_param) 128 std::vector<bool>* delete_dir_param)
129 : delete_dir_param_(delete_dir_param) {} 129 : delete_dir_param_(delete_dir_param) {}
130 130
131 void Initialize( 131 void Initialize(
132 syncer::SyncFrontend* frontend, 132 syncer::SyncEngineHost* host,
133 scoped_refptr<base::SingleThreadTaskRunner> sync_task_runner, 133 scoped_refptr<base::SingleThreadTaskRunner> sync_task_runner,
134 const syncer::WeakHandle<syncer::JsEventHandler>& event_handler, 134 const syncer::WeakHandle<syncer::JsEventHandler>& event_handler,
135 const GURL& service_url, 135 const GURL& service_url,
136 const std::string& sync_user_agent, 136 const std::string& sync_user_agent,
137 const syncer::SyncCredentials& credentials, 137 const syncer::SyncCredentials& credentials,
138 bool delete_sync_data_folder, 138 bool delete_sync_data_folder,
139 bool enable_local_sync_backend, 139 bool enable_local_sync_backend,
140 const base::FilePath& local_sync_backend_folder, 140 const base::FilePath& local_sync_backend_folder,
141 std::unique_ptr<syncer::SyncManagerFactory> sync_manager_factory, 141 std::unique_ptr<syncer::SyncManagerFactory> sync_manager_factory,
142 const syncer::WeakHandle<syncer::UnrecoverableErrorHandler>& 142 const syncer::WeakHandle<syncer::UnrecoverableErrorHandler>&
143 unrecoverable_error_handler, 143 unrecoverable_error_handler,
144 const base::Closure& report_unrecoverable_error_function, 144 const base::Closure& report_unrecoverable_error_function,
145 const HttpPostProviderFactoryGetter& http_post_provider_factory_getter, 145 const HttpPostProviderFactoryGetter& http_post_provider_factory_getter,
146 std::unique_ptr<syncer::SyncEncryptionHandler::NigoriState> 146 std::unique_ptr<syncer::SyncEncryptionHandler::NigoriState>
147 saved_nigori_state) override { 147 saved_nigori_state) override {
148 delete_dir_param_->push_back(delete_sync_data_folder); 148 delete_dir_param_->push_back(delete_sync_data_folder);
149 SyncBackendHostMock::Initialize( 149 FakeSyncEngine::Initialize(
150 frontend, std::move(sync_task_runner), event_handler, service_url, 150 host, std::move(sync_task_runner), event_handler, service_url,
151 sync_user_agent, credentials, delete_sync_data_folder, 151 sync_user_agent, credentials, delete_sync_data_folder,
152 enable_local_sync_backend, local_sync_backend_folder, 152 enable_local_sync_backend, local_sync_backend_folder,
153 std::move(sync_manager_factory), unrecoverable_error_handler, 153 std::move(sync_manager_factory), unrecoverable_error_handler,
154 report_unrecoverable_error_function, http_post_provider_factory_getter, 154 report_unrecoverable_error_function, http_post_provider_factory_getter,
155 std::move(saved_nigori_state)); 155 std::move(saved_nigori_state));
156 } 156 }
157 157
158 private: 158 private:
159 std::vector<bool>* delete_dir_param_; 159 std::vector<bool>* delete_dir_param_;
160 }; 160 };
161 161
162 // SyncBackendHostMock that calls an external callback when ClearServerData is 162 // FakeSyncEngine that calls an external callback when ClearServerData is
163 // called. 163 // called.
164 class SyncBackendHostCaptureClearServerData : public SyncBackendHostMock { 164 class SyncEngineCaptureClearServerData : public FakeSyncEngine {
165 public: 165 public:
166 typedef base::Callback<void( 166 typedef base::Callback<void(
167 const syncer::SyncManager::ClearServerDataCallback&)> 167 const syncer::SyncManager::ClearServerDataCallback&)>
168 ClearServerDataCalled; 168 ClearServerDataCalled;
169 explicit SyncBackendHostCaptureClearServerData( 169 explicit SyncEngineCaptureClearServerData(
170 const ClearServerDataCalled& clear_server_data_called) 170 const ClearServerDataCalled& clear_server_data_called)
171 : clear_server_data_called_(clear_server_data_called) {} 171 : clear_server_data_called_(clear_server_data_called) {}
172 172
173 void ClearServerData( 173 void ClearServerData(
174 const syncer::SyncManager::ClearServerDataCallback& callback) override { 174 const syncer::SyncManager::ClearServerDataCallback& callback) override {
175 clear_server_data_called_.Run(callback); 175 clear_server_data_called_.Run(callback);
176 } 176 }
177 177
178 private: 178 private:
179 ClearServerDataCalled clear_server_data_called_; 179 ClearServerDataCalled clear_server_data_called_;
180 }; 180 };
181 181
182 ACTION(ReturnNewSyncBackendHostMock) { 182 ACTION(ReturnNewFakeSyncEngine) {
183 return new SyncBackendHostMock(); 183 return new FakeSyncEngine();
184 } 184 }
185 185
186 ACTION(ReturnNewSyncBackendHostNoReturn) { 186 ACTION(ReturnNewSyncEngineNoReturn) {
187 return new SyncBackendHostNoReturn(); 187 return new SyncEngineNoReturn();
188 } 188 }
189 189
190 ACTION_P(ReturnNewMockHostCollectDeleteDirParam, delete_dir_param) { 190 ACTION_P(ReturnNewMockHostCollectDeleteDirParam, delete_dir_param) {
191 return new SyncBackendHostMockCollectDeleteDirParam(delete_dir_param); 191 return new FakeSyncEngineCollectDeleteDirParam(delete_dir_param);
192 } 192 }
193 193
194 void OnClearServerDataCalled( 194 void OnClearServerDataCalled(
195 syncer::SyncManager::ClearServerDataCallback* captured_callback, 195 syncer::SyncManager::ClearServerDataCallback* captured_callback,
196 const syncer::SyncManager::ClearServerDataCallback& callback) { 196 const syncer::SyncManager::ClearServerDataCallback& callback) {
197 *captured_callback = callback; 197 *captured_callback = callback;
198 } 198 }
199 199
200 ACTION_P(ReturnNewMockHostCaptureClearServerData, captured_callback) { 200 ACTION_P(ReturnNewMockHostCaptureClearServerData, captured_callback) {
201 return new SyncBackendHostCaptureClearServerData(base::Bind( 201 return new SyncEngineCaptureClearServerData(base::Bind(
202 &OnClearServerDataCalled, base::Unretained(captured_callback))); 202 &OnClearServerDataCalled, base::Unretained(captured_callback)));
203 } 203 }
204 204
205 void DoNothing(DataTypeController::ConfigureResult ignored1, 205 void DoNothing(DataTypeController::ConfigureResult ignored1,
206 const SyncMergeResult& ignored2, 206 const SyncMergeResult& ignored2,
207 const SyncMergeResult& ignored3) {} 207 const SyncMergeResult& ignored3) {}
208 208
209 // A test harness that uses a real ProfileSyncService and in most cases a 209 // A test harness that uses a real ProfileSyncService and in most cases a
210 // MockSyncBackendHost. 210 // MockSyncEngine.
211 // 211 //
212 // This is useful if we want to test the ProfileSyncService and don't care about 212 // This is useful if we want to test the ProfileSyncService and don't care about
213 // testing the SyncBackendHost. 213 // testing the SyncEngine.
214 class ProfileSyncServiceTest : public ::testing::Test { 214 class ProfileSyncServiceTest : public ::testing::Test {
215 protected: 215 protected:
216 ProfileSyncServiceTest() : component_factory_(nullptr) {} 216 ProfileSyncServiceTest() : component_factory_(nullptr) {}
217 ~ProfileSyncServiceTest() override {} 217 ~ProfileSyncServiceTest() override {}
218 218
219 void SetUp() override { 219 void SetUp() override {
220 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( 220 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
221 switches::kSyncDeferredStartupTimeoutSeconds, "0"); 221 switches::kSyncDeferredStartupTimeoutSeconds, "0");
222 } 222 }
223 223
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 } 308 }
309 309
310 void ExpectDataTypeManagerCreation( 310 void ExpectDataTypeManagerCreation(
311 int times, 311 int times,
312 const FakeDataTypeManager::ConfigureCalled& callback) { 312 const FakeDataTypeManager::ConfigureCalled& callback) {
313 EXPECT_CALL(*component_factory_, CreateDataTypeManager(_, _, _, _, _)) 313 EXPECT_CALL(*component_factory_, CreateDataTypeManager(_, _, _, _, _))
314 .Times(times) 314 .Times(times)
315 .WillRepeatedly(ReturnNewDataTypeManager(callback)); 315 .WillRepeatedly(ReturnNewDataTypeManager(callback));
316 } 316 }
317 317
318 void ExpectSyncBackendHostCreation(int times) { 318 void ExpectSyncEngineCreation(int times) {
319 EXPECT_CALL(*component_factory_, CreateSyncBackendHost(_, _, _, _)) 319 EXPECT_CALL(*component_factory_, CreateSyncEngine(_, _, _, _))
320 .Times(times) 320 .Times(times)
321 .WillRepeatedly(ReturnNewSyncBackendHostMock()); 321 .WillRepeatedly(ReturnNewFakeSyncEngine());
322 } 322 }
323 323
324 void ExpectSyncBackendHostCreationCollectDeleteDir( 324 void ExpectSyncEngineCreationCollectDeleteDir(
325 int times, 325 int times,
326 std::vector<bool>* delete_dir_param) { 326 std::vector<bool>* delete_dir_param) {
327 EXPECT_CALL(*component_factory_, CreateSyncBackendHost(_, _, _, _)) 327 EXPECT_CALL(*component_factory_, CreateSyncEngine(_, _, _, _))
328 .Times(times) 328 .Times(times)
329 .WillRepeatedly( 329 .WillRepeatedly(
330 ReturnNewMockHostCollectDeleteDirParam(delete_dir_param)); 330 ReturnNewMockHostCollectDeleteDirParam(delete_dir_param));
331 } 331 }
332 332
333 void ExpectSyncBackendHostCreationCaptureClearServerData( 333 void ExpectSyncEngineCreationCaptureClearServerData(
334 syncer::SyncManager::ClearServerDataCallback* captured_callback) { 334 syncer::SyncManager::ClearServerDataCallback* captured_callback) {
335 EXPECT_CALL(*component_factory_, CreateSyncBackendHost(_, _, _, _)) 335 EXPECT_CALL(*component_factory_, CreateSyncEngine(_, _, _, _))
336 .Times(1) 336 .Times(1)
337 .WillOnce(ReturnNewMockHostCaptureClearServerData(captured_callback)); 337 .WillOnce(ReturnNewMockHostCaptureClearServerData(captured_callback));
338 } 338 }
339 339
340 void PrepareDelayedInitSyncBackendHost() { 340 void PrepareDelayedInitSyncEngine() {
341 EXPECT_CALL(*component_factory_, CreateSyncBackendHost(_, _, _, _)) 341 EXPECT_CALL(*component_factory_, CreateSyncEngine(_, _, _, _))
342 .WillOnce(ReturnNewSyncBackendHostNoReturn()); 342 .WillOnce(ReturnNewSyncEngineNoReturn());
343 } 343 }
344 344
345 AccountTrackerService* account_tracker() { 345 AccountTrackerService* account_tracker() {
346 return profile_sync_service_bundle_.account_tracker(); 346 return profile_sync_service_bundle_.account_tracker();
347 } 347 }
348 348
349 #if defined(OS_CHROMEOS) 349 #if defined(OS_CHROMEOS)
350 SigninManagerBase* signin_manager() 350 SigninManagerBase* signin_manager()
351 #else 351 #else
352 SigninManager* signin_manager() 352 SigninManager* signin_manager()
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
397 url == syncer::internal::kSyncDevServerUrl); 397 url == syncer::internal::kSyncDevServerUrl);
398 } 398 }
399 399
400 // Verify a successful initialization. 400 // Verify a successful initialization.
401 TEST_F(ProfileSyncServiceTest, SuccessfulInitialization) { 401 TEST_F(ProfileSyncServiceTest, SuccessfulInitialization) {
402 prefs()->SetManagedPref(syncer::prefs::kSyncManaged, 402 prefs()->SetManagedPref(syncer::prefs::kSyncManaged,
403 new base::FundamentalValue(false)); 403 new base::FundamentalValue(false));
404 IssueTestTokens(); 404 IssueTestTokens();
405 CreateService(ProfileSyncService::AUTO_START); 405 CreateService(ProfileSyncService::AUTO_START);
406 ExpectDataTypeManagerCreation(1, GetDefaultConfigureCalledCallback()); 406 ExpectDataTypeManagerCreation(1, GetDefaultConfigureCalledCallback());
407 ExpectSyncBackendHostCreation(1); 407 ExpectSyncEngineCreation(1);
408 InitializeForNthSync(); 408 InitializeForNthSync();
409 EXPECT_FALSE(service()->IsManaged()); 409 EXPECT_FALSE(service()->IsManaged());
410 EXPECT_TRUE(service()->IsSyncActive()); 410 EXPECT_TRUE(service()->IsSyncActive());
411 } 411 }
412 412
413 // Verify that an initialization where first setup is not complete does not 413 // Verify that an initialization where first setup is not complete does not
414 // start up the backend. 414 // start up the backend.
415 TEST_F(ProfileSyncServiceTest, NeedsConfirmation) { 415 TEST_F(ProfileSyncServiceTest, NeedsConfirmation) {
416 prefs()->SetManagedPref(syncer::prefs::kSyncManaged, 416 prefs()->SetManagedPref(syncer::prefs::kSyncManaged,
417 new base::FundamentalValue(false)); 417 new base::FundamentalValue(false));
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
457 EXPECT_TRUE(service()->IsManaged()); 457 EXPECT_TRUE(service()->IsManaged());
458 EXPECT_FALSE(service()->IsSyncActive()); 458 EXPECT_FALSE(service()->IsSyncActive());
459 } 459 }
460 460
461 // Verify that disable by enterprise policy works even after the backend has 461 // Verify that disable by enterprise policy works even after the backend has
462 // been initialized. 462 // been initialized.
463 TEST_F(ProfileSyncServiceTest, DisabledByPolicyAfterInit) { 463 TEST_F(ProfileSyncServiceTest, DisabledByPolicyAfterInit) {
464 IssueTestTokens(); 464 IssueTestTokens();
465 CreateService(ProfileSyncService::AUTO_START); 465 CreateService(ProfileSyncService::AUTO_START);
466 ExpectDataTypeManagerCreation(1, GetDefaultConfigureCalledCallback()); 466 ExpectDataTypeManagerCreation(1, GetDefaultConfigureCalledCallback());
467 ExpectSyncBackendHostCreation(1); 467 ExpectSyncEngineCreation(1);
468 InitializeForNthSync(); 468 InitializeForNthSync();
469 469
470 EXPECT_FALSE(service()->IsManaged()); 470 EXPECT_FALSE(service()->IsManaged());
471 EXPECT_TRUE(service()->IsSyncActive()); 471 EXPECT_TRUE(service()->IsSyncActive());
472 472
473 prefs()->SetManagedPref(syncer::prefs::kSyncManaged, 473 prefs()->SetManagedPref(syncer::prefs::kSyncManaged,
474 new base::FundamentalValue(true)); 474 new base::FundamentalValue(true));
475 475
476 EXPECT_TRUE(service()->IsManaged()); 476 EXPECT_TRUE(service()->IsManaged());
477 EXPECT_FALSE(service()->IsSyncActive()); 477 EXPECT_FALSE(service()->IsSyncActive());
478 } 478 }
479 479
480 // Exercies the ProfileSyncService's code paths related to getting shut down 480 // Exercies the ProfileSyncService's code paths related to getting shut down
481 // before the backend initialize call returns. 481 // before the backend initialize call returns.
482 TEST_F(ProfileSyncServiceTest, AbortedByShutdown) { 482 TEST_F(ProfileSyncServiceTest, AbortedByShutdown) {
483 CreateService(ProfileSyncService::AUTO_START); 483 CreateService(ProfileSyncService::AUTO_START);
484 PrepareDelayedInitSyncBackendHost(); 484 PrepareDelayedInitSyncEngine();
485 485
486 IssueTestTokens(); 486 IssueTestTokens();
487 InitializeForNthSync(); 487 InitializeForNthSync();
488 EXPECT_FALSE(service()->IsSyncActive()); 488 EXPECT_FALSE(service()->IsSyncActive());
489 489
490 ShutdownAndDeleteService(); 490 ShutdownAndDeleteService();
491 } 491 }
492 492
493 // Test RequestStop() before we've initialized the backend. 493 // Test RequestStop() before we've initialized the backend.
494 TEST_F(ProfileSyncServiceTest, EarlyRequestStop) { 494 TEST_F(ProfileSyncServiceTest, EarlyRequestStop) {
495 CreateService(ProfileSyncService::AUTO_START); 495 CreateService(ProfileSyncService::AUTO_START);
496 IssueTestTokens(); 496 IssueTestTokens();
497 ExpectDataTypeManagerCreation(1, GetDefaultConfigureCalledCallback()); 497 ExpectDataTypeManagerCreation(1, GetDefaultConfigureCalledCallback());
498 ExpectSyncBackendHostCreation(1); 498 ExpectSyncEngineCreation(1);
499 499
500 service()->RequestStop(ProfileSyncService::KEEP_DATA); 500 service()->RequestStop(ProfileSyncService::KEEP_DATA);
501 EXPECT_FALSE(service()->IsSyncRequested()); 501 EXPECT_FALSE(service()->IsSyncRequested());
502 502
503 // Because sync is not requested, this should fail. 503 // Because sync is not requested, this should fail.
504 InitializeForNthSync(); 504 InitializeForNthSync();
505 EXPECT_FALSE(service()->IsSyncRequested()); 505 EXPECT_FALSE(service()->IsSyncRequested());
506 EXPECT_FALSE(service()->IsSyncActive()); 506 EXPECT_FALSE(service()->IsSyncActive());
507 507
508 // Request start. This should be enough to allow init to happen. 508 // Request start. This should be enough to allow init to happen.
509 service()->RequestStart(); 509 service()->RequestStart();
510 EXPECT_TRUE(service()->IsSyncRequested()); 510 EXPECT_TRUE(service()->IsSyncRequested());
511 EXPECT_TRUE(service()->IsSyncActive()); 511 EXPECT_TRUE(service()->IsSyncActive());
512 } 512 }
513 513
514 // Test RequestStop() after we've initialized the backend. 514 // Test RequestStop() after we've initialized the backend.
515 TEST_F(ProfileSyncServiceTest, DisableAndEnableSyncTemporarily) { 515 TEST_F(ProfileSyncServiceTest, DisableAndEnableSyncTemporarily) {
516 CreateService(ProfileSyncService::AUTO_START); 516 CreateService(ProfileSyncService::AUTO_START);
517 IssueTestTokens(); 517 IssueTestTokens();
518 ExpectDataTypeManagerCreation(1, GetDefaultConfigureCalledCallback()); 518 ExpectDataTypeManagerCreation(1, GetDefaultConfigureCalledCallback());
519 ExpectSyncBackendHostCreation(1); 519 ExpectSyncEngineCreation(1);
520 InitializeForNthSync(); 520 InitializeForNthSync();
521 521
522 EXPECT_TRUE(service()->IsSyncActive()); 522 EXPECT_TRUE(service()->IsSyncActive());
523 EXPECT_FALSE(prefs()->GetBoolean(syncer::prefs::kSyncSuppressStart)); 523 EXPECT_FALSE(prefs()->GetBoolean(syncer::prefs::kSyncSuppressStart));
524 524
525 testing::Mock::VerifyAndClearExpectations(component_factory()); 525 testing::Mock::VerifyAndClearExpectations(component_factory());
526 526
527 service()->RequestStop(ProfileSyncService::KEEP_DATA); 527 service()->RequestStop(ProfileSyncService::KEEP_DATA);
528 EXPECT_FALSE(service()->IsSyncActive()); 528 EXPECT_FALSE(service()->IsSyncActive());
529 EXPECT_TRUE(prefs()->GetBoolean(syncer::prefs::kSyncSuppressStart)); 529 EXPECT_TRUE(prefs()->GetBoolean(syncer::prefs::kSyncSuppressStart));
530 530
531 ExpectDataTypeManagerCreation(1, GetDefaultConfigureCalledCallback()); 531 ExpectDataTypeManagerCreation(1, GetDefaultConfigureCalledCallback());
532 ExpectSyncBackendHostCreation(1); 532 ExpectSyncEngineCreation(1);
533 533
534 service()->RequestStart(); 534 service()->RequestStart();
535 EXPECT_TRUE(service()->IsSyncActive()); 535 EXPECT_TRUE(service()->IsSyncActive());
536 EXPECT_FALSE(prefs()->GetBoolean(syncer::prefs::kSyncSuppressStart)); 536 EXPECT_FALSE(prefs()->GetBoolean(syncer::prefs::kSyncSuppressStart));
537 } 537 }
538 538
539 // Certain ProfileSyncService tests don't apply to Chrome OS, for example 539 // Certain ProfileSyncService tests don't apply to Chrome OS, for example
540 // things that deal with concepts like "signing out" and policy. 540 // things that deal with concepts like "signing out" and policy.
541 #if !defined(OS_CHROMEOS) 541 #if !defined(OS_CHROMEOS)
542 TEST_F(ProfileSyncServiceTest, EnableSyncAndSignOut) { 542 TEST_F(ProfileSyncServiceTest, EnableSyncAndSignOut) {
543 CreateService(ProfileSyncService::AUTO_START); 543 CreateService(ProfileSyncService::AUTO_START);
544 ExpectDataTypeManagerCreation(1, GetDefaultConfigureCalledCallback()); 544 ExpectDataTypeManagerCreation(1, GetDefaultConfigureCalledCallback());
545 ExpectSyncBackendHostCreation(1); 545 ExpectSyncEngineCreation(1);
546 IssueTestTokens(); 546 IssueTestTokens();
547 InitializeForNthSync(); 547 InitializeForNthSync();
548 548
549 EXPECT_TRUE(service()->IsSyncActive()); 549 EXPECT_TRUE(service()->IsSyncActive());
550 EXPECT_FALSE(prefs()->GetBoolean(syncer::prefs::kSyncSuppressStart)); 550 EXPECT_FALSE(prefs()->GetBoolean(syncer::prefs::kSyncSuppressStart));
551 551
552 signin_manager()->SignOut(signin_metrics::SIGNOUT_TEST, 552 signin_manager()->SignOut(signin_metrics::SIGNOUT_TEST,
553 signin_metrics::SignoutDelete::IGNORE_METRIC); 553 signin_metrics::SignoutDelete::IGNORE_METRIC);
554 EXPECT_FALSE(service()->IsSyncActive()); 554 EXPECT_FALSE(service()->IsSyncActive());
555 } 555 }
556 #endif // !defined(OS_CHROMEOS) 556 #endif // !defined(OS_CHROMEOS)
557 557
558 TEST_F(ProfileSyncServiceTest, GetSyncTokenStatus) { 558 TEST_F(ProfileSyncServiceTest, GetSyncTokenStatus) {
559 CreateService(ProfileSyncService::AUTO_START); 559 CreateService(ProfileSyncService::AUTO_START);
560 IssueTestTokens(); 560 IssueTestTokens();
561 ExpectDataTypeManagerCreation(1, GetDefaultConfigureCalledCallback()); 561 ExpectDataTypeManagerCreation(1, GetDefaultConfigureCalledCallback());
562 ExpectSyncBackendHostCreation(1); 562 ExpectSyncEngineCreation(1);
563 InitializeForNthSync(); 563 InitializeForNthSync();
564 564
565 // Initial status. 565 // Initial status.
566 ProfileSyncService::SyncTokenStatus token_status = 566 ProfileSyncService::SyncTokenStatus token_status =
567 service()->GetSyncTokenStatus(); 567 service()->GetSyncTokenStatus();
568 EXPECT_EQ(syncer::CONNECTION_NOT_ATTEMPTED, token_status.connection_status); 568 EXPECT_EQ(syncer::CONNECTION_NOT_ATTEMPTED, token_status.connection_status);
569 EXPECT_TRUE(token_status.connection_status_update_time.is_null()); 569 EXPECT_TRUE(token_status.connection_status_update_time.is_null());
570 EXPECT_TRUE(token_status.token_request_time.is_null()); 570 EXPECT_TRUE(token_status.token_request_time.is_null());
571 EXPECT_TRUE(token_status.token_receive_time.is_null()); 571 EXPECT_TRUE(token_status.token_receive_time.is_null());
572 572
(...skipping 16 matching lines...) Expand all
589 // Simulate successful connection. 589 // Simulate successful connection.
590 service()->OnConnectionStatusChange(syncer::CONNECTION_OK); 590 service()->OnConnectionStatusChange(syncer::CONNECTION_OK);
591 token_status = service()->GetSyncTokenStatus(); 591 token_status = service()->GetSyncTokenStatus();
592 EXPECT_EQ(syncer::CONNECTION_OK, token_status.connection_status); 592 EXPECT_EQ(syncer::CONNECTION_OK, token_status.connection_status);
593 } 593 }
594 594
595 TEST_F(ProfileSyncServiceTest, RevokeAccessTokenFromTokenService) { 595 TEST_F(ProfileSyncServiceTest, RevokeAccessTokenFromTokenService) {
596 CreateService(ProfileSyncService::AUTO_START); 596 CreateService(ProfileSyncService::AUTO_START);
597 IssueTestTokens(); 597 IssueTestTokens();
598 ExpectDataTypeManagerCreation(1, GetDefaultConfigureCalledCallback()); 598 ExpectDataTypeManagerCreation(1, GetDefaultConfigureCalledCallback());
599 ExpectSyncBackendHostCreation(1); 599 ExpectSyncEngineCreation(1);
600 InitializeForNthSync(); 600 InitializeForNthSync();
601 EXPECT_TRUE(service()->IsSyncActive()); 601 EXPECT_TRUE(service()->IsSyncActive());
602 602
603 std::string primary_account_id = 603 std::string primary_account_id =
604 signin_manager()->GetAuthenticatedAccountId(); 604 signin_manager()->GetAuthenticatedAccountId();
605 auth_service()->LoadCredentials(primary_account_id); 605 auth_service()->LoadCredentials(primary_account_id);
606 base::RunLoop().RunUntilIdle(); 606 base::RunLoop().RunUntilIdle();
607 EXPECT_FALSE(service()->GetAccessTokenForTest().empty()); 607 EXPECT_FALSE(service()->GetAccessTokenForTest().empty());
608 608
609 std::string secondary_account_gaiaid = "1234567"; 609 std::string secondary_account_gaiaid = "1234567";
610 std::string secondary_account_name = "test_user2@gmail.com"; 610 std::string secondary_account_name = "test_user2@gmail.com";
611 std::string secondary_account_id = account_tracker()->SeedAccountInfo( 611 std::string secondary_account_id = account_tracker()->SeedAccountInfo(
612 secondary_account_gaiaid, secondary_account_name); 612 secondary_account_gaiaid, secondary_account_name);
613 auth_service()->UpdateCredentials(secondary_account_id, 613 auth_service()->UpdateCredentials(secondary_account_id,
614 "second_account_refresh_token"); 614 "second_account_refresh_token");
615 auth_service()->RevokeCredentials(secondary_account_id); 615 auth_service()->RevokeCredentials(secondary_account_id);
616 EXPECT_FALSE(service()->GetAccessTokenForTest().empty()); 616 EXPECT_FALSE(service()->GetAccessTokenForTest().empty());
617 617
618 auth_service()->RevokeCredentials(primary_account_id); 618 auth_service()->RevokeCredentials(primary_account_id);
619 EXPECT_TRUE(service()->GetAccessTokenForTest().empty()); 619 EXPECT_TRUE(service()->GetAccessTokenForTest().empty());
620 } 620 }
621 621
622 // CrOS does not support signout. 622 // CrOS does not support signout.
623 #if !defined(OS_CHROMEOS) 623 #if !defined(OS_CHROMEOS)
624 TEST_F(ProfileSyncServiceTest, SignOutRevokeAccessToken) { 624 TEST_F(ProfileSyncServiceTest, SignOutRevokeAccessToken) {
625 CreateService(ProfileSyncService::AUTO_START); 625 CreateService(ProfileSyncService::AUTO_START);
626 IssueTestTokens(); 626 IssueTestTokens();
627 ExpectDataTypeManagerCreation(1, GetDefaultConfigureCalledCallback()); 627 ExpectDataTypeManagerCreation(1, GetDefaultConfigureCalledCallback());
628 ExpectSyncBackendHostCreation(1); 628 ExpectSyncEngineCreation(1);
629 InitializeForNthSync(); 629 InitializeForNthSync();
630 EXPECT_TRUE(service()->IsSyncActive()); 630 EXPECT_TRUE(service()->IsSyncActive());
631 631
632 std::string primary_account_id = 632 std::string primary_account_id =
633 signin_manager()->GetAuthenticatedAccountId(); 633 signin_manager()->GetAuthenticatedAccountId();
634 auth_service()->LoadCredentials(primary_account_id); 634 auth_service()->LoadCredentials(primary_account_id);
635 base::RunLoop().RunUntilIdle(); 635 base::RunLoop().RunUntilIdle();
636 EXPECT_FALSE(service()->GetAccessTokenForTest().empty()); 636 EXPECT_FALSE(service()->GetAccessTokenForTest().empty());
637 637
638 signin_manager()->SignOut(signin_metrics::SIGNOUT_TEST, 638 signin_manager()->SignOut(signin_metrics::SIGNOUT_TEST,
639 signin_metrics::SignoutDelete::IGNORE_METRIC); 639 signin_metrics::SignoutDelete::IGNORE_METRIC);
640 EXPECT_TRUE(service()->GetAccessTokenForTest().empty()); 640 EXPECT_TRUE(service()->GetAccessTokenForTest().empty());
641 } 641 }
642 #endif 642 #endif
643 643
644 // Verify that LastSyncedTime and local DeviceInfo is cleared on sign out. 644 // Verify that LastSyncedTime and local DeviceInfo is cleared on sign out.
645 TEST_F(ProfileSyncServiceTest, ClearDataOnSignOut) { 645 TEST_F(ProfileSyncServiceTest, ClearDataOnSignOut) {
646 IssueTestTokens(); 646 IssueTestTokens();
647 CreateService(ProfileSyncService::AUTO_START); 647 CreateService(ProfileSyncService::AUTO_START);
648 ExpectDataTypeManagerCreation(1, GetDefaultConfigureCalledCallback()); 648 ExpectDataTypeManagerCreation(1, GetDefaultConfigureCalledCallback());
649 ExpectSyncBackendHostCreation(1); 649 ExpectSyncEngineCreation(1);
650 InitializeForNthSync(); 650 InitializeForNthSync();
651 EXPECT_TRUE(service()->IsSyncActive()); 651 EXPECT_TRUE(service()->IsSyncActive());
652 EXPECT_EQ(l10n_util::GetStringUTF16(IDS_SYNC_TIME_JUST_NOW), 652 EXPECT_EQ(l10n_util::GetStringUTF16(IDS_SYNC_TIME_JUST_NOW),
653 service()->GetLastSyncedTimeString()); 653 service()->GetLastSyncedTimeString());
654 EXPECT_TRUE(service()->GetLocalDeviceInfoProvider()->GetLocalDeviceInfo()); 654 EXPECT_TRUE(service()->GetLocalDeviceInfoProvider()->GetLocalDeviceInfo());
655 655
656 // Sign out. 656 // Sign out.
657 service()->RequestStop(ProfileSyncService::CLEAR_DATA); 657 service()->RequestStop(ProfileSyncService::CLEAR_DATA);
658 PumpLoop(); 658 PumpLoop();
659 659
(...skipping 11 matching lines...) Expand all
671 // Verify that no disable sync flag enables sync. 671 // Verify that no disable sync flag enables sync.
672 TEST_F(ProfileSyncServiceTest, NoDisableSyncFlag) { 672 TEST_F(ProfileSyncServiceTest, NoDisableSyncFlag) {
673 EXPECT_TRUE(ProfileSyncService::IsSyncAllowedByFlag()); 673 EXPECT_TRUE(ProfileSyncService::IsSyncAllowedByFlag());
674 } 674 }
675 675
676 // Test Sync will stop after receive memory pressure 676 // Test Sync will stop after receive memory pressure
677 TEST_F(ProfileSyncServiceTest, MemoryPressureRecording) { 677 TEST_F(ProfileSyncServiceTest, MemoryPressureRecording) {
678 CreateService(ProfileSyncService::AUTO_START); 678 CreateService(ProfileSyncService::AUTO_START);
679 IssueTestTokens(); 679 IssueTestTokens();
680 ExpectDataTypeManagerCreation(1, GetDefaultConfigureCalledCallback()); 680 ExpectDataTypeManagerCreation(1, GetDefaultConfigureCalledCallback());
681 ExpectSyncBackendHostCreation(1); 681 ExpectSyncEngineCreation(1);
682 InitializeForNthSync(); 682 InitializeForNthSync();
683 683
684 EXPECT_TRUE(service()->IsSyncActive()); 684 EXPECT_TRUE(service()->IsSyncActive());
685 EXPECT_FALSE(prefs()->GetBoolean(syncer::prefs::kSyncSuppressStart)); 685 EXPECT_FALSE(prefs()->GetBoolean(syncer::prefs::kSyncSuppressStart));
686 686
687 testing::Mock::VerifyAndClearExpectations(component_factory()); 687 testing::Mock::VerifyAndClearExpectations(component_factory());
688 688
689 syncer::SyncPrefs sync_prefs(service()->GetSyncClient()->GetPrefService()); 689 syncer::SyncPrefs sync_prefs(service()->GetSyncClient()->GetPrefService());
690 690
691 EXPECT_EQ(prefs()->GetInteger(syncer::prefs::kSyncMemoryPressureWarningCount), 691 EXPECT_EQ(prefs()->GetInteger(syncer::prefs::kSyncMemoryPressureWarningCount),
(...skipping 27 matching lines...) Expand all
719 TEST_F(ProfileSyncServiceTest, OnLocalSetPassphraseEncryption) { 719 TEST_F(ProfileSyncServiceTest, OnLocalSetPassphraseEncryption) {
720 base::test::ScopedFeatureList scoped_feature_list; 720 base::test::ScopedFeatureList scoped_feature_list;
721 scoped_feature_list.InitAndEnableFeature( 721 scoped_feature_list.InitAndEnableFeature(
722 switches::kSyncClearDataOnPassphraseEncryption); 722 switches::kSyncClearDataOnPassphraseEncryption);
723 IssueTestTokens(); 723 IssueTestTokens();
724 CreateService(ProfileSyncService::AUTO_START); 724 CreateService(ProfileSyncService::AUTO_START);
725 725
726 syncer::SyncManager::ClearServerDataCallback captured_callback; 726 syncer::SyncManager::ClearServerDataCallback captured_callback;
727 syncer::ConfigureReason configure_reason = syncer::CONFIGURE_REASON_UNKNOWN; 727 syncer::ConfigureReason configure_reason = syncer::CONFIGURE_REASON_UNKNOWN;
728 728
729 // Initialize sync, ensure that both DataTypeManager and SyncBackendHost are 729 // Initialize sync, ensure that both DataTypeManager and SyncEngine are
730 // initialized and DTM::Configure is called with 730 // initialized and DTM::Configure is called with
731 // CONFIGURE_REASON_NEWLY_ENABLED_DATA_TYPE. 731 // CONFIGURE_REASON_NEWLY_ENABLED_DATA_TYPE.
732 ExpectSyncBackendHostCreationCaptureClearServerData(&captured_callback); 732 ExpectSyncEngineCreationCaptureClearServerData(&captured_callback);
733 ExpectDataTypeManagerCreation( 733 ExpectDataTypeManagerCreation(
734 1, GetRecordingConfigureCalledCallback(&configure_reason)); 734 1, GetRecordingConfigureCalledCallback(&configure_reason));
735 InitializeForNthSync(); 735 InitializeForNthSync();
736 EXPECT_TRUE(service()->IsSyncActive()); 736 EXPECT_TRUE(service()->IsSyncActive());
737 testing::Mock::VerifyAndClearExpectations(component_factory()); 737 testing::Mock::VerifyAndClearExpectations(component_factory());
738 EXPECT_EQ(syncer::CONFIGURE_REASON_NEWLY_ENABLED_DATA_TYPE, configure_reason); 738 EXPECT_EQ(syncer::CONFIGURE_REASON_NEWLY_ENABLED_DATA_TYPE, configure_reason);
739 syncer::DataTypeManager::ConfigureResult result; 739 syncer::DataTypeManager::ConfigureResult result;
740 result.status = syncer::DataTypeManager::OK; 740 result.status = syncer::DataTypeManager::OK;
741 service()->OnConfigureDone(result); 741 service()->OnConfigureDone(result);
742 742
743 // Simulate user entering encryption passphrase. Ensure that catch up 743 // Simulate user entering encryption passphrase. Ensure that catch up
744 // configure cycle is started (DTM::Configure is called with 744 // configure cycle is started (DTM::Configure is called with
745 // CONFIGURE_REASON_CATCH_UP). 745 // CONFIGURE_REASON_CATCH_UP).
746 const syncer::SyncEncryptionHandler::NigoriState nigori_state; 746 const syncer::SyncEncryptionHandler::NigoriState nigori_state;
747 service()->OnLocalSetPassphraseEncryption(nigori_state); 747 service()->OnLocalSetPassphraseEncryption(nigori_state);
748 EXPECT_EQ(syncer::CONFIGURE_REASON_CATCH_UP, configure_reason); 748 EXPECT_EQ(syncer::CONFIGURE_REASON_CATCH_UP, configure_reason);
749 EXPECT_TRUE(captured_callback.is_null()); 749 EXPECT_TRUE(captured_callback.is_null());
750 750
751 // Simulate configure successful. Ensure that SBH::ClearServerData is called. 751 // Simulate configure successful. Ensure that SBH::ClearServerData is called.
752 service()->OnConfigureDone(result); 752 service()->OnConfigureDone(result);
753 EXPECT_FALSE(captured_callback.is_null()); 753 EXPECT_FALSE(captured_callback.is_null());
754 754
755 // Once SBH::ClearServerData finishes successfully ensure that sync is 755 // Once SBH::ClearServerData finishes successfully ensure that sync is
756 // restarted. 756 // restarted.
757 configure_reason = syncer::CONFIGURE_REASON_UNKNOWN; 757 configure_reason = syncer::CONFIGURE_REASON_UNKNOWN;
758 ExpectSyncBackendHostCreation(1); 758 ExpectSyncEngineCreation(1);
759 ExpectDataTypeManagerCreation( 759 ExpectDataTypeManagerCreation(
760 1, GetRecordingConfigureCalledCallback(&configure_reason)); 760 1, GetRecordingConfigureCalledCallback(&configure_reason));
761 captured_callback.Run(); 761 captured_callback.Run();
762 testing::Mock::VerifyAndClearExpectations(component_factory()); 762 testing::Mock::VerifyAndClearExpectations(component_factory());
763 EXPECT_EQ(syncer::CONFIGURE_REASON_NEWLY_ENABLED_DATA_TYPE, configure_reason); 763 EXPECT_EQ(syncer::CONFIGURE_REASON_NEWLY_ENABLED_DATA_TYPE, configure_reason);
764 service()->OnConfigureDone(result); 764 service()->OnConfigureDone(result);
765 } 765 }
766 766
767 // Verify that if after OnLocalSetPassphraseEncryption catch up configure sync 767 // Verify that if after OnLocalSetPassphraseEncryption catch up configure sync
768 // cycle gets interrupted, it starts again after browser restart. 768 // cycle gets interrupted, it starts again after browser restart.
769 TEST_F(ProfileSyncServiceTest, 769 TEST_F(ProfileSyncServiceTest,
770 OnLocalSetPassphraseEncryption_RestartDuringCatchUp) { 770 OnLocalSetPassphraseEncryption_RestartDuringCatchUp) {
771 syncer::ConfigureReason configure_reason = syncer::CONFIGURE_REASON_UNKNOWN; 771 syncer::ConfigureReason configure_reason = syncer::CONFIGURE_REASON_UNKNOWN;
772 base::test::ScopedFeatureList scoped_feature_list; 772 base::test::ScopedFeatureList scoped_feature_list;
773 scoped_feature_list.InitAndEnableFeature( 773 scoped_feature_list.InitAndEnableFeature(
774 switches::kSyncClearDataOnPassphraseEncryption); 774 switches::kSyncClearDataOnPassphraseEncryption);
775 IssueTestTokens(); 775 IssueTestTokens();
776 CreateService(ProfileSyncService::AUTO_START); 776 CreateService(ProfileSyncService::AUTO_START);
777 ExpectSyncBackendHostCreation(1); 777 ExpectSyncEngineCreation(1);
778 ExpectDataTypeManagerCreation( 778 ExpectDataTypeManagerCreation(
779 1, GetRecordingConfigureCalledCallback(&configure_reason)); 779 1, GetRecordingConfigureCalledCallback(&configure_reason));
780 InitializeForNthSync(); 780 InitializeForNthSync();
781 testing::Mock::VerifyAndClearExpectations(component_factory()); 781 testing::Mock::VerifyAndClearExpectations(component_factory());
782 EXPECT_EQ(syncer::CONFIGURE_REASON_NEWLY_ENABLED_DATA_TYPE, configure_reason); 782 EXPECT_EQ(syncer::CONFIGURE_REASON_NEWLY_ENABLED_DATA_TYPE, configure_reason);
783 syncer::DataTypeManager::ConfigureResult result; 783 syncer::DataTypeManager::ConfigureResult result;
784 result.status = syncer::DataTypeManager::OK; 784 result.status = syncer::DataTypeManager::OK;
785 service()->OnConfigureDone(result); 785 service()->OnConfigureDone(result);
786 786
787 // Simulate user entering encryption passphrase. Ensure Configure was called 787 // Simulate user entering encryption passphrase. Ensure Configure was called
788 // but don't let it continue. 788 // but don't let it continue.
789 const syncer::SyncEncryptionHandler::NigoriState nigori_state; 789 const syncer::SyncEncryptionHandler::NigoriState nigori_state;
790 service()->OnLocalSetPassphraseEncryption(nigori_state); 790 service()->OnLocalSetPassphraseEncryption(nigori_state);
791 EXPECT_EQ(syncer::CONFIGURE_REASON_CATCH_UP, configure_reason); 791 EXPECT_EQ(syncer::CONFIGURE_REASON_CATCH_UP, configure_reason);
792 792
793 // Simulate browser restart. First configuration is a regular one. 793 // Simulate browser restart. First configuration is a regular one.
794 service()->Shutdown(); 794 service()->Shutdown();
795 syncer::SyncManager::ClearServerDataCallback captured_callback; 795 syncer::SyncManager::ClearServerDataCallback captured_callback;
796 ExpectSyncBackendHostCreationCaptureClearServerData(&captured_callback); 796 ExpectSyncEngineCreationCaptureClearServerData(&captured_callback);
797 ExpectDataTypeManagerCreation( 797 ExpectDataTypeManagerCreation(
798 1, GetRecordingConfigureCalledCallback(&configure_reason)); 798 1, GetRecordingConfigureCalledCallback(&configure_reason));
799 service()->RequestStart(); 799 service()->RequestStart();
800 testing::Mock::VerifyAndClearExpectations(component_factory()); 800 testing::Mock::VerifyAndClearExpectations(component_factory());
801 EXPECT_EQ(syncer::CONFIGURE_REASON_NEWLY_ENABLED_DATA_TYPE, configure_reason); 801 EXPECT_EQ(syncer::CONFIGURE_REASON_NEWLY_ENABLED_DATA_TYPE, configure_reason);
802 EXPECT_TRUE(captured_callback.is_null()); 802 EXPECT_TRUE(captured_callback.is_null());
803 803
804 // Simulate configure successful. This time it should be catch up. 804 // Simulate configure successful. This time it should be catch up.
805 service()->OnConfigureDone(result); 805 service()->OnConfigureDone(result);
806 EXPECT_EQ(syncer::CONFIGURE_REASON_CATCH_UP, configure_reason); 806 EXPECT_EQ(syncer::CONFIGURE_REASON_CATCH_UP, configure_reason);
807 EXPECT_TRUE(captured_callback.is_null()); 807 EXPECT_TRUE(captured_callback.is_null());
808 808
809 // Simulate catch up configure successful. Ensure that SBH::ClearServerData is 809 // Simulate catch up configure successful. Ensure that SBH::ClearServerData is
810 // called. 810 // called.
811 service()->OnConfigureDone(result); 811 service()->OnConfigureDone(result);
812 EXPECT_FALSE(captured_callback.is_null()); 812 EXPECT_FALSE(captured_callback.is_null());
813 813
814 ExpectSyncBackendHostCreation(1); 814 ExpectSyncEngineCreation(1);
815 ExpectDataTypeManagerCreation( 815 ExpectDataTypeManagerCreation(
816 1, GetRecordingConfigureCalledCallback(&configure_reason)); 816 1, GetRecordingConfigureCalledCallback(&configure_reason));
817 captured_callback.Run(); 817 captured_callback.Run();
818 testing::Mock::VerifyAndClearExpectations(component_factory()); 818 testing::Mock::VerifyAndClearExpectations(component_factory());
819 EXPECT_EQ(syncer::CONFIGURE_REASON_NEWLY_ENABLED_DATA_TYPE, configure_reason); 819 EXPECT_EQ(syncer::CONFIGURE_REASON_NEWLY_ENABLED_DATA_TYPE, configure_reason);
820 } 820 }
821 821
822 // Verify that if after OnLocalSetPassphraseEncryption ClearServerData gets 822 // Verify that if after OnLocalSetPassphraseEncryption ClearServerData gets
823 // interrupted, transition again from catch up sync cycle after browser restart. 823 // interrupted, transition again from catch up sync cycle after browser restart.
824 TEST_F(ProfileSyncServiceTest, 824 TEST_F(ProfileSyncServiceTest,
825 OnLocalSetPassphraseEncryption_RestartDuringClearServerData) { 825 OnLocalSetPassphraseEncryption_RestartDuringClearServerData) {
826 syncer::SyncManager::ClearServerDataCallback captured_callback; 826 syncer::SyncManager::ClearServerDataCallback captured_callback;
827 syncer::ConfigureReason configure_reason = syncer::CONFIGURE_REASON_UNKNOWN; 827 syncer::ConfigureReason configure_reason = syncer::CONFIGURE_REASON_UNKNOWN;
828 base::test::ScopedFeatureList scoped_feature_list; 828 base::test::ScopedFeatureList scoped_feature_list;
829 scoped_feature_list.InitAndEnableFeature( 829 scoped_feature_list.InitAndEnableFeature(
830 switches::kSyncClearDataOnPassphraseEncryption); 830 switches::kSyncClearDataOnPassphraseEncryption);
831 IssueTestTokens(); 831 IssueTestTokens();
832 CreateService(ProfileSyncService::AUTO_START); 832 CreateService(ProfileSyncService::AUTO_START);
833 ExpectSyncBackendHostCreationCaptureClearServerData(&captured_callback); 833 ExpectSyncEngineCreationCaptureClearServerData(&captured_callback);
834 ExpectDataTypeManagerCreation(1, GetDefaultConfigureCalledCallback()); 834 ExpectDataTypeManagerCreation(1, GetDefaultConfigureCalledCallback());
835 InitializeForNthSync(); 835 InitializeForNthSync();
836 testing::Mock::VerifyAndClearExpectations(component_factory()); 836 testing::Mock::VerifyAndClearExpectations(component_factory());
837 837
838 // Simulate user entering encryption passphrase. 838 // Simulate user entering encryption passphrase.
839 const syncer::SyncEncryptionHandler::NigoriState nigori_state; 839 const syncer::SyncEncryptionHandler::NigoriState nigori_state;
840 service()->OnLocalSetPassphraseEncryption(nigori_state); 840 service()->OnLocalSetPassphraseEncryption(nigori_state);
841 EXPECT_FALSE(captured_callback.is_null()); 841 EXPECT_FALSE(captured_callback.is_null());
842 captured_callback.Reset(); 842 captured_callback.Reset();
843 843
844 // Simulate browser restart. First configuration is a regular one. 844 // Simulate browser restart. First configuration is a regular one.
845 service()->Shutdown(); 845 service()->Shutdown();
846 ExpectSyncBackendHostCreationCaptureClearServerData(&captured_callback); 846 ExpectSyncEngineCreationCaptureClearServerData(&captured_callback);
847 ExpectDataTypeManagerCreation( 847 ExpectDataTypeManagerCreation(
848 1, GetRecordingConfigureCalledCallback(&configure_reason)); 848 1, GetRecordingConfigureCalledCallback(&configure_reason));
849 service()->RequestStart(); 849 service()->RequestStart();
850 testing::Mock::VerifyAndClearExpectations(component_factory()); 850 testing::Mock::VerifyAndClearExpectations(component_factory());
851 EXPECT_EQ(syncer::CONFIGURE_REASON_NEWLY_ENABLED_DATA_TYPE, configure_reason); 851 EXPECT_EQ(syncer::CONFIGURE_REASON_NEWLY_ENABLED_DATA_TYPE, configure_reason);
852 EXPECT_TRUE(captured_callback.is_null()); 852 EXPECT_TRUE(captured_callback.is_null());
853 853
854 // Simulate configure successful. This time it should be catch up. 854 // Simulate configure successful. This time it should be catch up.
855 syncer::DataTypeManager::ConfigureResult result; 855 syncer::DataTypeManager::ConfigureResult result;
856 result.status = syncer::DataTypeManager::OK; 856 result.status = syncer::DataTypeManager::OK;
857 service()->OnConfigureDone(result); 857 service()->OnConfigureDone(result);
858 EXPECT_EQ(syncer::CONFIGURE_REASON_CATCH_UP, configure_reason); 858 EXPECT_EQ(syncer::CONFIGURE_REASON_CATCH_UP, configure_reason);
859 EXPECT_TRUE(captured_callback.is_null()); 859 EXPECT_TRUE(captured_callback.is_null());
860 860
861 // Simulate catch up configure successful. Ensure that SBH::ClearServerData is 861 // Simulate catch up configure successful. Ensure that SBH::ClearServerData is
862 // called. 862 // called.
863 service()->OnConfigureDone(result); 863 service()->OnConfigureDone(result);
864 EXPECT_FALSE(captured_callback.is_null()); 864 EXPECT_FALSE(captured_callback.is_null());
865 865
866 ExpectSyncBackendHostCreation(1); 866 ExpectSyncEngineCreation(1);
867 ExpectDataTypeManagerCreation( 867 ExpectDataTypeManagerCreation(
868 1, GetRecordingConfigureCalledCallback(&configure_reason)); 868 1, GetRecordingConfigureCalledCallback(&configure_reason));
869 captured_callback.Run(); 869 captured_callback.Run();
870 testing::Mock::VerifyAndClearExpectations(component_factory()); 870 testing::Mock::VerifyAndClearExpectations(component_factory());
871 EXPECT_EQ(syncer::CONFIGURE_REASON_NEWLY_ENABLED_DATA_TYPE, configure_reason); 871 EXPECT_EQ(syncer::CONFIGURE_REASON_NEWLY_ENABLED_DATA_TYPE, configure_reason);
872 } 872 }
873 873
874 // Test that the passphrase prompt due to version change logic gets triggered 874 // Test that the passphrase prompt due to version change logic gets triggered
875 // on a datatype type requesting startup, but only happens once. 875 // on a datatype type requesting startup, but only happens once.
876 TEST_F(ProfileSyncServiceTest, PassphrasePromptDueToVersion) { 876 TEST_F(ProfileSyncServiceTest, PassphrasePromptDueToVersion) {
877 IssueTestTokens(); 877 IssueTestTokens();
878 CreateService(ProfileSyncService::AUTO_START); 878 CreateService(ProfileSyncService::AUTO_START);
879 ExpectDataTypeManagerCreation(1, GetDefaultConfigureCalledCallback()); 879 ExpectDataTypeManagerCreation(1, GetDefaultConfigureCalledCallback());
880 ExpectSyncBackendHostCreation(1); 880 ExpectSyncEngineCreation(1);
881 InitializeForNthSync(); 881 InitializeForNthSync();
882 882
883 syncer::SyncPrefs sync_prefs(service()->GetSyncClient()->GetPrefService()); 883 syncer::SyncPrefs sync_prefs(service()->GetSyncClient()->GetPrefService());
884 EXPECT_EQ(PRODUCT_VERSION, sync_prefs.GetLastRunVersion()); 884 EXPECT_EQ(PRODUCT_VERSION, sync_prefs.GetLastRunVersion());
885 885
886 sync_prefs.SetPassphrasePrompted(true); 886 sync_prefs.SetPassphrasePrompted(true);
887 887
888 // Until a datatype requests startup while a passphrase is required the 888 // Until a datatype requests startup while a passphrase is required the
889 // passphrase prompt bit should remain set. 889 // passphrase prompt bit should remain set.
890 EXPECT_TRUE(sync_prefs.IsPassphrasePrompted()); 890 EXPECT_TRUE(sync_prefs.IsPassphrasePrompted());
(...skipping 12 matching lines...) Expand all
903 } 903 }
904 904
905 // Test that when ProfileSyncService receives actionable error 905 // Test that when ProfileSyncService receives actionable error
906 // RESET_LOCAL_SYNC_DATA it restarts sync. 906 // RESET_LOCAL_SYNC_DATA it restarts sync.
907 TEST_F(ProfileSyncServiceTest, ResetSyncData) { 907 TEST_F(ProfileSyncServiceTest, ResetSyncData) {
908 IssueTestTokens(); 908 IssueTestTokens();
909 CreateService(ProfileSyncService::AUTO_START); 909 CreateService(ProfileSyncService::AUTO_START);
910 // Backend should get initialized two times: once during initialization and 910 // Backend should get initialized two times: once during initialization and
911 // once when handling actionable error. 911 // once when handling actionable error.
912 ExpectDataTypeManagerCreation(2, GetDefaultConfigureCalledCallback()); 912 ExpectDataTypeManagerCreation(2, GetDefaultConfigureCalledCallback());
913 ExpectSyncBackendHostCreation(2); 913 ExpectSyncEngineCreation(2);
914 InitializeForNthSync(); 914 InitializeForNthSync();
915 915
916 syncer::SyncProtocolError client_cmd; 916 syncer::SyncProtocolError client_cmd;
917 client_cmd.action = syncer::RESET_LOCAL_SYNC_DATA; 917 client_cmd.action = syncer::RESET_LOCAL_SYNC_DATA;
918 service()->OnActionableError(client_cmd); 918 service()->OnActionableError(client_cmd);
919 } 919 }
920 920
921 // Test that when ProfileSyncService receives actionable error 921 // Test that when ProfileSyncService receives actionable error
922 // DISABLE_SYNC_ON_CLIENT it disables sync and signs out. 922 // DISABLE_SYNC_ON_CLIENT it disables sync and signs out.
923 TEST_F(ProfileSyncServiceTest, DisableSyncOnClient) { 923 TEST_F(ProfileSyncServiceTest, DisableSyncOnClient) {
924 IssueTestTokens(); 924 IssueTestTokens();
925 CreateService(ProfileSyncService::AUTO_START); 925 CreateService(ProfileSyncService::AUTO_START);
926 ExpectDataTypeManagerCreation(1, GetDefaultConfigureCalledCallback()); 926 ExpectDataTypeManagerCreation(1, GetDefaultConfigureCalledCallback());
927 ExpectSyncBackendHostCreation(1); 927 ExpectSyncEngineCreation(1);
928 InitializeForNthSync(); 928 InitializeForNthSync();
929 929
930 EXPECT_TRUE(service()->IsSyncActive()); 930 EXPECT_TRUE(service()->IsSyncActive());
931 EXPECT_EQ(l10n_util::GetStringUTF16(IDS_SYNC_TIME_JUST_NOW), 931 EXPECT_EQ(l10n_util::GetStringUTF16(IDS_SYNC_TIME_JUST_NOW),
932 service()->GetLastSyncedTimeString()); 932 service()->GetLastSyncedTimeString());
933 EXPECT_TRUE(service()->GetLocalDeviceInfoProvider()->GetLocalDeviceInfo()); 933 EXPECT_TRUE(service()->GetLocalDeviceInfoProvider()->GetLocalDeviceInfo());
934 934
935 syncer::SyncProtocolError client_cmd; 935 syncer::SyncProtocolError client_cmd;
936 client_cmd.action = syncer::DISABLE_SYNC_ON_CLIENT; 936 client_cmd.action = syncer::DISABLE_SYNC_ON_CLIENT;
937 service()->OnActionableError(client_cmd); 937 service()->OnActionableError(client_cmd);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
970 // Progress the controller to RUNNING first, which is how the service 970 // Progress the controller to RUNNING first, which is how the service
971 // determines whether a type is enabled. 971 // determines whether a type is enabled.
972 controller->StartAssociating(base::Bind(&DoNothing)); 972 controller->StartAssociating(base::Bind(&DoNothing));
973 controller->FinishStart(DataTypeController::OK_FIRST_RUN); 973 controller->FinishStart(DataTypeController::OK_FIRST_RUN);
974 service()->RegisterDataTypeController(std::move(controller)); 974 service()->RegisterDataTypeController(std::move(controller));
975 EXPECT_NE(nullptr, service()->GetOpenTabsUIDelegate()); 975 EXPECT_NE(nullptr, service()->GetOpenTabsUIDelegate());
976 } 976 }
977 977
978 } // namespace 978 } // namespace
979 } // namespace browser_sync 979 } // namespace browser_sync
OLDNEW
« no previous file with comments | « components/browser_sync/profile_sync_service_startup_unittest.cc ('k') | components/sync/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698