notifier_settings_view_unittest.cc 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. // Copyright 2013 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/message_center/notifier_settings_view.h"
  5. #include <stddef.h>
  6. #include <memory>
  7. #include "ash/constants/ash_features.h"
  8. #include "ash/public/cpp/notifier_settings_controller.h"
  9. #include "ash/shell.h"
  10. #include "ash/system/message_center/test_notifier_settings_controller.h"
  11. #include "ash/test/ash_test_base.h"
  12. #include "ash/test/ash_test_helper.h"
  13. #include "base/run_loop.h"
  14. #include "base/test/scoped_feature_list.h"
  15. namespace ash {
  16. using message_center::NotifierId;
  17. class NotifierSettingsViewTest : public AshTestBase {
  18. public:
  19. NotifierSettingsViewTest();
  20. NotifierSettingsViewTest(const NotifierSettingsViewTest&) = delete;
  21. NotifierSettingsViewTest& operator=(const NotifierSettingsViewTest&) = delete;
  22. ~NotifierSettingsViewTest() override;
  23. void SetNoNotifiers(bool no_notifiers) {
  24. ash_test_helper()->notifier_settings_controller()->set_no_notifiers(
  25. no_notifiers);
  26. }
  27. };
  28. NotifierSettingsViewTest::NotifierSettingsViewTest() = default;
  29. NotifierSettingsViewTest::~NotifierSettingsViewTest() = default;
  30. TEST_F(NotifierSettingsViewTest, TestEmptyNotifierView) {
  31. SetNoNotifiers(false);
  32. auto notifier_settings_view = std::make_unique<NotifierSettingsView>();
  33. // Wait for mojo.
  34. base::RunLoop().RunUntilIdle();
  35. EXPECT_FALSE(notifier_settings_view->no_notifiers_view_->GetVisible());
  36. EXPECT_TRUE(notifier_settings_view->top_label_->GetVisible());
  37. SetNoNotifiers(true);
  38. notifier_settings_view = std::make_unique<NotifierSettingsView>();
  39. // Wait for mojo.
  40. base::RunLoop().RunUntilIdle();
  41. EXPECT_TRUE(notifier_settings_view->no_notifiers_view_->GetVisible());
  42. EXPECT_FALSE(notifier_settings_view->top_label_->GetVisible());
  43. }
  44. // Tests the notifier settings view with kSettingsAppNotificationSettings
  45. // enabled/disabled.
  46. class NotifierSettingsViewSettingsAppNotificationTest
  47. : public NotifierSettingsViewTest,
  48. public testing::WithParamInterface<bool> {
  49. public:
  50. NotifierSettingsViewSettingsAppNotificationTest() = default;
  51. NotifierSettingsViewSettingsAppNotificationTest(
  52. const NotifierSettingsViewSettingsAppNotificationTest&) = delete;
  53. NotifierSettingsViewSettingsAppNotificationTest& operator=(
  54. const NotifierSettingsViewSettingsAppNotificationTest&) = delete;
  55. ~NotifierSettingsViewSettingsAppNotificationTest() = default;
  56. void SetUp() override {
  57. feature_list_.InitWithFeatureState(
  58. features::kSettingsAppNotificationSettings, GetParam());
  59. NotifierSettingsViewTest::SetUp();
  60. }
  61. bool IsSettingsAppNotificationSettingsEnabled() { return GetParam(); }
  62. private:
  63. base::test::ScopedFeatureList feature_list_;
  64. };
  65. INSTANTIATE_TEST_SUITE_P(All,
  66. NotifierSettingsViewSettingsAppNotificationTest,
  67. testing::Bool());
  68. TEST_P(NotifierSettingsViewSettingsAppNotificationTest,
  69. NotificationSettingsLabelTest) {
  70. auto notifier_settings_view = std::make_unique<NotifierSettingsView>();
  71. EXPECT_TRUE(notifier_settings_view->get_quiet_mode_icon_view_for_test());
  72. EXPECT_TRUE(notifier_settings_view->get_quiet_mode_toggle_for_test());
  73. EXPECT_EQ(
  74. IsSettingsAppNotificationSettingsEnabled(),
  75. !!notifier_settings_view->get_notification_settings_lable_for_test());
  76. EXPECT_NE(IsSettingsAppNotificationSettingsEnabled(),
  77. !!notifier_settings_view->get_scroller_view_for_test());
  78. }
  79. } // namespace ash