channel_indicator_utils_unittest.cc 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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_utils.h"
  5. #include <string>
  6. #include "ash/public/cpp/style/dark_light_mode_controller.h"
  7. #include "ash/strings/grit/ash_strings.h"
  8. #include "ash/test/ash_test_base.h"
  9. #include "ash/test_shell_delegate.h"
  10. #include "components/version_info/channel.h"
  11. #include "ui/gfx/color_palette.h"
  12. namespace ash {
  13. namespace {
  14. // OS version that's set, and final button string that's expected.
  15. const char* kTestOsVersion = "123.45.6789.10";
  16. const char16_t* kTestButtonStr = u"Beta 123.45.6789.10";
  17. } // namespace
  18. class ChannelIndicatorUtilsTest : public AshTestBase {
  19. public:
  20. ChannelIndicatorUtilsTest() = default;
  21. ChannelIndicatorUtilsTest(const ChannelIndicatorUtilsTest&) = delete;
  22. ChannelIndicatorUtilsTest& operator=(const ChannelIndicatorUtilsTest&) =
  23. delete;
  24. ~ChannelIndicatorUtilsTest() override = default;
  25. // AshTestBase:
  26. void SetUp() override {
  27. // Instantiate a `TestShellDelegate` with the version set to something
  28. // tests can verify.
  29. std::unique_ptr<TestShellDelegate> shell_delegate =
  30. std::make_unique<TestShellDelegate>();
  31. shell_delegate->set_version_string(kTestOsVersion);
  32. AshTestBase::SetUp(std::move(shell_delegate));
  33. }
  34. };
  35. TEST_F(ChannelIndicatorUtilsTest, IsDisplayableChannel) {
  36. EXPECT_FALSE(channel_indicator_utils::IsDisplayableChannel(
  37. version_info::Channel::UNKNOWN));
  38. EXPECT_TRUE(channel_indicator_utils::IsDisplayableChannel(
  39. version_info::Channel::CANARY));
  40. EXPECT_TRUE(channel_indicator_utils::IsDisplayableChannel(
  41. version_info::Channel::DEV));
  42. EXPECT_TRUE(channel_indicator_utils::IsDisplayableChannel(
  43. version_info::Channel::BETA));
  44. EXPECT_FALSE(channel_indicator_utils::IsDisplayableChannel(
  45. version_info::Channel::STABLE));
  46. }
  47. TEST_F(ChannelIndicatorUtilsTest, GetChannelNameStringResourceID) {
  48. // Non-displayable channel should yield a resource_id of -1.
  49. EXPECT_EQ(channel_indicator_utils::GetChannelNameStringResourceID(
  50. version_info::Channel::STABLE, false),
  51. -1);
  52. // Same thing if `append_channel` is `true`.
  53. EXPECT_EQ(channel_indicator_utils::GetChannelNameStringResourceID(
  54. version_info::Channel::STABLE, true),
  55. -1);
  56. // Displayable channel should yield a valid resource_id.
  57. EXPECT_EQ(channel_indicator_utils::GetChannelNameStringResourceID(
  58. version_info::Channel::BETA, false),
  59. IDS_ASH_STATUS_TRAY_CHANNEL_BETA);
  60. // An equally-valid resource_id if `append_channel` is `true`.
  61. EXPECT_EQ(channel_indicator_utils::GetChannelNameStringResourceID(
  62. version_info::Channel::BETA, true),
  63. IDS_ASH_STATUS_TRAY_CHANNEL_BETA_CHANNEL);
  64. }
  65. TEST_F(ChannelIndicatorUtilsTest, GetColors) {
  66. // Non-displayable channel should yield fg/bg colors of 0.
  67. EXPECT_EQ(channel_indicator_utils::GetFgColor(version_info::Channel::STABLE),
  68. SkColorSetRGB(0x00, 0x00, 0x00));
  69. EXPECT_EQ(channel_indicator_utils::GetBgColor(version_info::Channel::STABLE),
  70. SkColorSetRGB(0x00, 0x00, 0x00));
  71. // Displayable channel should yield valid, nonzero fg/bg colors. Check with
  72. // dark mode not enabled first.
  73. DarkLightModeController::Get()->SetDarkModeEnabledForTest(false);
  74. EXPECT_EQ(channel_indicator_utils::GetFgColor(version_info::Channel::BETA),
  75. gfx::kGoogleBlue900);
  76. EXPECT_EQ(channel_indicator_utils::GetBgColor(version_info::Channel::BETA),
  77. gfx::kGoogleBlue200);
  78. // Check with dark mode enabled.
  79. DarkLightModeController::Get()->SetDarkModeEnabledForTest(true);
  80. EXPECT_EQ(channel_indicator_utils::GetFgColor(version_info::Channel::BETA),
  81. gfx::kGoogleBlue200);
  82. EXPECT_EQ(channel_indicator_utils::GetBgColor(version_info::Channel::BETA),
  83. SkColorSetA(gfx::kGoogleBlue300, 0x55));
  84. }
  85. TEST_F(ChannelIndicatorUtilsTest, GetFullReleaseTrackString) {
  86. // Channel is not displayable, no string.
  87. EXPECT_TRUE(channel_indicator_utils::GetFullReleaseTrackString(
  88. version_info::Channel::STABLE)
  89. .empty());
  90. // Channel is displayable, string that's expected.
  91. EXPECT_EQ(channel_indicator_utils::GetFullReleaseTrackString(
  92. version_info::Channel::BETA),
  93. kTestButtonStr);
  94. }
  95. } // namespace ash