| 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 <utility> | 5 #include <utility> |
| 6 | 6 |
| 7 #include "base/files/file_util.h" | 7 #include "base/files/file_util.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| 11 #include "base/thread_task_runner_handle.h" |
| 11 #include "build/build_config.h" | 12 #include "build/build_config.h" |
| 12 #include "chrome/browser/signin/account_tracker_service_factory.h" | 13 #include "chrome/browser/signin/account_tracker_service_factory.h" |
| 13 #include "chrome/browser/signin/fake_profile_oauth2_token_service_builder.h" | 14 #include "chrome/browser/signin/fake_profile_oauth2_token_service_builder.h" |
| 14 #include "chrome/browser/signin/fake_signin_manager_builder.h" | 15 #include "chrome/browser/signin/fake_signin_manager_builder.h" |
| 15 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | 16 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
| 16 #include "chrome/browser/signin/signin_manager_factory.h" | 17 #include "chrome/browser/signin/signin_manager_factory.h" |
| 17 #include "chrome/browser/sync/chrome_sync_client.h" | 18 #include "chrome/browser/sync/chrome_sync_client.h" |
| 18 #include "chrome/browser/sync/profile_sync_service_factory.h" | 19 #include "chrome/browser/sync/profile_sync_service_factory.h" |
| 19 #include "chrome/browser/sync/supervised_user_signin_manager_wrapper.h" | 20 #include "chrome/browser/sync/supervised_user_signin_manager_wrapper.h" |
| 20 #include "chrome/common/channel_info.h" | |
| 21 #include "chrome/common/pref_names.h" | 21 #include "chrome/common/pref_names.h" |
| 22 #include "chrome/test/base/testing_browser_process.h" | 22 #include "chrome/test/base/testing_browser_process.h" |
| 23 #include "chrome/test/base/testing_profile.h" | 23 #include "chrome/test/base/testing_profile.h" |
| 24 #include "chrome/test/base/testing_profile_manager.h" | 24 #include "chrome/test/base/testing_profile_manager.h" |
| 25 #include "components/browser_sync/browser/profile_sync_service.h" | 25 #include "components/browser_sync/browser/profile_sync_service.h" |
| 26 #include "components/browser_sync/browser/profile_sync_test_util.h" | 26 #include "components/browser_sync/browser/profile_sync_test_util.h" |
| 27 #include "components/signin/core/browser/account_tracker_service.h" | 27 #include "components/signin/core/browser/account_tracker_service.h" |
| 28 #include "components/signin/core/browser/fake_profile_oauth2_token_service.h" | 28 #include "components/signin/core/browser/fake_profile_oauth2_token_service.h" |
| 29 #include "components/signin/core/browser/profile_oauth2_token_service.h" | 29 #include "components/signin/core/browser/profile_oauth2_token_service.h" |
| 30 #include "components/signin/core/browser/signin_manager.h" | 30 #include "components/signin/core/browser/signin_manager.h" |
| 31 #include "components/signin/core/common/signin_pref_names.h" | 31 #include "components/signin/core/common/signin_pref_names.h" |
| 32 #include "components/sync_driver/data_type_manager.h" | 32 #include "components/sync_driver/data_type_manager.h" |
| 33 #include "components/sync_driver/data_type_manager_mock.h" | 33 #include "components/sync_driver/data_type_manager_mock.h" |
| 34 #include "components/sync_driver/glue/sync_backend_host_mock.h" | 34 #include "components/sync_driver/glue/sync_backend_host_mock.h" |
| 35 #include "components/sync_driver/pref_names.h" | 35 #include "components/sync_driver/pref_names.h" |
| 36 #include "components/sync_driver/sync_api_component_factory_mock.h" | 36 #include "components/sync_driver/sync_api_component_factory_mock.h" |
| 37 #include "components/sync_driver/sync_prefs.h" | 37 #include "components/sync_driver/sync_prefs.h" |
| 38 #include "components/syncable_prefs/pref_service_syncable.h" | 38 #include "components/syncable_prefs/pref_service_syncable.h" |
| 39 #include "content/public/test/test_browser_thread_bundle.h" | 39 #include "content/public/test/test_browser_thread_bundle.h" |
| 40 #include "content/public/test/test_utils.h" | 40 #include "content/public/test/test_utils.h" |
| 41 #include "google_apis/gaia/gaia_auth_consumer.h" | 41 #include "google_apis/gaia/gaia_auth_consumer.h" |
| 42 #include "google_apis/gaia/gaia_constants.h" | 42 #include "google_apis/gaia/gaia_constants.h" |
| 43 #include "google_apis/gaia/oauth2_token_service.h" | 43 #include "google_apis/gaia/oauth2_token_service.h" |
| 44 #include "net/url_request/url_request_test_util.h" |
| 44 #include "testing/gmock/include/gmock/gmock.h" | 45 #include "testing/gmock/include/gmock/gmock.h" |
| 45 #include "testing/gtest/include/gtest/gtest.h" | 46 #include "testing/gtest/include/gtest/gtest.h" |
| 46 | 47 |
| 47 using browser_sync::SyncBackendHostMock; | 48 using browser_sync::SyncBackendHostMock; |
| 48 using content::BrowserThread; | 49 using content::BrowserThread; |
| 49 using sync_driver::DataTypeManager; | 50 using sync_driver::DataTypeManager; |
| 50 using sync_driver::DataTypeManagerMock; | 51 using sync_driver::DataTypeManagerMock; |
| 51 using testing::_; | 52 using testing::_; |
| 52 using testing::AnyNumber; | 53 using testing::AnyNumber; |
| 53 using testing::DoAll; | 54 using testing::DoAll; |
| 54 using testing::InvokeArgument; | 55 using testing::InvokeArgument; |
| 55 using testing::Mock; | 56 using testing::Mock; |
| 56 using testing::Return; | 57 using testing::Return; |
| 57 using testing::SaveArg; | 58 using testing::SaveArg; |
| 58 | 59 |
| 59 namespace { | 60 namespace { |
| 60 | 61 |
| 61 const char kGaiaId[] = "12345"; | 62 const char kGaiaId[] = "12345"; |
| 62 const char kEmail[] = "test_user@gmail.com"; | 63 const char kEmail[] = "test_user@gmail.com"; |
| 63 const char kDummyPassword[] = ""; | 64 const char kDummyPassword[] = ""; |
| 64 | 65 |
| 65 ProfileSyncService::InitParams GetInitParams( | 66 ProfileSyncService::InitParams GetInitParams( |
| 66 scoped_ptr<sync_driver::SyncClient> sync_client, | 67 scoped_ptr<sync_driver::SyncClient> sync_client, |
| 67 Profile* profile, | |
| 68 scoped_ptr<SigninManagerWrapper> signin_wrapper, | 68 scoped_ptr<SigninManagerWrapper> signin_wrapper, |
| 69 ProfileOAuth2TokenService* oauth2_token_service, | 69 ProfileOAuth2TokenService* oauth2_token_service, |
| 70 browser_sync::ProfileSyncServiceStartBehavior start_behavior) { | 70 browser_sync::ProfileSyncServiceStartBehavior start_behavior, |
| 71 net::URLRequestContextGetter* url_request_context) { |
| 71 ProfileSyncService::InitParams init_params; | 72 ProfileSyncService::InitParams init_params; |
| 72 | 73 |
| 73 init_params.signin_wrapper = std::move(signin_wrapper); | 74 init_params.signin_wrapper = std::move(signin_wrapper); |
| 74 init_params.oauth2_token_service = oauth2_token_service; | 75 init_params.oauth2_token_service = oauth2_token_service; |
| 75 init_params.start_behavior = start_behavior; | 76 init_params.start_behavior = start_behavior; |
| 76 init_params.sync_client = std::move(sync_client); | 77 init_params.sync_client = std::move(sync_client); |
| 77 init_params.network_time_update_callback = | 78 init_params.network_time_update_callback = |
| 78 base::Bind(&browser_sync::EmptyNetworkTimeUpdate); | 79 base::Bind(&browser_sync::EmptyNetworkTimeUpdate); |
| 79 init_params.base_directory = profile->GetPath(); | 80 init_params.base_directory = base::FilePath(FILE_PATH_LITERAL("dummyPath")); |
| 80 init_params.url_request_context = profile->GetRequestContext(); | 81 init_params.url_request_context = url_request_context; |
| 81 init_params.debug_identifier = profile->GetDebugName(); | 82 init_params.debug_identifier = "dummyDebugName"; |
| 82 init_params.channel = chrome::GetChannel(); | 83 init_params.channel = version_info::Channel::UNKNOWN; |
| 83 init_params.db_thread = content::BrowserThread::GetMessageLoopProxyForThread( | 84 init_params.db_thread = content::BrowserThread::GetMessageLoopProxyForThread( |
| 84 content::BrowserThread::DB); | 85 content::BrowserThread::DB); |
| 85 init_params.file_thread = | 86 init_params.file_thread = |
| 86 content::BrowserThread::GetMessageLoopProxyForThread( | 87 content::BrowserThread::GetMessageLoopProxyForThread( |
| 87 content::BrowserThread::FILE); | 88 content::BrowserThread::FILE); |
| 88 init_params.blocking_pool = content::BrowserThread::GetBlockingPool(); | 89 init_params.blocking_pool = content::BrowserThread::GetBlockingPool(); |
| 89 | 90 |
| 90 return init_params; | 91 return init_params; |
| 91 } | 92 } |
| 92 | 93 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 105 static_cast<DataTypeManager::ConfigureResult>(result); | 106 static_cast<DataTypeManager::ConfigureResult>(result); |
| 106 if (result.status == sync_driver::DataTypeManager::ABORTED) | 107 if (result.status == sync_driver::DataTypeManager::ABORTED) |
| 107 error_callback.Run(&configure_result); | 108 error_callback.Run(&configure_result); |
| 108 service->OnConfigureDone(configure_result); | 109 service->OnConfigureDone(configure_result); |
| 109 } | 110 } |
| 110 | 111 |
| 111 class TestProfileSyncServiceNoBackup : public ProfileSyncService { | 112 class TestProfileSyncServiceNoBackup : public ProfileSyncService { |
| 112 public: | 113 public: |
| 113 TestProfileSyncServiceNoBackup( | 114 TestProfileSyncServiceNoBackup( |
| 114 scoped_ptr<sync_driver::SyncClient> sync_client, | 115 scoped_ptr<sync_driver::SyncClient> sync_client, |
| 115 Profile* profile, | |
| 116 scoped_ptr<SigninManagerWrapper> signin_wrapper, | 116 scoped_ptr<SigninManagerWrapper> signin_wrapper, |
| 117 ProfileOAuth2TokenService* oauth2_token_service, | 117 ProfileOAuth2TokenService* oauth2_token_service, |
| 118 browser_sync::ProfileSyncServiceStartBehavior start_behavior) | 118 browser_sync::ProfileSyncServiceStartBehavior start_behavior, |
| 119 net::URLRequestContextGetter* url_request_context) |
| 119 : ProfileSyncService(GetInitParams(std::move(sync_client), | 120 : ProfileSyncService(GetInitParams(std::move(sync_client), |
| 120 profile, | |
| 121 std::move(signin_wrapper), | 121 std::move(signin_wrapper), |
| 122 oauth2_token_service, | 122 oauth2_token_service, |
| 123 start_behavior)) {} | 123 start_behavior, |
| 124 url_request_context)) {} |
| 124 | 125 |
| 125 protected: | 126 protected: |
| 126 bool NeedBackup() const override { return false; } | 127 bool NeedBackup() const override { return false; } |
| 127 }; | 128 }; |
| 128 | 129 |
| 129 class ProfileSyncServiceStartupTest : public testing::Test { | 130 class ProfileSyncServiceStartupTest : public testing::Test { |
| 130 public: | 131 public: |
| 131 ProfileSyncServiceStartupTest() | 132 ProfileSyncServiceStartupTest() |
| 132 // Purposefully do not use a real FILE thread, see crbug/550013. | 133 // Purposefully do not use a real FILE thread, see crbug/550013. |
| 133 : thread_bundle_(content::TestBrowserThreadBundle::REAL_DB_THREAD | | 134 : thread_bundle_(content::TestBrowserThreadBundle::REAL_DB_THREAD | |
| (...skipping 23 matching lines...) Expand all Loading... |
| 157 | 158 |
| 158 void TearDown() override { sync_->RemoveObserver(&observer_); } | 159 void TearDown() override { sync_->RemoveObserver(&observer_); } |
| 159 | 160 |
| 160 static scoped_ptr<KeyedService> BuildService( | 161 static scoped_ptr<KeyedService> BuildService( |
| 161 content::BrowserContext* browser_context) { | 162 content::BrowserContext* browser_context) { |
| 162 Profile* profile = static_cast<Profile*>(browser_context); | 163 Profile* profile = static_cast<Profile*>(browser_context); |
| 163 scoped_ptr<browser_sync::ChromeSyncClient> sync_client( | 164 scoped_ptr<browser_sync::ChromeSyncClient> sync_client( |
| 164 new browser_sync::ChromeSyncClient(profile)); | 165 new browser_sync::ChromeSyncClient(profile)); |
| 165 sync_client->SetSyncApiComponentFactoryForTesting( | 166 sync_client->SetSyncApiComponentFactoryForTesting( |
| 166 make_scoped_ptr(new SyncApiComponentFactoryMock())); | 167 make_scoped_ptr(new SyncApiComponentFactoryMock())); |
| 168 scoped_refptr<net::URLRequestContextGetter> url_request_context = |
| 169 new net::TestURLRequestContextGetter( |
| 170 base::ThreadTaskRunnerHandle::Get()); |
| 167 return make_scoped_ptr(new TestProfileSyncServiceNoBackup( | 171 return make_scoped_ptr(new TestProfileSyncServiceNoBackup( |
| 168 std::move(sync_client), profile, | 172 std::move(sync_client), |
| 169 make_scoped_ptr(new SigninManagerWrapper( | 173 make_scoped_ptr(new SigninManagerWrapper( |
| 170 SigninManagerFactory::GetForProfile(profile))), | 174 SigninManagerFactory::GetForProfile(profile))), |
| 171 ProfileOAuth2TokenServiceFactory::GetForProfile(profile), | 175 ProfileOAuth2TokenServiceFactory::GetForProfile(profile), |
| 172 browser_sync::MANUAL_START)); | 176 browser_sync::MANUAL_START, url_request_context.get())); |
| 173 } | 177 } |
| 174 | 178 |
| 175 void CreateSyncService() { | 179 void CreateSyncService() { |
| 176 sync_ = static_cast<ProfileSyncService*>( | 180 sync_ = static_cast<ProfileSyncService*>( |
| 177 ProfileSyncServiceFactory::GetForProfile(profile_)); | 181 ProfileSyncServiceFactory::GetForProfile(profile_)); |
| 178 sync_->AddObserver(&observer_); | 182 sync_->AddObserver(&observer_); |
| 179 } | 183 } |
| 180 | 184 |
| 181 void IssueTestTokens(const std::string& account_id) { | 185 void IssueTestTokens(const std::string& account_id) { |
| 182 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_) | 186 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_) |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 264 static_cast<FakeSigninManagerForTesting*>( | 268 static_cast<FakeSigninManagerForTesting*>( |
| 265 SigninManagerFactory::GetForProfile(profile)); | 269 SigninManagerFactory::GetForProfile(profile)); |
| 266 SimulateTestUserSignin(profile, signin, nullptr); | 270 SimulateTestUserSignin(profile, signin, nullptr); |
| 267 ProfileOAuth2TokenService* oauth2_token_service = | 271 ProfileOAuth2TokenService* oauth2_token_service = |
| 268 ProfileOAuth2TokenServiceFactory::GetForProfile(profile); | 272 ProfileOAuth2TokenServiceFactory::GetForProfile(profile); |
| 269 EXPECT_TRUE(signin->IsAuthenticated()); | 273 EXPECT_TRUE(signin->IsAuthenticated()); |
| 270 scoped_ptr<browser_sync::ChromeSyncClient> sync_client( | 274 scoped_ptr<browser_sync::ChromeSyncClient> sync_client( |
| 271 new browser_sync::ChromeSyncClient(profile)); | 275 new browser_sync::ChromeSyncClient(profile)); |
| 272 sync_client->SetSyncApiComponentFactoryForTesting( | 276 sync_client->SetSyncApiComponentFactoryForTesting( |
| 273 make_scoped_ptr(new SyncApiComponentFactoryMock())); | 277 make_scoped_ptr(new SyncApiComponentFactoryMock())); |
| 278 scoped_refptr<net::URLRequestContextGetter> url_request_context = |
| 279 new net::TestURLRequestContextGetter( |
| 280 base::ThreadTaskRunnerHandle::Get()); |
| 274 return make_scoped_ptr(new TestProfileSyncServiceNoBackup( | 281 return make_scoped_ptr(new TestProfileSyncServiceNoBackup( |
| 275 std::move(sync_client), profile, | 282 std::move(sync_client), |
| 276 make_scoped_ptr(new SigninManagerWrapper(signin)), oauth2_token_service, | 283 make_scoped_ptr(new SigninManagerWrapper(signin)), oauth2_token_service, |
| 277 browser_sync::AUTO_START)); | 284 browser_sync::AUTO_START, url_request_context.get())); |
| 278 } | 285 } |
| 279 }; | 286 }; |
| 280 | 287 |
| 281 TEST_F(ProfileSyncServiceStartupTest, StartFirstTime) { | 288 TEST_F(ProfileSyncServiceStartupTest, StartFirstTime) { |
| 282 // We've never completed startup. | 289 // We've never completed startup. |
| 283 profile_->GetPrefs()->ClearPref(sync_driver::prefs::kSyncFirstSetupComplete); | 290 profile_->GetPrefs()->ClearPref(sync_driver::prefs::kSyncFirstSetupComplete); |
| 284 CreateSyncService(); | 291 CreateSyncService(); |
| 285 SetUpSyncBackendHost(); | 292 SetUpSyncBackendHost(); |
| 286 DataTypeManagerMock* data_type_manager = SetUpDataTypeManager(); | 293 DataTypeManagerMock* data_type_manager = SetUpDataTypeManager(); |
| 287 EXPECT_CALL(*data_type_manager, Configure(_, _)).Times(0); | 294 EXPECT_CALL(*data_type_manager, Configure(_, _)).Times(0); |
| (...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 596 profile_->GetPrefs()->ClearPref(sync_driver::prefs::kSyncFirstSetupComplete); | 603 profile_->GetPrefs()->ClearPref(sync_driver::prefs::kSyncFirstSetupComplete); |
| 597 | 604 |
| 598 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); | 605 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); |
| 599 sync_->Initialize(); | 606 sync_->Initialize(); |
| 600 | 607 |
| 601 sync_->SetSetupInProgress(true); | 608 sync_->SetSetupInProgress(true); |
| 602 IssueTestTokens(account_id); | 609 IssueTestTokens(account_id); |
| 603 sync_->SetSetupInProgress(false); | 610 sync_->SetSetupInProgress(false); |
| 604 EXPECT_FALSE(sync_->IsSyncActive()); | 611 EXPECT_FALSE(sync_->IsSyncActive()); |
| 605 } | 612 } |
| OLD | NEW |