dark_mode_feature_pod_controller_unittest.cc 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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/system/dark_mode/dark_mode_feature_pod_controller.h"
  5. #include "ash/session/session_controller_impl.h"
  6. #include "ash/shell.h"
  7. #include "ash/style/dark_light_mode_controller_impl.h"
  8. #include "ash/system/unified/feature_pod_button.h"
  9. #include "ash/system/unified/unified_system_tray.h"
  10. #include "ash/system/unified/unified_system_tray_bubble.h"
  11. #include "ash/test/ash_test_base.h"
  12. #include "base/test/scoped_feature_list.h"
  13. #include "chromeos/constants/chromeos_features.h"
  14. namespace ash {
  15. using DarkModeFeaturePodControllerTest = AshTestBase;
  16. // Tests that toggling dark mode from the system tray disables auto scheduling
  17. // and switches the color mode properly.
  18. TEST_F(DarkModeFeaturePodControllerTest, ToggleDarkMode) {
  19. base::test::ScopedFeatureList feature_list;
  20. feature_list.InitAndEnableFeature(chromeos::features::kDarkLightMode);
  21. auto* dark_light_mode_controller = DarkLightModeControllerImpl::Get();
  22. dark_light_mode_controller->OnActiveUserPrefServiceChanged(
  23. Shell::Get()->session_controller()->GetActivePrefService());
  24. UnifiedSystemTray* system_tray = GetPrimaryUnifiedSystemTray();
  25. system_tray->ShowBubble();
  26. std::unique_ptr<DarkModeFeaturePodController>
  27. dark_mode_feature_pod_controller =
  28. std::make_unique<DarkModeFeaturePodController>(
  29. system_tray->bubble()->unified_system_tray_controller());
  30. std::unique_ptr<FeaturePodButton> button(
  31. dark_mode_feature_pod_controller->CreateButton());
  32. // Enable dark mode auto scheduling.
  33. auto* controller = Shell::Get()->dark_light_mode_controller();
  34. controller->SetAutoScheduleEnabled(true);
  35. EXPECT_TRUE(controller->GetAutoScheduleEnabled());
  36. // Check that the statuses of toggle and dark mode are consistent.
  37. bool dark_mode_enabled = dark_light_mode_controller->IsDarkModeEnabled();
  38. EXPECT_EQ(dark_mode_enabled, button->IsToggled());
  39. // Pressing the dark mode button should disable the scheduling and switch the
  40. // dark mode status.
  41. dark_mode_feature_pod_controller->OnIconPressed();
  42. EXPECT_FALSE(controller->GetAutoScheduleEnabled());
  43. EXPECT_EQ(!dark_mode_enabled,
  44. dark_light_mode_controller->IsDarkModeEnabled());
  45. EXPECT_EQ(!dark_mode_enabled, button->IsToggled());
  46. // Pressing the dark mode button again should only switch the dark mode status
  47. // while maintaining the disabled status of scheduling.
  48. dark_mode_feature_pod_controller->OnIconPressed();
  49. EXPECT_FALSE(controller->GetAutoScheduleEnabled());
  50. EXPECT_EQ(dark_mode_enabled, dark_light_mode_controller->IsDarkModeEnabled());
  51. EXPECT_EQ(dark_mode_enabled, button->IsToggled());
  52. system_tray->CloseBubble();
  53. }
  54. } // namespace ash