OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 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 |
| 5 #include "chrome/installer/setup/setup_install_details.h" |
| 6 |
| 7 #include <windows.h> |
| 8 |
| 9 #include "base/command_line.h" |
| 10 #include "base/macros.h" |
| 11 #include "base/memory/ptr_util.h" |
| 12 #include "base/test/test_reg_util_win.h" |
| 13 #include "chrome/install_static/install_details.h" |
| 14 #include "chrome/install_static/install_modes.h" |
| 15 #include "chrome/installer/util/master_preferences.h" |
| 16 #include "chrome_elf/nt_registry/nt_registry.h" |
| 17 |
| 18 #include "testing/gmock/include/gmock/gmock.h" |
| 19 #include "testing/gtest/include/gtest/gtest.h" |
| 20 |
| 21 using ::testing::Eq; |
| 22 |
| 23 struct TestData { |
| 24 // Inputs: |
| 25 const wchar_t* command_line; |
| 26 const wchar_t* uninstall_args; |
| 27 const wchar_t* product_ap; |
| 28 const wchar_t* binaries_ap; |
| 29 |
| 30 // Expectations: |
| 31 install_static::InstallConstantIndex index; |
| 32 bool system_level; |
| 33 const wchar_t* channel; |
| 34 }; |
| 35 |
| 36 #if defined(GOOGLE_CHROME_BUILD) |
| 37 constexpr TestData kTestData[] = { |
| 38 // User-level test cases. |
| 39 { |
| 40 L"setup.exe", // User-level, primary mode. |
| 41 L"", // New install. |
| 42 L"x64-stable", // Stable channel. |
| 43 L"1.1-beta", // Value ignored in binaries. |
| 44 install_static::STABLE_INDEX, // Expect primary mode. |
| 45 false, // Expect user-level. |
| 46 L"", // Expect stable channel. |
| 47 }, |
| 48 { |
| 49 L"setup.exe", // User-level, primary mode. |
| 50 L"--uninstall", // Updating an existing install. |
| 51 L"x64-stable", // Stable channel. |
| 52 L"1.1-beta", // Value ignored in binaries. |
| 53 install_static::STABLE_INDEX, // Expect primary mode. |
| 54 false, // Expect user-level. |
| 55 L"", // Expect stable channel. |
| 56 }, |
| 57 { |
| 58 L"setup.exe", // User-level, primary mode. |
| 59 L"--uninstall --multi-install", // Updating an existing multi-install. |
| 60 L"x64-stable", // Value ignored in product. |
| 61 L"1.1-beta", // Channel read from binaries. |
| 62 install_static::STABLE_INDEX, // Expect primary mode. |
| 63 false, // Expect user-level. |
| 64 L"beta", // Expect beta channel. |
| 65 }, |
| 66 { |
| 67 L"setup.exe", // User-level, primary mode. |
| 68 L"", // New install. |
| 69 L"1.1-beta", // Beta channel. |
| 70 L"x64-stable", // Value ignored in binaries. |
| 71 install_static::STABLE_INDEX, // Expect primary mode. |
| 72 false, // Expect user-level. |
| 73 L"beta", // Expect beta channel. |
| 74 }, |
| 75 { |
| 76 L"setup.exe --chrome-sxs", // User-level, secondary SxS canary mode. |
| 77 L"", // New install. |
| 78 L"", // Unused. |
| 79 L"", // Unused. |
| 80 install_static::CANARY_INDEX, // Expect SxS canary mode. |
| 81 false, // Expect user-level. |
| 82 L"canary", // Expect canary channel. |
| 83 }, |
| 84 { |
| 85 L"setup.exe --chrome-sxs", // User-level, secondary SxS canary mode. |
| 86 L"--uninstall --chrome-sxs", // Update. |
| 87 L"", // Unused. |
| 88 L"", // Unused. |
| 89 install_static::CANARY_INDEX, // Expect SxS canary mode. |
| 90 false, // Expect user-level. |
| 91 L"canary", // Expect canary channel. |
| 92 }, |
| 93 |
| 94 // System-level test cases. |
| 95 { |
| 96 L"setup.exe --system-level", // System-level, primary mode. |
| 97 L"", // New install. |
| 98 L"x64-stable", // Stable channel. |
| 99 L"1.1-beta", // Value ignored in binaries. |
| 100 install_static::STABLE_INDEX, // Expect primary mode. |
| 101 true, // Expect system-level. |
| 102 L"", // Expect stable channel. |
| 103 }, |
| 104 { |
| 105 L"setup.exe --system-level", // System-level, primary mode. |
| 106 L"--uninstall --system-level", // Updating an existing install. |
| 107 L"x64-stable", // Stable channel. |
| 108 L"1.1-beta", // Value ignored in binaries. |
| 109 install_static::STABLE_INDEX, // Expect primary mode. |
| 110 true, // Expect system-level. |
| 111 L"", // Expect stable channel. |
| 112 }, |
| 113 { |
| 114 L"setup.exe --system-level", // System-level, primary mode. |
| 115 // Updating an existing multi-install. |
| 116 L"--uninstall --system-level --multi-install", |
| 117 L"x64-stable", // Value ignored in product. |
| 118 L"1.1-beta", // Channel read from binaries. |
| 119 install_static::STABLE_INDEX, // Expect primary mode. |
| 120 true, // Expect system-level. |
| 121 L"beta", // Expect beta channel. |
| 122 }, |
| 123 { |
| 124 L"setup.exe --system-level", // System-level, primary mode. |
| 125 L"", // New install. |
| 126 L"1.1-beta", // Beta channel. |
| 127 L"x64-stable", // Value ignored in binaries. |
| 128 install_static::STABLE_INDEX, // Expect primary mode. |
| 129 true, // Expect system-level. |
| 130 L"beta", // Expect beta channel. |
| 131 }, |
| 132 }; |
| 133 #else // GOOGLE_CHROME_BUILD |
| 134 constexpr TestData kTestData[] = { |
| 135 // User-level test cases. |
| 136 { |
| 137 L"setup.exe", // User-level, primary mode. |
| 138 L"", // New install. |
| 139 L"", // Channels are not supported. |
| 140 L"", // Channels are not supported. |
| 141 install_static::CHROMIUM_INDEX, // Expect primary mode. |
| 142 false, // Expect user-level. |
| 143 L"", // Expect empty channel. |
| 144 }, |
| 145 { |
| 146 L"setup.exe", // User-level, primary mode. |
| 147 L"--uninstall", // Updating an existing install. |
| 148 L"", // Channels are not supported. |
| 149 L"", // Channels are not supported. |
| 150 install_static::CHROMIUM_INDEX, // Expect primary mode. |
| 151 false, // Expect user-level. |
| 152 L"", // Expect empty channel. |
| 153 }, |
| 154 |
| 155 // System-level test cases. |
| 156 { |
| 157 L"setup.exe --system-level", // System-level, primary mode. |
| 158 L"", // New install. |
| 159 L"", // Channels are not supported. |
| 160 L"", // Channels are not supported. |
| 161 install_static::CHROMIUM_INDEX, // Expect primary mode. |
| 162 true, // Expect system-level. |
| 163 L"", // Expect empty channel. |
| 164 }, |
| 165 { |
| 166 L"setup.exe --system-level", // System-level, primary mode. |
| 167 L"--uninstall --system-level", // Updating an existing install. |
| 168 L"", // Channels are not supported. |
| 169 L"", // Channels are not supported. |
| 170 install_static::CHROMIUM_INDEX, // Expect primary mode. |
| 171 true, // Expect system-level. |
| 172 L"", // Expect empty channel. |
| 173 }, |
| 174 }; |
| 175 #endif // !GOOGLE_CHROME_BUILD |
| 176 |
| 177 class MakeInstallDetailsTest : public testing::TestWithParam<TestData> { |
| 178 protected: |
| 179 MakeInstallDetailsTest() |
| 180 : test_data_(GetParam()), |
| 181 root_key_(test_data_.system_level ? HKEY_LOCAL_MACHINE |
| 182 : HKEY_CURRENT_USER), |
| 183 nt_root_key_(test_data_.system_level ? nt::HKLM : nt::HKCU), |
| 184 command_line_(base::CommandLine::NO_PROGRAM) { |
| 185 // Prepare the inputs from the process command line. |
| 186 command_line_.ParseFromString(test_data_.command_line); |
| 187 master_preferences_ = |
| 188 base::MakeUnique<installer::MasterPreferences>(command_line_); |
| 189 } |
| 190 |
| 191 void SetUp() override { |
| 192 base::string16 path; |
| 193 ASSERT_NO_FATAL_FAILURE( |
| 194 override_manager_.OverrideRegistry(root_key_, &path)); |
| 195 nt::SetTestingOverride(nt_root_key_, path); |
| 196 |
| 197 // Prepare the inputs from the machine's state. |
| 198 ASSERT_NO_FATAL_FAILURE(SetUninstallArguments( |
| 199 root_key_, install_static::kInstallModes[test_data_.index].app_guid, |
| 200 test_data_.uninstall_args)); |
| 201 if (install_static::kUseGoogleUpdateIntegration) { |
| 202 ASSERT_NO_FATAL_FAILURE(SetProductAp( |
| 203 root_key_, install_static::kInstallModes[test_data_.index].app_guid, |
| 204 test_data_.product_ap)); |
| 205 ASSERT_NO_FATAL_FAILURE(SetBinariesAp(root_key_, test_data_.binaries_ap)); |
| 206 } |
| 207 } |
| 208 |
| 209 void TearDown() override { |
| 210 nt::SetTestingOverride(nt_root_key_, base::string16()); |
| 211 } |
| 212 |
| 213 const TestData& test_data() const { return test_data_; } |
| 214 |
| 215 const base::CommandLine& command_line() const { return command_line_; } |
| 216 |
| 217 const installer::MasterPreferences& master_preferences() const { |
| 218 return *master_preferences_; |
| 219 } |
| 220 |
| 221 private: |
| 222 static void SetUninstallArguments(HKEY root_key, |
| 223 const wchar_t* app_guid, |
| 224 const wchar_t* uninstall_args) { |
| 225 // Do nothing if there's no value to write. |
| 226 if (!uninstall_args || !*uninstall_args) |
| 227 return; |
| 228 // Make it appear that the product is installed with the given uninstall |
| 229 // args. |
| 230 ASSERT_THAT( |
| 231 base::win::RegKey(root_key, |
| 232 install_static::GetClientsKeyPath(app_guid).c_str(), |
| 233 KEY_WOW64_32KEY | KEY_SET_VALUE) |
| 234 .WriteValue(L"pv", L"1.2.3.4"), |
| 235 Eq(ERROR_SUCCESS)); |
| 236 ASSERT_THAT( |
| 237 base::win::RegKey( |
| 238 root_key, install_static::GetClientStateKeyPath(app_guid).c_str(), |
| 239 KEY_WOW64_32KEY | KEY_SET_VALUE) |
| 240 .WriteValue(L"UninstallArguments", uninstall_args), |
| 241 Eq(ERROR_SUCCESS)); |
| 242 } |
| 243 |
| 244 static void SetProductAp(HKEY root_key, |
| 245 const wchar_t* app_guid, |
| 246 const wchar_t* ap) { |
| 247 // Do nothing if there's no value to write. |
| 248 if (!ap || !*ap) |
| 249 return; |
| 250 ASSERT_THAT( |
| 251 base::win::RegKey( |
| 252 root_key, install_static::GetClientStateKeyPath(app_guid).c_str(), |
| 253 KEY_WOW64_32KEY | KEY_SET_VALUE) |
| 254 .WriteValue(L"ap", ap), |
| 255 Eq(ERROR_SUCCESS)); |
| 256 } |
| 257 |
| 258 static void SetBinariesAp(HKEY root_key, const wchar_t* ap) { |
| 259 // Do nothing if there's no value to write. |
| 260 if (!ap || !*ap) |
| 261 return; |
| 262 ASSERT_THAT( |
| 263 base::win::RegKey( |
| 264 root_key, install_static::GetBinariesClientStateKeyPath().c_str(), |
| 265 KEY_WOW64_32KEY | KEY_SET_VALUE) |
| 266 .WriteValue(L"ap", ap), |
| 267 Eq(ERROR_SUCCESS)); |
| 268 } |
| 269 |
| 270 registry_util::RegistryOverrideManager override_manager_; |
| 271 const TestData& test_data_; |
| 272 HKEY root_key_; |
| 273 nt::ROOT_KEY nt_root_key_; |
| 274 base::CommandLine command_line_; |
| 275 std::unique_ptr<installer::MasterPreferences> master_preferences_; |
| 276 |
| 277 DISALLOW_COPY_AND_ASSIGN(MakeInstallDetailsTest); |
| 278 }; |
| 279 |
| 280 TEST_P(MakeInstallDetailsTest, Test) { |
| 281 std::unique_ptr<install_static::PrimaryInstallDetails> details( |
| 282 MakeInstallDetails(command_line(), master_preferences())); |
| 283 EXPECT_THAT(details->install_mode_index(), Eq(test_data().index)); |
| 284 EXPECT_THAT(details->system_level(), Eq(test_data().system_level)); |
| 285 EXPECT_THAT(details->channel(), Eq(test_data().channel)); |
| 286 } |
| 287 |
| 288 INSTANTIATE_TEST_CASE_P(All, |
| 289 MakeInstallDetailsTest, |
| 290 testing::ValuesIn(kTestData)); |
OLD | NEW |