[Android] Added UMA for search by image context menu.
[chromium-blink-merge.git] / chrome / installer / util / channel_info_unittest.cc
blob1aacb24730d40a093241c4e66bce9406714b3c89
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 <utility>
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;
14 namespace {
16 const std::wstring kChannelStable(installer::kChromeChannelStable);
17 const std::wstring kChannelBeta(installer::kChromeChannelBeta);
18 const std::wstring kChannelDev(installer::kChromeChannelDev);
20 } // namespace
22 TEST(ChannelInfoTest, Channels) {
23 ChannelInfo ci;
24 std::wstring channel;
26 ci.set_value(L"");
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) {
58 ChannelInfo ci;
60 ci.set_value(L"");
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) {
90 ChannelInfo ci;
92 ci.set_value(L"");
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, Combinations) {
122 ChannelInfo ci;
124 ci.set_value(L"2.0-beta-chromeframe");
125 EXPECT_FALSE(ci.IsChrome());
126 ci.set_value(L"2.0-beta-chromeframe-chrome");
127 EXPECT_TRUE(ci.IsChrome());
130 TEST(ChannelInfoTest, GetStage) {
131 ChannelInfo ci;
133 ci.set_value(L"");
134 EXPECT_EQ(L"", ci.GetStage());
135 ci.set_value(L"-stage");
136 EXPECT_EQ(L"", ci.GetStage());
137 ci.set_value(L"-stage:");
138 EXPECT_EQ(L"", ci.GetStage());
139 ci.set_value(L"-stage:spammy");
140 EXPECT_EQ(L"spammy", ci.GetStage());
142 ci.set_value(L"-multi");
143 EXPECT_EQ(L"", ci.GetStage());
144 ci.set_value(L"-stage-multi");
145 EXPECT_EQ(L"", ci.GetStage());
146 ci.set_value(L"-stage:-multi");
147 EXPECT_EQ(L"", ci.GetStage());
148 ci.set_value(L"-stage:spammy-multi");
149 EXPECT_EQ(L"spammy", ci.GetStage());
151 ci.set_value(L"2.0-beta-multi");
152 EXPECT_EQ(L"", ci.GetStage());
153 ci.set_value(L"2.0-beta-stage-multi");
154 EXPECT_EQ(L"", ci.GetStage());
155 ci.set_value(L"2.0-beta-stage:-multi");
156 EXPECT_EQ(L"", ci.GetStage());
157 ci.set_value(L"2.0-beta-stage:spammy-multi");
158 EXPECT_EQ(L"spammy", ci.GetStage());
161 TEST(ChannelInfoTest, SetStage) {
162 ChannelInfo ci;
164 ci.set_value(L"");
165 EXPECT_FALSE(ci.SetStage(NULL));
166 EXPECT_EQ(L"", ci.value());
167 EXPECT_TRUE(ci.SetStage(L"spammy"));
168 EXPECT_EQ(L"-stage:spammy", ci.value());
169 EXPECT_FALSE(ci.SetStage(L"spammy"));
170 EXPECT_EQ(L"-stage:spammy", ci.value());
171 EXPECT_TRUE(ci.SetStage(NULL));
172 EXPECT_EQ(L"", ci.value());
173 EXPECT_TRUE(ci.SetStage(L"spammy"));
174 EXPECT_TRUE(ci.SetStage(L""));
175 EXPECT_EQ(L"", ci.value());
177 ci.set_value(L"-multi");
178 EXPECT_FALSE(ci.SetStage(NULL));
179 EXPECT_EQ(L"-multi", ci.value());
180 EXPECT_TRUE(ci.SetStage(L"spammy"));
181 EXPECT_EQ(L"-stage:spammy-multi", ci.value());
182 EXPECT_FALSE(ci.SetStage(L"spammy"));
183 EXPECT_EQ(L"-stage:spammy-multi", ci.value());
184 EXPECT_TRUE(ci.SetStage(NULL));
185 EXPECT_EQ(L"-multi", ci.value());
186 EXPECT_TRUE(ci.SetStage(L"spammy"));
187 EXPECT_TRUE(ci.SetStage(L""));
188 EXPECT_EQ(L"-multi", ci.value());
190 ci.set_value(L"2.0-beta-multi");
191 EXPECT_FALSE(ci.SetStage(NULL));
192 EXPECT_EQ(L"2.0-beta-multi", ci.value());
193 EXPECT_TRUE(ci.SetStage(L"spammy"));
194 EXPECT_EQ(L"2.0-beta-stage:spammy-multi", ci.value());
195 EXPECT_FALSE(ci.SetStage(L"spammy"));
196 EXPECT_EQ(L"2.0-beta-stage:spammy-multi", ci.value());
197 EXPECT_TRUE(ci.SetStage(NULL));
198 EXPECT_EQ(L"2.0-beta-multi", ci.value());
199 EXPECT_TRUE(ci.SetStage(L"spammy"));
200 EXPECT_TRUE(ci.SetStage(L""));
201 EXPECT_EQ(L"2.0-beta-multi", ci.value());
203 ci.set_value(L"2.0-beta-stage:-multi");
204 EXPECT_TRUE(ci.SetStage(NULL));
205 EXPECT_EQ(L"2.0-beta-multi", ci.value());
208 TEST(ChannelInfoTest, RemoveAllModifiersAndSuffixes) {
209 ChannelInfo ci;
211 ci.set_value(L"");
212 EXPECT_FALSE(ci.RemoveAllModifiersAndSuffixes());
213 EXPECT_EQ(L"", ci.value());
215 ci.set_value(L"2.0-dev-multi-chrome-chromeframe");
216 EXPECT_TRUE(ci.RemoveAllModifiersAndSuffixes());
217 EXPECT_EQ(L"2.0-dev", ci.value());