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

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

Issue 964563002: Replace SetAuthenticatedUsername with SetAuthenticatedAccountId. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@priv
Patch Set: rebased Created 5 years, 8 months 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/browser/account_tracker_service.h"
32 #include "components/signin/core/browser/profile_oauth2_token_service.h" 33 #include "components/signin/core/browser/profile_oauth2_token_service.h"
33 #include "components/user_manager/user.h" 34 #include "components/user_manager/user.h"
34 #include "components/user_manager/user_manager.h" 35 #include "components/user_manager/user_manager.h"
35 #include "content/public/browser/notification_service.h" 36 #include "content/public/browser/notification_service.h"
36 #include "content/public/test/browser_test_utils.h" 37 #include "content/public/test/browser_test_utils.h"
37 #include "extensions/browser/process_manager.h" 38 #include "extensions/browser/process_manager.h"
38 #include "extensions/test/extension_test_message_listener.h" 39 #include "extensions/test/extension_test_message_listener.h"
39 #include "extensions/test/result_catcher.h" 40 #include "extensions/test/result_catcher.h"
40 #include "google_apis/gaia/gaia_constants.h" 41 #include "google_apis/gaia/gaia_constants.h"
41 #include "google_apis/gaia/gaia_urls.h" 42 #include "google_apis/gaia/gaia_urls.h"
42 #include "net/cookies/canonical_cookie.h" 43 #include "net/cookies/canonical_cookie.h"
43 #include "net/cookies/cookie_monster.h" 44 #include "net/cookies/cookie_monster.h"
44 #include "net/cookies/cookie_store.h" 45 #include "net/cookies/cookie_store.h"
45 #include "net/test/embedded_test_server/http_request.h" 46 #include "net/test/embedded_test_server/http_request.h"
46 #include "net/test/embedded_test_server/http_response.h" 47 #include "net/test/embedded_test_server/http_response.h"
47 #include "net/url_request/url_request_context.h" 48 #include "net/url_request/url_request_context.h"
48 #include "net/url_request/url_request_context_getter.h" 49 #include "net/url_request/url_request_context_getter.h"
49 50
50 using app_modal::AppModalDialog; 51 using app_modal::AppModalDialog;
51 using app_modal::JavaScriptAppModalDialog; 52 using app_modal::JavaScriptAppModalDialog;
52 using net::test_server::BasicHttpResponse; 53 using net::test_server::BasicHttpResponse;
53 using net::test_server::HttpRequest; 54 using net::test_server::HttpRequest;
54 using net::test_server::HttpResponse; 55 using net::test_server::HttpResponse;
55 56
56 namespace chromeos { 57 namespace chromeos {
57 58
58 namespace { 59 namespace {
59 60
60 // Email of owner account for test. 61 // Email of owner account for test.
61 const char kTestAccountId[] = "username@gmail.com"; 62 const char kTestGaiaId[] = "12345";
62 const char kTestRawAccountId[] = "User.Name"; 63 const char kTestEmail[] = "username@gmail.com";
64 const char kTestRawEmail[] = "User.Name@gmail.com";
63 const char kTestAccountPassword[] = "fake-password"; 65 const char kTestAccountPassword[] = "fake-password";
64 const char kTestAuthCode[] = "fake-auth-code"; 66 const char kTestAuthCode[] = "fake-auth-code";
65 const char kTestGaiaUberToken[] = "fake-uber-token"; 67 const char kTestGaiaUberToken[] = "fake-uber-token";
66 const char kTestAuthLoginAccessToken[] = "fake-access-token"; 68 const char kTestAuthLoginAccessToken[] = "fake-access-token";
67 const char kTestRefreshToken[] = "fake-refresh-token"; 69 const char kTestRefreshToken[] = "fake-refresh-token";
68 const char kTestAuthSIDCookie[] = "fake-auth-SID-cookie"; 70 const char kTestAuthSIDCookie[] = "fake-auth-SID-cookie";
69 const char kTestAuthLSIDCookie[] = "fake-auth-LSID-cookie"; 71 const char kTestAuthLSIDCookie[] = "fake-auth-LSID-cookie";
70 const char kTestSessionSIDCookie[] = "fake-session-SID-cookie"; 72 const char kTestSessionSIDCookie[] = "fake-session-SID-cookie";
71 const char kTestSessionLSIDCookie[] = "fake-session-LSID-cookie"; 73 const char kTestSessionLSIDCookie[] = "fake-session-LSID-cookie";
72 const char kTestSession2SIDCookie[] = "fake-session2-SID-cookie"; 74 const char kTestSession2SIDCookie[] = "fake-session2-SID-cookie";
73 const char kTestSession2LSIDCookie[] = "fake-session2-LSID-cookie"; 75 const char kTestSession2LSIDCookie[] = "fake-session2-LSID-cookie";
74 const char kTestUserinfoToken[] = "fake-userinfo-token"; 76 const char kTestUserinfoToken[] = "fake-userinfo-token";
75 const char kTestLoginToken[] = "fake-login-token"; 77 const char kTestLoginToken[] = "fake-login-token";
76 const char kTestSyncToken[] = "fake-sync-token"; 78 const char kTestSyncToken[] = "fake-sync-token";
77 const char kTestAuthLoginToken[] = "fake-oauthlogin-token"; 79 const char kTestAuthLoginToken[] = "fake-oauthlogin-token";
78 80
81 std::string PickAccountId(Profile* profile,
82 const std::string& gaia_id,
83 const std::string& email) {
84 return AccountTrackerService::PickAccountIdForAccount(profile->GetPrefs(),
85 gaia_id, email);
86 }
87
79 class OAuth2LoginManagerStateWaiter : public OAuth2LoginManager::Observer { 88 class OAuth2LoginManagerStateWaiter : public OAuth2LoginManager::Observer {
80 public: 89 public:
81 explicit OAuth2LoginManagerStateWaiter(Profile* profile) 90 explicit OAuth2LoginManagerStateWaiter(Profile* profile)
82 : profile_(profile), 91 : profile_(profile),
83 waiting_for_state_(false), 92 waiting_for_state_(false),
84 final_state_(OAuth2LoginManager::SESSION_RESTORE_NOT_STARTED) { 93 final_state_(OAuth2LoginManager::SESSION_RESTORE_NOT_STARTED) {
85 } 94 }
86 95
87 void WaitForStates( 96 void WaitForStates(
88 const std::set<OAuth2LoginManager::SessionRestoreState>& states) { 97 const std::set<OAuth2LoginManager::SessionRestoreState>& states) {
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 params.access_token = kTestAuthLoginAccessToken; 164 params.access_token = kTestAuthLoginAccessToken;
156 params.gaia_uber_token = kTestGaiaUberToken; 165 params.gaia_uber_token = kTestGaiaUberToken;
157 params.session_sid_cookie = kTestSessionSIDCookie; 166 params.session_sid_cookie = kTestSessionSIDCookie;
158 params.session_lsid_cookie = kTestSessionLSIDCookie; 167 params.session_lsid_cookie = kTestSessionLSIDCookie;
159 fake_gaia_->SetMergeSessionParams(params); 168 fake_gaia_->SetMergeSessionParams(params);
160 SetupGaiaServerWithAccessTokens(); 169 SetupGaiaServerWithAccessTokens();
161 } 170 }
162 171
163 void SetupGaiaServerForUnexpiredAccount() { 172 void SetupGaiaServerForUnexpiredAccount() {
164 FakeGaia::MergeSessionParams params; 173 FakeGaia::MergeSessionParams params;
165 params.email = kTestAccountId; 174 params.email = kTestEmail;
166 fake_gaia_->SetMergeSessionParams(params); 175 fake_gaia_->SetMergeSessionParams(params);
167 SetupGaiaServerWithAccessTokens(); 176 SetupGaiaServerWithAccessTokens();
168 } 177 }
169 178
170 void SetupGaiaServerForExpiredAccount() { 179 void SetupGaiaServerForExpiredAccount() {
171 FakeGaia::MergeSessionParams params; 180 FakeGaia::MergeSessionParams params;
172 params.gaia_uber_token = kTestGaiaUberToken; 181 params.gaia_uber_token = kTestGaiaUberToken;
173 params.session_sid_cookie = kTestSession2SIDCookie; 182 params.session_sid_cookie = kTestSession2SIDCookie;
174 params.session_lsid_cookie = kTestSession2LSIDCookie; 183 params.session_lsid_cookie = kTestSession2LSIDCookie;
175 fake_gaia_->SetMergeSessionParams(params); 184 fake_gaia_->SetMergeSessionParams(params);
176 SetupGaiaServerWithAccessTokens(); 185 SetupGaiaServerWithAccessTokens();
177 } 186 }
178 187
179 void LoginAsExistingUser() { 188 void LoginAsExistingUser() {
180 content::WindowedNotificationObserver( 189 content::WindowedNotificationObserver(
181 chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE, 190 chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE,
182 content::NotificationService::AllSources()).Wait(); 191 content::NotificationService::AllSources()).Wait();
183 192
184 JsExpect("!!document.querySelector('#account-picker')"); 193 JsExpect("!!document.querySelector('#account-picker')");
185 JsExpect("!!document.querySelector('#pod-row')"); 194 JsExpect("!!document.querySelector('#pod-row')");
186 195
187 EXPECT_EQ(GetOAuthStatusFromLocalState(kTestAccountId), 196 std::string account_id = PickAccountId(
197 ProfileManager::GetPrimaryUserProfile(), kTestGaiaId, kTestEmail);
198
199 EXPECT_EQ(GetOAuthStatusFromLocalState(account_id),
188 user_manager::User::OAUTH2_TOKEN_STATUS_VALID); 200 user_manager::User::OAUTH2_TOKEN_STATUS_VALID);
189 201
190 EXPECT_TRUE(TryToLogin(kTestAccountId, kTestAccountPassword)); 202 // Try login. Primary profile has changed.
203 EXPECT_TRUE(TryToLogin(kTestGaiaId, kTestEmail, kTestAccountPassword));
191 Profile* profile = ProfileManager::GetPrimaryUserProfile(); 204 Profile* profile = ProfileManager::GetPrimaryUserProfile();
192 205
193 // Wait for the session merge to finish. 206 // Wait for the session merge to finish.
194 WaitForMergeSessionCompletion(OAuth2LoginManager::SESSION_RESTORE_DONE); 207 WaitForMergeSessionCompletion(OAuth2LoginManager::SESSION_RESTORE_DONE);
195 208
196 // Check for existance of refresh token. 209 // Check for existance of refresh token.
197 ProfileOAuth2TokenService* token_service = 210 ProfileOAuth2TokenService* token_service =
198 ProfileOAuth2TokenServiceFactory::GetForProfile(profile); 211 ProfileOAuth2TokenServiceFactory::GetForProfile(profile);
199 EXPECT_TRUE(token_service->RefreshTokenIsAvailable(kTestAccountId)); 212 EXPECT_TRUE(token_service->RefreshTokenIsAvailable(account_id));
200 213
201 EXPECT_EQ(GetOAuthStatusFromLocalState(kTestAccountId), 214 EXPECT_EQ(GetOAuthStatusFromLocalState(account_id),
202 user_manager::User::OAUTH2_TOKEN_STATUS_VALID); 215 user_manager::User::OAUTH2_TOKEN_STATUS_VALID);
203 } 216 }
204 217
205 bool TryToLogin(const std::string& username, 218 bool TryToLogin(const std::string& gaia_id,
219 const std::string& username,
206 const std::string& password) { 220 const std::string& password) {
207 if (!AddUserToSession(username, password)) 221 if (!AddUserToSession(gaia_id, username, password))
208 return false; 222 return false;
209 223
210 if (const user_manager::User* active_user = 224 if (const user_manager::User* active_user =
211 user_manager::UserManager::Get()->GetActiveUser()) { 225 user_manager::UserManager::Get()->GetActiveUser()) {
212 return active_user->email() == username; 226 return active_user->email() == username;
213 } 227 }
214 228
215 return false; 229 return false;
216 } 230 }
217 231
218 user_manager::User::OAuthTokenStatus GetOAuthStatusFromLocalState( 232 user_manager::User::OAuthTokenStatus GetOAuthStatusFromLocalState(
219 const std::string& user_id) const { 233 const std::string& account_id) const {
220 PrefService* local_state = g_browser_process->local_state(); 234 PrefService* local_state = g_browser_process->local_state();
221 const base::DictionaryValue* prefs_oauth_status = 235 const base::DictionaryValue* prefs_oauth_status =
222 local_state->GetDictionary("OAuthTokenStatus"); 236 local_state->GetDictionary("OAuthTokenStatus");
223 int oauth_token_status = user_manager::User::OAUTH_TOKEN_STATUS_UNKNOWN; 237 int oauth_token_status = user_manager::User::OAUTH_TOKEN_STATUS_UNKNOWN;
224 if (prefs_oauth_status && 238 if (prefs_oauth_status &&
225 prefs_oauth_status->GetIntegerWithoutPathExpansion( 239 prefs_oauth_status->GetIntegerWithoutPathExpansion(
226 user_id, &oauth_token_status)) { 240 account_id, &oauth_token_status)) {
227 user_manager::User::OAuthTokenStatus result = 241 user_manager::User::OAuthTokenStatus result =
228 static_cast<user_manager::User::OAuthTokenStatus>(oauth_token_status); 242 static_cast<user_manager::User::OAuthTokenStatus>(oauth_token_status);
229 return result; 243 return result;
230 } 244 }
231 return user_manager::User::OAUTH_TOKEN_STATUS_UNKNOWN; 245 return user_manager::User::OAUTH_TOKEN_STATUS_UNKNOWN;
232 } 246 }
233 247
234 protected: 248 protected:
235 // OobeBaseTest overrides. 249 // OobeBaseTest overrides.
236 Profile* profile() override { 250 Profile* profile() override {
237 if (user_manager::UserManager::Get()->GetActiveUser()) 251 if (user_manager::UserManager::Get()->GetActiveUser())
238 return ProfileManager::GetPrimaryUserProfile(); 252 return ProfileManager::GetPrimaryUserProfile();
239 253
240 return OobeBaseTest::profile(); 254 return OobeBaseTest::profile();
241 } 255 }
242 256
243 bool AddUserToSession(const std::string& username, 257 bool AddUserToSession(const std::string& gaia_id,
258 const std::string& username,
244 const std::string& password) { 259 const std::string& password) {
245 ExistingUserController* controller = 260 ExistingUserController* controller =
246 ExistingUserController::current_controller(); 261 ExistingUserController::current_controller();
247 if (!controller) { 262 if (!controller) {
248 ADD_FAILURE(); 263 ADD_FAILURE();
249 return false; 264 return false;
250 } 265 }
251 266
252 UserContext user_context(username); 267 UserContext user_context(username);
268 user_context.SetGaiaID(gaia_id);
253 user_context.SetKey(Key(password)); 269 user_context.SetKey(Key(password));
254 controller->Login(user_context, SigninSpecifics()); 270 controller->Login(user_context, SigninSpecifics());
255 content::WindowedNotificationObserver( 271 content::WindowedNotificationObserver(
256 chrome::NOTIFICATION_SESSION_STARTED, 272 chrome::NOTIFICATION_SESSION_STARTED,
257 content::NotificationService::AllSources()).Wait(); 273 content::NotificationService::AllSources()).Wait();
258 const user_manager::UserList& logged_users = 274 const user_manager::UserList& logged_users =
259 user_manager::UserManager::Get()->GetLoggedInUsers(); 275 user_manager::UserManager::Get()->GetLoggedInUsers();
260 for (user_manager::UserList::const_iterator it = logged_users.begin(); 276 for (user_manager::UserList::const_iterator it = logged_users.begin();
261 it != logged_users.end(); 277 it != logged_users.end();
262 ++it) { 278 ++it) {
263 if ((*it)->email() == username) 279 if ((*it)->email() == username)
264 return true; 280 return true;
265 } 281 }
266 return false; 282 return false;
267 } 283 }
268 284
269 void SetupGaiaServerWithAccessTokens() { 285 void SetupGaiaServerWithAccessTokens() {
286 fake_gaia_->MapEmailToGaiaId(kTestEmail, kTestGaiaId);
287
270 // Configure OAuth authentication. 288 // Configure OAuth authentication.
271 GaiaUrls* gaia_urls = GaiaUrls::GetInstance(); 289 GaiaUrls* gaia_urls = GaiaUrls::GetInstance();
272 290
273 // This token satisfies the userinfo.email request from 291 // This token satisfies the userinfo.email request from
274 // DeviceOAuth2TokenService used in token validation. 292 // DeviceOAuth2TokenService used in token validation.
275 FakeGaia::AccessTokenInfo userinfo_token_info; 293 FakeGaia::AccessTokenInfo userinfo_token_info;
276 userinfo_token_info.token = kTestUserinfoToken; 294 userinfo_token_info.token = kTestUserinfoToken;
277 userinfo_token_info.scopes.insert( 295 userinfo_token_info.scopes.insert(
278 "https://www.googleapis.com/auth/userinfo.email"); 296 "https://www.googleapis.com/auth/userinfo.email");
279 userinfo_token_info.audience = gaia_urls->oauth2_chrome_client_id(); 297 userinfo_token_info.audience = gaia_urls->oauth2_chrome_client_id();
280 userinfo_token_info.email = kTestAccountId; 298 userinfo_token_info.email = kTestEmail;
281 fake_gaia_->IssueOAuthToken(kTestRefreshToken, userinfo_token_info); 299 fake_gaia_->IssueOAuthToken(kTestRefreshToken, userinfo_token_info);
282 300
283 FakeGaia::AccessTokenInfo userinfo_profile_token_info; 301 FakeGaia::AccessTokenInfo userinfo_profile_token_info;
284 userinfo_profile_token_info.token = kTestUserinfoToken; 302 userinfo_profile_token_info.token = kTestUserinfoToken;
285 userinfo_profile_token_info.scopes.insert( 303 userinfo_profile_token_info.scopes.insert(
286 "https://www.googleapis.com/auth/userinfo.profile"); 304 "https://www.googleapis.com/auth/userinfo.profile");
287 userinfo_profile_token_info.audience = gaia_urls->oauth2_chrome_client_id(); 305 userinfo_profile_token_info.audience = gaia_urls->oauth2_chrome_client_id();
288 userinfo_profile_token_info.email = kTestAccountId; 306 userinfo_profile_token_info.email = kTestEmail;
289 fake_gaia_->IssueOAuthToken(kTestRefreshToken, userinfo_profile_token_info); 307 fake_gaia_->IssueOAuthToken(kTestRefreshToken, userinfo_profile_token_info);
290 308
291 // The any-api access token for accessing the token minting endpoint. 309 // The any-api access token for accessing the token minting endpoint.
292 FakeGaia::AccessTokenInfo login_token_info; 310 FakeGaia::AccessTokenInfo login_token_info;
293 login_token_info.token = kTestLoginToken; 311 login_token_info.token = kTestLoginToken;
294 login_token_info.scopes.insert(GaiaConstants::kAnyApiOAuth2Scope); 312 login_token_info.scopes.insert(GaiaConstants::kAnyApiOAuth2Scope);
295 login_token_info.audience = gaia_urls->oauth2_chrome_client_id(); 313 login_token_info.audience = gaia_urls->oauth2_chrome_client_id();
296 fake_gaia_->IssueOAuthToken(kTestRefreshToken, login_token_info); 314 fake_gaia_->IssueOAuthToken(kTestRefreshToken, login_token_info);
297 315
298 // The /auth/chromesync access token for accessing sync endpoint. 316 // The /auth/chromesync access token for accessing sync endpoint.
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 SetupGaiaServerForNewAccount(); 350 SetupGaiaServerForNewAccount();
333 SimulateNetworkOnline(); 351 SimulateNetworkOnline();
334 WaitForGaiaPageLoad(); 352 WaitForGaiaPageLoad();
335 353
336 content::WindowedNotificationObserver session_start_waiter( 354 content::WindowedNotificationObserver session_start_waiter(
337 chrome::NOTIFICATION_SESSION_STARTED, 355 chrome::NOTIFICATION_SESSION_STARTED,
338 content::NotificationService::AllSources()); 356 content::NotificationService::AllSources());
339 357
340 // Use capitalized and dotted user name on purpose to make sure 358 // Use capitalized and dotted user name on purpose to make sure
341 // our email normalization kicks in. 359 // our email normalization kicks in.
342 GetLoginDisplay()->ShowSigninScreenForCreds(kTestRawAccountId, 360 GetLoginDisplay()->ShowSigninScreenForCreds(kTestRawEmail,
343 kTestAccountPassword); 361 kTestAccountPassword);
344 session_start_waiter.Wait(); 362 session_start_waiter.Wait();
345 363
346 if (wait_for_merge) { 364 if (wait_for_merge) {
347 // Wait for the session merge to finish. 365 // Wait for the session merge to finish.
348 WaitForMergeSessionCompletion(OAuth2LoginManager::SESSION_RESTORE_DONE); 366 WaitForMergeSessionCompletion(OAuth2LoginManager::SESSION_RESTORE_DONE);
349 } 367 }
350 } 368 }
351 369
352 DISALLOW_COPY_AND_ASSIGN(OAuth2Test); 370 DISALLOW_COPY_AND_ASSIGN(OAuth2Test);
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
408 net::CookieList cookie_list_; 426 net::CookieList cookie_list_;
409 scoped_refptr<content::MessageLoopRunner> runner_; 427 scoped_refptr<content::MessageLoopRunner> runner_;
410 428
411 DISALLOW_COPY_AND_ASSIGN(CookieReader); 429 DISALLOW_COPY_AND_ASSIGN(CookieReader);
412 }; 430 };
413 431
414 // PRE_MergeSession is testing merge session for a new profile. 432 // PRE_MergeSession is testing merge session for a new profile.
415 IN_PROC_BROWSER_TEST_P(OAuth2Test, PRE_PRE_PRE_MergeSession) { 433 IN_PROC_BROWSER_TEST_P(OAuth2Test, PRE_PRE_PRE_MergeSession) {
416 StartNewUserSession(true); 434 StartNewUserSession(true);
417 // Check for existance of refresh token. 435 // Check for existance of refresh token.
436 std::string account_id = PickAccountId(profile(), kTestGaiaId, kTestEmail);
418 ProfileOAuth2TokenService* token_service = 437 ProfileOAuth2TokenService* token_service =
419 ProfileOAuth2TokenServiceFactory::GetForProfile( 438 ProfileOAuth2TokenServiceFactory::GetForProfile(
420 profile()); 439 profile());
421 EXPECT_TRUE(token_service->RefreshTokenIsAvailable(kTestAccountId)); 440 EXPECT_TRUE(token_service->RefreshTokenIsAvailable(account_id));
422 441
423 EXPECT_EQ(GetOAuthStatusFromLocalState(kTestAccountId), 442 EXPECT_EQ(GetOAuthStatusFromLocalState(account_id),
424 user_manager::User::OAUTH2_TOKEN_STATUS_VALID); 443 user_manager::User::OAUTH2_TOKEN_STATUS_VALID);
425 scoped_refptr<CookieReader> cookie_reader(new CookieReader()); 444 scoped_refptr<CookieReader> cookie_reader(new CookieReader());
426 cookie_reader->ReadCookies(profile()); 445 cookie_reader->ReadCookies(profile());
427 EXPECT_EQ(cookie_reader->GetCookieValue("SID"), kTestSessionSIDCookie); 446 EXPECT_EQ(cookie_reader->GetCookieValue("SID"), kTestSessionSIDCookie);
428 EXPECT_EQ(cookie_reader->GetCookieValue("LSID"), kTestSessionLSIDCookie); 447 EXPECT_EQ(cookie_reader->GetCookieValue("LSID"), kTestSessionLSIDCookie);
429 } 448 }
430 449
431 // MergeSession test is running merge session process for an existing profile 450 // MergeSession test is running merge session process for an existing profile
432 // that was generated in PRE_PRE_PRE_MergeSession test. In this test, we 451 // that was generated in PRE_PRE_PRE_MergeSession test. In this test, we
433 // are not running /MergeSession process since the /ListAccounts call confirms 452 // are not running /MergeSession process since the /ListAccounts call confirms
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
465 IN_PROC_BROWSER_TEST_P(OAuth2Test, MergeSession) { 484 IN_PROC_BROWSER_TEST_P(OAuth2Test, MergeSession) {
466 SimulateNetworkOnline(); 485 SimulateNetworkOnline();
467 486
468 content::WindowedNotificationObserver( 487 content::WindowedNotificationObserver(
469 chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE, 488 chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE,
470 content::NotificationService::AllSources()).Wait(); 489 content::NotificationService::AllSources()).Wait();
471 490
472 JsExpect("!!document.querySelector('#account-picker')"); 491 JsExpect("!!document.querySelector('#account-picker')");
473 JsExpect("!!document.querySelector('#pod-row')"); 492 JsExpect("!!document.querySelector('#pod-row')");
474 493
475 EXPECT_EQ(GetOAuthStatusFromLocalState(kTestAccountId), 494 std::string account_id = PickAccountId(profile(), kTestGaiaId, kTestEmail);
495 EXPECT_EQ(GetOAuthStatusFromLocalState(account_id),
476 user_manager::User::OAUTH2_TOKEN_STATUS_VALID); 496 user_manager::User::OAUTH2_TOKEN_STATUS_VALID);
477 497
478 EXPECT_TRUE(TryToLogin(kTestAccountId, kTestAccountPassword)); 498 EXPECT_TRUE(TryToLogin(kTestGaiaId, kTestEmail, kTestAccountPassword));
479 499
480 // Wait for the session merge to finish. 500 // Wait for the session merge to finish.
481 WaitForMergeSessionCompletion(OAuth2LoginManager::SESSION_RESTORE_FAILED); 501 WaitForMergeSessionCompletion(OAuth2LoginManager::SESSION_RESTORE_FAILED);
482 502
483 EXPECT_EQ(GetOAuthStatusFromLocalState(kTestAccountId), 503 EXPECT_EQ(GetOAuthStatusFromLocalState(account_id),
484 user_manager::User::OAUTH2_TOKEN_STATUS_INVALID); 504 user_manager::User::OAUTH2_TOKEN_STATUS_INVALID);
485 } 505 }
486 506
487 507
488 const char kGooglePageContent[] = 508 const char kGooglePageContent[] =
489 "<html><title>Hello!</title><script>alert('hello');</script>" 509 "<html><title>Hello!</title><script>alert('hello');</script>"
490 "<body>Hello Google!</body></html>"; 510 "<body>Hello Google!</body></html>";
491 const char kRandomPageContent[] = 511 const char kRandomPageContent[] =
492 "<html><title>SomthingElse</title><body>I am SomethingElse</body></html>"; 512 "<html><title>SomthingElse</title><body>I am SomethingElse</body></html>";
493 const char kHelloPagePath[] = "/hello_google"; 513 const char kHelloPagePath[] = "/hello_google";
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
788 ADD_FAILURE() << "Tests failed: " << message; 808 ADD_FAILURE() << "Tests failed: " << message;
789 } 809 }
790 810
791 EXPECT_TRUE(fake_google_.IsPageRequested()); 811 EXPECT_TRUE(fake_google_.IsPageRequested());
792 } 812 }
793 813
794 INSTANTIATE_TEST_CASE_P(OAuth2Suite, OAuth2Test, testing::Bool()); 814 INSTANTIATE_TEST_CASE_P(OAuth2Suite, OAuth2Test, testing::Bool());
795 INSTANTIATE_TEST_CASE_P(MergeSessionSuite, MergeSessionTest, testing::Bool()); 815 INSTANTIATE_TEST_CASE_P(MergeSessionSuite, MergeSessionTest, testing::Bool());
796 816
797 } // namespace chromeos 817 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698