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

Side by Side Diff: chrome_elf/chrome_elf_util_unittest.cc

Issue 1963373003: Revert of Remove dependencies on chrome\installer from the ChromeCrashReporterClient class on Windows. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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; 13 namespace {
14 14
15 namespace { 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}";
16 27
17 const wchar_t kCanaryExePath[] = 28 const wchar_t kCanaryExePath[] =
18 L"C:\\Users\\user\\AppData\\Local\\Google\\Chrome SxS\\Application" 29 L"C:\\Users\\user\\AppData\\Local\\Google\\Chrome SxS\\Application"
19 L"\\chrome.exe"; 30 L"\\chrome.exe";
20 const wchar_t kChromeSystemExePath[] = 31 const wchar_t kChromeSystemExePath[] =
21 L"C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe"; 32 L"C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe";
22 const wchar_t kChromeUserExePath[] = 33 const wchar_t kChromeUserExePath[] =
23 L"C:\\Users\\user\\AppData\\Local\\Google\\Chrome\\Application\\chrome.exe"; 34 L"C:\\Users\\user\\AppData\\Local\\Google\\Chrome\\Application\\chrome.exe";
24 const wchar_t kChromiumExePath[] = 35 const wchar_t kChromiumExePath[] =
25 L"C:\\Users\\user\\AppData\\Local\\Chromium\\Application\\chrome.exe"; 36 L"C:\\Users\\user\\AppData\\Local\\Chromium\\Application\\chrome.exe";
26 37
38
27 TEST(ChromeElfUtilTest, CanaryTest) { 39 TEST(ChromeElfUtilTest, CanaryTest) {
28 EXPECT_TRUE(IsSxSChrome(kCanaryExePath)); 40 EXPECT_TRUE(IsCanary(kCanaryExePath));
29 EXPECT_FALSE(IsSxSChrome(kChromeUserExePath)); 41 EXPECT_FALSE(IsCanary(kChromeUserExePath));
30 EXPECT_FALSE(IsSxSChrome(kChromiumExePath)); 42 EXPECT_FALSE(IsCanary(kChromiumExePath));
31 } 43 }
32 44
33 TEST(ChromeElfUtilTest, SystemInstallTest) { 45 TEST(ChromeElfUtilTest, SystemInstallTest) {
34 EXPECT_TRUE(IsSystemInstall(kChromeSystemExePath)); 46 EXPECT_TRUE(IsSystemInstall(kChromeSystemExePath));
35 EXPECT_FALSE(IsSystemInstall(kChromeUserExePath)); 47 EXPECT_FALSE(IsSystemInstall(kChromeUserExePath));
36 } 48 }
37 49
38 TEST(ChromeElfUtilTest, BrowserProcessTest) { 50 TEST(ChromeElfUtilTest, BrowserProcessTest) {
39 EXPECT_EQ(ProcessType::UNINITIALIZED, g_process_type); 51 EXPECT_EQ(ProcessType::UNINITIALIZED, g_process_type);
40 InitializeProcessType(); 52 InitializeProcessType();
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 LONG result; 112 LONG result;
101 if (multi) { 113 if (multi) {
102 result = key.WriteValue(kUninstallArgumentsField, 114 result = key.WriteValue(kUninstallArgumentsField,
103 L"yadda yadda --multi-install yadda yadda"); 115 L"yadda yadda --multi-install yadda yadda");
104 } else { 116 } else {
105 result = key.DeleteValue(kUninstallArgumentsField); 117 result = key.DeleteValue(kUninstallArgumentsField);
106 } 118 }
107 ASSERT_EQ(ERROR_SUCCESS, result); 119 ASSERT_EQ(ERROR_SUCCESS, result);
108 } 120 }
109 121
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 SetChannelName(L"x64-stable");
283 install_static::GetChromeChannelName(!system_level_, add_modifier,
284 &channel);
285 if (multi_install_ && add_modifier) {
286 EXPECT_EQ(L"-m", channel);
287 } else {
288 EXPECT_EQ(install_static::kChromeChannelStable, channel);
289 }
290 SetChannelName(L"baz-x64-stable");
291 install_static::GetChromeChannelName(!system_level_, add_modifier,
292 &channel);
293 if (multi_install_ && add_modifier) {
294 EXPECT_EQ(L"-m", channel);
295 } else {
296 EXPECT_EQ(install_static::kChromeChannelStable, channel);
297 }
298 SetChannelName(L"x64-Stable");
299 install_static::GetChromeChannelName(!system_level_, add_modifier,
300 &channel);
301 if (multi_install_ && add_modifier) {
302 EXPECT_EQ(L"-m", channel);
303 } else {
304 EXPECT_EQ(install_static::kChromeChannelStable, channel);
305 }
306
307 SetChannelName(L"fuzzy");
308 install_static::GetChromeChannelName(!system_level_, add_modifier,
309 &channel);
310 if (multi_install_ && add_modifier) {
311 EXPECT_EQ(L"-m", channel);
312 } else {
313 EXPECT_EQ(install_static::kChromeChannelStable, channel);
314 }
315 SetChannelName(L"foo");
316 install_static::GetChromeChannelName(!system_level_, add_modifier,
317 &channel);
318 if (multi_install_ && add_modifier) {
319 EXPECT_EQ(L"-m", channel);
320 } else {
321 EXPECT_EQ(install_static::kChromeChannelStable, channel);
322 }
323 }
324
325 const wchar_t* app_guid_; 122 const wchar_t* app_guid_;
326 const wchar_t* chrome_path_; 123 const wchar_t* chrome_path_;
327 bool system_level_; 124 bool system_level_;
328 bool multi_install_; 125 bool multi_install_;
329 bool is_canary_; 126 bool is_canary_;
330 registry_util::RegistryOverrideManager override_manager_; 127 registry_util::RegistryOverrideManager override_manager_;
331 }; 128 };
332 129
333 TEST_P(ChromeElfUtilTest, MultiInstallTest) { 130 TEST_P(ChromeElfUtilTest, MultiInstallTest) {
334 if (is_canary_) 131 if (is_canary_)
335 return; 132 return;
336 SetMultiInstallStateInRegistry(system_level_, true); 133 SetMultiInstallStateInRegistry(system_level_, true);
337 EXPECT_TRUE(IsMultiInstall(system_level_)); 134 EXPECT_TRUE(IsMultiInstall(system_level_));
338 135
339 SetMultiInstallStateInRegistry(system_level_, false); 136 SetMultiInstallStateInRegistry(system_level_, false);
340 EXPECT_FALSE(IsMultiInstall(system_level_)); 137 EXPECT_FALSE(IsMultiInstall(system_level_));
341 } 138 }
342 139
343 TEST_P(ChromeElfUtilTest, UsageStatsAbsent) { 140 TEST_P(ChromeElfUtilTest, UsageStatsAbsent) {
344 EXPECT_FALSE(GetCollectStatsConsentForTesting(chrome_path_)); 141 EXPECT_FALSE(AreUsageStatsEnabled(chrome_path_));
345 } 142 }
346 143
347 TEST_P(ChromeElfUtilTest, UsageStatsZero) { 144 TEST_P(ChromeElfUtilTest, UsageStatsZero) {
348 SetUsageStat(0, false); 145 SetUsageStat(0, false);
349 EXPECT_FALSE(GetCollectStatsConsentForTesting(chrome_path_)); 146 EXPECT_FALSE(AreUsageStatsEnabled(chrome_path_));
350 } 147 }
351 148
352 TEST_P(ChromeElfUtilTest, UsageStatsOne) { 149 TEST_P(ChromeElfUtilTest, UsageStatsOne) {
353 SetUsageStat(1, false); 150 SetUsageStat(1, false);
354 EXPECT_TRUE(GetCollectStatsConsentForTesting(chrome_path_)); 151 EXPECT_TRUE(AreUsageStatsEnabled(chrome_path_));
355 if (is_canary_) { 152 if (is_canary_) {
356 EXPECT_FALSE(GetCollectStatsConsentForTesting(kChromeUserExePath)); 153 EXPECT_FALSE(AreUsageStatsEnabled(kChromeUserExePath));
357 EXPECT_FALSE(GetCollectStatsConsentForTesting(kChromeSystemExePath)); 154 EXPECT_FALSE(AreUsageStatsEnabled(kChromeSystemExePath));
358 } else if (system_level_) { 155 } else if (system_level_) {
359 EXPECT_FALSE(GetCollectStatsConsentForTesting(kCanaryExePath)); 156 EXPECT_FALSE(AreUsageStatsEnabled(kCanaryExePath));
360 EXPECT_FALSE(GetCollectStatsConsentForTesting(kChromeUserExePath)); 157 EXPECT_FALSE(AreUsageStatsEnabled(kChromeUserExePath));
361 } else { 158 } else {
362 EXPECT_FALSE(GetCollectStatsConsentForTesting(kCanaryExePath)); 159 EXPECT_FALSE(AreUsageStatsEnabled(kCanaryExePath));
363 EXPECT_FALSE(GetCollectStatsConsentForTesting(kChromeSystemExePath)); 160 EXPECT_FALSE(AreUsageStatsEnabled(kChromeSystemExePath));
364 } 161 }
365 } 162 }
366 163
367 TEST_P(ChromeElfUtilTest, UsageStatsZeroInStateMedium) { 164 TEST_P(ChromeElfUtilTest, UsageStatsZeroInStateMedium) {
368 if (!system_level_) 165 if (!system_level_)
369 return; 166 return;
370 SetUsageStat(0, true); 167 SetUsageStat(0, true);
371 EXPECT_FALSE(GetCollectStatsConsentForTesting(chrome_path_)); 168 EXPECT_FALSE(AreUsageStatsEnabled(chrome_path_));
372 } 169 }
373 170
374 TEST_P(ChromeElfUtilTest, UsageStatsOneInStateMedium) { 171 TEST_P(ChromeElfUtilTest, UsageStatsOneInStateMedium) {
375 if (!system_level_) 172 if (!system_level_)
376 return; 173 return;
377 SetUsageStat(1, true); 174 SetUsageStat(1, true);
378 EXPECT_TRUE(GetCollectStatsConsentForTesting(chrome_path_)); 175 EXPECT_TRUE(AreUsageStatsEnabled(chrome_path_));
379 EXPECT_FALSE(GetCollectStatsConsentForTesting(kCanaryExePath)); 176 EXPECT_FALSE(AreUsageStatsEnabled(kCanaryExePath));
380 EXPECT_FALSE(GetCollectStatsConsentForTesting(kChromeUserExePath)); 177 EXPECT_FALSE(AreUsageStatsEnabled(kChromeUserExePath));
381 }
382
383 // TODO(ananta)
384 // Move this to install_static_unittests.
385 // http://crbug.com/604923
386 // This test tests the install_static::GetChromeChannelName function and is
387 // based on the ChannelInfoTest.Channels in channel_info_unittest.cc
388 TEST_P(ChromeElfUtilTest, InstallStaticGetChannelNameTest) {
389 PerformChannelNameTests(true); // add_modifier
390 PerformChannelNameTests(false); // !add_modifier
391 } 178 }
392 179
393 INSTANTIATE_TEST_CASE_P(Canary, ChromeElfUtilTest, 180 INSTANTIATE_TEST_CASE_P(Canary, ChromeElfUtilTest,
394 testing::Combine(testing::Values("canary"), 181 testing::Combine(testing::Values("canary"),
395 testing::Values("user"), 182 testing::Values("user"),
396 testing::Values("single"))); 183 testing::Values("single")));
397 INSTANTIATE_TEST_CASE_P(GoogleChrome, ChromeElfUtilTest, 184 INSTANTIATE_TEST_CASE_P(GoogleChrome, ChromeElfUtilTest,
398 testing::Combine(testing::Values("google"), 185 testing::Combine(testing::Values("google"),
399 testing::Values("user", "system"), 186 testing::Values("user", "system"),
400 testing::Values("single", "multi"))); 187 testing::Values("single", "multi")));
401 188
402 // Tests the MatchPattern function in the install_static library.
403 // TODO(ananta)
404 // Move this to install_static_unittests.
405 // http://crbug.com/604923
406 TEST(MiscUtilTest, InstallStaticMatchPattern) {
407 EXPECT_TRUE(install_static::MatchPattern(L"", L""));
408 EXPECT_TRUE(install_static::MatchPattern(L"", L"*"));
409 EXPECT_FALSE(install_static::MatchPattern(L"", L"*a"));
410 EXPECT_FALSE(install_static::MatchPattern(L"", L"abc"));
411 EXPECT_TRUE(install_static::MatchPattern(L"Hello1234", L"He??o*1*"));
412 EXPECT_TRUE(install_static::MatchPattern(L"Foo", L"F*?"));
413 EXPECT_TRUE(install_static::MatchPattern(L"Foo", L"F*"));
414 EXPECT_FALSE(install_static::MatchPattern(L"Foo", L"F*b"));
415 EXPECT_TRUE(install_static::MatchPattern(L"abcd", L"*c*d"));
416 EXPECT_TRUE(install_static::MatchPattern(L"abcd", L"*?c*d"));
417 EXPECT_FALSE(install_static::MatchPattern(L"abcd", L"abcd*efgh"));
418 EXPECT_TRUE(install_static::MatchPattern(L"foobarabc", L"*bar*"));
419 }
420
421 } // namespace 189 } // 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