Add unit test for fallback route of manifest cache
Test: Run atest
Change-Id: Icc6a2c809c571c3ad8e16a863c37afd8d4042ed6
diff --git a/common/mock_http_fetcher.h b/common/mock_http_fetcher.h
index dec81b0..b082bbd 100644
--- a/common/mock_http_fetcher.h
+++ b/common/mock_http_fetcher.h
@@ -46,7 +46,7 @@
size_t size,
ProxyResolver* proxy_resolver)
: HttpFetcher(proxy_resolver),
- sent_size_(0),
+ sent_offset_(0),
timeout_id_(brillo::MessageLoop::kTaskIdNull),
paused_(false),
fail_transfer_(false),
@@ -64,7 +64,7 @@
// Ignores this.
void SetOffset(off_t offset) override {
- sent_size_ = offset;
+ sent_offset_ = offset;
if (delegate_)
delegate_->SeekToOffset(offset);
}
@@ -77,7 +77,7 @@
void set_max_retry_count(int max_retry_count) override {}
// No bytes were downloaded in the mock class.
- size_t GetBytesDownloaded() override { return sent_size_; }
+ size_t GetBytesDownloaded() override { return bytes_sent_; }
// Begins the transfer if it hasn't already begun.
void BeginTransfer(const std::string& url) override;
@@ -113,6 +113,8 @@
const brillo::Blob& post_data() const { return post_data_; }
+ void set_delay(bool delay) { delay_ = delay; }
+
private:
// Sends data to the delegate and sets up a timeout callback if needed. There
// must be a delegate. If |skip_delivery| is true, no bytes will be delivered,
@@ -129,8 +131,11 @@
// A full copy of the data we'll return to the delegate
brillo::Blob data_;
- // The number of bytes we've sent so far
- size_t sent_size_;
+ // The current offset, marks the first byte that will be sent next
+ size_t sent_offset_;
+
+ // Total number of bytes transferred
+ size_t bytes_sent_;
// The extra headers set.
std::map<std::string, std::string> extra_headers_;
@@ -148,6 +153,9 @@
// Set to true if BeginTransfer should EXPECT fail.
bool never_use_;
+ // Whether it should wait for 10ms before sending data to delegates
+ bool delay_{true};
+
DISALLOW_COPY_AND_ASSIGN(MockHttpFetcher);
};