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 "chrome/browser/sync/profile_sync_service_harness.h" | 5 #include "chrome/browser/sync/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 <set> | 10 #include <set> |
11 #include <sstream> | 11 #include <sstream> |
12 #include <vector> | 12 #include <vector> |
13 | 13 |
14 #include "base/base64.h" | 14 #include "base/base64.h" |
15 #include "base/bind.h" | 15 #include "base/bind.h" |
16 #include "base/command_line.h" | 16 #include "base/command_line.h" |
17 #include "base/compiler_specific.h" | 17 #include "base/compiler_specific.h" |
18 #include "base/json/json_writer.h" | 18 #include "base/json/json_writer.h" |
19 #include "base/location.h" | 19 #include "base/location.h" |
20 #include "base/logging.h" | 20 #include "base/logging.h" |
21 #include "base/memory/ref_counted.h" | 21 #include "base/memory/ref_counted.h" |
22 #include "base/message_loop/message_loop.h" | 22 #include "base/message_loop/message_loop.h" |
23 #include "base/prefs/pref_service.h" | 23 #include "base/prefs/pref_service.h" |
24 #include "base/strings/stringprintf.h" | 24 #include "base/strings/stringprintf.h" |
25 #include "chrome/browser/chrome_notification_types.h" | 25 #include "chrome/browser/chrome_notification_types.h" |
26 #include "chrome/browser/invalidation/p2p_invalidation_service.h" | 26 #include "chrome/browser/invalidation/p2p_invalidation_service.h" |
27 #include "chrome/browser/profiles/profile.h" | 27 #include "chrome/browser/profiles/profile.h" |
| 28 #include "chrome/browser/signin/profile_oauth2_token_service.h" |
| 29 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
28 #include "chrome/browser/signin/signin_manager_base.h" | 30 #include "chrome/browser/signin/signin_manager_base.h" |
29 #include "chrome/browser/signin/token_service.h" | |
30 #include "chrome/browser/signin/token_service_factory.h" | |
31 #include "chrome/browser/sync/about_sync_util.h" | 31 #include "chrome/browser/sync/about_sync_util.h" |
32 #include "chrome/browser/sync/glue/data_type_controller.h" | 32 #include "chrome/browser/sync/glue/data_type_controller.h" |
33 #include "chrome/browser/sync/profile_sync_service_factory.h" | 33 #include "chrome/browser/sync/profile_sync_service_factory.h" |
34 #include "chrome/common/chrome_switches.h" | 34 #include "chrome/common/chrome_switches.h" |
35 #include "chrome/common/pref_names.h" | 35 #include "chrome/common/pref_names.h" |
36 #include "content/public/browser/notification_service.h" | 36 #include "content/public/browser/notification_service.h" |
37 #include "google_apis/gaia/gaia_constants.h" | 37 #include "google_apis/gaia/gaia_constants.h" |
38 #include "sync/internal_api/public/base/progress_marker_map.h" | 38 #include "sync/internal_api/public/base/progress_marker_map.h" |
39 #include "sync/internal_api/public/sessions/sync_session_snapshot.h" | 39 #include "sync/internal_api/public/sessions/sync_session_snapshot.h" |
40 #include "sync/internal_api/public/util/sync_string_conversions.h" | 40 #include "sync/internal_api/public/util/sync_string_conversions.h" |
41 | 41 |
| 42 #if defined(ENABLE_MANAGED_USERS) |
| 43 #include "chrome/browser/managed_mode/managed_user_constants.h" |
| 44 #endif |
| 45 |
42 using syncer::sessions::SyncSessionSnapshot; | 46 using syncer::sessions::SyncSessionSnapshot; |
43 using invalidation::P2PInvalidationService; | 47 using invalidation::P2PInvalidationService; |
44 | 48 |
45 // TODO(rsimha): Remove the following lines once crbug.com/91863 is fixed. | 49 // TODO(rsimha): Remove the following lines once crbug.com/91863 is fixed. |
46 // The amount of time for which we wait for a live sync operation to complete. | 50 // The amount of time for which we wait for a live sync operation to complete. |
47 static const int kLiveSyncOperationTimeoutMs = 45000; | 51 static const int kLiveSyncOperationTimeoutMs = 45000; |
48 | 52 |
49 // The amount of time we wait for test cases that verify exponential backoff. | 53 // The amount of time we wait for test cases that verify exponential backoff. |
50 static const int kExponentialBackoffVerificationTimeoutMs = 60000; | 54 static const int kExponentialBackoffVerificationTimeoutMs = 60000; |
51 | 55 |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 | 206 |
203 // Authenticate sync client using GAIA credentials. | 207 // Authenticate sync client using GAIA credentials. |
204 service_->signin()->SetAuthenticatedUsername(username_); | 208 service_->signin()->SetAuthenticatedUsername(username_); |
205 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, | 209 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, |
206 username_); | 210 username_); |
207 GoogleServiceSigninSuccessDetails details(username_, password_); | 211 GoogleServiceSigninSuccessDetails details(username_, password_); |
208 content::NotificationService::current()->Notify( | 212 content::NotificationService::current()->Notify( |
209 chrome::NOTIFICATION_GOOGLE_SIGNIN_SUCCESSFUL, | 213 chrome::NOTIFICATION_GOOGLE_SIGNIN_SUCCESSFUL, |
210 content::Source<Profile>(profile_), | 214 content::Source<Profile>(profile_), |
211 content::Details<const GoogleServiceSigninSuccessDetails>(&details)); | 215 content::Details<const GoogleServiceSigninSuccessDetails>(&details)); |
212 TokenServiceFactory::GetForProfile(profile_)->IssueAuthTokenForTest( | 216 |
213 GaiaConstants::kGaiaOAuth2LoginRefreshToken, | 217 #if defined(ENABLE_MANAGED_USERS) |
214 GenerateFakeOAuth2RefreshTokenString()); | 218 std::string account_id = profile_->IsManaged() ? |
| 219 managed_users::kManagedUserPseudoEmail : username_; |
| 220 #else |
| 221 std::string account_id = username_; |
| 222 #endif |
| 223 DCHECK(!account_id.empty()); |
| 224 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_)-> |
| 225 UpdateCredentials(account_id, GenerateFakeOAuth2RefreshTokenString()); |
215 | 226 |
216 // Wait for the OnBackendInitialized() callback. | 227 // Wait for the OnBackendInitialized() callback. |
217 if (!AwaitBackendInitialized()) { | 228 if (!AwaitBackendInitialized()) { |
218 LOG(ERROR) << "OnBackendInitialized() not seen after " | 229 LOG(ERROR) << "OnBackendInitialized() not seen after " |
219 << kLiveSyncOperationTimeoutMs / 1000 | 230 << kLiveSyncOperationTimeoutMs / 1000 |
220 << " seconds."; | 231 << " seconds."; |
221 return false; | 232 return false; |
222 } | 233 } |
223 | 234 |
224 // Make sure that initial sync wasn't blocked by a missing passphrase. | 235 // Make sure that initial sync wasn't blocked by a missing passphrase. |
(...skipping 954 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1179 | 1190 |
1180 std::string ProfileSyncServiceHarness::GetServiceStatus() { | 1191 std::string ProfileSyncServiceHarness::GetServiceStatus() { |
1181 scoped_ptr<DictionaryValue> value( | 1192 scoped_ptr<DictionaryValue> value( |
1182 sync_ui_util::ConstructAboutInformation(service_)); | 1193 sync_ui_util::ConstructAboutInformation(service_)); |
1183 std::string service_status; | 1194 std::string service_status; |
1184 base::JSONWriter::WriteWithOptions(value.get(), | 1195 base::JSONWriter::WriteWithOptions(value.get(), |
1185 base::JSONWriter::OPTIONS_PRETTY_PRINT, | 1196 base::JSONWriter::OPTIONS_PRETTY_PRINT, |
1186 &service_status); | 1197 &service_status); |
1187 return service_status; | 1198 return service_status; |
1188 } | 1199 } |
OLD | NEW |