| 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/session/session_state_delegate.h" | 5 #include "ash/session/session_state_delegate.h" |
| 6 #include "ash/shell.h" | 6 #include "ash/shell.h" |
| 7 #include "base/macros.h" | 7 #include "base/macros.h" |
| 8 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
| 9 #include "chrome/browser/chrome_notification_types.h" | 9 #include "chrome/browser/chrome_notification_types.h" |
| 10 #include "chrome/browser/chromeos/login/lock/screen_locker.h" | 10 #include "chrome/browser/chromeos/login/lock/screen_locker.h" |
| 11 #include "chrome/browser/chromeos/login/lock/screen_locker_tester.h" | 11 #include "chrome/browser/chromeos/login/lock/screen_locker_tester.h" |
| 12 #include "chrome/browser/chromeos/login/login_manager_test.h" | 12 #include "chrome/browser/chromeos/login/login_manager_test.h" |
| 13 #include "chrome/browser/chromeos/login/startup_utils.h" | 13 #include "chrome/browser/chromeos/login/startup_utils.h" |
| 14 #include "chrome/browser/chromeos/login/ui/login_display_host_impl.h" | 14 #include "chrome/browser/chromeos/login/ui/login_display_host.h" |
| 15 #include "chrome/browser/chromeos/login/ui/user_adding_screen.h" | 15 #include "chrome/browser/chromeos/login/ui/user_adding_screen.h" |
| 16 #include "chrome/browser/chromeos/login/ui/webui_login_view.h" | 16 #include "chrome/browser/chromeos/login/ui/webui_login_view.h" |
| 17 #include "chrome/browser/chromeos/login/users/multi_profile_user_controller.h" | 17 #include "chrome/browser/chromeos/login/users/multi_profile_user_controller.h" |
| 18 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 18 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
| 19 #include "chrome/common/pref_names.h" | 19 #include "chrome/common/pref_names.h" |
| 20 #include "chrome/test/base/in_process_browser_test.h" | 20 #include "chrome/test/base/in_process_browser_test.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/test/test_utils.h" | 23 #include "content/public/test/test_utils.h" |
| 23 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
| 24 | 25 |
| 25 using namespace testing; | 26 using namespace testing; |
| 26 | 27 |
| 27 namespace { | 28 namespace { |
| 28 | 29 |
| 29 const char* const kTestUsers[] = {"test-user1@gmail.com", | 30 const char* const kTestUsers[] = {"test-user1@gmail.com", |
| 30 "test-user2@gmail.com", | 31 "test-user2@gmail.com", |
| 31 "test-user3@gmail.com"}; | 32 "test-user3@gmail.com"}; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 50 void OnUserAddingFinished() override { ++user_adding_finished_; } | 51 void OnUserAddingFinished() override { ++user_adding_finished_; } |
| 51 | 52 |
| 52 void OnUserAddingStarted() override { ++user_adding_started_; } | 53 void OnUserAddingStarted() override { ++user_adding_started_; } |
| 53 | 54 |
| 54 void SetUserCanLock(user_manager::User* user, bool can_lock) { | 55 void SetUserCanLock(user_manager::User* user, bool can_lock) { |
| 55 user->set_can_lock(can_lock); | 56 user->set_can_lock(can_lock); |
| 56 } | 57 } |
| 57 | 58 |
| 58 void CheckScreenIsVisible() { | 59 void CheckScreenIsVisible() { |
| 59 views::View* web_view = | 60 views::View* web_view = |
| 60 LoginDisplayHostImpl::default_host()->GetWebUILoginView()->child_at(0); | 61 LoginDisplayHost::default_host()->GetWebUILoginView()->child_at(0); |
| 61 for (views::View* current_view = web_view; | 62 for (views::View* current_view = web_view; |
| 62 current_view; | 63 current_view; |
| 63 current_view = current_view->parent()) { | 64 current_view = current_view->parent()) { |
| 64 EXPECT_TRUE(current_view->visible()); | 65 EXPECT_TRUE(current_view->visible()); |
| 65 if (current_view->layer()) | 66 if (current_view->layer()) |
| 66 EXPECT_EQ(current_view->layer()->GetCombinedOpacity(), 1.f); | 67 EXPECT_EQ(current_view->layer()->GetCombinedOpacity(), 1.f); |
| 67 } | 68 } |
| 68 for (aura::Window* window = web_view->GetWidget()->GetNativeWindow(); | 69 for (aura::Window* window = web_view->GetWidget()->GetNativeWindow(); |
| 69 window; | 70 window; |
| 70 window = window->parent()) { | 71 window = window->parent()) { |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 ash::Shell::GetInstance()->session_state_delegate()-> | 113 ash::Shell::GetInstance()->session_state_delegate()-> |
| 113 GetSessionState()); | 114 GetSessionState()); |
| 114 | 115 |
| 115 UserAddingScreen::Get()->Cancel(); | 116 UserAddingScreen::Get()->Cancel(); |
| 116 content::RunAllPendingInMessageLoop(); | 117 content::RunAllPendingInMessageLoop(); |
| 117 EXPECT_EQ(1, user_adding_finished()); | 118 EXPECT_EQ(1, user_adding_finished()); |
| 118 EXPECT_EQ(ash::SessionStateDelegate::SESSION_STATE_ACTIVE, | 119 EXPECT_EQ(ash::SessionStateDelegate::SESSION_STATE_ACTIVE, |
| 119 ash::Shell::GetInstance()->session_state_delegate()-> | 120 ash::Shell::GetInstance()->session_state_delegate()-> |
| 120 GetSessionState()); | 121 GetSessionState()); |
| 121 | 122 |
| 122 EXPECT_TRUE(LoginDisplayHostImpl::default_host() == NULL); | 123 EXPECT_TRUE(LoginDisplayHost::default_host() == nullptr); |
| 123 EXPECT_EQ(1u, user_manager::UserManager::Get()->GetLoggedInUsers().size()); | 124 EXPECT_EQ(1u, user_manager::UserManager::Get()->GetLoggedInUsers().size()); |
| 124 EXPECT_EQ(kTestUsers[0], | 125 EXPECT_EQ(kTestUsers[0], |
| 125 user_manager::UserManager::Get()->GetActiveUser()->email()); | 126 user_manager::UserManager::Get()->GetActiveUser()->email()); |
| 126 } | 127 } |
| 127 | 128 |
| 128 IN_PROC_BROWSER_TEST_F(UserAddingScreenTest, PRE_AddingSeveralUsers) { | 129 IN_PROC_BROWSER_TEST_F(UserAddingScreenTest, PRE_AddingSeveralUsers) { |
| 129 RegisterUser(kTestUsers[0]); | 130 RegisterUser(kTestUsers[0]); |
| 130 RegisterUser(kTestUsers[1]); | 131 RegisterUser(kTestUsers[1]); |
| 131 RegisterUser(kTestUsers[2]); | 132 RegisterUser(kTestUsers[2]); |
| 132 StartupUtils::MarkOobeCompleted(); | 133 StartupUtils::MarkOobeCompleted(); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 148 content::RunAllPendingInMessageLoop(); | 149 content::RunAllPendingInMessageLoop(); |
| 149 EXPECT_EQ(i, user_adding_started()); | 150 EXPECT_EQ(i, user_adding_started()); |
| 150 EXPECT_EQ(ash::SessionStateDelegate::SESSION_STATE_LOGIN_SECONDARY, | 151 EXPECT_EQ(ash::SessionStateDelegate::SESSION_STATE_LOGIN_SECONDARY, |
| 151 ash::Shell::GetInstance()->session_state_delegate()-> | 152 ash::Shell::GetInstance()->session_state_delegate()-> |
| 152 GetSessionState()); | 153 GetSessionState()); |
| 153 AddUser(kTestUsers[i]); | 154 AddUser(kTestUsers[i]); |
| 154 EXPECT_EQ(i, user_adding_finished()); | 155 EXPECT_EQ(i, user_adding_finished()); |
| 155 EXPECT_EQ(ash::SessionStateDelegate::SESSION_STATE_ACTIVE, | 156 EXPECT_EQ(ash::SessionStateDelegate::SESSION_STATE_ACTIVE, |
| 156 ash::Shell::GetInstance()->session_state_delegate()-> | 157 ash::Shell::GetInstance()->session_state_delegate()-> |
| 157 GetSessionState()); | 158 GetSessionState()); |
| 158 EXPECT_TRUE(LoginDisplayHostImpl::default_host() == NULL); | 159 EXPECT_TRUE(LoginDisplayHost::default_host() == nullptr); |
| 159 ASSERT_EQ(unsigned(i + 1), user_manager->GetLoggedInUsers().size()); | 160 ASSERT_EQ(unsigned(i + 1), user_manager->GetLoggedInUsers().size()); |
| 160 } | 161 } |
| 161 | 162 |
| 162 EXPECT_EQ(ash::SessionStateDelegate::SESSION_STATE_ACTIVE, | 163 EXPECT_EQ(ash::SessionStateDelegate::SESSION_STATE_ACTIVE, |
| 163 ash::Shell::GetInstance()->session_state_delegate()-> | 164 ash::Shell::GetInstance()->session_state_delegate()-> |
| 164 GetSessionState()); | 165 GetSessionState()); |
| 165 | 166 |
| 166 // Now check how unlock policy works for these users. | 167 // Now check how unlock policy works for these users. |
| 167 PrefService* prefs1 = | 168 PrefService* prefs1 = |
| 168 ProfileHelper::Get() | 169 ProfileHelper::Get() |
| 169 ->GetProfileByUserUnsafe(user_manager->GetLoggedInUsers()[0]) | 170 ->GetProfileByUserUnsafe(user_manager->GetLoggedInUsers()[0]) |
| 170 ->GetPrefs(); | 171 ->GetPrefs(); |
| 171 PrefService* prefs2 = | 172 PrefService* prefs2 = |
| 172 ProfileHelper::Get() | 173 ProfileHelper::Get() |
| 173 ->GetProfileByUserUnsafe(user_manager->GetLoggedInUsers()[1]) | 174 ->GetProfileByUserUnsafe(user_manager->GetLoggedInUsers()[1]) |
| 174 ->GetPrefs(); | 175 ->GetPrefs(); |
| 175 PrefService* prefs3 = | 176 PrefService* prefs3 = |
| 176 ProfileHelper::Get() | 177 ProfileHelper::Get() |
| 177 ->GetProfileByUserUnsafe(user_manager->GetLoggedInUsers()[2]) | 178 ->GetProfileByUserUnsafe(user_manager->GetLoggedInUsers()[2]) |
| 178 ->GetPrefs(); | 179 ->GetPrefs(); |
| 179 ASSERT_TRUE(prefs1 != NULL); | 180 ASSERT_TRUE(prefs1 != nullptr); |
| 180 ASSERT_TRUE(prefs2 != NULL); | 181 ASSERT_TRUE(prefs2 != nullptr); |
| 181 ASSERT_TRUE(prefs3 != NULL); | 182 ASSERT_TRUE(prefs3 != nullptr); |
| 182 prefs1->SetBoolean(prefs::kEnableAutoScreenLock, false); | 183 prefs1->SetBoolean(prefs::kEnableAutoScreenLock, false); |
| 183 prefs2->SetBoolean(prefs::kEnableAutoScreenLock, false); | 184 prefs2->SetBoolean(prefs::kEnableAutoScreenLock, false); |
| 184 prefs3->SetBoolean(prefs::kEnableAutoScreenLock, false); | 185 prefs3->SetBoolean(prefs::kEnableAutoScreenLock, false); |
| 185 | 186 |
| 186 // One of the users has the primary-only policy. | 187 // One of the users has the primary-only policy. |
| 187 // List of unlock users doesn't depend on kEnableLockScreen preference. | 188 // List of unlock users doesn't depend on kEnableLockScreen preference. |
| 188 prefs1->SetBoolean(prefs::kEnableAutoScreenLock, true); | 189 prefs1->SetBoolean(prefs::kEnableAutoScreenLock, true); |
| 189 prefs1->SetString(prefs::kMultiProfileUserBehavior, | 190 prefs1->SetString(prefs::kMultiProfileUserBehavior, |
| 190 MultiProfileUserController::kBehaviorPrimaryOnly); | 191 MultiProfileUserController::kBehaviorPrimaryOnly); |
| 191 prefs2->SetString(prefs::kMultiProfileUserBehavior, | 192 prefs2->SetString(prefs::kMultiProfileUserBehavior, |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 content::NotificationService::AllSources()).Wait(); | 264 content::NotificationService::AllSources()).Wait(); |
| 264 | 265 |
| 265 UserAddingScreen::Get()->Start(); | 266 UserAddingScreen::Get()->Start(); |
| 266 content::RunAllPendingInMessageLoop(); | 267 content::RunAllPendingInMessageLoop(); |
| 267 CheckScreenIsVisible(); | 268 CheckScreenIsVisible(); |
| 268 UserAddingScreen::Get()->Cancel(); | 269 UserAddingScreen::Get()->Cancel(); |
| 269 content::RunAllPendingInMessageLoop(); | 270 content::RunAllPendingInMessageLoop(); |
| 270 } | 271 } |
| 271 | 272 |
| 272 } // namespace chromeos | 273 } // namespace chromeos |
| OLD | NEW |