File: channel_indicator_utils_unittest.cc

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (112 lines) | stat: -rw-r--r-- 4,156 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
// Copyright 2022 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "ash/system/channel_indicator/channel_indicator_utils.h"

#include <string>

#include "ash/public/cpp/style/dark_light_mode_controller.h"
#include "ash/strings/grit/ash_strings.h"
#include "ash/test/ash_test_base.h"
#include "ash/test_shell_delegate.h"
#include "components/version_info/channel.h"
#include "ui/chromeos/styles/cros_tokens_color_mappings.h"
#include "ui/color/color_id.h"
#include "ui/gfx/color_palette.h"

namespace ash {
namespace {

// OS version that's set, and final button string that's expected.
const char* kTestOsVersion = "123.45.6789.10";
const char16_t* kTestButtonStr = u"Beta 123.45.6789.10";

}  // namespace

class ChannelIndicatorUtilsTest : public AshTestBase {
 public:
  ChannelIndicatorUtilsTest() = default;
  ChannelIndicatorUtilsTest(const ChannelIndicatorUtilsTest&) = delete;
  ChannelIndicatorUtilsTest& operator=(const ChannelIndicatorUtilsTest&) =
      delete;
  ~ChannelIndicatorUtilsTest() override = default;

  // AshTestBase:
  void SetUp() override {
    // Instantiate a `TestShellDelegate` with the version set to something
    // tests can verify.
    std::unique_ptr<TestShellDelegate> shell_delegate =
        std::make_unique<TestShellDelegate>();
    shell_delegate->set_version_string(kTestOsVersion);
    set_shell_delegate(std::move(shell_delegate));
    AshTestBase::SetUp();
  }
};

TEST_F(ChannelIndicatorUtilsTest, IsDisplayableChannel) {
  EXPECT_FALSE(channel_indicator_utils::IsDisplayableChannel(
      version_info::Channel::UNKNOWN));
  EXPECT_TRUE(channel_indicator_utils::IsDisplayableChannel(
      version_info::Channel::CANARY));
  EXPECT_TRUE(channel_indicator_utils::IsDisplayableChannel(
      version_info::Channel::DEV));
  EXPECT_TRUE(channel_indicator_utils::IsDisplayableChannel(
      version_info::Channel::BETA));
  EXPECT_FALSE(channel_indicator_utils::IsDisplayableChannel(
      version_info::Channel::STABLE));
}

TEST_F(ChannelIndicatorUtilsTest, GetChannelNameStringResourceID) {
  // Non-displayable channel should yield a resource_id of -1.
  EXPECT_EQ(channel_indicator_utils::GetChannelNameStringResourceID(
                version_info::Channel::STABLE, false),
            -1);

  // Same thing if `append_channel` is `true`.
  EXPECT_EQ(channel_indicator_utils::GetChannelNameStringResourceID(
                version_info::Channel::STABLE, true),
            -1);

  // Displayable channel should yield a valid resource_id.
  EXPECT_EQ(channel_indicator_utils::GetChannelNameStringResourceID(
                version_info::Channel::BETA, false),
            IDS_ASH_STATUS_TRAY_CHANNEL_BETA);

  // An equally-valid resource_id if `append_channel` is `true`.
  EXPECT_EQ(channel_indicator_utils::GetChannelNameStringResourceID(
                version_info::Channel::BETA, true),
            IDS_ASH_STATUS_TRAY_CHANNEL_BETA_CHANNEL);
}

TEST_F(ChannelIndicatorUtilsTest, GetColors) {
  // Non-displayable channel should yield fg/bg `ColorId` of `ui::ColorId()`.
  EXPECT_EQ(
      channel_indicator_utils::GetFgColorJelly(version_info::Channel::STABLE),
      ui::ColorId());
  EXPECT_EQ(
      channel_indicator_utils::GetBgColorJelly(version_info::Channel::STABLE),
      ui::ColorId());

  // Displayable channel should yield valid, fg/bg `ColorId`s.
  EXPECT_EQ(
      channel_indicator_utils::GetFgColorJelly(version_info::Channel::BETA),
      cros_tokens::kCrosSysOnProgressContainer);
  EXPECT_EQ(
      channel_indicator_utils::GetBgColorJelly(version_info::Channel::BETA),
      cros_tokens::kCrosSysProgressContainer);
}

TEST_F(ChannelIndicatorUtilsTest, GetFullReleaseTrackString) {
  // Channel is not displayable, no string.
  EXPECT_TRUE(channel_indicator_utils::GetFullReleaseTrackString(
                  version_info::Channel::STABLE)
                  .empty());

  // Channel is displayable, string that's expected.
  EXPECT_EQ(channel_indicator_utils::GetFullReleaseTrackString(
                version_info::Channel::BETA),
            kTestButtonStr);
}

}  // namespace ash