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/chromeos/login/login_manager_test.h" | 5 #include "chrome/browser/chromeos/login/login_manager_test.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 30 matching lines...) Expand all Loading... |
41 | 41 |
42 namespace { | 42 namespace { |
43 | 43 |
44 const char kGAIAHost[] = "accounts.google.com"; | 44 const char kGAIAHost[] = "accounts.google.com"; |
45 const char kTestUserinfoToken1[] = "fake-userinfo-token-1"; | 45 const char kTestUserinfoToken1[] = "fake-userinfo-token-1"; |
46 const char kTestRefreshToken1[] = "fake-refresh-token-1"; | 46 const char kTestRefreshToken1[] = "fake-refresh-token-1"; |
47 const char kTestUserinfoToken2[] = "fake-userinfo-token-2"; | 47 const char kTestUserinfoToken2[] = "fake-userinfo-token-2"; |
48 const char kTestRefreshToken2[] = "fake-refresh-token-2"; | 48 const char kTestRefreshToken2[] = "fake-refresh-token-2"; |
49 | 49 |
50 UserContext CreateUserContext(const std::string& user_id) { | 50 UserContext CreateUserContext(const std::string& user_id) { |
51 UserContext user_context(user_id); | 51 UserContext user_context(AccountId::FromUserEmailGaiaId( |
| 52 user_id, LoginManagerTest::GetGaiaIDForUserID(user_id))); |
52 user_context.SetGaiaID(LoginManagerTest::GetGaiaIDForUserID(user_id)); | 53 user_context.SetGaiaID(LoginManagerTest::GetGaiaIDForUserID(user_id)); |
53 user_context.SetKey(Key("password")); | 54 user_context.SetKey(Key("password")); |
54 if (user_id == LoginManagerTest::kEnterpriseUser1) { | 55 if (user_id == LoginManagerTest::kEnterpriseUser1) { |
55 user_context.SetRefreshToken(kTestRefreshToken1); | 56 user_context.SetRefreshToken(kTestRefreshToken1); |
56 } else if (user_id == LoginManagerTest::kEnterpriseUser2) { | 57 } else if (user_id == LoginManagerTest::kEnterpriseUser2) { |
57 user_context.SetRefreshToken(kTestRefreshToken2); | 58 user_context.SetRefreshToken(kTestRefreshToken2); |
58 } | 59 } |
59 return user_context; | 60 return user_context; |
60 } | 61 } |
61 | 62 |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 test::UserSessionManagerTestApi session_manager_test_api( | 162 test::UserSessionManagerTestApi session_manager_test_api( |
162 UserSessionManager::GetInstance()); | 163 UserSessionManager::GetInstance()); |
163 session_manager_test_api.InjectStubUserContext(user_context); | 164 session_manager_test_api.InjectStubUserContext(user_context); |
164 } | 165 } |
165 | 166 |
166 bool LoginManagerTest::TryToLogin(const UserContext& user_context) { | 167 bool LoginManagerTest::TryToLogin(const UserContext& user_context) { |
167 if (!AddUserToSession(user_context)) | 168 if (!AddUserToSession(user_context)) |
168 return false; | 169 return false; |
169 if (const user_manager::User* active_user = | 170 if (const user_manager::User* active_user = |
170 user_manager::UserManager::Get()->GetActiveUser()) | 171 user_manager::UserManager::Get()->GetActiveUser()) |
171 return active_user->email() == user_context.GetUserID(); | 172 return active_user->GetAccountId() == user_context.GetAccountId(); |
172 return false; | 173 return false; |
173 } | 174 } |
174 | 175 |
175 bool LoginManagerTest::AddUserToSession(const UserContext& user_context) { | 176 bool LoginManagerTest::AddUserToSession(const UserContext& user_context) { |
176 ExistingUserController* controller = | 177 ExistingUserController* controller = |
177 ExistingUserController::current_controller(); | 178 ExistingUserController::current_controller(); |
178 if (!controller) { | 179 if (!controller) { |
179 ADD_FAILURE(); | 180 ADD_FAILURE(); |
180 return false; | 181 return false; |
181 } | 182 } |
182 content::WindowedNotificationObserver observer( | 183 content::WindowedNotificationObserver observer( |
183 chrome::NOTIFICATION_SESSION_STARTED, | 184 chrome::NOTIFICATION_SESSION_STARTED, |
184 content::NotificationService::AllSources()); | 185 content::NotificationService::AllSources()); |
185 controller->Login(user_context, SigninSpecifics()); | 186 controller->Login(user_context, SigninSpecifics()); |
186 observer.Wait(); | 187 observer.Wait(); |
187 const user_manager::UserList& logged_users = | 188 const user_manager::UserList& logged_users = |
188 user_manager::UserManager::Get()->GetLoggedInUsers(); | 189 user_manager::UserManager::Get()->GetLoggedInUsers(); |
189 for (user_manager::UserList::const_iterator it = logged_users.begin(); | 190 for (user_manager::UserList::const_iterator it = logged_users.begin(); |
190 it != logged_users.end(); | 191 it != logged_users.end(); |
191 ++it) { | 192 ++it) { |
192 if ((*it)->email() == user_context.GetUserID()) | 193 if ((*it)->GetAccountId() == user_context.GetAccountId()) |
193 return true; | 194 return true; |
194 } | 195 } |
195 return false; | 196 return false; |
196 } | 197 } |
197 | 198 |
198 void LoginManagerTest::LoginUser(const std::string& user_id) { | 199 void LoginManagerTest::LoginUser(const std::string& user_id) { |
199 const UserContext user_context = CreateUserContext(user_id); | 200 const UserContext user_context = CreateUserContext(user_id); |
200 SetExpectedCredentials(user_context); | 201 SetExpectedCredentials(user_context); |
201 EXPECT_TRUE(TryToLogin(user_context)); | 202 EXPECT_TRUE(TryToLogin(user_context)); |
202 } | 203 } |
(...skipping 18 matching lines...) Expand all Loading... |
221 EXPECT_TRUE(host != NULL); | 222 EXPECT_TRUE(host != NULL); |
222 | 223 |
223 content::WebContents* web_contents = | 224 content::WebContents* web_contents = |
224 host->GetWebUILoginView()->GetWebContents(); | 225 host->GetWebUILoginView()->GetWebContents(); |
225 EXPECT_TRUE(web_contents != NULL); | 226 EXPECT_TRUE(web_contents != NULL); |
226 set_web_contents(web_contents); | 227 set_web_contents(web_contents); |
227 js_checker_.set_web_contents(web_contents); | 228 js_checker_.set_web_contents(web_contents); |
228 } | 229 } |
229 | 230 |
230 } // namespace chromeos | 231 } // namespace chromeos |
OLD | NEW |