| 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 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 Vehicle vehicle, | 275 Vehicle vehicle, |
| 276 FakeProductState* state); | 276 FakeProductState* state); |
| 277 static void MakeMachineState( | 277 static void MakeMachineState( |
| 278 InstallationValidator::InstallationType inst_type, | 278 InstallationValidator::InstallationType inst_type, |
| 279 Level install_level, | 279 Level install_level, |
| 280 Channel channel, | 280 Channel channel, |
| 281 Vehicle vehicle, | 281 Vehicle vehicle, |
| 282 FakeInstallationState* state); | 282 FakeInstallationState* state); |
| 283 void TearDown() override; | 283 void TearDown() override; |
| 284 | 284 |
| 285 static logging::LogMessageHandlerFunction old_log_message_handler_; | |
| 286 static ValidationErrorRecipient* validation_error_recipient_; | 285 static ValidationErrorRecipient* validation_error_recipient_; |
| 287 static InstallationTypeToModifiers* type_to_modifiers_; | 286 static InstallationTypeToModifiers* type_to_modifiers_; |
| 288 }; | 287 }; |
| 289 | 288 |
| 290 // static | 289 // static |
| 291 logging::LogMessageHandlerFunction | |
| 292 InstallationValidatorTest::old_log_message_handler_ = NULL; | |
| 293 | |
| 294 // static | |
| 295 InstallationValidatorTest::ValidationErrorRecipient* | 290 InstallationValidatorTest::ValidationErrorRecipient* |
| 296 InstallationValidatorTest::validation_error_recipient_ = NULL; | 291 InstallationValidatorTest::validation_error_recipient_ = NULL; |
| 297 | 292 |
| 298 // static | 293 // static |
| 299 InstallationValidatorTest::InstallationTypeToModifiers* | 294 InstallationValidatorTest::InstallationTypeToModifiers* |
| 300 InstallationValidatorTest::type_to_modifiers_ = NULL; | 295 InstallationValidatorTest::type_to_modifiers_ = NULL; |
| 301 | 296 |
| 302 // static | 297 // static |
| 303 int InstallationValidatorTest::GetChannelModifiers( | 298 int InstallationValidatorTest::GetChannelModifiers( |
| 304 InstallationValidator::InstallationType type) { | 299 InstallationValidator::InstallationType type) { |
| 305 DCHECK(type_to_modifiers_); | 300 DCHECK(type_to_modifiers_); |
| 306 DCHECK(type_to_modifiers_->find(type) != type_to_modifiers_->end()); | 301 DCHECK(type_to_modifiers_->find(type) != type_to_modifiers_->end()); |
| 307 | 302 |
| 308 return (*type_to_modifiers_)[type]; | 303 return (*type_to_modifiers_)[type]; |
| 309 } | 304 } |
| 310 | 305 |
| 311 // static | 306 // static |
| 312 void InstallationValidatorTest::SetUpTestCase() { | 307 void InstallationValidatorTest::SetUpTestCase() { |
| 313 DCHECK(type_to_modifiers_ == NULL); | 308 DCHECK(type_to_modifiers_ == NULL); |
| 314 old_log_message_handler_ = logging::GetLogMessageHandler(); | 309 logging::PushLogMessageHandler(&HandleLogMessage); |
| 315 logging::SetLogMessageHandler(&HandleLogMessage); | |
| 316 | 310 |
| 317 type_to_modifiers_ = new InstallationTypeToModifiers(); | 311 type_to_modifiers_ = new InstallationTypeToModifiers(); |
| 318 InstallationTypeToModifiers& ttm = *type_to_modifiers_; | 312 InstallationTypeToModifiers& ttm = *type_to_modifiers_; |
| 319 ttm[InstallationValidator::NO_PRODUCTS] = 0; | 313 ttm[InstallationValidator::NO_PRODUCTS] = 0; |
| 320 ttm[InstallationValidator::CHROME_SINGLE] = 0; | 314 ttm[InstallationValidator::CHROME_SINGLE] = 0; |
| 321 ttm[InstallationValidator::CHROME_MULTI] = CM_MULTI | CM_CHROME; | 315 ttm[InstallationValidator::CHROME_MULTI] = CM_MULTI | CM_CHROME; |
| 322 ttm[InstallationValidator::CHROME_FRAME_SINGLE] = 0; | 316 ttm[InstallationValidator::CHROME_FRAME_SINGLE] = 0; |
| 323 ttm[InstallationValidator::CHROME_FRAME_SINGLE_CHROME_SINGLE] = 0; | 317 ttm[InstallationValidator::CHROME_FRAME_SINGLE_CHROME_SINGLE] = 0; |
| 324 ttm[InstallationValidator::CHROME_FRAME_SINGLE_CHROME_MULTI] = | 318 ttm[InstallationValidator::CHROME_FRAME_SINGLE_CHROME_MULTI] = |
| 325 CM_MULTI | CM_CHROME; | 319 CM_MULTI | CM_CHROME; |
| 326 ttm[InstallationValidator::CHROME_FRAME_MULTI] = CM_MULTI | CM_CHROME_FRAME; | 320 ttm[InstallationValidator::CHROME_FRAME_MULTI] = CM_MULTI | CM_CHROME_FRAME; |
| 327 ttm[InstallationValidator::CHROME_FRAME_MULTI_CHROME_MULTI] = | 321 ttm[InstallationValidator::CHROME_FRAME_MULTI_CHROME_MULTI] = |
| 328 CM_MULTI | CM_CHROME_FRAME | CM_CHROME; | 322 CM_MULTI | CM_CHROME_FRAME | CM_CHROME; |
| 329 } | 323 } |
| 330 | 324 |
| 331 // static | 325 // static |
| 332 void InstallationValidatorTest::TearDownTestCase() { | 326 void InstallationValidatorTest::TearDownTestCase() { |
| 333 logging::SetLogMessageHandler(old_log_message_handler_); | 327 logging::PopLogMessageHandler(); |
| 334 old_log_message_handler_ = NULL; | |
| 335 | 328 |
| 336 delete type_to_modifiers_; | 329 delete type_to_modifiers_; |
| 337 type_to_modifiers_ = NULL; | 330 type_to_modifiers_ = NULL; |
| 338 } | 331 } |
| 339 | 332 |
| 340 // static | 333 // static |
| 341 bool InstallationValidatorTest::HandleLogMessage(int severity, | 334 bool InstallationValidatorTest::HandleLogMessage(int severity, |
| 342 const char* file, | 335 const char* file, |
| 343 int line, | 336 int line, |
| 344 size_t message_start, | 337 size_t message_start, |
| 345 const std::string& str) { | 338 const std::string& str) { |
| 346 // All validation failures result in LOG(ERROR) | 339 // All validation failures result in LOG(ERROR) |
| 347 if (severity == logging::LOG_ERROR && !str.empty()) { | 340 if (severity == logging::LOG_ERROR && !str.empty()) { |
| 348 // Remove the trailing newline, if present. | 341 // Remove the trailing newline, if present. |
| 349 size_t message_length = str.size() - message_start; | 342 size_t message_length = str.size() - message_start; |
| 350 if (*str.rbegin() == '\n') | 343 if (*str.rbegin() == '\n') |
| 351 --message_length; | 344 --message_length; |
| 352 if (validation_error_recipient_ != NULL) { | 345 if (validation_error_recipient_ != NULL) { |
| 353 validation_error_recipient_->ReceiveValidationError( | 346 validation_error_recipient_->ReceiveValidationError( |
| 354 file, line, str.substr(message_start, message_length).c_str()); | 347 file, line, str.substr(message_start, message_length).c_str()); |
| 355 } else { | 348 } else { |
| 356 // Fail the test if an error wasn't handled. | 349 // Fail the test if an error wasn't handled. |
| 357 ADD_FAILURE_AT(file, line) | 350 ADD_FAILURE_AT(file, line) |
| 358 << base::StringPiece(str.c_str() + message_start, message_length); | 351 << base::StringPiece(str.c_str() + message_start, message_length); |
| 359 } | 352 } |
| 360 return true; | 353 return true; |
| 361 } | 354 } |
| 362 | 355 |
| 363 if (old_log_message_handler_ != NULL) | |
| 364 return (old_log_message_handler_)(severity, file, line, message_start, str); | |
| 365 | |
| 366 return false; | 356 return false; |
| 367 } | 357 } |
| 368 | 358 |
| 369 // static | 359 // static |
| 370 void InstallationValidatorTest::set_validation_error_recipient( | 360 void InstallationValidatorTest::set_validation_error_recipient( |
| 371 ValidationErrorRecipient* recipient) { | 361 ValidationErrorRecipient* recipient) { |
| 372 validation_error_recipient_ = recipient; | 362 validation_error_recipient_ = recipient; |
| 373 } | 363 } |
| 374 | 364 |
| 375 // static | 365 // static |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 482 AllValidInstallations, | 472 AllValidInstallations, |
| 483 InstallationValidatorTest, | 473 InstallationValidatorTest, |
| 484 Values(InstallationValidator::NO_PRODUCTS, | 474 Values(InstallationValidator::NO_PRODUCTS, |
| 485 InstallationValidator::CHROME_SINGLE, | 475 InstallationValidator::CHROME_SINGLE, |
| 486 InstallationValidator::CHROME_MULTI, | 476 InstallationValidator::CHROME_MULTI, |
| 487 InstallationValidator::CHROME_FRAME_SINGLE, | 477 InstallationValidator::CHROME_FRAME_SINGLE, |
| 488 InstallationValidator::CHROME_FRAME_SINGLE_CHROME_SINGLE, | 478 InstallationValidator::CHROME_FRAME_SINGLE_CHROME_SINGLE, |
| 489 InstallationValidator::CHROME_FRAME_SINGLE_CHROME_MULTI, | 479 InstallationValidator::CHROME_FRAME_SINGLE_CHROME_MULTI, |
| 490 InstallationValidator::CHROME_FRAME_MULTI, | 480 InstallationValidator::CHROME_FRAME_MULTI, |
| 491 InstallationValidator::CHROME_FRAME_MULTI_CHROME_MULTI)); | 481 InstallationValidator::CHROME_FRAME_MULTI_CHROME_MULTI)); |
| OLD | NEW |