AU: Separate error codes for different OmahaRequestAction failures.

BUG=8651
TEST=unit tests, tested an update on the device through dev server

Change-Id: Ic590906be269fe371702bfbe282cddc197ab01fc

Review URL: http://codereview.chromium.org/4432002
diff --git a/mock_http_fetcher.cc b/mock_http_fetcher.cc
index 2e11865..eec550f 100644
--- a/mock_http_fetcher.cc
+++ b/mock_http_fetcher.cc
@@ -17,7 +17,11 @@
 }
 
 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 @@
 // 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 @@
     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::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