1 // Copyright (c) 2012 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.
7 #include "base/basictypes.h"
8 #include "chrome/installer/util/channel_info.h"
9 #include "chrome/installer/util/util_constants.h"
10 #include "testing/gtest/include/gtest/gtest.h"
12 using installer::ChannelInfo
;
16 const std::wstring
kChannelStable(installer::kChromeChannelStable
);
17 const std::wstring
kChannelBeta(installer::kChromeChannelBeta
);
18 const std::wstring
kChannelDev(installer::kChromeChannelDev
);
22 TEST(ChannelInfoTest
, Channels
) {
27 EXPECT_TRUE(ci
.GetChannelName(&channel
));
28 EXPECT_EQ(kChannelStable
, channel
);
29 ci
.set_value(L
"-full");
30 EXPECT_TRUE(ci
.GetChannelName(&channel
));
31 EXPECT_EQ(kChannelStable
, channel
);
33 ci
.set_value(L
"2.0-beta");
34 EXPECT_TRUE(ci
.GetChannelName(&channel
));
35 EXPECT_EQ(kChannelBeta
, channel
);
36 ci
.set_value(L
"2.0-beta-spam");
37 EXPECT_TRUE(ci
.GetChannelName(&channel
));
38 EXPECT_EQ(kChannelBeta
, channel
);
39 ci
.set_value(L
"2.0-spam-beta");
40 EXPECT_TRUE(ci
.GetChannelName(&channel
));
41 EXPECT_EQ(kChannelBeta
, channel
);
43 ci
.set_value(L
"2.0-dev");
44 EXPECT_TRUE(ci
.GetChannelName(&channel
));
45 EXPECT_EQ(kChannelDev
, channel
);
46 ci
.set_value(L
"2.0-kinda-dev");
47 EXPECT_TRUE(ci
.GetChannelName(&channel
));
48 EXPECT_EQ(kChannelDev
, channel
);
49 ci
.set_value(L
"2.0-dev-eloper");
50 EXPECT_TRUE(ci
.GetChannelName(&channel
));
51 EXPECT_EQ(kChannelDev
, channel
);
53 ci
.set_value(L
"fuzzy");
54 EXPECT_FALSE(ci
.GetChannelName(&channel
));
57 TEST(ChannelInfoTest
, FullInstall
) {
61 EXPECT_TRUE(ci
.SetFullSuffix(true));
62 EXPECT_TRUE(ci
.HasFullSuffix());
63 EXPECT_EQ(L
"-full", ci
.value());
64 EXPECT_FALSE(ci
.SetFullSuffix(true));
65 EXPECT_TRUE(ci
.HasFullSuffix());
66 EXPECT_EQ(L
"-full", ci
.value());
67 EXPECT_TRUE(ci
.SetFullSuffix(false));
68 EXPECT_FALSE(ci
.HasFullSuffix());
69 EXPECT_EQ(L
"", ci
.value());
70 EXPECT_FALSE(ci
.SetFullSuffix(false));
71 EXPECT_FALSE(ci
.HasFullSuffix());
72 EXPECT_EQ(L
"", ci
.value());
74 ci
.set_value(L
"2.0-beta");
75 EXPECT_TRUE(ci
.SetFullSuffix(true));
76 EXPECT_TRUE(ci
.HasFullSuffix());
77 EXPECT_EQ(L
"2.0-beta-full", ci
.value());
78 EXPECT_FALSE(ci
.SetFullSuffix(true));
79 EXPECT_TRUE(ci
.HasFullSuffix());
80 EXPECT_EQ(L
"2.0-beta-full", ci
.value());
81 EXPECT_TRUE(ci
.SetFullSuffix(false));
82 EXPECT_FALSE(ci
.HasFullSuffix());
83 EXPECT_EQ(L
"2.0-beta", ci
.value());
84 EXPECT_FALSE(ci
.SetFullSuffix(false));
85 EXPECT_FALSE(ci
.HasFullSuffix());
86 EXPECT_EQ(L
"2.0-beta", ci
.value());
89 TEST(ChannelInfoTest
, MultiInstall
) {
93 EXPECT_TRUE(ci
.SetMultiInstall(true));
94 EXPECT_TRUE(ci
.IsMultiInstall());
95 EXPECT_EQ(L
"-multi", ci
.value());
96 EXPECT_FALSE(ci
.SetMultiInstall(true));
97 EXPECT_TRUE(ci
.IsMultiInstall());
98 EXPECT_EQ(L
"-multi", ci
.value());
99 EXPECT_TRUE(ci
.SetMultiInstall(false));
100 EXPECT_FALSE(ci
.IsMultiInstall());
101 EXPECT_EQ(L
"", ci
.value());
102 EXPECT_FALSE(ci
.SetMultiInstall(false));
103 EXPECT_FALSE(ci
.IsMultiInstall());
104 EXPECT_EQ(L
"", ci
.value());
106 ci
.set_value(L
"2.0-beta");
107 EXPECT_TRUE(ci
.SetMultiInstall(true));
108 EXPECT_TRUE(ci
.IsMultiInstall());
109 EXPECT_EQ(L
"2.0-beta-multi", ci
.value());
110 EXPECT_FALSE(ci
.SetMultiInstall(true));
111 EXPECT_TRUE(ci
.IsMultiInstall());
112 EXPECT_EQ(L
"2.0-beta-multi", ci
.value());
113 EXPECT_TRUE(ci
.SetMultiInstall(false));
114 EXPECT_FALSE(ci
.IsMultiInstall());
115 EXPECT_EQ(L
"2.0-beta", ci
.value());
116 EXPECT_FALSE(ci
.SetMultiInstall(false));
117 EXPECT_FALSE(ci
.IsMultiInstall());
118 EXPECT_EQ(L
"2.0-beta", ci
.value());
121 TEST(ChannelInfoTest
, Migration
) {
125 EXPECT_TRUE(ci
.SetMigratingSuffix(true));
126 EXPECT_TRUE(ci
.HasMigratingSuffix());
127 EXPECT_EQ(L
"-migrating", ci
.value());
128 EXPECT_FALSE(ci
.SetMigratingSuffix(true));
129 EXPECT_TRUE(ci
.HasMigratingSuffix());
130 EXPECT_EQ(L
"-migrating", ci
.value());
131 EXPECT_TRUE(ci
.SetMigratingSuffix(false));
132 EXPECT_FALSE(ci
.HasMigratingSuffix());
133 EXPECT_EQ(L
"", ci
.value());
134 EXPECT_FALSE(ci
.SetMigratingSuffix(false));
135 EXPECT_FALSE(ci
.HasMigratingSuffix());
136 EXPECT_EQ(L
"", ci
.value());
138 ci
.set_value(L
"2.0-beta");
139 EXPECT_TRUE(ci
.SetMigratingSuffix(true));
140 EXPECT_TRUE(ci
.HasMigratingSuffix());
141 EXPECT_EQ(L
"2.0-beta-migrating", ci
.value());
142 EXPECT_FALSE(ci
.SetMigratingSuffix(true));
143 EXPECT_TRUE(ci
.HasMigratingSuffix());
144 EXPECT_EQ(L
"2.0-beta-migrating", ci
.value());
145 EXPECT_TRUE(ci
.SetMigratingSuffix(false));
146 EXPECT_FALSE(ci
.HasMigratingSuffix());
147 EXPECT_EQ(L
"2.0-beta", ci
.value());
148 EXPECT_FALSE(ci
.SetMigratingSuffix(false));
149 EXPECT_FALSE(ci
.HasMigratingSuffix());
150 EXPECT_EQ(L
"2.0-beta", ci
.value());
153 TEST(ChannelInfoTest
, Combinations
) {
156 ci
.set_value(L
"2.0-beta-chromeframe");
157 EXPECT_FALSE(ci
.IsChrome());
158 ci
.set_value(L
"2.0-beta-chromeframe-chrome");
159 EXPECT_TRUE(ci
.IsChrome());
162 TEST(ChannelInfoTest
, GetStage
) {
166 EXPECT_EQ(L
"", ci
.GetStage());
167 ci
.set_value(L
"-stage");
168 EXPECT_EQ(L
"", ci
.GetStage());
169 ci
.set_value(L
"-stage:");
170 EXPECT_EQ(L
"", ci
.GetStage());
171 ci
.set_value(L
"-stage:spammy");
172 EXPECT_EQ(L
"spammy", ci
.GetStage());
174 ci
.set_value(L
"-multi");
175 EXPECT_EQ(L
"", ci
.GetStage());
176 ci
.set_value(L
"-stage-multi");
177 EXPECT_EQ(L
"", ci
.GetStage());
178 ci
.set_value(L
"-stage:-multi");
179 EXPECT_EQ(L
"", ci
.GetStage());
180 ci
.set_value(L
"-stage:spammy-multi");
181 EXPECT_EQ(L
"spammy", ci
.GetStage());
183 ci
.set_value(L
"2.0-beta-multi");
184 EXPECT_EQ(L
"", ci
.GetStage());
185 ci
.set_value(L
"2.0-beta-stage-multi");
186 EXPECT_EQ(L
"", ci
.GetStage());
187 ci
.set_value(L
"2.0-beta-stage:-multi");
188 EXPECT_EQ(L
"", ci
.GetStage());
189 ci
.set_value(L
"2.0-beta-stage:spammy-multi");
190 EXPECT_EQ(L
"spammy", ci
.GetStage());
193 TEST(ChannelInfoTest
, SetStage
) {
197 EXPECT_FALSE(ci
.SetStage(NULL
));
198 EXPECT_EQ(L
"", ci
.value());
199 EXPECT_TRUE(ci
.SetStage(L
"spammy"));
200 EXPECT_EQ(L
"-stage:spammy", ci
.value());
201 EXPECT_FALSE(ci
.SetStage(L
"spammy"));
202 EXPECT_EQ(L
"-stage:spammy", ci
.value());
203 EXPECT_TRUE(ci
.SetStage(NULL
));
204 EXPECT_EQ(L
"", ci
.value());
205 EXPECT_TRUE(ci
.SetStage(L
"spammy"));
206 EXPECT_TRUE(ci
.SetStage(L
""));
207 EXPECT_EQ(L
"", ci
.value());
209 ci
.set_value(L
"-multi");
210 EXPECT_FALSE(ci
.SetStage(NULL
));
211 EXPECT_EQ(L
"-multi", ci
.value());
212 EXPECT_TRUE(ci
.SetStage(L
"spammy"));
213 EXPECT_EQ(L
"-stage:spammy-multi", ci
.value());
214 EXPECT_FALSE(ci
.SetStage(L
"spammy"));
215 EXPECT_EQ(L
"-stage:spammy-multi", ci
.value());
216 EXPECT_TRUE(ci
.SetStage(NULL
));
217 EXPECT_EQ(L
"-multi", ci
.value());
218 EXPECT_TRUE(ci
.SetStage(L
"spammy"));
219 EXPECT_TRUE(ci
.SetStage(L
""));
220 EXPECT_EQ(L
"-multi", ci
.value());
222 ci
.set_value(L
"2.0-beta-multi");
223 EXPECT_FALSE(ci
.SetStage(NULL
));
224 EXPECT_EQ(L
"2.0-beta-multi", ci
.value());
225 EXPECT_TRUE(ci
.SetStage(L
"spammy"));
226 EXPECT_EQ(L
"2.0-beta-stage:spammy-multi", ci
.value());
227 EXPECT_FALSE(ci
.SetStage(L
"spammy"));
228 EXPECT_EQ(L
"2.0-beta-stage:spammy-multi", ci
.value());
229 EXPECT_TRUE(ci
.SetStage(NULL
));
230 EXPECT_EQ(L
"2.0-beta-multi", ci
.value());
231 EXPECT_TRUE(ci
.SetStage(L
"spammy"));
232 EXPECT_TRUE(ci
.SetStage(L
""));
233 EXPECT_EQ(L
"2.0-beta-multi", ci
.value());
235 ci
.set_value(L
"2.0-beta-stage:-multi");
236 EXPECT_TRUE(ci
.SetStage(NULL
));
237 EXPECT_EQ(L
"2.0-beta-multi", ci
.value());
240 TEST(ChannelInfoTest
, RemoveAllModifiersAndSuffixes
) {
244 EXPECT_FALSE(ci
.RemoveAllModifiersAndSuffixes());
245 EXPECT_EQ(L
"", ci
.value());
247 ci
.set_value(L
"2.0-dev-multi-chrome-chromeframe-migrating");
248 EXPECT_TRUE(ci
.RemoveAllModifiersAndSuffixes());
249 EXPECT_EQ(L
"2.0-dev", ci
.value());