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 <map> |
| 6 |
5 #include "base/command_line.h" | 7 #include "base/command_line.h" |
6 #include "base/file_path.h" | 8 #include "base/file_path.h" |
7 #include "base/logging.h" | 9 #include "base/logging.h" |
8 #include "base/ref_counted.h" | 10 #include "base/ref_counted.h" |
9 #include "base/version.h" | 11 #include "base/version.h" |
10 #include "chrome/common/chrome_constants.h" | 12 #include "chrome/common/chrome_constants.h" |
11 #include "chrome/installer/util/channel_info.h" | 13 #include "chrome/installer/util/channel_info.h" |
12 #include "chrome/installer/util/helper.h" | 14 #include "chrome/installer/util/helper.h" |
13 #include "chrome/installer/util/installation_state.h" | 15 #include "chrome/installer/util/installation_state.h" |
14 #include "chrome/installer/util/installation_validator.h" | 16 #include "chrome/installer/util/installation_validator.h" |
15 #include "testing/gmock/include/gmock/gmock.h" | 17 #include "testing/gmock/include/gmock/gmock.h" |
16 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
17 | 19 |
18 using installer::ChannelInfo; | 20 using installer::ChannelInfo; |
19 using installer::InstallationValidator; | 21 using installer::InstallationValidator; |
20 using installer::InstallationState; | 22 using installer::InstallationState; |
| 23 using installer::AppCommand; |
21 using installer::ProductState; | 24 using installer::ProductState; |
22 using testing::_; | 25 using testing::_; |
23 using testing::StrictMock; | 26 using testing::StrictMock; |
| 27 using testing::Values; |
24 | 28 |
25 namespace { | 29 namespace { |
26 | 30 |
27 enum Channel { | 31 enum Channel { |
28 STABLE_CHANNEL, | 32 STABLE_CHANNEL, |
29 BETA_CHANNEL, | 33 BETA_CHANNEL, |
30 DEV_CHANNEL | 34 DEV_CHANNEL |
31 }; | 35 }; |
32 | 36 |
33 enum PackageType { | 37 enum PackageType { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 class FakeProductState : public ProductState { | 72 class FakeProductState : public ProductState { |
69 public: | 73 public: |
70 void Clear(); | 74 void Clear(); |
71 void SetChannel(const wchar_t* base, int channel_modifiers); | 75 void SetChannel(const wchar_t* base, int channel_modifiers); |
72 void SetVersion(const char* version); | 76 void SetVersion(const char* version); |
73 void SetUninstallCommand(BrowserDistribution::Type dist_type, | 77 void SetUninstallCommand(BrowserDistribution::Type dist_type, |
74 Level install_level, | 78 Level install_level, |
75 const char* version, | 79 const char* version, |
76 int channel_modifiers, | 80 int channel_modifiers, |
77 Vehicle vehicle); | 81 Vehicle vehicle); |
| 82 void AddQuickEnableCfCommand(BrowserDistribution::Type dist_type, |
| 83 Level install_level, |
| 84 const char* version, |
| 85 int channel_modifiers); |
| 86 void RemoveQuickEnableCfCommand(BrowserDistribution::Type dist_type); |
78 void set_multi_install(bool is_multi_install) { | 87 void set_multi_install(bool is_multi_install) { |
79 multi_install_ = is_multi_install; | 88 multi_install_ = is_multi_install; |
80 } | 89 } |
| 90 installer::AppCommands& commands() { return commands_; } |
81 | 91 |
82 protected: | 92 protected: |
83 struct ChannelMethodForModifier { | 93 struct ChannelMethodForModifier { |
84 ChannelModifier modifier; | 94 ChannelModifier modifier; |
85 bool (ChannelInfo::*method)(bool value); | 95 bool (ChannelInfo::*method)(bool value); |
86 }; | 96 }; |
87 | 97 |
| 98 static FilePath GetSetupExePath( |
| 99 BrowserDistribution::Type dist_type, |
| 100 Level install_level, |
| 101 const char* version, |
| 102 int channel_modifiers); |
| 103 |
88 static const ChannelMethodForModifier kChannelMethods[]; | 104 static const ChannelMethodForModifier kChannelMethods[]; |
89 }; | 105 }; |
90 | 106 |
91 class FakeInstallationState : public InstallationState { | 107 class FakeInstallationState : public InstallationState { |
92 public: | 108 public: |
93 void SetProductState(BrowserDistribution::Type type, | 109 void SetProductState(BrowserDistribution::Type type, |
94 Level install_level, | 110 Level install_level, |
95 const ProductState& product) { | 111 const ProductState& product) { |
96 GetProducts(install_level)[IndexFromDistType(type)].CopyFrom(product); | 112 GetProducts(install_level)[IndexFromDistType(type)].CopyFrom(product); |
97 } | 113 } |
98 | 114 |
99 protected: | 115 protected: |
100 ProductState* GetProducts(Level install_level) { | 116 ProductState* GetProducts(Level install_level) { |
101 return install_level == USER_LEVEL ? user_products_ : system_products_; | 117 return install_level == USER_LEVEL ? user_products_ : system_products_; |
102 } | 118 } |
103 }; | 119 }; |
104 | 120 |
105 // static | 121 // static |
106 const FakeProductState::ChannelMethodForModifier | 122 const FakeProductState::ChannelMethodForModifier |
107 FakeProductState::kChannelMethods[] = { | 123 FakeProductState::kChannelMethods[] = { |
108 { CM_MULTI, &ChannelInfo::SetMultiInstall }, | 124 { CM_MULTI, &ChannelInfo::SetMultiInstall }, |
109 { CM_CHROME, &ChannelInfo::SetChrome }, | 125 { CM_CHROME, &ChannelInfo::SetChrome }, |
110 { CM_CHROME_FRAME, &ChannelInfo::SetChromeFrame }, | 126 { CM_CHROME_FRAME, &ChannelInfo::SetChromeFrame }, |
111 { CM_READY_MODE, &ChannelInfo::SetReadyMode }, | 127 { CM_READY_MODE, &ChannelInfo::SetReadyMode }, |
112 { CM_FULL, &ChannelInfo::SetFullSuffix } | 128 { CM_FULL, &ChannelInfo::SetFullSuffix } |
113 }; | 129 }; |
114 | 130 |
| 131 // static |
| 132 FilePath FakeProductState::GetSetupExePath(BrowserDistribution::Type dist_type, |
| 133 Level install_level, |
| 134 const char* version, |
| 135 int channel_modifiers) { |
| 136 const bool is_multi_install = (channel_modifiers & CM_MULTI) != 0; |
| 137 FilePath setup_path = installer::GetChromeInstallPath( |
| 138 install_level == SYSTEM_LEVEL, |
| 139 BrowserDistribution::GetSpecificDistribution(is_multi_install ? |
| 140 BrowserDistribution::CHROME_BINARIES : dist_type)); |
| 141 return setup_path |
| 142 .AppendASCII(version) |
| 143 .Append(installer::kInstallerDir) |
| 144 .Append(installer::kSetupExe); |
| 145 } |
| 146 |
115 void FakeProductState::Clear() { | 147 void FakeProductState::Clear() { |
116 channel_.set_value(std::wstring()); | 148 channel_.set_value(std::wstring()); |
117 version_.reset(); | 149 version_.reset(); |
118 old_version_.reset(); | 150 old_version_.reset(); |
119 rename_cmd_.clear(); | 151 rename_cmd_.clear(); |
120 uninstall_command_ = CommandLine(CommandLine::NO_PROGRAM); | 152 uninstall_command_ = CommandLine(CommandLine::NO_PROGRAM); |
| 153 commands_.Clear(); |
121 msi_ = false; | 154 msi_ = false; |
122 multi_install_ = false; | 155 multi_install_ = false; |
123 } | 156 } |
124 | 157 |
125 // Sets the channel_ member of this instance according to a base channel value | 158 // Sets the channel_ member of this instance according to a base channel value |
126 // and a set of modifiers. | 159 // and a set of modifiers. |
127 void FakeProductState::SetChannel(const wchar_t* base, int channel_modifiers) { | 160 void FakeProductState::SetChannel(const wchar_t* base, int channel_modifiers) { |
128 channel_.set_value(base); | 161 channel_.set_value(base); |
129 for (size_t i = 0; i < arraysize(kChannelMethods); ++i) { | 162 for (size_t i = 0; i < arraysize(kChannelMethods); ++i) { |
130 if ((channel_modifiers & kChannelMethods[i].modifier) != 0) | 163 if ((channel_modifiers & kChannelMethods[i].modifier) != 0) |
131 (channel_.*kChannelMethods[i].method)(true); | 164 (channel_.*kChannelMethods[i].method)(true); |
132 } | 165 } |
133 } | 166 } |
134 | 167 |
135 void FakeProductState::SetVersion(const char* version) { | 168 void FakeProductState::SetVersion(const char* version) { |
136 version_.reset( | 169 version_.reset( |
137 version == NULL ? NULL : Version::GetVersionFromString(version)); | 170 version == NULL ? NULL : Version::GetVersionFromString(version)); |
138 } | 171 } |
139 | 172 |
140 // Sets the uninstall command for this object. | 173 // Sets the uninstall command for this object. |
141 void FakeProductState::SetUninstallCommand(BrowserDistribution::Type dist_type, | 174 void FakeProductState::SetUninstallCommand(BrowserDistribution::Type dist_type, |
142 Level install_level, | 175 Level install_level, |
143 const char* version, | 176 const char* version, |
144 int channel_modifiers, | 177 int channel_modifiers, |
145 Vehicle vehicle) { | 178 Vehicle vehicle) { |
146 DCHECK(version); | 179 DCHECK(version); |
147 | 180 |
148 const bool is_multi_install = (channel_modifiers & CM_MULTI) != 0; | 181 const bool is_multi_install = (channel_modifiers & CM_MULTI) != 0; |
149 FilePath setup_path = installer::GetChromeInstallPath( | 182 uninstall_command_ = CommandLine(GetSetupExePath(dist_type, install_level, |
150 install_level == SYSTEM_LEVEL, | 183 version, channel_modifiers)); |
151 BrowserDistribution::GetSpecificDistribution(is_multi_install ? | |
152 BrowserDistribution::CHROME_BINARIES : dist_type)); | |
153 setup_path = setup_path | |
154 .AppendASCII(version) | |
155 .Append(installer::kInstallerDir) | |
156 .Append(installer::kSetupExe); | |
157 uninstall_command_ = CommandLine(setup_path); | |
158 uninstall_command_.AppendSwitch(installer::switches::kUninstall); | 184 uninstall_command_.AppendSwitch(installer::switches::kUninstall); |
159 if (install_level == SYSTEM_LEVEL) | 185 if (install_level == SYSTEM_LEVEL) |
160 uninstall_command_.AppendSwitch(installer::switches::kSystemLevel); | 186 uninstall_command_.AppendSwitch(installer::switches::kSystemLevel); |
161 if (is_multi_install) { | 187 if (is_multi_install) { |
162 uninstall_command_.AppendSwitch(installer::switches::kMultiInstall); | 188 uninstall_command_.AppendSwitch(installer::switches::kMultiInstall); |
163 if (dist_type == BrowserDistribution::CHROME_BROWSER) { | 189 if (dist_type == BrowserDistribution::CHROME_BROWSER) { |
164 uninstall_command_.AppendSwitch(installer::switches::kChrome); | 190 uninstall_command_.AppendSwitch(installer::switches::kChrome); |
165 if ((channel_modifiers & CM_READY_MODE) != 0) { | 191 if ((channel_modifiers & CM_READY_MODE) != 0) { |
166 uninstall_command_.AppendSwitch(installer::switches::kChromeFrame); | 192 uninstall_command_.AppendSwitch(installer::switches::kChromeFrame); |
167 uninstall_command_.AppendSwitch( | 193 uninstall_command_.AppendSwitch( |
168 installer::switches::kChromeFrameReadyMode); | 194 installer::switches::kChromeFrameReadyMode); |
169 } | 195 } |
| 196 } else if (dist_type == BrowserDistribution::CHROME_FRAME) { |
| 197 uninstall_command_.AppendSwitch(installer::switches::kChromeFrame); |
| 198 if ((channel_modifiers & CM_READY_MODE) != 0) { |
| 199 uninstall_command_.AppendSwitch( |
| 200 installer::switches::kChromeFrameReadyMode); |
| 201 } |
170 } | 202 } |
171 } else if (dist_type == BrowserDistribution::CHROME_FRAME) { | 203 } else if (dist_type == BrowserDistribution::CHROME_FRAME) { |
172 uninstall_command_.AppendSwitch(installer::switches::kChromeFrame); | 204 uninstall_command_.AppendSwitch(installer::switches::kChromeFrame); |
173 } | 205 } |
174 if (vehicle == MSI) | 206 if (vehicle == MSI) |
175 uninstall_command_.AppendSwitch(installer::switches::kMsi); | 207 uninstall_command_.AppendSwitch(installer::switches::kMsi); |
176 } | 208 } |
177 | 209 |
178 // Populates |chrome_state| with the state of a valid Chrome browser | 210 // Adds the "quick-enable-cf" Google Update product command. |
179 // installation. |channel_modifiers|, a field of bits defined by enum | 211 void FakeProductState::AddQuickEnableCfCommand( |
180 // ChannelModifier, dictate properties of the installation (multi-install, | 212 BrowserDistribution::Type dist_type, |
181 // ready-mode, etc). | 213 Level install_level, |
182 void MakeChromeState(Level install_level, | 214 const char* version, |
183 Channel channel, | 215 int channel_modifiers) { |
184 int channel_modifiers, | 216 DCHECK_EQ(dist_type, BrowserDistribution::CHROME_BINARIES); |
185 Vehicle vehicle, | 217 DCHECK_NE(channel_modifiers & CM_MULTI, 0); |
186 FakeProductState* chrome_state) { | 218 |
187 chrome_state->Clear(); | 219 CommandLine cmd_line(GetSetupExePath(dist_type, install_level, version, |
188 chrome_state->SetChannel(kChromeChannels[channel], channel_modifiers); | 220 channel_modifiers)); |
189 chrome_state->SetVersion(chrome::kChromeVersion); | 221 cmd_line.AppendSwitch(installer::switches::kMultiInstall); |
190 chrome_state->SetUninstallCommand(BrowserDistribution::CHROME_BROWSER, | 222 if (install_level == SYSTEM_LEVEL) |
191 install_level, chrome::kChromeVersion, | 223 cmd_line.AppendSwitch(installer::switches::kSystemLevel); |
192 channel_modifiers, vehicle); | 224 cmd_line.AppendSwitch(installer::switches::kChromeFrameQuickEnable); |
193 chrome_state->set_multi_install((channel_modifiers & CM_MULTI) != 0); | 225 commands_.Set(installer::kCmdQuickEnableCf, |
| 226 AppCommand(cmd_line.command_line_string(), true, true)); |
| 227 } |
| 228 |
| 229 // Removes the "quick-enable-cf" Google Update product command. |
| 230 void FakeProductState::RemoveQuickEnableCfCommand( |
| 231 BrowserDistribution::Type dist_type) { |
| 232 DCHECK_EQ(dist_type, BrowserDistribution::CHROME_BINARIES); |
| 233 |
| 234 commands_.Remove(installer::kCmdQuickEnableCf); |
194 } | 235 } |
195 | 236 |
196 } // namespace | 237 } // namespace |
197 | 238 |
198 // Fixture for testing the InstallationValidator. Errors logged by the | 239 // Fixture for testing the InstallationValidator. Errors logged by the |
199 // validator are sent to an optional mock recipient (see | 240 // validator are sent to an optional mock recipient (see |
200 // set_validation_error_recipient) upon which expectations can be placed. | 241 // set_validation_error_recipient) upon which expectations can be placed. |
201 class InstallationValidatorTest : public testing::Test { | 242 class InstallationValidatorTest |
| 243 : public testing::TestWithParam<InstallationValidator::InstallationType> { |
| 244 public: |
| 245 |
| 246 // These shouldn't need to be public, but there seems to be some interaction |
| 247 // with parameterized tests that requires it. |
| 248 static void SetUpTestCase(); |
| 249 static void TearDownTestCase(); |
| 250 |
| 251 // Returns the multi channel modifiers for a given installation type. |
| 252 static int GetChannelModifiers(InstallationValidator::InstallationType type); |
| 253 |
202 protected: | 254 protected: |
| 255 typedef std::map<InstallationValidator::InstallationType, int> |
| 256 InstallationTypeToModifiers; |
| 257 |
203 class ValidationErrorRecipient { | 258 class ValidationErrorRecipient { |
204 public: | 259 public: |
205 virtual ~ValidationErrorRecipient() { } | 260 virtual ~ValidationErrorRecipient() { } |
206 virtual void ReceiveValidationError(const char* file, | 261 virtual void ReceiveValidationError(const char* file, |
207 int line, | 262 int line, |
208 const char* message) = 0; | 263 const char* message) = 0; |
209 }; | 264 }; |
210 class MockValidationErrorRecipient : public ValidationErrorRecipient { | 265 class MockValidationErrorRecipient : public ValidationErrorRecipient { |
211 public: | 266 public: |
212 MOCK_METHOD3(ReceiveValidationError, void(const char* file, | 267 MOCK_METHOD3(ReceiveValidationError, void(const char* file, |
213 int line, | 268 int line, |
214 const char* message)); | 269 const char* message)); |
215 }; | 270 }; |
216 | 271 |
217 static void SetUpTestCase(); | 272 protected: |
218 static void TearDownTestCase(); | |
219 static bool HandleLogMessage(int severity, | 273 static bool HandleLogMessage(int severity, |
220 const char* file, | 274 const char* file, |
221 int line, | 275 int line, |
222 size_t message_start, | 276 size_t message_start, |
223 const std::string& str); | 277 const std::string& str); |
224 static void set_validation_error_recipient( | 278 static void set_validation_error_recipient( |
225 ValidationErrorRecipient* recipient); | 279 ValidationErrorRecipient* recipient); |
226 | 280 static void MakeProductState( |
| 281 BrowserDistribution::Type prod_type, |
| 282 InstallationValidator::InstallationType inst_type, |
| 283 Level install_level, |
| 284 Channel channel, |
| 285 Vehicle vehicle, |
| 286 FakeProductState* state); |
| 287 static void MakeMachineState( |
| 288 InstallationValidator::InstallationType inst_type, |
| 289 Level install_level, |
| 290 Channel channel, |
| 291 Vehicle vehicle, |
| 292 FakeInstallationState* state); |
227 virtual void TearDown(); | 293 virtual void TearDown(); |
228 | 294 |
229 static logging::LogMessageHandlerFunction old_log_message_handler_; | 295 static logging::LogMessageHandlerFunction old_log_message_handler_; |
230 static ValidationErrorRecipient* validation_error_recipient_; | 296 static ValidationErrorRecipient* validation_error_recipient_; |
| 297 static InstallationTypeToModifiers* type_to_modifiers_; |
231 }; | 298 }; |
232 | 299 |
233 // static | 300 // static |
234 logging::LogMessageHandlerFunction | 301 logging::LogMessageHandlerFunction |
235 InstallationValidatorTest::old_log_message_handler_ = NULL; | 302 InstallationValidatorTest::old_log_message_handler_ = NULL; |
236 | 303 |
237 // static | 304 // static |
238 InstallationValidatorTest::ValidationErrorRecipient* | 305 InstallationValidatorTest::ValidationErrorRecipient* |
239 InstallationValidatorTest::validation_error_recipient_ = NULL; | 306 InstallationValidatorTest::validation_error_recipient_ = NULL; |
240 | 307 |
241 // static | 308 // static |
| 309 InstallationValidatorTest::InstallationTypeToModifiers* |
| 310 InstallationValidatorTest::type_to_modifiers_ = NULL; |
| 311 |
| 312 // static |
| 313 int InstallationValidatorTest::GetChannelModifiers( |
| 314 InstallationValidator::InstallationType type) { |
| 315 DCHECK(type_to_modifiers_); |
| 316 DCHECK(type_to_modifiers_->find(type) != type_to_modifiers_->end()); |
| 317 |
| 318 return (*type_to_modifiers_)[type]; |
| 319 } |
| 320 |
| 321 // static |
242 void InstallationValidatorTest::SetUpTestCase() { | 322 void InstallationValidatorTest::SetUpTestCase() { |
| 323 DCHECK(type_to_modifiers_ == NULL); |
243 old_log_message_handler_ = logging::GetLogMessageHandler(); | 324 old_log_message_handler_ = logging::GetLogMessageHandler(); |
244 logging::SetLogMessageHandler(&HandleLogMessage); | 325 logging::SetLogMessageHandler(&HandleLogMessage); |
| 326 |
| 327 type_to_modifiers_ = new InstallationTypeToModifiers(); |
| 328 InstallationTypeToModifiers& ttm = *type_to_modifiers_; |
| 329 ttm[InstallationValidator::NO_PRODUCTS] = 0; |
| 330 ttm[InstallationValidator::CHROME_SINGLE] = 0; |
| 331 ttm[InstallationValidator::CHROME_MULTI] = CM_MULTI | CM_CHROME; |
| 332 ttm[InstallationValidator::CHROME_FRAME_SINGLE] = 0; |
| 333 ttm[InstallationValidator::CHROME_FRAME_SINGLE_CHROME_SINGLE] = 0; |
| 334 ttm[InstallationValidator::CHROME_FRAME_SINGLE_CHROME_MULTI] = |
| 335 CM_MULTI | CM_CHROME; |
| 336 ttm[InstallationValidator::CHROME_FRAME_MULTI] = CM_MULTI | CM_CHROME_FRAME; |
| 337 ttm[InstallationValidator::CHROME_FRAME_MULTI_CHROME_MULTI] = |
| 338 CM_MULTI | CM_CHROME_FRAME | CM_CHROME; |
| 339 ttm[InstallationValidator::CHROME_FRAME_READY_MODE_CHROME_MULTI] = |
| 340 CM_MULTI | CM_CHROME_FRAME | CM_CHROME | CM_READY_MODE; |
245 } | 341 } |
246 | 342 |
247 // static | 343 // static |
248 void InstallationValidatorTest::TearDownTestCase() { | 344 void InstallationValidatorTest::TearDownTestCase() { |
249 logging::SetLogMessageHandler(old_log_message_handler_); | 345 logging::SetLogMessageHandler(old_log_message_handler_); |
250 old_log_message_handler_ = NULL; | 346 old_log_message_handler_ = NULL; |
| 347 |
| 348 delete type_to_modifiers_; |
| 349 type_to_modifiers_ = NULL; |
251 } | 350 } |
252 | 351 |
253 // static | 352 // static |
254 bool InstallationValidatorTest::HandleLogMessage(int severity, | 353 bool InstallationValidatorTest::HandleLogMessage(int severity, |
255 const char* file, | 354 const char* file, |
256 int line, | 355 int line, |
257 size_t message_start, | 356 size_t message_start, |
258 const std::string& str) { | 357 const std::string& str) { |
259 // All validation failures result in LOG(ERROR) | 358 // All validation failures result in LOG(ERROR) |
260 if (severity == logging::LOG_ERROR) { | 359 if (severity == logging::LOG_ERROR && !str.empty()) { |
| 360 // Remove the trailing newline, if present. |
| 361 std::streamsize message_length = str.size() - message_start; |
| 362 if (*str.rbegin() == '\n') |
| 363 --message_length; |
261 if (validation_error_recipient_ != NULL) { | 364 if (validation_error_recipient_ != NULL) { |
262 validation_error_recipient_->ReceiveValidationError( | 365 validation_error_recipient_->ReceiveValidationError( |
263 file, line, str.c_str() + message_start); | 366 file, line, str.substr(message_start, message_length).c_str()); |
264 } else { | 367 } else { |
265 // Fail the test if an error wasn't handled. | 368 // Fail the test if an error wasn't handled. |
266 ADD_FAILURE_AT(file, line) << (str.c_str() + message_start); | 369 ADD_FAILURE_AT(file, line) |
| 370 << base::StringPiece(str.c_str() + message_start, message_length); |
267 } | 371 } |
268 return true; | 372 return true; |
269 } | 373 } |
270 | 374 |
271 if (old_log_message_handler_ != NULL) | 375 if (old_log_message_handler_ != NULL) |
272 return (old_log_message_handler_)(severity, file, line, message_start, str); | 376 return (old_log_message_handler_)(severity, file, line, message_start, str); |
273 | 377 |
274 return false; | 378 return false; |
275 } | 379 } |
276 | 380 |
277 // static | 381 // static |
278 void InstallationValidatorTest::set_validation_error_recipient( | 382 void InstallationValidatorTest::set_validation_error_recipient( |
279 ValidationErrorRecipient* recipient) { | 383 ValidationErrorRecipient* recipient) { |
280 validation_error_recipient_ = recipient; | 384 validation_error_recipient_ = recipient; |
281 } | 385 } |
282 | 386 |
| 387 // static |
| 388 // Populates |state| with the state of a valid installation of product |
| 389 // |prod_type|. |inst_type| dictates properties of the installation |
| 390 // (multi-install, ready-mode, etc). |
| 391 void InstallationValidatorTest::MakeProductState( |
| 392 BrowserDistribution::Type prod_type, |
| 393 InstallationValidator::InstallationType inst_type, |
| 394 Level install_level, |
| 395 Channel channel, |
| 396 Vehicle vehicle, |
| 397 FakeProductState* state) { |
| 398 DCHECK(state); |
| 399 |
| 400 const bool is_multi_install = |
| 401 prod_type == BrowserDistribution::CHROME_BINARIES || |
| 402 (prod_type == BrowserDistribution::CHROME_BROWSER && |
| 403 (inst_type & InstallationValidator::ProductBits::CHROME_MULTI) != 0) || |
| 404 (prod_type == BrowserDistribution::CHROME_FRAME && |
| 405 (inst_type & |
| 406 (InstallationValidator::ProductBits::CHROME_FRAME_MULTI | |
| 407 InstallationValidator::ProductBits::CHROME_FRAME_READY_MODE)) != 0); |
| 408 |
| 409 const wchar_t* const* channels = &kChromeChannels[0]; |
| 410 if (prod_type == BrowserDistribution::CHROME_FRAME && !is_multi_install) |
| 411 channels = &kChromeFrameChannels[0]; // SxS GCF has its own channel names. |
| 412 const int channel_modifiers = |
| 413 is_multi_install ? GetChannelModifiers(inst_type) : 0; |
| 414 |
| 415 state->Clear(); |
| 416 state->SetChannel(channels[channel], channel_modifiers); |
| 417 state->SetVersion(chrome::kChromeVersion); |
| 418 state->SetUninstallCommand(prod_type, install_level, chrome::kChromeVersion, |
| 419 channel_modifiers, vehicle); |
| 420 state->set_multi_install(is_multi_install); |
| 421 if (prod_type == BrowserDistribution::CHROME_BINARIES && |
| 422 (inst_type == InstallationValidator::CHROME_MULTI || |
| 423 inst_type == |
| 424 InstallationValidator::CHROME_FRAME_READY_MODE_CHROME_MULTI)) { |
| 425 state->AddQuickEnableCfCommand(prod_type, install_level, |
| 426 chrome::kChromeVersion, channel_modifiers); |
| 427 } |
| 428 } |
| 429 |
| 430 // static |
| 431 // Populates |state| with the state of a valid installation of |inst_type|. |
| 432 void InstallationValidatorTest::MakeMachineState( |
| 433 InstallationValidator::InstallationType inst_type, |
| 434 Level install_level, |
| 435 Channel channel, |
| 436 Vehicle vehicle, |
| 437 FakeInstallationState* state) { |
| 438 DCHECK(state); |
| 439 |
| 440 static const int kChromeMask = |
| 441 (InstallationValidator::ProductBits::CHROME_SINGLE | |
| 442 InstallationValidator::ProductBits::CHROME_MULTI); |
| 443 static const int kChromeFrameMask = |
| 444 (InstallationValidator::ProductBits::CHROME_FRAME_SINGLE | |
| 445 InstallationValidator::ProductBits::CHROME_FRAME_MULTI | |
| 446 InstallationValidator::ProductBits::CHROME_FRAME_READY_MODE); |
| 447 static const int kBinariesMask = |
| 448 (InstallationValidator::ProductBits::CHROME_MULTI | |
| 449 InstallationValidator::ProductBits::CHROME_FRAME_MULTI | |
| 450 InstallationValidator::ProductBits::CHROME_FRAME_READY_MODE); |
| 451 |
| 452 FakeProductState prod_state; |
| 453 |
| 454 if ((inst_type & kChromeMask) != 0) { |
| 455 MakeProductState(BrowserDistribution::CHROME_BROWSER, inst_type, |
| 456 install_level, channel, vehicle, &prod_state); |
| 457 state->SetProductState(BrowserDistribution::CHROME_BROWSER, install_level, |
| 458 prod_state); |
| 459 } |
| 460 |
| 461 if ((inst_type & kChromeFrameMask) != 0) { |
| 462 MakeProductState(BrowserDistribution::CHROME_FRAME, inst_type, |
| 463 install_level, channel, vehicle, &prod_state); |
| 464 state->SetProductState(BrowserDistribution::CHROME_FRAME, install_level, |
| 465 prod_state); |
| 466 } |
| 467 |
| 468 if ((inst_type & kBinariesMask) != 0) { |
| 469 MakeProductState(BrowserDistribution::CHROME_BINARIES, inst_type, |
| 470 install_level, channel, vehicle, &prod_state); |
| 471 state->SetProductState(BrowserDistribution::CHROME_BINARIES, install_level, |
| 472 prod_state); |
| 473 } |
| 474 } |
| 475 |
283 void InstallationValidatorTest::TearDown() { | 476 void InstallationValidatorTest::TearDown() { |
284 validation_error_recipient_ = NULL; | 477 validation_error_recipient_ = NULL; |
285 } | 478 } |
286 | 479 |
287 // Test that NO_PRODUCTS is returned. | 480 // Builds a proper machine state for a given InstallationType, then validates |
288 TEST_F(InstallationValidatorTest, NoProducts) { | 481 // it. |
289 InstallationState empty_state; | 482 TEST_P(InstallationValidatorTest, TestValidInstallation) { |
290 InstallationValidator::InstallationType type = | 483 const InstallationValidator::InstallationType inst_type = GetParam(); |
291 static_cast<InstallationValidator::InstallationType>(-1); | |
292 StrictMock<MockValidationErrorRecipient> recipient; | |
293 set_validation_error_recipient(&recipient); | |
294 | |
295 EXPECT_TRUE(InstallationValidator::ValidateInstallationTypeForState( | |
296 empty_state, true, &type)); | |
297 EXPECT_EQ(InstallationValidator::NO_PRODUCTS, type); | |
298 } | |
299 | |
300 // Test valid single Chrome. | |
301 TEST_F(InstallationValidatorTest, ChromeVersion) { | |
302 FakeProductState chrome_state; | |
303 FakeInstallationState machine_state; | 484 FakeInstallationState machine_state; |
304 InstallationValidator::InstallationType type; | 485 InstallationValidator::InstallationType type; |
305 StrictMock<MockValidationErrorRecipient> recipient; | 486 StrictMock<MockValidationErrorRecipient> recipient; |
306 set_validation_error_recipient(&recipient); | 487 set_validation_error_recipient(&recipient); |
307 | 488 |
308 MakeChromeState(SYSTEM_LEVEL, STABLE_CHANNEL, 0, GOOGLE_UPDATE, | 489 MakeMachineState(inst_type, SYSTEM_LEVEL, STABLE_CHANNEL, GOOGLE_UPDATE, |
309 &chrome_state); | 490 &machine_state); |
310 machine_state.SetProductState(BrowserDistribution::CHROME_BROWSER, | |
311 SYSTEM_LEVEL, chrome_state); | |
312 EXPECT_TRUE(InstallationValidator::ValidateInstallationTypeForState( | 491 EXPECT_TRUE(InstallationValidator::ValidateInstallationTypeForState( |
313 machine_state, true, &type)); | 492 machine_state, true, &type)); |
314 EXPECT_EQ(InstallationValidator::CHROME_SINGLE, type); | 493 EXPECT_EQ(inst_type, type); |
315 } | 494 } |
| 495 |
| 496 // Run the test for all installation types. |
| 497 INSTANTIATE_TEST_CASE_P( |
| 498 AllValidInstallations, |
| 499 InstallationValidatorTest, |
| 500 Values(InstallationValidator::NO_PRODUCTS, |
| 501 InstallationValidator::CHROME_SINGLE, |
| 502 InstallationValidator::CHROME_MULTI, |
| 503 InstallationValidator::CHROME_FRAME_SINGLE, |
| 504 InstallationValidator::CHROME_FRAME_SINGLE_CHROME_SINGLE, |
| 505 InstallationValidator::CHROME_FRAME_SINGLE_CHROME_MULTI, |
| 506 InstallationValidator::CHROME_FRAME_MULTI, |
| 507 InstallationValidator::CHROME_FRAME_MULTI_CHROME_MULTI, |
| 508 InstallationValidator::CHROME_FRAME_READY_MODE_CHROME_MULTI)); |
OLD | NEW |