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_manager.h" | |
14 #include "chromeos/chromeos_switches.h" | 13 #include "chromeos/chromeos_switches.h" |
15 #include "chromeos/login/auth/key.h" | 14 #include "chromeos/login/auth/key.h" |
16 #include "chromeos/login/auth/user_context.h" | 15 #include "chromeos/login/auth/user_context.h" |
17 #include "components/user_manager/user.h" | 16 #include "components/user_manager/user.h" |
| 17 #include "components/user_manager/user_manager.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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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_manager::User* active_user = | 70 if (const user_manager::User* active_user = |
71 UserManager::Get()->GetActiveUser()) | 71 user_manager::UserManager::Get()->GetActiveUser()) |
72 return active_user->email() == user_context.GetUserID(); | 72 return active_user->email() == user_context.GetUserID(); |
73 return false; | 73 return false; |
74 } | 74 } |
75 | 75 |
76 bool LoginManagerTest::AddUserToSession(const UserContext& user_context) { | 76 bool LoginManagerTest::AddUserToSession(const UserContext& user_context) { |
77 ExistingUserController* controller = | 77 ExistingUserController* controller = |
78 ExistingUserController::current_controller(); | 78 ExistingUserController::current_controller(); |
79 if (!controller) { | 79 if (!controller) { |
80 ADD_FAILURE(); | 80 ADD_FAILURE(); |
81 return false; | 81 return false; |
82 } | 82 } |
83 controller->Login(user_context, SigninSpecifics()); | 83 controller->Login(user_context, SigninSpecifics()); |
84 content::WindowedNotificationObserver( | 84 content::WindowedNotificationObserver( |
85 chrome::NOTIFICATION_SESSION_STARTED, | 85 chrome::NOTIFICATION_SESSION_STARTED, |
86 content::NotificationService::AllSources()).Wait(); | 86 content::NotificationService::AllSources()).Wait(); |
87 const user_manager::UserList& logged_users = | 87 const user_manager::UserList& logged_users = |
88 UserManager::Get()->GetLoggedInUsers(); | 88 user_manager::UserManager::Get()->GetLoggedInUsers(); |
89 for (user_manager::UserList::const_iterator it = logged_users.begin(); | 89 for (user_manager::UserList::const_iterator it = logged_users.begin(); |
90 it != logged_users.end(); | 90 it != logged_users.end(); |
91 ++it) { | 91 ++it) { |
92 if ((*it)->email() == user_context.GetUserID()) | 92 if ((*it)->email() == user_context.GetUserID()) |
93 return true; | 93 return true; |
94 } | 94 } |
95 return false; | 95 return false; |
96 } | 96 } |
97 | 97 |
98 void LoginManagerTest::LoginUser(const std::string& user_id) { | 98 void LoginManagerTest::LoginUser(const std::string& user_id) { |
(...skipping 19 matching lines...) Expand all Loading... |
118 EXPECT_TRUE(host != NULL); | 118 EXPECT_TRUE(host != NULL); |
119 | 119 |
120 content::WebContents* web_contents = | 120 content::WebContents* web_contents = |
121 host->GetWebUILoginView()->GetWebContents(); | 121 host->GetWebUILoginView()->GetWebContents(); |
122 EXPECT_TRUE(web_contents != NULL); | 122 EXPECT_TRUE(web_contents != NULL); |
123 set_web_contents(web_contents); | 123 set_web_contents(web_contents); |
124 js_checker_.set_web_contents(web_contents); | 124 js_checker_.set_web_contents(web_contents); |
125 } | 125 } |
126 | 126 |
127 } // namespace chromeos | 127 } // namespace chromeos |
OLD | NEW |