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