OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/test/device_management_test_util.h" | 5 #include "chrome/test/device_management_test_util.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "chrome/browser/net/gaia/token_service.h" | 9 #include "chrome/browser/net/gaia/token_service.h" |
| 10 #include "chrome/browser/policy/device_token_fetcher.h" |
10 #include "chrome/common/net/gaia/gaia_constants.h" | 11 #include "chrome/common/net/gaia/gaia_constants.h" |
11 #include "chrome/common/notification_service.h" | 12 #include "chrome/common/notification_service.h" |
12 #include "chrome/common/notification_source.h" | 13 #include "chrome/common/notification_source.h" |
13 #include "chrome/common/notification_type.h" | 14 #include "chrome/common/notification_type.h" |
14 | 15 |
| 16 #if defined(OS_CHROMEOS) |
| 17 #include "chrome/browser/chromeos/login/user_manager.h" |
| 18 #else |
| 19 #include "chrome/browser/sync/signin_manager.h" |
| 20 #endif |
| 21 |
15 namespace policy { | 22 namespace policy { |
16 | 23 |
| 24 const char* kTestDasherDomainUsername = "___@example.com"; |
| 25 |
17 namespace { | 26 namespace { |
18 | 27 |
19 static const char kFakeGaiaAuthToken[] = "FakeGAIAToken"; | 28 static const char kFakeGaiaAuthToken[] = "FakeGAIAToken"; |
20 | 29 |
21 } // namespace | 30 } // namespace |
22 | 31 |
23 void SimulateSuccessfulLogin() { | 32 void SimulateTokenAvailable() { |
24 const std::string service(GaiaConstants::kDeviceManagementService); | 33 const std::string service(GaiaConstants::kDeviceManagementService); |
25 const std::string auth_token(kFakeGaiaAuthToken); | 34 const std::string auth_token(kFakeGaiaAuthToken); |
26 TokenService::TokenAvailableDetails details(service, auth_token); | 35 TokenService::TokenAvailableDetails details(service, auth_token); |
27 NotificationService::current()->Notify( | 36 NotificationService::current()->Notify( |
28 NotificationType::TOKEN_AVAILABLE, | 37 NotificationType::TOKEN_AVAILABLE, |
29 Source<TokenService>(NULL), | 38 Source<TokenService>(NULL), |
30 Details<const TokenService::TokenAvailableDetails>(&details)); | 39 Details<const TokenService::TokenAvailableDetails>(&details)); |
31 } | 40 } |
32 | 41 |
| 42 void SimulateUsernameAvailable(DeviceTokenFetcher* fetcher, |
| 43 const std::string& username) { |
| 44 fetcher->injected_username.reset(new std::string(username)); |
| 45 #if defined(OS_CHROMEOS) |
| 46 chromeos::UserManager::User user; |
| 47 user.set_email(username); |
| 48 NotificationService::current()->Notify( |
| 49 NotificationType::LOGIN_USER_CHANGED, |
| 50 Source<chromeos::UserManager>(NULL), |
| 51 Details<const chromeos::UserManager::User>(&user)); |
| 52 #else |
| 53 GoogleServiceSigninSuccessDetails details(username, ""); |
| 54 NotificationService::current()->Notify( |
| 55 NotificationType::GOOGLE_SIGNIN_SUCCESSFUL, |
| 56 Source<SigninManager>(NULL), |
| 57 Details<const GoogleServiceSigninSuccessDetails>(&details)); |
| 58 #endif |
| 59 } |
| 60 |
| 61 void SimulateSuccessfulLogin(DeviceTokenFetcher* fetcher, |
| 62 const std::string& username) { |
| 63 SimulateTokenAvailable(); |
| 64 SimulateUsernameAvailable(fetcher, username); |
| 65 } |
| 66 |
33 } // namespace policy | 67 } // namespace policy |
OLD | NEW |