blob: ad4671a5efe3913c49197780833621dfb4c37f88 [file] [log] [blame]
[email protected]5a542072014-02-24 02:12:091// Copyright 2014 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.
4
[email protected]5a542072014-02-24 02:12:095#include <tuple>
pennymac84fd6692016-07-13 22:35:346#include <windows.h>
7#include <versionhelpers.h> // windows.h must be before.
[email protected]5a542072014-02-24 02:12:098
9#include "base/test/test_reg_util_win.h"
10#include "base/win/registry.h"
ananta0a700e22016-04-21 03:00:4611#include "chrome/install_static/install_util.h"
pennymac84fd6692016-07-13 22:35:3412#include "chrome_elf/chrome_elf_constants.h"
pennymac4e0b5f22016-07-19 19:15:4513#include "chrome_elf/chrome_elf_security.h"
pennymac84fd6692016-07-13 22:35:3414#include "chrome_elf/nt_registry/nt_registry.h"
[email protected]5a542072014-02-24 02:12:0915#include "testing/gtest/include/gtest/gtest.h"
16#include "testing/platform_test.h"
17
ananta69086d72016-05-12 23:29:0418using namespace install_static;
19
[email protected]5a542072014-02-24 02:12:0920namespace {
21
[email protected]5a542072014-02-24 02:12:0922const wchar_t kCanaryExePath[] =
23 L"C:\\Users\\user\\AppData\\Local\\Google\\Chrome SxS\\Application"
24 L"\\chrome.exe";
25const wchar_t kChromeSystemExePath[] =
26 L"C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe";
27const wchar_t kChromeUserExePath[] =
28 L"C:\\Users\\user\\AppData\\Local\\Google\\Chrome\\Application\\chrome.exe";
29const wchar_t kChromiumExePath[] =
30 L"C:\\Users\\user\\AppData\\Local\\Chromium\\Application\\chrome.exe";
31
pennymac4e0b5f22016-07-19 19:15:4532bool SetSecurityFinchFlag(bool creation) {
33 bool success = true;
34 base::win::RegKey security_key(HKEY_CURRENT_USER, L"", KEY_ALL_ACCESS);
35
36 if (creation) {
37 if (ERROR_SUCCESS !=
38 security_key.CreateKey(elf_sec::kRegSecurityFinchPath, KEY_QUERY_VALUE))
39 success = false;
40 } else {
41 if (ERROR_SUCCESS != security_key.DeleteKey(elf_sec::kRegSecurityFinchPath))
42 success = false;
43 }
44
45 security_key.Close();
46 return success;
47}
48
49bool IsSecuritySet() {
50 typedef decltype(GetProcessMitigationPolicy)* GetProcessMitigationPolicyFunc;
51
52 // Check the settings from EarlyBrowserSecurity().
53 if (::IsWindows8OrGreater()) {
54 GetProcessMitigationPolicyFunc get_process_mitigation_policy =
55 reinterpret_cast<GetProcessMitigationPolicyFunc>(::GetProcAddress(
56 ::GetModuleHandleW(L"kernel32.dll"), "GetProcessMitigationPolicy"));
57 if (!get_process_mitigation_policy)
58 return false;
59
60 // Check that extension points are disabled.
61 // (Legacy hooking.)
62 PROCESS_MITIGATION_EXTENSION_POINT_DISABLE_POLICY policy = {};
63 if (!get_process_mitigation_policy(::GetCurrentProcess(),
64 ProcessExtensionPointDisablePolicy,
65 &policy, sizeof(policy)))
66 return false;
67
68 return policy.DisableExtensionPoints;
69 }
70
71 return true;
72}
73
74void RegRedirect(nt::ROOT_KEY key,
75 registry_util::RegistryOverrideManager& rom) {
76 base::string16 temp;
77
78 if (key == nt::HKCU) {
79 rom.OverrideRegistry(HKEY_CURRENT_USER, &temp);
80 ::wcsncpy(nt::HKCU_override, temp.c_str(), nt::g_kRegMaxPathLen - 1);
81 } else if (key == nt::HKLM) {
82 rom.OverrideRegistry(HKEY_LOCAL_MACHINE, &temp);
83 ::wcsncpy(nt::HKLM_override, temp.c_str(), nt::g_kRegMaxPathLen - 1);
84 }
85 // nt::AUTO should not be passed into this function.
86}
87
[email protected]5a542072014-02-24 02:12:0988TEST(ChromeElfUtilTest, CanaryTest) {
ananta69086d72016-05-12 23:29:0489 EXPECT_TRUE(IsSxSChrome(kCanaryExePath));
90 EXPECT_FALSE(IsSxSChrome(kChromeUserExePath));
91 EXPECT_FALSE(IsSxSChrome(kChromiumExePath));
[email protected]5a542072014-02-24 02:12:0992}
93
94TEST(ChromeElfUtilTest, SystemInstallTest) {
95 EXPECT_TRUE(IsSystemInstall(kChromeSystemExePath));
96 EXPECT_FALSE(IsSystemInstall(kChromeUserExePath));
97}
98
caitkpc393a5b2015-05-14 19:56:3399TEST(ChromeElfUtilTest, BrowserProcessTest) {
100 EXPECT_EQ(ProcessType::UNINITIALIZED, g_process_type);
101 InitializeProcessType();
102 EXPECT_FALSE(IsNonBrowserProcess());
103}
104
pennymac4e0b5f22016-07-19 19:15:45105TEST(ChromeElfUtilTest, BrowserProcessSecurityTest) {
106 if (!::IsWindows8OrGreater())
107 return;
108
109 // Set up registry override for this test.
110 registry_util::RegistryOverrideManager override_manager;
111 RegRedirect(nt::HKCU, override_manager);
112
113 // First, ensure that the emergency-off finch signal works.
114 EXPECT_TRUE(SetSecurityFinchFlag(true));
115 EarlyBrowserSecurity();
116 EXPECT_FALSE(IsSecuritySet());
117 EXPECT_TRUE(SetSecurityFinchFlag(false));
118
119 // Second, test that the process mitigation is set when no finch signal.
120 EarlyBrowserSecurity();
121 EXPECT_TRUE(IsSecuritySet());
122}
123
pennymac84fd6692016-07-13 22:35:34124//------------------------------------------------------------------------------
125// NT registry API tests (chrome_elf_reg)
126//------------------------------------------------------------------------------
127
128TEST(ChromeElfUtilTest, NTRegistry) {
129 HANDLE key_handle;
130 const wchar_t* dword_val_name = L"DwordTestValue";
131 DWORD dword_val = 1234;
132 const wchar_t* sz_val_name = L"SzTestValue";
133 base::string16 sz_val = L"blah de blah de blahhhhh.";
134 const wchar_t* sz_val_name2 = L"SzTestValueEmpty";
135 base::string16 sz_val2 = L"";
136 const wchar_t* multisz_val_name = L"SzmultiTestValue";
137 std::vector<base::string16> multisz_val;
138 base::string16 multi1 = L"one";
139 base::string16 multi2 = L"two";
140 base::string16 multi3 = L"three";
141 const wchar_t* multisz_val_name2 = L"SzmultiTestValueBad";
142 base::string16 multi_empty = L"";
143 const wchar_t* sz_new_key_1 = L"test\\new\\subkey";
144 const wchar_t* sz_new_key_2 = L"test\\new\\subkey\\blah\\";
145 const wchar_t* sz_new_key_3 = L"\\test\\new\\subkey\\\\blah2";
146
147 // Set up registry override for this test.
pennymac84fd6692016-07-13 22:35:34148 registry_util::RegistryOverrideManager override_manager;
pennymac4e0b5f22016-07-19 19:15:45149 RegRedirect(nt::HKCU, override_manager);
pennymac84fd6692016-07-13 22:35:34150
151 // Create a temp key to play under.
152 ASSERT_TRUE(nt::CreateRegKey(nt::HKCU, elf_sec::kRegSecurityPath,
153 KEY_ALL_ACCESS, &key_handle));
154
155 // Exercise the supported getter & setter functions.
156 EXPECT_TRUE(nt::SetRegValueDWORD(key_handle, dword_val_name, dword_val));
157 EXPECT_TRUE(nt::SetRegValueSZ(key_handle, sz_val_name, sz_val));
158 EXPECT_TRUE(nt::SetRegValueSZ(key_handle, sz_val_name2, sz_val2));
159
160 DWORD get_dword = 0;
161 base::string16 get_sz;
162 EXPECT_TRUE(nt::QueryRegValueDWORD(key_handle, dword_val_name, &get_dword) &&
163 get_dword == dword_val);
164 EXPECT_TRUE(nt::QueryRegValueSZ(key_handle, sz_val_name, &get_sz) &&
165 get_sz.compare(sz_val) == 0);
166 EXPECT_TRUE(nt::QueryRegValueSZ(key_handle, sz_val_name2, &get_sz) &&
167 get_sz.compare(sz_val2) == 0);
168
169 multisz_val.push_back(multi1);
170 multisz_val.push_back(multi2);
171 multisz_val.push_back(multi3);
172 EXPECT_TRUE(
173 nt::SetRegValueMULTISZ(key_handle, multisz_val_name, multisz_val));
174 multisz_val.clear();
175 multisz_val.push_back(multi_empty);
176 EXPECT_TRUE(
177 nt::SetRegValueMULTISZ(key_handle, multisz_val_name2, multisz_val));
178 multisz_val.clear();
179
180 EXPECT_TRUE(
181 nt::QueryRegValueMULTISZ(key_handle, multisz_val_name, &multisz_val));
182 if (multisz_val.size() == 3) {
183 EXPECT_TRUE(multi1.compare(multisz_val.at(0)) == 0);
184 EXPECT_TRUE(multi2.compare(multisz_val.at(1)) == 0);
185 EXPECT_TRUE(multi3.compare(multisz_val.at(2)) == 0);
186 } else {
187 EXPECT_TRUE(false);
188 }
189 multisz_val.clear();
190
191 EXPECT_TRUE(
192 nt::QueryRegValueMULTISZ(key_handle, multisz_val_name2, &multisz_val));
193 if (multisz_val.size() == 1) {
194 EXPECT_TRUE(multi_empty.compare(multisz_val.at(0)) == 0);
195 } else {
196 EXPECT_TRUE(false);
197 }
198 multisz_val.clear();
199
200 // Clean up
201 EXPECT_TRUE(nt::DeleteRegKey(key_handle));
202 nt::CloseRegKey(key_handle);
203
204 // More tests for CreateRegKey recursion.
205 ASSERT_TRUE(
206 nt::CreateRegKey(nt::HKCU, sz_new_key_1, KEY_ALL_ACCESS, nullptr));
207 EXPECT_TRUE(nt::OpenRegKey(nt::HKCU, sz_new_key_1, KEY_ALL_ACCESS,
208 &key_handle, nullptr));
209 EXPECT_TRUE(nt::DeleteRegKey(key_handle));
210 nt::CloseRegKey(key_handle);
211
212 ASSERT_TRUE(
213 nt::CreateRegKey(nt::HKCU, sz_new_key_2, KEY_ALL_ACCESS, nullptr));
214 EXPECT_TRUE(nt::OpenRegKey(nt::HKCU, sz_new_key_2, KEY_ALL_ACCESS,
215 &key_handle, nullptr));
216 EXPECT_TRUE(nt::DeleteRegKey(key_handle));
217 nt::CloseRegKey(key_handle);
218
219 ASSERT_TRUE(
220 nt::CreateRegKey(nt::HKCU, sz_new_key_3, KEY_ALL_ACCESS, nullptr));
221 EXPECT_TRUE(nt::OpenRegKey(nt::HKCU, L"test\\new\\subkey\\blah2",
222 KEY_ALL_ACCESS, &key_handle, nullptr));
223 EXPECT_TRUE(nt::DeleteRegKey(key_handle));
224 nt::CloseRegKey(key_handle);
225
226 ASSERT_TRUE(nt::CreateRegKey(nt::HKCU, nullptr, KEY_ALL_ACCESS, &key_handle));
227 nt::CloseRegKey(key_handle);
228}
229
[email protected]5a542072014-02-24 02:12:09230// Parameterized test with paramters:
231// 1: product: "canary" or "google"
232// 2: install level: "user" or "system"
233// 3: install mode: "single" or "multi"
pennymac84fd6692016-07-13 22:35:34234class ChromeElfUtilTest
235 : public testing::TestWithParam<
236 std::tuple<const char*, const char*, const char*>> {
[email protected]5a542072014-02-24 02:12:09237 protected:
nick5c1d0602015-04-23 04:43:32238 void SetUp() override {
pennymac4e0b5f22016-07-19 19:15:45239 // Set up registry override for these tests.
240 RegRedirect(nt::HKLM, override_manager_);
241 RegRedirect(nt::HKCU, override_manager_);
pennymac84fd6692016-07-13 22:35:34242
[email protected]5a542072014-02-24 02:12:09243 const char* app;
244 const char* level;
245 const char* mode;
246 std::tie(app, level, mode) = GetParam();
247 is_canary_ = (std::string(app) == "canary");
248 system_level_ = (std::string(level) != "user");
249 multi_install_ = (std::string(mode) != "single");
250 if (is_canary_) {
251 ASSERT_FALSE(system_level_);
252 ASSERT_FALSE(multi_install_);
253 app_guid_ = kAppGuidCanary;
254 chrome_path_ = kCanaryExePath;
255 } else {
256 app_guid_ = kAppGuidGoogleChrome;
pennymac84fd6692016-07-13 22:35:34257 chrome_path_ =
258 (system_level_ ? kChromeSystemExePath : kChromeUserExePath);
[email protected]5a542072014-02-24 02:12:09259 }
260 if (multi_install_) {
261 SetMultiInstallStateInRegistry(system_level_, true);
262 app_guid_ = kAppGuidGoogleBinaries;
263 }
264 }
265
266 base::string16 BuildKey(const wchar_t* path, const wchar_t* guid) {
267 base::string16 full_key_path(path);
268 full_key_path.append(1, L'\\');
269 full_key_path.append(guid);
270 return full_key_path;
271 }
272
273 void SetUsageStat(DWORD value, bool state_medium) {
274 LONG result = base::win::RegKey(
pennymac84fd6692016-07-13 22:35:34275 system_level_ ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER,
276 BuildKey(state_medium ? kRegPathClientStateMedium
277 : kRegPathClientState,
278 app_guid_)
279 .c_str(),
280 KEY_SET_VALUE)
281 .WriteValue(kRegValueUsageStats, value);
[email protected]5a542072014-02-24 02:12:09282 ASSERT_EQ(ERROR_SUCCESS, result);
283 }
284
285 void SetMultiInstallStateInRegistry(bool system_install, bool multi) {
286 base::win::RegKey key(
287 system_install ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER,
288 BuildKey(kRegPathClientState, kAppGuidGoogleChrome).c_str(),
289 KEY_SET_VALUE);
290 LONG result;
291 if (multi) {
292 result = key.WriteValue(kUninstallArgumentsField,
293 L"yadda yadda --multi-install yadda yadda");
294 } else {
295 result = key.DeleteValue(kUninstallArgumentsField);
296 }
297 ASSERT_EQ(ERROR_SUCCESS, result);
298 }
299
ananta69086d72016-05-12 23:29:04300 void SetChannelName(const base::string16& channel_name) {
pennymac84fd6692016-07-13 22:35:34301 LONG result =
302 base::win::RegKey(
303 system_level_ ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER,
304 BuildKey(kRegPathClientState, app_guid_).c_str(), KEY_SET_VALUE)
305 .WriteValue(kRegApField, channel_name.c_str());
ananta69086d72016-05-12 23:29:04306 ASSERT_EQ(ERROR_SUCCESS, result);
307 }
308
309 // This function tests the install_static::GetChromeChannelName function and
310 // is based on the ChannelInfoTest.Channels in channel_info_unittest.cc.
311 // The |add_modifier| parameter controls whether we expect modifiers in the
312 // returned channel name.
313 void PerformChannelNameTests(bool add_modifier) {
314 // We can't test the channel name correctly for canary mode because the
315 // install_static checks whether an exe is a canary executable is based on
316 // the path where the exe is running from.
317 if (is_canary_)
318 return;
319 SetChannelName(L"");
320 base::string16 channel;
321 install_static::GetChromeChannelName(!system_level_, add_modifier,
322 &channel);
323 if (multi_install_ && add_modifier) {
pennymac84fd6692016-07-13 22:35:34324 EXPECT_STREQ(L"-m", channel.c_str());
ananta69086d72016-05-12 23:29:04325 } else {
pennymac84fd6692016-07-13 22:35:34326 EXPECT_STREQ(install_static::kChromeChannelStable, channel.c_str());
ananta69086d72016-05-12 23:29:04327 }
328
329 SetChannelName(L"-full");
330 install_static::GetChromeChannelName(!system_level_, add_modifier,
331 &channel);
332 if (multi_install_ && add_modifier) {
pennymac84fd6692016-07-13 22:35:34333 EXPECT_STREQ(L"-m", channel.c_str());
ananta69086d72016-05-12 23:29:04334 } else {
pennymac84fd6692016-07-13 22:35:34335 EXPECT_STREQ(install_static::kChromeChannelStable, channel.c_str());
ananta69086d72016-05-12 23:29:04336 }
337
338 SetChannelName(L"1.1-beta");
339 install_static::GetChromeChannelName(!system_level_, add_modifier,
340 &channel);
341 if (multi_install_ && add_modifier) {
pennymac84fd6692016-07-13 22:35:34342 EXPECT_STREQ(L"beta-m", channel.c_str());
ananta69086d72016-05-12 23:29:04343 } else {
pennymac84fd6692016-07-13 22:35:34344 EXPECT_STREQ(install_static::kChromeChannelBeta, channel.c_str());
ananta69086d72016-05-12 23:29:04345 }
346
347 SetChannelName(L"1.1-beta");
348 install_static::GetChromeChannelName(!system_level_, add_modifier,
349 &channel);
350 if (multi_install_ && add_modifier) {
pennymac84fd6692016-07-13 22:35:34351 EXPECT_STREQ(L"beta-m", channel.c_str());
ananta69086d72016-05-12 23:29:04352 } else {
pennymac84fd6692016-07-13 22:35:34353 EXPECT_STREQ(install_static::kChromeChannelBeta, channel.c_str());
ananta69086d72016-05-12 23:29:04354 }
355
356 SetChannelName(L"1.1-bar");
357 install_static::GetChromeChannelName(!system_level_, add_modifier,
358 &channel);
359 if (multi_install_ && add_modifier) {
pennymac84fd6692016-07-13 22:35:34360 EXPECT_STREQ(L"beta-m", channel.c_str());
ananta69086d72016-05-12 23:29:04361 } else {
pennymac84fd6692016-07-13 22:35:34362 EXPECT_STREQ(install_static::kChromeChannelBeta, channel.c_str());
ananta69086d72016-05-12 23:29:04363 }
364
365 SetChannelName(L"1n1-foobar");
366 install_static::GetChromeChannelName(!system_level_, add_modifier,
367 &channel);
368 if (multi_install_ && add_modifier) {
pennymac84fd6692016-07-13 22:35:34369 EXPECT_STREQ(L"beta-m", channel.c_str());
ananta69086d72016-05-12 23:29:04370 } else {
pennymac84fd6692016-07-13 22:35:34371 EXPECT_STREQ(install_static::kChromeChannelBeta, channel.c_str());
ananta69086d72016-05-12 23:29:04372 }
373
374 SetChannelName(L"foo-1.1-beta");
375 install_static::GetChromeChannelName(!system_level_, add_modifier,
376 &channel);
377 if (multi_install_ && add_modifier) {
pennymac84fd6692016-07-13 22:35:34378 EXPECT_STREQ(L"-m", channel.c_str());
ananta69086d72016-05-12 23:29:04379 } else {
pennymac84fd6692016-07-13 22:35:34380 EXPECT_STREQ(install_static::kChromeChannelStable, channel.c_str());
ananta69086d72016-05-12 23:29:04381 }
382 SetChannelName(L"2.0-beta");
383 install_static::GetChromeChannelName(!system_level_, add_modifier,
384 &channel);
385 if (multi_install_ && add_modifier) {
pennymac84fd6692016-07-13 22:35:34386 EXPECT_STREQ(L"-m", channel.c_str());
ananta69086d72016-05-12 23:29:04387 } else {
pennymac84fd6692016-07-13 22:35:34388 EXPECT_STREQ(install_static::kChromeChannelStable, channel.c_str());
ananta69086d72016-05-12 23:29:04389 }
390
391 SetChannelName(L"2.0-dev");
392 install_static::GetChromeChannelName(!system_level_, add_modifier,
393 &channel);
394 if (multi_install_ && add_modifier) {
pennymac84fd6692016-07-13 22:35:34395 EXPECT_STREQ(L"dev-m", channel.c_str());
ananta69086d72016-05-12 23:29:04396 } else {
pennymac84fd6692016-07-13 22:35:34397 EXPECT_STREQ(install_static::kChromeChannelDev, channel.c_str());
ananta69086d72016-05-12 23:29:04398 }
399 SetChannelName(L"2.0-DEV");
400 install_static::GetChromeChannelName(!system_level_, add_modifier,
401 &channel);
402 if (multi_install_ && add_modifier) {
pennymac84fd6692016-07-13 22:35:34403 EXPECT_STREQ(L"dev-m", channel.c_str());
ananta69086d72016-05-12 23:29:04404 } else {
pennymac84fd6692016-07-13 22:35:34405 EXPECT_STREQ(install_static::kChromeChannelDev, channel.c_str());
ananta69086d72016-05-12 23:29:04406 }
407 SetChannelName(L"2.0-dev-eloper");
408 install_static::GetChromeChannelName(!system_level_, add_modifier,
409 &channel);
410 if (multi_install_ && add_modifier) {
pennymac84fd6692016-07-13 22:35:34411 EXPECT_STREQ(L"dev-m", channel.c_str());
ananta69086d72016-05-12 23:29:04412 } else {
pennymac84fd6692016-07-13 22:35:34413 EXPECT_STREQ(install_static::kChromeChannelDev, channel.c_str());
ananta69086d72016-05-12 23:29:04414 }
415 SetChannelName(L"2.0-doom");
416 install_static::GetChromeChannelName(!system_level_, add_modifier,
417 &channel);
418 if (multi_install_ && add_modifier) {
pennymac84fd6692016-07-13 22:35:34419 EXPECT_STREQ(L"dev-m", channel.c_str());
ananta69086d72016-05-12 23:29:04420 } else {
pennymac84fd6692016-07-13 22:35:34421 EXPECT_STREQ(install_static::kChromeChannelDev, channel.c_str());
ananta69086d72016-05-12 23:29:04422 }
423 SetChannelName(L"250-doom");
424 install_static::GetChromeChannelName(!system_level_, add_modifier,
425 &channel);
426 if (multi_install_ && add_modifier) {
pennymac84fd6692016-07-13 22:35:34427 EXPECT_STREQ(L"dev-m", channel.c_str());
ananta69086d72016-05-12 23:29:04428 } else {
pennymac84fd6692016-07-13 22:35:34429 EXPECT_STREQ(install_static::kChromeChannelDev, channel.c_str());
ananta69086d72016-05-12 23:29:04430 }
431 SetChannelName(L"bar-2.0-dev");
432 install_static::GetChromeChannelName(!system_level_, add_modifier,
433 &channel);
434 if (multi_install_ && add_modifier) {
pennymac84fd6692016-07-13 22:35:34435 EXPECT_STREQ(L"-m", channel.c_str());
ananta69086d72016-05-12 23:29:04436 } else {
pennymac84fd6692016-07-13 22:35:34437 EXPECT_STREQ(install_static::kChromeChannelStable, channel.c_str());
ananta69086d72016-05-12 23:29:04438 }
439 SetChannelName(L"1.0-dev");
440 install_static::GetChromeChannelName(!system_level_, add_modifier,
441 &channel);
442 if (multi_install_ && add_modifier) {
pennymac84fd6692016-07-13 22:35:34443 EXPECT_STREQ(L"-m", channel.c_str());
ananta69086d72016-05-12 23:29:04444 } else {
pennymac84fd6692016-07-13 22:35:34445 EXPECT_STREQ(install_static::kChromeChannelStable, channel.c_str());
ananta69086d72016-05-12 23:29:04446 }
447
448 SetChannelName(L"x64-beta");
449 install_static::GetChromeChannelName(!system_level_, add_modifier,
450 &channel);
451 if (multi_install_ && add_modifier) {
pennymac84fd6692016-07-13 22:35:34452 EXPECT_STREQ(L"beta-m", channel.c_str());
ananta69086d72016-05-12 23:29:04453 } else {
pennymac84fd6692016-07-13 22:35:34454 EXPECT_STREQ(install_static::kChromeChannelBeta, channel.c_str());
ananta69086d72016-05-12 23:29:04455 }
456 SetChannelName(L"bar-x64-beta");
457 install_static::GetChromeChannelName(!system_level_, add_modifier,
458 &channel);
459 if (multi_install_ && add_modifier) {
pennymac84fd6692016-07-13 22:35:34460 EXPECT_STREQ(L"beta-m", channel.c_str());
ananta69086d72016-05-12 23:29:04461 } else {
pennymac84fd6692016-07-13 22:35:34462 EXPECT_STREQ(install_static::kChromeChannelBeta, channel.c_str());
ananta69086d72016-05-12 23:29:04463 }
464 SetChannelName(L"x64-Beta");
465 install_static::GetChromeChannelName(!system_level_, add_modifier,
466 &channel);
467 if (multi_install_ && add_modifier) {
pennymac84fd6692016-07-13 22:35:34468 EXPECT_STREQ(L"beta-m", channel.c_str());
ananta69086d72016-05-12 23:29:04469 } else {
pennymac84fd6692016-07-13 22:35:34470 EXPECT_STREQ(install_static::kChromeChannelBeta, channel.c_str());
ananta69086d72016-05-12 23:29:04471 }
472
473 SetChannelName(L"x64-stable");
474 install_static::GetChromeChannelName(!system_level_, add_modifier,
475 &channel);
476 if (multi_install_ && add_modifier) {
pennymac84fd6692016-07-13 22:35:34477 EXPECT_STREQ(L"-m", channel.c_str());
ananta69086d72016-05-12 23:29:04478 } else {
pennymac84fd6692016-07-13 22:35:34479 EXPECT_STREQ(install_static::kChromeChannelStable, channel.c_str());
ananta69086d72016-05-12 23:29:04480 }
481 SetChannelName(L"baz-x64-stable");
482 install_static::GetChromeChannelName(!system_level_, add_modifier,
483 &channel);
484 if (multi_install_ && add_modifier) {
pennymac84fd6692016-07-13 22:35:34485 EXPECT_STREQ(L"-m", channel.c_str());
ananta69086d72016-05-12 23:29:04486 } else {
pennymac84fd6692016-07-13 22:35:34487 EXPECT_STREQ(install_static::kChromeChannelStable, channel.c_str());
ananta69086d72016-05-12 23:29:04488 }
489 SetChannelName(L"x64-Stable");
490 install_static::GetChromeChannelName(!system_level_, add_modifier,
491 &channel);
492 if (multi_install_ && add_modifier) {
pennymac84fd6692016-07-13 22:35:34493 EXPECT_STREQ(L"-m", channel.c_str());
ananta69086d72016-05-12 23:29:04494 } else {
pennymac84fd6692016-07-13 22:35:34495 EXPECT_STREQ(install_static::kChromeChannelStable, channel.c_str());
ananta69086d72016-05-12 23:29:04496 }
497
498 SetChannelName(L"fuzzy");
499 install_static::GetChromeChannelName(!system_level_, add_modifier,
500 &channel);
501 if (multi_install_ && add_modifier) {
pennymac84fd6692016-07-13 22:35:34502 EXPECT_STREQ(L"-m", channel.c_str());
ananta69086d72016-05-12 23:29:04503 } else {
pennymac84fd6692016-07-13 22:35:34504 EXPECT_STREQ(install_static::kChromeChannelStable, channel.c_str());
ananta69086d72016-05-12 23:29:04505 }
506 SetChannelName(L"foo");
507 install_static::GetChromeChannelName(!system_level_, add_modifier,
508 &channel);
509 if (multi_install_ && add_modifier) {
pennymac84fd6692016-07-13 22:35:34510 EXPECT_STREQ(L"-m", channel.c_str());
ananta69086d72016-05-12 23:29:04511 } else {
pennymac84fd6692016-07-13 22:35:34512 EXPECT_STREQ(install_static::kChromeChannelStable, channel.c_str());
ananta69086d72016-05-12 23:29:04513 }
514 }
515
[email protected]5a542072014-02-24 02:12:09516 const wchar_t* app_guid_;
517 const wchar_t* chrome_path_;
518 bool system_level_;
519 bool multi_install_;
520 bool is_canary_;
521 registry_util::RegistryOverrideManager override_manager_;
522};
523
524TEST_P(ChromeElfUtilTest, MultiInstallTest) {
525 if (is_canary_)
526 return;
527 SetMultiInstallStateInRegistry(system_level_, true);
528 EXPECT_TRUE(IsMultiInstall(system_level_));
529
530 SetMultiInstallStateInRegistry(system_level_, false);
531 EXPECT_FALSE(IsMultiInstall(system_level_));
532}
533
534TEST_P(ChromeElfUtilTest, UsageStatsAbsent) {
ananta69086d72016-05-12 23:29:04535 EXPECT_FALSE(GetCollectStatsConsentForTesting(chrome_path_));
[email protected]5a542072014-02-24 02:12:09536}
537
538TEST_P(ChromeElfUtilTest, UsageStatsZero) {
539 SetUsageStat(0, false);
ananta69086d72016-05-12 23:29:04540 EXPECT_FALSE(GetCollectStatsConsentForTesting(chrome_path_));
[email protected]5a542072014-02-24 02:12:09541}
542
543TEST_P(ChromeElfUtilTest, UsageStatsOne) {
544 SetUsageStat(1, false);
ananta69086d72016-05-12 23:29:04545 EXPECT_TRUE(GetCollectStatsConsentForTesting(chrome_path_));
[email protected]5a542072014-02-24 02:12:09546 if (is_canary_) {
ananta69086d72016-05-12 23:29:04547 EXPECT_FALSE(GetCollectStatsConsentForTesting(kChromeUserExePath));
548 EXPECT_FALSE(GetCollectStatsConsentForTesting(kChromeSystemExePath));
[email protected]5a542072014-02-24 02:12:09549 } else if (system_level_) {
ananta69086d72016-05-12 23:29:04550 EXPECT_FALSE(GetCollectStatsConsentForTesting(kCanaryExePath));
551 EXPECT_FALSE(GetCollectStatsConsentForTesting(kChromeUserExePath));
[email protected]5a542072014-02-24 02:12:09552 } else {
ananta69086d72016-05-12 23:29:04553 EXPECT_FALSE(GetCollectStatsConsentForTesting(kCanaryExePath));
554 EXPECT_FALSE(GetCollectStatsConsentForTesting(kChromeSystemExePath));
[email protected]5a542072014-02-24 02:12:09555 }
556}
557
558TEST_P(ChromeElfUtilTest, UsageStatsZeroInStateMedium) {
559 if (!system_level_)
560 return;
561 SetUsageStat(0, true);
ananta69086d72016-05-12 23:29:04562 EXPECT_FALSE(GetCollectStatsConsentForTesting(chrome_path_));
[email protected]5a542072014-02-24 02:12:09563}
564
565TEST_P(ChromeElfUtilTest, UsageStatsOneInStateMedium) {
566 if (!system_level_)
567 return;
568 SetUsageStat(1, true);
ananta69086d72016-05-12 23:29:04569 EXPECT_TRUE(GetCollectStatsConsentForTesting(chrome_path_));
570 EXPECT_FALSE(GetCollectStatsConsentForTesting(kCanaryExePath));
571 EXPECT_FALSE(GetCollectStatsConsentForTesting(kChromeUserExePath));
572}
573
574// TODO(ananta)
575// Move this to install_static_unittests.
576// http://crbug.com/604923
577// This test tests the install_static::GetChromeChannelName function and is
578// based on the ChannelInfoTest.Channels in channel_info_unittest.cc
579TEST_P(ChromeElfUtilTest, InstallStaticGetChannelNameTest) {
pennymac84fd6692016-07-13 22:35:34580 PerformChannelNameTests(true); // add_modifier
581 PerformChannelNameTests(false); // !add_modifier
[email protected]5a542072014-02-24 02:12:09582}
583
pennymac84fd6692016-07-13 22:35:34584INSTANTIATE_TEST_CASE_P(Canary,
585 ChromeElfUtilTest,
[email protected]5a542072014-02-24 02:12:09586 testing::Combine(testing::Values("canary"),
587 testing::Values("user"),
588 testing::Values("single")));
pennymac84fd6692016-07-13 22:35:34589INSTANTIATE_TEST_CASE_P(GoogleChrome,
590 ChromeElfUtilTest,
[email protected]5a542072014-02-24 02:12:09591 testing::Combine(testing::Values("google"),
592 testing::Values("user", "system"),
593 testing::Values("single", "multi")));
594
[email protected]5a542072014-02-24 02:12:09595} // namespace