| 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 "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/signin/account_tracker_service_factory.h" | 9 #include "chrome/browser/signin/account_tracker_service_factory.h" | 
| 10 #include "chrome/browser/signin/fake_profile_oauth2_token_service_builder.h" | 10 #include "chrome/browser/signin/fake_profile_oauth2_token_service_builder.h" | 
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 91                            start_behavior, | 91                            start_behavior, | 
| 92                            base::Bind(&EmptyNetworkTimeUpdate), | 92                            base::Bind(&EmptyNetworkTimeUpdate), | 
| 93                            profile->GetPath(), | 93                            profile->GetPath(), | 
| 94                            profile->GetRequestContext(), | 94                            profile->GetRequestContext(), | 
| 95                            profile->GetDebugName(), | 95                            profile->GetDebugName(), | 
| 96                            chrome::GetChannel(), | 96                            chrome::GetChannel(), | 
| 97                            content::BrowserThread::GetMessageLoopProxyForThread( | 97                            content::BrowserThread::GetMessageLoopProxyForThread( | 
| 98                                content::BrowserThread::DB), | 98                                content::BrowserThread::DB), | 
| 99                            content::BrowserThread::GetMessageLoopProxyForThread( | 99                            content::BrowserThread::GetMessageLoopProxyForThread( | 
| 100                                content::BrowserThread::FILE), | 100                                content::BrowserThread::FILE), | 
| 101                            content::BrowserThread::GetBlockingPool()) {} | 101                            content::BrowserThread::GetBlockingPool()) { | 
|  | 102     GetSyncClient()->Initialize( | 
|  | 103         make_scoped_ptr(new SyncApiComponentFactoryMock()), this); | 
|  | 104   } | 
| 102 | 105 | 
| 103  protected: | 106  protected: | 
| 104   bool NeedBackup() const override { return false; } | 107   bool NeedBackup() const override { return false; } | 
| 105 }; | 108 }; | 
| 106 | 109 | 
| 107 class ProfileSyncServiceStartupTest : public testing::Test { | 110 class ProfileSyncServiceStartupTest : public testing::Test { | 
| 108  public: | 111  public: | 
| 109   ProfileSyncServiceStartupTest() | 112   ProfileSyncServiceStartupTest() | 
| 110       : thread_bundle_(content::TestBrowserThreadBundle::REAL_DB_THREAD | | 113       : thread_bundle_(content::TestBrowserThreadBundle::REAL_DB_THREAD | | 
| 111                        content::TestBrowserThreadBundle::REAL_FILE_THREAD | | 114                        content::TestBrowserThreadBundle::REAL_FILE_THREAD | | 
| (...skipping 21 matching lines...) Expand all  Loading... | 
| 133         base::UTF8ToUTF16("sync-startup-test"), 0, std::string(), | 136         base::UTF8ToUTF16("sync-startup-test"), 0, std::string(), | 
| 134         testing_facotries); | 137         testing_facotries); | 
| 135   } | 138   } | 
| 136 | 139 | 
| 137   void TearDown() override { sync_->RemoveObserver(&observer_); } | 140   void TearDown() override { sync_->RemoveObserver(&observer_); } | 
| 138 | 141 | 
| 139   static scoped_ptr<KeyedService> BuildService( | 142   static scoped_ptr<KeyedService> BuildService( | 
| 140       content::BrowserContext* browser_context) { | 143       content::BrowserContext* browser_context) { | 
| 141     Profile* profile = static_cast<Profile*>(browser_context); | 144     Profile* profile = static_cast<Profile*>(browser_context); | 
| 142     scoped_ptr<browser_sync::ChromeSyncClient> sync_client( | 145     scoped_ptr<browser_sync::ChromeSyncClient> sync_client( | 
| 143         new browser_sync::ChromeSyncClient( | 146         new browser_sync::ChromeSyncClient(profile)); | 
| 144             profile, make_scoped_ptr(new SyncApiComponentFactoryMock()))); |  | 
| 145     return make_scoped_ptr(new TestProfileSyncServiceNoBackup( | 147     return make_scoped_ptr(new TestProfileSyncServiceNoBackup( | 
| 146         sync_client.Pass(), profile, | 148         sync_client.Pass(), profile, | 
| 147         make_scoped_ptr(new SigninManagerWrapper( | 149         make_scoped_ptr(new SigninManagerWrapper( | 
| 148             SigninManagerFactory::GetForProfile(profile))), | 150             SigninManagerFactory::GetForProfile(profile))), | 
| 149         ProfileOAuth2TokenServiceFactory::GetForProfile(profile), | 151         ProfileOAuth2TokenServiceFactory::GetForProfile(profile), | 
| 150         browser_sync::MANUAL_START)); | 152         browser_sync::MANUAL_START)); | 
| 151   } | 153   } | 
| 152 | 154 | 
| 153   void CreateSyncService() { | 155   void CreateSyncService() { | 
| 154     sync_ = static_cast<ProfileSyncService*>( | 156     sync_ = static_cast<ProfileSyncService*>( | 
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 205     EXPECT_CALL(*GetSyncApiComponentFactoryMock(), | 207     EXPECT_CALL(*GetSyncApiComponentFactoryMock(), | 
| 206                 CreateDataTypeManager(_, _, _, _, _)) | 208                 CreateDataTypeManager(_, _, _, _, _)) | 
| 207         .WillOnce(Return(data_type_manager)); | 209         .WillOnce(Return(data_type_manager)); | 
| 208     return data_type_manager; | 210     return data_type_manager; | 
| 209   } | 211   } | 
| 210 | 212 | 
| 211   browser_sync::SyncBackendHostMock* SetUpSyncBackendHost() { | 213   browser_sync::SyncBackendHostMock* SetUpSyncBackendHost() { | 
| 212     browser_sync::SyncBackendHostMock* sync_backend_host = | 214     browser_sync::SyncBackendHostMock* sync_backend_host = | 
| 213         new browser_sync::SyncBackendHostMock(); | 215         new browser_sync::SyncBackendHostMock(); | 
| 214     EXPECT_CALL(*GetSyncApiComponentFactoryMock(), | 216     EXPECT_CALL(*GetSyncApiComponentFactoryMock(), | 
| 215                 CreateSyncBackendHost(_, _, _, _, _)) | 217                 CreateSyncBackendHost(_, _, _, _)) | 
| 216         .WillOnce(Return(sync_backend_host)); | 218         .WillOnce(Return(sync_backend_host)); | 
| 217     return sync_backend_host; | 219     return sync_backend_host; | 
| 218   } | 220   } | 
| 219 | 221 | 
| 220   content::TestBrowserThreadBundle thread_bundle_; | 222   content::TestBrowserThreadBundle thread_bundle_; | 
| 221   TestingProfileManager profile_manager_; | 223   TestingProfileManager profile_manager_; | 
| 222   TestingProfile* profile_; | 224   TestingProfile* profile_; | 
| 223   ProfileSyncService* sync_; | 225   ProfileSyncService* sync_; | 
| 224   SyncServiceObserverMock observer_; | 226   SyncServiceObserverMock observer_; | 
| 225   sync_driver::DataTypeStatusTable data_type_status_table_; | 227   sync_driver::DataTypeStatusTable data_type_status_table_; | 
| (...skipping 13 matching lines...) Expand all  Loading... | 
| 239       content::BrowserContext* context) { | 241       content::BrowserContext* context) { | 
| 240     Profile* profile = static_cast<Profile*>(context); | 242     Profile* profile = static_cast<Profile*>(context); | 
| 241     FakeSigninManagerForTesting* signin = | 243     FakeSigninManagerForTesting* signin = | 
| 242         static_cast<FakeSigninManagerForTesting*>( | 244         static_cast<FakeSigninManagerForTesting*>( | 
| 243         SigninManagerFactory::GetForProfile(profile)); | 245         SigninManagerFactory::GetForProfile(profile)); | 
| 244     SimulateTestUserSignin(profile, signin, nullptr); | 246     SimulateTestUserSignin(profile, signin, nullptr); | 
| 245     ProfileOAuth2TokenService* oauth2_token_service = | 247     ProfileOAuth2TokenService* oauth2_token_service = | 
| 246         ProfileOAuth2TokenServiceFactory::GetForProfile(profile); | 248         ProfileOAuth2TokenServiceFactory::GetForProfile(profile); | 
| 247     EXPECT_TRUE(signin->IsAuthenticated()); | 249     EXPECT_TRUE(signin->IsAuthenticated()); | 
| 248     scoped_ptr<browser_sync::ChromeSyncClient> sync_client( | 250     scoped_ptr<browser_sync::ChromeSyncClient> sync_client( | 
| 249         new browser_sync::ChromeSyncClient( | 251         new browser_sync::ChromeSyncClient(profile)); | 
| 250             profile, make_scoped_ptr(new SyncApiComponentFactoryMock()))); |  | 
| 251     return make_scoped_ptr(new TestProfileSyncServiceNoBackup( | 252     return make_scoped_ptr(new TestProfileSyncServiceNoBackup( | 
| 252         sync_client.Pass(), profile, | 253         sync_client.Pass(), profile, | 
| 253         make_scoped_ptr(new SigninManagerWrapper(signin)), oauth2_token_service, | 254         make_scoped_ptr(new SigninManagerWrapper(signin)), oauth2_token_service, | 
| 254         browser_sync::AUTO_START)); | 255         browser_sync::AUTO_START)); | 
| 255   } | 256   } | 
| 256 }; | 257 }; | 
| 257 | 258 | 
| 258 // http://crbug.com/550013 | 259 // http://crbug.com/550013 | 
| 259 TEST_F(ProfileSyncServiceStartupTest, DISABLED_StartFirstTime) { | 260 TEST_F(ProfileSyncServiceStartupTest, DISABLED_StartFirstTime) { | 
| 260   // We've never completed startup. | 261   // We've never completed startup. | 
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 378 // http://crbug.com/396402 | 379 // http://crbug.com/396402 | 
| 379 #define MAYBE_StartCrosNoCredentials DISABLED_StartCrosNoCredentials | 380 #define MAYBE_StartCrosNoCredentials DISABLED_StartCrosNoCredentials | 
| 380 #else | 381 #else | 
| 381 #define MAYBE_StartCrosNoCredentials StartCrosNoCredentials | 382 #define MAYBE_StartCrosNoCredentials StartCrosNoCredentials | 
| 382 #endif | 383 #endif | 
| 383 TEST_F(ProfileSyncServiceStartupCrosTest, MAYBE_StartCrosNoCredentials) { | 384 TEST_F(ProfileSyncServiceStartupCrosTest, MAYBE_StartCrosNoCredentials) { | 
| 384   EXPECT_CALL(*GetSyncApiComponentFactoryMock(), | 385   EXPECT_CALL(*GetSyncApiComponentFactoryMock(), | 
| 385               CreateDataTypeManager(_, _, _, _, _)) | 386               CreateDataTypeManager(_, _, _, _, _)) | 
| 386       .Times(0); | 387       .Times(0); | 
| 387   EXPECT_CALL(*GetSyncApiComponentFactoryMock(), | 388   EXPECT_CALL(*GetSyncApiComponentFactoryMock(), | 
| 388               CreateSyncBackendHost(_, _, _, _, _)) | 389               CreateSyncBackendHost(_, _, _, _)) | 
| 389       .Times(0); | 390       .Times(0); | 
| 390   profile_->GetPrefs()->ClearPref(sync_driver::prefs::kSyncHasSetupCompleted); | 391   profile_->GetPrefs()->ClearPref(sync_driver::prefs::kSyncHasSetupCompleted); | 
| 391   EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); | 392   EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); | 
| 392 | 393 | 
| 393   sync_->Initialize(); | 394   sync_->Initialize(); | 
| 394   // Sync should not start because there are no tokens yet. | 395   // Sync should not start because there are no tokens yet. | 
| 395   EXPECT_FALSE(sync_->IsSyncActive()); | 396   EXPECT_FALSE(sync_->IsSyncActive()); | 
| 396   sync_->SetSetupInProgress(false); | 397   sync_->SetSetupInProgress(false); | 
| 397 | 398 | 
| 398   // Sync should not start because there are still no tokens. | 399   // Sync should not start because there are still no tokens. | 
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 602   profile_->GetPrefs()->ClearPref(sync_driver::prefs::kSyncHasSetupCompleted); | 603   profile_->GetPrefs()->ClearPref(sync_driver::prefs::kSyncHasSetupCompleted); | 
| 603 | 604 | 
| 604   EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); | 605   EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); | 
| 605   sync_->Initialize(); | 606   sync_->Initialize(); | 
| 606 | 607 | 
| 607   sync_->SetSetupInProgress(true); | 608   sync_->SetSetupInProgress(true); | 
| 608   IssueTestTokens(account_id); | 609   IssueTestTokens(account_id); | 
| 609   sync_->SetSetupInProgress(false); | 610   sync_->SetSetupInProgress(false); | 
| 610   EXPECT_FALSE(sync_->IsSyncActive()); | 611   EXPECT_FALSE(sync_->IsSyncActive()); | 
| 611 } | 612 } | 
| OLD | NEW | 
|---|