channel_indicator_quick_settings_view_unittest.cc 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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/channel_indicator/channel_indicator_quick_settings_view.h"
  5. #include "ash/constants/ash_features.h"
  6. #include "ash/public/cpp/test/test_system_tray_client.h"
  7. #include "ash/test/ash_test_base.h"
  8. #include "components/version_info/channel.h"
  9. namespace ash {
  10. class ChannelIndicatorQuickSettingsViewTest
  11. : public AshTestBase,
  12. public testing::WithParamInterface<bool> {
  13. public:
  14. ChannelIndicatorQuickSettingsViewTest() = default;
  15. ChannelIndicatorQuickSettingsViewTest(
  16. const ChannelIndicatorQuickSettingsViewTest&) = delete;
  17. ChannelIndicatorQuickSettingsViewTest& operator=(
  18. const ChannelIndicatorQuickSettingsViewTest&) = delete;
  19. ~ChannelIndicatorQuickSettingsViewTest() override = default;
  20. // AshTestBase:
  21. void SetUp() override {
  22. AshTestBase::SetUp();
  23. // Param is whether user feedback is allowed.
  24. system_tray_client_ = GetSystemTrayClient();
  25. system_tray_client_->set_user_feedback_enabled(GetParam());
  26. // Instantiate view.
  27. view_ = std::make_unique<ChannelIndicatorQuickSettingsView>(
  28. version_info::Channel::BETA,
  29. system_tray_client_->IsUserFeedbackEnabled());
  30. }
  31. bool IsFeedbackShown() {
  32. return system_tray_client_->IsUserFeedbackEnabled();
  33. }
  34. ChannelIndicatorQuickSettingsView* view() { return view_.get(); }
  35. private:
  36. TestSystemTrayClient* system_tray_client_;
  37. std::unique_ptr<ChannelIndicatorQuickSettingsView> view_;
  38. };
  39. // Run the `Visible` test below for each value of version_info::Channel.
  40. INSTANTIATE_TEST_SUITE_P(ChannelValues,
  41. ChannelIndicatorQuickSettingsViewTest,
  42. ::testing::Bool());
  43. TEST_P(ChannelIndicatorQuickSettingsViewTest, Visible) {
  44. // View exists.
  45. EXPECT_TRUE(view());
  46. // Version button is always visible.
  47. EXPECT_TRUE(view()->IsVersionButtonVisibleForTesting());
  48. // Feedback button is visible if `SystemTrayClient` says the user preference
  49. // is set that allows user feedback.
  50. EXPECT_EQ(view()->IsSubmitFeedbackButtonVisibleForTesting(),
  51. IsFeedbackShown());
  52. }
  53. } // namespace ash