Chromium Code Reviews| 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 <windows.h> | 5 #include <windows.h> |
| 6 | 6 |
| 7 #include "base/strings/utf_string_conversions.h" | |
| 8 #include "base/test/test_reg_util_win.h" | 7 #include "base/test/test_reg_util_win.h" |
| 9 #include "base/version.h" | 8 #include "base/version.h" |
| 10 #include "base/win/registry.h" | 9 #include "base/win/registry.h" |
| 11 #include "chrome/installer/util/browser_distribution.h" | 10 #include "chrome/installer/util/browser_distribution.h" |
| 12 #include "chrome/installer/util/google_update_constants.h" | 11 #include "chrome/installer/util/google_update_constants.h" |
| 13 #include "chrome/installer/util/installation_state.h" | 12 #include "chrome/installer/util/installation_state.h" |
| 14 #include "chrome/installer/util/util_constants.h" | 13 #include "chrome/installer/util/util_constants.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 16 | 15 |
| 17 using base::win::RegKey; | 16 namespace installer { |
| 18 using installer::ProductState; | |
| 19 using registry_util::RegistryOverrideManager; | |
| 20 | 17 |
| 21 class ProductStateTest : public testing::Test { | 18 class ProductStateTest : public testing::Test { |
| 22 protected: | 19 protected: |
| 23 static void SetUpTestCase(); | 20 ProductStateTest(); |
| 24 static void TearDownTestCase(); | |
| 25 | |
| 26 void SetUp() override; | |
| 27 void TearDown() override; | |
| 28 | 21 |
| 29 void ApplyUninstallCommand(const wchar_t* exe_path, const wchar_t* args); | 22 void ApplyUninstallCommand(const wchar_t* exe_path, const wchar_t* args); |
| 30 void MinimallyInstallProduct(const wchar_t* version); | 23 void MinimallyInstallProduct(const wchar_t* version); |
| 31 | 24 |
| 32 static BrowserDistribution* dist_; | 25 const bool system_install_; |
| 33 bool system_install_; | 26 const HKEY overridden_; |
| 34 HKEY overridden_; | |
| 35 registry_util::RegistryOverrideManager registry_override_manager_; | 27 registry_util::RegistryOverrideManager registry_override_manager_; |
| 36 RegKey clients_; | 28 base::win::RegKey clients_; |
| 37 RegKey client_state_; | 29 base::win::RegKey client_state_; |
| 38 }; | 30 }; |
| 39 | 31 |
| 40 BrowserDistribution* ProductStateTest::dist_; | 32 ProductStateTest::ProductStateTest() |
| 41 | 33 : system_install_(true), |
|
huangs
2017/01/09 09:09:10
Test looks broken: It skips user-level altogether.
grt (UTC plus 2)
2017/01/09 10:11:45
Added coverage for user-level.
| |
| 42 // static | 34 overridden_(system_install_ ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER) { |
| 43 void ProductStateTest::SetUpTestCase() { | |
| 44 testing::Test::SetUpTestCase(); | |
| 45 | |
| 46 // We'll use Chrome as our test subject. | |
| 47 dist_ = BrowserDistribution::GetSpecificDistribution( | |
| 48 BrowserDistribution::CHROME_BROWSER); | |
| 49 } | |
| 50 | |
| 51 // static | |
| 52 void ProductStateTest::TearDownTestCase() { | |
| 53 dist_ = NULL; | |
| 54 | |
| 55 testing::Test::TearDownTestCase(); | |
| 56 } | |
| 57 | |
| 58 void ProductStateTest::SetUp() { | |
| 59 testing::Test::SetUp(); | |
| 60 | |
| 61 // Create/open the keys for the product we'll test. | |
| 62 system_install_ = true; | |
| 63 overridden_ = (system_install_ ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER); | |
| 64 | |
| 65 // Override for test purposes. We don't use ScopedRegistryKeyOverride | |
| 66 // directly because it doesn't suit itself to our use here. | |
| 67 RegKey temp_key; | |
| 68 | |
| 69 registry_override_manager_.OverrideRegistry(overridden_); | 35 registry_override_manager_.OverrideRegistry(overridden_); |
| 70 | 36 |
| 37 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); | |
| 71 EXPECT_EQ(ERROR_SUCCESS, | 38 EXPECT_EQ(ERROR_SUCCESS, |
| 72 clients_.Create(overridden_, dist_->GetVersionKey().c_str(), | 39 clients_.Create(overridden_, dist->GetVersionKey().c_str(), |
| 73 KEY_ALL_ACCESS)); | 40 KEY_ALL_ACCESS | KEY_WOW64_32KEY)); |
| 74 EXPECT_EQ(ERROR_SUCCESS, | 41 EXPECT_EQ(ERROR_SUCCESS, |
| 75 client_state_.Create(overridden_, dist_->GetStateKey().c_str(), | 42 client_state_.Create(overridden_, dist->GetStateKey().c_str(), |
| 76 KEY_ALL_ACCESS)); | 43 KEY_ALL_ACCESS | KEY_WOW64_32KEY)); |
| 77 } | |
| 78 | |
| 79 void ProductStateTest::TearDown() { | |
| 80 // Done with the keys. | |
| 81 client_state_.Close(); | |
| 82 clients_.Close(); | |
| 83 overridden_ = NULL; | |
| 84 system_install_ = false; | |
| 85 | |
| 86 testing::Test::TearDown(); | |
| 87 } | 44 } |
| 88 | 45 |
| 89 void ProductStateTest::MinimallyInstallProduct(const wchar_t* version) { | 46 void ProductStateTest::MinimallyInstallProduct(const wchar_t* version) { |
| 90 EXPECT_EQ(ERROR_SUCCESS, | 47 EXPECT_EQ(ERROR_SUCCESS, |
| 91 clients_.WriteValue(google_update::kRegVersionField, version)); | 48 clients_.WriteValue(google_update::kRegVersionField, version)); |
| 92 } | 49 } |
| 93 | 50 |
| 94 void ProductStateTest::ApplyUninstallCommand(const wchar_t* exe_path, | 51 void ProductStateTest::ApplyUninstallCommand(const wchar_t* exe_path, |
| 95 const wchar_t* args) { | 52 const wchar_t* args) { |
| 96 if (exe_path == NULL) { | 53 if (exe_path == NULL) { |
| 97 LONG result = client_state_.DeleteValue(installer::kUninstallStringField); | 54 LONG result = client_state_.DeleteValue(kUninstallStringField); |
| 98 EXPECT_TRUE(result == ERROR_SUCCESS || result == ERROR_FILE_NOT_FOUND); | 55 EXPECT_TRUE(result == ERROR_SUCCESS || result == ERROR_FILE_NOT_FOUND); |
| 99 } else { | 56 } else { |
| 100 EXPECT_EQ(ERROR_SUCCESS, | 57 EXPECT_EQ(ERROR_SUCCESS, |
| 101 client_state_.WriteValue(installer::kUninstallStringField, | 58 client_state_.WriteValue(kUninstallStringField, exe_path)); |
| 102 exe_path)); | |
| 103 } | 59 } |
| 104 | 60 |
| 105 if (args == NULL) { | 61 if (args == NULL) { |
| 106 LONG result = | 62 LONG result = client_state_.DeleteValue(kUninstallArgumentsField); |
| 107 client_state_.DeleteValue(installer::kUninstallArgumentsField); | |
| 108 EXPECT_TRUE(result == ERROR_SUCCESS || result == ERROR_FILE_NOT_FOUND); | 63 EXPECT_TRUE(result == ERROR_SUCCESS || result == ERROR_FILE_NOT_FOUND); |
| 109 } else { | 64 } else { |
| 110 EXPECT_EQ(ERROR_SUCCESS, | 65 EXPECT_EQ(ERROR_SUCCESS, |
| 111 client_state_.WriteValue(installer::kUninstallArgumentsField, | 66 client_state_.WriteValue(kUninstallArgumentsField, args)); |
| 112 args)); | |
| 113 } | 67 } |
| 114 } | 68 } |
| 115 | 69 |
| 116 TEST_F(ProductStateTest, InitializeInstalled) { | 70 TEST_F(ProductStateTest, InitializeInstalled) { |
| 117 // Not installed. | 71 // Not installed. |
| 118 { | 72 { |
| 119 ProductState state; | 73 ProductState state; |
| 120 LONG result = clients_.DeleteValue(google_update::kRegVersionField); | 74 LONG result = clients_.DeleteValue(google_update::kRegVersionField); |
| 121 EXPECT_TRUE(result == ERROR_SUCCESS || result == ERROR_FILE_NOT_FOUND); | 75 EXPECT_TRUE(result == ERROR_SUCCESS || result == ERROR_FILE_NOT_FOUND); |
| 122 EXPECT_FALSE(state.Initialize(system_install_, dist_)); | 76 EXPECT_FALSE(state.Initialize(system_install_)); |
| 123 } | 77 } |
| 124 | 78 |
| 125 // Empty version. | 79 // Empty version. |
| 126 { | 80 { |
| 127 ProductState state; | 81 ProductState state; |
| 128 LONG result = clients_.WriteValue(google_update::kRegVersionField, L""); | 82 LONG result = clients_.WriteValue(google_update::kRegVersionField, L""); |
| 129 EXPECT_TRUE(result == ERROR_SUCCESS || result == ERROR_FILE_NOT_FOUND); | 83 EXPECT_TRUE(result == ERROR_SUCCESS || result == ERROR_FILE_NOT_FOUND); |
| 130 EXPECT_FALSE(state.Initialize(system_install_, dist_)); | 84 EXPECT_FALSE(state.Initialize(system_install_)); |
| 131 } | 85 } |
| 132 | 86 |
| 133 // Bogus version. | 87 // Bogus version. |
| 134 { | 88 { |
| 135 ProductState state; | 89 ProductState state; |
| 136 LONG result = clients_.WriteValue(google_update::kRegVersionField, | 90 LONG result = clients_.WriteValue(google_update::kRegVersionField, |
| 137 L"goofy"); | 91 L"goofy"); |
| 138 EXPECT_TRUE(result == ERROR_SUCCESS || result == ERROR_FILE_NOT_FOUND); | 92 EXPECT_TRUE(result == ERROR_SUCCESS || result == ERROR_FILE_NOT_FOUND); |
| 139 EXPECT_FALSE(state.Initialize(system_install_, dist_)); | 93 EXPECT_FALSE(state.Initialize(system_install_)); |
| 140 } | 94 } |
| 141 | 95 |
| 142 // Valid "pv" value. | 96 // Valid "pv" value. |
| 143 { | 97 { |
| 144 ProductState state; | 98 ProductState state; |
| 145 LONG result = clients_.WriteValue(google_update::kRegVersionField, | 99 LONG result = clients_.WriteValue(google_update::kRegVersionField, |
| 146 L"10.0.47.0"); | 100 L"10.0.47.0"); |
| 147 EXPECT_TRUE(result == ERROR_SUCCESS || result == ERROR_FILE_NOT_FOUND); | 101 EXPECT_TRUE(result == ERROR_SUCCESS || result == ERROR_FILE_NOT_FOUND); |
| 148 EXPECT_TRUE(state.Initialize(system_install_, dist_)); | 102 EXPECT_TRUE(state.Initialize(system_install_)); |
| 149 EXPECT_EQ("10.0.47.0", state.version().GetString()); | 103 EXPECT_EQ("10.0.47.0", state.version().GetString()); |
| 150 } | 104 } |
| 151 } | 105 } |
| 152 | 106 |
| 153 // Test extraction of the "opv" value from the Clients key. | 107 // Test extraction of the "opv" value from the Clients key. |
| 154 TEST_F(ProductStateTest, InitializeOldVersion) { | 108 TEST_F(ProductStateTest, InitializeOldVersion) { |
| 155 MinimallyInstallProduct(L"10.0.1.1"); | 109 MinimallyInstallProduct(L"10.0.1.1"); |
| 156 | 110 |
| 157 // No "opv" value. | 111 // No "opv" value. |
| 158 { | 112 { |
| 159 ProductState state; | 113 ProductState state; |
| 160 LONG result = clients_.DeleteValue(google_update::kRegOldVersionField); | 114 LONG result = clients_.DeleteValue(google_update::kRegOldVersionField); |
| 161 EXPECT_TRUE(result == ERROR_SUCCESS || result == ERROR_FILE_NOT_FOUND); | 115 EXPECT_TRUE(result == ERROR_SUCCESS || result == ERROR_FILE_NOT_FOUND); |
| 162 EXPECT_TRUE(state.Initialize(system_install_, dist_)); | 116 EXPECT_TRUE(state.Initialize(system_install_)); |
| 163 EXPECT_TRUE(state.old_version() == NULL); | 117 EXPECT_TRUE(state.old_version() == NULL); |
| 164 } | 118 } |
| 165 | 119 |
| 166 // Empty "opv" value. | 120 // Empty "opv" value. |
| 167 { | 121 { |
| 168 ProductState state; | 122 ProductState state; |
| 169 LONG result = clients_.WriteValue(google_update::kRegOldVersionField, L""); | 123 LONG result = clients_.WriteValue(google_update::kRegOldVersionField, L""); |
| 170 EXPECT_TRUE(result == ERROR_SUCCESS || result == ERROR_FILE_NOT_FOUND); | 124 EXPECT_TRUE(result == ERROR_SUCCESS || result == ERROR_FILE_NOT_FOUND); |
| 171 EXPECT_TRUE(state.Initialize(system_install_, dist_)); | 125 EXPECT_TRUE(state.Initialize(system_install_)); |
| 172 EXPECT_TRUE(state.old_version() == NULL); | 126 EXPECT_TRUE(state.old_version() == NULL); |
| 173 } | 127 } |
| 174 | 128 |
| 175 // Bogus "opv" value. | 129 // Bogus "opv" value. |
| 176 { | 130 { |
| 177 ProductState state; | 131 ProductState state; |
| 178 LONG result = clients_.WriteValue(google_update::kRegOldVersionField, | 132 LONG result = clients_.WriteValue(google_update::kRegOldVersionField, |
| 179 L"coming home"); | 133 L"coming home"); |
| 180 EXPECT_TRUE(result == ERROR_SUCCESS || result == ERROR_FILE_NOT_FOUND); | 134 EXPECT_TRUE(result == ERROR_SUCCESS || result == ERROR_FILE_NOT_FOUND); |
| 181 EXPECT_TRUE(state.Initialize(system_install_, dist_)); | 135 EXPECT_TRUE(state.Initialize(system_install_)); |
| 182 EXPECT_TRUE(state.old_version() == NULL); | 136 EXPECT_TRUE(state.old_version() == NULL); |
| 183 } | 137 } |
| 184 | 138 |
| 185 // Valid "opv" value. | 139 // Valid "opv" value. |
| 186 { | 140 { |
| 187 ProductState state; | 141 ProductState state; |
| 188 LONG result = clients_.WriteValue(google_update::kRegOldVersionField, | 142 LONG result = clients_.WriteValue(google_update::kRegOldVersionField, |
| 189 L"10.0.47.0"); | 143 L"10.0.47.0"); |
| 190 EXPECT_TRUE(result == ERROR_SUCCESS || result == ERROR_FILE_NOT_FOUND); | 144 EXPECT_TRUE(result == ERROR_SUCCESS || result == ERROR_FILE_NOT_FOUND); |
| 191 EXPECT_TRUE(state.Initialize(system_install_, dist_)); | 145 EXPECT_TRUE(state.Initialize(system_install_)); |
| 192 EXPECT_TRUE(state.old_version() != NULL); | 146 EXPECT_TRUE(state.old_version() != NULL); |
| 193 EXPECT_EQ("10.0.47.0", state.old_version()->GetString()); | 147 EXPECT_EQ("10.0.47.0", state.old_version()->GetString()); |
| 194 } | 148 } |
| 195 } | 149 } |
| 196 | 150 |
| 197 // Test extraction of the "cmd" value from the Clients key. | 151 // Test extraction of the "cmd" value from the Clients key. |
| 198 TEST_F(ProductStateTest, InitializeRenameCmd) { | 152 TEST_F(ProductStateTest, InitializeRenameCmd) { |
| 199 MinimallyInstallProduct(L"10.0.1.1"); | 153 MinimallyInstallProduct(L"10.0.1.1"); |
| 200 | 154 |
| 201 // No "cmd" value. | 155 // No "cmd" value. |
| 202 { | 156 { |
| 203 ProductState state; | 157 ProductState state; |
| 204 LONG result = clients_.DeleteValue(google_update::kRegRenameCmdField); | 158 LONG result = clients_.DeleteValue(google_update::kRegRenameCmdField); |
| 205 EXPECT_TRUE(result == ERROR_SUCCESS || result == ERROR_FILE_NOT_FOUND); | 159 EXPECT_TRUE(result == ERROR_SUCCESS || result == ERROR_FILE_NOT_FOUND); |
| 206 EXPECT_TRUE(state.Initialize(system_install_, dist_)); | 160 EXPECT_TRUE(state.Initialize(system_install_)); |
| 207 EXPECT_TRUE(state.rename_cmd().empty()); | 161 EXPECT_TRUE(state.rename_cmd().empty()); |
| 208 } | 162 } |
| 209 | 163 |
| 210 // Empty "cmd" value. | 164 // Empty "cmd" value. |
| 211 { | 165 { |
| 212 ProductState state; | 166 ProductState state; |
| 213 LONG result = clients_.WriteValue(google_update::kRegRenameCmdField, L""); | 167 LONG result = clients_.WriteValue(google_update::kRegRenameCmdField, L""); |
| 214 EXPECT_TRUE(result == ERROR_SUCCESS || result == ERROR_FILE_NOT_FOUND); | 168 EXPECT_TRUE(result == ERROR_SUCCESS || result == ERROR_FILE_NOT_FOUND); |
| 215 EXPECT_TRUE(state.Initialize(system_install_, dist_)); | 169 EXPECT_TRUE(state.Initialize(system_install_)); |
| 216 EXPECT_TRUE(state.rename_cmd().empty()); | 170 EXPECT_TRUE(state.rename_cmd().empty()); |
| 217 } | 171 } |
| 218 | 172 |
| 219 // Valid "cmd" value. | 173 // Valid "cmd" value. |
| 220 { | 174 { |
| 221 ProductState state; | 175 ProductState state; |
| 222 LONG result = clients_.WriteValue(google_update::kRegRenameCmdField, | 176 LONG result = clients_.WriteValue(google_update::kRegRenameCmdField, |
| 223 L"spam.exe --spamalot"); | 177 L"spam.exe --spamalot"); |
| 224 EXPECT_TRUE(result == ERROR_SUCCESS || result == ERROR_FILE_NOT_FOUND); | 178 EXPECT_TRUE(result == ERROR_SUCCESS || result == ERROR_FILE_NOT_FOUND); |
| 225 EXPECT_TRUE(state.Initialize(system_install_, dist_)); | 179 EXPECT_TRUE(state.Initialize(system_install_)); |
| 226 EXPECT_EQ(L"spam.exe --spamalot", state.rename_cmd()); | 180 EXPECT_EQ(L"spam.exe --spamalot", state.rename_cmd()); |
| 227 } | 181 } |
| 228 } | 182 } |
| 229 | 183 |
| 230 // Test extraction of the "ap" value from the ClientState key. | 184 // Test extraction of the "ap" value from the ClientState key. |
| 231 TEST_F(ProductStateTest, InitializeChannelInfo) { | 185 TEST_F(ProductStateTest, InitializeChannelInfo) { |
| 232 MinimallyInstallProduct(L"10.0.1.1"); | 186 MinimallyInstallProduct(L"10.0.1.1"); |
| 233 | 187 |
| 234 // No "ap" value. | 188 // No "ap" value. |
| 235 { | 189 { |
| 236 ProductState state; | 190 ProductState state; |
| 237 LONG result = client_state_.DeleteValue(google_update::kRegApField); | 191 LONG result = client_state_.DeleteValue(google_update::kRegApField); |
| 238 EXPECT_TRUE(result == ERROR_SUCCESS || result == ERROR_FILE_NOT_FOUND); | 192 EXPECT_TRUE(result == ERROR_SUCCESS || result == ERROR_FILE_NOT_FOUND); |
| 239 EXPECT_TRUE(state.Initialize(system_install_, dist_)); | 193 EXPECT_TRUE(state.Initialize(system_install_)); |
| 240 EXPECT_TRUE(state.channel().value().empty()); | 194 EXPECT_TRUE(state.channel().value().empty()); |
| 241 } | 195 } |
| 242 | 196 |
| 243 // Empty "ap" value. | 197 // Empty "ap" value. |
| 244 { | 198 { |
| 245 ProductState state; | 199 ProductState state; |
| 246 LONG result = client_state_.WriteValue(google_update::kRegApField, L""); | 200 LONG result = client_state_.WriteValue(google_update::kRegApField, L""); |
| 247 EXPECT_TRUE(result == ERROR_SUCCESS || result == ERROR_FILE_NOT_FOUND); | 201 EXPECT_TRUE(result == ERROR_SUCCESS || result == ERROR_FILE_NOT_FOUND); |
| 248 EXPECT_TRUE(state.Initialize(system_install_, dist_)); | 202 EXPECT_TRUE(state.Initialize(system_install_)); |
| 249 EXPECT_TRUE(state.channel().value().empty()); | 203 EXPECT_TRUE(state.channel().value().empty()); |
| 250 } | 204 } |
| 251 | 205 |
| 252 // Valid "ap" value. | 206 // Valid "ap" value. |
| 253 { | 207 { |
| 254 ProductState state; | 208 ProductState state; |
| 255 LONG result = client_state_.WriteValue(google_update::kRegApField, L"spam"); | 209 LONG result = client_state_.WriteValue(google_update::kRegApField, L"spam"); |
| 256 EXPECT_TRUE(result == ERROR_SUCCESS || result == ERROR_FILE_NOT_FOUND); | 210 EXPECT_TRUE(result == ERROR_SUCCESS || result == ERROR_FILE_NOT_FOUND); |
| 257 EXPECT_TRUE(state.Initialize(system_install_, dist_)); | 211 EXPECT_TRUE(state.Initialize(system_install_)); |
| 258 EXPECT_EQ(L"spam", state.channel().value()); | 212 EXPECT_EQ(L"spam", state.channel().value()); |
| 259 } | 213 } |
| 260 } | 214 } |
| 261 | 215 |
| 262 // Test extraction of the uninstall command and arguments from the ClientState | 216 // Test extraction of the uninstall command and arguments from the ClientState |
| 263 // key. | 217 // key. |
| 264 TEST_F(ProductStateTest, InitializeUninstallCommand) { | 218 TEST_F(ProductStateTest, InitializeUninstallCommand) { |
| 265 MinimallyInstallProduct(L"10.0.1.1"); | 219 MinimallyInstallProduct(L"10.0.1.1"); |
| 266 | 220 |
| 267 // No uninstall command. | 221 // No uninstall command. |
| 268 { | 222 { |
| 269 ProductState state; | 223 ProductState state; |
| 270 ApplyUninstallCommand(NULL, NULL); | 224 ApplyUninstallCommand(NULL, NULL); |
| 271 EXPECT_TRUE(state.Initialize(system_install_, dist_)); | 225 EXPECT_TRUE(state.Initialize(system_install_)); |
| 272 EXPECT_TRUE(state.GetSetupPath().empty()); | 226 EXPECT_TRUE(state.GetSetupPath().empty()); |
| 273 EXPECT_TRUE(state.uninstall_command().GetCommandLineString().empty()); | 227 EXPECT_TRUE(state.uninstall_command().GetCommandLineString().empty()); |
| 274 EXPECT_TRUE(state.uninstall_command().GetSwitches().empty()); | 228 EXPECT_TRUE(state.uninstall_command().GetSwitches().empty()); |
| 275 } | 229 } |
| 276 | 230 |
| 277 // Empty values. | 231 // Empty values. |
| 278 { | 232 { |
| 279 ProductState state; | 233 ProductState state; |
| 280 ApplyUninstallCommand(L"", L""); | 234 ApplyUninstallCommand(L"", L""); |
| 281 EXPECT_TRUE(state.Initialize(system_install_, dist_)); | 235 EXPECT_TRUE(state.Initialize(system_install_)); |
| 282 EXPECT_TRUE(state.GetSetupPath().empty()); | 236 EXPECT_TRUE(state.GetSetupPath().empty()); |
| 283 EXPECT_TRUE(state.uninstall_command().GetCommandLineString().empty()); | 237 EXPECT_TRUE(state.uninstall_command().GetCommandLineString().empty()); |
| 284 EXPECT_TRUE(state.uninstall_command().GetSwitches().empty()); | 238 EXPECT_TRUE(state.uninstall_command().GetSwitches().empty()); |
| 285 } | 239 } |
| 286 | 240 |
| 287 // Uninstall command without exe. | 241 // Uninstall command without exe. |
| 288 { | 242 { |
| 289 ProductState state; | 243 ProductState state; |
| 290 ApplyUninstallCommand(NULL, L"--uninstall"); | 244 ApplyUninstallCommand(NULL, L"--uninstall"); |
| 291 EXPECT_TRUE(state.Initialize(system_install_, dist_)); | 245 EXPECT_TRUE(state.Initialize(system_install_)); |
| 292 EXPECT_TRUE(state.GetSetupPath().empty()); | 246 EXPECT_TRUE(state.GetSetupPath().empty()); |
| 293 EXPECT_EQ(L" --uninstall", | 247 EXPECT_EQ(L" --uninstall", |
| 294 state.uninstall_command().GetCommandLineString()); | 248 state.uninstall_command().GetCommandLineString()); |
| 295 EXPECT_EQ(1U, state.uninstall_command().GetSwitches().size()); | 249 EXPECT_EQ(1U, state.uninstall_command().GetSwitches().size()); |
| 296 } | 250 } |
| 297 | 251 |
| 298 // Uninstall command without args. | 252 // Uninstall command without args. |
| 299 { | 253 { |
| 300 ProductState state; | 254 ProductState state; |
| 301 ApplyUninstallCommand(L"setup.exe", NULL); | 255 ApplyUninstallCommand(L"setup.exe", NULL); |
| 302 EXPECT_TRUE(state.Initialize(system_install_, dist_)); | 256 EXPECT_TRUE(state.Initialize(system_install_)); |
| 303 EXPECT_EQ(L"setup.exe", state.GetSetupPath().value()); | 257 EXPECT_EQ(L"setup.exe", state.GetSetupPath().value()); |
| 304 EXPECT_EQ(L"setup.exe", state.uninstall_command().GetCommandLineString()); | 258 EXPECT_EQ(L"setup.exe", state.uninstall_command().GetCommandLineString()); |
| 305 EXPECT_TRUE(state.uninstall_command().GetSwitches().empty()); | 259 EXPECT_TRUE(state.uninstall_command().GetSwitches().empty()); |
| 306 } | 260 } |
| 307 | 261 |
| 308 // Uninstall command with exe that requires quoting. | 262 // Uninstall command with exe that requires quoting. |
| 309 { | 263 { |
| 310 ProductState state; | 264 ProductState state; |
| 311 ApplyUninstallCommand(L"set up.exe", NULL); | 265 ApplyUninstallCommand(L"set up.exe", NULL); |
| 312 EXPECT_TRUE(state.Initialize(system_install_, dist_)); | 266 EXPECT_TRUE(state.Initialize(system_install_)); |
| 313 EXPECT_EQ(L"set up.exe", state.GetSetupPath().value()); | 267 EXPECT_EQ(L"set up.exe", state.GetSetupPath().value()); |
| 314 EXPECT_EQ(L"\"set up.exe\"", | 268 EXPECT_EQ(L"\"set up.exe\"", |
| 315 state.uninstall_command().GetCommandLineString()); | 269 state.uninstall_command().GetCommandLineString()); |
| 316 EXPECT_TRUE(state.uninstall_command().GetSwitches().empty()); | 270 EXPECT_TRUE(state.uninstall_command().GetSwitches().empty()); |
| 317 } | 271 } |
| 318 | 272 |
| 319 // Uninstall command with both exe and args. | 273 // Uninstall command with both exe and args. |
| 320 { | 274 { |
| 321 ProductState state; | 275 ProductState state; |
| 322 ApplyUninstallCommand(L"setup.exe", L"--uninstall"); | 276 ApplyUninstallCommand(L"setup.exe", L"--uninstall"); |
| 323 EXPECT_TRUE(state.Initialize(system_install_, dist_)); | 277 EXPECT_TRUE(state.Initialize(system_install_)); |
| 324 EXPECT_EQ(L"setup.exe", state.GetSetupPath().value()); | 278 EXPECT_EQ(L"setup.exe", state.GetSetupPath().value()); |
| 325 EXPECT_EQ(L"setup.exe --uninstall", | 279 EXPECT_EQ(L"setup.exe --uninstall", |
| 326 state.uninstall_command().GetCommandLineString()); | 280 state.uninstall_command().GetCommandLineString()); |
| 327 EXPECT_EQ(1U, state.uninstall_command().GetSwitches().size()); | 281 EXPECT_EQ(1U, state.uninstall_command().GetSwitches().size()); |
| 328 } | 282 } |
| 329 } | 283 } |
| 330 | 284 |
| 331 // Test extraction of the msi marker from the ClientState key. | 285 // Test extraction of the msi marker from the ClientState key. |
| 332 TEST_F(ProductStateTest, InitializeMsi) { | 286 TEST_F(ProductStateTest, InitializeMsi) { |
| 333 MinimallyInstallProduct(L"10.0.1.1"); | 287 MinimallyInstallProduct(L"10.0.1.1"); |
| 334 | 288 |
| 335 // No msi marker. | 289 // No msi marker. |
| 336 { | 290 { |
| 337 ProductState state; | 291 ProductState state; |
| 338 LONG result = client_state_.DeleteValue(google_update::kRegMSIField); | 292 LONG result = client_state_.DeleteValue(google_update::kRegMSIField); |
| 339 EXPECT_TRUE(result == ERROR_SUCCESS || result == ERROR_FILE_NOT_FOUND); | 293 EXPECT_TRUE(result == ERROR_SUCCESS || result == ERROR_FILE_NOT_FOUND); |
| 340 EXPECT_TRUE(state.Initialize(system_install_, dist_)); | 294 EXPECT_TRUE(state.Initialize(system_install_)); |
| 341 EXPECT_FALSE(state.is_msi()); | 295 EXPECT_FALSE(state.is_msi()); |
| 342 } | 296 } |
| 343 | 297 |
| 344 // Msi marker set to zero. | 298 // Msi marker set to zero. |
| 345 { | 299 { |
| 346 ProductState state; | 300 ProductState state; |
| 347 EXPECT_EQ(ERROR_SUCCESS, | 301 EXPECT_EQ(ERROR_SUCCESS, |
| 348 client_state_.WriteValue(google_update::kRegMSIField, | 302 client_state_.WriteValue(google_update::kRegMSIField, |
| 349 static_cast<DWORD>(0))); | 303 static_cast<DWORD>(0))); |
| 350 EXPECT_TRUE(state.Initialize(system_install_, dist_)); | 304 EXPECT_TRUE(state.Initialize(system_install_)); |
| 351 EXPECT_FALSE(state.is_msi()); | 305 EXPECT_FALSE(state.is_msi()); |
| 352 } | 306 } |
| 353 | 307 |
| 354 // Msi marker set to one. | 308 // Msi marker set to one. |
| 355 { | 309 { |
| 356 ProductState state; | 310 ProductState state; |
| 357 EXPECT_EQ(ERROR_SUCCESS, | 311 EXPECT_EQ(ERROR_SUCCESS, |
| 358 client_state_.WriteValue(google_update::kRegMSIField, | 312 client_state_.WriteValue(google_update::kRegMSIField, |
| 359 static_cast<DWORD>(1))); | 313 static_cast<DWORD>(1))); |
| 360 EXPECT_TRUE(state.Initialize(system_install_, dist_)); | 314 EXPECT_TRUE(state.Initialize(system_install_)); |
| 361 EXPECT_TRUE(state.is_msi()); | 315 EXPECT_TRUE(state.is_msi()); |
| 362 } | 316 } |
| 363 | 317 |
| 364 // Msi marker set to a bogus DWORD. | 318 // Msi marker set to a bogus DWORD. |
| 365 { | 319 { |
| 366 ProductState state; | 320 ProductState state; |
| 367 EXPECT_EQ(ERROR_SUCCESS, | 321 EXPECT_EQ(ERROR_SUCCESS, |
| 368 client_state_.WriteValue(google_update::kRegMSIField, | 322 client_state_.WriteValue(google_update::kRegMSIField, |
| 369 static_cast<DWORD>(47))); | 323 static_cast<DWORD>(47))); |
| 370 EXPECT_TRUE(state.Initialize(system_install_, dist_)); | 324 EXPECT_TRUE(state.Initialize(system_install_)); |
| 371 EXPECT_TRUE(state.is_msi()); | 325 EXPECT_TRUE(state.is_msi()); |
| 372 } | 326 } |
| 373 | 327 |
| 374 // Msi marker set to a bogus string. | 328 // Msi marker set to a bogus string. |
| 375 { | 329 { |
| 376 ProductState state; | 330 ProductState state; |
| 377 EXPECT_EQ(ERROR_SUCCESS, | 331 EXPECT_EQ(ERROR_SUCCESS, |
| 378 client_state_.WriteValue(google_update::kRegMSIField, | 332 client_state_.WriteValue(google_update::kRegMSIField, |
| 379 L"bogus!")); | 333 L"bogus!")); |
| 380 EXPECT_TRUE(state.Initialize(system_install_, dist_)); | 334 EXPECT_TRUE(state.Initialize(system_install_)); |
| 381 EXPECT_FALSE(state.is_msi()); | 335 EXPECT_FALSE(state.is_msi()); |
| 382 } | 336 } |
| 383 } | 337 } |
| 384 | 338 |
| 385 // Test detection of multi-install. | 339 // Test detection of multi-install. |
| 386 TEST_F(ProductStateTest, InitializeMultiInstall) { | 340 TEST_F(ProductStateTest, InitializeMultiInstall) { |
| 387 MinimallyInstallProduct(L"10.0.1.1"); | 341 MinimallyInstallProduct(L"10.0.1.1"); |
| 388 | 342 |
| 389 // No uninstall command means single install. | 343 // No uninstall command means single install. |
| 390 { | 344 { |
| 391 ProductState state; | 345 ProductState state; |
| 392 ApplyUninstallCommand(NULL, NULL); | 346 ApplyUninstallCommand(NULL, NULL); |
| 393 EXPECT_TRUE(state.Initialize(system_install_, dist_)); | 347 EXPECT_TRUE(state.Initialize(system_install_)); |
| 394 EXPECT_FALSE(state.is_multi_install()); | 348 EXPECT_FALSE(state.is_multi_install()); |
| 395 } | 349 } |
| 396 | 350 |
| 397 // Uninstall command without --multi-install is single install. | 351 // Uninstall command without --multi-install is single install. |
| 398 { | 352 { |
| 399 ProductState state; | 353 ProductState state; |
| 400 ApplyUninstallCommand(L"setup.exe", L"--uninstall"); | 354 ApplyUninstallCommand(L"setup.exe", L"--uninstall"); |
| 401 EXPECT_TRUE(state.Initialize(system_install_, dist_)); | 355 EXPECT_TRUE(state.Initialize(system_install_)); |
| 402 EXPECT_FALSE(state.is_multi_install()); | 356 EXPECT_FALSE(state.is_multi_install()); |
| 403 } | 357 } |
| 404 | 358 |
| 405 // Uninstall command with --multi-install is multi install. | 359 // Uninstall command with --multi-install is multi install. |
| 406 { | 360 { |
| 407 ProductState state; | 361 ProductState state; |
| 408 ApplyUninstallCommand(L"setup.exe", | 362 ApplyUninstallCommand(L"setup.exe", |
| 409 L"--uninstall --chrome --multi-install"); | 363 L"--uninstall --chrome --multi-install"); |
| 410 EXPECT_TRUE(state.Initialize(system_install_, dist_)); | 364 EXPECT_TRUE(state.Initialize(system_install_)); |
| 411 EXPECT_TRUE(state.is_multi_install()); | 365 EXPECT_TRUE(state.is_multi_install()); |
| 412 } | 366 } |
| 413 } | 367 } |
| 368 | |
| 369 } // namespace installer | |
| OLD | NEW |