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" |
11 #include "chrome/browser/browser_process.h" | 11 #include "chrome/browser/browser_process.h" |
12 #include "chrome/browser/chrome_notification_types.h" | 12 #include "chrome/browser/chrome_notification_types.h" |
13 #include "chrome/browser/chromeos/login/signin/oauth2_login_manager.h" | 13 #include "chrome/browser/chromeos/login/signin/oauth2_login_manager.h" |
14 #include "chrome/browser/chromeos/login/signin/oauth2_login_manager_factory.h" | 14 #include "chrome/browser/chromeos/login/signin/oauth2_login_manager_factory.h" |
15 #include "chrome/browser/chromeos/login/signin_specifics.h" | 15 #include "chrome/browser/chromeos/login/signin_specifics.h" |
16 #include "chrome/browser/chromeos/login/test/oobe_base_test.h" | 16 #include "chrome/browser/chromeos/login/test/oobe_base_test.h" |
17 #include "chrome/browser/chromeos/login/users/user.h" | |
18 #include "chrome/browser/chromeos/login/users/user_manager.h" | 17 #include "chrome/browser/chromeos/login/users/user_manager.h" |
19 #include "chrome/browser/chromeos/login/wizard_controller.h" | 18 #include "chrome/browser/chromeos/login/wizard_controller.h" |
20 #include "chrome/browser/extensions/extension_test_message_listener.h" | 19 #include "chrome/browser/extensions/extension_test_message_listener.h" |
21 #include "chrome/browser/profiles/profile_manager.h" | 20 #include "chrome/browser/profiles/profile_manager.h" |
22 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | 21 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
23 #include "chrome/browser/ui/app_modal_dialogs/javascript_app_modal_dialog.h" | 22 #include "chrome/browser/ui/app_modal_dialogs/javascript_app_modal_dialog.h" |
24 #include "chrome/browser/ui/app_modal_dialogs/native_app_modal_dialog.h" | 23 #include "chrome/browser/ui/app_modal_dialogs/native_app_modal_dialog.h" |
25 #include "chrome/browser/ui/browser.h" | 24 #include "chrome/browser/ui/browser.h" |
26 #include "chrome/browser/ui/browser_tabstrip.h" | 25 #include "chrome/browser/ui/browser_tabstrip.h" |
27 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h" | 26 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h" |
28 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 27 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
29 #include "chrome/browser/ui/webui/chromeos/login/signin_screen_handler.h" | 28 #include "chrome/browser/ui/webui/chromeos/login/signin_screen_handler.h" |
30 #include "chrome/test/base/ui_test_utils.h" | 29 #include "chrome/test/base/ui_test_utils.h" |
31 #include "chromeos/login/auth/key.h" | 30 #include "chromeos/login/auth/key.h" |
32 #include "chromeos/login/auth/user_context.h" | 31 #include "chromeos/login/auth/user_context.h" |
33 #include "components/signin/core/browser/profile_oauth2_token_service.h" | 32 #include "components/signin/core/browser/profile_oauth2_token_service.h" |
| 33 #include "components/user_manager/user.h" |
34 #include "content/public/browser/notification_service.h" | 34 #include "content/public/browser/notification_service.h" |
35 #include "content/public/test/browser_test_utils.h" | 35 #include "content/public/test/browser_test_utils.h" |
36 #include "extensions/browser/process_manager.h" | 36 #include "extensions/browser/process_manager.h" |
37 #include "google_apis/gaia/gaia_constants.h" | 37 #include "google_apis/gaia/gaia_constants.h" |
38 #include "google_apis/gaia/gaia_urls.h" | 38 #include "google_apis/gaia/gaia_urls.h" |
39 #include "net/cookies/canonical_cookie.h" | 39 #include "net/cookies/canonical_cookie.h" |
40 #include "net/cookies/cookie_monster.h" | 40 #include "net/cookies/cookie_monster.h" |
41 #include "net/cookies/cookie_store.h" | 41 #include "net/cookies/cookie_store.h" |
42 #include "net/test/embedded_test_server/http_request.h" | 42 #include "net/test/embedded_test_server/http_request.h" |
43 #include "net/test/embedded_test_server/http_response.h" | 43 #include "net/test/embedded_test_server/http_response.h" |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 | 162 |
163 void LoginAsExistingUser() { | 163 void LoginAsExistingUser() { |
164 content::WindowedNotificationObserver( | 164 content::WindowedNotificationObserver( |
165 chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE, | 165 chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE, |
166 content::NotificationService::AllSources()).Wait(); | 166 content::NotificationService::AllSources()).Wait(); |
167 | 167 |
168 JsExpect("!!document.querySelector('#account-picker')"); | 168 JsExpect("!!document.querySelector('#account-picker')"); |
169 JsExpect("!!document.querySelector('#pod-row')"); | 169 JsExpect("!!document.querySelector('#pod-row')"); |
170 | 170 |
171 EXPECT_EQ(GetOAuthStatusFromLocalState(kTestAccountId), | 171 EXPECT_EQ(GetOAuthStatusFromLocalState(kTestAccountId), |
172 User::OAUTH2_TOKEN_STATUS_VALID); | 172 user_manager::User::OAUTH2_TOKEN_STATUS_VALID); |
173 | 173 |
174 EXPECT_TRUE(TryToLogin(kTestAccountId, kTestAccountPassword)); | 174 EXPECT_TRUE(TryToLogin(kTestAccountId, kTestAccountPassword)); |
175 Profile* profile = ProfileManager::GetPrimaryUserProfile(); | 175 Profile* profile = ProfileManager::GetPrimaryUserProfile(); |
176 | 176 |
177 // Wait for the session merge to finish. | 177 // Wait for the session merge to finish. |
178 WaitForMergeSessionCompletion(OAuth2LoginManager::SESSION_RESTORE_DONE); | 178 WaitForMergeSessionCompletion(OAuth2LoginManager::SESSION_RESTORE_DONE); |
179 | 179 |
180 // Check for existance of refresh token. | 180 // Check for existance of refresh token. |
181 ProfileOAuth2TokenService* token_service = | 181 ProfileOAuth2TokenService* token_service = |
182 ProfileOAuth2TokenServiceFactory::GetForProfile(profile); | 182 ProfileOAuth2TokenServiceFactory::GetForProfile(profile); |
183 EXPECT_TRUE(token_service->RefreshTokenIsAvailable(kTestAccountId)); | 183 EXPECT_TRUE(token_service->RefreshTokenIsAvailable(kTestAccountId)); |
184 | 184 |
185 EXPECT_EQ(GetOAuthStatusFromLocalState(kTestAccountId), | 185 EXPECT_EQ(GetOAuthStatusFromLocalState(kTestAccountId), |
186 User::OAUTH2_TOKEN_STATUS_VALID); | 186 user_manager::User::OAUTH2_TOKEN_STATUS_VALID); |
187 } | 187 } |
188 | 188 |
189 bool TryToLogin(const std::string& username, | 189 bool TryToLogin(const std::string& username, |
190 const std::string& password) { | 190 const std::string& password) { |
191 if (!AddUserToSession(username, password)) | 191 if (!AddUserToSession(username, password)) |
192 return false; | 192 return false; |
193 | 193 |
194 if (const User* active_user = UserManager::Get()->GetActiveUser()) | 194 if (const user_manager::User* active_user = |
| 195 UserManager::Get()->GetActiveUser()) |
195 return active_user->email() == username; | 196 return active_user->email() == username; |
196 | 197 |
197 return false; | 198 return false; |
198 } | 199 } |
199 | 200 |
200 User::OAuthTokenStatus GetOAuthStatusFromLocalState( | 201 user_manager::User::OAuthTokenStatus GetOAuthStatusFromLocalState( |
201 const std::string& user_id) const { | 202 const std::string& user_id) const { |
202 PrefService* local_state = g_browser_process->local_state(); | 203 PrefService* local_state = g_browser_process->local_state(); |
203 const base::DictionaryValue* prefs_oauth_status = | 204 const base::DictionaryValue* prefs_oauth_status = |
204 local_state->GetDictionary("OAuthTokenStatus"); | 205 local_state->GetDictionary("OAuthTokenStatus"); |
205 int oauth_token_status = User::OAUTH_TOKEN_STATUS_UNKNOWN; | 206 int oauth_token_status = user_manager::User::OAUTH_TOKEN_STATUS_UNKNOWN; |
206 if (prefs_oauth_status && | 207 if (prefs_oauth_status && |
207 prefs_oauth_status->GetIntegerWithoutPathExpansion( | 208 prefs_oauth_status->GetIntegerWithoutPathExpansion( |
208 user_id, &oauth_token_status)) { | 209 user_id, &oauth_token_status)) { |
209 User::OAuthTokenStatus result = | 210 user_manager::User::OAuthTokenStatus result = |
210 static_cast<User::OAuthTokenStatus>(oauth_token_status); | 211 static_cast<user_manager::User::OAuthTokenStatus>(oauth_token_status); |
211 return result; | 212 return result; |
212 } | 213 } |
213 return User::OAUTH_TOKEN_STATUS_UNKNOWN; | 214 return user_manager::User::OAUTH_TOKEN_STATUS_UNKNOWN; |
214 } | 215 } |
215 | 216 |
216 protected: | 217 protected: |
217 // OobeBaseTest overrides. | 218 // OobeBaseTest overrides. |
218 virtual Profile* profile() OVERRIDE { | 219 virtual Profile* profile() OVERRIDE { |
219 if (UserManager::Get()->GetActiveUser()) | 220 if (UserManager::Get()->GetActiveUser()) |
220 return ProfileManager::GetPrimaryUserProfile(); | 221 return ProfileManager::GetPrimaryUserProfile(); |
221 | 222 |
222 return OobeBaseTest::profile(); | 223 return OobeBaseTest::profile(); |
223 } | 224 } |
224 | 225 |
225 bool AddUserToSession(const std::string& username, | 226 bool AddUserToSession(const std::string& username, |
226 const std::string& password) { | 227 const std::string& password) { |
227 ExistingUserController* controller = | 228 ExistingUserController* controller = |
228 ExistingUserController::current_controller(); | 229 ExistingUserController::current_controller(); |
229 if (!controller) { | 230 if (!controller) { |
230 ADD_FAILURE(); | 231 ADD_FAILURE(); |
231 return false; | 232 return false; |
232 } | 233 } |
233 | 234 |
234 UserContext user_context(username); | 235 UserContext user_context(username); |
235 user_context.SetKey(Key(password)); | 236 user_context.SetKey(Key(password)); |
236 controller->Login(user_context, SigninSpecifics()); | 237 controller->Login(user_context, SigninSpecifics()); |
237 content::WindowedNotificationObserver( | 238 content::WindowedNotificationObserver( |
238 chrome::NOTIFICATION_SESSION_STARTED, | 239 chrome::NOTIFICATION_SESSION_STARTED, |
239 content::NotificationService::AllSources()).Wait(); | 240 content::NotificationService::AllSources()).Wait(); |
240 const UserList& logged_users = UserManager::Get()->GetLoggedInUsers(); | 241 const user_manager::UserList& logged_users = |
241 for (UserList::const_iterator it = logged_users.begin(); | 242 UserManager::Get()->GetLoggedInUsers(); |
242 it != logged_users.end(); ++it) { | 243 for (user_manager::UserList::const_iterator it = logged_users.begin(); |
| 244 it != logged_users.end(); |
| 245 ++it) { |
243 if ((*it)->email() == username) | 246 if ((*it)->email() == username) |
244 return true; | 247 return true; |
245 } | 248 } |
246 return false; | 249 return false; |
247 } | 250 } |
248 | 251 |
249 void SetupGaiaServerWithAccessTokens() { | 252 void SetupGaiaServerWithAccessTokens() { |
250 // Configure OAuth authentication. | 253 // Configure OAuth authentication. |
251 GaiaUrls* gaia_urls = GaiaUrls::GetInstance(); | 254 GaiaUrls* gaia_urls = GaiaUrls::GetInstance(); |
252 | 255 |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
400 // PRE_MergeSession is testing merge session for a new profile. | 403 // PRE_MergeSession is testing merge session for a new profile. |
401 IN_PROC_BROWSER_TEST_F(OAuth2Test, PRE_PRE_PRE_MergeSession) { | 404 IN_PROC_BROWSER_TEST_F(OAuth2Test, PRE_PRE_PRE_MergeSession) { |
402 StartNewUserSession(true); | 405 StartNewUserSession(true); |
403 // Check for existance of refresh token. | 406 // Check for existance of refresh token. |
404 ProfileOAuth2TokenService* token_service = | 407 ProfileOAuth2TokenService* token_service = |
405 ProfileOAuth2TokenServiceFactory::GetForProfile( | 408 ProfileOAuth2TokenServiceFactory::GetForProfile( |
406 profile()); | 409 profile()); |
407 EXPECT_TRUE(token_service->RefreshTokenIsAvailable(kTestAccountId)); | 410 EXPECT_TRUE(token_service->RefreshTokenIsAvailable(kTestAccountId)); |
408 | 411 |
409 EXPECT_EQ(GetOAuthStatusFromLocalState(kTestAccountId), | 412 EXPECT_EQ(GetOAuthStatusFromLocalState(kTestAccountId), |
410 User::OAUTH2_TOKEN_STATUS_VALID); | 413 user_manager::User::OAUTH2_TOKEN_STATUS_VALID); |
411 | 414 |
412 scoped_refptr<CookieReader> cookie_reader(new CookieReader()); | 415 scoped_refptr<CookieReader> cookie_reader(new CookieReader()); |
413 cookie_reader->ReadCookies(profile()); | 416 cookie_reader->ReadCookies(profile()); |
414 EXPECT_EQ(cookie_reader->GetCookieValue("SID"), kTestSessionSIDCookie); | 417 EXPECT_EQ(cookie_reader->GetCookieValue("SID"), kTestSessionSIDCookie); |
415 EXPECT_EQ(cookie_reader->GetCookieValue("LSID"), kTestSessionLSIDCookie); | 418 EXPECT_EQ(cookie_reader->GetCookieValue("LSID"), kTestSessionLSIDCookie); |
416 } | 419 } |
417 | 420 |
418 // MergeSession test is running merge session process for an existing profile | 421 // MergeSession test is running merge session process for an existing profile |
419 // that was generated in PRE_PRE_PRE_MergeSession test. In this test, we | 422 // that was generated in PRE_PRE_PRE_MergeSession test. In this test, we |
420 // are not running /MergeSession process since the /ListAccounts call confirms | 423 // are not running /MergeSession process since the /ListAccounts call confirms |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
453 SimulateNetworkOnline(); | 456 SimulateNetworkOnline(); |
454 | 457 |
455 content::WindowedNotificationObserver( | 458 content::WindowedNotificationObserver( |
456 chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE, | 459 chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE, |
457 content::NotificationService::AllSources()).Wait(); | 460 content::NotificationService::AllSources()).Wait(); |
458 | 461 |
459 JsExpect("!!document.querySelector('#account-picker')"); | 462 JsExpect("!!document.querySelector('#account-picker')"); |
460 JsExpect("!!document.querySelector('#pod-row')"); | 463 JsExpect("!!document.querySelector('#pod-row')"); |
461 | 464 |
462 EXPECT_EQ(GetOAuthStatusFromLocalState(kTestAccountId), | 465 EXPECT_EQ(GetOAuthStatusFromLocalState(kTestAccountId), |
463 User::OAUTH2_TOKEN_STATUS_VALID); | 466 user_manager::User::OAUTH2_TOKEN_STATUS_VALID); |
464 | 467 |
465 EXPECT_TRUE(TryToLogin(kTestAccountId, kTestAccountPassword)); | 468 EXPECT_TRUE(TryToLogin(kTestAccountId, kTestAccountPassword)); |
466 | 469 |
467 // Wait for the session merge to finish. | 470 // Wait for the session merge to finish. |
468 WaitForMergeSessionCompletion(OAuth2LoginManager::SESSION_RESTORE_FAILED); | 471 WaitForMergeSessionCompletion(OAuth2LoginManager::SESSION_RESTORE_FAILED); |
469 | 472 |
470 EXPECT_EQ(GetOAuthStatusFromLocalState(kTestAccountId), | 473 EXPECT_EQ(GetOAuthStatusFromLocalState(kTestAccountId), |
471 User::OAUTH2_TOKEN_STATUS_INVALID); | 474 user_manager::User::OAUTH2_TOKEN_STATUS_INVALID); |
472 } | 475 } |
473 | 476 |
474 | 477 |
475 const char kGooglePageContent[] = | 478 const char kGooglePageContent[] = |
476 "<html><title>Hello!</title><script>alert('hello');</script>" | 479 "<html><title>Hello!</title><script>alert('hello');</script>" |
477 "<body>Hello Google!</body></html>"; | 480 "<body>Hello Google!</body></html>"; |
478 const char kRandomPageContent[] = | 481 const char kRandomPageContent[] = |
479 "<html><title>SomthingElse</title><body>I am SomethingElse</body></html>"; | 482 "<html><title>SomthingElse</title><body>I am SomethingElse</body></html>"; |
480 const char kHelloPagePath[] = "/hello_google"; | 483 const char kHelloPagePath[] = "/hello_google"; |
481 const char kRandomPagePath[] = "/non_google_page"; | 484 const char kRandomPagePath[] = "/non_google_page"; |
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
776 | 779 |
777 if (!catcher.GetNextResult()) { | 780 if (!catcher.GetNextResult()) { |
778 std::string message = catcher.message(); | 781 std::string message = catcher.message(); |
779 ADD_FAILURE() << "Tests failed: " << message; | 782 ADD_FAILURE() << "Tests failed: " << message; |
780 } | 783 } |
781 | 784 |
782 EXPECT_TRUE(fake_google_.IsPageRequested()); | 785 EXPECT_TRUE(fake_google_.IsPageRequested()); |
783 } | 786 } |
784 | 787 |
785 } // namespace chromeos | 788 } // namespace chromeos |
OLD | NEW |