quiet_mode_feature_pod_controller_unittest.cc 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. // Copyright 2018 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/quiet_mode_feature_pod_controller.h"
  5. #include "ash/system/unified/feature_pod_button.h"
  6. #include "ash/system/unified/unified_system_tray_controller.h"
  7. #include "ash/system/unified/unified_system_tray_model.h"
  8. #include "ash/test/ash_test_base.h"
  9. #include "base/memory/scoped_refptr.h"
  10. namespace ash {
  11. // Tests manually control their session state.
  12. class QuietModeFeaturePodControllerTest : public NoSessionAshTestBase {
  13. public:
  14. QuietModeFeaturePodControllerTest() = default;
  15. QuietModeFeaturePodControllerTest(const QuietModeFeaturePodControllerTest&) =
  16. delete;
  17. QuietModeFeaturePodControllerTest& operator=(
  18. const QuietModeFeaturePodControllerTest&) = delete;
  19. ~QuietModeFeaturePodControllerTest() override = default;
  20. void SetUp() override {
  21. NoSessionAshTestBase::SetUp();
  22. tray_model_ = base::MakeRefCounted<UnifiedSystemTrayModel>(nullptr);
  23. tray_controller_ =
  24. std::make_unique<UnifiedSystemTrayController>(tray_model_.get());
  25. }
  26. void TearDown() override {
  27. button_.reset();
  28. controller_.reset();
  29. tray_controller_.reset();
  30. tray_model_.reset();
  31. NoSessionAshTestBase::TearDown();
  32. }
  33. protected:
  34. void SetUpButton() {
  35. controller_ =
  36. std::make_unique<QuietModeFeaturePodController>(tray_controller());
  37. button_.reset(controller_->CreateButton());
  38. }
  39. UnifiedSystemTrayController* tray_controller() {
  40. return tray_controller_.get();
  41. }
  42. FeaturePodButton* button() { return button_.get(); }
  43. private:
  44. scoped_refptr<UnifiedSystemTrayModel> tray_model_;
  45. std::unique_ptr<UnifiedSystemTrayController> tray_controller_;
  46. std::unique_ptr<QuietModeFeaturePodController> controller_;
  47. std::unique_ptr<FeaturePodButton> button_;
  48. };
  49. TEST_F(QuietModeFeaturePodControllerTest, ButtonVisibilityNotLoggedIn) {
  50. SetUpButton();
  51. // If not logged in, it should not be visible.
  52. EXPECT_FALSE(button()->GetVisible());
  53. }
  54. TEST_F(QuietModeFeaturePodControllerTest, ButtonVisibilityLoggedIn) {
  55. CreateUserSessions(1);
  56. SetUpButton();
  57. // If logged in, it should be visible.
  58. EXPECT_TRUE(button()->GetVisible());
  59. }
  60. TEST_F(QuietModeFeaturePodControllerTest, ButtonVisibilityLocked) {
  61. CreateUserSessions(1);
  62. BlockUserSession(UserSessionBlockReason::BLOCKED_BY_LOCK_SCREEN);
  63. SetUpButton();
  64. // If locked, it should not be visible.
  65. EXPECT_FALSE(button()->GetVisible());
  66. }
  67. } // namespace ash