OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 <string> | 5 #include <string> |
6 | 6 |
7 #include "base/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
8 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
10 #include "base/synchronization/waitable_event.h" | 10 #include "base/synchronization/waitable_event.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 #include "chrome/browser/ui/browser_tabstrip.h" | 22 #include "chrome/browser/ui/browser_tabstrip.h" |
23 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h" | 23 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h" |
24 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 24 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
25 #include "chrome/browser/ui/webui/chromeos/login/signin_screen_handler.h" | 25 #include "chrome/browser/ui/webui/chromeos/login/signin_screen_handler.h" |
26 #include "chrome/common/chrome_switches.h" | 26 #include "chrome/common/chrome_switches.h" |
27 #include "chrome/test/base/ui_test_utils.h" | 27 #include "chrome/test/base/ui_test_utils.h" |
28 #include "chromeos/login/auth/key.h" | 28 #include "chromeos/login/auth/key.h" |
29 #include "chromeos/login/auth/user_context.h" | 29 #include "chromeos/login/auth/user_context.h" |
30 #include "components/app_modal/javascript_app_modal_dialog.h" | 30 #include "components/app_modal/javascript_app_modal_dialog.h" |
31 #include "components/app_modal/native_app_modal_dialog.h" | 31 #include "components/app_modal/native_app_modal_dialog.h" |
32 #include "components/signin/core/account_id/account_id.h" | |
33 #include "components/signin/core/browser/account_tracker_service.h" | 32 #include "components/signin/core/browser/account_tracker_service.h" |
34 #include "components/signin/core/browser/profile_oauth2_token_service.h" | 33 #include "components/signin/core/browser/profile_oauth2_token_service.h" |
35 #include "components/user_manager/user.h" | 34 #include "components/user_manager/user.h" |
36 #include "components/user_manager/user_manager.h" | 35 #include "components/user_manager/user_manager.h" |
37 #include "content/public/browser/notification_service.h" | 36 #include "content/public/browser/notification_service.h" |
38 #include "content/public/test/browser_test_utils.h" | 37 #include "content/public/test/browser_test_utils.h" |
39 #include "extensions/browser/process_manager.h" | 38 #include "extensions/browser/process_manager.h" |
40 #include "extensions/test/extension_test_message_listener.h" | 39 #include "extensions/test/extension_test_message_listener.h" |
41 #include "extensions/test/result_catcher.h" | 40 #include "extensions/test/result_catcher.h" |
42 #include "google_apis/gaia/gaia_constants.h" | 41 #include "google_apis/gaia/gaia_constants.h" |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 JsExpect("!!document.querySelector('#account-picker')"); | 190 JsExpect("!!document.querySelector('#account-picker')"); |
192 JsExpect("!!document.querySelector('#pod-row')"); | 191 JsExpect("!!document.querySelector('#pod-row')"); |
193 | 192 |
194 std::string account_id = PickAccountId( | 193 std::string account_id = PickAccountId( |
195 ProfileManager::GetPrimaryUserProfile(), kTestGaiaId, kTestEmail); | 194 ProfileManager::GetPrimaryUserProfile(), kTestGaiaId, kTestEmail); |
196 | 195 |
197 EXPECT_EQ(GetOAuthStatusFromLocalState(account_id), | 196 EXPECT_EQ(GetOAuthStatusFromLocalState(account_id), |
198 user_manager::User::OAUTH2_TOKEN_STATUS_VALID); | 197 user_manager::User::OAUTH2_TOKEN_STATUS_VALID); |
199 | 198 |
200 // Try login. Primary profile has changed. | 199 // Try login. Primary profile has changed. |
201 EXPECT_TRUE( | 200 EXPECT_TRUE(TryToLogin(kTestGaiaId, kTestEmail, kTestAccountPassword)); |
202 TryToLogin(AccountId::FromUserEmailGaiaId(kTestEmail, kTestGaiaId), | |
203 kTestAccountPassword)); | |
204 Profile* profile = ProfileManager::GetPrimaryUserProfile(); | 201 Profile* profile = ProfileManager::GetPrimaryUserProfile(); |
205 | 202 |
206 // Wait for the session merge to finish. | 203 // Wait for the session merge to finish. |
207 WaitForMergeSessionCompletion(OAuth2LoginManager::SESSION_RESTORE_DONE); | 204 WaitForMergeSessionCompletion(OAuth2LoginManager::SESSION_RESTORE_DONE); |
208 | 205 |
209 // Check for existance of refresh token. | 206 // Check for existance of refresh token. |
210 ProfileOAuth2TokenService* token_service = | 207 ProfileOAuth2TokenService* token_service = |
211 ProfileOAuth2TokenServiceFactory::GetForProfile(profile); | 208 ProfileOAuth2TokenServiceFactory::GetForProfile(profile); |
212 EXPECT_TRUE(token_service->RefreshTokenIsAvailable(account_id)); | 209 EXPECT_TRUE(token_service->RefreshTokenIsAvailable(account_id)); |
213 | 210 |
214 EXPECT_EQ(GetOAuthStatusFromLocalState(account_id), | 211 EXPECT_EQ(GetOAuthStatusFromLocalState(account_id), |
215 user_manager::User::OAUTH2_TOKEN_STATUS_VALID); | 212 user_manager::User::OAUTH2_TOKEN_STATUS_VALID); |
216 } | 213 } |
217 | 214 |
218 bool TryToLogin(const AccountId& account_id, const std::string& password) { | 215 bool TryToLogin(const std::string& gaia_id, |
219 if (!AddUserToSession(account_id, password)) | 216 const std::string& username, |
| 217 const std::string& password) { |
| 218 if (!AddUserToSession(gaia_id, username, password)) |
220 return false; | 219 return false; |
221 | 220 |
222 if (const user_manager::User* active_user = | 221 if (const user_manager::User* active_user = |
223 user_manager::UserManager::Get()->GetActiveUser()) { | 222 user_manager::UserManager::Get()->GetActiveUser()) { |
224 return active_user->GetAccountId() == account_id; | 223 return active_user->email() == username; |
225 } | 224 } |
226 | 225 |
227 return false; | 226 return false; |
228 } | 227 } |
229 | 228 |
230 user_manager::User::OAuthTokenStatus GetOAuthStatusFromLocalState( | 229 user_manager::User::OAuthTokenStatus GetOAuthStatusFromLocalState( |
231 const std::string& account_id) const { | 230 const std::string& account_id) const { |
232 PrefService* local_state = g_browser_process->local_state(); | 231 PrefService* local_state = g_browser_process->local_state(); |
233 const base::DictionaryValue* prefs_oauth_status = | 232 const base::DictionaryValue* prefs_oauth_status = |
234 local_state->GetDictionary("OAuthTokenStatus"); | 233 local_state->GetDictionary("OAuthTokenStatus"); |
(...skipping 10 matching lines...) Expand all Loading... |
245 | 244 |
246 protected: | 245 protected: |
247 // OobeBaseTest overrides. | 246 // OobeBaseTest overrides. |
248 Profile* profile() override { | 247 Profile* profile() override { |
249 if (user_manager::UserManager::Get()->GetActiveUser()) | 248 if (user_manager::UserManager::Get()->GetActiveUser()) |
250 return ProfileManager::GetPrimaryUserProfile(); | 249 return ProfileManager::GetPrimaryUserProfile(); |
251 | 250 |
252 return OobeBaseTest::profile(); | 251 return OobeBaseTest::profile(); |
253 } | 252 } |
254 | 253 |
255 bool AddUserToSession(const AccountId& account_id, | 254 bool AddUserToSession(const std::string& gaia_id, |
| 255 const std::string& username, |
256 const std::string& password) { | 256 const std::string& password) { |
257 ExistingUserController* controller = | 257 ExistingUserController* controller = |
258 ExistingUserController::current_controller(); | 258 ExistingUserController::current_controller(); |
259 if (!controller) { | 259 if (!controller) { |
260 ADD_FAILURE(); | 260 ADD_FAILURE(); |
261 return false; | 261 return false; |
262 } | 262 } |
263 | 263 |
264 UserContext user_context(account_id); | 264 UserContext user_context(username); |
265 user_context.SetGaiaID(account_id.GetGaiaId()); | 265 user_context.SetGaiaID(gaia_id); |
266 user_context.SetKey(Key(password)); | 266 user_context.SetKey(Key(password)); |
267 controller->Login(user_context, SigninSpecifics()); | 267 controller->Login(user_context, SigninSpecifics()); |
268 content::WindowedNotificationObserver( | 268 content::WindowedNotificationObserver( |
269 chrome::NOTIFICATION_SESSION_STARTED, | 269 chrome::NOTIFICATION_SESSION_STARTED, |
270 content::NotificationService::AllSources()).Wait(); | 270 content::NotificationService::AllSources()).Wait(); |
271 const user_manager::UserList& logged_users = | 271 const user_manager::UserList& logged_users = |
272 user_manager::UserManager::Get()->GetLoggedInUsers(); | 272 user_manager::UserManager::Get()->GetLoggedInUsers(); |
273 for (user_manager::UserList::const_iterator it = logged_users.begin(); | 273 for (user_manager::UserList::const_iterator it = logged_users.begin(); |
274 it != logged_users.end(); | 274 it != logged_users.end(); |
275 ++it) { | 275 ++it) { |
276 if ((*it)->GetAccountId() == account_id) | 276 if ((*it)->email() == username) |
277 return true; | 277 return true; |
278 } | 278 } |
279 return false; | 279 return false; |
280 } | 280 } |
281 | 281 |
282 void SetupGaiaServerWithAccessTokens() { | 282 void SetupGaiaServerWithAccessTokens() { |
283 fake_gaia_->MapEmailToGaiaId(kTestEmail, kTestGaiaId); | 283 fake_gaia_->MapEmailToGaiaId(kTestEmail, kTestGaiaId); |
284 | 284 |
285 // Configure OAuth authentication. | 285 // Configure OAuth authentication. |
286 GaiaUrls* gaia_urls = GaiaUrls::GetInstance(); | 286 GaiaUrls* gaia_urls = GaiaUrls::GetInstance(); |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
487 chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE, | 487 chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE, |
488 content::NotificationService::AllSources()).Wait(); | 488 content::NotificationService::AllSources()).Wait(); |
489 | 489 |
490 JsExpect("!!document.querySelector('#account-picker')"); | 490 JsExpect("!!document.querySelector('#account-picker')"); |
491 JsExpect("!!document.querySelector('#pod-row')"); | 491 JsExpect("!!document.querySelector('#pod-row')"); |
492 | 492 |
493 std::string account_id = PickAccountId(profile(), kTestGaiaId, kTestEmail); | 493 std::string account_id = PickAccountId(profile(), kTestGaiaId, kTestEmail); |
494 EXPECT_EQ(GetOAuthStatusFromLocalState(account_id), | 494 EXPECT_EQ(GetOAuthStatusFromLocalState(account_id), |
495 user_manager::User::OAUTH2_TOKEN_STATUS_VALID); | 495 user_manager::User::OAUTH2_TOKEN_STATUS_VALID); |
496 | 496 |
497 EXPECT_TRUE( | 497 EXPECT_TRUE(TryToLogin(kTestGaiaId, kTestEmail, kTestAccountPassword)); |
498 TryToLogin(AccountId::FromUserEmailGaiaId(kTestEmail, kTestGaiaId), | |
499 kTestAccountPassword)); | |
500 | 498 |
501 // Wait for the session merge to finish. | 499 // Wait for the session merge to finish. |
502 WaitForMergeSessionCompletion(OAuth2LoginManager::SESSION_RESTORE_FAILED); | 500 WaitForMergeSessionCompletion(OAuth2LoginManager::SESSION_RESTORE_FAILED); |
503 | 501 |
504 EXPECT_EQ(GetOAuthStatusFromLocalState(account_id), | 502 EXPECT_EQ(GetOAuthStatusFromLocalState(account_id), |
505 user_manager::User::OAUTH2_TOKEN_STATUS_INVALID); | 503 user_manager::User::OAUTH2_TOKEN_STATUS_INVALID); |
506 } | 504 } |
507 | 505 |
508 | 506 |
509 const char kGooglePageContent[] = | 507 const char kGooglePageContent[] = |
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
806 | 804 |
807 if (!catcher.GetNextResult()) { | 805 if (!catcher.GetNextResult()) { |
808 std::string message = catcher.message(); | 806 std::string message = catcher.message(); |
809 ADD_FAILURE() << "Tests failed: " << message; | 807 ADD_FAILURE() << "Tests failed: " << message; |
810 } | 808 } |
811 | 809 |
812 EXPECT_TRUE(fake_google_.IsPageRequested()); | 810 EXPECT_TRUE(fake_google_.IsPageRequested()); |
813 } | 811 } |
814 | 812 |
815 } // namespace chromeos | 813 } // namespace chromeos |
OLD | NEW |