| 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 <stddef.h> | 5 #include <stddef.h> |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 app_cmd.set_is_auto_run_on_os_upgrade(true); | 223 app_cmd.set_is_auto_run_on_os_upgrade(true); |
| 224 commands_.Set(installer::kCmdOnOsUpgrade, app_cmd); | 224 commands_.Set(installer::kCmdOnOsUpgrade, app_cmd); |
| 225 } | 225 } |
| 226 | 226 |
| 227 } // namespace | 227 } // namespace |
| 228 | 228 |
| 229 // Fixture for testing the InstallationValidator. Errors logged by the | 229 // Fixture for testing the InstallationValidator. Errors logged by the |
| 230 // validator are sent to an optional mock recipient (see | 230 // validator are sent to an optional mock recipient (see |
| 231 // set_validation_error_recipient) upon which expectations can be placed. | 231 // set_validation_error_recipient) upon which expectations can be placed. |
| 232 class InstallationValidatorTest | 232 class InstallationValidatorTest |
| 233 : public testing::TestWithParam<InstallationValidator::InstallationType> { | 233 : public testing::TestWithParam<InstallationValidator::InstallationType>, |
| 234 logging::LogMessageHandler { |
| 234 public: | 235 public: |
| 235 | 236 |
| 236 // These shouldn't need to be public, but there seems to be some interaction | 237 // These shouldn't need to be public, but there seems to be some interaction |
| 237 // with parameterized tests that requires it. | 238 // with parameterized tests that requires it. |
| 238 static void SetUpTestCase(); | 239 static void SetUpTestCase(); |
| 239 static void TearDownTestCase(); | 240 static void TearDownTestCase(); |
| 240 | 241 |
| 241 // Returns the multi channel modifiers for a given installation type. | 242 // Returns the multi channel modifiers for a given installation type. |
| 242 static int GetChannelModifiers(InstallationValidator::InstallationType type); | 243 static int GetChannelModifiers(InstallationValidator::InstallationType type); |
| 243 | 244 |
| 244 protected: | 245 protected: |
| 245 typedef std::map<InstallationValidator::InstallationType, int> | 246 typedef std::map<InstallationValidator::InstallationType, int> |
| 246 InstallationTypeToModifiers; | 247 InstallationTypeToModifiers; |
| 247 | 248 |
| 248 class ValidationErrorRecipient { | 249 class ValidationErrorRecipient { |
| 249 public: | 250 public: |
| 250 virtual ~ValidationErrorRecipient() { } | 251 virtual ~ValidationErrorRecipient() { } |
| 251 virtual void ReceiveValidationError(const char* file, | 252 virtual void ReceiveValidationError(const char* file, |
| 252 int line, | 253 int line, |
| 253 const char* message) = 0; | 254 const char* message) = 0; |
| 254 }; | 255 }; |
| 255 class MockValidationErrorRecipient : public ValidationErrorRecipient { | 256 class MockValidationErrorRecipient : public ValidationErrorRecipient { |
| 256 public: | 257 public: |
| 257 MOCK_METHOD3(ReceiveValidationError, void(const char* file, | 258 MOCK_METHOD3(ReceiveValidationError, void(const char* file, |
| 258 int line, | 259 int line, |
| 259 const char* message)); | 260 const char* message)); |
| 260 }; | 261 }; |
| 261 | 262 |
| 262 protected: | 263 protected: |
| 263 static bool HandleLogMessage(int severity, | 264 // logging::LogMessageHandler |
| 264 const char* file, | 265 bool OnMessage(int severity, |
| 265 int line, | 266 const char* file, |
| 266 size_t message_start, | 267 int line, |
| 267 const std::string& str); | 268 size_t message_start, |
| 269 const std::string& str) override; |
| 268 static void set_validation_error_recipient( | 270 static void set_validation_error_recipient( |
| 269 ValidationErrorRecipient* recipient); | 271 ValidationErrorRecipient* recipient); |
| 270 static void MakeProductState( | 272 static void MakeProductState( |
| 271 BrowserDistribution::Type prod_type, | 273 BrowserDistribution::Type prod_type, |
| 272 InstallationValidator::InstallationType inst_type, | 274 InstallationValidator::InstallationType inst_type, |
| 273 Level install_level, | 275 Level install_level, |
| 274 Channel channel, | 276 Channel channel, |
| 275 Vehicle vehicle, | 277 Vehicle vehicle, |
| 276 FakeProductState* state); | 278 FakeProductState* state); |
| 277 static void MakeMachineState( | 279 static void MakeMachineState( |
| 278 InstallationValidator::InstallationType inst_type, | 280 InstallationValidator::InstallationType inst_type, |
| 279 Level install_level, | 281 Level install_level, |
| 280 Channel channel, | 282 Channel channel, |
| 281 Vehicle vehicle, | 283 Vehicle vehicle, |
| 282 FakeInstallationState* state); | 284 FakeInstallationState* state); |
| 283 void TearDown() override; | 285 void TearDown() override; |
| 284 | 286 |
| 285 static logging::LogMessageHandlerFunction old_log_message_handler_; | |
| 286 static ValidationErrorRecipient* validation_error_recipient_; | 287 static ValidationErrorRecipient* validation_error_recipient_; |
| 287 static InstallationTypeToModifiers* type_to_modifiers_; | 288 static InstallationTypeToModifiers* type_to_modifiers_; |
| 288 }; | 289 }; |
| 289 | 290 |
| 290 // static | 291 // static |
| 291 logging::LogMessageHandlerFunction | |
| 292 InstallationValidatorTest::old_log_message_handler_ = NULL; | |
| 293 | |
| 294 // static | |
| 295 InstallationValidatorTest::ValidationErrorRecipient* | 292 InstallationValidatorTest::ValidationErrorRecipient* |
| 296 InstallationValidatorTest::validation_error_recipient_ = NULL; | 293 InstallationValidatorTest::validation_error_recipient_ = NULL; |
| 297 | 294 |
| 298 // static | 295 // static |
| 299 InstallationValidatorTest::InstallationTypeToModifiers* | 296 InstallationValidatorTest::InstallationTypeToModifiers* |
| 300 InstallationValidatorTest::type_to_modifiers_ = NULL; | 297 InstallationValidatorTest::type_to_modifiers_ = NULL; |
| 301 | 298 |
| 302 // static | 299 // static |
| 303 int InstallationValidatorTest::GetChannelModifiers( | 300 int InstallationValidatorTest::GetChannelModifiers( |
| 304 InstallationValidator::InstallationType type) { | 301 InstallationValidator::InstallationType type) { |
| 305 DCHECK(type_to_modifiers_); | 302 DCHECK(type_to_modifiers_); |
| 306 DCHECK(type_to_modifiers_->find(type) != type_to_modifiers_->end()); | 303 DCHECK(type_to_modifiers_->find(type) != type_to_modifiers_->end()); |
| 307 | 304 |
| 308 return (*type_to_modifiers_)[type]; | 305 return (*type_to_modifiers_)[type]; |
| 309 } | 306 } |
| 310 | 307 |
| 311 // static | 308 // static |
| 312 void InstallationValidatorTest::SetUpTestCase() { | 309 void InstallationValidatorTest::SetUpTestCase() { |
| 313 DCHECK(type_to_modifiers_ == NULL); | 310 DCHECK(type_to_modifiers_ == NULL); |
| 314 old_log_message_handler_ = logging::GetLogMessageHandler(); | |
| 315 logging::SetLogMessageHandler(&HandleLogMessage); | |
| 316 | 311 |
| 317 type_to_modifiers_ = new InstallationTypeToModifiers(); | 312 type_to_modifiers_ = new InstallationTypeToModifiers(); |
| 318 InstallationTypeToModifiers& ttm = *type_to_modifiers_; | 313 InstallationTypeToModifiers& ttm = *type_to_modifiers_; |
| 319 ttm[InstallationValidator::NO_PRODUCTS] = 0; | 314 ttm[InstallationValidator::NO_PRODUCTS] = 0; |
| 320 ttm[InstallationValidator::CHROME_SINGLE] = 0; | 315 ttm[InstallationValidator::CHROME_SINGLE] = 0; |
| 321 ttm[InstallationValidator::CHROME_MULTI] = CM_MULTI | CM_CHROME; | 316 ttm[InstallationValidator::CHROME_MULTI] = CM_MULTI | CM_CHROME; |
| 322 ttm[InstallationValidator::CHROME_FRAME_SINGLE] = 0; | 317 ttm[InstallationValidator::CHROME_FRAME_SINGLE] = 0; |
| 323 ttm[InstallationValidator::CHROME_FRAME_SINGLE_CHROME_SINGLE] = 0; | 318 ttm[InstallationValidator::CHROME_FRAME_SINGLE_CHROME_SINGLE] = 0; |
| 324 ttm[InstallationValidator::CHROME_FRAME_SINGLE_CHROME_MULTI] = | 319 ttm[InstallationValidator::CHROME_FRAME_SINGLE_CHROME_MULTI] = |
| 325 CM_MULTI | CM_CHROME; | 320 CM_MULTI | CM_CHROME; |
| 326 ttm[InstallationValidator::CHROME_FRAME_MULTI] = CM_MULTI | CM_CHROME_FRAME; | 321 ttm[InstallationValidator::CHROME_FRAME_MULTI] = CM_MULTI | CM_CHROME_FRAME; |
| 327 ttm[InstallationValidator::CHROME_FRAME_MULTI_CHROME_MULTI] = | 322 ttm[InstallationValidator::CHROME_FRAME_MULTI_CHROME_MULTI] = |
| 328 CM_MULTI | CM_CHROME_FRAME | CM_CHROME; | 323 CM_MULTI | CM_CHROME_FRAME | CM_CHROME; |
| 329 } | 324 } |
| 330 | 325 |
| 331 // static | 326 // static |
| 332 void InstallationValidatorTest::TearDownTestCase() { | 327 void InstallationValidatorTest::TearDownTestCase() { |
| 333 logging::SetLogMessageHandler(old_log_message_handler_); | |
| 334 old_log_message_handler_ = NULL; | |
| 335 | |
| 336 delete type_to_modifiers_; | 328 delete type_to_modifiers_; |
| 337 type_to_modifiers_ = NULL; | 329 type_to_modifiers_ = NULL; |
| 338 } | 330 } |
| 339 | 331 |
| 340 // static | 332 bool InstallationValidatorTest::OnMessage(int severity, |
| 341 bool InstallationValidatorTest::HandleLogMessage(int severity, | 333 const char* file, |
| 342 const char* file, | 334 int line, |
| 343 int line, | 335 size_t message_start, |
| 344 size_t message_start, | 336 const std::string& str) { |
| 345 const std::string& str) { | |
| 346 // All validation failures result in LOG(ERROR) | 337 // All validation failures result in LOG(ERROR) |
| 347 if (severity == logging::LOG_ERROR && !str.empty()) { | 338 if (severity == logging::LOG_ERROR && !str.empty()) { |
| 348 // Remove the trailing newline, if present. | 339 // Remove the trailing newline, if present. |
| 349 size_t message_length = str.size() - message_start; | 340 size_t message_length = str.size() - message_start; |
| 350 if (*str.rbegin() == '\n') | 341 if (*str.rbegin() == '\n') |
| 351 --message_length; | 342 --message_length; |
| 352 if (validation_error_recipient_ != NULL) { | 343 if (validation_error_recipient_ != NULL) { |
| 353 validation_error_recipient_->ReceiveValidationError( | 344 validation_error_recipient_->ReceiveValidationError( |
| 354 file, line, str.substr(message_start, message_length).c_str()); | 345 file, line, str.substr(message_start, message_length).c_str()); |
| 355 } else { | 346 } else { |
| 356 // Fail the test if an error wasn't handled. | 347 // Fail the test if an error wasn't handled. |
| 357 ADD_FAILURE_AT(file, line) | 348 ADD_FAILURE_AT(file, line) |
| 358 << base::StringPiece(str.c_str() + message_start, message_length); | 349 << base::StringPiece(str.c_str() + message_start, message_length); |
| 359 } | 350 } |
| 360 return true; | 351 return true; |
| 361 } | 352 } |
| 362 | 353 |
| 363 if (old_log_message_handler_ != NULL) | |
| 364 return (old_log_message_handler_)(severity, file, line, message_start, str); | |
| 365 | |
| 366 return false; | 354 return false; |
| 367 } | 355 } |
| 368 | 356 |
| 369 // static | 357 // static |
| 370 void InstallationValidatorTest::set_validation_error_recipient( | 358 void InstallationValidatorTest::set_validation_error_recipient( |
| 371 ValidationErrorRecipient* recipient) { | 359 ValidationErrorRecipient* recipient) { |
| 372 validation_error_recipient_ = recipient; | 360 validation_error_recipient_ = recipient; |
| 373 } | 361 } |
| 374 | 362 |
| 375 // static | 363 // static |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 482 AllValidInstallations, | 470 AllValidInstallations, |
| 483 InstallationValidatorTest, | 471 InstallationValidatorTest, |
| 484 Values(InstallationValidator::NO_PRODUCTS, | 472 Values(InstallationValidator::NO_PRODUCTS, |
| 485 InstallationValidator::CHROME_SINGLE, | 473 InstallationValidator::CHROME_SINGLE, |
| 486 InstallationValidator::CHROME_MULTI, | 474 InstallationValidator::CHROME_MULTI, |
| 487 InstallationValidator::CHROME_FRAME_SINGLE, | 475 InstallationValidator::CHROME_FRAME_SINGLE, |
| 488 InstallationValidator::CHROME_FRAME_SINGLE_CHROME_SINGLE, | 476 InstallationValidator::CHROME_FRAME_SINGLE_CHROME_SINGLE, |
| 489 InstallationValidator::CHROME_FRAME_SINGLE_CHROME_MULTI, | 477 InstallationValidator::CHROME_FRAME_SINGLE_CHROME_MULTI, |
| 490 InstallationValidator::CHROME_FRAME_MULTI, | 478 InstallationValidator::CHROME_FRAME_MULTI, |
| 491 InstallationValidator::CHROME_FRAME_MULTI_CHROME_MULTI)); | 479 InstallationValidator::CHROME_FRAME_MULTI_CHROME_MULTI)); |
| OLD | NEW |