Add MultiRangeHttpFetcherOverFileFetcherTest to HttpFetcherTest.
When fetching a payload in DownloadAction, in addition to using
MultiRangeHttpFetcher over LibcurlHttpFetcher, we're also actively using
MultiRangeHttpFetcher over FileFetcher in Android, e.g. when installing
or verifying a local payload.
This CL adds MultiRangeHttpFetcherOverFileFetcherTest into
HttpFetcherTest to exercise this path. The test would be helpful in
capturing issues addressed by commit 028ea416 (it still requires running
with an ASAN build though).
It also fixes a bug in MultiRangeHttpFetcher::ReceivedBytes(), which is
uncovered while fixing the test.
Fixes: 120577143
Test: Run unittest on taimen.
Change-Id: I5dddb95e9bdfd842017876017a99c04d6be304db
diff --git a/common/multi_range_http_fetcher.cc b/common/multi_range_http_fetcher.cc
index d39b7f9..230106d 100644
--- a/common/multi_range_http_fetcher.cc
+++ b/common/multi_range_http_fetcher.cc
@@ -99,10 +99,13 @@
range.length() - bytes_received_this_range_);
}
LOG_IF(WARNING, next_size <= 0) << "Asked to write length <= 0";
+ // bytes_received_this_range_ needs to be updated regardless of the delegate_
+ // result, because it will be used to determine a successful transfer in
+ // TransferEnded().
+ bytes_received_this_range_ += length;
if (delegate_ && !delegate_->ReceivedBytes(this, bytes, next_size))
return false;
- bytes_received_this_range_ += length;
if (range.HasLength() && bytes_received_this_range_ >= range.length()) {
// Terminates the current fetcher. Waits for its TransferTerminated
// callback before starting the next range so that we don't end up