Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(203)

Side by Side Diff: chrome_elf/chrome_elf_util_unittest.cc

Issue 1913943003: Remove dependencies on chrome\installer from the ChromeCrashReporterClient class on Windows. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update ChromeElfUtilTest.InstallStaticGetChannelNameTest for changed expectations for channel name Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome_elf/chrome_elf_main.cc ('k') | chrome_elf/elf_imports_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <tuple> 5 #include <tuple>
6 6
7 #include "base/test/test_reg_util_win.h" 7 #include "base/test/test_reg_util_win.h"
8 #include "base/win/registry.h" 8 #include "base/win/registry.h"
9 #include "chrome/install_static/install_util.h" 9 #include "chrome/install_static/install_util.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
11 #include "testing/platform_test.h" 11 #include "testing/platform_test.h"
12 12
13 using namespace install_static;
14
13 namespace { 15 namespace {
14 16
15 const wchar_t kRegPathClientState[] = L"Software\\Google\\Update\\ClientState";
16 const wchar_t kRegPathClientStateMedium[] =
17 L"Software\\Google\\Update\\ClientStateMedium";
18 const wchar_t kRegValueUsageStats[] = L"usagestats";
19 const wchar_t kUninstallArgumentsField[] = L"UninstallArguments";
20
21 const wchar_t kAppGuidCanary[] =
22 L"{4ea16ac7-fd5a-47c3-875b-dbf4a2008c20}";
23 const wchar_t kAppGuidGoogleChrome[] =
24 L"{8A69D345-D564-463c-AFF1-A69D9E530F96}";
25 const wchar_t kAppGuidGoogleBinaries[] =
26 L"{4DC8B4CA-1BDA-483e-B5FA-D3C12E15B62D}";
27
28 const wchar_t kCanaryExePath[] = 17 const wchar_t kCanaryExePath[] =
29 L"C:\\Users\\user\\AppData\\Local\\Google\\Chrome SxS\\Application" 18 L"C:\\Users\\user\\AppData\\Local\\Google\\Chrome SxS\\Application"
30 L"\\chrome.exe"; 19 L"\\chrome.exe";
31 const wchar_t kChromeSystemExePath[] = 20 const wchar_t kChromeSystemExePath[] =
32 L"C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe"; 21 L"C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe";
33 const wchar_t kChromeUserExePath[] = 22 const wchar_t kChromeUserExePath[] =
34 L"C:\\Users\\user\\AppData\\Local\\Google\\Chrome\\Application\\chrome.exe"; 23 L"C:\\Users\\user\\AppData\\Local\\Google\\Chrome\\Application\\chrome.exe";
35 const wchar_t kChromiumExePath[] = 24 const wchar_t kChromiumExePath[] =
36 L"C:\\Users\\user\\AppData\\Local\\Chromium\\Application\\chrome.exe"; 25 L"C:\\Users\\user\\AppData\\Local\\Chromium\\Application\\chrome.exe";
37 26
38
39 TEST(ChromeElfUtilTest, CanaryTest) { 27 TEST(ChromeElfUtilTest, CanaryTest) {
40 EXPECT_TRUE(IsCanary(kCanaryExePath)); 28 EXPECT_TRUE(IsSxSChrome(kCanaryExePath));
41 EXPECT_FALSE(IsCanary(kChromeUserExePath)); 29 EXPECT_FALSE(IsSxSChrome(kChromeUserExePath));
42 EXPECT_FALSE(IsCanary(kChromiumExePath)); 30 EXPECT_FALSE(IsSxSChrome(kChromiumExePath));
43 } 31 }
44 32
45 TEST(ChromeElfUtilTest, SystemInstallTest) { 33 TEST(ChromeElfUtilTest, SystemInstallTest) {
46 EXPECT_TRUE(IsSystemInstall(kChromeSystemExePath)); 34 EXPECT_TRUE(IsSystemInstall(kChromeSystemExePath));
47 EXPECT_FALSE(IsSystemInstall(kChromeUserExePath)); 35 EXPECT_FALSE(IsSystemInstall(kChromeUserExePath));
48 } 36 }
49 37
50 TEST(ChromeElfUtilTest, BrowserProcessTest) { 38 TEST(ChromeElfUtilTest, BrowserProcessTest) {
51 EXPECT_EQ(ProcessType::UNINITIALIZED, g_process_type); 39 EXPECT_EQ(ProcessType::UNINITIALIZED, g_process_type);
52 InitializeProcessType(); 40 InitializeProcessType();
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 LONG result; 100 LONG result;
113 if (multi) { 101 if (multi) {
114 result = key.WriteValue(kUninstallArgumentsField, 102 result = key.WriteValue(kUninstallArgumentsField,
115 L"yadda yadda --multi-install yadda yadda"); 103 L"yadda yadda --multi-install yadda yadda");
116 } else { 104 } else {
117 result = key.DeleteValue(kUninstallArgumentsField); 105 result = key.DeleteValue(kUninstallArgumentsField);
118 } 106 }
119 ASSERT_EQ(ERROR_SUCCESS, result); 107 ASSERT_EQ(ERROR_SUCCESS, result);
120 } 108 }
121 109
110 void SetChannelName(const base::string16& channel_name) {
111 LONG result = base::win::RegKey(
112 system_level_ ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER,
113 BuildKey(kRegPathClientState, app_guid_).c_str(),
114 KEY_SET_VALUE).WriteValue(kRegApField, channel_name.c_str());
115 ASSERT_EQ(ERROR_SUCCESS, result);
116 }
117
122 const wchar_t* app_guid_; 118 const wchar_t* app_guid_;
123 const wchar_t* chrome_path_; 119 const wchar_t* chrome_path_;
124 bool system_level_; 120 bool system_level_;
125 bool multi_install_; 121 bool multi_install_;
126 bool is_canary_; 122 bool is_canary_;
127 registry_util::RegistryOverrideManager override_manager_; 123 registry_util::RegistryOverrideManager override_manager_;
128 }; 124 };
129 125
130 TEST_P(ChromeElfUtilTest, MultiInstallTest) { 126 TEST_P(ChromeElfUtilTest, MultiInstallTest) {
131 if (is_canary_) 127 if (is_canary_)
132 return; 128 return;
133 SetMultiInstallStateInRegistry(system_level_, true); 129 SetMultiInstallStateInRegistry(system_level_, true);
134 EXPECT_TRUE(IsMultiInstall(system_level_)); 130 EXPECT_TRUE(IsMultiInstall(system_level_));
135 131
136 SetMultiInstallStateInRegistry(system_level_, false); 132 SetMultiInstallStateInRegistry(system_level_, false);
137 EXPECT_FALSE(IsMultiInstall(system_level_)); 133 EXPECT_FALSE(IsMultiInstall(system_level_));
138 } 134 }
139 135
140 TEST_P(ChromeElfUtilTest, UsageStatsAbsent) { 136 TEST_P(ChromeElfUtilTest, UsageStatsAbsent) {
141 EXPECT_FALSE(AreUsageStatsEnabled(chrome_path_)); 137 EXPECT_FALSE(GetCollectStatsConsentForTesting(chrome_path_));
142 } 138 }
143 139
144 TEST_P(ChromeElfUtilTest, UsageStatsZero) { 140 TEST_P(ChromeElfUtilTest, UsageStatsZero) {
145 SetUsageStat(0, false); 141 SetUsageStat(0, false);
146 EXPECT_FALSE(AreUsageStatsEnabled(chrome_path_)); 142 EXPECT_FALSE(GetCollectStatsConsentForTesting(chrome_path_));
147 } 143 }
148 144
149 TEST_P(ChromeElfUtilTest, UsageStatsOne) { 145 TEST_P(ChromeElfUtilTest, UsageStatsOne) {
150 SetUsageStat(1, false); 146 SetUsageStat(1, false);
151 EXPECT_TRUE(AreUsageStatsEnabled(chrome_path_)); 147 EXPECT_TRUE(GetCollectStatsConsentForTesting(chrome_path_));
152 if (is_canary_) { 148 if (is_canary_) {
153 EXPECT_FALSE(AreUsageStatsEnabled(kChromeUserExePath)); 149 EXPECT_FALSE(GetCollectStatsConsentForTesting(kChromeUserExePath));
154 EXPECT_FALSE(AreUsageStatsEnabled(kChromeSystemExePath)); 150 EXPECT_FALSE(GetCollectStatsConsentForTesting(kChromeSystemExePath));
155 } else if (system_level_) { 151 } else if (system_level_) {
156 EXPECT_FALSE(AreUsageStatsEnabled(kCanaryExePath)); 152 EXPECT_FALSE(GetCollectStatsConsentForTesting(kCanaryExePath));
157 EXPECT_FALSE(AreUsageStatsEnabled(kChromeUserExePath)); 153 EXPECT_FALSE(GetCollectStatsConsentForTesting(kChromeUserExePath));
158 } else { 154 } else {
159 EXPECT_FALSE(AreUsageStatsEnabled(kCanaryExePath)); 155 EXPECT_FALSE(GetCollectStatsConsentForTesting(kCanaryExePath));
160 EXPECT_FALSE(AreUsageStatsEnabled(kChromeSystemExePath)); 156 EXPECT_FALSE(GetCollectStatsConsentForTesting(kChromeSystemExePath));
161 } 157 }
162 } 158 }
163 159
164 TEST_P(ChromeElfUtilTest, UsageStatsZeroInStateMedium) { 160 TEST_P(ChromeElfUtilTest, UsageStatsZeroInStateMedium) {
165 if (!system_level_) 161 if (!system_level_)
166 return; 162 return;
167 SetUsageStat(0, true); 163 SetUsageStat(0, true);
168 EXPECT_FALSE(AreUsageStatsEnabled(chrome_path_)); 164 EXPECT_FALSE(GetCollectStatsConsentForTesting(chrome_path_));
169 } 165 }
170 166
171 TEST_P(ChromeElfUtilTest, UsageStatsOneInStateMedium) { 167 TEST_P(ChromeElfUtilTest, UsageStatsOneInStateMedium) {
172 if (!system_level_) 168 if (!system_level_)
173 return; 169 return;
174 SetUsageStat(1, true); 170 SetUsageStat(1, true);
175 EXPECT_TRUE(AreUsageStatsEnabled(chrome_path_)); 171 EXPECT_TRUE(GetCollectStatsConsentForTesting(chrome_path_));
176 EXPECT_FALSE(AreUsageStatsEnabled(kCanaryExePath)); 172 EXPECT_FALSE(GetCollectStatsConsentForTesting(kCanaryExePath));
177 EXPECT_FALSE(AreUsageStatsEnabled(kChromeUserExePath)); 173 EXPECT_FALSE(GetCollectStatsConsentForTesting(kChromeUserExePath));
174 }
175
176 // TODO(ananta)
177 // Move this to install_static_unittests.
178 // http://crbug.com/604923
179 // This test tests the install_static::GetChromeChannelName function and is
180 // based on the ChannelInfoTest.Channels in channel_info_unittest.cc
181 TEST_P(ChromeElfUtilTest, InstallStaticGetChannelNameTest) {
182 // We can't test the channel name correctly for canary mode because the
183 // install_static checks whether an exe is a canary executable is based on
184 // the path where the exe is running from.
185 if (is_canary_)
186 return;
187 SetChannelName(L"");
188 base::string16 channel;
189 install_static::GetChromeChannelName(!system_level_, true, &channel);
grt (UTC plus 2) 2016/05/06 15:05:01 please add test coverage for the cases where add_m
ananta 2016/05/06 19:36:03 Done.
190 EXPECT_EQ(install_static::kChromeChannelStable, channel);
191
192 SetChannelName(L"-full");
193 install_static::GetChromeChannelName(!system_level_, true, &channel);
194 if (multi_install_) {
195 EXPECT_TRUE(install_static::MatchPattern(channel, L"*-m*"));
grt (UTC plus 2) 2016/05/06 15:05:01 "-full" multi-install should be "-m" when modifier
ananta 2016/05/06 19:36:03 Done.
196 } else {
197 EXPECT_EQ(install_static::kChromeChannelStable, channel);
198 }
199
200 SetChannelName(L"1.1-beta");
201 install_static::GetChromeChannelName(!system_level_, true, &channel);
202 if (multi_install_) {
203 EXPECT_EQ(L"beta-m", channel);
204 } else {
205 EXPECT_EQ(install_static::kChromeChannelBeta, channel);
206 }
207
208 SetChannelName(L"1.1-beta");
209 install_static::GetChromeChannelName(!system_level_, true, &channel);
210 if (multi_install_) {
211 EXPECT_EQ(L"beta-m", channel);
212 } else {
213 EXPECT_EQ(install_static::kChromeChannelBeta, channel);
214 }
215
216 SetChannelName(L"1.1-bar");
217 install_static::GetChromeChannelName(!system_level_, true, &channel);
218 if (multi_install_) {
219 EXPECT_EQ(L"beta-m", channel);
220 } else {
221 EXPECT_EQ(install_static::kChromeChannelBeta, channel);
222 }
223
224 SetChannelName(L"1n1-foobar");
225 install_static::GetChromeChannelName(!system_level_, true, &channel);
226 if (multi_install_) {
227 EXPECT_EQ(L"beta-m", channel);
228 } else {
229 EXPECT_EQ(install_static::kChromeChannelBeta, channel);
230 }
231
232 SetChannelName(L"foo-1.1-beta");
233 install_static::GetChromeChannelName(!system_level_, true, &channel);
234 if (multi_install_) {
235 EXPECT_EQ(L"-m", channel);
236 } else {
237 EXPECT_TRUE(channel.empty());
grt (UTC plus 2) 2016/05/06 15:05:01 install_static::kChromeChannelStable for all of th
ananta 2016/05/06 19:36:03 Done.
238 }
239 SetChannelName(L"2.0-beta");
240 install_static::GetChromeChannelName(!system_level_, true, &channel);
241 if (multi_install_) {
242 EXPECT_EQ(L"-m", channel);
243 } else {
244 EXPECT_TRUE(channel.empty());
245 }
246
247 SetChannelName(L"2.0-dev");
248 install_static::GetChromeChannelName(!system_level_, true, &channel);
249 if (multi_install_) {
250 EXPECT_EQ(L"dev-m", channel);
251 } else {
252 EXPECT_EQ(install_static::kChromeChannelDev, channel);
253 }
254 SetChannelName(L"2.0-DEV");
255 install_static::GetChromeChannelName(!system_level_, true, &channel);
256 if (multi_install_) {
257 EXPECT_EQ(L"dev-m", channel);
258 } else {
259 EXPECT_EQ(install_static::kChromeChannelDev, channel);
260 }
261 SetChannelName(L"2.0-dev-eloper");
262 install_static::GetChromeChannelName(!system_level_, true, &channel);
263 if (multi_install_) {
264 EXPECT_EQ(L"dev-m", channel);
265 } else {
266 EXPECT_EQ(install_static::kChromeChannelDev, channel);
267 }
268 SetChannelName(L"2.0-doom");
269 install_static::GetChromeChannelName(!system_level_, true, &channel);
270 if (multi_install_) {
271 EXPECT_EQ(L"dev-m", channel);
272 } else {
273 EXPECT_EQ(install_static::kChromeChannelDev, channel);
274 }
275 SetChannelName(L"250-doom");
276 install_static::GetChromeChannelName(!system_level_, true, &channel);
277 if (multi_install_) {
278 EXPECT_EQ(L"dev-m", channel);
279 } else {
280 EXPECT_EQ(install_static::kChromeChannelDev, channel);
281 }
282 SetChannelName(L"bar-2.0-dev");
283 install_static::GetChromeChannelName(!system_level_, true, &channel);
284 if (multi_install_) {
285 EXPECT_EQ(L"-m", channel);
286 } else {
287 EXPECT_TRUE(channel.empty());
288 }
289 SetChannelName(L"1.0-dev");
290 install_static::GetChromeChannelName(!system_level_, true, &channel);
291 if (multi_install_) {
292 EXPECT_EQ(L"-m", channel);
293 } else {
294 EXPECT_TRUE(channel.empty());
295 }
296
297 SetChannelName(L"x64-beta");
298 install_static::GetChromeChannelName(!system_level_, true, &channel);
299 if (multi_install_) {
300 EXPECT_EQ(L"beta-m", channel);
301 } else {
302 EXPECT_EQ(install_static::kChromeChannelBeta, channel);
303 }
304 SetChannelName(L"bar-x64-beta");
305 if (multi_install_) {
grt (UTC plus 2) 2016/05/06 15:05:01 GetChromeChannelName before this?
ananta 2016/05/06 19:36:03 Done. Forgot to upload the patch with the fix yest
306 EXPECT_EQ(L"beta-m", channel);
307 } else {
308 EXPECT_EQ(install_static::kChromeChannelBeta, channel);
309 }
310 SetChannelName(L"x64-Beta");
311 if (multi_install_) {
grt (UTC plus 2) 2016/05/06 15:05:01 GetChromeChannelName before this?
ananta 2016/05/06 19:36:03 Done.
312 EXPECT_EQ(L"beta-m", channel);
313 } else {
314 EXPECT_EQ(install_static::kChromeChannelBeta, channel);
315 }
316
317 SetChannelName(L"x64-stable");
318 install_static::GetChromeChannelName(!system_level_, true, &channel);
319 EXPECT_EQ(install_static::kChromeChannelStable, channel);
grt (UTC plus 2) 2016/05/06 15:05:01 why isn't this handling multi-install as above?
ananta 2016/05/06 19:36:03 Channel names with "stable" in them are returned a
ananta 2016/05/06 21:30:11 Please look here https://code.google.com/p/chromiu
grt (UTC plus 2) 2016/05/09 18:54:11 Correct. The modifier is still added in this case
ananta 2016/05/09 22:21:07 Thanks. Done
320 SetChannelName(L"baz-x64-stable");
321 install_static::GetChromeChannelName(!system_level_, true, &channel);
322 EXPECT_EQ(install_static::kChromeChannelStable, channel);
323 SetChannelName(L"x64-Stable");
324 install_static::GetChromeChannelName(!system_level_, true, &channel);
325 EXPECT_EQ(install_static::kChromeChannelStable, channel);
326
327 SetChannelName(L"fuzzy");
328 install_static::GetChromeChannelName(!system_level_, true, &channel);
329 if (multi_install_) {
330 EXPECT_EQ(L"-m", channel);
331 } else {
332 EXPECT_TRUE(channel.empty());
333 }
334 SetChannelName(L"foo");
335 install_static::GetChromeChannelName(!system_level_, true, &channel);
336 if (multi_install_) {
337 EXPECT_EQ(L"-m", channel);
338 } else {
339 EXPECT_TRUE(channel.empty());
340 }
178 } 341 }
179 342
180 INSTANTIATE_TEST_CASE_P(Canary, ChromeElfUtilTest, 343 INSTANTIATE_TEST_CASE_P(Canary, ChromeElfUtilTest,
181 testing::Combine(testing::Values("canary"), 344 testing::Combine(testing::Values("canary"),
182 testing::Values("user"), 345 testing::Values("user"),
183 testing::Values("single"))); 346 testing::Values("single")));
184 INSTANTIATE_TEST_CASE_P(GoogleChrome, ChromeElfUtilTest, 347 INSTANTIATE_TEST_CASE_P(GoogleChrome, ChromeElfUtilTest,
185 testing::Combine(testing::Values("google"), 348 testing::Combine(testing::Values("google"),
186 testing::Values("user", "system"), 349 testing::Values("user", "system"),
187 testing::Values("single", "multi"))); 350 testing::Values("single", "multi")));
188 351
352 // Tests the MatchPattern function in the install_static library.
353 // TODO(ananta)
354 // Move this to install_static_unittests.
355 // http://crbug.com/604923
356 TEST(MiscUtilTest, InstallStaticMatchPattern) {
357 EXPECT_TRUE(install_static::MatchPattern(L"", L""));
358 EXPECT_TRUE(install_static::MatchPattern(L"", L"*"));
359 EXPECT_FALSE(install_static::MatchPattern(L"", L"*a"));
360 EXPECT_FALSE(install_static::MatchPattern(L"", L"abc"));
361 EXPECT_TRUE(install_static::MatchPattern(L"Hello1234", L"He??o*1*"));
362 EXPECT_TRUE(install_static::MatchPattern(L"Foo", L"F*?"));
363 EXPECT_TRUE(install_static::MatchPattern(L"Foo", L"F*"));
364 EXPECT_FALSE(install_static::MatchPattern(L"Foo", L"F*b"));
365 EXPECT_TRUE(install_static::MatchPattern(L"abcd", L"*c*d"));
366 EXPECT_TRUE(install_static::MatchPattern(L"abcd", L"*?c*d"));
367 EXPECT_FALSE(install_static::MatchPattern(L"abcd", L"abcd*efgh"));
368 EXPECT_TRUE(install_static::MatchPattern(L"foobarabc", L"*bar*"));
369 }
370
189 } // namespace 371 } // namespace
OLDNEW
« no previous file with comments | « chrome_elf/chrome_elf_main.cc ('k') | chrome_elf/elf_imports_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698