| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <windows.h> | 5 #include <windows.h> |
| 6 #include <shlwapi.h> // For SHDeleteKey. | 6 #include <shlwapi.h> // For SHDeleteKey. |
| 7 | 7 |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/test/test_reg_util_win.h" | 9 #include "base/test/test_reg_util_win.h" |
| 10 #include "base/win/registry.h" | 10 #include "base/win/registry.h" |
| 11 #include "chrome/common/chrome_constants.h" | 11 #include "chrome/common/chrome_constants.h" |
| 12 #include "chrome/installer/util/browser_distribution.h" | 12 #include "chrome/installer/util/browser_distribution.h" |
| 13 #include "chrome/installer/util/channel_info.h" | 13 #include "chrome/installer/util/channel_info.h" |
| 14 #include "chrome/installer/util/fake_installation_state.h" | 14 #include "chrome/installer/util/fake_installation_state.h" |
| 15 #include "chrome/installer/util/google_update_constants.h" | 15 #include "chrome/installer/util/google_update_constants.h" |
| 16 #include "chrome/installer/util/google_update_settings.h" | 16 #include "chrome/installer/util/google_update_settings.h" |
| 17 #include "chrome/installer/util/util_constants.h" | 17 #include "chrome/installer/util/util_constants.h" |
| 18 #include "chrome/installer/util/work_item_list.h" | 18 #include "chrome/installer/util/work_item_list.h" |
| 19 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
| 20 | 20 |
| 21 using base::win::RegKey; | 21 using base::win::RegKey; |
| 22 using installer::ChannelInfo; | 22 using installer::ChannelInfo; |
| 23 | 23 |
| 24 namespace { | 24 namespace { |
| 25 | 25 |
| 26 const wchar_t kHKCUReplacement[] = | |
| 27 L"Software\\Google\\InstallUtilUnittest\\HKCU"; | |
| 28 const wchar_t kHKLMReplacement[] = | |
| 29 L"Software\\Google\\InstallUtilUnittest\\HKLM"; | |
| 30 const wchar_t kGoogleUpdatePoliciesKey[] = | 26 const wchar_t kGoogleUpdatePoliciesKey[] = |
| 31 L"SOFTWARE\\Policies\\Google\\Update"; | 27 L"SOFTWARE\\Policies\\Google\\Update"; |
| 32 const wchar_t kGoogleUpdateUpdateDefault[] = L"UpdateDefault"; | 28 const wchar_t kGoogleUpdateUpdateDefault[] = L"UpdateDefault"; |
| 33 const wchar_t kGoogleUpdateUpdatePrefix[] = L"Update"; | 29 const wchar_t kGoogleUpdateUpdatePrefix[] = L"Update"; |
| 34 const GoogleUpdateSettings::UpdatePolicy kDefaultUpdatePolicy = | 30 const GoogleUpdateSettings::UpdatePolicy kDefaultUpdatePolicy = |
| 35 #if defined(GOOGLE_CHROME_BUILD) | 31 #if defined(GOOGLE_CHROME_BUILD) |
| 36 GoogleUpdateSettings::AUTOMATIC_UPDATES; | 32 GoogleUpdateSettings::AUTOMATIC_UPDATES; |
| 37 #else | 33 #else |
| 38 GoogleUpdateSettings::UPDATES_DISABLED; | 34 GoogleUpdateSettings::UPDATES_DISABLED; |
| 39 #endif | 35 #endif |
| 40 | 36 |
| 41 const wchar_t kTestProductGuid[] = L"{89F1B351-B15D-48D4-8F10-1298721CF13D}"; | 37 const wchar_t kTestProductGuid[] = L"{89F1B351-B15D-48D4-8F10-1298721CF13D}"; |
| 42 | 38 |
| 43 // This test fixture redirects the HKLM and HKCU registry hives for | 39 // This test fixture redirects the HKLM and HKCU registry hives for |
| 44 // the duration of the test to make it independent of the machine | 40 // the duration of the test to make it independent of the machine |
| 45 // and user settings. | 41 // and user settings. |
| 46 class GoogleUpdateSettingsTest: public testing::Test { | 42 class GoogleUpdateSettingsTest: public testing::Test { |
| 47 protected: | 43 protected: |
| 48 virtual void SetUp() { | 44 virtual void SetUp() OVERRIDE { |
| 49 // Wipe the keys we redirect to. | 45 registry_overrides_.OverrideRegistry(HKEY_LOCAL_MACHINE, L"HKLM_pit"); |
| 50 // This gives us a stable run, even in the presence of previous | 46 registry_overrides_.OverrideRegistry(HKEY_CURRENT_USER, L"HKCU_pit"); |
| 51 // crashes or failures. | |
| 52 LSTATUS err = SHDeleteKey(HKEY_CURRENT_USER, kHKCUReplacement); | |
| 53 EXPECT_TRUE(err == ERROR_SUCCESS || err == ERROR_FILE_NOT_FOUND); | |
| 54 err = SHDeleteKey(HKEY_CURRENT_USER, kHKLMReplacement); | |
| 55 EXPECT_TRUE(err == ERROR_SUCCESS || err == ERROR_FILE_NOT_FOUND); | |
| 56 | |
| 57 // Create the keys we're redirecting HKCU and HKLM to. | |
| 58 ASSERT_EQ(ERROR_SUCCESS, | |
| 59 hkcu_.Create(HKEY_CURRENT_USER, kHKCUReplacement, KEY_READ)); | |
| 60 ASSERT_EQ(ERROR_SUCCESS, | |
| 61 hklm_.Create(HKEY_CURRENT_USER, kHKLMReplacement, KEY_READ)); | |
| 62 | |
| 63 // And do the switcharoo. | |
| 64 ASSERT_EQ(ERROR_SUCCESS, | |
| 65 ::RegOverridePredefKey(HKEY_CURRENT_USER, hkcu_.Handle())); | |
| 66 ASSERT_EQ(ERROR_SUCCESS, | |
| 67 ::RegOverridePredefKey(HKEY_LOCAL_MACHINE, hklm_.Handle())); | |
| 68 } | |
| 69 | |
| 70 virtual void TearDown() { | |
| 71 // Undo the redirection. | |
| 72 EXPECT_EQ(ERROR_SUCCESS, ::RegOverridePredefKey(HKEY_CURRENT_USER, NULL)); | |
| 73 EXPECT_EQ(ERROR_SUCCESS, ::RegOverridePredefKey(HKEY_LOCAL_MACHINE, NULL)); | |
| 74 | |
| 75 // Close our handles and delete the temp keys we redirected to. | |
| 76 hkcu_.Close(); | |
| 77 hklm_.Close(); | |
| 78 EXPECT_EQ(ERROR_SUCCESS, SHDeleteKey(HKEY_CURRENT_USER, kHKCUReplacement)); | |
| 79 EXPECT_EQ(ERROR_SUCCESS, SHDeleteKey(HKEY_CURRENT_USER, kHKLMReplacement)); | |
| 80 } | 47 } |
| 81 | 48 |
| 82 enum SystemUserInstall { | 49 enum SystemUserInstall { |
| 83 SYSTEM_INSTALL, | 50 SYSTEM_INSTALL, |
| 84 USER_INSTALL, | 51 USER_INSTALL, |
| 85 }; | 52 }; |
| 86 | 53 |
| 87 void SetApField(SystemUserInstall is_system, const wchar_t* value) { | 54 void SetApField(SystemUserInstall is_system, const wchar_t* value) { |
| 88 HKEY root = is_system == SYSTEM_INSTALL ? | 55 HKEY root = is_system == SYSTEM_INSTALL ? |
| 89 HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; | 56 HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 std::wstring ap_key_value; | 141 std::wstring ap_key_value; |
| 175 std::wstring reg_key = GetApKeyPath(); | 142 std::wstring reg_key = GetApKeyPath(); |
| 176 if (key.Open(HKEY_CURRENT_USER, reg_key.c_str(), KEY_ALL_ACCESS) == | 143 if (key.Open(HKEY_CURRENT_USER, reg_key.c_str(), KEY_ALL_ACCESS) == |
| 177 ERROR_SUCCESS) { | 144 ERROR_SUCCESS) { |
| 178 key.ReadValue(google_update::kRegApField, &ap_key_value); | 145 key.ReadValue(google_update::kRegApField, &ap_key_value); |
| 179 } | 146 } |
| 180 | 147 |
| 181 return ap_key_value; | 148 return ap_key_value; |
| 182 } | 149 } |
| 183 | 150 |
| 184 RegKey hkcu_; | 151 registry_util::RegistryOverrideManager registry_overrides_; |
| 185 RegKey hklm_; | |
| 186 }; | 152 }; |
| 187 | 153 |
| 188 } // namespace | 154 } // namespace |
| 189 | 155 |
| 190 // Verify that we return success on no registration (which means stable), | 156 // Verify that we return success on no registration (which means stable), |
| 191 // whether per-system or per-user install. | 157 // whether per-system or per-user install. |
| 192 TEST_F(GoogleUpdateSettingsTest, CurrentChromeChannelAbsent) { | 158 TEST_F(GoogleUpdateSettingsTest, CurrentChromeChannelAbsent) { |
| 193 // Per-system first. | 159 // Per-system first. |
| 194 string16 channel; | 160 string16 channel; |
| 195 EXPECT_TRUE(GoogleUpdateSettings::GetChromeChannelAndModifiers(true, | 161 EXPECT_TRUE(GoogleUpdateSettings::GetChromeChannelAndModifiers(true, |
| (...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 583 static_cast<DWORD>(3))); | 549 static_cast<DWORD>(3))); |
| 584 is_overridden = true; | 550 is_overridden = true; |
| 585 EXPECT_EQ(GoogleUpdateSettings::UPDATES_DISABLED, | 551 EXPECT_EQ(GoogleUpdateSettings::UPDATES_DISABLED, |
| 586 GoogleUpdateSettings::GetAppUpdatePolicy(kTestProductGuid, | 552 GoogleUpdateSettings::GetAppUpdatePolicy(kTestProductGuid, |
| 587 &is_overridden)); | 553 &is_overridden)); |
| 588 EXPECT_FALSE(is_overridden); | 554 EXPECT_FALSE(is_overridden); |
| 589 } | 555 } |
| 590 | 556 |
| 591 #endif // defined(GOOGLE_CHROME_BUILD) | 557 #endif // defined(GOOGLE_CHROME_BUILD) |
| 592 | 558 |
| 559 // Test GoogleUpdateSettings::GetUninstallCommandLine at system- or user-level, |
| 560 // according to the param. |
| 561 class GetUninstallCommandLine : public GoogleUpdateSettingsTest, |
| 562 public testing::WithParamInterface<bool> { |
| 563 protected: |
| 564 static const wchar_t kDummyCommand[]; |
| 565 |
| 566 virtual void SetUp() OVERRIDE { |
| 567 GoogleUpdateSettingsTest::SetUp(); |
| 568 system_install_ = GetParam(); |
| 569 root_key_ = system_install_ ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; |
| 570 } |
| 571 |
| 572 HKEY root_key_; |
| 573 bool system_install_; |
| 574 }; |
| 575 |
| 576 const wchar_t GetUninstallCommandLine::kDummyCommand[] = |
| 577 L"\"goopdate.exe\" /spam"; |
| 578 |
| 579 // Tests that GetUninstallCommandLine returns an empty string if there's no |
| 580 // Software\Google\Update key. |
| 581 TEST_P(GetUninstallCommandLine, TestNoKey) { |
| 582 EXPECT_EQ(string16(), |
| 583 GoogleUpdateSettings::GetUninstallCommandLine(system_install_)); |
| 584 } |
| 585 |
| 586 // Tests that GetUninstallCommandLine returns an empty string if there's no |
| 587 // UninstallCmdLine value in the Software\Google\Update key. |
| 588 TEST_P(GetUninstallCommandLine, TestNoValue) { |
| 589 RegKey(root_key_, google_update::kRegPathGoogleUpdate, KEY_SET_VALUE); |
| 590 EXPECT_EQ(string16(), |
| 591 GoogleUpdateSettings::GetUninstallCommandLine(system_install_)); |
| 592 } |
| 593 |
| 594 // Tests that GetUninstallCommandLine returns an empty string if there's an |
| 595 // empty UninstallCmdLine value in the Software\Google\Update key. |
| 596 TEST_P(GetUninstallCommandLine, TestEmptyValue) { |
| 597 RegKey(root_key_, google_update::kRegPathGoogleUpdate, KEY_SET_VALUE) |
| 598 .WriteValue(google_update::kRegUninstallCmdLine, L""); |
| 599 EXPECT_EQ(string16(), |
| 600 GoogleUpdateSettings::GetUninstallCommandLine(system_install_)); |
| 601 } |
| 602 |
| 603 // Tests that GetUninstallCommandLine returns the correct string if there's an |
| 604 // UninstallCmdLine value in the Software\Google\Update key. |
| 605 TEST_P(GetUninstallCommandLine, TestRealValue) { |
| 606 RegKey(root_key_, google_update::kRegPathGoogleUpdate, KEY_SET_VALUE) |
| 607 .WriteValue(google_update::kRegUninstallCmdLine, kDummyCommand); |
| 608 EXPECT_EQ(string16(kDummyCommand), |
| 609 GoogleUpdateSettings::GetUninstallCommandLine(system_install_)); |
| 610 // Make sure that there's no value in the other level (user or system). |
| 611 EXPECT_EQ(string16(), |
| 612 GoogleUpdateSettings::GetUninstallCommandLine(!system_install_)); |
| 613 } |
| 614 |
| 615 INSTANTIATE_TEST_CASE_P(GetUninstallCommandLineAtLevel, GetUninstallCommandLine, |
| 616 testing::Bool()); |
| 617 |
| 593 // Test values for use by the CollectStatsConsent test fixture. | 618 // Test values for use by the CollectStatsConsent test fixture. |
| 594 class StatsState { | 619 class StatsState { |
| 595 public: | 620 public: |
| 596 enum InstallType { | 621 enum InstallType { |
| 597 SINGLE_INSTALL, | 622 SINGLE_INSTALL, |
| 598 MULTI_INSTALL, | 623 MULTI_INSTALL, |
| 599 }; | 624 }; |
| 600 enum StateSetting { | 625 enum StateSetting { |
| 601 NO_SETTING, | 626 NO_SETTING, |
| 602 FALSE_SETTING, | 627 FALSE_SETTING, |
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 845 StatsState(StatsState::kSystemLevel, StatsState::MULTI_INSTALL, | 870 StatsState(StatsState::kSystemLevel, StatsState::MULTI_INSTALL, |
| 846 StatsState::FALSE_SETTING, StatsState::FALSE_SETTING), | 871 StatsState::FALSE_SETTING, StatsState::FALSE_SETTING), |
| 847 StatsState(StatsState::kSystemLevel, StatsState::MULTI_INSTALL, | 872 StatsState(StatsState::kSystemLevel, StatsState::MULTI_INSTALL, |
| 848 StatsState::FALSE_SETTING, StatsState::TRUE_SETTING), | 873 StatsState::FALSE_SETTING, StatsState::TRUE_SETTING), |
| 849 StatsState(StatsState::kSystemLevel, StatsState::MULTI_INSTALL, | 874 StatsState(StatsState::kSystemLevel, StatsState::MULTI_INSTALL, |
| 850 StatsState::TRUE_SETTING, StatsState::NO_SETTING), | 875 StatsState::TRUE_SETTING, StatsState::NO_SETTING), |
| 851 StatsState(StatsState::kSystemLevel, StatsState::MULTI_INSTALL, | 876 StatsState(StatsState::kSystemLevel, StatsState::MULTI_INSTALL, |
| 852 StatsState::TRUE_SETTING, StatsState::FALSE_SETTING), | 877 StatsState::TRUE_SETTING, StatsState::FALSE_SETTING), |
| 853 StatsState(StatsState::kSystemLevel, StatsState::MULTI_INSTALL, | 878 StatsState(StatsState::kSystemLevel, StatsState::MULTI_INSTALL, |
| 854 StatsState::TRUE_SETTING, StatsState::TRUE_SETTING))); | 879 StatsState::TRUE_SETTING, StatsState::TRUE_SETTING))); |
| OLD | NEW |