keyboard_backlight_color_nudge_controller_unittest.cc 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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/keyboard_brightness/keyboard_backlight_color_nudge_controller.h"
  5. #include "ash/constants/ash_features.h"
  6. #include "ash/controls/contextual_tooltip.h"
  7. #include "ash/session/session_controller_impl.h"
  8. #include "ash/shell.h"
  9. #include "ash/system/keyboard_brightness/keyboard_backlight_color_controller.h"
  10. #include "ash/test/ash_test_base.h"
  11. #include "base/test/scoped_feature_list.h"
  12. #include "base/test/task_environment.h"
  13. #include "components/account_id/account_id.h"
  14. #include "testing/gtest/include/gtest/gtest.h"
  15. namespace ash {
  16. namespace {
  17. constexpr char kUser1[] = "user1@test.com";
  18. const AccountId account_id_1 = AccountId::FromUserEmailGaiaId(kUser1, kUser1);
  19. } // namespace
  20. class KeyboardBacklightColorNudgeControllerTest : public AshTestBase {
  21. public:
  22. KeyboardBacklightColorNudgeControllerTest()
  23. : AshTestBase(base::test::TaskEnvironment::TimeSource::MOCK_TIME),
  24. scoped_feature_list_(features::kRgbKeyboard) {}
  25. KeyboardBacklightColorNudgeControllerTest(
  26. const KeyboardBacklightColorNudgeControllerTest&) = delete;
  27. KeyboardBacklightColorNudgeControllerTest& operator=(
  28. const KeyboardBacklightColorNudgeControllerTest&) = delete;
  29. ~KeyboardBacklightColorNudgeControllerTest() override = default;
  30. // testing::Test:
  31. void SetUp() override {
  32. AshTestBase::SetUp();
  33. controller_ = Shell::Get()
  34. ->keyboard_backlight_color_controller()
  35. ->keyboard_backlight_color_nudge_controller();
  36. }
  37. protected:
  38. KeyboardBacklightColorNudgeController* controller_ = nullptr;
  39. PrefService* pref_service() {
  40. return Shell::Get()->session_controller()->GetActivePrefService();
  41. }
  42. bool can_show_nudge() {
  43. return contextual_tooltip::ShouldShowNudge(
  44. pref_service(),
  45. contextual_tooltip::TooltipType::kKeyboardBacklightColor, nullptr);
  46. }
  47. private:
  48. base::test::ScopedFeatureList scoped_feature_list_;
  49. };
  50. TEST_F(KeyboardBacklightColorNudgeControllerTest, ShowEducationNudge) {
  51. // Create a dummy anchor view for the bubble.
  52. views::View anchor_view;
  53. anchor_view.SetBounds(200, 200, 10, 10);
  54. SimulateUserLogin(account_id_1);
  55. EXPECT_TRUE(can_show_nudge());
  56. controller_->MaybeShowEducationNudge(&anchor_view);
  57. EXPECT_FALSE(can_show_nudge());
  58. // Fast forward to the next 1 day.
  59. task_environment()->FastForwardBy(base::Days(1));
  60. EXPECT_TRUE(can_show_nudge());
  61. }
  62. TEST_F(KeyboardBacklightColorNudgeControllerTest,
  63. WontShowNudgeAfterUserSelectsColor) {
  64. SimulateUserLogin(account_id_1);
  65. EXPECT_TRUE(can_show_nudge());
  66. controller_->SetUserPerformedAction();
  67. EXPECT_FALSE(can_show_nudge());
  68. // Fast forward to the next 1 day. Still can't show nudge.
  69. task_environment()->FastForwardBy(base::Days(1));
  70. EXPECT_FALSE(can_show_nudge());
  71. }
  72. } // namespace ash