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