Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(433)

Side by Side Diff: chrome/browser/chromeos/login/signin/oauth2_browsertest.cc

Issue 1412813003: This CL replaces user_manager::UserID with AccountId. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@468875--Chrome-OS-handles-deletion-of-Gmail-account-poorly--Create-AccountID-structure-part2--user_names
Patch Set: Fix Win GN build. Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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"
32 #include "components/signin/core/browser/account_tracker_service.h" 33 #include "components/signin/core/browser/account_tracker_service.h"
33 #include "components/signin/core/browser/profile_oauth2_token_service.h" 34 #include "components/signin/core/browser/profile_oauth2_token_service.h"
34 #include "components/user_manager/user.h" 35 #include "components/user_manager/user.h"
35 #include "components/user_manager/user_manager.h" 36 #include "components/user_manager/user_manager.h"
36 #include "content/public/browser/notification_service.h" 37 #include "content/public/browser/notification_service.h"
37 #include "content/public/test/browser_test_utils.h" 38 #include "content/public/test/browser_test_utils.h"
38 #include "extensions/browser/process_manager.h" 39 #include "extensions/browser/process_manager.h"
39 #include "extensions/test/extension_test_message_listener.h" 40 #include "extensions/test/extension_test_message_listener.h"
40 #include "extensions/test/result_catcher.h" 41 #include "extensions/test/result_catcher.h"
41 #include "google_apis/gaia/gaia_constants.h" 42 #include "google_apis/gaia/gaia_constants.h"
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 JsExpect("!!document.querySelector('#account-picker')"); 191 JsExpect("!!document.querySelector('#account-picker')");
191 JsExpect("!!document.querySelector('#pod-row')"); 192 JsExpect("!!document.querySelector('#pod-row')");
192 193
193 std::string account_id = PickAccountId( 194 std::string account_id = PickAccountId(
194 ProfileManager::GetPrimaryUserProfile(), kTestGaiaId, kTestEmail); 195 ProfileManager::GetPrimaryUserProfile(), kTestGaiaId, kTestEmail);
195 196
196 EXPECT_EQ(GetOAuthStatusFromLocalState(account_id), 197 EXPECT_EQ(GetOAuthStatusFromLocalState(account_id),
197 user_manager::User::OAUTH2_TOKEN_STATUS_VALID); 198 user_manager::User::OAUTH2_TOKEN_STATUS_VALID);
198 199
199 // Try login. Primary profile has changed. 200 // Try login. Primary profile has changed.
200 EXPECT_TRUE(TryToLogin(kTestGaiaId, kTestEmail, kTestAccountPassword)); 201 EXPECT_TRUE(
202 TryToLogin(AccountId::FromUserEmailGaiaId(kTestEmail, kTestGaiaId),
203 kTestAccountPassword));
201 Profile* profile = ProfileManager::GetPrimaryUserProfile(); 204 Profile* profile = ProfileManager::GetPrimaryUserProfile();
202 205
203 // Wait for the session merge to finish. 206 // Wait for the session merge to finish.
204 WaitForMergeSessionCompletion(OAuth2LoginManager::SESSION_RESTORE_DONE); 207 WaitForMergeSessionCompletion(OAuth2LoginManager::SESSION_RESTORE_DONE);
205 208
206 // Check for existance of refresh token. 209 // Check for existance of refresh token.
207 ProfileOAuth2TokenService* token_service = 210 ProfileOAuth2TokenService* token_service =
208 ProfileOAuth2TokenServiceFactory::GetForProfile(profile); 211 ProfileOAuth2TokenServiceFactory::GetForProfile(profile);
209 EXPECT_TRUE(token_service->RefreshTokenIsAvailable(account_id)); 212 EXPECT_TRUE(token_service->RefreshTokenIsAvailable(account_id));
210 213
211 EXPECT_EQ(GetOAuthStatusFromLocalState(account_id), 214 EXPECT_EQ(GetOAuthStatusFromLocalState(account_id),
212 user_manager::User::OAUTH2_TOKEN_STATUS_VALID); 215 user_manager::User::OAUTH2_TOKEN_STATUS_VALID);
213 } 216 }
214 217
215 bool TryToLogin(const std::string& gaia_id, 218 bool TryToLogin(const AccountId& account_id, const std::string& password) {
216 const std::string& username, 219 if (!AddUserToSession(account_id, password))
217 const std::string& password) {
218 if (!AddUserToSession(gaia_id, username, password))
219 return false; 220 return false;
220 221
221 if (const user_manager::User* active_user = 222 if (const user_manager::User* active_user =
222 user_manager::UserManager::Get()->GetActiveUser()) { 223 user_manager::UserManager::Get()->GetActiveUser()) {
223 return active_user->email() == username; 224 return active_user->GetAccountId() == account_id;
224 } 225 }
225 226
226 return false; 227 return false;
227 } 228 }
228 229
229 user_manager::User::OAuthTokenStatus GetOAuthStatusFromLocalState( 230 user_manager::User::OAuthTokenStatus GetOAuthStatusFromLocalState(
230 const std::string& account_id) const { 231 const std::string& account_id) const {
231 PrefService* local_state = g_browser_process->local_state(); 232 PrefService* local_state = g_browser_process->local_state();
232 const base::DictionaryValue* prefs_oauth_status = 233 const base::DictionaryValue* prefs_oauth_status =
233 local_state->GetDictionary("OAuthTokenStatus"); 234 local_state->GetDictionary("OAuthTokenStatus");
(...skipping 10 matching lines...) Expand all
244 245
245 protected: 246 protected:
246 // OobeBaseTest overrides. 247 // OobeBaseTest overrides.
247 Profile* profile() override { 248 Profile* profile() override {
248 if (user_manager::UserManager::Get()->GetActiveUser()) 249 if (user_manager::UserManager::Get()->GetActiveUser())
249 return ProfileManager::GetPrimaryUserProfile(); 250 return ProfileManager::GetPrimaryUserProfile();
250 251
251 return OobeBaseTest::profile(); 252 return OobeBaseTest::profile();
252 } 253 }
253 254
254 bool AddUserToSession(const std::string& gaia_id, 255 bool AddUserToSession(const AccountId& account_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(username); 264 UserContext user_context(account_id);
265 user_context.SetGaiaID(gaia_id); 265 user_context.SetGaiaID(account_id.GetGaiaId());
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)->email() == username) 276 if ((*it)->GetAccountId() == account_id)
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
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(TryToLogin(kTestGaiaId, kTestEmail, kTestAccountPassword)); 497 EXPECT_TRUE(
498 TryToLogin(AccountId::FromUserEmailGaiaId(kTestEmail, kTestGaiaId),
499 kTestAccountPassword));
498 500
499 // Wait for the session merge to finish. 501 // Wait for the session merge to finish.
500 WaitForMergeSessionCompletion(OAuth2LoginManager::SESSION_RESTORE_FAILED); 502 WaitForMergeSessionCompletion(OAuth2LoginManager::SESSION_RESTORE_FAILED);
501 503
502 EXPECT_EQ(GetOAuthStatusFromLocalState(account_id), 504 EXPECT_EQ(GetOAuthStatusFromLocalState(account_id),
503 user_manager::User::OAUTH2_TOKEN_STATUS_INVALID); 505 user_manager::User::OAUTH2_TOKEN_STATUS_INVALID);
504 } 506 }
505 507
506 508
507 const char kGooglePageContent[] = 509 const char kGooglePageContent[] =
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after
804 806
805 if (!catcher.GetNextResult()) { 807 if (!catcher.GetNextResult()) {
806 std::string message = catcher.message(); 808 std::string message = catcher.message();
807 ADD_FAILURE() << "Tests failed: " << message; 809 ADD_FAILURE() << "Tests failed: " << message;
808 } 810 }
809 811
810 EXPECT_TRUE(fake_google_.IsPageRequested()); 812 EXPECT_TRUE(fake_google_.IsPageRequested());
811 } 813 }
812 814
813 } // namespace chromeos 815 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698