blob: 5eee6a9258ab1d1d2a60687a744afb1e9741d79b [file] [log] [blame]
Greg Thompson32772c1f2021-06-29 21:18:481// Copyright 2021 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
5#include "chrome/common/channel_info.h"
6
Peter Boström3f798572022-07-26 23:44:367#include "base/debug/debugging_buildflags.h"
Greg Thompson32772c1f2021-06-29 21:18:488#include "build/branding_buildflags.h"
9#include "build/build_config.h"
Roman Arora88892072021-10-06 21:40:3810#include "build/chromeos_buildflags.h"
Greg Thompson32772c1f2021-06-29 21:18:4811#include "components/version_info/channel.h"
12#include "testing/gmock/include/gmock/gmock.h"
13#include "testing/gtest/include/gtest/gtest.h"
14
15#if BUILDFLAG(GOOGLE_CHROME_BRANDING)
16#include "chrome/test/base/scoped_channel_override.h"
17#endif // BUILDFLAG(GOOGLE_CHROME_BRANDING)
18
19namespace chrome {
20
21namespace {
22
23// A bucket of test parameters for ChannelInfoTest.
24struct Param {
25#if BUILDFLAG(GOOGLE_CHROME_BRANDING)
26 Param(ScopedChannelOverride::Channel channel_override,
27 const char* name_without_es,
28 const char* name_with_es,
29 version_info::Channel channel,
30 bool is_extended_stable,
31 const char* posix_data_dir_suffix)
32 : channel_override(channel_override),
33 channel_name_without_es(name_without_es),
34 channel_name_with_es(name_with_es),
35 channel(channel),
36 is_extended_stable(is_extended_stable),
37 posix_data_dir_suffix(posix_data_dir_suffix) {}
38#else
39 Param(const char* name_without_es,
40 const char* name_with_es,
41 version_info::Channel channel,
42 bool is_extended_stable,
43 const char* posix_data_dir_suffix)
44 : channel_name_without_es(name_without_es),
45 channel_name_with_es(name_with_es),
46 channel(channel),
47 is_extended_stable(is_extended_stable),
48 posix_data_dir_suffix(posix_data_dir_suffix) {}
49#endif
50
51#if BUILDFLAG(GOOGLE_CHROME_BRANDING)
52 // Value to use in the test to override the default channel in branded builds.
53 const ScopedChannelOverride::Channel channel_override;
54#endif
55
56 // Expected channel name when extended stable should not be surfaced.
57 const char* const channel_name_without_es;
58
59 // Expected channel name when extended stable should be surfaced.
60 const char* const channel_name_with_es;
61
62 // Expected channel value.
63 const version_info::Channel channel;
64
65 // Expected extended stable channel value.
66 const bool is_extended_stable;
67
68 // Suffix for User Data dir (only used for non-Mac Posix).
69 const char* const posix_data_dir_suffix;
70};
71
72} // namespace
73
74// A value-parameterized test to facilitate testing the various channel info
75// functions. Branded builds evaluate all tests once for each supported channel.
76class ChannelInfoTest : public ::testing::TestWithParam<Param> {
77 protected:
78 ChannelInfoTest() = default;
79
80 private:
81#if BUILDFLAG(GOOGLE_CHROME_BRANDING)
82 ScopedChannelOverride scoped_channel_override_{GetParam().channel_override};
83#endif // BUILDFLAG(GOOGLE_CHROME_BRANDING)
84};
85
86TEST_P(ChannelInfoTest, GetVersionStringWithout) {
87 const std::string channel_name = GetParam().channel_name_without_es;
88 if (!channel_name.empty()) {
89 EXPECT_THAT(GetVersionString(WithExtendedStable(false)),
90 ::testing::EndsWith(channel_name));
91 }
92}
93
94TEST_P(ChannelInfoTest, GetVersionStringWith) {
95 const std::string channel_name = GetParam().channel_name_with_es;
96 if (!channel_name.empty()) {
97 EXPECT_THAT(GetVersionString(WithExtendedStable(true)),
98 ::testing::EndsWith(channel_name));
99 }
100}
101
102TEST_P(ChannelInfoTest, GetChannelNameWithout) {
103 EXPECT_EQ(GetChannelName(WithExtendedStable(false)),
104 GetParam().channel_name_without_es);
105}
106
107TEST_P(ChannelInfoTest, GetChannelNameWith) {
108 EXPECT_EQ(GetChannelName(WithExtendedStable(true)),
109 GetParam().channel_name_with_es);
110}
111
112TEST_P(ChannelInfoTest, GetChannel) {
113 EXPECT_EQ(GetChannel(), GetParam().channel);
114}
115
116TEST_P(ChannelInfoTest, IsExtendedStableChannel) {
117 EXPECT_EQ(IsExtendedStableChannel(), GetParam().is_extended_stable);
118}
119
Xiaohan Wang4d5c5042022-01-18 21:54:37120#if BUILDFLAG(IS_WIN)
121#elif BUILDFLAG(IS_MAC)
Greg Thompson32772c1f2021-06-29 21:18:48122
123TEST_P(ChannelInfoTest, GetChannelByName) {
124 EXPECT_EQ(GetChannelByName(GetParam().channel_name_with_es),
125 GetParam().channel);
126}
127
Xiaohan Wang4d5c5042022-01-18 21:54:37128#elif BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_CHROMEOS_LACROS)
Greg Thompson32772c1f2021-06-29 21:18:48129
130TEST_P(ChannelInfoTest, GetChannelSuffixForDataDir) {
131 EXPECT_EQ(GetChannelSuffixForDataDir(), GetParam().posix_data_dir_suffix);
132}
133
134#endif
135
136#if BUILDFLAG(GOOGLE_CHROME_BRANDING)
137// Instantiate the test suite once per supported channel in branded builds.
138INSTANTIATE_TEST_SUITE_P(
139 Stable,
140 ChannelInfoTest,
141 ::testing::Values(Param(ScopedChannelOverride::Channel::kStable,
Peter Boström3f798572022-07-26 23:44:36142#if BUILDFLAG(DCHECK_IS_CONFIGURABLE)
Peter Boström25866122022-06-02 10:25:33143 "-dcheck",
144 "-dcheck",
145#else
Greg Thompson32772c1f2021-06-29 21:18:48146 "",
147 "",
Peter Boström3f798572022-07-26 23:44:36148#endif // BUILDFLAG(DCHECK_IS_CONFIGURABLE)
Greg Thompson32772c1f2021-06-29 21:18:48149 version_info::Channel::STABLE,
150 /*is_extended_stable=*/false,
151 /*posix_data_dir_suffix=*/"")));
152INSTANTIATE_TEST_SUITE_P(
153 ExtendedStable,
154 ChannelInfoTest,
155 ::testing::Values(Param(ScopedChannelOverride::Channel::kExtendedStable,
Peter Boström3f798572022-07-26 23:44:36156#if BUILDFLAG(DCHECK_IS_CONFIGURABLE)
Peter Boström25866122022-06-02 10:25:33157 "-dcheck",
158 "extended-dcheck",
159#else
Greg Thompson32772c1f2021-06-29 21:18:48160 "",
161 "extended",
Peter Boström3f798572022-07-26 23:44:36162#endif // BUILDFLAG(DCHECK_IS_CONFIGURABLE)
Greg Thompson32772c1f2021-06-29 21:18:48163 version_info::Channel::STABLE,
164 /*is_extended_stable=*/true,
165 /*posix_data_dir_suffix=*/"")));
166INSTANTIATE_TEST_SUITE_P(
167 Beta,
168 ChannelInfoTest,
169 ::testing::Values(Param(ScopedChannelOverride::Channel::kBeta,
Peter Boström3f798572022-07-26 23:44:36170#if BUILDFLAG(DCHECK_IS_CONFIGURABLE)
Peter Boström25866122022-06-02 10:25:33171 "beta-dcheck",
172 "beta-dcheck",
173#else
Greg Thompson32772c1f2021-06-29 21:18:48174 "beta",
175 "beta",
Peter Boström3f798572022-07-26 23:44:36176#endif // BUILDFLAG(DCHECK_IS_CONFIGURABLE)
Greg Thompson32772c1f2021-06-29 21:18:48177 version_info::Channel::BETA,
178 /*is_extended_stable=*/false,
179 /*posix_data_dir_suffix=*/"-beta")));
180INSTANTIATE_TEST_SUITE_P(
181 Dev,
182 ChannelInfoTest,
183 ::testing::Values(Param(ScopedChannelOverride::Channel::kDev,
Peter Boström3f798572022-07-26 23:44:36184#if BUILDFLAG(DCHECK_IS_CONFIGURABLE)
Peter Boström25866122022-06-02 10:25:33185 "dev-dcheck",
186 "dev-dcheck",
187#else
Greg Thompson32772c1f2021-06-29 21:18:48188 "dev",
189 "dev",
Peter Boström3f798572022-07-26 23:44:36190#endif // BUILDFLAG(DCHECK_IS_CONFIGURABLE)
Greg Thompson32772c1f2021-06-29 21:18:48191 version_info::Channel::DEV,
192 /*is_extended_stable=*/false,
193 /*posix_data_dir_suffix=*/"-unstable")));
Xiaohan Wang4d5c5042022-01-18 21:54:37194#if BUILDFLAG(IS_MAC) || BUILDFLAG(IS_WIN) || \
195 BUILDFLAG(IS_FUCHSIA) // No canary channel on Linux.
Greg Thompson32772c1f2021-06-29 21:18:48196INSTANTIATE_TEST_SUITE_P(
197 Canary,
198 ChannelInfoTest,
199 ::testing::Values(Param(ScopedChannelOverride::Channel::kCanary,
Peter Boström3f798572022-07-26 23:44:36200#if BUILDFLAG(DCHECK_IS_CONFIGURABLE)
Peter Boström25866122022-06-02 10:25:33201 "canary-dcheck",
202 "canary-dcheck",
203#else
Greg Thompson32772c1f2021-06-29 21:18:48204 "canary",
205 "canary",
Peter Boström3f798572022-07-26 23:44:36206#endif // BUILDFLAG(DCHECK_IS_CONFIGURABLE)
Greg Thompson32772c1f2021-06-29 21:18:48207 version_info::Channel::CANARY,
208 /*is_extended_stable=*/false,
209 /*posix_data_dir_suffix=*/"")));
Xiaohan Wang4d5c5042022-01-18 21:54:37210#endif // BUILDFLAG(IS_MAC) || BUILDFLAG(IS_WIN)
Greg Thompson32772c1f2021-06-29 21:18:48211#else // BUILDFLAG(GOOGLE_CHROME_BRANDING)
212INSTANTIATE_TEST_SUITE_P(
213 Chromium,
214 ChannelInfoTest,
215 ::testing::Values(Param("",
216 "",
217 version_info::Channel::UNKNOWN,
218 /*is_extended_stable=*/false,
219 /*posix_data_dir_suffix=*/"")));
220#endif // BUILDFLAG(GOOGLE_CHROME_BRANDING)
221
222} // namespace chrome