ambient_animation_shield_controller_unittest.cc 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. // Copyright 2022 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/ambient/ui/ambient_animation_shield_controller.h"
  5. #include "ash/ambient/test/ambient_ash_test_base.h"
  6. #include "ash/ambient/ui/ambient_view_ids.h"
  7. #include "ash/style/dark_light_mode_controller_impl.h"
  8. #include "base/logging.h"
  9. #include "base/test/scoped_feature_list.h"
  10. #include "chromeos/constants/chromeos_features.h"
  11. #include "testing/gmock/include/gmock/gmock.h"
  12. #include "testing/gtest/include/gtest/gtest.h"
  13. #include "ui/views/view.h"
  14. namespace ash {
  15. namespace {
  16. using ::testing::IsNull;
  17. using ::testing::NotNull;
  18. } // namespace
  19. class AmbientAnimationShieldControllerTest : public AmbientAshTestBase {
  20. protected:
  21. void SetUp() override {
  22. enable_dark_light_.InitAndEnableFeature(chromeos::features::kDarkLightMode);
  23. AmbientAshTestBase::SetUp();
  24. }
  25. void SetDarkModeEnabled(bool dark_mode_enabled) {
  26. auto* dark_light_mode_controller = DarkLightModeControllerImpl::Get();
  27. CHECK(dark_light_mode_controller);
  28. if (dark_light_mode_controller->IsDarkModeEnabled() != dark_mode_enabled)
  29. dark_light_mode_controller->ToggleColorMode();
  30. }
  31. std::unique_ptr<views::View> CreateShieldView() {
  32. auto shield_view = std::make_unique<views::View>();
  33. shield_view->SetID(kAmbientShieldView);
  34. return shield_view;
  35. }
  36. base::test::ScopedFeatureList enable_dark_light_;
  37. views::View parent_view_;
  38. };
  39. TEST_F(AmbientAnimationShieldControllerTest, InitialDarkMode) {
  40. SetDarkModeEnabled(true);
  41. AmbientAnimationShieldController controller(CreateShieldView(),
  42. &parent_view_);
  43. EXPECT_THAT(parent_view_.GetViewByID(kAmbientShieldView), NotNull());
  44. }
  45. TEST_F(AmbientAnimationShieldControllerTest, InitialLightMode) {
  46. SetDarkModeEnabled(false);
  47. AmbientAnimationShieldController controller(CreateShieldView(),
  48. &parent_view_);
  49. EXPECT_THAT(parent_view_.GetViewByID(kAmbientShieldView), IsNull());
  50. }
  51. TEST_F(AmbientAnimationShieldControllerTest, TogglesShield) {
  52. SetDarkModeEnabled(true);
  53. AmbientAnimationShieldController controller(CreateShieldView(),
  54. &parent_view_);
  55. SetDarkModeEnabled(false);
  56. EXPECT_THAT(parent_view_.GetViewByID(kAmbientShieldView), IsNull());
  57. SetDarkModeEnabled(true);
  58. EXPECT_THAT(parent_view_.GetViewByID(kAmbientShieldView), NotNull());
  59. }
  60. } // namespace ash