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

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: Fixed compile err 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
118 // This function tests the install_static::GetChromeChannelName function and
119 // is based on the ChannelInfoTest.Channels in channel_info_unittest.cc.
120 // The |add_modifier| parameter controls whether we expect modifiers in the
121 // returned channel name.
122 void PerformChannelNameTests(bool add_modifier) {
123 // We can't test the channel name correctly for canary mode because the
124 // install_static checks whether an exe is a canary executable is based on
125 // the path where the exe is running from.
126 if (is_canary_)
127 return;
128 SetChannelName(L"");
129 base::string16 channel;
130 install_static::GetChromeChannelName(!system_level_, add_modifier,
131 &channel);
132 if (multi_install_ && add_modifier) {
133 EXPECT_EQ(L"-m", channel);
134 } else {
135 EXPECT_EQ(install_static::kChromeChannelStable, channel);
136 }
137
138 SetChannelName(L"-full");
139 install_static::GetChromeChannelName(!system_level_, add_modifier,
140 &channel);
141 if (multi_install_ && add_modifier) {
142 EXPECT_EQ(L"-m", channel);
143 } else {
144 EXPECT_EQ(install_static::kChromeChannelStable, channel);
145 }
146
147 SetChannelName(L"1.1-beta");
148 install_static::GetChromeChannelName(!system_level_, add_modifier,
149 &channel);
150 if (multi_install_ && add_modifier) {
151 EXPECT_EQ(L"beta-m", channel);
152 } else {
153 EXPECT_EQ(install_static::kChromeChannelBeta, channel);
154 }
155
156 SetChannelName(L"1.1-beta");
157 install_static::GetChromeChannelName(!system_level_, add_modifier,
158 &channel);
159 if (multi_install_ && add_modifier) {
160 EXPECT_EQ(L"beta-m", channel);
161 } else {
162 EXPECT_EQ(install_static::kChromeChannelBeta, channel);
163 }
164
165 SetChannelName(L"1.1-bar");
166 install_static::GetChromeChannelName(!system_level_, add_modifier,
167 &channel);
168 if (multi_install_ && add_modifier) {
169 EXPECT_EQ(L"beta-m", channel);
170 } else {
171 EXPECT_EQ(install_static::kChromeChannelBeta, channel);
172 }
173
174 SetChannelName(L"1n1-foobar");
175 install_static::GetChromeChannelName(!system_level_, add_modifier,
176 &channel);
177 if (multi_install_ && add_modifier) {
178 EXPECT_EQ(L"beta-m", channel);
179 } else {
180 EXPECT_EQ(install_static::kChromeChannelBeta, channel);
181 }
182
183 SetChannelName(L"foo-1.1-beta");
184 install_static::GetChromeChannelName(!system_level_, add_modifier,
185 &channel);
186 if (multi_install_ && add_modifier) {
187 EXPECT_EQ(L"-m", channel);
188 } else {
189 EXPECT_EQ(install_static::kChromeChannelStable, channel);
190 }
191 SetChannelName(L"2.0-beta");
192 install_static::GetChromeChannelName(!system_level_, add_modifier,
193 &channel);
194 if (multi_install_ && add_modifier) {
195 EXPECT_EQ(L"-m", channel);
196 } else {
197 EXPECT_EQ(install_static::kChromeChannelStable, channel);
198 }
199
200 SetChannelName(L"2.0-dev");
201 install_static::GetChromeChannelName(!system_level_, add_modifier,
202 &channel);
203 if (multi_install_ && add_modifier) {
204 EXPECT_EQ(L"dev-m", channel);
205 } else {
206 EXPECT_EQ(install_static::kChromeChannelDev, channel);
207 }
208 SetChannelName(L"2.0-DEV");
209 install_static::GetChromeChannelName(!system_level_, add_modifier,
210 &channel);
211 if (multi_install_ && add_modifier) {
212 EXPECT_EQ(L"dev-m", channel);
213 } else {
214 EXPECT_EQ(install_static::kChromeChannelDev, channel);
215 }
216 SetChannelName(L"2.0-dev-eloper");
217 install_static::GetChromeChannelName(!system_level_, add_modifier,
218 &channel);
219 if (multi_install_ && add_modifier) {
220 EXPECT_EQ(L"dev-m", channel);
221 } else {
222 EXPECT_EQ(install_static::kChromeChannelDev, channel);
223 }
224 SetChannelName(L"2.0-doom");
225 install_static::GetChromeChannelName(!system_level_, add_modifier,
226 &channel);
227 if (multi_install_ && add_modifier) {
228 EXPECT_EQ(L"dev-m", channel);
229 } else {
230 EXPECT_EQ(install_static::kChromeChannelDev, channel);
231 }
232 SetChannelName(L"250-doom");
233 install_static::GetChromeChannelName(!system_level_, add_modifier,
234 &channel);
235 if (multi_install_ && add_modifier) {
236 EXPECT_EQ(L"dev-m", channel);
237 } else {
238 EXPECT_EQ(install_static::kChromeChannelDev, channel);
239 }
240 SetChannelName(L"bar-2.0-dev");
241 install_static::GetChromeChannelName(!system_level_, add_modifier,
242 &channel);
243 if (multi_install_ && add_modifier) {
244 EXPECT_EQ(L"-m", channel);
245 } else {
246 EXPECT_EQ(install_static::kChromeChannelStable, channel);
247 }
248 SetChannelName(L"1.0-dev");
249 install_static::GetChromeChannelName(!system_level_, add_modifier,
250 &channel);
251 if (multi_install_ && add_modifier) {
252 EXPECT_EQ(L"-m", channel);
253 } else {
254 EXPECT_EQ(install_static::kChromeChannelStable, channel);
255 }
256
257 SetChannelName(L"x64-beta");
258 install_static::GetChromeChannelName(!system_level_, add_modifier,
259 &channel);
260 if (multi_install_ && add_modifier) {
261 EXPECT_EQ(L"beta-m", channel);
262 } else {
263 EXPECT_EQ(install_static::kChromeChannelBeta, channel);
264 }
265 SetChannelName(L"bar-x64-beta");
266 install_static::GetChromeChannelName(!system_level_, add_modifier,
267 &channel);
268 if (multi_install_ && add_modifier) {
269 EXPECT_EQ(L"beta-m", channel);
270 } else {
271 EXPECT_EQ(install_static::kChromeChannelBeta, channel);
272 }
273 SetChannelName(L"x64-Beta");
274 install_static::GetChromeChannelName(!system_level_, add_modifier,
275 &channel);
276 if (multi_install_ && add_modifier) {
277 EXPECT_EQ(L"beta-m", channel);
278 } else {
279 EXPECT_EQ(install_static::kChromeChannelBeta, channel);
280 }
281
282 // We don't check for modifiers here as any channel name with "stable" in it
grt (UTC plus 2) 2016/05/10 16:04:16 please update comment
ananta 2016/05/10 19:28:18 Done.
283 // is returned as an empty string.
284 SetChannelName(L"x64-stable");
285 install_static::GetChromeChannelName(!system_level_, add_modifier,
286 &channel);
287 if (multi_install_ && add_modifier) {
288 EXPECT_EQ(L"-m", channel);
289 } else {
290 EXPECT_EQ(install_static::kChromeChannelStable, channel);
291 }
292 SetChannelName(L"baz-x64-stable");
293 install_static::GetChromeChannelName(!system_level_, add_modifier,
294 &channel);
295 if (multi_install_ && add_modifier) {
296 EXPECT_EQ(L"-m", channel);
297 } else {
298 EXPECT_EQ(install_static::kChromeChannelStable, channel);
299 }
300 SetChannelName(L"x64-Stable");
301 install_static::GetChromeChannelName(!system_level_, add_modifier,
302 &channel);
303 if (multi_install_ && add_modifier) {
304 EXPECT_EQ(L"-m", channel);
305 } else {
306 EXPECT_EQ(install_static::kChromeChannelStable, channel);
307 }
308
309 SetChannelName(L"fuzzy");
310 install_static::GetChromeChannelName(!system_level_, add_modifier,
311 &channel);
312 if (multi_install_ && add_modifier) {
313 EXPECT_EQ(L"-m", channel);
314 } else {
315 EXPECT_EQ(install_static::kChromeChannelStable, channel);
316 }
317 SetChannelName(L"foo");
318 install_static::GetChromeChannelName(!system_level_, add_modifier,
319 &channel);
320 if (multi_install_ && add_modifier) {
321 EXPECT_EQ(L"-m", channel);
322 } else {
323 EXPECT_EQ(install_static::kChromeChannelStable, channel);
324 }
325 }
326
122 const wchar_t* app_guid_; 327 const wchar_t* app_guid_;
123 const wchar_t* chrome_path_; 328 const wchar_t* chrome_path_;
124 bool system_level_; 329 bool system_level_;
125 bool multi_install_; 330 bool multi_install_;
126 bool is_canary_; 331 bool is_canary_;
127 registry_util::RegistryOverrideManager override_manager_; 332 registry_util::RegistryOverrideManager override_manager_;
128 }; 333 };
129 334
130 TEST_P(ChromeElfUtilTest, MultiInstallTest) { 335 TEST_P(ChromeElfUtilTest, MultiInstallTest) {
131 if (is_canary_) 336 if (is_canary_)
132 return; 337 return;
133 SetMultiInstallStateInRegistry(system_level_, true); 338 SetMultiInstallStateInRegistry(system_level_, true);
134 EXPECT_TRUE(IsMultiInstall(system_level_)); 339 EXPECT_TRUE(IsMultiInstall(system_level_));
135 340
136 SetMultiInstallStateInRegistry(system_level_, false); 341 SetMultiInstallStateInRegistry(system_level_, false);
137 EXPECT_FALSE(IsMultiInstall(system_level_)); 342 EXPECT_FALSE(IsMultiInstall(system_level_));
138 } 343 }
139 344
140 TEST_P(ChromeElfUtilTest, UsageStatsAbsent) { 345 TEST_P(ChromeElfUtilTest, UsageStatsAbsent) {
141 EXPECT_FALSE(AreUsageStatsEnabled(chrome_path_)); 346 EXPECT_FALSE(GetCollectStatsConsentForTesting(chrome_path_));
142 } 347 }
143 348
144 TEST_P(ChromeElfUtilTest, UsageStatsZero) { 349 TEST_P(ChromeElfUtilTest, UsageStatsZero) {
145 SetUsageStat(0, false); 350 SetUsageStat(0, false);
146 EXPECT_FALSE(AreUsageStatsEnabled(chrome_path_)); 351 EXPECT_FALSE(GetCollectStatsConsentForTesting(chrome_path_));
147 } 352 }
148 353
149 TEST_P(ChromeElfUtilTest, UsageStatsOne) { 354 TEST_P(ChromeElfUtilTest, UsageStatsOne) {
150 SetUsageStat(1, false); 355 SetUsageStat(1, false);
151 EXPECT_TRUE(AreUsageStatsEnabled(chrome_path_)); 356 EXPECT_TRUE(GetCollectStatsConsentForTesting(chrome_path_));
152 if (is_canary_) { 357 if (is_canary_) {
153 EXPECT_FALSE(AreUsageStatsEnabled(kChromeUserExePath)); 358 EXPECT_FALSE(GetCollectStatsConsentForTesting(kChromeUserExePath));
154 EXPECT_FALSE(AreUsageStatsEnabled(kChromeSystemExePath)); 359 EXPECT_FALSE(GetCollectStatsConsentForTesting(kChromeSystemExePath));
155 } else if (system_level_) { 360 } else if (system_level_) {
156 EXPECT_FALSE(AreUsageStatsEnabled(kCanaryExePath)); 361 EXPECT_FALSE(GetCollectStatsConsentForTesting(kCanaryExePath));
157 EXPECT_FALSE(AreUsageStatsEnabled(kChromeUserExePath)); 362 EXPECT_FALSE(GetCollectStatsConsentForTesting(kChromeUserExePath));
158 } else { 363 } else {
159 EXPECT_FALSE(AreUsageStatsEnabled(kCanaryExePath)); 364 EXPECT_FALSE(GetCollectStatsConsentForTesting(kCanaryExePath));
160 EXPECT_FALSE(AreUsageStatsEnabled(kChromeSystemExePath)); 365 EXPECT_FALSE(GetCollectStatsConsentForTesting(kChromeSystemExePath));
161 } 366 }
162 } 367 }
163 368
164 TEST_P(ChromeElfUtilTest, UsageStatsZeroInStateMedium) { 369 TEST_P(ChromeElfUtilTest, UsageStatsZeroInStateMedium) {
165 if (!system_level_) 370 if (!system_level_)
166 return; 371 return;
167 SetUsageStat(0, true); 372 SetUsageStat(0, true);
168 EXPECT_FALSE(AreUsageStatsEnabled(chrome_path_)); 373 EXPECT_FALSE(GetCollectStatsConsentForTesting(chrome_path_));
169 } 374 }
170 375
171 TEST_P(ChromeElfUtilTest, UsageStatsOneInStateMedium) { 376 TEST_P(ChromeElfUtilTest, UsageStatsOneInStateMedium) {
172 if (!system_level_) 377 if (!system_level_)
173 return; 378 return;
174 SetUsageStat(1, true); 379 SetUsageStat(1, true);
175 EXPECT_TRUE(AreUsageStatsEnabled(chrome_path_)); 380 EXPECT_TRUE(GetCollectStatsConsentForTesting(chrome_path_));
176 EXPECT_FALSE(AreUsageStatsEnabled(kCanaryExePath)); 381 EXPECT_FALSE(GetCollectStatsConsentForTesting(kCanaryExePath));
177 EXPECT_FALSE(AreUsageStatsEnabled(kChromeUserExePath)); 382 EXPECT_FALSE(GetCollectStatsConsentForTesting(kChromeUserExePath));
383 }
384
385 // TODO(ananta)
386 // Move this to install_static_unittests.
387 // http://crbug.com/604923
388 // This test tests the install_static::GetChromeChannelName function and is
389 // based on the ChannelInfoTest.Channels in channel_info_unittest.cc
390 TEST_P(ChromeElfUtilTest, InstallStaticGetChannelNameTest) {
391 PerformChannelNameTests(true); // add_modifier
392 PerformChannelNameTests(false); // !add_modifier
178 } 393 }
179 394
180 INSTANTIATE_TEST_CASE_P(Canary, ChromeElfUtilTest, 395 INSTANTIATE_TEST_CASE_P(Canary, ChromeElfUtilTest,
181 testing::Combine(testing::Values("canary"), 396 testing::Combine(testing::Values("canary"),
182 testing::Values("user"), 397 testing::Values("user"),
183 testing::Values("single"))); 398 testing::Values("single")));
184 INSTANTIATE_TEST_CASE_P(GoogleChrome, ChromeElfUtilTest, 399 INSTANTIATE_TEST_CASE_P(GoogleChrome, ChromeElfUtilTest,
185 testing::Combine(testing::Values("google"), 400 testing::Combine(testing::Values("google"),
186 testing::Values("user", "system"), 401 testing::Values("user", "system"),
187 testing::Values("single", "multi"))); 402 testing::Values("single", "multi")));
188 403
404 // Tests the MatchPattern function in the install_static library.
405 // TODO(ananta)
406 // Move this to install_static_unittests.
407 // http://crbug.com/604923
408 TEST(MiscUtilTest, InstallStaticMatchPattern) {
409 EXPECT_TRUE(install_static::MatchPattern(L"", L""));
410 EXPECT_TRUE(install_static::MatchPattern(L"", L"*"));
411 EXPECT_FALSE(install_static::MatchPattern(L"", L"*a"));
412 EXPECT_FALSE(install_static::MatchPattern(L"", L"abc"));
413 EXPECT_TRUE(install_static::MatchPattern(L"Hello1234", L"He??o*1*"));
414 EXPECT_TRUE(install_static::MatchPattern(L"Foo", L"F*?"));
415 EXPECT_TRUE(install_static::MatchPattern(L"Foo", L"F*"));
416 EXPECT_FALSE(install_static::MatchPattern(L"Foo", L"F*b"));
417 EXPECT_TRUE(install_static::MatchPattern(L"abcd", L"*c*d"));
418 EXPECT_TRUE(install_static::MatchPattern(L"abcd", L"*?c*d"));
419 EXPECT_FALSE(install_static::MatchPattern(L"abcd", L"abcd*efgh"));
420 EXPECT_TRUE(install_static::MatchPattern(L"foobarabc", L"*bar*"));
421 }
422
189 } // namespace 423 } // 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