| OLD | NEW |
| 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 "testing/gtest/include/gtest/gtest.h" | 5 #include "testing/gtest/include/gtest/gtest.h" |
| 6 | 6 |
| 7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
| 10 #include "chrome/browser/signin/fake_signin_manager.h" | 10 #include "chrome/browser/signin/fake_signin_manager.h" |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 profile_.reset(); | 98 profile_.reset(); |
| 99 | 99 |
| 100 // Pump messages posted by the sync core thread (which may end up | 100 // Pump messages posted by the sync core thread (which may end up |
| 101 // posting on the IO thread). | 101 // posting on the IO thread). |
| 102 ui_loop_.RunUntilIdle(); | 102 ui_loop_.RunUntilIdle(); |
| 103 io_thread_.Stop(); | 103 io_thread_.Stop(); |
| 104 file_thread_.Stop(); | 104 file_thread_.Stop(); |
| 105 ui_loop_.RunUntilIdle(); | 105 ui_loop_.RunUntilIdle(); |
| 106 } | 106 } |
| 107 | 107 |
| 108 static ProfileKeyedService* BuildService(content::BrowserContext* profile) { | 108 static BrowserContextKeyedService* BuildService(content::BrowserContext* profi
le) { |
| 109 return new TestProfileSyncService( | 109 return new TestProfileSyncService( |
| 110 new ProfileSyncComponentsFactoryMock(), | 110 new ProfileSyncComponentsFactoryMock(), |
| 111 static_cast<Profile*>(profile), | 111 static_cast<Profile*>(profile), |
| 112 SigninManagerFactory::GetForProfile(static_cast<Profile*>(profile)), | 112 SigninManagerFactory::GetForProfile(static_cast<Profile*>(profile)), |
| 113 ProfileSyncService::MANUAL_START, | 113 ProfileSyncService::MANUAL_START, |
| 114 true); | 114 true); |
| 115 } | 115 } |
| 116 | 116 |
| 117 void CreateSyncService() { | 117 void CreateSyncService() { |
| 118 sync_ = static_cast<TestProfileSyncService*>( | 118 sync_ = static_cast<TestProfileSyncService*>( |
| (...skipping 26 matching lines...) Expand all Loading... |
| 145 public: | 145 public: |
| 146 virtual void SetUp() { | 146 virtual void SetUp() { |
| 147 ProfileSyncServiceStartupTest::SetUp(); | 147 ProfileSyncServiceStartupTest::SetUp(); |
| 148 sync_ = static_cast<TestProfileSyncService*>( | 148 sync_ = static_cast<TestProfileSyncService*>( |
| 149 ProfileSyncServiceFactory::GetInstance()->SetTestingFactoryAndUse( | 149 ProfileSyncServiceFactory::GetInstance()->SetTestingFactoryAndUse( |
| 150 profile_.get(), BuildCrosService)); | 150 profile_.get(), BuildCrosService)); |
| 151 sync_->AddObserver(&observer_); | 151 sync_->AddObserver(&observer_); |
| 152 sync_->set_synchronous_sync_configuration(); | 152 sync_->set_synchronous_sync_configuration(); |
| 153 } | 153 } |
| 154 | 154 |
| 155 static ProfileKeyedService* BuildCrosService( | 155 static BrowserContextKeyedService* BuildCrosService( |
| 156 content::BrowserContext* context) { | 156 content::BrowserContext* context) { |
| 157 Profile* profile = static_cast<Profile*>(context); | 157 Profile* profile = static_cast<Profile*>(context); |
| 158 SigninManagerBase* signin = | 158 SigninManagerBase* signin = |
| 159 SigninManagerFactory::GetForProfile(profile); | 159 SigninManagerFactory::GetForProfile(profile); |
| 160 profile->GetPrefs()->SetString(prefs::kGoogleServicesUsername, | 160 profile->GetPrefs()->SetString(prefs::kGoogleServicesUsername, |
| 161 "test_user"); | 161 "test_user"); |
| 162 signin->Initialize(profile, NULL); | 162 signin->Initialize(profile, NULL); |
| 163 EXPECT_FALSE(signin->GetAuthenticatedUsername().empty()); | 163 EXPECT_FALSE(signin->GetAuthenticatedUsername().empty()); |
| 164 return new TestProfileSyncService( | 164 return new TestProfileSyncService( |
| 165 new ProfileSyncComponentsFactoryMock(), | 165 new ProfileSyncComponentsFactoryMock(), |
| 166 profile, | 166 profile, |
| 167 signin, | 167 signin, |
| 168 ProfileSyncService::AUTO_START, | 168 ProfileSyncService::AUTO_START, |
| 169 true); | 169 true); |
| 170 } | 170 } |
| 171 }; | 171 }; |
| 172 | 172 |
| 173 ProfileKeyedService* BuildFakeTokenService(content::BrowserContext* profile) { | 173 BrowserContextKeyedService* BuildFakeTokenService(content::BrowserContext* profi
le) { |
| 174 return new FakeTokenService(); | 174 return new FakeTokenService(); |
| 175 } | 175 } |
| 176 | 176 |
| 177 TEST_F(ProfileSyncServiceStartupTest, StartFirstTime) { | 177 TEST_F(ProfileSyncServiceStartupTest, StartFirstTime) { |
| 178 // We've never completed startup. | 178 // We've never completed startup. |
| 179 profile_->GetPrefs()->ClearPref(prefs::kSyncHasSetupCompleted); | 179 profile_->GetPrefs()->ClearPref(prefs::kSyncHasSetupCompleted); |
| 180 SigninManagerFactory::GetForProfile( | 180 SigninManagerFactory::GetForProfile( |
| 181 profile_.get())->Initialize(profile_.get(), NULL); | 181 profile_.get())->Initialize(profile_.get(), NULL); |
| 182 CreateSyncService(); | 182 CreateSyncService(); |
| 183 DataTypeManagerMock* data_type_manager = SetUpDataTypeManager(); | 183 DataTypeManagerMock* data_type_manager = SetUpDataTypeManager(); |
| (...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 523 | 523 |
| 524 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); | 524 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); |
| 525 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest( | 525 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest( |
| 526 GaiaConstants::kSyncService, "sync_token"); | 526 GaiaConstants::kSyncService, "sync_token"); |
| 527 sync_->fail_initial_download(); | 527 sync_->fail_initial_download(); |
| 528 | 528 |
| 529 sync_->Initialize(); | 529 sync_->Initialize(); |
| 530 EXPECT_FALSE(sync_->sync_initialized()); | 530 EXPECT_FALSE(sync_->sync_initialized()); |
| 531 EXPECT_FALSE(sync_->GetBackendForTest()); | 531 EXPECT_FALSE(sync_->GetBackendForTest()); |
| 532 } | 532 } |
| OLD | NEW |