rotation_lock_feature_pod_controller_unittest.cc 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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/rotation/rotation_lock_feature_pod_controller.h"
  5. #include "ash/shell.h"
  6. #include "ash/system/unified/feature_pod_button.h"
  7. #include "ash/test/ash_test_base.h"
  8. #include "ash/wm/tablet_mode/tablet_mode_controller.h"
  9. #include "base/command_line.h"
  10. #include "ui/display/display_switches.h"
  11. namespace ash {
  12. class RotationLockFeaturePodControllerTest : public AshTestBase {
  13. public:
  14. RotationLockFeaturePodControllerTest() = default;
  15. RotationLockFeaturePodControllerTest(
  16. const RotationLockFeaturePodControllerTest&) = delete;
  17. RotationLockFeaturePodControllerTest& operator=(
  18. const RotationLockFeaturePodControllerTest&) = delete;
  19. ~RotationLockFeaturePodControllerTest() override = default;
  20. // AshTestBase:
  21. void SetUp() override;
  22. void TearDown() override;
  23. protected:
  24. void SetUpController();
  25. RotationLockFeaturePodController* controller() const {
  26. return controller_.get();
  27. }
  28. FeaturePodButton* button_view() const { return button_view_.get(); }
  29. private:
  30. std::unique_ptr<RotationLockFeaturePodController> controller_;
  31. std::unique_ptr<FeaturePodButton> button_view_;
  32. };
  33. void RotationLockFeaturePodControllerTest::SetUp() {
  34. // The Display used for testing is not an internal display. This flag
  35. // allows for DisplayManager to treat it as one.
  36. base::CommandLine::ForCurrentProcess()->AppendSwitch(
  37. ::switches::kUseFirstDisplayAsInternal);
  38. AshTestBase::SetUp();
  39. }
  40. void RotationLockFeaturePodControllerTest::TearDown() {
  41. controller_.reset();
  42. button_view_.reset();
  43. AshTestBase::TearDown();
  44. }
  45. void RotationLockFeaturePodControllerTest::SetUpController() {
  46. controller_ = std::make_unique<RotationLockFeaturePodController>();
  47. button_view_.reset(controller_->CreateButton());
  48. }
  49. // Tests that when the button is initially created, that it is created
  50. // not visible.
  51. TEST_F(RotationLockFeaturePodControllerTest, CreateButton) {
  52. SetUpController();
  53. EXPECT_FALSE(button_view()->GetVisible());
  54. }
  55. // Tests that when the button is created, while TabletMode is active,
  56. // that it is visible.
  57. TEST_F(RotationLockFeaturePodControllerTest, CreateButtonDuringTabletMode) {
  58. Shell::Get()->tablet_mode_controller()->SetEnabledForTest(true);
  59. SetUpController();
  60. EXPECT_TRUE(button_view()->GetVisible());
  61. Shell::Get()->tablet_mode_controller()->SetEnabledForTest(false);
  62. EXPECT_FALSE(button_view()->GetVisible());
  63. }
  64. // Tests that the enabling of TabletMode affects a previously created default
  65. // view, changing the visibility.
  66. TEST_F(RotationLockFeaturePodControllerTest,
  67. ButtonVisibilityChangesDuringTabletMode) {
  68. SetUpController();
  69. Shell::Get()->tablet_mode_controller()->SetEnabledForTest(true);
  70. EXPECT_TRUE(button_view()->GetVisible());
  71. Shell::Get()->tablet_mode_controller()->SetEnabledForTest(false);
  72. EXPECT_FALSE(button_view()->GetVisible());
  73. }
  74. TEST_F(RotationLockFeaturePodControllerTest, OnIconPressed) {
  75. SetUpController();
  76. TabletModeController* tablet_mode_controller =
  77. Shell::Get()->tablet_mode_controller();
  78. ScreenOrientationController* screen_orientation_controller =
  79. Shell::Get()->screen_orientation_controller();
  80. ASSERT_FALSE(screen_orientation_controller->rotation_locked());
  81. tablet_mode_controller->SetEnabledForTest(true);
  82. ASSERT_TRUE(button_view()->GetVisible());
  83. EXPECT_FALSE(button_view()->IsToggled());
  84. controller()->OnIconPressed();
  85. EXPECT_TRUE(screen_orientation_controller->rotation_locked());
  86. EXPECT_TRUE(button_view()->GetVisible());
  87. EXPECT_TRUE(button_view()->IsToggled());
  88. controller()->OnIconPressed();
  89. EXPECT_FALSE(screen_orientation_controller->rotation_locked());
  90. EXPECT_TRUE(button_view()->GetVisible());
  91. EXPECT_FALSE(button_view()->IsToggled());
  92. tablet_mode_controller->SetEnabledForTest(false);
  93. }
  94. } // namespace ash