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

Side by Side Diff: chrome/browser/sync/profile_sync_service_startup_unittest.cc

Issue 535683002: Fix use-after-free in HDDDTC shutdown (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix tests Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/files/file_util.h" 5 #include "base/files/file_util.h"
6 #include "base/memory/scoped_ptr.h" 6 #include "base/memory/scoped_ptr.h"
7 #include "base/prefs/pref_service.h" 7 #include "base/prefs/pref_service.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "chrome/browser/prefs/pref_service_syncable.h" 9 #include "chrome/browser/prefs/pref_service_syncable.h"
10 #include "chrome/browser/signin/fake_profile_oauth2_token_service.h" 10 #include "chrome/browser/signin/fake_profile_oauth2_token_service.h"
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 static_cast<ProfileSyncService*>(pss); 52 static_cast<ProfileSyncService*>(pss);
53 service->OnConfigureStart(); 53 service->OnConfigureStart();
54 } 54 }
55 55
56 ACTION_P3(InvokeOnConfigureDone, pss, error_callback, result) { 56 ACTION_P3(InvokeOnConfigureDone, pss, error_callback, result) {
57 ProfileSyncService* service = 57 ProfileSyncService* service =
58 static_cast<ProfileSyncService*>(pss); 58 static_cast<ProfileSyncService*>(pss);
59 DataTypeManager::ConfigureResult configure_result = 59 DataTypeManager::ConfigureResult configure_result =
60 static_cast<DataTypeManager::ConfigureResult>(result); 60 static_cast<DataTypeManager::ConfigureResult>(result);
61 if (result.status == sync_driver::DataTypeManager::ABORTED) 61 if (result.status == sync_driver::DataTypeManager::ABORTED)
62 error_callback.Run(); 62 error_callback.Run(&configure_result);
63 service->OnConfigureDone(configure_result); 63 service->OnConfigureDone(configure_result);
64 } 64 }
65 65
66 class TestProfileSyncServiceNoBackup : public ProfileSyncService { 66 class TestProfileSyncServiceNoBackup : public ProfileSyncService {
67 public: 67 public:
68 TestProfileSyncServiceNoBackup( 68 TestProfileSyncServiceNoBackup(
69 scoped_ptr<ProfileSyncComponentsFactory> factory, 69 scoped_ptr<ProfileSyncComponentsFactory> factory,
70 Profile* profile, 70 Profile* profile,
71 scoped_ptr<SupervisedUserSigninManagerWrapper> signin_wrapper, 71 scoped_ptr<SupervisedUserSigninManagerWrapper> signin_wrapper,
72 ProfileOAuth2TokenService* oauth2_token_service, 72 ProfileOAuth2TokenService* oauth2_token_service,
73 browser_sync::ProfileSyncServiceStartBehavior start_behavior) 73 browser_sync::ProfileSyncServiceStartBehavior start_behavior)
74 : ProfileSyncService(factory.Pass(), profile, signin_wrapper.Pass(), 74 : ProfileSyncService(factory.Pass(), profile, signin_wrapper.Pass(),
75 oauth2_token_service, start_behavior) {} 75 oauth2_token_service, start_behavior) {}
76 76
77 protected: 77 protected:
78 virtual bool NeedBackup() const OVERRIDE { 78 virtual bool NeedBackup() const OVERRIDE {
79 return false; 79 return false;
80 } 80 }
81 }; 81 };
82 82
83 class ProfileSyncServiceStartupTest : public testing::Test { 83 class ProfileSyncServiceStartupTest : public testing::Test {
84 public: 84 public:
85 ProfileSyncServiceStartupTest() 85 ProfileSyncServiceStartupTest()
86 : thread_bundle_(content::TestBrowserThreadBundle::REAL_DB_THREAD | 86 : thread_bundle_(content::TestBrowserThreadBundle::REAL_DB_THREAD |
87 content::TestBrowserThreadBundle::REAL_FILE_THREAD | 87 content::TestBrowserThreadBundle::REAL_FILE_THREAD |
88 content::TestBrowserThreadBundle::REAL_IO_THREAD), 88 content::TestBrowserThreadBundle::REAL_IO_THREAD),
89 profile_manager_(TestingBrowserProcess::GetGlobal()), 89 profile_manager_(TestingBrowserProcess::GetGlobal()),
90 sync_(NULL), 90 sync_(NULL) {}
91 data_type_status_table_(NULL) {}
92 91
93 virtual ~ProfileSyncServiceStartupTest() { 92 virtual ~ProfileSyncServiceStartupTest() {
94 } 93 }
95 94
96 virtual void SetUp() { 95 virtual void SetUp() {
97 CHECK(profile_manager_.SetUp()); 96 CHECK(profile_manager_.SetUp());
98 97
99 TestingProfile::TestingFactories testing_facotries; 98 TestingProfile::TestingFactories testing_facotries;
100 testing_facotries.push_back( 99 testing_facotries.push_back(
101 std::make_pair(SigninManagerFactory::GetInstance(), 100 std::make_pair(SigninManagerFactory::GetInstance(),
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 } 140 }
142 141
143 ProfileSyncComponentsFactoryMock* components_factory_mock() { 142 ProfileSyncComponentsFactoryMock* components_factory_mock() {
144 return static_cast<ProfileSyncComponentsFactoryMock*>(sync_->factory()); 143 return static_cast<ProfileSyncComponentsFactoryMock*>(sync_->factory());
145 } 144 }
146 145
147 FakeSigninManagerForTesting* fake_signin() { 146 FakeSigninManagerForTesting* fake_signin() {
148 return static_cast<FakeSigninManagerForTesting*>(sync_->signin()); 147 return static_cast<FakeSigninManagerForTesting*>(sync_->signin());
149 } 148 }
150 149
151 void SetError() { 150 void SetError(DataTypeManager::ConfigureResult* result) {
152 sync_driver::DataTypeStatusTable::TypeErrorMap errors; 151 sync_driver::DataTypeStatusTable::TypeErrorMap errors;
153 errors[syncer::BOOKMARKS] = 152 errors[syncer::BOOKMARKS] =
154 syncer::SyncError(FROM_HERE, 153 syncer::SyncError(FROM_HERE,
155 syncer::SyncError::UNRECOVERABLE_ERROR, 154 syncer::SyncError::UNRECOVERABLE_ERROR,
156 "Error", 155 "Error",
157 syncer::BOOKMARKS); 156 syncer::BOOKMARKS);
158 data_type_status_table_->UpdateFailedDataTypes(errors); 157 result->data_type_status_table.UpdateFailedDataTypes(errors);
159 } 158 }
160 159
161 protected: 160 protected:
162 void SimulateTestUserSignin() { 161 void SimulateTestUserSignin() {
163 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, 162 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername,
164 "test_user@gmail.com"); 163 "test_user@gmail.com");
165 #if !defined(OS_CHROMEOS) 164 #if !defined(OS_CHROMEOS)
166 fake_signin()->SignIn("test_user@gmail.com", ""); 165 fake_signin()->SignIn("test_user@gmail.com", "");
167 #else 166 #else
168 fake_signin()->SetAuthenticatedUsername("test_user@gmail.com"); 167 fake_signin()->SetAuthenticatedUsername("test_user@gmail.com");
169 sync_->GoogleSigninSucceeded("test_user@gmail.com", 168 sync_->GoogleSigninSucceeded("test_user@gmail.com",
170 "test_user@gmail.com", 169 "test_user@gmail.com",
171 ""); 170 "");
172 #endif 171 #endif
173 } 172 }
174 173
175 DataTypeManagerMock* SetUpDataTypeManager() { 174 DataTypeManagerMock* SetUpDataTypeManager() {
176 DataTypeManagerMock* data_type_manager = new DataTypeManagerMock(); 175 DataTypeManagerMock* data_type_manager = new DataTypeManagerMock();
177 EXPECT_CALL(*components_factory_mock(), 176 EXPECT_CALL(*components_factory_mock(),
178 CreateDataTypeManager(_, _, _, _, _, _)). 177 CreateDataTypeManager(_, _, _, _, _)).
179 WillOnce(DoAll(SaveArg<5>(&data_type_status_table_), 178 WillOnce(Return(data_type_manager));
180 Return(data_type_manager)));
181 return data_type_manager; 179 return data_type_manager;
182 } 180 }
183 181
184 browser_sync::SyncBackendHostMock* SetUpSyncBackendHost() { 182 browser_sync::SyncBackendHostMock* SetUpSyncBackendHost() {
185 browser_sync::SyncBackendHostMock* sync_backend_host = 183 browser_sync::SyncBackendHostMock* sync_backend_host =
186 new browser_sync::SyncBackendHostMock(); 184 new browser_sync::SyncBackendHostMock();
187 EXPECT_CALL(*components_factory_mock(), 185 EXPECT_CALL(*components_factory_mock(),
188 CreateSyncBackendHost(_, _, _, _, _)). 186 CreateSyncBackendHost(_, _, _, _, _)).
189 WillOnce(Return(sync_backend_host)); 187 WillOnce(Return(sync_backend_host));
190 return sync_backend_host; 188 return sync_backend_host;
191 } 189 }
192 190
193 content::TestBrowserThreadBundle thread_bundle_; 191 content::TestBrowserThreadBundle thread_bundle_;
194 TestingProfileManager profile_manager_; 192 TestingProfileManager profile_manager_;
195 TestingProfile* profile_; 193 TestingProfile* profile_;
196 ProfileSyncService* sync_; 194 ProfileSyncService* sync_;
197 ProfileSyncServiceObserverMock observer_; 195 ProfileSyncServiceObserverMock observer_;
198 sync_driver::DataTypeStatusTable* data_type_status_table_; 196 sync_driver::DataTypeStatusTable data_type_status_table_;
199 }; 197 };
200 198
201 class ProfileSyncServiceStartupCrosTest : public ProfileSyncServiceStartupTest { 199 class ProfileSyncServiceStartupCrosTest : public ProfileSyncServiceStartupTest {
202 public: 200 public:
203 virtual void SetUp() { 201 virtual void SetUp() {
204 ProfileSyncServiceStartupTest::SetUp(); 202 ProfileSyncServiceStartupTest::SetUp();
205 sync_ = static_cast<ProfileSyncService*>( 203 sync_ = static_cast<ProfileSyncService*>(
206 ProfileSyncServiceFactory::GetInstance()->SetTestingFactoryAndUse( 204 ProfileSyncServiceFactory::GetInstance()->SetTestingFactoryAndUse(
207 profile_, BuildCrosService)); 205 profile_, BuildCrosService));
208 sync_->AddObserver(&observer_); 206 sync_->AddObserver(&observer_);
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 270
273 // TODO(pavely): Reenable test once android is switched to oauth2. 271 // TODO(pavely): Reenable test once android is switched to oauth2.
274 TEST_F(ProfileSyncServiceStartupTest, DISABLED_StartNoCredentials) { 272 TEST_F(ProfileSyncServiceStartupTest, DISABLED_StartNoCredentials) {
275 // We've never completed startup. 273 // We've never completed startup.
276 profile_->GetPrefs()->ClearPref(sync_driver::prefs::kSyncHasSetupCompleted); 274 profile_->GetPrefs()->ClearPref(sync_driver::prefs::kSyncHasSetupCompleted);
277 CreateSyncService(); 275 CreateSyncService();
278 276
279 // Should not actually start, rather just clean things up and wait 277 // Should not actually start, rather just clean things up and wait
280 // to be enabled. 278 // to be enabled.
281 EXPECT_CALL(*components_factory_mock(), 279 EXPECT_CALL(*components_factory_mock(),
282 CreateDataTypeManager(_, _, _, _, _, _)).Times(0); 280 CreateDataTypeManager(_, _, _, _, _)).Times(0);
283 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); 281 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber());
284 sync_->Initialize(); 282 sync_->Initialize();
285 283
286 // Preferences should be back to defaults. 284 // Preferences should be back to defaults.
287 EXPECT_EQ( 285 EXPECT_EQ(
288 0, 286 0,
289 profile_->GetPrefs()->GetInt64(sync_driver::prefs::kSyncLastSyncedTime)); 287 profile_->GetPrefs()->GetInt64(sync_driver::prefs::kSyncLastSyncedTime));
290 EXPECT_FALSE(profile_->GetPrefs()->GetBoolean( 288 EXPECT_FALSE(profile_->GetPrefs()->GetBoolean(
291 sync_driver::prefs::kSyncHasSetupCompleted)); 289 sync_driver::prefs::kSyncHasSetupCompleted));
292 290
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 } 344 }
347 345
348 #if defined(OS_WIN) 346 #if defined(OS_WIN)
349 // http://crbug.com/396402 347 // http://crbug.com/396402
350 #define MAYBE_StartCrosNoCredentials DISABLED_StartCrosNoCredentials 348 #define MAYBE_StartCrosNoCredentials DISABLED_StartCrosNoCredentials
351 #else 349 #else
352 #define MAYBE_StartCrosNoCredentials StartCrosNoCredentials 350 #define MAYBE_StartCrosNoCredentials StartCrosNoCredentials
353 #endif 351 #endif
354 TEST_F(ProfileSyncServiceStartupCrosTest, MAYBE_StartCrosNoCredentials) { 352 TEST_F(ProfileSyncServiceStartupCrosTest, MAYBE_StartCrosNoCredentials) {
355 EXPECT_CALL(*components_factory_mock(), 353 EXPECT_CALL(*components_factory_mock(),
356 CreateDataTypeManager(_, _, _, _, _, _)).Times(0); 354 CreateDataTypeManager(_, _, _, _, _)).Times(0);
357 EXPECT_CALL(*components_factory_mock(), 355 EXPECT_CALL(*components_factory_mock(),
358 CreateSyncBackendHost(_, _, _, _, _)).Times(0); 356 CreateSyncBackendHost(_, _, _, _, _)).Times(0);
359 profile_->GetPrefs()->ClearPref(sync_driver::prefs::kSyncHasSetupCompleted); 357 profile_->GetPrefs()->ClearPref(sync_driver::prefs::kSyncHasSetupCompleted);
360 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); 358 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber());
361 359
362 sync_->Initialize(); 360 sync_->Initialize();
363 // Sync should not start because there are no tokens yet. 361 // Sync should not start because there are no tokens yet.
364 EXPECT_FALSE(sync_->ShouldPushChanges()); 362 EXPECT_FALSE(sync_->ShouldPushChanges());
365 sync_->SetSetupInProgress(false); 363 sync_->SetSetupInProgress(false);
366 364
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
489 #endif 487 #endif
490 TEST_F(ProfileSyncServiceStartupTest, MAYBE_ManagedStartup) { 488 TEST_F(ProfileSyncServiceStartupTest, MAYBE_ManagedStartup) {
491 // Service should not be started by Initialize() since it's managed. 489 // Service should not be started by Initialize() since it's managed.
492 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, 490 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername,
493 "test_user@gmail.com"); 491 "test_user@gmail.com");
494 CreateSyncService(); 492 CreateSyncService();
495 493
496 // Disable sync through policy. 494 // Disable sync through policy.
497 profile_->GetPrefs()->SetBoolean(sync_driver::prefs::kSyncManaged, true); 495 profile_->GetPrefs()->SetBoolean(sync_driver::prefs::kSyncManaged, true);
498 EXPECT_CALL(*components_factory_mock(), 496 EXPECT_CALL(*components_factory_mock(),
499 CreateDataTypeManager(_, _, _, _, _, _)).Times(0); 497 CreateDataTypeManager(_, _, _, _, _)).Times(0);
500 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); 498 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber());
501 499
502 sync_->Initialize(); 500 sync_->Initialize();
503 } 501 }
504 502
505 TEST_F(ProfileSyncServiceStartupTest, SwitchManaged) { 503 TEST_F(ProfileSyncServiceStartupTest, SwitchManaged) {
506 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, 504 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername,
507 "test_user@gmail.com"); 505 "test_user@gmail.com");
508 SigninManagerFactory::GetForProfile(profile_) 506 SigninManagerFactory::GetForProfile(profile_)
509 ->SetAuthenticatedUsername("test_user@gmail.com"); 507 ->SetAuthenticatedUsername("test_user@gmail.com");
(...skipping 11 matching lines...) Expand all
521 EXPECT_CALL(*data_type_manager, state()). 519 EXPECT_CALL(*data_type_manager, state()).
522 WillOnce(Return(DataTypeManager::CONFIGURED)); 520 WillOnce(Return(DataTypeManager::CONFIGURED));
523 EXPECT_CALL(*data_type_manager, Stop()).Times(1); 521 EXPECT_CALL(*data_type_manager, Stop()).Times(1);
524 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); 522 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber());
525 profile_->GetPrefs()->SetBoolean(sync_driver::prefs::kSyncManaged, true); 523 profile_->GetPrefs()->SetBoolean(sync_driver::prefs::kSyncManaged, true);
526 524
527 // When switching back to unmanaged, the state should change, but the service 525 // When switching back to unmanaged, the state should change, but the service
528 // should not start up automatically (kSyncSetupCompleted will be false). 526 // should not start up automatically (kSyncSetupCompleted will be false).
529 Mock::VerifyAndClearExpectations(data_type_manager); 527 Mock::VerifyAndClearExpectations(data_type_manager);
530 EXPECT_CALL(*components_factory_mock(), 528 EXPECT_CALL(*components_factory_mock(),
531 CreateDataTypeManager(_, _, _, _, _, _)).Times(0); 529 CreateDataTypeManager(_, _, _, _, _)).Times(0);
532 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); 530 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber());
533 profile_->GetPrefs()->ClearPref(sync_driver::prefs::kSyncManaged); 531 profile_->GetPrefs()->ClearPref(sync_driver::prefs::kSyncManaged);
534 } 532 }
535 533
536 TEST_F(ProfileSyncServiceStartupTest, StartFailure) { 534 TEST_F(ProfileSyncServiceStartupTest, StartFailure) {
537 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, 535 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername,
538 "test_user@gmail.com"); 536 "test_user@gmail.com");
539 SigninManagerFactory::GetForProfile(profile_) 537 SigninManagerFactory::GetForProfile(profile_)
540 ->SetAuthenticatedUsername("test_user@gmail.com"); 538 ->SetAuthenticatedUsername("test_user@gmail.com");
541 CreateSyncService(); 539 CreateSyncService();
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
574 profile_->GetPrefs()->ClearPref(sync_driver::prefs::kSyncHasSetupCompleted); 572 profile_->GetPrefs()->ClearPref(sync_driver::prefs::kSyncHasSetupCompleted);
575 573
576 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); 574 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber());
577 sync_->Initialize(); 575 sync_->Initialize();
578 576
579 sync_->SetSetupInProgress(true); 577 sync_->SetSetupInProgress(true);
580 IssueTestTokens(); 578 IssueTestTokens();
581 sync_->SetSetupInProgress(false); 579 sync_->SetSetupInProgress(false);
582 EXPECT_FALSE(sync_->sync_initialized()); 580 EXPECT_FALSE(sync_->sync_initialized());
583 } 581 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698