| 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/session/session_controller.h" | 5 #include "ash/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> |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 | 84 |
| 85 void SetSessionInfo(const mojom::SessionInfo& info) { | 85 void SetSessionInfo(const mojom::SessionInfo& info) { |
| 86 mojom::SessionInfoPtr info_ptr = mojom::SessionInfo::New(); | 86 mojom::SessionInfoPtr info_ptr = mojom::SessionInfo::New(); |
| 87 *info_ptr = info; | 87 *info_ptr = info; |
| 88 controller_->SetSessionInfo(std::move(info_ptr)); | 88 controller_->SetSessionInfo(std::move(info_ptr)); |
| 89 } | 89 } |
| 90 | 90 |
| 91 void UpdateSession(uint32_t session_id, const std::string& email) { | 91 void UpdateSession(uint32_t session_id, const std::string& email) { |
| 92 mojom::UserSessionPtr session = mojom::UserSession::New(); | 92 mojom::UserSessionPtr session = mojom::UserSession::New(); |
| 93 session->session_id = session_id; | 93 session->session_id = session_id; |
| 94 session->type = user_manager::USER_TYPE_REGULAR; | 94 session->user_info = mojom::UserInfo::New(); |
| 95 session->account_id = AccountId::FromUserEmail(email); | 95 session->user_info->type = user_manager::USER_TYPE_REGULAR; |
| 96 session->display_name = email; | 96 session->user_info->account_id = AccountId::FromUserEmail(email); |
| 97 session->display_email = email; | 97 session->user_info->display_name = email; |
| 98 session->user_info->display_email = email; |
| 98 | 99 |
| 99 controller_->UpdateUserSession(std::move(session)); | 100 controller_->UpdateUserSession(std::move(session)); |
| 100 } | 101 } |
| 101 | 102 |
| 102 std::string GetUserSessionEmails() const { | 103 std::string GetUserSessionEmails() const { |
| 103 std::string emails; | 104 std::string emails; |
| 104 for (const auto& session : controller_->GetUserSessions()) { | 105 for (const auto& session : controller_->GetUserSessions()) { |
| 105 emails += session->display_email + ","; | 106 emails += session->user_info->display_email + ","; |
| 106 } | 107 } |
| 107 return emails; | 108 return emails; |
| 108 } | 109 } |
| 109 | 110 |
| 110 SessionController* controller() { return controller_.get(); } | 111 SessionController* controller() { return controller_.get(); } |
| 111 const TestSessionObserver* observer() const { return &observer_; } | 112 const TestSessionObserver* observer() const { return &observer_; } |
| 112 | 113 |
| 113 private: | 114 private: |
| 114 std::unique_ptr<SessionController> controller_; | 115 std::unique_ptr<SessionController> controller_; |
| 115 TestSessionObserver observer_; | 116 TestSessionObserver observer_; |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 {user_manager::USER_TYPE_SUPERVISED, LoginStatus::SUPERVISED}, | 250 {user_manager::USER_TYPE_SUPERVISED, LoginStatus::SUPERVISED}, |
| 250 {user_manager::USER_TYPE_KIOSK_APP, LoginStatus::KIOSK_APP}, | 251 {user_manager::USER_TYPE_KIOSK_APP, LoginStatus::KIOSK_APP}, |
| 251 {user_manager::USER_TYPE_CHILD, LoginStatus::SUPERVISED}, | 252 {user_manager::USER_TYPE_CHILD, LoginStatus::SUPERVISED}, |
| 252 {user_manager::USER_TYPE_ARC_KIOSK_APP, LoginStatus::ARC_KIOSK_APP}, | 253 {user_manager::USER_TYPE_ARC_KIOSK_APP, LoginStatus::ARC_KIOSK_APP}, |
| 253 // TODO: Add USER_TYPE_ACTIVE_DIRECTORY if we add a status for it. | 254 // TODO: Add USER_TYPE_ACTIVE_DIRECTORY if we add a status for it. |
| 254 }; | 255 }; |
| 255 | 256 |
| 256 for (const auto& test_case : kTestCases) { | 257 for (const auto& test_case : kTestCases) { |
| 257 mojom::UserSessionPtr session = mojom::UserSession::New(); | 258 mojom::UserSessionPtr session = mojom::UserSession::New(); |
| 258 session->session_id = 1u; | 259 session->session_id = 1u; |
| 259 session->type = test_case.user_type; | 260 session->user_info = mojom::UserInfo::New(); |
| 260 session->account_id = AccountId::FromUserEmail("user1@test.com"); | 261 session->user_info->type = test_case.user_type; |
| 261 session->display_name = "User 1"; | 262 session->user_info->account_id = AccountId::FromUserEmail("user1@test.com"); |
| 262 session->display_email = "user1@test.com"; | 263 session->user_info->display_name = "User 1"; |
| 264 session->user_info->display_email = "user1@test.com"; |
| 263 controller()->UpdateUserSession(std::move(session)); | 265 controller()->UpdateUserSession(std::move(session)); |
| 264 | 266 |
| 265 EXPECT_EQ(test_case.expected_status, controller()->login_status()) | 267 EXPECT_EQ(test_case.expected_status, controller()->login_status()) |
| 266 << "Test case user_type=" << static_cast<int>(test_case.user_type); | 268 << "Test case user_type=" << static_cast<int>(test_case.user_type); |
| 267 } | 269 } |
| 268 } | 270 } |
| 269 | 271 |
| 270 // Tests that user sessions can be set and updated. | 272 // Tests that user sessions can be set and updated. |
| 271 TEST_F(SessionControllerTest, UserSessions) { | 273 TEST_F(SessionControllerTest, UserSessions) { |
| 272 EXPECT_FALSE(controller()->IsActiveUserSessionStarted()); | 274 EXPECT_FALSE(controller()->IsActiveUserSessionStarted()); |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 342 | 344 |
| 343 EXPECT_EQ(test_case.expected_is_user_session_blocked, | 345 EXPECT_EQ(test_case.expected_is_user_session_blocked, |
| 344 controller()->IsUserSessionBlocked()) | 346 controller()->IsUserSessionBlocked()) |
| 345 << "Test case state=" << static_cast<int>(test_case.state); | 347 << "Test case state=" << static_cast<int>(test_case.state); |
| 346 } | 348 } |
| 347 } | 349 } |
| 348 | 350 |
| 349 TEST_F(SessionControllerTest, IsUserSupervised) { | 351 TEST_F(SessionControllerTest, IsUserSupervised) { |
| 350 mojom::UserSessionPtr session = mojom::UserSession::New(); | 352 mojom::UserSessionPtr session = mojom::UserSession::New(); |
| 351 session->session_id = 1u; | 353 session->session_id = 1u; |
| 352 session->type = user_manager::USER_TYPE_SUPERVISED; | 354 session->user_info = mojom::UserInfo::New(); |
| 355 session->user_info->type = user_manager::USER_TYPE_SUPERVISED; |
| 353 controller()->UpdateUserSession(std::move(session)); | 356 controller()->UpdateUserSession(std::move(session)); |
| 354 | 357 |
| 355 EXPECT_TRUE(controller()->IsUserSupervised()); | 358 EXPECT_TRUE(controller()->IsUserSupervised()); |
| 356 } | 359 } |
| 357 | 360 |
| 358 TEST_F(SessionControllerTest, IsUserChild) { | 361 TEST_F(SessionControllerTest, IsUserChild) { |
| 359 mojom::UserSessionPtr session = mojom::UserSession::New(); | 362 mojom::UserSessionPtr session = mojom::UserSession::New(); |
| 360 session->session_id = 1u; | 363 session->session_id = 1u; |
| 361 session->type = user_manager::USER_TYPE_CHILD; | 364 session->user_info = mojom::UserInfo::New(); |
| 365 session->user_info->type = user_manager::USER_TYPE_CHILD; |
| 362 controller()->UpdateUserSession(std::move(session)); | 366 controller()->UpdateUserSession(std::move(session)); |
| 363 | 367 |
| 364 EXPECT_TRUE(controller()->IsUserChild()); | 368 EXPECT_TRUE(controller()->IsUserChild()); |
| 365 | 369 |
| 366 // Child accounts are supervised. | 370 // Child accounts are supervised. |
| 367 EXPECT_TRUE(controller()->IsUserSupervised()); | 371 EXPECT_TRUE(controller()->IsUserSupervised()); |
| 368 } | 372 } |
| 369 | 373 |
| 370 } // namespace | 374 } // namespace |
| 371 } // namespace ash | 375 } // namespace ash |
| OLD | NEW |