| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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_controller.h" | 5 #include "ash/common/session/session_controller.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <utility> | 9 #include <utility> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "ash/common/login_status.h" |
| 12 #include "ash/common/session/session_controller.h" | 13 #include "ash/common/session/session_controller.h" |
| 13 #include "ash/common/session/session_state_observer.h" | 14 #include "ash/common/session/session_state_observer.h" |
| 14 #include "ash/public/interfaces/session_controller.mojom.h" | 15 #include "ash/public/interfaces/session_controller.mojom.h" |
| 15 #include "base/macros.h" | 16 #include "base/macros.h" |
| 16 #include "base/memory/ptr_util.h" | 17 #include "base/memory/ptr_util.h" |
| 17 #include "components/user_manager/user_type.h" | 18 #include "components/user_manager/user_type.h" |
| 18 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
| 19 | 20 |
| 20 namespace ash { | 21 namespace ash { |
| 21 namespace { | 22 namespace { |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 << "Test case state=" << static_cast<int>(test_case.state); | 186 << "Test case state=" << static_cast<int>(test_case.state); |
| 186 EXPECT_EQ(test_case.expected_is_screen_locked, | 187 EXPECT_EQ(test_case.expected_is_screen_locked, |
| 187 controller()->IsScreenLocked()) | 188 controller()->IsScreenLocked()) |
| 188 << "Test case state=" << static_cast<int>(test_case.state); | 189 << "Test case state=" << static_cast<int>(test_case.state); |
| 189 EXPECT_EQ(test_case.expected_is_user_session_blocked, | 190 EXPECT_EQ(test_case.expected_is_user_session_blocked, |
| 190 controller()->IsUserSessionBlocked()) | 191 controller()->IsUserSessionBlocked()) |
| 191 << "Test case state=" << static_cast<int>(test_case.state); | 192 << "Test case state=" << static_cast<int>(test_case.state); |
| 192 } | 193 } |
| 193 } | 194 } |
| 194 | 195 |
| 196 // Tests that LoginStatus is computed correctly for most session states. |
| 197 TEST_F(SessionControllerTest, GetLoginStatus) { |
| 198 using session_manager::SessionState; |
| 199 |
| 200 const struct { |
| 201 SessionState state; |
| 202 LoginStatus expected_status; |
| 203 } kTestCases[] = { |
| 204 {SessionState::UNKNOWN, LoginStatus::NOT_LOGGED_IN}, |
| 205 {SessionState::OOBE, LoginStatus::NOT_LOGGED_IN}, |
| 206 {SessionState::LOGIN_PRIMARY, LoginStatus::NOT_LOGGED_IN}, |
| 207 {SessionState::LOGGED_IN_NOT_ACTIVE, LoginStatus::NOT_LOGGED_IN}, |
| 208 {SessionState::LOCKED, LoginStatus::LOCKED}, |
| 209 // TODO: Add LOGIN_SECONDARY if we added a status for it. |
| 210 }; |
| 211 |
| 212 mojom::SessionInfo info; |
| 213 FillDefaultSessionInfo(&info); |
| 214 for (const auto& test_case : kTestCases) { |
| 215 info.state = test_case.state; |
| 216 SetSessionInfo(info); |
| 217 EXPECT_EQ(test_case.expected_status, controller()->GetLoginStatus()) |
| 218 << "Test case state=" << static_cast<int>(test_case.state); |
| 219 } |
| 220 } |
| 221 |
| 222 // Tests that LoginStatus is computed correctly for active sessions. |
| 223 TEST_F(SessionControllerTest, GetLoginStateForActiveSession) { |
| 224 // Simulate an active user session. |
| 225 mojom::SessionInfo info; |
| 226 FillDefaultSessionInfo(&info); |
| 227 info.state = session_manager::SessionState::ACTIVE; |
| 228 SetSessionInfo(info); |
| 229 |
| 230 const struct { |
| 231 user_manager::UserType user_type; |
| 232 LoginStatus expected_status; |
| 233 } kTestCases[] = { |
| 234 {user_manager::USER_TYPE_REGULAR, LoginStatus::USER}, |
| 235 {user_manager::USER_TYPE_GUEST, LoginStatus::GUEST}, |
| 236 {user_manager::USER_TYPE_PUBLIC_ACCOUNT, LoginStatus::PUBLIC}, |
| 237 {user_manager::USER_TYPE_SUPERVISED, LoginStatus::SUPERVISED}, |
| 238 {user_manager::USER_TYPE_KIOSK_APP, LoginStatus::KIOSK_APP}, |
| 239 {user_manager::USER_TYPE_CHILD, LoginStatus::SUPERVISED}, |
| 240 {user_manager::USER_TYPE_ARC_KIOSK_APP, LoginStatus::ARC_KIOSK_APP}, |
| 241 // TODO: Add USER_TYPE_ACTIVE_DIRECTORY if we add a status for it. |
| 242 }; |
| 243 |
| 244 for (const auto& test_case : kTestCases) { |
| 245 mojom::UserSessionPtr session = mojom::UserSession::New(); |
| 246 session->session_id = 1u; |
| 247 session->type = test_case.user_type; |
| 248 session->account_id = AccountId::FromUserEmail("user1@test.com"); |
| 249 session->display_name = "User 1"; |
| 250 session->display_email = "user1@test.com"; |
| 251 controller()->UpdateUserSession(std::move(session)); |
| 252 |
| 253 EXPECT_EQ(test_case.expected_status, controller()->GetLoginStatus()) |
| 254 << "Test case user_type=" << static_cast<int>(test_case.user_type); |
| 255 } |
| 256 } |
| 257 |
| 195 // Tests that user sessions can be set and updated. | 258 // Tests that user sessions can be set and updated. |
| 196 TEST_F(SessionControllerTest, UserSessions) { | 259 TEST_F(SessionControllerTest, UserSessions) { |
| 197 EXPECT_FALSE(controller()->IsActiveUserSessionStarted()); | 260 EXPECT_FALSE(controller()->IsActiveUserSessionStarted()); |
| 198 | 261 |
| 199 UpdateSession(1u, "user1@test.com"); | 262 UpdateSession(1u, "user1@test.com"); |
| 200 EXPECT_TRUE(controller()->IsActiveUserSessionStarted()); | 263 EXPECT_TRUE(controller()->IsActiveUserSessionStarted()); |
| 201 EXPECT_EQ("user1@test.com,", GetUserSessionEmails()); | 264 EXPECT_EQ("user1@test.com,", GetUserSessionEmails()); |
| 202 EXPECT_EQ(GetUserSessionEmails(), observer()->GetUserSessionEmails()); | 265 EXPECT_EQ(GetUserSessionEmails(), observer()->GetUserSessionEmails()); |
| 203 | 266 |
| 204 UpdateSession(2u, "user2@test.com"); | 267 UpdateSession(2u, "user2@test.com"); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 227 EXPECT_EQ("user2@test.com", observer()->active_account_id().GetUserEmail()); | 290 EXPECT_EQ("user2@test.com", observer()->active_account_id().GetUserEmail()); |
| 228 | 291 |
| 229 order = {1u, 2u}; | 292 order = {1u, 2u}; |
| 230 controller()->SetUserSessionOrder(order); | 293 controller()->SetUserSessionOrder(order); |
| 231 EXPECT_EQ("user1@test.com,user2@test.com,", GetUserSessionEmails()); | 294 EXPECT_EQ("user1@test.com,user2@test.com,", GetUserSessionEmails()); |
| 232 EXPECT_EQ("user1@test.com", observer()->active_account_id().GetUserEmail()); | 295 EXPECT_EQ("user1@test.com", observer()->active_account_id().GetUserEmail()); |
| 233 } | 296 } |
| 234 | 297 |
| 235 } // namespace | 298 } // namespace |
| 236 } // namespace ash | 299 } // namespace ash |
| OLD | NEW |