Commit 12bd94e4 authored by Robert Ogden's avatar Robert Ogden Committed by Commit Bot

Expose URLLoaderCompletionStatus in SimpleURLLoader

Adds a new method that returns the URLLoaderCompletionStatus from the
URL Loader's OnComplete. This is needed since the completion status
provides additional metrics needed to compute fetch duration and
encoded body length which are used in
https://chromium-review.googlesource.com/c/chromium/src/+/2463544.

The returned completion status is Optional to account for cases where
the URLLoader never starts, or gets an unexpected response from the
network.

Bug: 1136174
Change-Id: Ib956135f30ec738f85f22739372387b1093815fe
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2468347
Commit-Queue: Robert Ogden <robertogden@chromium.org>
Reviewed-by: default avatarClark DuVall <cduvall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#816815}
parent b79ce46d
......@@ -235,6 +235,8 @@ class SimpleURLLoaderImpl : public SimpleURLLoader,
int NetError() const override;
const mojom::URLResponseHead* ResponseInfo() const override;
const base::Optional<URLLoaderCompletionStatus>& CompletionStatus()
const override;
const GURL& GetFinalURL() const override;
bool LoadedFromCache() const override;
int64_t GetContentSize() const override;
......@@ -267,9 +269,6 @@ class SimpleURLLoaderImpl : public SimpleURLLoader,
~RequestState() = default;
bool request_completed = false;
// The expected total size of the body, taken from
// URLLoaderCompletionStatus.
int64_t expected_body_size = 0;
bool body_started = false;
bool body_completed = false;
......@@ -286,6 +285,8 @@ class SimpleURLLoaderImpl : public SimpleURLLoader,
bool loaded_from_cache = false;
mojom::URLResponseHeadPtr response_info;
base::Optional<URLLoaderCompletionStatus> completion_status;
};
// Prepares internal state to start a request, and then calls StartRequest().
......@@ -1381,36 +1382,43 @@ void SimpleURLLoaderImpl::SetTimeoutDuration(base::TimeDelta timeout_duration) {
}
int SimpleURLLoaderImpl::NetError() const {
// Should only be called once the request is compelete.
// Should only be called once the request is complete.
DCHECK(request_state_->finished);
DCHECK_NE(net::ERR_IO_PENDING, request_state_->net_error);
return request_state_->net_error;
}
const GURL& SimpleURLLoaderImpl::GetFinalURL() const {
// Should only be called once the request is compelete.
// Should only be called once the request is complete.
DCHECK(request_state_->finished);
return final_url_;
}
bool SimpleURLLoaderImpl::LoadedFromCache() const {
// Should only be called once the request is compelete.
// Should only be called once the request is complete.
DCHECK(request_state_->finished);
return request_state_->loaded_from_cache;
}
int64_t SimpleURLLoaderImpl::GetContentSize() const {
// Should only be called once the request is compelete.
// Should only be called once the request is complete.
DCHECK(request_state_->finished);
return request_state_->received_body_size;
}
const mojom::URLResponseHead* SimpleURLLoaderImpl::ResponseInfo() const {
// Should only be called once the request is compelete.
// Should only be called once the request is complete.
DCHECK(request_state_->finished);
return request_state_->response_info.get();
}
const base::Optional<URLLoaderCompletionStatus>&
SimpleURLLoaderImpl::CompletionStatus() const {
// Should only be called once the request is complete.
DCHECK(request_state_->finished);
return request_state_->completion_status;
}
void SimpleURLLoaderImpl::OnBodyHandlerDone(net::Error error,
int64_t received_body_size) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
......@@ -1419,6 +1427,10 @@ void SimpleURLLoaderImpl::OnBodyHandlerDone(net::Error error,
// If there's an error, fail request and report it immediately.
if (error != net::OK) {
// Reset the completion status since the contained metrics like encoded body
// length and net error are not reliable when the body itself was not
// successfully completed.
request_state_->completion_status = base::nullopt;
// When |allow_partial_results_| is true, a valid body|file_path is
// passed to the completion callback even in the case of failures.
// For consistency, it makes sense to also hold the actual decompressed
......@@ -1668,14 +1680,16 @@ void SimpleURLLoaderImpl::OnComplete(const URLLoaderCompletionStatus& status) {
client_receiver_.reset();
url_loader_.reset();
request_state_->completion_status = status;
request_state_->request_completed = true;
request_state_->expected_body_size = status.decoded_body_length;
request_state_->net_error = status.error_code;
request_state_->loaded_from_cache = status.exists_in_cache;
// If |status| indicates success, but the body pipe was never received, the
// URLLoader is violating the API contract.
if (request_state_->net_error == net::OK && !request_state_->body_started)
if (request_state_->net_error == net::OK && !request_state_->body_started) {
request_state_->net_error = net::ERR_UNEXPECTED;
request_state_->completion_status = base::nullopt;
}
MaybeComplete();
}
......@@ -1693,6 +1707,8 @@ void SimpleURLLoaderImpl::OnMojoDisconnect() {
request_state_->request_completed = true;
request_state_->net_error = net::ERR_FAILED;
request_state_->completion_status = base::nullopt;
// Wait to receive any pending data on the data pipe before reporting the
// failure.
MaybeComplete();
......@@ -1733,17 +1749,21 @@ void SimpleURLLoaderImpl::MaybeComplete() {
// When OnCompleted sees a success result, still need to report an error if
// the size isn't what was expected.
if (request_state_->net_error == net::OK &&
request_state_->expected_body_size !=
request_state_->completion_status &&
request_state_->completion_status->decoded_body_length !=
request_state_->received_body_size) {
if (request_state_->expected_body_size >
if (request_state_->completion_status->decoded_body_length >
request_state_->received_body_size) {
// The body pipe was closed before it received the entire body.
request_state_->net_error = net::ERR_FAILED;
request_state_->completion_status = base::nullopt;
} else {
// The caller provided more data through the pipe than it reported in
// URLLoaderCompletionStatus, so the URLLoader is violating the
// API contract. Just fail the request.
// API contract. Just fail the request and delete the retained completion
// status.
request_state_->net_error = net::ERR_UNEXPECTED;
request_state_->completion_status = base::nullopt;
}
}
......
......@@ -15,6 +15,7 @@
#include "base/callback_forward.h"
#include "base/component_export.h"
#include "base/macros.h"
#include "base/optional.h"
#include "services/network/public/mojom/url_response_head.mojom.h"
class GURL;
......@@ -26,7 +27,7 @@ namespace base {
class FilePath;
class TickClock;
class TimeDelta;
}
} // namespace base
namespace net {
class HttpResponseHeaders;
......@@ -348,6 +349,12 @@ class COMPONENT_EXPORT(NETWORK_CPP) SimpleURLLoader {
// caller of completion.
virtual const mojom::URLResponseHead* ResponseInfo() const = 0;
// The URLLoaderCompletionStatus for the request. Will be nullopt if the
// response never completed. May only be called once the loader has informed
// the caller of completion.
virtual const base::Optional<URLLoaderCompletionStatus>& CompletionStatus()
const = 0;
// Returns the URL that this loader is processing. May only be called once the
// loader has informed the caller of completion.
virtual const GURL& GetFinalURL() const = 0;
......
......@@ -723,6 +723,9 @@ TEST_P(SimpleURLLoaderTest, BasicRequest) {
test_helper->StartSimpleLoaderAndWait(url_loader_factory_.get());
EXPECT_EQ(net::OK, test_helper->simple_url_loader()->NetError());
ASSERT_TRUE(test_helper->simple_url_loader()->CompletionStatus());
EXPECT_EQ(net::OK,
test_helper->simple_url_loader()->CompletionStatus()->error_code);
EXPECT_EQ(200, test_helper->GetResponseCode());
if (GetParam() != SimpleLoaderTestHelper::DownloadType::HEADERS_ONLY) {
......@@ -730,6 +733,9 @@ TEST_P(SimpleURLLoaderTest, BasicRequest) {
EXPECT_EQ(kExpectedResponse, *test_helper->response_body());
EXPECT_EQ(kExpectedResponseSize,
test_helper->simple_url_loader()->GetContentSize());
EXPECT_EQ(kExpectedResponseSize, test_helper->simple_url_loader()
->CompletionStatus()
->decoded_body_length);
}
}
......@@ -743,6 +749,9 @@ TEST_P(SimpleURLLoaderTest, GzipBody) {
test_helper->StartSimpleLoaderAndWait(url_loader_factory_.get());
EXPECT_EQ(net::OK, test_helper->simple_url_loader()->NetError());
ASSERT_TRUE(test_helper->simple_url_loader()->CompletionStatus());
EXPECT_EQ(net::OK,
test_helper->simple_url_loader()->CompletionStatus()->error_code);
EXPECT_EQ(200, test_helper->GetResponseCode());
if (GetParam() != SimpleLoaderTestHelper::DownloadType::HEADERS_ONLY) {
......@@ -750,6 +759,17 @@ TEST_P(SimpleURLLoaderTest, GzipBody) {
EXPECT_EQ(content, *test_helper->response_body());
EXPECT_EQ(static_cast<int64_t>(content.size()),
test_helper->simple_url_loader()->GetContentSize());
ASSERT_TRUE(test_helper->simple_url_loader()->CompletionStatus());
EXPECT_EQ(static_cast<int64_t>(content.size()),
test_helper->simple_url_loader()
->CompletionStatus()
->decoded_body_length);
EXPECT_LT(test_helper->simple_url_loader()
->CompletionStatus()
->encoded_body_length,
test_helper->simple_url_loader()
->CompletionStatus()
->decoded_body_length);
}
}
......@@ -761,6 +781,9 @@ TEST_P(SimpleURLLoaderTest, Redirect) {
test_helper->StartSimpleLoaderAndWait(url_loader_factory_.get());
EXPECT_EQ(net::OK, test_helper->simple_url_loader()->NetError());
ASSERT_TRUE(test_helper->simple_url_loader()->CompletionStatus());
EXPECT_EQ(net::OK,
test_helper->simple_url_loader()->CompletionStatus()->error_code);
EXPECT_EQ(200, test_helper->GetResponseCode());
if (GetParam() != SimpleLoaderTestHelper::DownloadType::HEADERS_ONLY) {
......@@ -777,6 +800,9 @@ TEST_P(SimpleURLLoaderTest, RedirectFile) {
EXPECT_EQ(net::ERR_UNKNOWN_URL_SCHEME,
test_helper->simple_url_loader()->NetError());
ASSERT_TRUE(test_helper->simple_url_loader()->CompletionStatus());
EXPECT_EQ(net::ERR_UNKNOWN_URL_SCHEME,
test_helper->simple_url_loader()->CompletionStatus()->error_code);
EXPECT_FALSE(test_helper->simple_url_loader()->ResponseInfo());
}
......@@ -789,6 +815,9 @@ TEST_P(SimpleURLLoaderTest, RedirectData) {
EXPECT_EQ(net::ERR_UNKNOWN_URL_SCHEME,
test_helper->simple_url_loader()->NetError());
ASSERT_TRUE(test_helper->simple_url_loader()->CompletionStatus());
EXPECT_EQ(net::ERR_UNKNOWN_URL_SCHEME,
test_helper->simple_url_loader()->CompletionStatus()->error_code);
EXPECT_FALSE(test_helper->simple_url_loader()->ResponseInfo());
}
......@@ -899,6 +928,9 @@ TEST_P(SimpleURLLoaderTest, UploadShortStringWithRedirect) {
test_helper->StartSimpleLoaderAndWait(url_loader_factory_.get());
EXPECT_EQ(net::OK, test_helper->simple_url_loader()->NetError());
ASSERT_TRUE(test_helper->simple_url_loader()->CompletionStatus());
EXPECT_EQ(net::OK,
test_helper->simple_url_loader()->CompletionStatus()->error_code);
if (GetParam() != SimpleLoaderTestHelper::DownloadType::HEADERS_ONLY) {
ASSERT_TRUE(test_helper->response_body());
......@@ -927,6 +959,9 @@ TEST_P(SimpleURLLoaderTest, UploadLongStringWithRedirect) {
test_helper->StartSimpleLoaderAndWait(url_loader_factory_.get());
EXPECT_EQ(net::OK, test_helper->simple_url_loader()->NetError());
ASSERT_TRUE(test_helper->simple_url_loader()->CompletionStatus());
EXPECT_EQ(net::OK,
test_helper->simple_url_loader()->CompletionStatus()->error_code);
if (GetParam() != SimpleLoaderTestHelper::DownloadType::HEADERS_ONLY) {
ASSERT_TRUE(test_helper->response_body());
......@@ -962,6 +997,9 @@ TEST_P(SimpleURLLoaderTest,
test_helper->StartSimpleLoaderAndWait(url_loader_factory_.get());
EXPECT_EQ(net::OK, test_helper->simple_url_loader()->NetError());
ASSERT_TRUE(test_helper->simple_url_loader()->CompletionStatus());
EXPECT_EQ(net::OK,
test_helper->simple_url_loader()->CompletionStatus()->error_code);
if (GetParam() != SimpleLoaderTestHelper::DownloadType::HEADERS_ONLY) {
ASSERT_TRUE(test_helper->response_body());
......@@ -996,6 +1034,9 @@ TEST_P(SimpleURLLoaderTest,
test_helper->StartSimpleLoaderAndWait(url_loader_factory_.get());
EXPECT_EQ(net::OK, test_helper->simple_url_loader()->NetError());
ASSERT_TRUE(test_helper->simple_url_loader()->CompletionStatus());
EXPECT_EQ(net::OK,
test_helper->simple_url_loader()->CompletionStatus()->error_code);
if (GetParam() != SimpleLoaderTestHelper::DownloadType::HEADERS_ONLY) {
ASSERT_TRUE(test_helper->response_body());
......@@ -1101,6 +1142,7 @@ TEST_P(SimpleURLLoaderTest, DisconnectedURLLoader) {
test_helper->StartSimpleLoaderAndWait(url_loader_factory_.get());
EXPECT_EQ(net::ERR_FAILED, test_helper->simple_url_loader()->NetError());
EXPECT_FALSE(test_helper->simple_url_loader()->CompletionStatus());
EXPECT_FALSE(test_helper->simple_url_loader()->ResponseInfo());
}
......@@ -1112,6 +1154,7 @@ TEST_P(SimpleURLLoaderTest, HttpErrorStatusCodeResponse) {
EXPECT_EQ(net::ERR_HTTP_RESPONSE_CODE_FAILURE,
test_helper->simple_url_loader()->NetError());
EXPECT_FALSE(test_helper->simple_url_loader()->CompletionStatus());
EXPECT_EQ(400, test_helper->GetResponseCode());
EXPECT_FALSE(test_helper->response_body());
EXPECT_EQ(0, test_helper->simple_url_loader()->GetContentSize());
......@@ -1126,12 +1169,18 @@ TEST_P(SimpleURLLoaderTest, HttpErrorStatusCodeResponseAllowed) {
test_helper->StartSimpleLoaderAndWait(url_loader_factory_.get());
EXPECT_EQ(net::OK, test_helper->simple_url_loader()->NetError());
ASSERT_TRUE(test_helper->simple_url_loader()->CompletionStatus());
EXPECT_EQ(net::OK,
test_helper->simple_url_loader()->CompletionStatus()->error_code);
EXPECT_EQ(400, test_helper->GetResponseCode());
if (GetParam() != SimpleLoaderTestHelper::DownloadType::HEADERS_ONLY) {
ASSERT_TRUE(test_helper->response_body());
EXPECT_EQ("Echo", *test_helper->response_body());
EXPECT_EQ(4, test_helper->simple_url_loader()->GetContentSize());
EXPECT_EQ(4, test_helper->simple_url_loader()
->CompletionStatus()
->decoded_body_length);
}
}
......@@ -1141,6 +1190,9 @@ TEST_P(SimpleURLLoaderTest, EmptyResponseBody) {
test_helper->StartSimpleLoaderAndWait(url_loader_factory_.get());
EXPECT_EQ(net::OK, test_helper->simple_url_loader()->NetError());
ASSERT_TRUE(test_helper->simple_url_loader()->CompletionStatus());
EXPECT_EQ(net::OK,
test_helper->simple_url_loader()->CompletionStatus()->error_code);
EXPECT_EQ(204, test_helper->GetResponseCode());
if (GetParam() != SimpleLoaderTestHelper::DownloadType::HEADERS_ONLY) {
......@@ -1148,6 +1200,9 @@ TEST_P(SimpleURLLoaderTest, EmptyResponseBody) {
// A response body is sent from the NetworkService, but it's empty.
EXPECT_EQ("", *test_helper->response_body());
EXPECT_EQ(0, test_helper->simple_url_loader()->GetContentSize());
EXPECT_EQ(0, test_helper->simple_url_loader()
->CompletionStatus()
->decoded_body_length);
}
}
......@@ -1163,6 +1218,9 @@ TEST_P(SimpleURLLoaderTest, BigResponseBody) {
test_helper->StartSimpleLoaderAndWait(url_loader_factory_.get());
EXPECT_EQ(net::OK, test_helper->simple_url_loader()->NetError());
ASSERT_TRUE(test_helper->simple_url_loader()->CompletionStatus());
EXPECT_EQ(net::OK,
test_helper->simple_url_loader()->CompletionStatus()->error_code);
EXPECT_EQ(200, test_helper->GetResponseCode());
if (GetParam() != SimpleLoaderTestHelper::DownloadType::HEADERS_ONLY) {
......@@ -1171,6 +1229,9 @@ TEST_P(SimpleURLLoaderTest, BigResponseBody) {
EXPECT_EQ(std::string(kResponseSize, 'a'), *test_helper->response_body());
EXPECT_EQ(kResponseSize,
test_helper->simple_url_loader()->GetContentSize());
EXPECT_EQ(kResponseSize, test_helper->simple_url_loader()
->CompletionStatus()
->decoded_body_length);
}
}
......@@ -1187,6 +1248,9 @@ TEST_P(SimpleURLLoaderTest, ResponseBodyWithSizeMatchingLimit) {
kResponseSize);
EXPECT_EQ(net::OK, test_helper->simple_url_loader()->NetError());
ASSERT_TRUE(test_helper->simple_url_loader()->CompletionStatus());
EXPECT_EQ(net::OK,
test_helper->simple_url_loader()->CompletionStatus()->error_code);
EXPECT_EQ(200, test_helper->GetResponseCode());
if (GetParam() != SimpleLoaderTestHelper::DownloadType::HEADERS_ONLY) {
......@@ -1195,6 +1259,9 @@ TEST_P(SimpleURLLoaderTest, ResponseBodyWithSizeMatchingLimit) {
EXPECT_EQ(std::string(kResponseSize, 'a'), *test_helper->response_body());
EXPECT_EQ(kResponseSize,
test_helper->simple_url_loader()->GetContentSize());
EXPECT_EQ(kResponseSize, test_helper->simple_url_loader()
->CompletionStatus()
->decoded_body_length);
}
}
......@@ -1212,6 +1279,9 @@ TEST_P(SimpleURLLoaderTest, ResponseBodyWithSizeBelowLimit) {
kMaxResponseSize);
EXPECT_EQ(net::OK, test_helper->simple_url_loader()->NetError());
ASSERT_TRUE(test_helper->simple_url_loader()->CompletionStatus());
EXPECT_EQ(net::OK,
test_helper->simple_url_loader()->CompletionStatus()->error_code);
EXPECT_EQ(200, test_helper->GetResponseCode());
if (GetParam() != SimpleLoaderTestHelper::DownloadType::HEADERS_ONLY) {
......@@ -1220,6 +1290,9 @@ TEST_P(SimpleURLLoaderTest, ResponseBodyWithSizeBelowLimit) {
EXPECT_EQ(std::string(kResponseSize, 'a'), *test_helper->response_body());
EXPECT_EQ(kResponseSize,
test_helper->simple_url_loader()->GetContentSize());
EXPECT_EQ(kResponseSize, test_helper->simple_url_loader()
->CompletionStatus()
->decoded_body_length);
}
}
......@@ -1237,7 +1310,9 @@ TEST_P(SimpleURLLoaderTest, ResponseBodyWithSizeAboveLimit) {
if (GetParam() == SimpleLoaderTestHelper::DownloadType::HEADERS_ONLY) {
EXPECT_EQ(net::OK, test_helper->simple_url_loader()->NetError());
EXPECT_TRUE(test_helper->simple_url_loader()->CompletionStatus());
} else {
EXPECT_FALSE(test_helper->simple_url_loader()->CompletionStatus());
EXPECT_EQ(net::ERR_INSUFFICIENT_RESOURCES,
test_helper->simple_url_loader()->NetError());
EXPECT_EQ(0, test_helper->simple_url_loader()->GetContentSize());
......@@ -1261,9 +1336,11 @@ TEST_P(SimpleURLLoaderTest, ResponseBodyWithSizeAboveLimitPartialResponse) {
kMaxResponseSize);
if (GetParam() == SimpleLoaderTestHelper::DownloadType::HEADERS_ONLY) {
EXPECT_TRUE(test_helper->simple_url_loader()->CompletionStatus());
EXPECT_EQ(net::OK, test_helper->simple_url_loader()->NetError());
EXPECT_FALSE(test_helper->response_body());
} else {
EXPECT_FALSE(test_helper->simple_url_loader()->CompletionStatus());
EXPECT_EQ(net::ERR_INSUFFICIENT_RESOURCES,
test_helper->simple_url_loader()->NetError());
ASSERT_TRUE(test_helper->response_body());
......@@ -1290,6 +1367,9 @@ TEST_P(SimpleURLLoaderTest, BigResponseBodyWithSizeMatchingLimit) {
kResponseSize);
EXPECT_EQ(net::OK, test_helper->simple_url_loader()->NetError());
ASSERT_TRUE(test_helper->simple_url_loader()->CompletionStatus());
EXPECT_EQ(net::OK,
test_helper->simple_url_loader()->CompletionStatus()->error_code);
if (GetParam() != SimpleLoaderTestHelper::DownloadType::HEADERS_ONLY) {
ASSERT_TRUE(test_helper->response_body());
......@@ -1297,6 +1377,9 @@ TEST_P(SimpleURLLoaderTest, BigResponseBodyWithSizeMatchingLimit) {
EXPECT_EQ(std::string(kResponseSize, 'a'), *test_helper->response_body());
EXPECT_EQ(kResponseSize,
test_helper->simple_url_loader()->GetContentSize());
EXPECT_EQ(kResponseSize, test_helper->simple_url_loader()
->CompletionStatus()
->decoded_body_length);
}
}
......@@ -1314,6 +1397,9 @@ TEST_P(SimpleURLLoaderTest, BigResponseBodyWithSizeBelowLimit) {
kMaxResponseSize);
EXPECT_EQ(net::OK, test_helper->simple_url_loader()->NetError());
ASSERT_TRUE(test_helper->simple_url_loader()->CompletionStatus());
EXPECT_EQ(net::OK,
test_helper->simple_url_loader()->CompletionStatus()->error_code);
if (GetParam() != SimpleLoaderTestHelper::DownloadType::HEADERS_ONLY) {
ASSERT_TRUE(test_helper->response_body());
......@@ -1321,6 +1407,9 @@ TEST_P(SimpleURLLoaderTest, BigResponseBodyWithSizeBelowLimit) {
EXPECT_EQ(std::string(kResponseSize, 'a'), *test_helper->response_body());
EXPECT_EQ(kResponseSize,
test_helper->simple_url_loader()->GetContentSize());
EXPECT_EQ(kResponseSize, test_helper->simple_url_loader()
->CompletionStatus()
->decoded_body_length);
}
}
......@@ -1338,9 +1427,13 @@ TEST_P(SimpleURLLoaderTest, BigResponseBodyWithSizeAboveLimit) {
if (GetParam() == SimpleLoaderTestHelper::DownloadType::HEADERS_ONLY) {
EXPECT_EQ(net::OK, test_helper->simple_url_loader()->NetError());
ASSERT_TRUE(test_helper->simple_url_loader()->CompletionStatus());
EXPECT_EQ(net::OK,
test_helper->simple_url_loader()->CompletionStatus()->error_code);
} else {
EXPECT_EQ(net::ERR_INSUFFICIENT_RESOURCES,
test_helper->simple_url_loader()->NetError());
EXPECT_FALSE(test_helper->simple_url_loader()->CompletionStatus());
EXPECT_EQ(0, test_helper->simple_url_loader()->GetContentSize());
}
EXPECT_FALSE(test_helper->response_body());
......@@ -1362,10 +1455,14 @@ TEST_P(SimpleURLLoaderTest, BigResponseBodyWithSizeAboveLimitPartialResponse) {
if (GetParam() == SimpleLoaderTestHelper::DownloadType::HEADERS_ONLY) {
EXPECT_EQ(net::OK, test_helper->simple_url_loader()->NetError());
ASSERT_TRUE(test_helper->simple_url_loader()->CompletionStatus());
EXPECT_EQ(net::OK,
test_helper->simple_url_loader()->CompletionStatus()->error_code);
EXPECT_FALSE(test_helper->response_body());
} else {
EXPECT_EQ(net::ERR_INSUFFICIENT_RESOURCES,
test_helper->simple_url_loader()->NetError());
EXPECT_FALSE(test_helper->simple_url_loader()->CompletionStatus());
ASSERT_TRUE(test_helper->response_body());
EXPECT_EQ(std::string(kMaxResponseSize, 'a'),
*test_helper->response_body());
......@@ -1382,9 +1479,15 @@ TEST_P(SimpleURLLoaderTest, NetErrorBeforeHeaders) {
EXPECT_EQ(net::ERR_EMPTY_RESPONSE,
test_helper->simple_url_loader()->NetError());
ASSERT_TRUE(test_helper->simple_url_loader()->CompletionStatus());
EXPECT_EQ(net::ERR_EMPTY_RESPONSE,
test_helper->simple_url_loader()->CompletionStatus()->error_code);
EXPECT_FALSE(test_helper->simple_url_loader()->ResponseInfo());
EXPECT_FALSE(test_helper->response_body());
EXPECT_EQ(0, test_helper->simple_url_loader()->GetContentSize());
EXPECT_EQ(0, test_helper->simple_url_loader()
->CompletionStatus()
->decoded_body_length);
}
TEST_P(SimpleURLLoaderTest, NetErrorBeforeHeadersWithPartialResults) {
......@@ -1399,8 +1502,14 @@ TEST_P(SimpleURLLoaderTest, NetErrorBeforeHeadersWithPartialResults) {
EXPECT_EQ(net::ERR_EMPTY_RESPONSE,
test_helper->simple_url_loader()->NetError());
ASSERT_TRUE(test_helper->simple_url_loader()->CompletionStatus());
EXPECT_EQ(net::ERR_EMPTY_RESPONSE,
test_helper->simple_url_loader()->CompletionStatus()->error_code);
EXPECT_FALSE(test_helper->simple_url_loader()->ResponseInfo());
EXPECT_EQ(0, test_helper->simple_url_loader()->GetContentSize());
EXPECT_EQ(0, test_helper->simple_url_loader()
->CompletionStatus()
->decoded_body_length);
}
TEST_P(SimpleURLLoaderTest, NetErrorAfterHeaders) {
......@@ -1410,9 +1519,15 @@ TEST_P(SimpleURLLoaderTest, NetErrorAfterHeaders) {
EXPECT_EQ(net::ERR_CONTENT_DECODING_FAILED,
test_helper->simple_url_loader()->NetError());
ASSERT_TRUE(test_helper->simple_url_loader()->CompletionStatus());
EXPECT_EQ(net::ERR_CONTENT_DECODING_FAILED,
test_helper->simple_url_loader()->CompletionStatus()->error_code);
EXPECT_EQ(200, test_helper->GetResponseCode());
EXPECT_FALSE(test_helper->response_body());
EXPECT_EQ(0, test_helper->simple_url_loader()->GetContentSize());
EXPECT_EQ(0, test_helper->simple_url_loader()
->CompletionStatus()
->decoded_body_length);
}
TEST_P(SimpleURLLoaderTest, NetErrorAfterHeadersWithPartialResults) {
......@@ -1424,12 +1539,18 @@ TEST_P(SimpleURLLoaderTest, NetErrorAfterHeadersWithPartialResults) {
EXPECT_EQ(net::ERR_CONTENT_DECODING_FAILED,
test_helper->simple_url_loader()->NetError());
ASSERT_TRUE(test_helper->simple_url_loader()->CompletionStatus());
EXPECT_EQ(net::ERR_CONTENT_DECODING_FAILED,
test_helper->simple_url_loader()->CompletionStatus()->error_code);
EXPECT_EQ(200, test_helper->GetResponseCode());
if (GetParam() != SimpleLoaderTestHelper::DownloadType::HEADERS_ONLY) {
ASSERT_TRUE(test_helper->response_body());
EXPECT_EQ("", *test_helper->response_body());
EXPECT_EQ(0, test_helper->simple_url_loader()->GetContentSize());
EXPECT_EQ(0, test_helper->simple_url_loader()
->CompletionStatus()
->decoded_body_length);
}
}
......@@ -1440,10 +1561,17 @@ TEST_P(SimpleURLLoaderTest, TruncatedBody) {
EXPECT_EQ(net::ERR_CONTENT_LENGTH_MISMATCH,
test_helper->simple_url_loader()->NetError());
ASSERT_TRUE(test_helper->simple_url_loader()->CompletionStatus());
EXPECT_EQ(net::ERR_CONTENT_LENGTH_MISMATCH,
test_helper->simple_url_loader()->CompletionStatus()->error_code);
EXPECT_EQ(200, test_helper->GetResponseCode());
EXPECT_FALSE(test_helper->response_body());
EXPECT_EQ(static_cast<int64_t>(strlen(kTruncatedBody)),
test_helper->simple_url_loader()->GetContentSize());
EXPECT_EQ(static_cast<int64_t>(strlen(kTruncatedBody)),
test_helper->simple_url_loader()
->CompletionStatus()
->decoded_body_length);
}
TEST_P(SimpleURLLoaderTest, TruncatedBodyWithPartialResults) {
......@@ -1454,12 +1582,19 @@ TEST_P(SimpleURLLoaderTest, TruncatedBodyWithPartialResults) {
EXPECT_EQ(net::ERR_CONTENT_LENGTH_MISMATCH,
test_helper->simple_url_loader()->NetError());
ASSERT_TRUE(test_helper->simple_url_loader()->CompletionStatus());
EXPECT_EQ(net::ERR_CONTENT_LENGTH_MISMATCH,
test_helper->simple_url_loader()->CompletionStatus()->error_code);
EXPECT_EQ(200, test_helper->GetResponseCode());
if (GetParam() != SimpleLoaderTestHelper::DownloadType::HEADERS_ONLY) {
ASSERT_TRUE(test_helper->response_body());
EXPECT_EQ(static_cast<int64_t>(strlen(kTruncatedBody)),
test_helper->simple_url_loader()->GetContentSize());
EXPECT_EQ(static_cast<int64_t>(strlen(kTruncatedBody)),
test_helper->simple_url_loader()
->CompletionStatus()
->decoded_body_length);
}
}
......@@ -1478,6 +1613,7 @@ TEST_P(SimpleURLLoaderTest, DestroyServiceBeforeResponseStarts) {
test_helper->Wait();
EXPECT_EQ(net::ERR_FAILED, test_helper->simple_url_loader()->NetError());
EXPECT_FALSE(test_helper->simple_url_loader()->CompletionStatus());
EXPECT_FALSE(test_helper->response_body());
ASSERT_FALSE(test_helper->simple_url_loader()->ResponseInfo());
}
......@@ -1489,6 +1625,9 @@ TEST_P(SimpleURLLoaderTest, UploadShortString) {
"text/plain");
test_helper->StartSimpleLoaderAndWait(url_loader_factory_.get());
EXPECT_EQ(net::OK, test_helper->simple_url_loader()->NetError());
ASSERT_TRUE(test_helper->simple_url_loader()->CompletionStatus());
EXPECT_EQ(net::OK,
test_helper->simple_url_loader()->CompletionStatus()->error_code);
if (GetParam() != SimpleLoaderTestHelper::DownloadType::HEADERS_ONLY) {
ASSERT_TRUE(test_helper->response_body());
......@@ -1504,6 +1643,9 @@ TEST_P(SimpleURLLoaderTest, UploadLongString) {
"text/plain");
test_helper->StartSimpleLoaderAndWait(url_loader_factory_.get());
EXPECT_EQ(net::OK, test_helper->simple_url_loader()->NetError());
ASSERT_TRUE(test_helper->simple_url_loader()->CompletionStatus());
EXPECT_EQ(net::OK,
test_helper->simple_url_loader()->CompletionStatus()->error_code);
if (GetParam() != SimpleLoaderTestHelper::DownloadType::HEADERS_ONLY) {
ASSERT_TRUE(test_helper->response_body());
......@@ -1517,6 +1659,9 @@ TEST_P(SimpleURLLoaderTest, UploadEmptyString) {
test_helper->simple_url_loader()->AttachStringForUpload("", "text/plain");
test_helper->StartSimpleLoaderAndWait(url_loader_factory_.get());
EXPECT_EQ(net::OK, test_helper->simple_url_loader()->NetError());
ASSERT_TRUE(test_helper->simple_url_loader()->CompletionStatus());
EXPECT_EQ(net::OK,
test_helper->simple_url_loader()->CompletionStatus()->error_code);
if (GetParam() != SimpleLoaderTestHelper::DownloadType::HEADERS_ONLY) {
ASSERT_TRUE(test_helper->response_body());
......@@ -1528,6 +1673,9 @@ TEST_P(SimpleURLLoaderTest, UploadEmptyString) {
test_helper->simple_url_loader()->AttachStringForUpload("", "text/plain");
test_helper->StartSimpleLoaderAndWait(url_loader_factory_.get());
EXPECT_EQ(net::OK, test_helper->simple_url_loader()->NetError());
ASSERT_TRUE(test_helper->simple_url_loader()->CompletionStatus());
EXPECT_EQ(net::OK,
test_helper->simple_url_loader()->CompletionStatus()->error_code);
if (GetParam() != SimpleLoaderTestHelper::DownloadType::HEADERS_ONLY) {
ASSERT_TRUE(test_helper->response_body());
......@@ -1547,6 +1695,9 @@ TEST_P(SimpleURLLoaderTest, UploadShortStringWithRetry) {
1, SimpleURLLoader::RETRY_ON_5XX);
test_helper->StartSimpleLoaderAndWait(url_loader_factory_.get());
EXPECT_EQ(net::OK, test_helper->simple_url_loader()->NetError());
ASSERT_TRUE(test_helper->simple_url_loader()->CompletionStatus());
EXPECT_EQ(net::OK,
test_helper->simple_url_loader()->CompletionStatus()->error_code);
if (GetParam() != SimpleLoaderTestHelper::DownloadType::HEADERS_ONLY) {
ASSERT_TRUE(test_helper->response_body());
......@@ -1567,6 +1718,9 @@ TEST_P(SimpleURLLoaderTest, UploadLongStringWithRetry) {
1, SimpleURLLoader::RETRY_ON_5XX);
test_helper->StartSimpleLoaderAndWait(url_loader_factory_.get());
EXPECT_EQ(net::OK, test_helper->simple_url_loader()->NetError());
ASSERT_TRUE(test_helper->simple_url_loader()->CompletionStatus());
EXPECT_EQ(net::OK,
test_helper->simple_url_loader()->CompletionStatus()->error_code);
if (GetParam() != SimpleLoaderTestHelper::DownloadType::HEADERS_ONLY) {
ASSERT_TRUE(test_helper->response_body());
......@@ -1584,6 +1738,9 @@ TEST_P(SimpleURLLoaderTest, UploadFile) {
"text/plain");
test_helper->StartSimpleLoaderAndWait(url_loader_factory_.get());
EXPECT_EQ(net::OK, test_helper->simple_url_loader()->NetError());
ASSERT_TRUE(test_helper->simple_url_loader()->CompletionStatus());
EXPECT_EQ(net::OK,
test_helper->simple_url_loader()->CompletionStatus()->error_code);
if (GetParam() != SimpleLoaderTestHelper::DownloadType::HEADERS_ONLY) {
ASSERT_TRUE(test_helper->response_body());
......@@ -1596,6 +1753,9 @@ TEST_P(SimpleURLLoaderTest, UploadFile) {
"text/plain");
test_helper->StartSimpleLoaderAndWait(url_loader_factory_.get());
EXPECT_EQ(net::OK, test_helper->simple_url_loader()->NetError());
ASSERT_TRUE(test_helper->simple_url_loader()->CompletionStatus());
EXPECT_EQ(net::OK,
test_helper->simple_url_loader()->CompletionStatus()->error_code);
if (GetParam() != SimpleLoaderTestHelper::DownloadType::HEADERS_ONLY) {
ASSERT_TRUE(test_helper->response_body());
......@@ -1616,6 +1776,9 @@ TEST_P(SimpleURLLoaderTest, UploadFileRange) {
GetTestFilePath(), "text/plain", kOffset, kLength);
test_helper->StartSimpleLoaderAndWait(url_loader_factory_.get());
EXPECT_EQ(net::OK, test_helper->simple_url_loader()->NetError());
ASSERT_TRUE(test_helper->simple_url_loader()->CompletionStatus());
EXPECT_EQ(net::OK,
test_helper->simple_url_loader()->CompletionStatus()->error_code);
if (GetParam() != SimpleLoaderTestHelper::DownloadType::HEADERS_ONLY) {
ASSERT_TRUE(test_helper->response_body());
......@@ -1631,6 +1794,9 @@ TEST_P(SimpleURLLoaderTest, UploadFileWithPut) {
"text/plain");
test_helper->StartSimpleLoaderAndWait(url_loader_factory_.get());
EXPECT_EQ(net::OK, test_helper->simple_url_loader()->NetError());
ASSERT_TRUE(test_helper->simple_url_loader()->CompletionStatus());
EXPECT_EQ(net::OK,
test_helper->simple_url_loader()->CompletionStatus()->error_code);
if (GetParam() != SimpleLoaderTestHelper::DownloadType::HEADERS_ONLY) {
ASSERT_TRUE(test_helper->response_body());
......@@ -1643,6 +1809,9 @@ TEST_P(SimpleURLLoaderTest, UploadFileWithPut) {
"text/salted");
test_helper->StartSimpleLoaderAndWait(url_loader_factory_.get());
EXPECT_EQ(net::OK, test_helper->simple_url_loader()->NetError());
ASSERT_TRUE(test_helper->simple_url_loader()->CompletionStatus());
EXPECT_EQ(net::OK,
test_helper->simple_url_loader()->CompletionStatus()->error_code);
if (GetParam() != SimpleLoaderTestHelper::DownloadType::HEADERS_ONLY) {
ASSERT_TRUE(test_helper->response_body());
......@@ -1664,12 +1833,19 @@ TEST_P(SimpleURLLoaderTest, UploadFileWithRetry) {
1, SimpleURLLoader::RETRY_ON_5XX);
test_helper->StartSimpleLoaderAndWait(url_loader_factory_.get());
EXPECT_EQ(net::OK, test_helper->simple_url_loader()->NetError());
ASSERT_TRUE(test_helper->simple_url_loader()->CompletionStatus());
EXPECT_EQ(net::OK,
test_helper->simple_url_loader()->CompletionStatus()->error_code);
if (GetParam() != SimpleLoaderTestHelper::DownloadType::HEADERS_ONLY) {
ASSERT_TRUE(test_helper->response_body());
EXPECT_EQ(GetTestFileContents(), *test_helper->response_body());
EXPECT_EQ(static_cast<int64_t>(GetTestFileContents().size()),
test_helper->simple_url_loader()->GetContentSize());
EXPECT_EQ(static_cast<int64_t>(GetTestFileContents().size()),
test_helper->simple_url_loader()
->CompletionStatus()
->decoded_body_length);
}
if (GetParam() == SimpleLoaderTestHelper::DownloadType::AS_STREAM)
......@@ -1689,9 +1865,15 @@ TEST_P(SimpleURLLoaderTest, UploadNonexistantFile) {
test_helper->StartSimpleLoaderAndWait(url_loader_factory_.get());
EXPECT_EQ(net::ERR_FILE_NOT_FOUND,
test_helper->simple_url_loader()->NetError());
ASSERT_TRUE(test_helper->simple_url_loader()->CompletionStatus());
EXPECT_EQ(net::ERR_FILE_NOT_FOUND,
test_helper->simple_url_loader()->CompletionStatus()->error_code);
EXPECT_FALSE(test_helper->simple_url_loader()->ResponseInfo());
EXPECT_FALSE(test_helper->response_body());
EXPECT_EQ(0, test_helper->simple_url_loader()->GetContentSize());
EXPECT_EQ(0, test_helper->simple_url_loader()
->CompletionStatus()
->decoded_body_length);
}
// Test case where uploading a file is canceled before the URLLoader is started
......@@ -2142,6 +2324,7 @@ TEST_P(SimpleURLLoaderTest, ResponseCompleteBeforeReceivedResponse) {
loader_factory.RunTest(test_helper.get());
EXPECT_EQ(net::ERR_UNEXPECTED, test_helper->simple_url_loader()->NetError());
EXPECT_FALSE(test_helper->simple_url_loader()->CompletionStatus());
EXPECT_FALSE(test_helper->simple_url_loader()->ResponseInfo());
EXPECT_FALSE(test_helper->response_body());
}
......@@ -2157,6 +2340,7 @@ TEST_P(SimpleURLLoaderTest, ResponseCompleteAfterReceivedResponse) {
loader_factory.RunTest(test_helper.get());
EXPECT_EQ(net::ERR_UNEXPECTED, test_helper->simple_url_loader()->NetError());
EXPECT_FALSE(test_helper->simple_url_loader()->CompletionStatus());
EXPECT_EQ(200, test_helper->GetResponseCode());
EXPECT_FALSE(test_helper->response_body());
}
......@@ -2170,6 +2354,7 @@ TEST_P(SimpleURLLoaderTest, CloseClientPipeBeforeBodyStarts) {
loader_factory.RunTest(test_helper.get());
EXPECT_EQ(net::ERR_FAILED, test_helper->simple_url_loader()->NetError());
EXPECT_FALSE(test_helper->simple_url_loader()->CompletionStatus());
EXPECT_EQ(200, test_helper->GetResponseCode());
EXPECT_FALSE(test_helper->response_body());
}
......@@ -2242,9 +2427,15 @@ TEST_P(SimpleURLLoaderTest, CloseClientPipeOrder) {
TestLoaderEvent::kResponseCompleteFailed) {
EXPECT_EQ(net::ERR_TIMED_OUT,
test_helper->simple_url_loader()->NetError());
ASSERT_TRUE(test_helper->simple_url_loader()->CompletionStatus());
EXPECT_EQ(net::ERR_TIMED_OUT, test_helper->simple_url_loader()
->CompletionStatus()
->error_code);
} else {
EXPECT_EQ(net::ERR_FAILED,
test_helper->simple_url_loader()->NetError());
EXPECT_FALSE(
test_helper->simple_url_loader()->CompletionStatus());
}
if (!allow_partial_results) {
EXPECT_FALSE(test_helper->response_body());
......@@ -2256,6 +2447,10 @@ TEST_P(SimpleURLLoaderTest, CloseClientPipeOrder) {
}
} else {
EXPECT_EQ(net::OK, test_helper->simple_url_loader()->NetError());
ASSERT_TRUE(test_helper->simple_url_loader()->CompletionStatus());
EXPECT_EQ(net::OK, test_helper->simple_url_loader()
->CompletionStatus()
->error_code);
if (GetParam() !=
SimpleLoaderTestHelper::DownloadType::HEADERS_ONLY) {
......@@ -2281,6 +2476,9 @@ TEST_P(SimpleURLLoaderTest, ErrorAndCloseClientPipeBeforeBodyStarts) {
loader_factory.RunTest(test_helper.get());
EXPECT_EQ(net::ERR_TIMED_OUT, test_helper->simple_url_loader()->NetError());
ASSERT_TRUE(test_helper->simple_url_loader()->CompletionStatus());
EXPECT_EQ(net::ERR_TIMED_OUT,
test_helper->simple_url_loader()->CompletionStatus()->error_code);
EXPECT_EQ(200, test_helper->GetResponseCode());
EXPECT_FALSE(test_helper->response_body());
}
......@@ -2297,6 +2495,9 @@ TEST_P(SimpleURLLoaderTest, SuccessAndCloseClientPipeBeforeBodyComplete) {
loader_factory.RunTest(test_helper.get());
EXPECT_EQ(net::OK, test_helper->simple_url_loader()->NetError());
ASSERT_TRUE(test_helper->simple_url_loader()->CompletionStatus());
EXPECT_EQ(net::OK,
test_helper->simple_url_loader()->CompletionStatus()->error_code);
EXPECT_EQ(200, test_helper->GetResponseCode());
if (GetParam() != SimpleLoaderTestHelper::DownloadType::HEADERS_ONLY) {
......@@ -2317,6 +2518,9 @@ TEST_P(SimpleURLLoaderTest, SuccessAndCloseClientPipeAfterBodyComplete) {
loader_factory.RunTest(test_helper.get());
EXPECT_EQ(net::OK, test_helper->simple_url_loader()->NetError());
ASSERT_TRUE(test_helper->simple_url_loader()->CompletionStatus());
EXPECT_EQ(net::OK,
test_helper->simple_url_loader()->CompletionStatus()->error_code);
EXPECT_EQ(200, test_helper->GetResponseCode());
if (GetParam() != SimpleLoaderTestHelper::DownloadType::HEADERS_ONLY) {
......@@ -2334,11 +2538,12 @@ TEST_P(SimpleURLLoaderTest, DoubleReceivedResponse) {
loader_factory.RunTest(test_helper.get());
EXPECT_EQ(net::ERR_UNEXPECTED, test_helper->simple_url_loader()->NetError());
EXPECT_FALSE(test_helper->simple_url_loader()->CompletionStatus());
EXPECT_EQ(200, test_helper->GetResponseCode());
EXPECT_FALSE(test_helper->response_body());
}
TEST_P(SimpleURLLoaderTest, RedirectAfterReseivedResponse) {
TEST_P(SimpleURLLoaderTest, RedirectAfterReceivedResponse) {
MockURLLoaderFactory loader_factory(&task_environment_);
loader_factory.AddEvents(
{TestLoaderEvent::kReceivedResponse, TestLoaderEvent::kReceivedRedirect});
......@@ -2347,6 +2552,7 @@ TEST_P(SimpleURLLoaderTest, RedirectAfterReseivedResponse) {
loader_factory.RunTest(test_helper.get());
EXPECT_EQ(net::ERR_UNEXPECTED, test_helper->simple_url_loader()->NetError());
EXPECT_FALSE(test_helper->simple_url_loader()->CompletionStatus());
EXPECT_EQ(200, test_helper->GetResponseCode());
EXPECT_FALSE(test_helper->response_body());
}
......@@ -2359,6 +2565,7 @@ TEST_P(SimpleURLLoaderTest, UnexpectedBodyBufferReceived) {
loader_factory.RunTest(test_helper.get());
EXPECT_EQ(net::ERR_UNEXPECTED, test_helper->simple_url_loader()->NetError());
EXPECT_FALSE(test_helper->simple_url_loader()->CompletionStatus());
EXPECT_FALSE(test_helper->simple_url_loader()->ResponseInfo());
EXPECT_FALSE(test_helper->response_body());
}
......@@ -2373,6 +2580,7 @@ TEST_P(SimpleURLLoaderTest, DoubleBodyBufferReceived) {
loader_factory.RunTest(test_helper.get());
EXPECT_EQ(net::ERR_UNEXPECTED, test_helper->simple_url_loader()->NetError());
EXPECT_FALSE(test_helper->simple_url_loader()->CompletionStatus());
EXPECT_EQ(200, test_helper->GetResponseCode());
EXPECT_FALSE(test_helper->response_body());
}
......@@ -2387,6 +2595,7 @@ TEST_P(SimpleURLLoaderTest, UnexpectedMessageAfterBodyStarts) {
loader_factory.RunTest(test_helper.get());
EXPECT_EQ(net::ERR_UNEXPECTED, test_helper->simple_url_loader()->NetError());
EXPECT_FALSE(test_helper->simple_url_loader()->CompletionStatus());
EXPECT_EQ(200, test_helper->GetResponseCode());
EXPECT_FALSE(test_helper->response_body());
}
......@@ -2401,6 +2610,7 @@ TEST_P(SimpleURLLoaderTest, UnexpectedMessageAfterBodyStarts2) {
loader_factory.RunTest(test_helper.get());
EXPECT_EQ(net::ERR_UNEXPECTED, test_helper->simple_url_loader()->NetError());
EXPECT_FALSE(test_helper->simple_url_loader()->CompletionStatus());
EXPECT_EQ(200, test_helper->GetResponseCode());
EXPECT_FALSE(test_helper->response_body());
}
......@@ -2416,6 +2626,7 @@ TEST_P(SimpleURLLoaderTest, UnexpectedMessageAfterBodyComplete) {
loader_factory.RunTest(test_helper.get());
EXPECT_EQ(net::ERR_UNEXPECTED, test_helper->simple_url_loader()->NetError());
EXPECT_FALSE(test_helper->simple_url_loader()->CompletionStatus());
EXPECT_EQ(200, test_helper->GetResponseCode());
EXPECT_FALSE(test_helper->response_body());
}
......@@ -2432,6 +2643,7 @@ TEST_P(SimpleURLLoaderTest, MoreDataThanExpected) {
loader_factory.RunTest(test_helper.get());
EXPECT_EQ(net::ERR_UNEXPECTED, test_helper->simple_url_loader()->NetError());
EXPECT_FALSE(test_helper->simple_url_loader()->CompletionStatus());
EXPECT_EQ(200, test_helper->GetResponseCode());
EXPECT_FALSE(test_helper->response_body());
}
......@@ -2527,6 +2739,10 @@ TEST_P(SimpleURLLoaderTest, RetryOn5xx) {
if (test_case.expect_success) {
EXPECT_EQ(net::OK, test_helper->simple_url_loader()->NetError());
ASSERT_TRUE(test_helper->simple_url_loader()->CompletionStatus());
EXPECT_EQ(
net::OK,
test_helper->simple_url_loader()->CompletionStatus()->error_code);
EXPECT_EQ(200, test_helper->GetResponseCode());
if (GetParam() != SimpleLoaderTestHelper::DownloadType::HEADERS_ONLY) {
......@@ -2611,6 +2827,10 @@ TEST_P(SimpleURLLoaderTest, RetryOnNameNotResolved) {
if (test_case.expect_success) {
EXPECT_EQ(net::OK, test_helper->simple_url_loader()->NetError());
ASSERT_TRUE(test_helper->simple_url_loader()->CompletionStatus());
EXPECT_EQ(
net::OK,
test_helper->simple_url_loader()->CompletionStatus()->error_code);
EXPECT_EQ(200, test_helper->GetResponseCode());
if (GetParam() != SimpleLoaderTestHelper::DownloadType::HEADERS_ONLY) {
......@@ -2620,6 +2840,10 @@ TEST_P(SimpleURLLoaderTest, RetryOnNameNotResolved) {
} else {
EXPECT_EQ(net::ERR_NAME_NOT_RESOLVED,
test_helper->simple_url_loader()->NetError());
ASSERT_TRUE(test_helper->simple_url_loader()->CompletionStatus());
EXPECT_EQ(
net::ERR_NAME_NOT_RESOLVED,
test_helper->simple_url_loader()->CompletionStatus()->error_code);
}
EXPECT_EQ(static_cast<size_t>(test_case.expected_num_requests),
......@@ -2783,6 +3007,10 @@ TEST_P(SimpleURLLoaderTest, RetryOnNetworkChange) {
if (test_case.expect_success) {
EXPECT_EQ(net::OK, test_helper->simple_url_loader()->NetError());
ASSERT_TRUE(test_helper->simple_url_loader()->CompletionStatus());
EXPECT_EQ(
net::OK,
test_helper->simple_url_loader()->CompletionStatus()->error_code);
EXPECT_EQ(200, test_helper->GetResponseCode());
if (GetParam() != SimpleLoaderTestHelper::DownloadType::HEADERS_ONLY) {
......@@ -2792,6 +3020,10 @@ TEST_P(SimpleURLLoaderTest, RetryOnNetworkChange) {
} else {
EXPECT_EQ(net::ERR_NETWORK_CHANGED,
test_helper->simple_url_loader()->NetError());
ASSERT_TRUE(test_helper->simple_url_loader()->CompletionStatus());
EXPECT_EQ(
net::ERR_NETWORK_CHANGED,
test_helper->simple_url_loader()->CompletionStatus()->error_code);
EXPECT_FALSE(test_helper->response_body());
}
......@@ -2826,6 +3058,9 @@ TEST_P(SimpleURLLoaderTest, RetryOnNetworkChange) {
loader_factory.RunTest(test_helper.get());
EXPECT_EQ(net::ERR_TIMED_OUT, test_helper->simple_url_loader()->NetError());
ASSERT_TRUE(test_helper->simple_url_loader()->CompletionStatus());
EXPECT_EQ(net::ERR_TIMED_OUT,
test_helper->simple_url_loader()->CompletionStatus()->error_code);
EXPECT_FALSE(test_helper->response_body());
EXPECT_EQ(1u, loader_factory.requested_urls().size());
......@@ -2849,6 +3084,7 @@ TEST_P(SimpleURLLoaderTest, RetryWithUnboundFactory) {
1, SimpleURLLoader::RETRY_ON_NETWORK_CHANGE);
loader_factory.RunTest(test_helper.get());
EXPECT_EQ(net::ERR_FAILED, test_helper->simple_url_loader()->NetError());
EXPECT_FALSE(test_helper->simple_url_loader()->CompletionStatus());
EXPECT_FALSE(test_helper->response_body());
// Retry is still called, before the dead factory is discovered.
......@@ -2875,6 +3111,9 @@ TEST_P(SimpleURLLoaderTest, UploadLongStringStartReadTwice) {
loader_factory.RunTest(test_helper.get());
EXPECT_EQ(net::OK, test_helper->simple_url_loader()->NetError());
ASSERT_TRUE(test_helper->simple_url_loader()->CompletionStatus());
EXPECT_EQ(net::OK,
test_helper->simple_url_loader()->CompletionStatus()->error_code);
if (GetParam() != SimpleLoaderTestHelper::DownloadType::HEADERS_ONLY) {
ASSERT_TRUE(test_helper->response_body());
EXPECT_EQ("", *test_helper->response_body());
......@@ -2904,6 +3143,9 @@ TEST_P(SimpleURLLoaderTest,
loader_factory.RunTest(test_helper.get());
EXPECT_EQ(net::OK, test_helper->simple_url_loader()->NetError());
ASSERT_TRUE(test_helper->simple_url_loader()->CompletionStatus());
EXPECT_EQ(net::OK,
test_helper->simple_url_loader()->CompletionStatus()->error_code);
if (GetParam() != SimpleLoaderTestHelper::DownloadType::HEADERS_ONLY) {
ASSERT_TRUE(test_helper->response_body());
......@@ -2922,6 +3164,9 @@ TEST_P(SimpleURLLoaderTest, GetFinalURL) {
test_helper->StartSimpleLoaderAndWait(url_loader_factory_.get());
EXPECT_EQ(net::OK, test_helper->simple_url_loader()->NetError());
ASSERT_TRUE(test_helper->simple_url_loader()->CompletionStatus());
EXPECT_EQ(net::OK,
test_helper->simple_url_loader()->CompletionStatus()->error_code);
EXPECT_EQ(url, test_helper->simple_url_loader()->GetFinalURL());
}
......@@ -2933,6 +3178,9 @@ TEST_P(SimpleURLLoaderTest, GetFinalURLAfterRedirect) {
test_helper->StartSimpleLoaderAndWait(url_loader_factory_.get());
EXPECT_EQ(net::OK, test_helper->simple_url_loader()->NetError());
ASSERT_TRUE(test_helper->simple_url_loader()->CompletionStatus());
EXPECT_EQ(net::OK,
test_helper->simple_url_loader()->CompletionStatus()->error_code);
EXPECT_EQ(url, test_helper->simple_url_loader()->GetFinalURL());
}
......@@ -2977,6 +3225,9 @@ TEST_F(SimpleURLLoaderFileTest, OverwriteFile) {
test_helper->StartSimpleLoaderAndWait(url_loader_factory_.get());
EXPECT_EQ(net::OK, test_helper->simple_url_loader()->NetError());
ASSERT_TRUE(test_helper->simple_url_loader()->CompletionStatus());
EXPECT_EQ(net::OK,
test_helper->simple_url_loader()->CompletionStatus()->error_code);
ASSERT_TRUE(test_helper->simple_url_loader()->ResponseInfo());
ASSERT_TRUE(test_helper->response_body());
EXPECT_EQ("Echo", *test_helper->response_body());
......@@ -2998,6 +3249,7 @@ TEST_F(SimpleURLLoaderFileTest, FileCreateError) {
EXPECT_EQ(net::ERR_ACCESS_DENIED,
test_helper->simple_url_loader()->NetError());
EXPECT_FALSE(test_helper->simple_url_loader()->CompletionStatus());
EXPECT_TRUE(test_helper->simple_url_loader()->ResponseInfo());
EXPECT_FALSE(test_helper->response_body());
}
......@@ -3086,6 +3338,9 @@ TEST_F(SimpleURLLoaderStreamTest, OnDataReceivedCompletesAsync) {
test_helper->StartSimpleLoaderAndWait(url_loader_factory_.get());
EXPECT_EQ(net::OK, test_helper->simple_url_loader()->NetError());
ASSERT_TRUE(test_helper->simple_url_loader()->CompletionStatus());
EXPECT_EQ(net::OK,
test_helper->simple_url_loader()->CompletionStatus()->error_code);
EXPECT_EQ(200, test_helper->GetResponseCode());
ASSERT_TRUE(test_helper->response_body());
EXPECT_EQ(kResponseSize, test_helper->response_body()->length());
......@@ -3115,6 +3370,9 @@ TEST_F(SimpleURLLoaderStreamTest, OnRetryCompletesAsync) {
1, SimpleURLLoader::RETRY_ON_5XX);
test_helper->StartSimpleLoaderAndWait(url_loader_factory_.get());
EXPECT_EQ(net::OK, test_helper->simple_url_loader()->NetError());
ASSERT_TRUE(test_helper->simple_url_loader()->CompletionStatus());
EXPECT_EQ(net::OK,
test_helper->simple_url_loader()->CompletionStatus()->error_code);
ASSERT_TRUE(test_helper->response_body());
EXPECT_EQ(kShortUploadBody, *test_helper->response_body());
EXPECT_EQ(1, test_helper->download_as_stream_retries());
......@@ -3182,6 +3440,7 @@ TEST_F(SimpleURLLoaderMockTimeTest, TimeoutTriggered) {
loader_factory.RunTest(test_helper.get());
EXPECT_EQ(net::ERR_TIMED_OUT, test_helper->simple_url_loader()->NetError());
EXPECT_FALSE(test_helper->simple_url_loader()->CompletionStatus());
}
// Less time is simulated passing than the timeout value, so this request should
......@@ -3199,6 +3458,9 @@ TEST_F(SimpleURLLoaderMockTimeTest, TimeoutNotTriggered) {
loader_factory.RunTest(test_helper.get());
EXPECT_EQ(net::OK, test_helper->simple_url_loader()->NetError());
ASSERT_TRUE(test_helper->simple_url_loader()->CompletionStatus());
EXPECT_EQ(net::OK,
test_helper->simple_url_loader()->CompletionStatus()->error_code);
EXPECT_EQ(200, test_helper->GetResponseCode());
}
......@@ -3215,6 +3477,9 @@ TEST_F(SimpleURLLoaderMockTimeTest, TimeNotSetAndTimeAdvanced) {
loader_factory.RunTest(test_helper.get());
EXPECT_EQ(net::OK, test_helper->simple_url_loader()->NetError());
ASSERT_TRUE(test_helper->simple_url_loader()->CompletionStatus());
EXPECT_EQ(net::OK,
test_helper->simple_url_loader()->CompletionStatus()->error_code);
EXPECT_EQ(200, test_helper->GetResponseCode());
}
......@@ -3234,6 +3499,7 @@ TEST_F(SimpleURLLoaderMockTimeTest, TimeoutAfterRedirectTriggered) {
loader_factory.RunTest(test_helper.get());
EXPECT_EQ(net::ERR_TIMED_OUT, test_helper->simple_url_loader()->NetError());
EXPECT_FALSE(test_helper->simple_url_loader()->CompletionStatus());
}
// Simulate time passing after a failure. The retry restarts the timeout timer,
......@@ -3255,6 +3521,9 @@ TEST_F(SimpleURLLoaderMockTimeTest, TimeoutAfterRetryNotTriggered) {
loader_factory.RunTest(test_helper.get());
EXPECT_EQ(net::OK, test_helper->simple_url_loader()->NetError());
ASSERT_TRUE(test_helper->simple_url_loader()->CompletionStatus());
EXPECT_EQ(net::OK,
test_helper->simple_url_loader()->CompletionStatus()->error_code);
EXPECT_EQ(200, test_helper->GetResponseCode());
}
......@@ -3277,6 +3546,7 @@ TEST_F(SimpleURLLoaderMockTimeTest, TimeoutAfterRetryTriggered) {
loader_factory.RunTest(test_helper.get());
EXPECT_EQ(net::ERR_TIMED_OUT, test_helper->simple_url_loader()->NetError());
EXPECT_FALSE(test_helper->simple_url_loader()->CompletionStatus());
}
TEST_P(SimpleURLLoaderTest, OnUploadProgressCallback) {
......@@ -3307,6 +3577,9 @@ TEST_P(SimpleURLLoaderTest, OnUploadProgressCallback) {
}));
test_helper->StartSimpleLoaderAndWait(url_loader_factory_.get());
EXPECT_EQ(net::OK, test_helper->simple_url_loader()->NetError());
ASSERT_TRUE(test_helper->simple_url_loader()->CompletionStatus());
EXPECT_EQ(net::OK,
test_helper->simple_url_loader()->CompletionStatus()->error_code);
EXPECT_EQ(long_string.size(), progress);
if (GetParam() != SimpleLoaderTestHelper::DownloadType::HEADERS_ONLY) {
ASSERT_TRUE(test_helper->response_body());
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment