OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "chrome/browser/sync/test/integration/profile_sync_service_harness.h" | 5 #include "chrome/browser/sync/test/integration/profile_sync_service_harness.h" |
6 | 6 |
7 #include <cstddef> | 7 #include <cstddef> |
8 #include <iterator> | 8 #include <iterator> |
9 #include <ostream> | 9 #include <ostream> |
10 #include <sstream> | 10 #include <sstream> |
(...skipping 19 matching lines...) Expand all Loading... |
30 #include "components/signin/core/browser/signin_manager_base.h" | 30 #include "components/signin/core/browser/signin_manager_base.h" |
31 #include "components/sync_driver/data_type_controller.h" | 31 #include "components/sync_driver/data_type_controller.h" |
32 #include "google_apis/gaia/gaia_constants.h" | 32 #include "google_apis/gaia/gaia_constants.h" |
33 #include "sync/internal_api/public/base/progress_marker_map.h" | 33 #include "sync/internal_api/public/base/progress_marker_map.h" |
34 #include "sync/internal_api/public/util/sync_string_conversions.h" | 34 #include "sync/internal_api/public/util/sync_string_conversions.h" |
35 | 35 |
36 using syncer::sessions::SyncSessionSnapshot; | 36 using syncer::sessions::SyncSessionSnapshot; |
37 | 37 |
38 namespace { | 38 namespace { |
39 | 39 |
| 40 std::string GetGaiaIdForUsername(const std::string& username) { |
| 41 return "gaia-id-" + username; |
| 42 } |
| 43 |
40 bool HasAuthError(ProfileSyncService* service) { | 44 bool HasAuthError(ProfileSyncService* service) { |
41 return service->GetAuthError().state() == | 45 return service->GetAuthError().state() == |
42 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS || | 46 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS || |
43 service->GetAuthError().state() == | 47 service->GetAuthError().state() == |
44 GoogleServiceAuthError::SERVICE_ERROR || | 48 GoogleServiceAuthError::SERVICE_ERROR || |
45 service->GetAuthError().state() == | 49 service->GetAuthError().state() == |
46 GoogleServiceAuthError::REQUEST_CANCELED; | 50 GoogleServiceAuthError::REQUEST_CANCELED; |
47 } | 51 } |
48 | 52 |
49 class BackendInitializeChecker : public SingleClientStatusChangeChecker { | 53 class BackendInitializeChecker : public SingleClientStatusChangeChecker { |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 // Initialize the sync client's profile sync service object. | 152 // Initialize the sync client's profile sync service object. |
149 if (service() == NULL) { | 153 if (service() == NULL) { |
150 LOG(ERROR) << "SetupSync(): service() is null."; | 154 LOG(ERROR) << "SetupSync(): service() is null."; |
151 return false; | 155 return false; |
152 } | 156 } |
153 | 157 |
154 // Tell the sync service that setup is in progress so we don't start syncing | 158 // Tell the sync service that setup is in progress so we don't start syncing |
155 // until we've finished configuration. | 159 // until we've finished configuration. |
156 service()->SetSetupInProgress(true); | 160 service()->SetSetupInProgress(true); |
157 | 161 |
| 162 // Authenticate sync client using GAIA credentials. |
| 163 std::string gaia_id = GetGaiaIdForUsername(username_); |
| 164 service()->signin()->SetAuthenticatedAccountInfo(gaia_id, username_); |
| 165 std::string account_id = service()->signin()->GetAuthenticatedAccountId(); |
| 166 service()->GoogleSigninSucceeded(account_id, username_, password_); |
| 167 |
158 DCHECK(!username_.empty()); | 168 DCHECK(!username_.empty()); |
159 if (signin_type_ == SigninType::UI_SIGNIN) { | 169 if (signin_type_ == SigninType::UI_SIGNIN) { |
160 Browser* browser = | 170 Browser* browser = |
161 FindBrowserWithProfile(profile_, chrome::GetActiveDesktop()); | 171 FindBrowserWithProfile(profile_, chrome::GetActiveDesktop()); |
162 DCHECK(browser); | 172 DCHECK(browser); |
163 if (!login_ui_test_utils::SignInWithUI(browser, username_, password_)) { | 173 if (!login_ui_test_utils::SignInWithUI(browser, username_, password_)) { |
164 LOG(ERROR) << "Could not sign in to GAIA servers."; | 174 LOG(ERROR) << "Could not sign in to GAIA servers."; |
165 return false; | 175 return false; |
166 } | 176 } |
167 } else if (signin_type_ == SigninType::FAKE_SIGNIN) { | 177 } else if (signin_type_ == SigninType::FAKE_SIGNIN) { |
168 // Authenticate sync client using GAIA credentials. | 178 // Authenticate sync client using GAIA credentials. |
169 service()->signin()->SetAuthenticatedUsername(username_); | 179 service()->signin()->SetAuthenticatedAccountInfo(gaia_id, username_); |
170 service()->GoogleSigninSucceeded(username_, username_, password_); | 180 service()->GoogleSigninSucceeded(account_id, username_, password_); |
171 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_)-> | 181 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_)-> |
172 UpdateCredentials(username_, GenerateFakeOAuth2RefreshTokenString()); | 182 UpdateCredentials(account_id, GenerateFakeOAuth2RefreshTokenString()); |
173 } else { | 183 } else { |
174 LOG(ERROR) << "Unsupported profile signin type."; | 184 LOG(ERROR) << "Unsupported profile signin type."; |
175 } | 185 } |
176 | 186 |
177 if (!AwaitBackendInitialization()) { | 187 if (!AwaitBackendInitialization()) { |
178 return false; | 188 return false; |
179 } | 189 } |
180 | 190 |
181 // Choose the datatypes to be synced. If all datatypes are to be synced, | 191 // Choose the datatypes to be synced. If all datatypes are to be synced, |
182 // set sync_everything to true; otherwise, set it to false. | 192 // set sync_everything to true; otherwise, set it to false. |
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
461 | 471 |
462 std::string ProfileSyncServiceHarness::GetServiceStatus() { | 472 std::string ProfileSyncServiceHarness::GetServiceStatus() { |
463 scoped_ptr<base::DictionaryValue> value( | 473 scoped_ptr<base::DictionaryValue> value( |
464 sync_ui_util::ConstructAboutInformation(service())); | 474 sync_ui_util::ConstructAboutInformation(service())); |
465 std::string service_status; | 475 std::string service_status; |
466 base::JSONWriter::WriteWithOptions(value.get(), | 476 base::JSONWriter::WriteWithOptions(value.get(), |
467 base::JSONWriter::OPTIONS_PRETTY_PRINT, | 477 base::JSONWriter::OPTIONS_PRETTY_PRINT, |
468 &service_status); | 478 &service_status); |
469 return service_status; | 479 return service_status; |
470 } | 480 } |
OLD | NEW |