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_manager.h" | |
18 #include "chrome/browser/chromeos/login/wizard_controller.h" | 17 #include "chrome/browser/chromeos/login/wizard_controller.h" |
19 #include "chrome/browser/extensions/extension_test_message_listener.h" | 18 #include "chrome/browser/extensions/extension_test_message_listener.h" |
20 #include "chrome/browser/profiles/profile_manager.h" | 19 #include "chrome/browser/profiles/profile_manager.h" |
21 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | 20 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
22 #include "chrome/browser/ui/app_modal_dialogs/javascript_app_modal_dialog.h" | 21 #include "chrome/browser/ui/app_modal_dialogs/javascript_app_modal_dialog.h" |
23 #include "chrome/browser/ui/app_modal_dialogs/native_app_modal_dialog.h" | 22 #include "chrome/browser/ui/app_modal_dialogs/native_app_modal_dialog.h" |
24 #include "chrome/browser/ui/browser.h" | 23 #include "chrome/browser/ui/browser.h" |
25 #include "chrome/browser/ui/browser_tabstrip.h" | 24 #include "chrome/browser/ui/browser_tabstrip.h" |
26 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h" | 25 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h" |
27 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 26 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
28 #include "chrome/browser/ui/webui/chromeos/login/signin_screen_handler.h" | 27 #include "chrome/browser/ui/webui/chromeos/login/signin_screen_handler.h" |
29 #include "chrome/test/base/ui_test_utils.h" | 28 #include "chrome/test/base/ui_test_utils.h" |
30 #include "chromeos/login/auth/key.h" | 29 #include "chromeos/login/auth/key.h" |
31 #include "chromeos/login/auth/user_context.h" | 30 #include "chromeos/login/auth/user_context.h" |
32 #include "components/signin/core/browser/profile_oauth2_token_service.h" | 31 #include "components/signin/core/browser/profile_oauth2_token_service.h" |
33 #include "components/user_manager/user.h" | 32 #include "components/user_manager/user.h" |
| 33 #include "components/user_manager/user_manager.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 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 EXPECT_EQ(GetOAuthStatusFromLocalState(kTestAccountId), | 185 EXPECT_EQ(GetOAuthStatusFromLocalState(kTestAccountId), |
186 user_manager::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_manager::User* active_user = | 194 if (const user_manager::User* active_user = |
195 UserManager::Get()->GetActiveUser()) | 195 user_manager::UserManager::Get()->GetActiveUser()) { |
196 return active_user->email() == username; | 196 return active_user->email() == username; |
| 197 } |
197 | 198 |
198 return false; | 199 return false; |
199 } | 200 } |
200 | 201 |
201 user_manager::User::OAuthTokenStatus GetOAuthStatusFromLocalState( | 202 user_manager::User::OAuthTokenStatus GetOAuthStatusFromLocalState( |
202 const std::string& user_id) const { | 203 const std::string& user_id) const { |
203 PrefService* local_state = g_browser_process->local_state(); | 204 PrefService* local_state = g_browser_process->local_state(); |
204 const base::DictionaryValue* prefs_oauth_status = | 205 const base::DictionaryValue* prefs_oauth_status = |
205 local_state->GetDictionary("OAuthTokenStatus"); | 206 local_state->GetDictionary("OAuthTokenStatus"); |
206 int oauth_token_status = user_manager::User::OAUTH_TOKEN_STATUS_UNKNOWN; | 207 int oauth_token_status = user_manager::User::OAUTH_TOKEN_STATUS_UNKNOWN; |
207 if (prefs_oauth_status && | 208 if (prefs_oauth_status && |
208 prefs_oauth_status->GetIntegerWithoutPathExpansion( | 209 prefs_oauth_status->GetIntegerWithoutPathExpansion( |
209 user_id, &oauth_token_status)) { | 210 user_id, &oauth_token_status)) { |
210 user_manager::User::OAuthTokenStatus result = | 211 user_manager::User::OAuthTokenStatus result = |
211 static_cast<user_manager::User::OAuthTokenStatus>(oauth_token_status); | 212 static_cast<user_manager::User::OAuthTokenStatus>(oauth_token_status); |
212 return result; | 213 return result; |
213 } | 214 } |
214 return user_manager::User::OAUTH_TOKEN_STATUS_UNKNOWN; | 215 return user_manager::User::OAUTH_TOKEN_STATUS_UNKNOWN; |
215 } | 216 } |
216 | 217 |
217 protected: | 218 protected: |
218 // OobeBaseTest overrides. | 219 // OobeBaseTest overrides. |
219 virtual Profile* profile() OVERRIDE { | 220 virtual Profile* profile() OVERRIDE { |
220 if (UserManager::Get()->GetActiveUser()) | 221 if (user_manager::UserManager::Get()->GetActiveUser()) |
221 return ProfileManager::GetPrimaryUserProfile(); | 222 return ProfileManager::GetPrimaryUserProfile(); |
222 | 223 |
223 return OobeBaseTest::profile(); | 224 return OobeBaseTest::profile(); |
224 } | 225 } |
225 | 226 |
226 bool AddUserToSession(const std::string& username, | 227 bool AddUserToSession(const std::string& username, |
227 const std::string& password) { | 228 const std::string& password) { |
228 ExistingUserController* controller = | 229 ExistingUserController* controller = |
229 ExistingUserController::current_controller(); | 230 ExistingUserController::current_controller(); |
230 if (!controller) { | 231 if (!controller) { |
231 ADD_FAILURE(); | 232 ADD_FAILURE(); |
232 return false; | 233 return false; |
233 } | 234 } |
234 | 235 |
235 UserContext user_context(username); | 236 UserContext user_context(username); |
236 user_context.SetKey(Key(password)); | 237 user_context.SetKey(Key(password)); |
237 controller->Login(user_context, SigninSpecifics()); | 238 controller->Login(user_context, SigninSpecifics()); |
238 content::WindowedNotificationObserver( | 239 content::WindowedNotificationObserver( |
239 chrome::NOTIFICATION_SESSION_STARTED, | 240 chrome::NOTIFICATION_SESSION_STARTED, |
240 content::NotificationService::AllSources()).Wait(); | 241 content::NotificationService::AllSources()).Wait(); |
241 const user_manager::UserList& logged_users = | 242 const user_manager::UserList& logged_users = |
242 UserManager::Get()->GetLoggedInUsers(); | 243 user_manager::UserManager::Get()->GetLoggedInUsers(); |
243 for (user_manager::UserList::const_iterator it = logged_users.begin(); | 244 for (user_manager::UserList::const_iterator it = logged_users.begin(); |
244 it != logged_users.end(); | 245 it != logged_users.end(); |
245 ++it) { | 246 ++it) { |
246 if ((*it)->email() == username) | 247 if ((*it)->email() == username) |
247 return true; | 248 return true; |
248 } | 249 } |
249 return false; | 250 return false; |
250 } | 251 } |
251 | 252 |
252 void SetupGaiaServerWithAccessTokens() { | 253 void SetupGaiaServerWithAccessTokens() { |
(...skipping 526 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
779 | 780 |
780 if (!catcher.GetNextResult()) { | 781 if (!catcher.GetNextResult()) { |
781 std::string message = catcher.message(); | 782 std::string message = catcher.message(); |
782 ADD_FAILURE() << "Tests failed: " << message; | 783 ADD_FAILURE() << "Tests failed: " << message; |
783 } | 784 } |
784 | 785 |
785 EXPECT_TRUE(fake_google_.IsPageRequested()); | 786 EXPECT_TRUE(fake_google_.IsPageRequested()); |
786 } | 787 } |
787 | 788 |
788 } // namespace chromeos | 789 } // namespace chromeos |
OLD | NEW |