| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/installer/mini_installer/configuration.h" | 5 #include "chrome/installer/mini_installer/configuration.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdlib.h> | 8 #include <stdlib.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/environment.h" | 13 #include "base/environment.h" |
| 14 #include "base/macros.h" |
| 14 #include "base/test/test_reg_util_win.h" | 15 #include "base/test/test_reg_util_win.h" |
| 15 #include "base/win/registry.h" | 16 #include "base/win/registry.h" |
| 16 #include "chrome/installer/mini_installer/appid.h" | 17 #include "chrome/installer/mini_installer/appid.h" |
| 17 #include "chrome/installer/mini_installer/mini_installer_constants.h" | 18 #include "chrome/installer/mini_installer/mini_installer_constants.h" |
| 18 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
| 19 | 20 |
| 20 namespace mini_installer { | 21 namespace mini_installer { |
| 21 | 22 |
| 22 namespace { | 23 namespace { |
| 23 | 24 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 // Adds sufficient state in the registry for Configuration to think that | 60 // Adds sufficient state in the registry for Configuration to think that |
| 60 // Chrome is already installed at |system_level| as per |multi_install|. | 61 // Chrome is already installed at |system_level| as per |multi_install|. |
| 61 void AddChromeRegistryState(bool system_level, bool multi_install) { | 62 void AddChromeRegistryState(bool system_level, bool multi_install) { |
| 62 #if defined(GOOGLE_CHROME_BUILD) | 63 #if defined(GOOGLE_CHROME_BUILD) |
| 63 static constexpr wchar_t kClientsPath[] = | 64 static constexpr wchar_t kClientsPath[] = |
| 64 L"SOFTWARE\\Google\\Update\\Clients\\" | 65 L"SOFTWARE\\Google\\Update\\Clients\\" |
| 65 L"{8A69D345-D564-463c-AFF1-A69D9E530F96}"; | 66 L"{8A69D345-D564-463c-AFF1-A69D9E530F96}"; |
| 66 static constexpr wchar_t kClientStatePath[] = | 67 static constexpr wchar_t kClientStatePath[] = |
| 67 L"SOFTWARE\\Google\\Update\\ClientState\\" | 68 L"SOFTWARE\\Google\\Update\\ClientState\\" |
| 68 L"{8A69D345-D564-463c-AFF1-A69D9E530F96}"; | 69 L"{8A69D345-D564-463c-AFF1-A69D9E530F96}"; |
| 69 #else | 70 #else // GOOGLE_CHROME_BUILD |
| 70 static constexpr wchar_t kClientsPath[] = L"SOFTWARE\\Chromium"; | 71 static constexpr wchar_t kClientsPath[] = L"SOFTWARE\\Chromium"; |
| 71 static constexpr wchar_t kClientStatePath[] = L"SOFTWARE\\Chromium"; | 72 static constexpr wchar_t kClientStatePath[] = L"SOFTWARE\\Chromium"; |
| 72 #endif | 73 #endif // GOOGLE_CHROME_BUILD |
| 73 static constexpr const wchar_t* kUninstallArguments[] = { | 74 base::string16 uninstall_arguments(L"--uninstall"); |
| 74 L"--uninstall", L"--uninstall --multi-install --chrome", | 75 if (system_level) |
| 75 L"--uninstall --system-level", | 76 uninstall_arguments += L" --system_level"; |
| 76 L"--uninstall --system-level --multi-install --chrome", | 77 if (multi_install) |
| 77 }; | 78 uninstall_arguments += L" --multi-install --chrome"; |
| 78 const int uninstall_index = | |
| 79 ((system_level ? 0x02 : 0) | (multi_install ? 0x01 : 0)); | |
| 80 const HKEY root = system_level ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; | 79 const HKEY root = system_level ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; |
| 80 // Use base::win::RegKey rather than mini_installer's since it's more |
| 81 // prevalent in the codebase and more likely to be easy to understand. |
| 81 base::win::RegKey key; | 82 base::win::RegKey key; |
| 82 ASSERT_EQ(ERROR_SUCCESS, | 83 ASSERT_EQ(ERROR_SUCCESS, |
| 83 key.Create(root, kClientsPath, KEY_WOW64_32KEY | KEY_SET_VALUE)); | 84 key.Create(root, kClientsPath, KEY_WOW64_32KEY | KEY_SET_VALUE)); |
| 84 ASSERT_EQ(ERROR_SUCCESS, key.WriteValue(L"pv", L"4.3.2.1")); | 85 ASSERT_EQ(ERROR_SUCCESS, key.WriteValue(L"pv", L"4.3.2.1")); |
| 85 ASSERT_EQ(ERROR_SUCCESS, key.Create(root, kClientStatePath, | 86 ASSERT_EQ(ERROR_SUCCESS, key.Create(root, kClientStatePath, |
| 86 KEY_WOW64_32KEY | KEY_SET_VALUE)); | 87 KEY_WOW64_32KEY | KEY_SET_VALUE)); |
| 87 ASSERT_EQ(ERROR_SUCCESS, | 88 ASSERT_EQ( |
| 88 key.WriteValue(L"UninstallArguments", | 89 ERROR_SUCCESS, |
| 89 kUninstallArguments[uninstall_index])); | 90 key.WriteValue(L"UninstallArguments", uninstall_arguments.c_str())); |
| 90 } | 91 } |
| 91 | 92 |
| 92 private: | 93 private: |
| 93 registry_util::RegistryOverrideManager registry_overrides_; | 94 registry_util::RegistryOverrideManager registry_overrides_; |
| 94 | 95 |
| 95 DISALLOW_COPY_AND_ASSIGN(MiniInstallerConfigurationTest); | 96 DISALLOW_COPY_AND_ASSIGN(MiniInstallerConfigurationTest); |
| 96 }; | 97 }; |
| 97 | 98 |
| 98 // Test that the operation type is CLEANUP iff --cleanup is on the cmdline. | 99 // Test that the operation type is CLEANUP iff --cleanup is on the cmdline. |
| 99 TEST_F(MiniInstallerConfigurationTest, Operation) { | 100 TEST_F(MiniInstallerConfigurationTest, Operation) { |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 AddChromeRegistryState(true /* system_level */, true /* multi_install */); | 163 AddChromeRegistryState(true /* system_level */, true /* multi_install */); |
| 163 #if defined(GOOGLE_CHROME_BUILD) | 164 #if defined(GOOGLE_CHROME_BUILD) |
| 164 EXPECT_TRUE( | 165 EXPECT_TRUE( |
| 165 TestConfiguration(L"spam.exe --system-level").is_updating_multi_chrome()); | 166 TestConfiguration(L"spam.exe --system-level").is_updating_multi_chrome()); |
| 166 #else | 167 #else |
| 167 EXPECT_FALSE( | 168 EXPECT_FALSE( |
| 168 TestConfiguration(L"spam.exe --system-level").is_updating_multi_chrome()); | 169 TestConfiguration(L"spam.exe --system-level").is_updating_multi_chrome()); |
| 169 #endif | 170 #endif |
| 170 } | 171 } |
| 171 | 172 |
| 173 #if defined(GOOGLE_CHROME_BUILD) |
| 172 TEST_F(MiniInstallerConfigurationTest, ChromeAppGuid) { | 174 TEST_F(MiniInstallerConfigurationTest, ChromeAppGuid) { |
| 173 #if defined(GOOGLE_CHROME_BUILD) | |
| 174 EXPECT_STREQ(google_update::kAppGuid, | 175 EXPECT_STREQ(google_update::kAppGuid, |
| 175 TestConfiguration(L"spam.exe").chrome_app_guid()); | 176 TestConfiguration(L"spam.exe").chrome_app_guid()); |
| 176 EXPECT_STREQ(google_update::kSxSAppGuid, | 177 EXPECT_STREQ(google_update::kSxSAppGuid, |
| 177 TestConfiguration(L"spam.exe --chrome-sxs").chrome_app_guid()); | 178 TestConfiguration(L"spam.exe --chrome-sxs").chrome_app_guid()); |
| 179 } |
| 178 #endif | 180 #endif |
| 179 } | |
| 180 | 181 |
| 181 TEST_F(MiniInstallerConfigurationTest, IsSystemLevel) { | 182 TEST_F(MiniInstallerConfigurationTest, IsSystemLevel) { |
| 182 EXPECT_FALSE(TestConfiguration(L"spam.exe").is_system_level()); | 183 EXPECT_FALSE(TestConfiguration(L"spam.exe").is_system_level()); |
| 183 EXPECT_FALSE(TestConfiguration(L"spam.exe --chrome").is_system_level()); | 184 EXPECT_FALSE(TestConfiguration(L"spam.exe --chrome").is_system_level()); |
| 184 EXPECT_TRUE(TestConfiguration(L"spam.exe --system-level").is_system_level()); | 185 EXPECT_TRUE(TestConfiguration(L"spam.exe --system-level").is_system_level()); |
| 185 | 186 |
| 186 { | 187 { |
| 187 ScopedGoogleUpdateIsMachine env_setter(false); | 188 ScopedGoogleUpdateIsMachine env_setter(false); |
| 188 EXPECT_FALSE(TestConfiguration(L"spam.exe").is_system_level()); | 189 EXPECT_FALSE(TestConfiguration(L"spam.exe").is_system_level()); |
| 189 } | 190 } |
| 190 | 191 |
| 191 { | 192 { |
| 192 ScopedGoogleUpdateIsMachine env_setter(true); | 193 ScopedGoogleUpdateIsMachine env_setter(true); |
| 193 EXPECT_TRUE(TestConfiguration(L"spam.exe").is_system_level()); | 194 EXPECT_TRUE(TestConfiguration(L"spam.exe").is_system_level()); |
| 194 } | 195 } |
| 195 } | 196 } |
| 196 | 197 |
| 197 TEST_F(MiniInstallerConfigurationTest, IsSideBySide) { | |
| 198 EXPECT_FALSE(TestConfiguration(L"spam.exe").is_side_by_side()); | |
| 199 #if defined(GOOGLE_CHROME_BUILD) | |
| 200 EXPECT_TRUE(TestConfiguration(L"spam.exe --chrome-sxs").is_side_by_side()); | |
| 201 #else | |
| 202 EXPECT_FALSE(TestConfiguration(L"spam.exe --chrome-sxs").is_side_by_side()); | |
| 203 #endif | |
| 204 } | |
| 205 | |
| 206 TEST_F(MiniInstallerConfigurationTest, HasInvalidSwitch) { | 198 TEST_F(MiniInstallerConfigurationTest, HasInvalidSwitch) { |
| 207 EXPECT_FALSE(TestConfiguration(L"spam.exe").has_invalid_switch()); | 199 EXPECT_FALSE(TestConfiguration(L"spam.exe").has_invalid_switch()); |
| 208 EXPECT_TRUE(TestConfiguration(L"spam.exe --chrome-frame") | 200 EXPECT_TRUE(TestConfiguration(L"spam.exe --chrome-frame") |
| 209 .has_invalid_switch()); | 201 .has_invalid_switch()); |
| 210 } | 202 } |
| 211 | 203 |
| 212 } // namespace mini_installer | 204 } // namespace mini_installer |
| OLD | NEW |