| 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 "ash/common/session/session_state_delegate.h" | |
| 6 #include "ash/common/wm_shell.h" | |
| 7 #include "base/macros.h" | 5 #include "base/macros.h" |
| 8 #include "chrome/browser/chrome_notification_types.h" | 6 #include "chrome/browser/chrome_notification_types.h" |
| 9 #include "chrome/browser/chromeos/login/lock/screen_locker.h" | 7 #include "chrome/browser/chromeos/login/lock/screen_locker.h" |
| 10 #include "chrome/browser/chromeos/login/lock/screen_locker_tester.h" | 8 #include "chrome/browser/chromeos/login/lock/screen_locker_tester.h" |
| 11 #include "chrome/browser/chromeos/login/login_manager_test.h" | 9 #include "chrome/browser/chromeos/login/login_manager_test.h" |
| 12 #include "chrome/browser/chromeos/login/startup_utils.h" | 10 #include "chrome/browser/chromeos/login/startup_utils.h" |
| 13 #include "chrome/browser/chromeos/login/ui/login_display_host.h" | 11 #include "chrome/browser/chromeos/login/ui/login_display_host.h" |
| 14 #include "chrome/browser/chromeos/login/ui/user_adding_screen.h" | 12 #include "chrome/browser/chromeos/login/ui/user_adding_screen.h" |
| 15 #include "chrome/browser/chromeos/login/ui/webui_login_view.h" | 13 #include "chrome/browser/chromeos/login/ui/webui_login_view.h" |
| 16 #include "chrome/browser/chromeos/login/users/multi_profile_user_controller.h" | 14 #include "chrome/browser/chromeos/login/users/multi_profile_user_controller.h" |
| 17 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 15 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
| 18 #include "chrome/common/pref_names.h" | 16 #include "chrome/common/pref_names.h" |
| 19 #include "chrome/test/base/in_process_browser_test.h" | 17 #include "chrome/test/base/in_process_browser_test.h" |
| 20 #include "components/prefs/pref_service.h" | 18 #include "components/prefs/pref_service.h" |
| 19 #include "components/session_manager/core/session_manager.h" |
| 21 #include "components/user_manager/user_manager.h" | 20 #include "components/user_manager/user_manager.h" |
| 22 #include "content/public/browser/notification_service.h" | 21 #include "content/public/browser/notification_service.h" |
| 23 #include "content/public/test/test_utils.h" | 22 #include "content/public/test/test_utils.h" |
| 24 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
| 25 #include "ui/aura/window.h" | 24 #include "ui/aura/window.h" |
| 26 | 25 |
| 27 using namespace testing; | 26 using namespace testing; |
| 28 | 27 |
| 29 namespace { | 28 namespace { |
| 30 | 29 |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 RegisterUser(kTestUsers[0]); | 104 RegisterUser(kTestUsers[0]); |
| 106 RegisterUser(kTestUsers[1]); | 105 RegisterUser(kTestUsers[1]); |
| 107 RegisterUser(kTestUsers[2]); | 106 RegisterUser(kTestUsers[2]); |
| 108 StartupUtils::MarkOobeCompleted(); | 107 StartupUtils::MarkOobeCompleted(); |
| 109 } | 108 } |
| 110 | 109 |
| 111 IN_PROC_BROWSER_TEST_F(UserAddingScreenTest, CancelAdding) { | 110 IN_PROC_BROWSER_TEST_F(UserAddingScreenTest, CancelAdding) { |
| 112 EXPECT_EQ(3u, user_manager::UserManager::Get()->GetUsers().size()); | 111 EXPECT_EQ(3u, user_manager::UserManager::Get()->GetUsers().size()); |
| 113 EXPECT_EQ(0u, user_manager::UserManager::Get()->GetLoggedInUsers().size()); | 112 EXPECT_EQ(0u, user_manager::UserManager::Get()->GetLoggedInUsers().size()); |
| 114 EXPECT_EQ(session_manager::SessionState::LOGIN_PRIMARY, | 113 EXPECT_EQ(session_manager::SessionState::LOGIN_PRIMARY, |
| 115 ash::WmShell::Get()->GetSessionStateDelegate()->GetSessionState()); | 114 session_manager::SessionManager::Get()->session_state()); |
| 116 | 115 |
| 117 LoginUser(kTestUsers[0]); | 116 LoginUser(kTestUsers[0]); |
| 118 EXPECT_EQ(1u, user_manager::UserManager::Get()->GetLoggedInUsers().size()); | 117 EXPECT_EQ(1u, user_manager::UserManager::Get()->GetLoggedInUsers().size()); |
| 119 EXPECT_EQ(session_manager::SessionState::ACTIVE, | 118 EXPECT_EQ(session_manager::SessionState::ACTIVE, |
| 120 ash::WmShell::Get()->GetSessionStateDelegate()->GetSessionState()); | 119 session_manager::SessionManager::Get()->session_state()); |
| 121 | 120 |
| 122 UserAddingScreen::Get()->Start(); | 121 UserAddingScreen::Get()->Start(); |
| 123 content::RunAllPendingInMessageLoop(); | 122 content::RunAllPendingInMessageLoop(); |
| 124 EXPECT_EQ(1, user_adding_started()); | 123 EXPECT_EQ(1, user_adding_started()); |
| 125 EXPECT_EQ(session_manager::SessionState::LOGIN_SECONDARY, | 124 EXPECT_EQ(session_manager::SessionState::LOGIN_SECONDARY, |
| 126 ash::WmShell::Get()->GetSessionStateDelegate()->GetSessionState()); | 125 session_manager::SessionManager::Get()->session_state()); |
| 127 | 126 |
| 128 UserAddingScreen::Get()->Cancel(); | 127 UserAddingScreen::Get()->Cancel(); |
| 129 WaitUntilUserAddingFinishedOrCancelled(); | 128 WaitUntilUserAddingFinishedOrCancelled(); |
| 130 content::RunAllPendingInMessageLoop(); | 129 content::RunAllPendingInMessageLoop(); |
| 131 EXPECT_EQ(1, user_adding_finished()); | 130 EXPECT_EQ(1, user_adding_finished()); |
| 132 EXPECT_EQ(session_manager::SessionState::ACTIVE, | 131 EXPECT_EQ(session_manager::SessionState::ACTIVE, |
| 133 ash::WmShell::Get()->GetSessionStateDelegate()->GetSessionState()); | 132 session_manager::SessionManager::Get()->session_state()); |
| 134 | 133 |
| 135 EXPECT_TRUE(LoginDisplayHost::default_host() == nullptr); | 134 EXPECT_TRUE(LoginDisplayHost::default_host() == nullptr); |
| 136 EXPECT_EQ(1u, user_manager::UserManager::Get()->GetLoggedInUsers().size()); | 135 EXPECT_EQ(1u, user_manager::UserManager::Get()->GetLoggedInUsers().size()); |
| 137 EXPECT_EQ(kTestUsers[0], user_manager::UserManager::Get() | 136 EXPECT_EQ(kTestUsers[0], user_manager::UserManager::Get() |
| 138 ->GetActiveUser() | 137 ->GetActiveUser() |
| 139 ->GetAccountId() | 138 ->GetAccountId() |
| 140 .GetUserEmail()); | 139 .GetUserEmail()); |
| 141 } | 140 } |
| 142 | 141 |
| 143 IN_PROC_BROWSER_TEST_F(UserAddingScreenTest, PRE_AddingSeveralUsers) { | 142 IN_PROC_BROWSER_TEST_F(UserAddingScreenTest, PRE_AddingSeveralUsers) { |
| 144 RegisterUser(kTestUsers[0]); | 143 RegisterUser(kTestUsers[0]); |
| 145 RegisterUser(kTestUsers[1]); | 144 RegisterUser(kTestUsers[1]); |
| 146 RegisterUser(kTestUsers[2]); | 145 RegisterUser(kTestUsers[2]); |
| 147 StartupUtils::MarkOobeCompleted(); | 146 StartupUtils::MarkOobeCompleted(); |
| 148 } | 147 } |
| 149 | 148 |
| 150 IN_PROC_BROWSER_TEST_F(UserAddingScreenTest, AddingSeveralUsers) { | 149 IN_PROC_BROWSER_TEST_F(UserAddingScreenTest, AddingSeveralUsers) { |
| 151 ash::WmShell* wm_shell = ash::WmShell::Get(); | |
| 152 EXPECT_EQ(session_manager::SessionState::LOGIN_PRIMARY, | 150 EXPECT_EQ(session_manager::SessionState::LOGIN_PRIMARY, |
| 153 wm_shell->GetSessionStateDelegate()->GetSessionState()); | 151 session_manager::SessionManager::Get()->session_state()); |
| 154 LoginUser(kTestUsers[0]); | 152 LoginUser(kTestUsers[0]); |
| 155 EXPECT_EQ(session_manager::SessionState::ACTIVE, | 153 EXPECT_EQ(session_manager::SessionState::ACTIVE, |
| 156 wm_shell->GetSessionStateDelegate()->GetSessionState()); | 154 session_manager::SessionManager::Get()->session_state()); |
| 157 | 155 |
| 158 user_manager::UserManager* user_manager = user_manager::UserManager::Get(); | 156 user_manager::UserManager* user_manager = user_manager::UserManager::Get(); |
| 159 | 157 |
| 160 for (int i = 1; i < 3; ++i) { | 158 for (int i = 1; i < 3; ++i) { |
| 161 UserAddingScreen::Get()->Start(); | 159 UserAddingScreen::Get()->Start(); |
| 162 content::RunAllPendingInMessageLoop(); | 160 content::RunAllPendingInMessageLoop(); |
| 163 EXPECT_EQ(i, user_adding_started()); | 161 EXPECT_EQ(i, user_adding_started()); |
| 164 EXPECT_EQ(session_manager::SessionState::LOGIN_SECONDARY, | 162 EXPECT_EQ(session_manager::SessionState::LOGIN_SECONDARY, |
| 165 wm_shell->GetSessionStateDelegate()->GetSessionState()); | 163 session_manager::SessionManager::Get()->session_state()); |
| 166 AddUser(kTestUsers[i]); | 164 AddUser(kTestUsers[i]); |
| 167 WaitUntilUserAddingFinishedOrCancelled(); | 165 WaitUntilUserAddingFinishedOrCancelled(); |
| 168 content::RunAllPendingInMessageLoop(); | 166 content::RunAllPendingInMessageLoop(); |
| 169 EXPECT_EQ(i, user_adding_finished()); | 167 EXPECT_EQ(i, user_adding_finished()); |
| 170 EXPECT_EQ(session_manager::SessionState::ACTIVE, | 168 EXPECT_EQ(session_manager::SessionState::ACTIVE, |
| 171 wm_shell->GetSessionStateDelegate()->GetSessionState()); | 169 session_manager::SessionManager::Get()->session_state()); |
| 172 EXPECT_TRUE(LoginDisplayHost::default_host() == nullptr); | 170 EXPECT_TRUE(LoginDisplayHost::default_host() == nullptr); |
| 173 ASSERT_EQ(unsigned(i + 1), user_manager->GetLoggedInUsers().size()); | 171 ASSERT_EQ(unsigned(i + 1), user_manager->GetLoggedInUsers().size()); |
| 174 } | 172 } |
| 175 | 173 |
| 176 EXPECT_EQ(session_manager::SessionState::ACTIVE, | 174 EXPECT_EQ(session_manager::SessionState::ACTIVE, |
| 177 wm_shell->GetSessionStateDelegate()->GetSessionState()); | 175 session_manager::SessionManager::Get()->session_state()); |
| 178 | 176 |
| 179 // Now check how unlock policy works for these users. | 177 // Now check how unlock policy works for these users. |
| 180 PrefService* prefs1 = | 178 PrefService* prefs1 = |
| 181 ProfileHelper::Get() | 179 ProfileHelper::Get() |
| 182 ->GetProfileByUserUnsafe(user_manager->GetLoggedInUsers()[0]) | 180 ->GetProfileByUserUnsafe(user_manager->GetLoggedInUsers()[0]) |
| 183 ->GetPrefs(); | 181 ->GetPrefs(); |
| 184 PrefService* prefs2 = | 182 PrefService* prefs2 = |
| 185 ProfileHelper::Get() | 183 ProfileHelper::Get() |
| 186 ->GetProfileByUserUnsafe(user_manager->GetLoggedInUsers()[1]) | 184 ->GetProfileByUserUnsafe(user_manager->GetLoggedInUsers()[1]) |
| 187 ->GetPrefs(); | 185 ->GetPrefs(); |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 | 282 |
| 285 UserAddingScreen::Get()->Start(); | 283 UserAddingScreen::Get()->Start(); |
| 286 content::RunAllPendingInMessageLoop(); | 284 content::RunAllPendingInMessageLoop(); |
| 287 CheckScreenIsVisible(); | 285 CheckScreenIsVisible(); |
| 288 UserAddingScreen::Get()->Cancel(); | 286 UserAddingScreen::Get()->Cancel(); |
| 289 WaitUntilUserAddingFinishedOrCancelled(); | 287 WaitUntilUserAddingFinishedOrCancelled(); |
| 290 content::RunAllPendingInMessageLoop(); | 288 content::RunAllPendingInMessageLoop(); |
| 291 } | 289 } |
| 292 | 290 |
| 293 } // namespace chromeos | 291 } // namespace chromeos |
| OLD | NEW |