OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "chrome/install_static/install_util.h" | 5 #include "chrome/install_static/install_util.h" |
6 | 6 |
7 #include <tuple> | 7 #include <tuple> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 } | 260 } |
261 | 261 |
262 TEST(InstallStaticTest, BrowserProcessTest) { | 262 TEST(InstallStaticTest, BrowserProcessTest) { |
263 EXPECT_EQ(ProcessType::UNINITIALIZED, g_process_type); | 263 EXPECT_EQ(ProcessType::UNINITIALIZED, g_process_type); |
264 InitializeProcessType(); | 264 InitializeProcessType(); |
265 EXPECT_FALSE(IsNonBrowserProcess()); | 265 EXPECT_FALSE(IsNonBrowserProcess()); |
266 } | 266 } |
267 | 267 |
268 class InstallStaticUtilTest | 268 class InstallStaticUtilTest |
269 : public ::testing::TestWithParam< | 269 : public ::testing::TestWithParam< |
270 std::tuple<InstallConstantIndex, const char*, const char*>> { | 270 std::tuple<InstallConstantIndex, const char*>> { |
271 protected: | 271 protected: |
272 InstallStaticUtilTest() { | 272 InstallStaticUtilTest() { |
273 InstallConstantIndex mode_index; | 273 InstallConstantIndex mode_index; |
274 const char* level; | 274 const char* level; |
275 const char* mode; | |
276 | 275 |
277 std::tie(mode_index, level, mode) = GetParam(); | 276 std::tie(mode_index, level) = GetParam(); |
278 | 277 |
279 mode_ = &kInstallModes[mode_index]; | 278 mode_ = &kInstallModes[mode_index]; |
280 system_level_ = std::string(level) != "user"; | 279 system_level_ = std::string(level) != "user"; |
281 EXPECT_TRUE(!system_level_ || mode_->supports_system_level); | 280 EXPECT_TRUE(!system_level_ || mode_->supports_system_level); |
282 multi_install_ = std::string(mode) != "single"; | |
283 EXPECT_TRUE(!multi_install_ || mode_->supports_multi_install); | |
284 root_key_ = system_level_ ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; | 281 root_key_ = system_level_ ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; |
285 nt_root_key_ = system_level_ ? nt::HKLM : nt::HKCU; | 282 nt_root_key_ = system_level_ ? nt::HKLM : nt::HKCU; |
286 | 283 |
287 std::unique_ptr<PrimaryInstallDetails> details = | 284 std::unique_ptr<PrimaryInstallDetails> details = |
288 base::MakeUnique<PrimaryInstallDetails>(); | 285 base::MakeUnique<PrimaryInstallDetails>(); |
289 details->set_mode(mode_); | 286 details->set_mode(mode_); |
290 details->set_channel(mode_->default_channel_name); | 287 details->set_channel(mode_->default_channel_name); |
291 details->set_system_level(system_level_); | 288 details->set_system_level(system_level_); |
292 details->set_multi_install(multi_install_); | |
293 InstallDetails::SetForProcess(std::move(details)); | 289 InstallDetails::SetForProcess(std::move(details)); |
294 | 290 |
295 base::string16 path; | 291 base::string16 path; |
296 override_manager_.OverrideRegistry(root_key_, &path); | 292 override_manager_.OverrideRegistry(root_key_, &path); |
297 nt::SetTestingOverride(nt_root_key_, path); | 293 nt::SetTestingOverride(nt_root_key_, path); |
298 } | 294 } |
299 | 295 |
300 ~InstallStaticUtilTest() { | 296 ~InstallStaticUtilTest() { |
301 InstallDetails::SetForProcess(nullptr); | 297 InstallDetails::SetForProcess(nullptr); |
302 nt::SetTestingOverride(nt_root_key_, base::string16()); | 298 nt::SetTestingOverride(nt_root_key_, base::string16()); |
303 } | 299 } |
304 | 300 |
305 bool system_level() const { return system_level_; } | 301 bool system_level() const { return system_level_; } |
306 | 302 |
307 bool multi_install() const { return multi_install_; } | |
308 | |
309 const wchar_t* default_channel() const { return mode_->default_channel_name; } | 303 const wchar_t* default_channel() const { return mode_->default_channel_name; } |
310 | 304 |
311 void SetUsageStat(DWORD value, bool medium) { | 305 void SetUsageStat(DWORD value, bool medium) { |
312 ASSERT_TRUE(!medium || system_level_); | 306 ASSERT_TRUE(!medium || system_level_); |
313 ASSERT_EQ(ERROR_SUCCESS, | 307 ASSERT_EQ(ERROR_SUCCESS, |
314 base::win::RegKey(root_key_, GetUsageStatsKeyPath(medium).c_str(), | 308 base::win::RegKey(root_key_, GetUsageStatsKeyPath(medium).c_str(), |
315 KEY_SET_VALUE | KEY_WOW64_32KEY) | 309 KEY_SET_VALUE | KEY_WOW64_32KEY) |
316 .WriteValue(L"usagestats", value)); | 310 .WriteValue(L"usagestats", value)); |
317 } | 311 } |
318 | 312 |
(...skipping 15 matching lines...) Expand all Loading... |
334 // value. |medium| = true returns the path for ClientStateMedium. | 328 // value. |medium| = true returns the path for ClientStateMedium. |
335 std::wstring GetUsageStatsKeyPath(bool medium) { | 329 std::wstring GetUsageStatsKeyPath(bool medium) { |
336 EXPECT_TRUE(!medium || system_level_); | 330 EXPECT_TRUE(!medium || system_level_); |
337 | 331 |
338 std::wstring result(L"Software\\"); | 332 std::wstring result(L"Software\\"); |
339 if (kUseGoogleUpdateIntegration) { | 333 if (kUseGoogleUpdateIntegration) { |
340 result.append(L"Google\\Update\\ClientState"); | 334 result.append(L"Google\\Update\\ClientState"); |
341 if (medium) | 335 if (medium) |
342 result.append(L"Medium"); | 336 result.append(L"Medium"); |
343 result.push_back(L'\\'); | 337 result.push_back(L'\\'); |
344 if (multi_install_) | 338 result.append(mode_->app_guid); |
345 result.append(kBinariesAppGuid); | |
346 else | |
347 result.append(mode_->app_guid); | |
348 } else if (multi_install_) { | |
349 result.append(kBinariesPathName); | |
350 } else { | 339 } else { |
351 result.append(kProductPathName); | 340 result.append(kProductPathName); |
352 } | 341 } |
353 return result; | 342 return result; |
354 } | 343 } |
355 | 344 |
356 registry_util::RegistryOverrideManager override_manager_; | 345 registry_util::RegistryOverrideManager override_manager_; |
357 HKEY root_key_ = nullptr; | 346 HKEY root_key_ = nullptr; |
358 nt::ROOT_KEY nt_root_key_ = nt::AUTO; | 347 nt::ROOT_KEY nt_root_key_ = nt::AUTO; |
359 const InstallConstants* mode_ = nullptr; | 348 const InstallConstants* mode_ = nullptr; |
360 bool system_level_ = false; | 349 bool system_level_ = false; |
361 bool multi_install_ = false; | |
362 | 350 |
363 DISALLOW_COPY_AND_ASSIGN(InstallStaticUtilTest); | 351 DISALLOW_COPY_AND_ASSIGN(InstallStaticUtilTest); |
364 }; | 352 }; |
365 | 353 |
366 TEST_P(InstallStaticUtilTest, UsageStatsAbsent) { | 354 TEST_P(InstallStaticUtilTest, UsageStatsAbsent) { |
367 EXPECT_FALSE(GetCollectStatsConsent()); | 355 EXPECT_FALSE(GetCollectStatsConsent()); |
368 } | 356 } |
369 | 357 |
370 TEST_P(InstallStaticUtilTest, UsageStatsZero) { | 358 TEST_P(InstallStaticUtilTest, UsageStatsZero) { |
371 SetUsageStat(0, false); | 359 SetUsageStat(0, false); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
416 SetMetricsReportingPolicy(1); | 404 SetMetricsReportingPolicy(1); |
417 SetUsageStat(0, false); | 405 SetUsageStat(0, false); |
418 EXPECT_TRUE(GetCollectStatsConsent()); | 406 EXPECT_TRUE(GetCollectStatsConsent()); |
419 | 407 |
420 SetMetricsReportingPolicy(0); | 408 SetMetricsReportingPolicy(0); |
421 SetUsageStat(1, false); | 409 SetUsageStat(1, false); |
422 EXPECT_FALSE(GetCollectStatsConsent()); | 410 EXPECT_FALSE(GetCollectStatsConsent()); |
423 } | 411 } |
424 | 412 |
425 TEST_P(InstallStaticUtilTest, GetChromeChannelName) { | 413 TEST_P(InstallStaticUtilTest, GetChromeChannelName) { |
426 EXPECT_EQ(default_channel(), GetChromeChannelName(false)); | 414 EXPECT_EQ(default_channel(), GetChromeChannelName()); |
427 std::wstring expected = default_channel(); | |
428 if (multi_install()) { | |
429 if (expected.empty()) | |
430 expected = L"m"; | |
431 else | |
432 expected += L"-m"; | |
433 } | |
434 EXPECT_EQ(expected, GetChromeChannelName(true)); | |
435 } | 415 } |
436 | 416 |
437 #if defined(GOOGLE_CHROME_BUILD) | 417 #if defined(GOOGLE_CHROME_BUILD) |
438 // Stable supports multi-install at user and system levels. | 418 // Stable supports user and system levels. |
439 INSTANTIATE_TEST_CASE_P(Stable, | 419 INSTANTIATE_TEST_CASE_P(Stable, |
440 InstallStaticUtilTest, | 420 InstallStaticUtilTest, |
441 testing::Combine(testing::Values(STABLE_INDEX), | 421 testing::Combine(testing::Values(STABLE_INDEX), |
442 testing::Values("user", "system"), | 422 testing::Values("user", "system"))); |
443 testing::Values("single", "multi"))); | 423 // Canary is only at user level. |
444 // Canary is single-only at user level. | |
445 INSTANTIATE_TEST_CASE_P(Canary, | 424 INSTANTIATE_TEST_CASE_P(Canary, |
446 InstallStaticUtilTest, | 425 InstallStaticUtilTest, |
447 testing::Combine(testing::Values(CANARY_INDEX), | 426 testing::Combine(testing::Values(CANARY_INDEX), |
448 testing::Values("user"), | 427 testing::Values("user"))); |
449 testing::Values("single"))); | |
450 #else // GOOGLE_CHROME_BUILD | 428 #else // GOOGLE_CHROME_BUILD |
451 // Chromium supports multi-install at user and system levels. | 429 // Chromium supports user and system levels. |
452 INSTANTIATE_TEST_CASE_P(Chromium, | 430 INSTANTIATE_TEST_CASE_P(Chromium, |
453 InstallStaticUtilTest, | 431 InstallStaticUtilTest, |
454 testing::Combine(testing::Values(CHROMIUM_INDEX), | 432 testing::Combine(testing::Values(CHROMIUM_INDEX), |
455 testing::Values("user", "system"), | 433 testing::Values("user", "system"))); |
456 testing::Values("single", "multi"))); | |
457 #endif // !GOOGLE_CHROME_BUILD | 434 #endif // !GOOGLE_CHROME_BUILD |
458 | 435 |
459 } // namespace install_static | 436 } // namespace install_static |
OLD | NEW |