| 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 100 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  111                        content::TestBrowserThreadBundle::REAL_FILE_THREAD | |  111                        content::TestBrowserThreadBundle::REAL_FILE_THREAD | | 
|  112                        content::TestBrowserThreadBundle::REAL_IO_THREAD), |  112                        content::TestBrowserThreadBundle::REAL_IO_THREAD), | 
|  113         profile_manager_(TestingBrowserProcess::GetGlobal()), |  113         profile_manager_(TestingBrowserProcess::GetGlobal()), | 
|  114         sync_(NULL) {} |  114         sync_(NULL) {} | 
|  115  |  115  | 
|  116   ~ProfileSyncServiceStartupTest() override {} |  116   ~ProfileSyncServiceStartupTest() override {} | 
|  117  |  117  | 
|  118   void SetUp() override { |  118   void SetUp() override { | 
|  119     CHECK(profile_manager_.SetUp()); |  119     CHECK(profile_manager_.SetUp()); | 
|  120  |  120  | 
|  121     TestingProfile::TestingFactories testing_facotries; |  121     TestingProfile::TestingFactories testing_factories; | 
|  122     testing_facotries.push_back(std::make_pair( |  122     testing_factories.push_back(std::make_pair( | 
|  123         SigninManagerFactory::GetInstance(), BuildFakeSigninManagerBase)); |  123         SigninManagerFactory::GetInstance(), BuildFakeSigninManagerBase)); | 
|  124     testing_facotries.push_back( |  124     testing_factories.push_back( | 
|  125             std::make_pair(ProfileOAuth2TokenServiceFactory::GetInstance(), |  125         std::make_pair(ProfileOAuth2TokenServiceFactory::GetInstance(), | 
|  126                            BuildAutoIssuingFakeProfileOAuth2TokenService)); |  126                        BuildAutoIssuingFakeProfileOAuth2TokenService)); | 
|  127     testing_facotries.push_back( |  127     testing_factories.push_back( | 
|  128             std::make_pair(ProfileSyncServiceFactory::GetInstance(), |  128         std::make_pair(ProfileSyncServiceFactory::GetInstance(), BuildService)); | 
|  129                            BuildService)); |  | 
|  130  |  129  | 
|  131     profile_ = profile_manager_.CreateTestingProfile( |  130     profile_ = profile_manager_.CreateTestingProfile( | 
|  132         "sync-startup-test", scoped_ptr<syncable_prefs::PrefServiceSyncable>(), |  131         "sync-startup-test", scoped_ptr<syncable_prefs::PrefServiceSyncable>(), | 
|  133         base::UTF8ToUTF16("sync-startup-test"), 0, std::string(), |  132         base::UTF8ToUTF16("sync-startup-test"), 0, std::string(), | 
|  134         testing_facotries); |  133         testing_factories); | 
|  135   } |  134   } | 
|  136  |  135  | 
|  137   void TearDown() override { sync_->RemoveObserver(&observer_); } |  136   void TearDown() override { sync_->RemoveObserver(&observer_); } | 
|  138  |  137  | 
|  139   static scoped_ptr<KeyedService> BuildService( |  138   static scoped_ptr<KeyedService> BuildService( | 
|  140       content::BrowserContext* browser_context) { |  139       content::BrowserContext* browser_context) { | 
|  141     Profile* profile = static_cast<Profile*>(browser_context); |  140     Profile* profile = static_cast<Profile*>(browser_context); | 
|  142     scoped_ptr<browser_sync::ChromeSyncClient> sync_client( |  141     scoped_ptr<browser_sync::ChromeSyncClient> sync_client( | 
|  143         new browser_sync::ChromeSyncClient( |  142         new browser_sync::ChromeSyncClient(profile)); | 
|  144             profile, make_scoped_ptr(new SyncApiComponentFactoryMock()))); |  143     sync_client->SetSyncApiComponentFactoryForTesting( | 
 |  144         make_scoped_ptr(new SyncApiComponentFactoryMock())); | 
|  145     return make_scoped_ptr(new TestProfileSyncServiceNoBackup( |  145     return make_scoped_ptr(new TestProfileSyncServiceNoBackup( | 
|  146         sync_client.Pass(), profile, |  146         sync_client.Pass(), profile, | 
|  147         make_scoped_ptr(new SigninManagerWrapper( |  147         make_scoped_ptr(new SigninManagerWrapper( | 
|  148             SigninManagerFactory::GetForProfile(profile))), |  148             SigninManagerFactory::GetForProfile(profile))), | 
|  149         ProfileOAuth2TokenServiceFactory::GetForProfile(profile), |  149         ProfileOAuth2TokenServiceFactory::GetForProfile(profile), | 
|  150         browser_sync::MANUAL_START)); |  150         browser_sync::MANUAL_START)); | 
|  151   } |  151   } | 
|  152  |  152  | 
|  153   void CreateSyncService() { |  153   void CreateSyncService() { | 
|  154     sync_ = static_cast<ProfileSyncService*>( |  154     sync_ = static_cast<ProfileSyncService*>( | 
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  205     EXPECT_CALL(*GetSyncApiComponentFactoryMock(), |  205     EXPECT_CALL(*GetSyncApiComponentFactoryMock(), | 
|  206                 CreateDataTypeManager(_, _, _, _, _)) |  206                 CreateDataTypeManager(_, _, _, _, _)) | 
|  207         .WillOnce(Return(data_type_manager)); |  207         .WillOnce(Return(data_type_manager)); | 
|  208     return data_type_manager; |  208     return data_type_manager; | 
|  209   } |  209   } | 
|  210  |  210  | 
|  211   browser_sync::SyncBackendHostMock* SetUpSyncBackendHost() { |  211   browser_sync::SyncBackendHostMock* SetUpSyncBackendHost() { | 
|  212     browser_sync::SyncBackendHostMock* sync_backend_host = |  212     browser_sync::SyncBackendHostMock* sync_backend_host = | 
|  213         new browser_sync::SyncBackendHostMock(); |  213         new browser_sync::SyncBackendHostMock(); | 
|  214     EXPECT_CALL(*GetSyncApiComponentFactoryMock(), |  214     EXPECT_CALL(*GetSyncApiComponentFactoryMock(), | 
|  215                 CreateSyncBackendHost(_, _, _, _, _)) |  215                 CreateSyncBackendHost(_, _, _, _)) | 
|  216         .WillOnce(Return(sync_backend_host)); |  216         .WillOnce(Return(sync_backend_host)); | 
|  217     return sync_backend_host; |  217     return sync_backend_host; | 
|  218   } |  218   } | 
|  219  |  219  | 
|  220   content::TestBrowserThreadBundle thread_bundle_; |  220   content::TestBrowserThreadBundle thread_bundle_; | 
|  221   TestingProfileManager profile_manager_; |  221   TestingProfileManager profile_manager_; | 
|  222   TestingProfile* profile_; |  222   TestingProfile* profile_; | 
|  223   ProfileSyncService* sync_; |  223   ProfileSyncService* sync_; | 
|  224   SyncServiceObserverMock observer_; |  224   SyncServiceObserverMock observer_; | 
|  225   sync_driver::DataTypeStatusTable data_type_status_table_; |  225   sync_driver::DataTypeStatusTable data_type_status_table_; | 
| (...skipping 13 matching lines...) Expand all  Loading... | 
|  239       content::BrowserContext* context) { |  239       content::BrowserContext* context) { | 
|  240     Profile* profile = static_cast<Profile*>(context); |  240     Profile* profile = static_cast<Profile*>(context); | 
|  241     FakeSigninManagerForTesting* signin = |  241     FakeSigninManagerForTesting* signin = | 
|  242         static_cast<FakeSigninManagerForTesting*>( |  242         static_cast<FakeSigninManagerForTesting*>( | 
|  243         SigninManagerFactory::GetForProfile(profile)); |  243         SigninManagerFactory::GetForProfile(profile)); | 
|  244     SimulateTestUserSignin(profile, signin, nullptr); |  244     SimulateTestUserSignin(profile, signin, nullptr); | 
|  245     ProfileOAuth2TokenService* oauth2_token_service = |  245     ProfileOAuth2TokenService* oauth2_token_service = | 
|  246         ProfileOAuth2TokenServiceFactory::GetForProfile(profile); |  246         ProfileOAuth2TokenServiceFactory::GetForProfile(profile); | 
|  247     EXPECT_TRUE(signin->IsAuthenticated()); |  247     EXPECT_TRUE(signin->IsAuthenticated()); | 
|  248     scoped_ptr<browser_sync::ChromeSyncClient> sync_client( |  248     scoped_ptr<browser_sync::ChromeSyncClient> sync_client( | 
|  249         new browser_sync::ChromeSyncClient( |  249         new browser_sync::ChromeSyncClient(profile)); | 
|  250             profile, make_scoped_ptr(new SyncApiComponentFactoryMock()))); |  250     sync_client->SetSyncApiComponentFactoryForTesting( | 
 |  251         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 |