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 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205
|
// Copyright 2021 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/common/channel_info.h"
#include "build/branding_buildflags.h"
#include "build/build_config.h"
#include "components/version_info/channel.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#if BUILDFLAG(GOOGLE_CHROME_BRANDING)
#include "chrome/test/base/scoped_channel_override.h"
#endif // BUILDFLAG(GOOGLE_CHROME_BRANDING)
namespace chrome {
namespace {
// A bucket of test parameters for ChannelInfoTest.
struct Param {
#if BUILDFLAG(GOOGLE_CHROME_BRANDING)
Param(ScopedChannelOverride::Channel channel_override,
const char* name_without_es,
const char* name_with_es,
version_info::Channel channel,
bool is_extended_stable,
const char* posix_data_dir_suffix)
: channel_override(channel_override),
channel_name_without_es(name_without_es),
channel_name_with_es(name_with_es),
channel(channel),
is_extended_stable(is_extended_stable),
posix_data_dir_suffix(posix_data_dir_suffix) {}
#else
Param(const char* name_without_es,
const char* name_with_es,
version_info::Channel channel,
bool is_extended_stable,
const char* posix_data_dir_suffix)
: channel_name_without_es(name_without_es),
channel_name_with_es(name_with_es),
channel(channel),
is_extended_stable(is_extended_stable),
posix_data_dir_suffix(posix_data_dir_suffix) {}
#endif
#if BUILDFLAG(GOOGLE_CHROME_BRANDING)
// Value to use in the test to override the default channel in branded builds.
const ScopedChannelOverride::Channel channel_override;
#endif
// Expected channel name when extended stable should not be surfaced.
const char* const channel_name_without_es;
// Expected channel name when extended stable should be surfaced.
const char* const channel_name_with_es;
// Expected channel value.
const version_info::Channel channel;
// Expected extended stable channel value.
const bool is_extended_stable;
// Suffix for User Data dir (only used for non-Mac Posix).
const char* const posix_data_dir_suffix;
};
} // namespace
// A value-parameterized test to facilitate testing the various channel info
// functions. Branded builds evaluate all tests once for each supported channel.
class ChannelInfoTest : public ::testing::TestWithParam<Param> {
protected:
ChannelInfoTest() = default;
private:
#if BUILDFLAG(GOOGLE_CHROME_BRANDING)
ScopedChannelOverride scoped_channel_override_{GetParam().channel_override};
#endif // BUILDFLAG(GOOGLE_CHROME_BRANDING)
};
TEST_P(ChannelInfoTest, GetVersionStringWithout) {
const std::string channel_name = GetParam().channel_name_without_es;
if (!channel_name.empty()) {
EXPECT_THAT(GetVersionString(WithExtendedStable(false)),
::testing::EndsWith(channel_name));
}
}
TEST_P(ChannelInfoTest, GetVersionStringWith) {
const std::string channel_name = GetParam().channel_name_with_es;
if (!channel_name.empty()) {
EXPECT_THAT(GetVersionString(WithExtendedStable(true)),
::testing::EndsWith(channel_name));
}
}
TEST_P(ChannelInfoTest, GetChannelNameWithout) {
EXPECT_EQ(GetChannelName(WithExtendedStable(false)),
GetParam().channel_name_without_es);
}
TEST_P(ChannelInfoTest, GetChannelNameWith) {
EXPECT_EQ(GetChannelName(WithExtendedStable(true)),
GetParam().channel_name_with_es);
}
TEST_P(ChannelInfoTest, GetChannel) {
EXPECT_EQ(GetChannel(), GetParam().channel);
}
TEST_P(ChannelInfoTest, IsExtendedStableChannel) {
EXPECT_EQ(IsExtendedStableChannel(), GetParam().is_extended_stable);
}
#if BUILDFLAG(IS_WIN)
#elif BUILDFLAG(IS_MAC)
TEST_P(ChannelInfoTest, GetChannelByName) {
EXPECT_EQ(GetChannelByName(GetParam().channel_name_with_es),
GetParam().channel);
}
#elif BUILDFLAG(IS_POSIX)
TEST_P(ChannelInfoTest, GetChannelSuffixForDataDir) {
EXPECT_EQ(GetChannelSuffixForDataDir(), GetParam().posix_data_dir_suffix);
}
#endif
#if BUILDFLAG(GOOGLE_CHROME_BRANDING)
// Instantiate the test suite once per supported channel in branded builds.
INSTANTIATE_TEST_SUITE_P(
Stable,
ChannelInfoTest,
::testing::Values(Param(ScopedChannelOverride::Channel::kStable,
"",
"",
version_info::Channel::STABLE,
/*is_extended_stable=*/false,
/*posix_data_dir_suffix=*/"")));
INSTANTIATE_TEST_SUITE_P(
ExtendedStable,
ChannelInfoTest,
::testing::Values(Param(ScopedChannelOverride::Channel::kExtendedStable,
"",
"extended",
version_info::Channel::STABLE,
/*is_extended_stable=*/true,
/*posix_data_dir_suffix=*/"")));
INSTANTIATE_TEST_SUITE_P(
Beta,
ChannelInfoTest,
::testing::Values(Param(ScopedChannelOverride::Channel::kBeta,
"beta",
"beta",
version_info::Channel::BETA,
/*is_extended_stable=*/false,
/*posix_data_dir_suffix=*/"-beta")));
INSTANTIATE_TEST_SUITE_P(
Dev,
ChannelInfoTest,
::testing::Values(Param(ScopedChannelOverride::Channel::kDev,
"dev",
"dev",
version_info::Channel::DEV,
/*is_extended_stable=*/false,
/*posix_data_dir_suffix=*/"-unstable")));
#if BUILDFLAG(IS_MAC) || BUILDFLAG(IS_WIN)
INSTANTIATE_TEST_SUITE_P(
Canary,
ChannelInfoTest,
::testing::Values(Param(ScopedChannelOverride::Channel::kCanary,
"canary",
"canary",
version_info::Channel::CANARY,
/*is_extended_stable=*/false,
/*posix_data_dir_suffix=*/"")));
#elif BUILDFLAG(IS_LINUX)
INSTANTIATE_TEST_SUITE_P(
Canary,
ChannelInfoTest,
::testing::Values(Param(ScopedChannelOverride::Channel::kCanary,
"canary",
"canary",
version_info::Channel::CANARY,
/*is_extended_stable=*/false,
/*posix_data_dir_suffix=*/"-canary")));
#endif // BUILDFLAG(IS_MAC) || BUILDFLAG(IS_WIN) ||
// BUILDFLAG(IS_LINUX)
#else // BUILDFLAG(GOOGLE_CHROME_BRANDING)
INSTANTIATE_TEST_SUITE_P(
Chromium,
ChannelInfoTest,
::testing::Values(Param("",
"",
version_info::Channel::UNKNOWN,
/*is_extended_stable=*/false,
/*posix_data_dir_suffix=*/"")));
#endif // BUILDFLAG(GOOGLE_CHROME_BRANDING)
} // namespace chrome
|