Update V8 to version 4.5.11.
[chromium-blink-merge.git] / chrome / installer / util / channel_info_unittest.cc
blobdd50c38f4888359a283f0ef3fcc197c97afc32bd
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.
5 #include "chrome/installer/util/channel_info.h"
7 #include <utility>
9 #include "base/basictypes.h"
10 #include "chrome/installer/util/util_constants.h"
11 #include "testing/gtest/include/gtest/gtest.h"
13 using installer::ChannelInfo;
15 namespace {
17 const base::string16 kChannelStable(installer::kChromeChannelStable);
18 const base::string16 kChannelBeta(installer::kChromeChannelBeta);
19 const base::string16 kChannelDev(installer::kChromeChannelDev);
21 } // namespace
23 TEST(ChannelInfoTest, Channels) {
24 ChannelInfo ci;
25 base::string16 channel;
27 ci.set_value(L"");
28 EXPECT_TRUE(ci.GetChannelName(&channel));
29 EXPECT_EQ(kChannelStable, channel);
30 ci.set_value(L"-full");
31 EXPECT_TRUE(ci.GetChannelName(&channel));
32 EXPECT_EQ(kChannelStable, channel);
34 ci.set_value(L"2.0-beta");
35 EXPECT_TRUE(ci.GetChannelName(&channel));
36 EXPECT_EQ(kChannelBeta, channel);
37 ci.set_value(L"2.0-beta-spam");
38 EXPECT_TRUE(ci.GetChannelName(&channel));
39 EXPECT_EQ(kChannelBeta, channel);
40 ci.set_value(L"2.0-spam-beta");
41 EXPECT_TRUE(ci.GetChannelName(&channel));
42 EXPECT_EQ(kChannelBeta, channel);
44 ci.set_value(L"2.0-dev");
45 EXPECT_TRUE(ci.GetChannelName(&channel));
46 EXPECT_EQ(kChannelDev, channel);
47 ci.set_value(L"2.0-kinda-dev");
48 EXPECT_TRUE(ci.GetChannelName(&channel));
49 EXPECT_EQ(kChannelDev, channel);
50 ci.set_value(L"2.0-dev-eloper");
51 EXPECT_TRUE(ci.GetChannelName(&channel));
52 EXPECT_EQ(kChannelDev, channel);
54 ci.set_value(L"x64-dev");
55 EXPECT_TRUE(ci.GetChannelName(&channel));
56 EXPECT_EQ(kChannelDev, channel);
57 ci.set_value(L"x64-beta");
58 EXPECT_TRUE(ci.GetChannelName(&channel));
59 EXPECT_EQ(kChannelBeta, channel);
60 ci.set_value(L"x64-stable");
61 EXPECT_TRUE(ci.GetChannelName(&channel));
62 EXPECT_EQ(kChannelStable, channel);
64 ci.set_value(L"fuzzy");
65 EXPECT_FALSE(ci.GetChannelName(&channel));
68 TEST(ChannelInfoTest, FullInstall) {
69 ChannelInfo ci;
71 ci.set_value(L"");
72 EXPECT_TRUE(ci.SetFullSuffix(true));
73 EXPECT_TRUE(ci.HasFullSuffix());
74 EXPECT_EQ(L"-full", ci.value());
75 EXPECT_FALSE(ci.SetFullSuffix(true));
76 EXPECT_TRUE(ci.HasFullSuffix());
77 EXPECT_EQ(L"-full", ci.value());
78 EXPECT_TRUE(ci.SetFullSuffix(false));
79 EXPECT_FALSE(ci.HasFullSuffix());
80 EXPECT_EQ(L"", ci.value());
81 EXPECT_FALSE(ci.SetFullSuffix(false));
82 EXPECT_FALSE(ci.HasFullSuffix());
83 EXPECT_EQ(L"", ci.value());
85 ci.set_value(L"2.0-beta");
86 EXPECT_TRUE(ci.SetFullSuffix(true));
87 EXPECT_TRUE(ci.HasFullSuffix());
88 EXPECT_EQ(L"2.0-beta-full", ci.value());
89 EXPECT_FALSE(ci.SetFullSuffix(true));
90 EXPECT_TRUE(ci.HasFullSuffix());
91 EXPECT_EQ(L"2.0-beta-full", ci.value());
92 EXPECT_TRUE(ci.SetFullSuffix(false));
93 EXPECT_FALSE(ci.HasFullSuffix());
94 EXPECT_EQ(L"2.0-beta", ci.value());
95 EXPECT_FALSE(ci.SetFullSuffix(false));
96 EXPECT_FALSE(ci.HasFullSuffix());
97 EXPECT_EQ(L"2.0-beta", ci.value());
100 TEST(ChannelInfoTest, MultiInstall) {
101 ChannelInfo ci;
103 ci.set_value(L"");
104 EXPECT_TRUE(ci.SetMultiInstall(true));
105 EXPECT_TRUE(ci.IsMultiInstall());
106 EXPECT_EQ(L"-multi", ci.value());
107 EXPECT_FALSE(ci.SetMultiInstall(true));
108 EXPECT_TRUE(ci.IsMultiInstall());
109 EXPECT_EQ(L"-multi", ci.value());
110 EXPECT_TRUE(ci.SetMultiInstall(false));
111 EXPECT_FALSE(ci.IsMultiInstall());
112 EXPECT_EQ(L"", ci.value());
113 EXPECT_FALSE(ci.SetMultiInstall(false));
114 EXPECT_FALSE(ci.IsMultiInstall());
115 EXPECT_EQ(L"", ci.value());
117 ci.set_value(L"2.0-beta");
118 EXPECT_TRUE(ci.SetMultiInstall(true));
119 EXPECT_TRUE(ci.IsMultiInstall());
120 EXPECT_EQ(L"2.0-beta-multi", ci.value());
121 EXPECT_FALSE(ci.SetMultiInstall(true));
122 EXPECT_TRUE(ci.IsMultiInstall());
123 EXPECT_EQ(L"2.0-beta-multi", ci.value());
124 EXPECT_TRUE(ci.SetMultiInstall(false));
125 EXPECT_FALSE(ci.IsMultiInstall());
126 EXPECT_EQ(L"2.0-beta", ci.value());
127 EXPECT_FALSE(ci.SetMultiInstall(false));
128 EXPECT_FALSE(ci.IsMultiInstall());
129 EXPECT_EQ(L"2.0-beta", ci.value());
132 TEST(ChannelInfoTest, Migration) {
133 ChannelInfo ci;
135 ci.set_value(L"");
136 EXPECT_TRUE(ci.SetMigratingSuffix(true));
137 EXPECT_TRUE(ci.HasMigratingSuffix());
138 EXPECT_EQ(L"-migrating", ci.value());
139 EXPECT_FALSE(ci.SetMigratingSuffix(true));
140 EXPECT_TRUE(ci.HasMigratingSuffix());
141 EXPECT_EQ(L"-migrating", ci.value());
142 EXPECT_TRUE(ci.SetMigratingSuffix(false));
143 EXPECT_FALSE(ci.HasMigratingSuffix());
144 EXPECT_EQ(L"", ci.value());
145 EXPECT_FALSE(ci.SetMigratingSuffix(false));
146 EXPECT_FALSE(ci.HasMigratingSuffix());
147 EXPECT_EQ(L"", ci.value());
149 ci.set_value(L"2.0-beta");
150 EXPECT_TRUE(ci.SetMigratingSuffix(true));
151 EXPECT_TRUE(ci.HasMigratingSuffix());
152 EXPECT_EQ(L"2.0-beta-migrating", ci.value());
153 EXPECT_FALSE(ci.SetMigratingSuffix(true));
154 EXPECT_TRUE(ci.HasMigratingSuffix());
155 EXPECT_EQ(L"2.0-beta-migrating", ci.value());
156 EXPECT_TRUE(ci.SetMigratingSuffix(false));
157 EXPECT_FALSE(ci.HasMigratingSuffix());
158 EXPECT_EQ(L"2.0-beta", ci.value());
159 EXPECT_FALSE(ci.SetMigratingSuffix(false));
160 EXPECT_FALSE(ci.HasMigratingSuffix());
161 EXPECT_EQ(L"2.0-beta", ci.value());
164 TEST(ChannelInfoTest, Combinations) {
165 ChannelInfo ci;
167 ci.set_value(L"2.0-beta-chromeframe");
168 EXPECT_FALSE(ci.IsChrome());
169 ci.set_value(L"2.0-beta-chromeframe-chrome");
170 EXPECT_TRUE(ci.IsChrome());
173 TEST(ChannelInfoTest, GetStage) {
174 ChannelInfo ci;
176 ci.set_value(L"");
177 EXPECT_EQ(L"", ci.GetStage());
178 ci.set_value(L"-stage");
179 EXPECT_EQ(L"", ci.GetStage());
180 ci.set_value(L"-stage:");
181 EXPECT_EQ(L"", ci.GetStage());
182 ci.set_value(L"-stage:spammy");
183 EXPECT_EQ(L"spammy", ci.GetStage());
185 ci.set_value(L"-multi");
186 EXPECT_EQ(L"", ci.GetStage());
187 ci.set_value(L"-stage-multi");
188 EXPECT_EQ(L"", ci.GetStage());
189 ci.set_value(L"-stage:-multi");
190 EXPECT_EQ(L"", ci.GetStage());
191 ci.set_value(L"-stage:spammy-multi");
192 EXPECT_EQ(L"spammy", ci.GetStage());
194 ci.set_value(L"2.0-beta-multi");
195 EXPECT_EQ(L"", ci.GetStage());
196 ci.set_value(L"2.0-beta-stage-multi");
197 EXPECT_EQ(L"", ci.GetStage());
198 ci.set_value(L"2.0-beta-stage:-multi");
199 EXPECT_EQ(L"", ci.GetStage());
200 ci.set_value(L"2.0-beta-stage:spammy-multi");
201 EXPECT_EQ(L"spammy", ci.GetStage());
204 TEST(ChannelInfoTest, SetStage) {
205 ChannelInfo ci;
207 ci.set_value(L"");
208 EXPECT_FALSE(ci.SetStage(NULL));
209 EXPECT_EQ(L"", ci.value());
210 EXPECT_TRUE(ci.SetStage(L"spammy"));
211 EXPECT_EQ(L"-stage:spammy", ci.value());
212 EXPECT_FALSE(ci.SetStage(L"spammy"));
213 EXPECT_EQ(L"-stage:spammy", ci.value());
214 EXPECT_TRUE(ci.SetStage(NULL));
215 EXPECT_EQ(L"", ci.value());
216 EXPECT_TRUE(ci.SetStage(L"spammy"));
217 EXPECT_TRUE(ci.SetStage(L""));
218 EXPECT_EQ(L"", ci.value());
220 ci.set_value(L"-multi");
221 EXPECT_FALSE(ci.SetStage(NULL));
222 EXPECT_EQ(L"-multi", ci.value());
223 EXPECT_TRUE(ci.SetStage(L"spammy"));
224 EXPECT_EQ(L"-stage:spammy-multi", ci.value());
225 EXPECT_FALSE(ci.SetStage(L"spammy"));
226 EXPECT_EQ(L"-stage:spammy-multi", ci.value());
227 EXPECT_TRUE(ci.SetStage(NULL));
228 EXPECT_EQ(L"-multi", ci.value());
229 EXPECT_TRUE(ci.SetStage(L"spammy"));
230 EXPECT_TRUE(ci.SetStage(L""));
231 EXPECT_EQ(L"-multi", ci.value());
233 ci.set_value(L"2.0-beta-multi");
234 EXPECT_FALSE(ci.SetStage(NULL));
235 EXPECT_EQ(L"2.0-beta-multi", ci.value());
236 EXPECT_TRUE(ci.SetStage(L"spammy"));
237 EXPECT_EQ(L"2.0-beta-stage:spammy-multi", ci.value());
238 EXPECT_FALSE(ci.SetStage(L"spammy"));
239 EXPECT_EQ(L"2.0-beta-stage:spammy-multi", ci.value());
240 EXPECT_TRUE(ci.SetStage(NULL));
241 EXPECT_EQ(L"2.0-beta-multi", ci.value());
242 EXPECT_TRUE(ci.SetStage(L"spammy"));
243 EXPECT_TRUE(ci.SetStage(L""));
244 EXPECT_EQ(L"2.0-beta-multi", ci.value());
246 ci.set_value(L"2.0-beta-stage:-multi");
247 EXPECT_TRUE(ci.SetStage(NULL));
248 EXPECT_EQ(L"2.0-beta-multi", ci.value());
251 TEST(ChannelInfoTest, RemoveAllModifiersAndSuffixes) {
252 ChannelInfo ci;
254 ci.set_value(L"");
255 EXPECT_FALSE(ci.RemoveAllModifiersAndSuffixes());
256 EXPECT_EQ(L"", ci.value());
258 ci.set_value(L"2.0-dev-multi-chrome-chromeframe-migrating");
259 EXPECT_TRUE(ci.RemoveAllModifiersAndSuffixes());
260 EXPECT_EQ(L"2.0-dev", ci.value());