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