| Index: mock_http_fetcher.cc
|
| diff --git a/mock_http_fetcher.cc b/mock_http_fetcher.cc
|
| index 2e1186529a8c72abc2b67e903ddf75fe01786020..eec550f6f49765af1d831b5d4388f322c205cc38 100644
|
| --- a/mock_http_fetcher.cc
|
| +++ b/mock_http_fetcher.cc
|
| @@ -17,7 +17,11 @@ MockHttpFetcher::~MockHttpFetcher() {
|
| }
|
|
|
| void MockHttpFetcher::BeginTransfer(const std::string& url) {
|
| - http_response_code_ = 0;
|
| + if (fail_transfer_ || data_.empty()) {
|
| + // No data to send, just notify of completion..
|
| + SignalTransferComplete();
|
| + return;
|
| + }
|
| if (sent_size_ < data_.size())
|
| SendData(true);
|
| }
|
| @@ -26,6 +30,11 @@ void MockHttpFetcher::BeginTransfer(const std::string& url) {
|
| // and it needs to be deleted by the caller. If timeout_source_ is NULL
|
| // when this function is called, this function will always return true.
|
| bool MockHttpFetcher::SendData(bool skip_delivery) {
|
| + if (fail_transfer_) {
|
| + SignalTransferComplete();
|
| + return timeout_source_;
|
| + }
|
| +
|
| CHECK_LT(sent_size_, data_.size());
|
| if (!skip_delivery) {
|
| const size_t chunk_size = min(kMockHttpFetcherChunkSize,
|
| @@ -36,8 +45,7 @@ bool MockHttpFetcher::SendData(bool skip_delivery) {
|
| CHECK_LE(sent_size_, data_.size());
|
| if (sent_size_ == data_.size()) {
|
| // We've sent all the data. Notify of success.
|
| - http_response_code_ = 200;
|
| - delegate_->TransferComplete(this, true);
|
| + SignalTransferComplete();
|
| }
|
| }
|
|
|
| @@ -101,4 +109,18 @@ void MockHttpFetcher::Unpause() {
|
| }
|
| }
|
|
|
| +void MockHttpFetcher::FailTransfer(int http_response_code) {
|
| + fail_transfer_ = true;
|
| + http_response_code_ = http_response_code;
|
| +}
|
| +
|
| +void MockHttpFetcher::SignalTransferComplete() {
|
| + // If the transfer has been failed, the HTTP response code should be set
|
| + // already.
|
| + if (!fail_transfer_) {
|
| + http_response_code_ = 200;
|
| + }
|
| + delegate_->TransferComplete(this, !fail_transfer_);
|
| +}
|
| +
|
| } // namespace chromeos_update_engine
|
|
|