blob: dc4f1e13c2d7c91b299c397a226c71ea0d128ec2 [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"
13#include "chrome_elf/nt_registry/nt_registry.h"
[email protected]5a542072014-02-24 02:12:0914#include "testing/gtest/include/gtest/gtest.h"
15#include "testing/platform_test.h"
16
ananta69086d72016-05-12 23:29:0417using namespace install_static;
18
[email protected]5a542072014-02-24 02:12:0919namespace {
20
[email protected]5a542072014-02-24 02:12:0921const wchar_t kCanaryExePath[] =
22 L"C:\\Users\\user\\AppData\\Local\\Google\\Chrome SxS\\Application"
23 L"\\chrome.exe";
24const wchar_t kChromeSystemExePath[] =
25 L"C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe";
26const wchar_t kChromeUserExePath[] =
27 L"C:\\Users\\user\\AppData\\Local\\Google\\Chrome\\Application\\chrome.exe";
28const wchar_t kChromiumExePath[] =
29 L"C:\\Users\\user\\AppData\\Local\\Chromium\\Application\\chrome.exe";
30
[email protected]5a542072014-02-24 02:12:0931TEST(ChromeElfUtilTest, CanaryTest) {
ananta69086d72016-05-12 23:29:0432 EXPECT_TRUE(IsSxSChrome(kCanaryExePath));
33 EXPECT_FALSE(IsSxSChrome(kChromeUserExePath));
34 EXPECT_FALSE(IsSxSChrome(kChromiumExePath));
[email protected]5a542072014-02-24 02:12:0935}
36
37TEST(ChromeElfUtilTest, SystemInstallTest) {
38 EXPECT_TRUE(IsSystemInstall(kChromeSystemExePath));
39 EXPECT_FALSE(IsSystemInstall(kChromeUserExePath));
40}
41
caitkpc393a5b2015-05-14 19:56:3342TEST(ChromeElfUtilTest, BrowserProcessTest) {
43 EXPECT_EQ(ProcessType::UNINITIALIZED, g_process_type);
44 InitializeProcessType();
45 EXPECT_FALSE(IsNonBrowserProcess());
46}
47
pennymac84fd6692016-07-13 22:35:3448//------------------------------------------------------------------------------
49// NT registry API tests (chrome_elf_reg)
50//------------------------------------------------------------------------------
51
52TEST(ChromeElfUtilTest, NTRegistry) {
53 HANDLE key_handle;
54 const wchar_t* dword_val_name = L"DwordTestValue";
55 DWORD dword_val = 1234;
56 const wchar_t* sz_val_name = L"SzTestValue";
57 base::string16 sz_val = L"blah de blah de blahhhhh.";
58 const wchar_t* sz_val_name2 = L"SzTestValueEmpty";
59 base::string16 sz_val2 = L"";
60 const wchar_t* multisz_val_name = L"SzmultiTestValue";
61 std::vector<base::string16> multisz_val;
62 base::string16 multi1 = L"one";
63 base::string16 multi2 = L"two";
64 base::string16 multi3 = L"three";
65 const wchar_t* multisz_val_name2 = L"SzmultiTestValueBad";
66 base::string16 multi_empty = L"";
67 const wchar_t* sz_new_key_1 = L"test\\new\\subkey";
68 const wchar_t* sz_new_key_2 = L"test\\new\\subkey\\blah\\";
69 const wchar_t* sz_new_key_3 = L"\\test\\new\\subkey\\\\blah2";
70
71 // Set up registry override for this test.
72 base::string16 temp;
73 registry_util::RegistryOverrideManager override_manager;
74 override_manager.OverrideRegistry(HKEY_CURRENT_USER, &temp);
75 ::wcsncpy(nt::HKCU_override, temp.c_str(), nt::g_kRegMaxPathLen - 1);
76
77 // Create a temp key to play under.
78 ASSERT_TRUE(nt::CreateRegKey(nt::HKCU, elf_sec::kRegSecurityPath,
79 KEY_ALL_ACCESS, &key_handle));
80
81 // Exercise the supported getter & setter functions.
82 EXPECT_TRUE(nt::SetRegValueDWORD(key_handle, dword_val_name, dword_val));
83 EXPECT_TRUE(nt::SetRegValueSZ(key_handle, sz_val_name, sz_val));
84 EXPECT_TRUE(nt::SetRegValueSZ(key_handle, sz_val_name2, sz_val2));
85
86 DWORD get_dword = 0;
87 base::string16 get_sz;
88 EXPECT_TRUE(nt::QueryRegValueDWORD(key_handle, dword_val_name, &get_dword) &&
89 get_dword == dword_val);
90 EXPECT_TRUE(nt::QueryRegValueSZ(key_handle, sz_val_name, &get_sz) &&
91 get_sz.compare(sz_val) == 0);
92 EXPECT_TRUE(nt::QueryRegValueSZ(key_handle, sz_val_name2, &get_sz) &&
93 get_sz.compare(sz_val2) == 0);
94
95 multisz_val.push_back(multi1);
96 multisz_val.push_back(multi2);
97 multisz_val.push_back(multi3);
98 EXPECT_TRUE(
99 nt::SetRegValueMULTISZ(key_handle, multisz_val_name, multisz_val));
100 multisz_val.clear();
101 multisz_val.push_back(multi_empty);
102 EXPECT_TRUE(
103 nt::SetRegValueMULTISZ(key_handle, multisz_val_name2, multisz_val));
104 multisz_val.clear();
105
106 EXPECT_TRUE(
107 nt::QueryRegValueMULTISZ(key_handle, multisz_val_name, &multisz_val));
108 if (multisz_val.size() == 3) {
109 EXPECT_TRUE(multi1.compare(multisz_val.at(0)) == 0);
110 EXPECT_TRUE(multi2.compare(multisz_val.at(1)) == 0);
111 EXPECT_TRUE(multi3.compare(multisz_val.at(2)) == 0);
112 } else {
113 EXPECT_TRUE(false);
114 }
115 multisz_val.clear();
116
117 EXPECT_TRUE(
118 nt::QueryRegValueMULTISZ(key_handle, multisz_val_name2, &multisz_val));
119 if (multisz_val.size() == 1) {
120 EXPECT_TRUE(multi_empty.compare(multisz_val.at(0)) == 0);
121 } else {
122 EXPECT_TRUE(false);
123 }
124 multisz_val.clear();
125
126 // Clean up
127 EXPECT_TRUE(nt::DeleteRegKey(key_handle));
128 nt::CloseRegKey(key_handle);
129
130 // More tests for CreateRegKey recursion.
131 ASSERT_TRUE(
132 nt::CreateRegKey(nt::HKCU, sz_new_key_1, KEY_ALL_ACCESS, nullptr));
133 EXPECT_TRUE(nt::OpenRegKey(nt::HKCU, sz_new_key_1, KEY_ALL_ACCESS,
134 &key_handle, nullptr));
135 EXPECT_TRUE(nt::DeleteRegKey(key_handle));
136 nt::CloseRegKey(key_handle);
137
138 ASSERT_TRUE(
139 nt::CreateRegKey(nt::HKCU, sz_new_key_2, KEY_ALL_ACCESS, nullptr));
140 EXPECT_TRUE(nt::OpenRegKey(nt::HKCU, sz_new_key_2, KEY_ALL_ACCESS,
141 &key_handle, nullptr));
142 EXPECT_TRUE(nt::DeleteRegKey(key_handle));
143 nt::CloseRegKey(key_handle);
144
145 ASSERT_TRUE(
146 nt::CreateRegKey(nt::HKCU, sz_new_key_3, KEY_ALL_ACCESS, nullptr));
147 EXPECT_TRUE(nt::OpenRegKey(nt::HKCU, L"test\\new\\subkey\\blah2",
148 KEY_ALL_ACCESS, &key_handle, nullptr));
149 EXPECT_TRUE(nt::DeleteRegKey(key_handle));
150 nt::CloseRegKey(key_handle);
151
152 ASSERT_TRUE(nt::CreateRegKey(nt::HKCU, nullptr, KEY_ALL_ACCESS, &key_handle));
153 nt::CloseRegKey(key_handle);
154}
155
[email protected]5a542072014-02-24 02:12:09156// Parameterized test with paramters:
157// 1: product: "canary" or "google"
158// 2: install level: "user" or "system"
159// 3: install mode: "single" or "multi"
pennymac84fd6692016-07-13 22:35:34160class ChromeElfUtilTest
161 : public testing::TestWithParam<
162 std::tuple<const char*, const char*, const char*>> {
[email protected]5a542072014-02-24 02:12:09163 protected:
nick5c1d0602015-04-23 04:43:32164 void SetUp() override {
pennymac84fd6692016-07-13 22:35:34165 base::string16 temp;
166 override_manager_.OverrideRegistry(HKEY_LOCAL_MACHINE, &temp);
167 ::wcsncpy(nt::HKLM_override, temp.c_str(), nt::g_kRegMaxPathLen - 1);
168 temp.clear();
169 override_manager_.OverrideRegistry(HKEY_CURRENT_USER, &temp);
170 ::wcsncpy(nt::HKCU_override, temp.c_str(), nt::g_kRegMaxPathLen - 1);
171
[email protected]5a542072014-02-24 02:12:09172 const char* app;
173 const char* level;
174 const char* mode;
175 std::tie(app, level, mode) = GetParam();
176 is_canary_ = (std::string(app) == "canary");
177 system_level_ = (std::string(level) != "user");
178 multi_install_ = (std::string(mode) != "single");
179 if (is_canary_) {
180 ASSERT_FALSE(system_level_);
181 ASSERT_FALSE(multi_install_);
182 app_guid_ = kAppGuidCanary;
183 chrome_path_ = kCanaryExePath;
184 } else {
185 app_guid_ = kAppGuidGoogleChrome;
pennymac84fd6692016-07-13 22:35:34186 chrome_path_ =
187 (system_level_ ? kChromeSystemExePath : kChromeUserExePath);
[email protected]5a542072014-02-24 02:12:09188 }
189 if (multi_install_) {
190 SetMultiInstallStateInRegistry(system_level_, true);
191 app_guid_ = kAppGuidGoogleBinaries;
192 }
193 }
194
195 base::string16 BuildKey(const wchar_t* path, const wchar_t* guid) {
196 base::string16 full_key_path(path);
197 full_key_path.append(1, L'\\');
198 full_key_path.append(guid);
199 return full_key_path;
200 }
201
202 void SetUsageStat(DWORD value, bool state_medium) {
203 LONG result = base::win::RegKey(
pennymac84fd6692016-07-13 22:35:34204 system_level_ ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER,
205 BuildKey(state_medium ? kRegPathClientStateMedium
206 : kRegPathClientState,
207 app_guid_)
208 .c_str(),
209 KEY_SET_VALUE)
210 .WriteValue(kRegValueUsageStats, value);
[email protected]5a542072014-02-24 02:12:09211 ASSERT_EQ(ERROR_SUCCESS, result);
212 }
213
214 void SetMultiInstallStateInRegistry(bool system_install, bool multi) {
215 base::win::RegKey key(
216 system_install ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER,
217 BuildKey(kRegPathClientState, kAppGuidGoogleChrome).c_str(),
218 KEY_SET_VALUE);
219 LONG result;
220 if (multi) {
221 result = key.WriteValue(kUninstallArgumentsField,
222 L"yadda yadda --multi-install yadda yadda");
223 } else {
224 result = key.DeleteValue(kUninstallArgumentsField);
225 }
226 ASSERT_EQ(ERROR_SUCCESS, result);
227 }
228
ananta69086d72016-05-12 23:29:04229 void SetChannelName(const base::string16& channel_name) {
pennymac84fd6692016-07-13 22:35:34230 LONG result =
231 base::win::RegKey(
232 system_level_ ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER,
233 BuildKey(kRegPathClientState, app_guid_).c_str(), KEY_SET_VALUE)
234 .WriteValue(kRegApField, channel_name.c_str());
ananta69086d72016-05-12 23:29:04235 ASSERT_EQ(ERROR_SUCCESS, result);
236 }
237
238 // This function tests the install_static::GetChromeChannelName function and
239 // is based on the ChannelInfoTest.Channels in channel_info_unittest.cc.
240 // The |add_modifier| parameter controls whether we expect modifiers in the
241 // returned channel name.
242 void PerformChannelNameTests(bool add_modifier) {
243 // We can't test the channel name correctly for canary mode because the
244 // install_static checks whether an exe is a canary executable is based on
245 // the path where the exe is running from.
246 if (is_canary_)
247 return;
248 SetChannelName(L"");
249 base::string16 channel;
250 install_static::GetChromeChannelName(!system_level_, add_modifier,
251 &channel);
252 if (multi_install_ && add_modifier) {
pennymac84fd6692016-07-13 22:35:34253 EXPECT_STREQ(L"-m", channel.c_str());
ananta69086d72016-05-12 23:29:04254 } else {
pennymac84fd6692016-07-13 22:35:34255 EXPECT_STREQ(install_static::kChromeChannelStable, channel.c_str());
ananta69086d72016-05-12 23:29:04256 }
257
258 SetChannelName(L"-full");
259 install_static::GetChromeChannelName(!system_level_, add_modifier,
260 &channel);
261 if (multi_install_ && add_modifier) {
pennymac84fd6692016-07-13 22:35:34262 EXPECT_STREQ(L"-m", channel.c_str());
ananta69086d72016-05-12 23:29:04263 } else {
pennymac84fd6692016-07-13 22:35:34264 EXPECT_STREQ(install_static::kChromeChannelStable, channel.c_str());
ananta69086d72016-05-12 23:29:04265 }
266
267 SetChannelName(L"1.1-beta");
268 install_static::GetChromeChannelName(!system_level_, add_modifier,
269 &channel);
270 if (multi_install_ && add_modifier) {
pennymac84fd6692016-07-13 22:35:34271 EXPECT_STREQ(L"beta-m", channel.c_str());
ananta69086d72016-05-12 23:29:04272 } else {
pennymac84fd6692016-07-13 22:35:34273 EXPECT_STREQ(install_static::kChromeChannelBeta, channel.c_str());
ananta69086d72016-05-12 23:29:04274 }
275
276 SetChannelName(L"1.1-beta");
277 install_static::GetChromeChannelName(!system_level_, add_modifier,
278 &channel);
279 if (multi_install_ && add_modifier) {
pennymac84fd6692016-07-13 22:35:34280 EXPECT_STREQ(L"beta-m", channel.c_str());
ananta69086d72016-05-12 23:29:04281 } else {
pennymac84fd6692016-07-13 22:35:34282 EXPECT_STREQ(install_static::kChromeChannelBeta, channel.c_str());
ananta69086d72016-05-12 23:29:04283 }
284
285 SetChannelName(L"1.1-bar");
286 install_static::GetChromeChannelName(!system_level_, add_modifier,
287 &channel);
288 if (multi_install_ && add_modifier) {
pennymac84fd6692016-07-13 22:35:34289 EXPECT_STREQ(L"beta-m", channel.c_str());
ananta69086d72016-05-12 23:29:04290 } else {
pennymac84fd6692016-07-13 22:35:34291 EXPECT_STREQ(install_static::kChromeChannelBeta, channel.c_str());
ananta69086d72016-05-12 23:29:04292 }
293
294 SetChannelName(L"1n1-foobar");
295 install_static::GetChromeChannelName(!system_level_, add_modifier,
296 &channel);
297 if (multi_install_ && add_modifier) {
pennymac84fd6692016-07-13 22:35:34298 EXPECT_STREQ(L"beta-m", channel.c_str());
ananta69086d72016-05-12 23:29:04299 } else {
pennymac84fd6692016-07-13 22:35:34300 EXPECT_STREQ(install_static::kChromeChannelBeta, channel.c_str());
ananta69086d72016-05-12 23:29:04301 }
302
303 SetChannelName(L"foo-1.1-beta");
304 install_static::GetChromeChannelName(!system_level_, add_modifier,
305 &channel);
306 if (multi_install_ && add_modifier) {
pennymac84fd6692016-07-13 22:35:34307 EXPECT_STREQ(L"-m", channel.c_str());
ananta69086d72016-05-12 23:29:04308 } else {
pennymac84fd6692016-07-13 22:35:34309 EXPECT_STREQ(install_static::kChromeChannelStable, channel.c_str());
ananta69086d72016-05-12 23:29:04310 }
311 SetChannelName(L"2.0-beta");
312 install_static::GetChromeChannelName(!system_level_, add_modifier,
313 &channel);
314 if (multi_install_ && add_modifier) {
pennymac84fd6692016-07-13 22:35:34315 EXPECT_STREQ(L"-m", channel.c_str());
ananta69086d72016-05-12 23:29:04316 } else {
pennymac84fd6692016-07-13 22:35:34317 EXPECT_STREQ(install_static::kChromeChannelStable, channel.c_str());
ananta69086d72016-05-12 23:29:04318 }
319
320 SetChannelName(L"2.0-dev");
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"dev-m", channel.c_str());
ananta69086d72016-05-12 23:29:04325 } else {
pennymac84fd6692016-07-13 22:35:34326 EXPECT_STREQ(install_static::kChromeChannelDev, channel.c_str());
ananta69086d72016-05-12 23:29:04327 }
328 SetChannelName(L"2.0-DEV");
329 install_static::GetChromeChannelName(!system_level_, add_modifier,
330 &channel);
331 if (multi_install_ && add_modifier) {
pennymac84fd6692016-07-13 22:35:34332 EXPECT_STREQ(L"dev-m", channel.c_str());
ananta69086d72016-05-12 23:29:04333 } else {
pennymac84fd6692016-07-13 22:35:34334 EXPECT_STREQ(install_static::kChromeChannelDev, channel.c_str());
ananta69086d72016-05-12 23:29:04335 }
336 SetChannelName(L"2.0-dev-eloper");
337 install_static::GetChromeChannelName(!system_level_, add_modifier,
338 &channel);
339 if (multi_install_ && add_modifier) {
pennymac84fd6692016-07-13 22:35:34340 EXPECT_STREQ(L"dev-m", channel.c_str());
ananta69086d72016-05-12 23:29:04341 } else {
pennymac84fd6692016-07-13 22:35:34342 EXPECT_STREQ(install_static::kChromeChannelDev, channel.c_str());
ananta69086d72016-05-12 23:29:04343 }
344 SetChannelName(L"2.0-doom");
345 install_static::GetChromeChannelName(!system_level_, add_modifier,
346 &channel);
347 if (multi_install_ && add_modifier) {
pennymac84fd6692016-07-13 22:35:34348 EXPECT_STREQ(L"dev-m", channel.c_str());
ananta69086d72016-05-12 23:29:04349 } else {
pennymac84fd6692016-07-13 22:35:34350 EXPECT_STREQ(install_static::kChromeChannelDev, channel.c_str());
ananta69086d72016-05-12 23:29:04351 }
352 SetChannelName(L"250-doom");
353 install_static::GetChromeChannelName(!system_level_, add_modifier,
354 &channel);
355 if (multi_install_ && add_modifier) {
pennymac84fd6692016-07-13 22:35:34356 EXPECT_STREQ(L"dev-m", channel.c_str());
ananta69086d72016-05-12 23:29:04357 } else {
pennymac84fd6692016-07-13 22:35:34358 EXPECT_STREQ(install_static::kChromeChannelDev, channel.c_str());
ananta69086d72016-05-12 23:29:04359 }
360 SetChannelName(L"bar-2.0-dev");
361 install_static::GetChromeChannelName(!system_level_, add_modifier,
362 &channel);
363 if (multi_install_ && add_modifier) {
pennymac84fd6692016-07-13 22:35:34364 EXPECT_STREQ(L"-m", channel.c_str());
ananta69086d72016-05-12 23:29:04365 } else {
pennymac84fd6692016-07-13 22:35:34366 EXPECT_STREQ(install_static::kChromeChannelStable, channel.c_str());
ananta69086d72016-05-12 23:29:04367 }
368 SetChannelName(L"1.0-dev");
369 install_static::GetChromeChannelName(!system_level_, add_modifier,
370 &channel);
371 if (multi_install_ && add_modifier) {
pennymac84fd6692016-07-13 22:35:34372 EXPECT_STREQ(L"-m", channel.c_str());
ananta69086d72016-05-12 23:29:04373 } else {
pennymac84fd6692016-07-13 22:35:34374 EXPECT_STREQ(install_static::kChromeChannelStable, channel.c_str());
ananta69086d72016-05-12 23:29:04375 }
376
377 SetChannelName(L"x64-beta");
378 install_static::GetChromeChannelName(!system_level_, add_modifier,
379 &channel);
380 if (multi_install_ && add_modifier) {
pennymac84fd6692016-07-13 22:35:34381 EXPECT_STREQ(L"beta-m", channel.c_str());
ananta69086d72016-05-12 23:29:04382 } else {
pennymac84fd6692016-07-13 22:35:34383 EXPECT_STREQ(install_static::kChromeChannelBeta, channel.c_str());
ananta69086d72016-05-12 23:29:04384 }
385 SetChannelName(L"bar-x64-beta");
386 install_static::GetChromeChannelName(!system_level_, add_modifier,
387 &channel);
388 if (multi_install_ && add_modifier) {
pennymac84fd6692016-07-13 22:35:34389 EXPECT_STREQ(L"beta-m", channel.c_str());
ananta69086d72016-05-12 23:29:04390 } else {
pennymac84fd6692016-07-13 22:35:34391 EXPECT_STREQ(install_static::kChromeChannelBeta, channel.c_str());
ananta69086d72016-05-12 23:29:04392 }
393 SetChannelName(L"x64-Beta");
394 install_static::GetChromeChannelName(!system_level_, add_modifier,
395 &channel);
396 if (multi_install_ && add_modifier) {
pennymac84fd6692016-07-13 22:35:34397 EXPECT_STREQ(L"beta-m", channel.c_str());
ananta69086d72016-05-12 23:29:04398 } else {
pennymac84fd6692016-07-13 22:35:34399 EXPECT_STREQ(install_static::kChromeChannelBeta, channel.c_str());
ananta69086d72016-05-12 23:29:04400 }
401
402 SetChannelName(L"x64-stable");
403 install_static::GetChromeChannelName(!system_level_, add_modifier,
404 &channel);
405 if (multi_install_ && add_modifier) {
pennymac84fd6692016-07-13 22:35:34406 EXPECT_STREQ(L"-m", channel.c_str());
ananta69086d72016-05-12 23:29:04407 } else {
pennymac84fd6692016-07-13 22:35:34408 EXPECT_STREQ(install_static::kChromeChannelStable, channel.c_str());
ananta69086d72016-05-12 23:29:04409 }
410 SetChannelName(L"baz-x64-stable");
411 install_static::GetChromeChannelName(!system_level_, add_modifier,
412 &channel);
413 if (multi_install_ && add_modifier) {
pennymac84fd6692016-07-13 22:35:34414 EXPECT_STREQ(L"-m", channel.c_str());
ananta69086d72016-05-12 23:29:04415 } else {
pennymac84fd6692016-07-13 22:35:34416 EXPECT_STREQ(install_static::kChromeChannelStable, channel.c_str());
ananta69086d72016-05-12 23:29:04417 }
418 SetChannelName(L"x64-Stable");
419 install_static::GetChromeChannelName(!system_level_, add_modifier,
420 &channel);
421 if (multi_install_ && add_modifier) {
pennymac84fd6692016-07-13 22:35:34422 EXPECT_STREQ(L"-m", channel.c_str());
ananta69086d72016-05-12 23:29:04423 } else {
pennymac84fd6692016-07-13 22:35:34424 EXPECT_STREQ(install_static::kChromeChannelStable, channel.c_str());
ananta69086d72016-05-12 23:29:04425 }
426
427 SetChannelName(L"fuzzy");
428 install_static::GetChromeChannelName(!system_level_, add_modifier,
429 &channel);
430 if (multi_install_ && add_modifier) {
pennymac84fd6692016-07-13 22:35:34431 EXPECT_STREQ(L"-m", channel.c_str());
ananta69086d72016-05-12 23:29:04432 } else {
pennymac84fd6692016-07-13 22:35:34433 EXPECT_STREQ(install_static::kChromeChannelStable, channel.c_str());
ananta69086d72016-05-12 23:29:04434 }
435 SetChannelName(L"foo");
436 install_static::GetChromeChannelName(!system_level_, add_modifier,
437 &channel);
438 if (multi_install_ && add_modifier) {
pennymac84fd6692016-07-13 22:35:34439 EXPECT_STREQ(L"-m", channel.c_str());
ananta69086d72016-05-12 23:29:04440 } else {
pennymac84fd6692016-07-13 22:35:34441 EXPECT_STREQ(install_static::kChromeChannelStable, channel.c_str());
ananta69086d72016-05-12 23:29:04442 }
443 }
444
[email protected]5a542072014-02-24 02:12:09445 const wchar_t* app_guid_;
446 const wchar_t* chrome_path_;
447 bool system_level_;
448 bool multi_install_;
449 bool is_canary_;
450 registry_util::RegistryOverrideManager override_manager_;
451};
452
453TEST_P(ChromeElfUtilTest, MultiInstallTest) {
454 if (is_canary_)
455 return;
456 SetMultiInstallStateInRegistry(system_level_, true);
457 EXPECT_TRUE(IsMultiInstall(system_level_));
458
459 SetMultiInstallStateInRegistry(system_level_, false);
460 EXPECT_FALSE(IsMultiInstall(system_level_));
461}
462
463TEST_P(ChromeElfUtilTest, UsageStatsAbsent) {
ananta69086d72016-05-12 23:29:04464 EXPECT_FALSE(GetCollectStatsConsentForTesting(chrome_path_));
[email protected]5a542072014-02-24 02:12:09465}
466
467TEST_P(ChromeElfUtilTest, UsageStatsZero) {
468 SetUsageStat(0, false);
ananta69086d72016-05-12 23:29:04469 EXPECT_FALSE(GetCollectStatsConsentForTesting(chrome_path_));
[email protected]5a542072014-02-24 02:12:09470}
471
472TEST_P(ChromeElfUtilTest, UsageStatsOne) {
473 SetUsageStat(1, false);
ananta69086d72016-05-12 23:29:04474 EXPECT_TRUE(GetCollectStatsConsentForTesting(chrome_path_));
[email protected]5a542072014-02-24 02:12:09475 if (is_canary_) {
ananta69086d72016-05-12 23:29:04476 EXPECT_FALSE(GetCollectStatsConsentForTesting(kChromeUserExePath));
477 EXPECT_FALSE(GetCollectStatsConsentForTesting(kChromeSystemExePath));
[email protected]5a542072014-02-24 02:12:09478 } else if (system_level_) {
ananta69086d72016-05-12 23:29:04479 EXPECT_FALSE(GetCollectStatsConsentForTesting(kCanaryExePath));
480 EXPECT_FALSE(GetCollectStatsConsentForTesting(kChromeUserExePath));
[email protected]5a542072014-02-24 02:12:09481 } else {
ananta69086d72016-05-12 23:29:04482 EXPECT_FALSE(GetCollectStatsConsentForTesting(kCanaryExePath));
483 EXPECT_FALSE(GetCollectStatsConsentForTesting(kChromeSystemExePath));
[email protected]5a542072014-02-24 02:12:09484 }
485}
486
487TEST_P(ChromeElfUtilTest, UsageStatsZeroInStateMedium) {
488 if (!system_level_)
489 return;
490 SetUsageStat(0, true);
ananta69086d72016-05-12 23:29:04491 EXPECT_FALSE(GetCollectStatsConsentForTesting(chrome_path_));
[email protected]5a542072014-02-24 02:12:09492}
493
494TEST_P(ChromeElfUtilTest, UsageStatsOneInStateMedium) {
495 if (!system_level_)
496 return;
497 SetUsageStat(1, true);
ananta69086d72016-05-12 23:29:04498 EXPECT_TRUE(GetCollectStatsConsentForTesting(chrome_path_));
499 EXPECT_FALSE(GetCollectStatsConsentForTesting(kCanaryExePath));
500 EXPECT_FALSE(GetCollectStatsConsentForTesting(kChromeUserExePath));
501}
502
503// TODO(ananta)
504// Move this to install_static_unittests.
505// http://crbug.com/604923
506// This test tests the install_static::GetChromeChannelName function and is
507// based on the ChannelInfoTest.Channels in channel_info_unittest.cc
508TEST_P(ChromeElfUtilTest, InstallStaticGetChannelNameTest) {
pennymac84fd6692016-07-13 22:35:34509 PerformChannelNameTests(true); // add_modifier
510 PerformChannelNameTests(false); // !add_modifier
[email protected]5a542072014-02-24 02:12:09511}
512
pennymac84fd6692016-07-13 22:35:34513INSTANTIATE_TEST_CASE_P(Canary,
514 ChromeElfUtilTest,
[email protected]5a542072014-02-24 02:12:09515 testing::Combine(testing::Values("canary"),
516 testing::Values("user"),
517 testing::Values("single")));
pennymac84fd6692016-07-13 22:35:34518INSTANTIATE_TEST_CASE_P(GoogleChrome,
519 ChromeElfUtilTest,
[email protected]5a542072014-02-24 02:12:09520 testing::Combine(testing::Values("google"),
521 testing::Values("user", "system"),
522 testing::Values("single", "multi")));
523
[email protected]5a542072014-02-24 02:12:09524} // namespace