OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "chrome/browser/chromeos/login/login_manager_test.h" | 5 #include "chrome/browser/chromeos/login/login_manager_test.h" |
6 | 6 |
7 #include "base/prefs/scoped_user_pref_update.h" | 7 #include "base/prefs/scoped_user_pref_update.h" |
8 #include "chrome/browser/browser_process.h" | 8 #include "chrome/browser/browser_process.h" |
9 #include "chrome/browser/chrome_notification_types.h" | 9 #include "chrome/browser/chrome_notification_types.h" |
10 #include "chrome/browser/chromeos/login/existing_user_controller.h" | 10 #include "chrome/browser/chromeos/login/existing_user_controller.h" |
11 #include "chrome/browser/chromeos/login/ui/login_display_host_impl.h" | 11 #include "chrome/browser/chromeos/login/ui/login_display_host_impl.h" |
12 #include "chrome/browser/chromeos/login/ui/webui_login_view.h" | 12 #include "chrome/browser/chromeos/login/ui/webui_login_view.h" |
13 #include "chrome/browser/chromeos/login/users/user.h" | |
14 #include "chrome/browser/chromeos/login/users/user_manager.h" | 13 #include "chrome/browser/chromeos/login/users/user_manager.h" |
15 #include "chromeos/chromeos_switches.h" | 14 #include "chromeos/chromeos_switches.h" |
16 #include "chromeos/login/auth/key.h" | 15 #include "chromeos/login/auth/key.h" |
17 #include "chromeos/login/auth/user_context.h" | 16 #include "chromeos/login/auth/user_context.h" |
| 17 #include "components/user_manager/user.h" |
18 #include "content/public/browser/notification_service.h" | 18 #include "content/public/browser/notification_service.h" |
19 #include "content/public/browser/web_contents.h" | 19 #include "content/public/browser/web_contents.h" |
20 #include "content/public/test/browser_test_utils.h" | 20 #include "content/public/test/browser_test_utils.h" |
21 #include "content/public/test/test_utils.h" | 21 #include "content/public/test/test_utils.h" |
22 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
23 | 23 |
24 namespace chromeos { | 24 namespace chromeos { |
25 | 25 |
26 LoginManagerTest::LoginManagerTest(bool should_launch_browser) | 26 LoginManagerTest::LoginManagerTest(bool should_launch_browser) |
27 : should_launch_browser_(should_launch_browser), | 27 : should_launch_browser_(should_launch_browser), |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 users_pref->AppendIfNotPresent(new base::StringValue(user_id)); | 60 users_pref->AppendIfNotPresent(new base::StringValue(user_id)); |
61 } | 61 } |
62 | 62 |
63 void LoginManagerTest::SetExpectedCredentials(const UserContext& user_context) { | 63 void LoginManagerTest::SetExpectedCredentials(const UserContext& user_context) { |
64 login_utils().GetFakeLoginUtils()->SetExpectedCredentials(user_context); | 64 login_utils().GetFakeLoginUtils()->SetExpectedCredentials(user_context); |
65 } | 65 } |
66 | 66 |
67 bool LoginManagerTest::TryToLogin(const UserContext& user_context) { | 67 bool LoginManagerTest::TryToLogin(const UserContext& user_context) { |
68 if (!AddUserToSession(user_context)) | 68 if (!AddUserToSession(user_context)) |
69 return false; | 69 return false; |
70 if (const User* active_user = UserManager::Get()->GetActiveUser()) | 70 if (const user_manager::User* active_user = |
| 71 UserManager::Get()->GetActiveUser()) |
71 return active_user->email() == user_context.GetUserID(); | 72 return active_user->email() == user_context.GetUserID(); |
72 return false; | 73 return false; |
73 } | 74 } |
74 | 75 |
75 bool LoginManagerTest::AddUserToSession(const UserContext& user_context) { | 76 bool LoginManagerTest::AddUserToSession(const UserContext& user_context) { |
76 ExistingUserController* controller = | 77 ExistingUserController* controller = |
77 ExistingUserController::current_controller(); | 78 ExistingUserController::current_controller(); |
78 if (!controller) { | 79 if (!controller) { |
79 ADD_FAILURE(); | 80 ADD_FAILURE(); |
80 return false; | 81 return false; |
81 } | 82 } |
82 controller->Login(user_context, SigninSpecifics()); | 83 controller->Login(user_context, SigninSpecifics()); |
83 content::WindowedNotificationObserver( | 84 content::WindowedNotificationObserver( |
84 chrome::NOTIFICATION_SESSION_STARTED, | 85 chrome::NOTIFICATION_SESSION_STARTED, |
85 content::NotificationService::AllSources()).Wait(); | 86 content::NotificationService::AllSources()).Wait(); |
86 const UserList& logged_users = UserManager::Get()->GetLoggedInUsers(); | 87 const user_manager::UserList& logged_users = |
87 for (UserList::const_iterator it = logged_users.begin(); | 88 UserManager::Get()->GetLoggedInUsers(); |
88 it != logged_users.end(); ++it) { | 89 for (user_manager::UserList::const_iterator it = logged_users.begin(); |
| 90 it != logged_users.end(); |
| 91 ++it) { |
89 if ((*it)->email() == user_context.GetUserID()) | 92 if ((*it)->email() == user_context.GetUserID()) |
90 return true; | 93 return true; |
91 } | 94 } |
92 return false; | 95 return false; |
93 } | 96 } |
94 | 97 |
95 void LoginManagerTest::LoginUser(const std::string& user_id) { | 98 void LoginManagerTest::LoginUser(const std::string& user_id) { |
96 UserContext user_context(user_id); | 99 UserContext user_context(user_id); |
97 user_context.SetKey(Key("password")); | 100 user_context.SetKey(Key("password")); |
98 SetExpectedCredentials(user_context); | 101 SetExpectedCredentials(user_context); |
(...skipping 16 matching lines...) Expand all Loading... |
115 EXPECT_TRUE(host != NULL); | 118 EXPECT_TRUE(host != NULL); |
116 | 119 |
117 content::WebContents* web_contents = | 120 content::WebContents* web_contents = |
118 host->GetWebUILoginView()->GetWebContents(); | 121 host->GetWebUILoginView()->GetWebContents(); |
119 EXPECT_TRUE(web_contents != NULL); | 122 EXPECT_TRUE(web_contents != NULL); |
120 set_web_contents(web_contents); | 123 set_web_contents(web_contents); |
121 js_checker_.set_web_contents(web_contents); | 124 js_checker_.set_web_contents(web_contents); |
122 } | 125 } |
123 | 126 |
124 } // namespace chromeos | 127 } // namespace chromeos |
OLD | NEW |