user_chooser_detailed_view_controller_unittest.cc 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. // Copyright 2019 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "ash/system/unified/user_chooser_detailed_view_controller.h"
  5. #include <memory>
  6. #include "ash/public/cpp/ash_view_ids.h"
  7. #include "ash/public/cpp/system_tray_test_api.h"
  8. #include "ash/root_window_controller.h"
  9. #include "ash/session/session_controller_impl.h"
  10. #include "ash/shell.h"
  11. #include "ash/system/unified/unified_system_tray.h"
  12. #include "ash/test/ash_test_base.h"
  13. #include "ash/wm/overview/overview_controller.h"
  14. #include "components/account_id/account_id.h"
  15. #include "ui/compositor/scoped_animation_duration_scale_mode.h"
  16. #include "ui/views/widget/widget.h"
  17. namespace ash {
  18. namespace {
  19. AccountId GetActiveUser() {
  20. return Shell::Get()
  21. ->session_controller()
  22. ->GetUserSession(/*user_index=*/0)
  23. ->user_info.account_id;
  24. }
  25. } // namespace
  26. class UserChooserDetailedViewControllerTest : public AshTestBase {
  27. public:
  28. UserChooserDetailedViewControllerTest() = default;
  29. UserChooserDetailedViewControllerTest(
  30. const UserChooserDetailedViewControllerTest&) = delete;
  31. UserChooserDetailedViewControllerTest& operator=(
  32. const UserChooserDetailedViewControllerTest&) = delete;
  33. ~UserChooserDetailedViewControllerTest() override = default;
  34. // AshTestBase
  35. void SetUp() override {
  36. AshTestBase::SetUp();
  37. tray_test_api_ = std::make_unique<SystemTrayTestApi>();
  38. disable_animations_ =
  39. std::make_unique<ui::ScopedAnimationDurationScaleMode>(
  40. ui::ScopedAnimationDurationScaleMode::ZERO_DURATION);
  41. }
  42. SystemTrayTestApi* tray_test_api() { return tray_test_api_.get(); }
  43. private:
  44. std::unique_ptr<ui::ScopedAnimationDurationScaleMode> disable_animations_;
  45. std::unique_ptr<SystemTrayTestApi> tray_test_api_;
  46. };
  47. TEST_F(UserChooserDetailedViewControllerTest,
  48. ShowMultiProfileLoginWithOverview) {
  49. // Enter overview mode.
  50. EnterOverview();
  51. ASSERT_TRUE(Shell::Get()->overview_controller()->InOverviewSession());
  52. // Show system tray.
  53. tray_test_api()->ShowBubble();
  54. ASSERT_TRUE(tray_test_api()->IsTrayBubbleOpen());
  55. // Click on user avatar button to start user adding.
  56. ASSERT_TRUE(tray_test_api()->IsBubbleViewVisible(VIEW_ID_USER_AVATAR_BUTTON,
  57. /*open_tray=*/false));
  58. tray_test_api()->ClickBubbleView(VIEW_ID_USER_AVATAR_BUTTON);
  59. // Click on add user button to show multi profile login window.
  60. ASSERT_TRUE(tray_test_api()->IsBubbleViewVisible(VIEW_ID_ADD_USER_BUTTON,
  61. /*open_tray=*/false));
  62. tray_test_api()->ClickBubbleView(VIEW_ID_ADD_USER_BUTTON);
  63. }
  64. TEST_F(UserChooserDetailedViewControllerTest, SwitchUserWithOverview) {
  65. // Add a secondary user.
  66. const AccountId secondary_user =
  67. AccountId::FromUserEmail("secondary@gmail.com");
  68. GetSessionControllerClient()->AddUserSession(secondary_user.GetUserEmail());
  69. ASSERT_NE(GetActiveUser(), secondary_user);
  70. // Create an activatable widget.
  71. std::unique_ptr<views::Widget> widget = CreateTestWidget();
  72. // Enter overview mode.
  73. EnterOverview();
  74. ASSERT_TRUE(Shell::Get()->overview_controller()->InOverviewSession());
  75. // Show system tray.
  76. tray_test_api()->ShowBubble();
  77. ASSERT_TRUE(tray_test_api()->IsTrayBubbleOpen());
  78. // Click on user avatar button to select user.
  79. ASSERT_TRUE(tray_test_api()->IsBubbleViewVisible(VIEW_ID_USER_AVATAR_BUTTON,
  80. /*open_tray=*/false));
  81. tray_test_api()->ClickBubbleView(VIEW_ID_USER_AVATAR_BUTTON);
  82. const int secondary_user_button_id = VIEW_ID_USER_ITEM_BUTTON_START + 1;
  83. ASSERT_TRUE(tray_test_api()->IsBubbleViewVisible(secondary_user_button_id,
  84. /*open_tray=*/false));
  85. tray_test_api()->ClickBubbleView(secondary_user_button_id);
  86. // Active user is switched.
  87. EXPECT_EQ(GetActiveUser(), secondary_user);
  88. }
  89. TEST_F(UserChooserDetailedViewControllerTest,
  90. MultiProfileLoginDisabledForFamilyLinkUsers) {
  91. EXPECT_TRUE(UserChooserDetailedViewController::IsUserChooserEnabled());
  92. GetSessionControllerClient()->Reset();
  93. // Log in as a child user.
  94. SimulateUserLogin("child@gmail.com", user_manager::USER_TYPE_CHILD);
  95. EXPECT_FALSE(UserChooserDetailedViewController::IsUserChooserEnabled());
  96. }
  97. } // namespace ash