Commit b624551f authored by Reilly Grant's avatar Reilly Grant Committed by Commit Bot

Revert "Port policy::UploadJobImpl to network::SimpleURLLoader"

This reverts commit 581330a9.

Reason for revert: SimpleURLLoaderTest.OnUploadProgressCallback/3 is flaky

Original change's description:
> Port policy::UploadJobImpl to network::SimpleURLLoader
> 
> This change ports UploadJobImpl from net::URLFetcher to SimpleURLLoader.
> 
> Since this request does not make use of the response a new method has
> been added to SimpleURLLoader, DownloadToNull. This download mode still
> reads the response body from the network but does not save it anywhere.
> This is useful for requests which upload data and would otherwise have
> to specify an arbitrary |max_body_size|. A maximum may still be set if
> the caller wants to limit the amount of data transferred over the
> network.
> 
> Bug: 773295
> Cq-Include-Trybots: luci.chromium.try:linux_mojo
> Change-Id: Iee1fdc6f7406066ced8c91122e22cd51ddcb1c5f
> Reviewed-on: https://chromium-review.googlesource.com/1161551
> Commit-Queue: Reilly Grant <reillyg@chromium.org>
> Reviewed-by: Matt Menke <mmenke@chromium.org>
> Reviewed-by: Julian Pastarmov <pastarmovj@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#581060}

TBR=pastarmovj@chromium.org,reillyg@chromium.org,mmenke@chromium.org

Change-Id: Ica09c85a12861d35efbdfd9a882d137bac6b9e56
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: 773295, 872023
Cq-Include-Trybots: luci.chromium.try:linux_mojo
Reviewed-on: https://chromium-review.googlesource.com/1166288Reviewed-by: default avatarReilly Grant <reillyg@chromium.org>
Commit-Queue: Reilly Grant <reillyg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#581389}
parent e00760c6
...@@ -53,6 +53,8 @@ std::unique_ptr<UploadJob> ScreenshotDelegate::CreateUploadJob( ...@@ -53,6 +53,8 @@ std::unique_ptr<UploadJob> ScreenshotDelegate::CreateUploadJob(
chromeos::DeviceOAuth2TokenService* device_oauth2_token_service = chromeos::DeviceOAuth2TokenService* device_oauth2_token_service =
chromeos::DeviceOAuth2TokenServiceFactory::Get(); chromeos::DeviceOAuth2TokenServiceFactory::Get();
scoped_refptr<net::URLRequestContextGetter> system_request_context =
g_browser_process->system_request_context();
std::string robot_account_id = std::string robot_account_id =
device_oauth2_token_service->GetRobotAccountId(); device_oauth2_token_service->GetRobotAccountId();
...@@ -78,7 +80,7 @@ std::unique_ptr<UploadJob> ScreenshotDelegate::CreateUploadJob( ...@@ -78,7 +80,7 @@ std::unique_ptr<UploadJob> ScreenshotDelegate::CreateUploadJob(
)"); )");
return std::unique_ptr<UploadJob>(new UploadJobImpl( return std::unique_ptr<UploadJob>(new UploadJobImpl(
upload_url, robot_account_id, device_oauth2_token_service, upload_url, robot_account_id, device_oauth2_token_service,
g_browser_process->shared_url_loader_factory(), delegate, system_request_context, delegate,
base::WrapUnique(new UploadJobImpl::RandomMimeBoundaryGenerator), base::WrapUnique(new UploadJobImpl::RandomMimeBoundaryGenerator),
traffic_annotation, base::ThreadTaskRunnerHandle::Get())); traffic_annotation, base::ThreadTaskRunnerHandle::Get()));
} }
......
...@@ -27,7 +27,6 @@ ...@@ -27,7 +27,6 @@
#include "components/policy/core/browser/browser_policy_connector.h" #include "components/policy/core/browser/browser_policy_connector.h"
#include "components/user_manager/user_manager.h" #include "components/user_manager/user_manager.h"
#include "net/http/http_request_headers.h" #include "net/http/http_request_headers.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
namespace policy { namespace policy {
...@@ -145,6 +144,8 @@ std::unique_ptr<UploadJob> SystemLogDelegate::CreateUploadJob( ...@@ -145,6 +144,8 @@ std::unique_ptr<UploadJob> SystemLogDelegate::CreateUploadJob(
chromeos::DeviceOAuth2TokenService* device_oauth2_token_service = chromeos::DeviceOAuth2TokenService* device_oauth2_token_service =
chromeos::DeviceOAuth2TokenServiceFactory::Get(); chromeos::DeviceOAuth2TokenServiceFactory::Get();
scoped_refptr<net::URLRequestContextGetter> system_request_context =
g_browser_process->system_request_context();
std::string robot_account_id = std::string robot_account_id =
device_oauth2_token_service->GetRobotAccountId(); device_oauth2_token_service->GetRobotAccountId();
...@@ -172,7 +173,7 @@ std::unique_ptr<UploadJob> SystemLogDelegate::CreateUploadJob( ...@@ -172,7 +173,7 @@ std::unique_ptr<UploadJob> SystemLogDelegate::CreateUploadJob(
)"); )");
return std::make_unique<UploadJobImpl>( return std::make_unique<UploadJobImpl>(
upload_url, robot_account_id, device_oauth2_token_service, upload_url, robot_account_id, device_oauth2_token_service,
g_browser_process->shared_url_loader_factory(), delegate, system_request_context, delegate,
std::make_unique<UploadJobImpl::RandomMimeBoundaryGenerator>(), std::make_unique<UploadJobImpl::RandomMimeBoundaryGenerator>(),
traffic_annotation, task_runner_); traffic_annotation, task_runner_);
} }
......
...@@ -19,8 +19,7 @@ ...@@ -19,8 +19,7 @@
#include "net/base/mime_util.h" #include "net/base/mime_util.h"
#include "net/http/http_status_code.h" #include "net/http/http_status_code.h"
#include "net/traffic_annotation/network_traffic_annotation.h" #include "net/traffic_annotation/network_traffic_annotation.h"
#include "services/network/public/cpp/shared_url_loader_factory.h" #include "net/url_request/url_request_status.h"
#include "services/network/public/cpp/simple_url_loader.h"
namespace policy { namespace policy {
...@@ -28,7 +27,7 @@ namespace { ...@@ -28,7 +27,7 @@ namespace {
// Format for bearer tokens in HTTP requests to access OAuth 2.0 protected // Format for bearer tokens in HTTP requests to access OAuth 2.0 protected
// resources. // resources.
const char kAuthorizationHeaderFormat[] = "Bearer %s"; const char kAuthorizationHeaderFormat[] = "Authorization: Bearer %s";
// Value the "Content-Type" field will be set to in the POST request. // Value the "Content-Type" field will be set to in the POST request.
const char kUploadContentType[] = "multipart/form-data"; const char kUploadContentType[] = "multipart/form-data";
...@@ -152,7 +151,7 @@ UploadJobImpl::UploadJobImpl( ...@@ -152,7 +151,7 @@ UploadJobImpl::UploadJobImpl(
const GURL& upload_url, const GURL& upload_url,
const std::string& account_id, const std::string& account_id,
OAuth2TokenService* token_service, OAuth2TokenService* token_service,
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory, scoped_refptr<net::URLRequestContextGetter> url_context_getter,
Delegate* delegate, Delegate* delegate,
std::unique_ptr<MimeBoundaryGenerator> boundary_generator, std::unique_ptr<MimeBoundaryGenerator> boundary_generator,
net::NetworkTrafficAnnotationTag traffic_annotation, net::NetworkTrafficAnnotationTag traffic_annotation,
...@@ -161,7 +160,7 @@ UploadJobImpl::UploadJobImpl( ...@@ -161,7 +160,7 @@ UploadJobImpl::UploadJobImpl(
upload_url_(upload_url), upload_url_(upload_url),
account_id_(account_id), account_id_(account_id),
token_service_(token_service), token_service_(token_service),
url_loader_factory_(std::move(url_loader_factory)), url_context_getter_(url_context_getter),
delegate_(delegate), delegate_(delegate),
boundary_generator_(std::move(boundary_generator)), boundary_generator_(std::move(boundary_generator)),
traffic_annotation_(traffic_annotation), traffic_annotation_(traffic_annotation),
...@@ -170,7 +169,7 @@ UploadJobImpl::UploadJobImpl( ...@@ -170,7 +169,7 @@ UploadJobImpl::UploadJobImpl(
task_runner_(task_runner), task_runner_(task_runner),
weak_factory_(this) { weak_factory_(this) {
DCHECK(token_service_); DCHECK(token_service_);
DCHECK(url_loader_factory_); DCHECK(url_context_getter_);
DCHECK(delegate_); DCHECK(delegate_);
SYSLOG(INFO) << "Upload job created."; SYSLOG(INFO) << "Upload job created.";
if (!upload_url_.is_valid()) { if (!upload_url_.is_valid()) {
...@@ -300,7 +299,7 @@ bool UploadJobImpl::SetUpMultipart() { ...@@ -300,7 +299,7 @@ bool UploadJobImpl::SetUpMultipart() {
return true; return true;
} }
void UploadJobImpl::CreateAndStartURLLoader(const std::string& access_token) { void UploadJobImpl::CreateAndStartURLFetcher(const std::string& access_token) {
// Ensure that the content has been prepared and the upload url is valid. // Ensure that the content has been prepared and the upload url is valid.
DCHECK_EQ(PREPARING_CONTENT, state_); DCHECK_EQ(PREPARING_CONTENT, state_);
SYSLOG(INFO) << "Starting URL fetcher."; SYSLOG(INFO) << "Starting URL fetcher.";
...@@ -309,20 +308,13 @@ void UploadJobImpl::CreateAndStartURLLoader(const std::string& access_token) { ...@@ -309,20 +308,13 @@ void UploadJobImpl::CreateAndStartURLLoader(const std::string& access_token) {
content_type.append("; boundary="); content_type.append("; boundary=");
content_type.append(*mime_boundary_.get()); content_type.append(*mime_boundary_.get());
auto resource_request = std::make_unique<network::ResourceRequest>(); upload_fetcher_ = net::URLFetcher::Create(upload_url_, net::URLFetcher::POST,
resource_request->method = "POST"; this, traffic_annotation_);
resource_request->url = upload_url_; upload_fetcher_->SetRequestContext(url_context_getter_.get());
resource_request->headers.SetHeader( upload_fetcher_->SetUploadData(content_type, *post_data_);
net::HttpRequestHeaders::kAuthorization, upload_fetcher_->AddExtraRequestHeader(
base::StringPrintf(kAuthorizationHeaderFormat, access_token.c_str())); base::StringPrintf(kAuthorizationHeaderFormat, access_token.c_str()));
upload_fetcher_->Start();
url_loader_ = network::SimpleURLLoader::Create(std::move(resource_request),
traffic_annotation_);
url_loader_->AttachStringForUpload(*post_data_, content_type);
url_loader_->DownloadHeadersOnly(
url_loader_factory_.get(),
base::BindOnce(&UploadJobImpl::OnURLLoadComplete,
base::Unretained(this)));
} }
void UploadJobImpl::StartUpload() { void UploadJobImpl::StartUpload() {
...@@ -334,7 +326,7 @@ void UploadJobImpl::StartUpload() { ...@@ -334,7 +326,7 @@ void UploadJobImpl::StartUpload() {
state_ = ERROR; state_ = ERROR;
return; return;
} }
CreateAndStartURLLoader(access_token_); CreateAndStartURLFetcher(access_token_);
state_ = UPLOADING; state_ = UPLOADING;
} }
...@@ -364,7 +356,7 @@ void UploadJobImpl::OnGetTokenFailure( ...@@ -364,7 +356,7 @@ void UploadJobImpl::OnGetTokenFailure(
void UploadJobImpl::HandleError(ErrorCode error_code) { void UploadJobImpl::HandleError(ErrorCode error_code) {
retry_++; retry_++;
url_loader_.reset(); upload_fetcher_.reset();
SYSLOG(ERROR) << "Upload failed, error code: " << error_code; SYSLOG(ERROR) << "Upload failed, error code: " << error_code;
...@@ -405,32 +397,35 @@ void UploadJobImpl::HandleError(ErrorCode error_code) { ...@@ -405,32 +397,35 @@ void UploadJobImpl::HandleError(ErrorCode error_code) {
} }
} }
void UploadJobImpl::OnURLLoadComplete( void UploadJobImpl::OnURLFetchComplete(const net::URLFetcher* source) {
scoped_refptr<net::HttpResponseHeaders> headers) { DCHECK_EQ(upload_fetcher_.get(), source);
DCHECK_EQ(UPLOADING, state_); DCHECK_EQ(UPLOADING, state_);
SYSLOG(INFO) << "URL fetch completed."; SYSLOG(INFO) << "URL fetch completed.";
std::unique_ptr<network::SimpleURLLoader> url_loader = std::move(url_loader_); const net::URLRequestStatus& status = source->GetStatus();
if (!status.is_success()) {
if (!headers) { SYSLOG(ERROR) << "URLRequestStatus error " << status.error();
SYSLOG(ERROR) << "SimpleURLLoader error " << url_loader->NetError();
HandleError(NETWORK_ERROR); HandleError(NETWORK_ERROR);
} else if (headers->response_code() == net::HTTP_OK) { } else {
const int response_code = source->GetResponseCode();
if (response_code == net::HTTP_OK) {
// Successful upload // Successful upload
upload_fetcher_.reset();
access_token_.clear(); access_token_.clear();
post_data_.reset(); post_data_.reset();
state_ = SUCCESS; state_ = SUCCESS;
UMA_HISTOGRAM_EXACT_LINEAR(kUploadJobSuccessHistogram, retry_, UMA_HISTOGRAM_EXACT_LINEAR(
kUploadJobSuccessHistogram, retry_,
static_cast<int>(UploadJobSuccess::REQUEST_MAX)); static_cast<int>(UploadJobSuccess::REQUEST_MAX));
delegate_->OnSuccess(); delegate_->OnSuccess();
} else if (headers->response_code() == net::HTTP_UNAUTHORIZED) { } else if (response_code == net::HTTP_UNAUTHORIZED) {
SYSLOG(ERROR) << "Unauthorized request."; SYSLOG(ERROR) << "Unauthorized request.";
HandleError(AUTHENTICATION_ERROR); HandleError(AUTHENTICATION_ERROR);
} else { } else {
SYSLOG(ERROR) << "POST request failed with HTTP status code " SYSLOG(ERROR) << "POST request failed with HTTP status code "
<< headers->response_code() << "."; << response_code << ".";
HandleError(SERVER_ERROR); HandleError(SERVER_ERROR);
} }
}
} }
} // namespace policy } // namespace policy
...@@ -15,28 +15,23 @@ ...@@ -15,28 +15,23 @@
#include "base/threading/thread_checker.h" #include "base/threading/thread_checker.h"
#include "chrome/browser/chromeos/policy/upload_job.h" #include "chrome/browser/chromeos/policy/upload_job.h"
#include "google_apis/gaia/oauth2_token_service.h" #include "google_apis/gaia/oauth2_token_service.h"
#include "net/traffic_annotation/network_traffic_annotation.h" #include "net/url_request/url_fetcher.h"
#include "net/url_request/url_fetcher_delegate.h"
#include "net/url_request/url_request_context_getter.h"
#include "url/gurl.h" #include "url/gurl.h"
namespace base { namespace base {
class SequencedTaskRunner; class SequencedTaskRunner;
} }
namespace net {
class HttpResponseHeaders;
}
namespace network {
class SharedURLLoaderFactory;
class SimpleURLLoader;
} // namespace network
namespace policy { namespace policy {
// This implementation of UploadJob uses the OAuth2TokenService to acquire // This implementation of UploadJob uses the OAuth2TokenService to acquire
// access tokens for the device management (cloud-based policy) server scope and // access tokens for the device management (cloud-based policy) server scope and
// uses a SimpleURLLoader to upload data to the specified upload url. // uses a URLFetcher to upload data to the specified upload url.
class UploadJobImpl : public UploadJob, public OAuth2TokenService::Consumer { class UploadJobImpl : public UploadJob,
public OAuth2TokenService::Consumer,
public net::URLFetcherDelegate {
public: public:
// UploadJobImpl uses a MimeBoundaryGenerator to generate strings which // UploadJobImpl uses a MimeBoundaryGenerator to generate strings which
// mark the boundaries between data segments. // mark the boundaries between data segments.
...@@ -61,11 +56,10 @@ class UploadJobImpl : public UploadJob, public OAuth2TokenService::Consumer { ...@@ -61,11 +56,10 @@ class UploadJobImpl : public UploadJob, public OAuth2TokenService::Consumer {
// |task_runner| must belong to the same thread from which the constructor and // |task_runner| must belong to the same thread from which the constructor and
// all the public methods are called. // all the public methods are called.
UploadJobImpl( UploadJobImpl(const GURL& upload_url,
const GURL& upload_url,
const std::string& account_id, const std::string& account_id,
OAuth2TokenService* token_service, OAuth2TokenService* token_service,
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory, scoped_refptr<net::URLRequestContextGetter> url_context_getter,
Delegate* delegate, Delegate* delegate,
std::unique_ptr<MimeBoundaryGenerator> boundary_generator, std::unique_ptr<MimeBoundaryGenerator> boundary_generator,
net::NetworkTrafficAnnotationTag traffic_annotation, net::NetworkTrafficAnnotationTag traffic_annotation,
...@@ -109,15 +103,15 @@ class UploadJobImpl : public UploadJob, public OAuth2TokenService::Consumer { ...@@ -109,15 +103,15 @@ class UploadJobImpl : public UploadJob, public OAuth2TokenService::Consumer {
void OnGetTokenFailure(const OAuth2TokenService::Request* request, void OnGetTokenFailure(const OAuth2TokenService::Request* request,
const GoogleServiceAuthError& error) override; const GoogleServiceAuthError& error) override;
// Called when the SimpleURLLoader is finished. // net::URLFetcherDelegate:
void OnURLLoadComplete(scoped_refptr<net::HttpResponseHeaders> headers); void OnURLFetchComplete(const net::URLFetcher* source) override;
void HandleError(ErrorCode errorCode); void HandleError(ErrorCode errorCode);
// Requests an access token for the upload scope. // Requests an access token for the upload scope.
void RequestAccessToken(); void RequestAccessToken();
// Dispatches POST request. // Dispatches POST request to URLFetcher.
void StartUpload(); void StartUpload();
// Constructs the body of the POST request by concatenating the // Constructs the body of the POST request by concatenating the
...@@ -128,9 +122,9 @@ class UploadJobImpl : public UploadJob, public OAuth2TokenService::Consumer { ...@@ -128,9 +122,9 @@ class UploadJobImpl : public UploadJob, public OAuth2TokenService::Consumer {
// an error, clears |post_data_| and |mime_boundary_| and returns false. // an error, clears |post_data_| and |mime_boundary_| and returns false.
bool SetUpMultipart(); bool SetUpMultipart();
// Assembles the request and starts the SimpleURLLoader. Fails if another // Assembles the request and starts the URLFetcher. Fails if another upload
// upload is still in progress or the content was not successfully encoded. // is still in progress or the content was not successfully encoded.
void CreateAndStartURLLoader(const std::string& access_token); void CreateAndStartURLFetcher(const std::string& access_token);
// The URL to which the POST request should be directed. // The URL to which the POST request should be directed.
const GURL upload_url_; const GURL upload_url_;
...@@ -141,8 +135,8 @@ class UploadJobImpl : public UploadJob, public OAuth2TokenService::Consumer { ...@@ -141,8 +135,8 @@ class UploadJobImpl : public UploadJob, public OAuth2TokenService::Consumer {
// The token service used to retrieve the access token. // The token service used to retrieve the access token.
OAuth2TokenService* const token_service_; OAuth2TokenService* const token_service_;
// This is used to initialize the network::SimpleURLLoader object. // This is used to initialize the net::URLFetcher object.
const scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory_; const scoped_refptr<net::URLRequestContextGetter> url_context_getter_;
// The delegate to be notified of events. // The delegate to be notified of events.
Delegate* const delegate_; Delegate* const delegate_;
...@@ -175,7 +169,7 @@ class UploadJobImpl : public UploadJob, public OAuth2TokenService::Consumer { ...@@ -175,7 +169,7 @@ class UploadJobImpl : public UploadJob, public OAuth2TokenService::Consumer {
std::string access_token_; std::string access_token_;
// Helper to upload the data. // Helper to upload the data.
std::unique_ptr<network::SimpleURLLoader> url_loader_; std::unique_ptr<net::URLFetcher> upload_fetcher_;
// The data chunks to be uploaded. // The data chunks to be uploaded.
std::vector<std::unique_ptr<DataSegment>> data_segments_; std::vector<std::unique_ptr<DataSegment>> data_segments_;
......
...@@ -27,7 +27,8 @@ ...@@ -27,7 +27,8 @@
#include "net/test/embedded_test_server/http_request.h" #include "net/test/embedded_test_server/http_request.h"
#include "net/test/embedded_test_server/http_response.h" #include "net/test/embedded_test_server/http_response.h"
#include "net/traffic_annotation/network_traffic_annotation_test_helper.h" #include "net/traffic_annotation/network_traffic_annotation_test_helper.h"
#include "services/network/test/test_shared_url_loader_factory.h" #include "net/url_request/url_request_test_util.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
namespace policy { namespace policy {
...@@ -182,8 +183,8 @@ class UploadJobTestBase : public testing::Test, public UploadJob::Delegate { ...@@ -182,8 +183,8 @@ class UploadJobTestBase : public testing::Test, public UploadJob::Delegate {
// testing::Test: // testing::Test:
void SetUp() override { void SetUp() override {
url_loader_factory_ = request_context_getter_ = new net::TestURLRequestContextGetter(
base::MakeRefCounted<network::TestSharedURLLoaderFactory>(); base::ThreadTaskRunnerHandle::Get());
oauth2_service_.AddAccount("robot@gmail.com"); oauth2_service_.AddAccount("robot@gmail.com");
ASSERT_TRUE(test_server_.Start()); ASSERT_TRUE(test_server_.Start());
// Set retry delay to prevent timeouts // Set retry delay to prevent timeouts
...@@ -200,9 +201,9 @@ class UploadJobTestBase : public testing::Test, public UploadJob::Delegate { ...@@ -200,9 +201,9 @@ class UploadJobTestBase : public testing::Test, public UploadJob::Delegate {
std::unique_ptr<UploadJobImpl::MimeBoundaryGenerator> std::unique_ptr<UploadJobImpl::MimeBoundaryGenerator>
mime_boundary_generator) { mime_boundary_generator) {
std::unique_ptr<UploadJob> upload_job(new UploadJobImpl( std::unique_ptr<UploadJob> upload_job(new UploadJobImpl(
GetServerURL(), kRobotAccountId, &oauth2_service_, url_loader_factory_, GetServerURL(), kRobotAccountId, &oauth2_service_,
this, std::move(mime_boundary_generator), TRAFFIC_ANNOTATION_FOR_TESTS, request_context_getter_.get(), this, std::move(mime_boundary_generator),
base::ThreadTaskRunnerHandle::Get())); TRAFFIC_ANNOTATION_FOR_TESTS, base::ThreadTaskRunnerHandle::Get()));
std::map<std::string, std::string> header_entries; std::map<std::string, std::string> header_entries;
header_entries.insert(std::make_pair(kCustomField1, "CUSTOM1")); header_entries.insert(std::make_pair(kCustomField1, "CUSTOM1"));
...@@ -219,7 +220,7 @@ class UploadJobTestBase : public testing::Test, public UploadJob::Delegate { ...@@ -219,7 +220,7 @@ class UploadJobTestBase : public testing::Test, public UploadJob::Delegate {
content::TestBrowserThreadBundle test_browser_thread_bundle_; content::TestBrowserThreadBundle test_browser_thread_bundle_;
base::RunLoop run_loop_; base::RunLoop run_loop_;
net::EmbeddedTestServer test_server_; net::EmbeddedTestServer test_server_;
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory_; scoped_refptr<net::TestURLRequestContextGetter> request_context_getter_;
MockOAuth2TokenService oauth2_service_; MockOAuth2TokenService oauth2_service_;
std::unique_ptr<UploadJob::ErrorCode> expected_error_; std::unique_ptr<UploadJob::ErrorCode> expected_error_;
......
...@@ -188,8 +188,6 @@ class SimpleURLLoaderImpl : public SimpleURLLoader, ...@@ -188,8 +188,6 @@ class SimpleURLLoaderImpl : public SimpleURLLoader,
void DownloadToStringOfUnboundedSizeUntilCrashAndDie( void DownloadToStringOfUnboundedSizeUntilCrashAndDie(
mojom::URLLoaderFactory* url_loader_factory, mojom::URLLoaderFactory* url_loader_factory,
BodyAsStringCallback body_as_string_callback) override; BodyAsStringCallback body_as_string_callback) override;
void DownloadHeadersOnly(mojom::URLLoaderFactory* url_loader_factory,
HeadersOnlyCallback headers_only_callback) override;
void DownloadToFile( void DownloadToFile(
mojom::URLLoaderFactory* url_loader_factory, mojom::URLLoaderFactory* url_loader_factory,
DownloadToFileCompleteCallback download_to_file_complete_callback, DownloadToFileCompleteCallback download_to_file_complete_callback,
...@@ -627,58 +625,6 @@ class SaveToStringBodyHandler : public BodyHandler, ...@@ -627,58 +625,6 @@ class SaveToStringBodyHandler : public BodyHandler,
DISALLOW_COPY_AND_ASSIGN(SaveToStringBodyHandler); DISALLOW_COPY_AND_ASSIGN(SaveToStringBodyHandler);
}; };
// BodyHandler that discards the response body.
class HeadersOnlyBodyHandler : public BodyHandler, public BodyReader::Delegate {
public:
HeadersOnlyBodyHandler(
SimpleURLLoaderImpl* simple_url_loader,
SimpleURLLoader::HeadersOnlyCallback headers_only_callback)
: BodyHandler(simple_url_loader),
headers_only_callback_(std::move(headers_only_callback)) {}
~HeadersOnlyBodyHandler() override {}
// BodyHandler implementation
void OnStartLoadingResponseBody(
mojo::ScopedDataPipeConsumerHandle body_data_pipe) override {
// TODO(crbug.com/871420): The request can be completed at this point
// however that requires more changes to SimpleURLLoader as OnComplete()
// will not have been called yet.
DCHECK(!body_reader_);
body_reader_ =
std::make_unique<BodyReader>(this, std::numeric_limits<int64_t>::max());
body_reader_->Start(std::move(body_data_pipe));
}
void NotifyConsumerOfCompletion(bool destroy_results) override {
body_reader_.reset();
std::move(headers_only_callback_)
.Run(simple_url_loader()->ResponseInfo()
? simple_url_loader()->ResponseInfo()->headers
: nullptr);
}
void PrepareToRetry(base::OnceClosure retry_callback) override {
body_reader_.reset();
std::move(retry_callback).Run();
}
private:
// BodyReader::Delegate implementation
net::Error OnDataRead(uint32_t length, const char* data) override {
return net::OK;
}
void OnDone(net::Error error, int64_t total_bytes) override {
simple_url_loader()->OnBodyHandlerDone(error, total_bytes);
}
SimpleURLLoader::HeadersOnlyCallback headers_only_callback_;
std::unique_ptr<BodyReader> body_reader_;
DISALLOW_COPY_AND_ASSIGN(HeadersOnlyBodyHandler);
};
// BodyHandler implementation for saving the response to a file // BodyHandler implementation for saving the response to a file
class SaveToFileBodyHandler : public BodyHandler { class SaveToFileBodyHandler : public BodyHandler {
public: public:
...@@ -1115,14 +1061,6 @@ void SimpleURLLoaderImpl::DownloadToStringOfUnboundedSizeUntilCrashAndDie( ...@@ -1115,14 +1061,6 @@ void SimpleURLLoaderImpl::DownloadToStringOfUnboundedSizeUntilCrashAndDie(
Start(url_loader_factory); Start(url_loader_factory);
} }
void SimpleURLLoaderImpl::DownloadHeadersOnly(
mojom::URLLoaderFactory* url_loader_factory,
HeadersOnlyCallback headers_only_callback) {
body_handler_ = std::make_unique<HeadersOnlyBodyHandler>(
this, std::move(headers_only_callback));
Start(url_loader_factory);
}
void SimpleURLLoaderImpl::DownloadToFile( void SimpleURLLoaderImpl::DownloadToFile(
mojom::URLLoaderFactory* url_loader_factory, mojom::URLLoaderFactory* url_loader_factory,
DownloadToFileCompleteCallback download_to_file_complete_callback, DownloadToFileCompleteCallback download_to_file_complete_callback,
...@@ -1308,7 +1246,6 @@ void SimpleURLLoaderImpl::FinishWithResult(int net_error) { ...@@ -1308,7 +1246,6 @@ void SimpleURLLoaderImpl::FinishWithResult(int net_error) {
request_state_->finished = true; request_state_->finished = true;
request_state_->net_error = net_error; request_state_->net_error = net_error;
// If it's a partial download or an error was received, erase the body. // If it's a partial download or an error was received, erase the body.
bool destroy_results = bool destroy_results =
request_state_->net_error != net::OK && !allow_partial_results_; request_state_->net_error != net::OK && !allow_partial_results_;
...@@ -1374,6 +1311,7 @@ void SimpleURLLoaderImpl::Retry() { ...@@ -1374,6 +1311,7 @@ void SimpleURLLoaderImpl::Retry() {
url_loader_.reset(); url_loader_.reset();
request_state_ = std::make_unique<RequestState>(); request_state_ = std::make_unique<RequestState>();
body_handler_->PrepareToRetry(base::BindOnce( body_handler_->PrepareToRetry(base::BindOnce(
&SimpleURLLoaderImpl::StartRequest, weak_ptr_factory_.GetWeakPtr(), &SimpleURLLoaderImpl::StartRequest, weak_ptr_factory_.GetWeakPtr(),
url_loader_factory_ptr_.get())); url_loader_factory_ptr_.get()));
......
...@@ -18,15 +18,11 @@ ...@@ -18,15 +18,11 @@
class GURL; class GURL;
template <class T>
class scoped_refptr;
namespace base { namespace base {
class FilePath; class FilePath;
} }
namespace net { namespace net {
class HttpResponseHeaders;
struct NetworkTrafficAnnotationTag; struct NetworkTrafficAnnotationTag;
struct RedirectInfo; struct RedirectInfo;
} // namespace net } // namespace net
...@@ -89,14 +85,8 @@ class COMPONENT_EXPORT(NETWORK_CPP) SimpleURLLoader { ...@@ -89,14 +85,8 @@ class COMPONENT_EXPORT(NETWORK_CPP) SimpleURLLoader {
using BodyAsStringCallback = using BodyAsStringCallback =
base::OnceCallback<void(std::unique_ptr<std::string> response_body)>; base::OnceCallback<void(std::unique_ptr<std::string> response_body)>;
// Callback used when ignoring the response body. |headers| are the received // Callback used when download the response body to a file. On failure, |path|
// HTTP headers, or nullptr if none were received. It is safe to delete the // will be empty. It is safe to delete the SimpleURLLoader during the
// SimpleURLLoader during the callback.
using HeadersOnlyCallback =
base::OnceCallback<void(scoped_refptr<net::HttpResponseHeaders> headers)>;
// Callback used when downloading the response body to a file. On failure,
// |path| will be empty. It is safe to delete the SimpleURLLoader during the
// callback. // callback.
using DownloadToFileCompleteCallback = using DownloadToFileCompleteCallback =
base::OnceCallback<void(base::FilePath path)>; base::OnceCallback<void(base::FilePath path)>;
...@@ -130,7 +120,7 @@ class COMPONENT_EXPORT(NETWORK_CPP) SimpleURLLoader { ...@@ -130,7 +120,7 @@ class COMPONENT_EXPORT(NETWORK_CPP) SimpleURLLoader {
virtual ~SimpleURLLoader(); virtual ~SimpleURLLoader();
// Starts the request using |url_loader_factory|. The SimpleURLLoader will // Starts the request using |network_context|. The SimpleURLLoader will
// accumulate all downloaded data in an in-memory string of bounded size. If // accumulate all downloaded data in an in-memory string of bounded size. If
// |max_body_size| is exceeded, the request will fail with // |max_body_size| is exceeded, the request will fail with
// net::ERR_INSUFFICIENT_RESOURCES. |max_body_size| must be no greater than 1 // net::ERR_INSUFFICIENT_RESOURCES. |max_body_size| must be no greater than 1
...@@ -155,14 +145,6 @@ class COMPONENT_EXPORT(NETWORK_CPP) SimpleURLLoader { ...@@ -155,14 +145,6 @@ class COMPONENT_EXPORT(NETWORK_CPP) SimpleURLLoader {
mojom::URLLoaderFactory* url_loader_factory, mojom::URLLoaderFactory* url_loader_factory,
BodyAsStringCallback body_as_string_callback) = 0; BodyAsStringCallback body_as_string_callback) = 0;
// Starts the request using |url_loader_factory|. The SimpleURLLoader will
// discard the response body as it is received and |headers_only_callback|
// will be invoked on completion. It is safe to delete the SimpleURLLoader in
// this callback.
virtual void DownloadHeadersOnly(
mojom::URLLoaderFactory* url_loader_factory,
HeadersOnlyCallback headers_only_callback) = 0;
// SimpleURLLoader will download the entire response to a file at the // SimpleURLLoader will download the entire response to a file at the
// specified path. File I/O will happen on another sequence, so it's safe to // specified path. File I/O will happen on another sequence, so it's safe to
// use this on any sequence. // use this on any sequence.
......
...@@ -94,13 +94,7 @@ class SimpleLoaderTestHelper : public SimpleURLLoaderStreamConsumer { ...@@ -94,13 +94,7 @@ class SimpleLoaderTestHelper : public SimpleURLLoaderStreamConsumer {
public: public:
// What the response should be downloaded to. Running all tests for all types // What the response should be downloaded to. Running all tests for all types
// is more than strictly needed, but simplest just to cover all cases. // is more than strictly needed, but simplest just to cover all cases.
enum class DownloadType { enum class DownloadType { TO_STRING, TO_FILE, TO_TEMP_FILE, AS_STREAM };
TO_STRING,
TO_FILE,
TO_TEMP_FILE,
HEADERS_ONLY,
AS_STREAM
};
explicit SimpleLoaderTestHelper( explicit SimpleLoaderTestHelper(
std::unique_ptr<network::ResourceRequest> resource_request, std::unique_ptr<network::ResourceRequest> resource_request,
...@@ -183,12 +177,6 @@ class SimpleLoaderTestHelper : public SimpleURLLoaderStreamConsumer { ...@@ -183,12 +177,6 @@ class SimpleLoaderTestHelper : public SimpleURLLoaderStreamConsumer {
max_body_size); max_body_size);
} }
break; break;
case DownloadType::HEADERS_ONLY:
simple_url_loader_->DownloadHeadersOnly(
url_loader_factory,
base::BindOnce(&SimpleLoaderTestHelper::DownloadedHeadersOnly,
base::Unretained(this)));
break;
case DownloadType::AS_STREAM: case DownloadType::AS_STREAM:
// Downloading to stream doesn't support a max body size. // Downloading to stream doesn't support a max body size.
DCHECK_LT(max_body_size, 0); DCHECK_LT(max_body_size, 0);
...@@ -355,19 +343,6 @@ class SimpleLoaderTestHelper : public SimpleURLLoaderStreamConsumer { ...@@ -355,19 +343,6 @@ class SimpleLoaderTestHelper : public SimpleURLLoaderStreamConsumer {
run_loop_.Quit(); run_loop_.Quit();
} }
void DownloadedHeadersOnly(scoped_refptr<net::HttpResponseHeaders> headers) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
EXPECT_FALSE(done_);
EXPECT_EQ(DownloadType::HEADERS_ONLY, download_type_);
EXPECT_FALSE(response_body_);
if (destroy_loader_on_complete_)
simple_url_loader_.reset();
done_ = true;
run_loop_.Quit();
}
// SimpleURLLoaderStreamConsumer implementation: // SimpleURLLoaderStreamConsumer implementation:
void OnDataReceived(base::StringPiece string_piece, void OnDataReceived(base::StringPiece string_piece,
...@@ -674,11 +649,8 @@ TEST_P(SimpleURLLoaderTest, BasicRequest) { ...@@ -674,11 +649,8 @@ TEST_P(SimpleURLLoaderTest, BasicRequest) {
EXPECT_EQ(net::OK, test_helper->simple_url_loader()->NetError()); EXPECT_EQ(net::OK, test_helper->simple_url_loader()->NetError());
EXPECT_EQ(200, test_helper->GetResponseCode()); EXPECT_EQ(200, test_helper->GetResponseCode());
if (GetParam() != SimpleLoaderTestHelper::DownloadType::HEADERS_ONLY) {
ASSERT_TRUE(test_helper->response_body()); ASSERT_TRUE(test_helper->response_body());
EXPECT_EQ("Expected Response", *test_helper->response_body()); EXPECT_EQ("Expected Response", *test_helper->response_body());
}
} }
// Test that SimpleURLLoader handles data URLs, which don't have headers. // Test that SimpleURLLoader handles data URLs, which don't have headers.
...@@ -690,11 +662,8 @@ TEST_P(SimpleURLLoaderTest, DataURL) { ...@@ -690,11 +662,8 @@ TEST_P(SimpleURLLoaderTest, DataURL) {
EXPECT_EQ(net::OK, test_helper->simple_url_loader()->NetError()); EXPECT_EQ(net::OK, test_helper->simple_url_loader()->NetError());
ASSERT_TRUE(test_helper->simple_url_loader()->ResponseInfo()); ASSERT_TRUE(test_helper->simple_url_loader()->ResponseInfo());
EXPECT_FALSE(test_helper->simple_url_loader()->ResponseInfo()->headers); EXPECT_FALSE(test_helper->simple_url_loader()->ResponseInfo()->headers);
if (GetParam() != SimpleLoaderTestHelper::DownloadType::HEADERS_ONLY) {
ASSERT_TRUE(test_helper->response_body()); ASSERT_TRUE(test_helper->response_body());
EXPECT_EQ("foo", *test_helper->response_body()); EXPECT_EQ("foo", *test_helper->response_body());
}
} }
// Make sure the class works when the size of the encoded and decoded bodies are // Make sure the class works when the size of the encoded and decoded bodies are
...@@ -706,11 +675,8 @@ TEST_P(SimpleURLLoaderTest, GzipBody) { ...@@ -706,11 +675,8 @@ TEST_P(SimpleURLLoaderTest, GzipBody) {
EXPECT_EQ(net::OK, test_helper->simple_url_loader()->NetError()); EXPECT_EQ(net::OK, test_helper->simple_url_loader()->NetError());
EXPECT_EQ(200, test_helper->GetResponseCode()); EXPECT_EQ(200, test_helper->GetResponseCode());
if (GetParam() != SimpleLoaderTestHelper::DownloadType::HEADERS_ONLY) {
ASSERT_TRUE(test_helper->response_body()); ASSERT_TRUE(test_helper->response_body());
EXPECT_EQ("foo", *test_helper->response_body()); EXPECT_EQ("foo", *test_helper->response_body());
}
} }
// Make sure redirects are followed. // Make sure redirects are followed.
...@@ -722,11 +688,8 @@ TEST_P(SimpleURLLoaderTest, Redirect) { ...@@ -722,11 +688,8 @@ TEST_P(SimpleURLLoaderTest, Redirect) {
EXPECT_EQ(net::OK, test_helper->simple_url_loader()->NetError()); EXPECT_EQ(net::OK, test_helper->simple_url_loader()->NetError());
EXPECT_EQ(200, test_helper->GetResponseCode()); EXPECT_EQ(200, test_helper->GetResponseCode());
if (GetParam() != SimpleLoaderTestHelper::DownloadType::HEADERS_ONLY) {
ASSERT_TRUE(test_helper->response_body()); ASSERT_TRUE(test_helper->response_body());
EXPECT_EQ("Echo", *test_helper->response_body()); EXPECT_EQ("Echo", *test_helper->response_body());
}
} }
// Make sure OnRedirectCallback is invoked on a redirect. // Make sure OnRedirectCallback is invoked on a redirect.
...@@ -752,11 +715,8 @@ TEST_P(SimpleURLLoaderTest, OnRedirectCallback) { ...@@ -752,11 +715,8 @@ TEST_P(SimpleURLLoaderTest, OnRedirectCallback) {
base::Unretained(&response_head))); base::Unretained(&response_head)));
test_helper->StartSimpleLoaderAndWait(url_loader_factory_.get()); test_helper->StartSimpleLoaderAndWait(url_loader_factory_.get());
if (GetParam() != SimpleLoaderTestHelper::DownloadType::HEADERS_ONLY) {
ASSERT_TRUE(test_helper->response_body()); ASSERT_TRUE(test_helper->response_body());
EXPECT_EQ("Echo", *test_helper->response_body()); EXPECT_EQ("Echo", *test_helper->response_body());
}
EXPECT_EQ(1, num_redirects); EXPECT_EQ(1, num_redirects);
EXPECT_EQ(test_server_.GetURL("/echo"), redirect_info.new_url); EXPECT_EQ(test_server_.GetURL("/echo"), redirect_info.new_url);
...@@ -781,10 +741,8 @@ TEST_P(SimpleURLLoaderTest, OnRedirectCallbackTwoRedirects) { ...@@ -781,10 +741,8 @@ TEST_P(SimpleURLLoaderTest, OnRedirectCallbackTwoRedirects) {
test_helper->StartSimpleLoaderAndWait(url_loader_factory_.get()); test_helper->StartSimpleLoaderAndWait(url_loader_factory_.get());
if (GetParam() != SimpleLoaderTestHelper::DownloadType::HEADERS_ONLY) {
ASSERT_TRUE(test_helper->response_body()); ASSERT_TRUE(test_helper->response_body());
EXPECT_EQ("Echo", *test_helper->response_body()); EXPECT_EQ("Echo", *test_helper->response_body());
}
EXPECT_EQ(2, num_redirects); EXPECT_EQ(2, num_redirects);
} }
...@@ -836,12 +794,8 @@ TEST_P(SimpleURLLoaderTest, UploadShortStringWithRedirect) { ...@@ -836,12 +794,8 @@ TEST_P(SimpleURLLoaderTest, UploadShortStringWithRedirect) {
test_helper->StartSimpleLoaderAndWait(url_loader_factory_.get()); test_helper->StartSimpleLoaderAndWait(url_loader_factory_.get());
EXPECT_EQ(net::OK, test_helper->simple_url_loader()->NetError()); EXPECT_EQ(net::OK, test_helper->simple_url_loader()->NetError());
if (GetParam() != SimpleLoaderTestHelper::DownloadType::HEADERS_ONLY) {
ASSERT_TRUE(test_helper->response_body()); ASSERT_TRUE(test_helper->response_body());
EXPECT_EQ(kShortUploadBody, *test_helper->response_body()); EXPECT_EQ(kShortUploadBody, *test_helper->response_body());
}
// Make sure request really was redirected. // Make sure request really was redirected.
EXPECT_EQ(1, num_redirects); EXPECT_EQ(1, num_redirects);
} }
...@@ -864,12 +818,8 @@ TEST_P(SimpleURLLoaderTest, UploadLongStringWithRedirect) { ...@@ -864,12 +818,8 @@ TEST_P(SimpleURLLoaderTest, UploadLongStringWithRedirect) {
test_helper->StartSimpleLoaderAndWait(url_loader_factory_.get()); test_helper->StartSimpleLoaderAndWait(url_loader_factory_.get());
EXPECT_EQ(net::OK, test_helper->simple_url_loader()->NetError()); EXPECT_EQ(net::OK, test_helper->simple_url_loader()->NetError());
if (GetParam() != SimpleLoaderTestHelper::DownloadType::HEADERS_ONLY) {
ASSERT_TRUE(test_helper->response_body()); ASSERT_TRUE(test_helper->response_body());
EXPECT_EQ(GetLongUploadBody(), *test_helper->response_body()); EXPECT_EQ(GetLongUploadBody(), *test_helper->response_body());
}
// Make sure request really was redirected. // Make sure request really was redirected.
EXPECT_EQ(1, num_redirects); EXPECT_EQ(1, num_redirects);
} }
...@@ -899,14 +849,10 @@ TEST_P(SimpleURLLoaderTest, ...@@ -899,14 +849,10 @@ TEST_P(SimpleURLLoaderTest,
test_helper->StartSimpleLoaderAndWait(url_loader_factory_.get()); test_helper->StartSimpleLoaderAndWait(url_loader_factory_.get());
EXPECT_EQ(net::OK, test_helper->simple_url_loader()->NetError()); EXPECT_EQ(net::OK, test_helper->simple_url_loader()->NetError());
if (GetParam() != SimpleLoaderTestHelper::DownloadType::HEADERS_ONLY) {
ASSERT_TRUE(test_helper->response_body()); ASSERT_TRUE(test_helper->response_body());
// The "foo" header is removed since the SimpleURLLoader's redirect callback // The "foo" header is removed since the SimpleURLLoader's redirect callback
// marks "foo" header to be removed. // marks "foo" header to be removed.
EXPECT_EQ("None", *test_helper->response_body()); EXPECT_EQ("None", *test_helper->response_body());
}
// Make sure request really was redirected. // Make sure request really was redirected.
EXPECT_EQ(1, num_redirects); EXPECT_EQ(1, num_redirects);
} }
...@@ -933,14 +879,10 @@ TEST_P(SimpleURLLoaderTest, ...@@ -933,14 +879,10 @@ TEST_P(SimpleURLLoaderTest,
test_helper->StartSimpleLoaderAndWait(url_loader_factory_.get()); test_helper->StartSimpleLoaderAndWait(url_loader_factory_.get());
EXPECT_EQ(net::OK, test_helper->simple_url_loader()->NetError()); EXPECT_EQ(net::OK, test_helper->simple_url_loader()->NetError());
if (GetParam() != SimpleLoaderTestHelper::DownloadType::HEADERS_ONLY) {
ASSERT_TRUE(test_helper->response_body()); ASSERT_TRUE(test_helper->response_body());
// The "foo" header is not removed since the SimpleURLLoader's redirect // The "foo" header is not removed since the SimpleURLLoader's redirect
// callback marks "bar" header to be removed. // callback marks "bar" header to be removed.
EXPECT_EQ("Expected Response", *test_helper->response_body()); EXPECT_EQ("Expected Response", *test_helper->response_body());
}
// Make sure request really was redirected. // Make sure request really was redirected.
EXPECT_EQ(1, num_redirects); EXPECT_EQ(1, num_redirects);
} }
...@@ -1014,11 +956,8 @@ TEST_P(SimpleURLLoaderTest, DestroyLoaderInOnComplete) { ...@@ -1014,11 +956,8 @@ TEST_P(SimpleURLLoaderTest, DestroyLoaderInOnComplete) {
CreateHelper(std::move(resource_request)); CreateHelper(std::move(resource_request));
test_helper->set_destroy_loader_on_complete(true); test_helper->set_destroy_loader_on_complete(true);
test_helper->StartSimpleLoaderAndWait(url_loader_factory_.get()); test_helper->StartSimpleLoaderAndWait(url_loader_factory_.get());
if (GetParam() != SimpleLoaderTestHelper::DownloadType::HEADERS_ONLY) {
ASSERT_TRUE(test_helper->response_body()); ASSERT_TRUE(test_helper->response_body());
EXPECT_EQ("Expected Response", *test_helper->response_body()); EXPECT_EQ("Expected Response", *test_helper->response_body());
}
} }
// Check the case where a URLLoaderFactory with a closed Mojo pipe was passed // Check the case where a URLLoaderFactory with a closed Mojo pipe was passed
...@@ -1062,11 +1001,8 @@ TEST_P(SimpleURLLoaderTest, HttpErrorStatusCodeResponseAllowed) { ...@@ -1062,11 +1001,8 @@ TEST_P(SimpleURLLoaderTest, HttpErrorStatusCodeResponseAllowed) {
EXPECT_EQ(net::OK, test_helper->simple_url_loader()->NetError()); EXPECT_EQ(net::OK, test_helper->simple_url_loader()->NetError());
EXPECT_EQ(400, test_helper->GetResponseCode()); EXPECT_EQ(400, test_helper->GetResponseCode());
if (GetParam() != SimpleLoaderTestHelper::DownloadType::HEADERS_ONLY) {
ASSERT_TRUE(test_helper->response_body()); ASSERT_TRUE(test_helper->response_body());
EXPECT_EQ("Echo", *test_helper->response_body()); EXPECT_EQ("Echo", *test_helper->response_body());
}
} }
TEST_P(SimpleURLLoaderTest, EmptyResponseBody) { TEST_P(SimpleURLLoaderTest, EmptyResponseBody) {
...@@ -1076,12 +1012,9 @@ TEST_P(SimpleURLLoaderTest, EmptyResponseBody) { ...@@ -1076,12 +1012,9 @@ TEST_P(SimpleURLLoaderTest, EmptyResponseBody) {
EXPECT_EQ(net::OK, test_helper->simple_url_loader()->NetError()); EXPECT_EQ(net::OK, test_helper->simple_url_loader()->NetError());
EXPECT_EQ(204, test_helper->GetResponseCode()); EXPECT_EQ(204, test_helper->GetResponseCode());
if (GetParam() != SimpleLoaderTestHelper::DownloadType::HEADERS_ONLY) {
ASSERT_TRUE(test_helper->response_body()); ASSERT_TRUE(test_helper->response_body());
// A response body is sent from the NetworkService, but it's empty. // A response body is sent from the NetworkService, but it's empty.
EXPECT_EQ("", *test_helper->response_body()); EXPECT_EQ("", *test_helper->response_body());
}
} }
TEST_P(SimpleURLLoaderTest, BigResponseBody) { TEST_P(SimpleURLLoaderTest, BigResponseBody) {
...@@ -1097,12 +1030,9 @@ TEST_P(SimpleURLLoaderTest, BigResponseBody) { ...@@ -1097,12 +1030,9 @@ TEST_P(SimpleURLLoaderTest, BigResponseBody) {
EXPECT_EQ(net::OK, test_helper->simple_url_loader()->NetError()); EXPECT_EQ(net::OK, test_helper->simple_url_loader()->NetError());
EXPECT_EQ(200, test_helper->GetResponseCode()); EXPECT_EQ(200, test_helper->GetResponseCode());
if (GetParam() != SimpleLoaderTestHelper::DownloadType::HEADERS_ONLY) {
ASSERT_TRUE(test_helper->response_body()); ASSERT_TRUE(test_helper->response_body());
EXPECT_EQ(kResponseSize, test_helper->response_body()->length()); EXPECT_EQ(kResponseSize, test_helper->response_body()->length());
EXPECT_EQ(std::string(kResponseSize, 'a'), *test_helper->response_body()); EXPECT_EQ(std::string(kResponseSize, 'a'), *test_helper->response_body());
}
} }
TEST_P(SimpleURLLoaderTest, ResponseBodyWithSizeMatchingLimit) { TEST_P(SimpleURLLoaderTest, ResponseBodyWithSizeMatchingLimit) {
...@@ -1119,12 +1049,9 @@ TEST_P(SimpleURLLoaderTest, ResponseBodyWithSizeMatchingLimit) { ...@@ -1119,12 +1049,9 @@ TEST_P(SimpleURLLoaderTest, ResponseBodyWithSizeMatchingLimit) {
EXPECT_EQ(net::OK, test_helper->simple_url_loader()->NetError()); EXPECT_EQ(net::OK, test_helper->simple_url_loader()->NetError());
EXPECT_EQ(200, test_helper->GetResponseCode()); EXPECT_EQ(200, test_helper->GetResponseCode());
if (GetParam() != SimpleLoaderTestHelper::DownloadType::HEADERS_ONLY) {
ASSERT_TRUE(test_helper->response_body()); ASSERT_TRUE(test_helper->response_body());
EXPECT_EQ(kResponseSize, test_helper->response_body()->length()); EXPECT_EQ(kResponseSize, test_helper->response_body()->length());
EXPECT_EQ(std::string(kResponseSize, 'a'), *test_helper->response_body()); EXPECT_EQ(std::string(kResponseSize, 'a'), *test_helper->response_body());
}
} }
TEST_P(SimpleURLLoaderTest, ResponseBodyWithSizeBelowLimit) { TEST_P(SimpleURLLoaderTest, ResponseBodyWithSizeBelowLimit) {
...@@ -1142,12 +1069,9 @@ TEST_P(SimpleURLLoaderTest, ResponseBodyWithSizeBelowLimit) { ...@@ -1142,12 +1069,9 @@ TEST_P(SimpleURLLoaderTest, ResponseBodyWithSizeBelowLimit) {
EXPECT_EQ(net::OK, test_helper->simple_url_loader()->NetError()); EXPECT_EQ(net::OK, test_helper->simple_url_loader()->NetError());
EXPECT_EQ(200, test_helper->GetResponseCode()); EXPECT_EQ(200, test_helper->GetResponseCode());
if (GetParam() != SimpleLoaderTestHelper::DownloadType::HEADERS_ONLY) {
ASSERT_TRUE(test_helper->response_body()); ASSERT_TRUE(test_helper->response_body());
EXPECT_EQ(kResponseSize, test_helper->response_body()->length()); EXPECT_EQ(kResponseSize, test_helper->response_body()->length());
EXPECT_EQ(std::string(kResponseSize, 'a'), *test_helper->response_body()); EXPECT_EQ(std::string(kResponseSize, 'a'), *test_helper->response_body());
}
} }
TEST_P(SimpleURLLoaderTest, ResponseBodyWithSizeAboveLimit) { TEST_P(SimpleURLLoaderTest, ResponseBodyWithSizeAboveLimit) {
...@@ -1162,12 +1086,8 @@ TEST_P(SimpleURLLoaderTest, ResponseBodyWithSizeAboveLimit) { ...@@ -1162,12 +1086,8 @@ TEST_P(SimpleURLLoaderTest, ResponseBodyWithSizeAboveLimit) {
test_helper->StartSimpleLoaderAndWait(url_loader_factory_.get(), test_helper->StartSimpleLoaderAndWait(url_loader_factory_.get(),
kResponseSize - 1); kResponseSize - 1);
if (GetParam() == SimpleLoaderTestHelper::DownloadType::HEADERS_ONLY) {
EXPECT_EQ(net::OK, test_helper->simple_url_loader()->NetError());
} else {
EXPECT_EQ(net::ERR_INSUFFICIENT_RESOURCES, EXPECT_EQ(net::ERR_INSUFFICIENT_RESOURCES,
test_helper->simple_url_loader()->NetError()); test_helper->simple_url_loader()->NetError());
}
EXPECT_FALSE(test_helper->response_body()); EXPECT_FALSE(test_helper->response_body());
} }
...@@ -1186,17 +1106,11 @@ TEST_P(SimpleURLLoaderTest, ResponseBodyWithSizeAboveLimitPartialResponse) { ...@@ -1186,17 +1106,11 @@ TEST_P(SimpleURLLoaderTest, ResponseBodyWithSizeAboveLimitPartialResponse) {
test_helper->StartSimpleLoaderAndWait(url_loader_factory_.get(), test_helper->StartSimpleLoaderAndWait(url_loader_factory_.get(),
kMaxResponseSize); kMaxResponseSize);
if (GetParam() == SimpleLoaderTestHelper::DownloadType::HEADERS_ONLY) {
EXPECT_EQ(net::OK, test_helper->simple_url_loader()->NetError());
EXPECT_FALSE(test_helper->response_body());
} else {
EXPECT_EQ(net::ERR_INSUFFICIENT_RESOURCES, EXPECT_EQ(net::ERR_INSUFFICIENT_RESOURCES,
test_helper->simple_url_loader()->NetError()); test_helper->simple_url_loader()->NetError());
ASSERT_TRUE(test_helper->response_body()); ASSERT_TRUE(test_helper->response_body());
EXPECT_EQ(std::string(kMaxResponseSize, 'a'), EXPECT_EQ(std::string(kMaxResponseSize, 'a'), *test_helper->response_body());
*test_helper->response_body());
EXPECT_EQ(kMaxResponseSize, test_helper->response_body()->length()); EXPECT_EQ(kMaxResponseSize, test_helper->response_body()->length());
}
} }
// The next 4 tests duplicate the above 4, but with larger response sizes. This // The next 4 tests duplicate the above 4, but with larger response sizes. This
...@@ -1214,12 +1128,9 @@ TEST_P(SimpleURLLoaderTest, BigResponseBodyWithSizeMatchingLimit) { ...@@ -1214,12 +1128,9 @@ TEST_P(SimpleURLLoaderTest, BigResponseBodyWithSizeMatchingLimit) {
kResponseSize); kResponseSize);
EXPECT_EQ(net::OK, test_helper->simple_url_loader()->NetError()); EXPECT_EQ(net::OK, test_helper->simple_url_loader()->NetError());
if (GetParam() != SimpleLoaderTestHelper::DownloadType::HEADERS_ONLY) {
ASSERT_TRUE(test_helper->response_body()); ASSERT_TRUE(test_helper->response_body());
EXPECT_EQ(kResponseSize, test_helper->response_body()->length()); EXPECT_EQ(kResponseSize, test_helper->response_body()->length());
EXPECT_EQ(std::string(kResponseSize, 'a'), *test_helper->response_body()); EXPECT_EQ(std::string(kResponseSize, 'a'), *test_helper->response_body());
}
} }
TEST_P(SimpleURLLoaderTest, BigResponseBodyWithSizeBelowLimit) { TEST_P(SimpleURLLoaderTest, BigResponseBodyWithSizeBelowLimit) {
...@@ -1236,12 +1147,9 @@ TEST_P(SimpleURLLoaderTest, BigResponseBodyWithSizeBelowLimit) { ...@@ -1236,12 +1147,9 @@ TEST_P(SimpleURLLoaderTest, BigResponseBodyWithSizeBelowLimit) {
kMaxResponseSize); kMaxResponseSize);
EXPECT_EQ(net::OK, test_helper->simple_url_loader()->NetError()); EXPECT_EQ(net::OK, test_helper->simple_url_loader()->NetError());
if (GetParam() != SimpleLoaderTestHelper::DownloadType::HEADERS_ONLY) {
ASSERT_TRUE(test_helper->response_body()); ASSERT_TRUE(test_helper->response_body());
EXPECT_EQ(kResponseSize, test_helper->response_body()->length()); EXPECT_EQ(kResponseSize, test_helper->response_body()->length());
EXPECT_EQ(std::string(kResponseSize, 'a'), *test_helper->response_body()); EXPECT_EQ(std::string(kResponseSize, 'a'), *test_helper->response_body());
}
} }
TEST_P(SimpleURLLoaderTest, BigResponseBodyWithSizeAboveLimit) { TEST_P(SimpleURLLoaderTest, BigResponseBodyWithSizeAboveLimit) {
...@@ -1256,12 +1164,8 @@ TEST_P(SimpleURLLoaderTest, BigResponseBodyWithSizeAboveLimit) { ...@@ -1256,12 +1164,8 @@ TEST_P(SimpleURLLoaderTest, BigResponseBodyWithSizeAboveLimit) {
test_helper->StartSimpleLoaderAndWait(url_loader_factory_.get(), test_helper->StartSimpleLoaderAndWait(url_loader_factory_.get(),
kResponseSize - 1); kResponseSize - 1);
if (GetParam() == SimpleLoaderTestHelper::DownloadType::HEADERS_ONLY) {
EXPECT_EQ(net::OK, test_helper->simple_url_loader()->NetError());
} else {
EXPECT_EQ(net::ERR_INSUFFICIENT_RESOURCES, EXPECT_EQ(net::ERR_INSUFFICIENT_RESOURCES,
test_helper->simple_url_loader()->NetError()); test_helper->simple_url_loader()->NetError());
}
EXPECT_FALSE(test_helper->response_body()); EXPECT_FALSE(test_helper->response_body());
} }
...@@ -1279,17 +1183,11 @@ TEST_P(SimpleURLLoaderTest, BigResponseBodyWithSizeAboveLimitPartialResponse) { ...@@ -1279,17 +1183,11 @@ TEST_P(SimpleURLLoaderTest, BigResponseBodyWithSizeAboveLimitPartialResponse) {
test_helper->StartSimpleLoaderAndWait(url_loader_factory_.get(), test_helper->StartSimpleLoaderAndWait(url_loader_factory_.get(),
kMaxResponseSize); kMaxResponseSize);
if (GetParam() == SimpleLoaderTestHelper::DownloadType::HEADERS_ONLY) {
EXPECT_EQ(net::OK, test_helper->simple_url_loader()->NetError());
EXPECT_FALSE(test_helper->response_body());
} else {
EXPECT_EQ(net::ERR_INSUFFICIENT_RESOURCES, EXPECT_EQ(net::ERR_INSUFFICIENT_RESOURCES,
test_helper->simple_url_loader()->NetError()); test_helper->simple_url_loader()->NetError());
ASSERT_TRUE(test_helper->response_body()); ASSERT_TRUE(test_helper->response_body());
EXPECT_EQ(std::string(kMaxResponseSize, 'a'), EXPECT_EQ(std::string(kMaxResponseSize, 'a'), *test_helper->response_body());
*test_helper->response_body());
EXPECT_EQ(kMaxResponseSize, test_helper->response_body()->length()); EXPECT_EQ(kMaxResponseSize, test_helper->response_body()->length());
}
} }
TEST_P(SimpleURLLoaderTest, NetErrorBeforeHeaders) { TEST_P(SimpleURLLoaderTest, NetErrorBeforeHeaders) {
...@@ -1339,11 +1237,8 @@ TEST_P(SimpleURLLoaderTest, NetErrorAfterHeadersWithPartialResults) { ...@@ -1339,11 +1237,8 @@ TEST_P(SimpleURLLoaderTest, NetErrorAfterHeadersWithPartialResults) {
EXPECT_EQ(net::ERR_CONTENT_DECODING_FAILED, EXPECT_EQ(net::ERR_CONTENT_DECODING_FAILED,
test_helper->simple_url_loader()->NetError()); test_helper->simple_url_loader()->NetError());
EXPECT_EQ(200, test_helper->GetResponseCode()); EXPECT_EQ(200, test_helper->GetResponseCode());
if (GetParam() != SimpleLoaderTestHelper::DownloadType::HEADERS_ONLY) {
ASSERT_TRUE(test_helper->response_body()); ASSERT_TRUE(test_helper->response_body());
EXPECT_EQ("", *test_helper->response_body()); EXPECT_EQ("", *test_helper->response_body());
}
} }
TEST_P(SimpleURLLoaderTest, TruncatedBody) { TEST_P(SimpleURLLoaderTest, TruncatedBody) {
...@@ -1366,11 +1261,8 @@ TEST_P(SimpleURLLoaderTest, TruncatedBodyWithPartialResults) { ...@@ -1366,11 +1261,8 @@ TEST_P(SimpleURLLoaderTest, TruncatedBodyWithPartialResults) {
EXPECT_EQ(net::ERR_CONTENT_LENGTH_MISMATCH, EXPECT_EQ(net::ERR_CONTENT_LENGTH_MISMATCH,
test_helper->simple_url_loader()->NetError()); test_helper->simple_url_loader()->NetError());
EXPECT_EQ(200, test_helper->GetResponseCode()); EXPECT_EQ(200, test_helper->GetResponseCode());
if (GetParam() != SimpleLoaderTestHelper::DownloadType::HEADERS_ONLY) {
ASSERT_TRUE(test_helper->response_body()); ASSERT_TRUE(test_helper->response_body());
EXPECT_EQ(kTruncatedBody, *test_helper->response_body()); EXPECT_EQ(kTruncatedBody, *test_helper->response_body());
}
} }
// Test case where NetworkService is destroyed before headers are received (and // Test case where NetworkService is destroyed before headers are received (and
...@@ -1399,11 +1291,8 @@ TEST_P(SimpleURLLoaderTest, UploadShortString) { ...@@ -1399,11 +1291,8 @@ TEST_P(SimpleURLLoaderTest, UploadShortString) {
"text/plain"); "text/plain");
test_helper->StartSimpleLoaderAndWait(url_loader_factory_.get()); test_helper->StartSimpleLoaderAndWait(url_loader_factory_.get());
EXPECT_EQ(net::OK, test_helper->simple_url_loader()->NetError()); EXPECT_EQ(net::OK, test_helper->simple_url_loader()->NetError());
if (GetParam() != SimpleLoaderTestHelper::DownloadType::HEADERS_ONLY) {
ASSERT_TRUE(test_helper->response_body()); ASSERT_TRUE(test_helper->response_body());
EXPECT_EQ(kShortUploadBody, *test_helper->response_body()); EXPECT_EQ(kShortUploadBody, *test_helper->response_body());
}
} }
TEST_P(SimpleURLLoaderTest, UploadLongString) { TEST_P(SimpleURLLoaderTest, UploadLongString) {
...@@ -1414,11 +1303,8 @@ TEST_P(SimpleURLLoaderTest, UploadLongString) { ...@@ -1414,11 +1303,8 @@ TEST_P(SimpleURLLoaderTest, UploadLongString) {
"text/plain"); "text/plain");
test_helper->StartSimpleLoaderAndWait(url_loader_factory_.get()); test_helper->StartSimpleLoaderAndWait(url_loader_factory_.get());
EXPECT_EQ(net::OK, test_helper->simple_url_loader()->NetError()); EXPECT_EQ(net::OK, test_helper->simple_url_loader()->NetError());
if (GetParam() != SimpleLoaderTestHelper::DownloadType::HEADERS_ONLY) {
ASSERT_TRUE(test_helper->response_body()); ASSERT_TRUE(test_helper->response_body());
EXPECT_EQ(long_string, *test_helper->response_body()); EXPECT_EQ(long_string, *test_helper->response_body());
}
} }
TEST_P(SimpleURLLoaderTest, UploadEmptyString) { TEST_P(SimpleURLLoaderTest, UploadEmptyString) {
...@@ -1427,25 +1313,19 @@ TEST_P(SimpleURLLoaderTest, UploadEmptyString) { ...@@ -1427,25 +1313,19 @@ TEST_P(SimpleURLLoaderTest, UploadEmptyString) {
test_helper->simple_url_loader()->AttachStringForUpload("", "text/plain"); test_helper->simple_url_loader()->AttachStringForUpload("", "text/plain");
test_helper->StartSimpleLoaderAndWait(url_loader_factory_.get()); test_helper->StartSimpleLoaderAndWait(url_loader_factory_.get());
EXPECT_EQ(net::OK, test_helper->simple_url_loader()->NetError()); EXPECT_EQ(net::OK, test_helper->simple_url_loader()->NetError());
if (GetParam() != SimpleLoaderTestHelper::DownloadType::HEADERS_ONLY) {
ASSERT_TRUE(test_helper->response_body()); ASSERT_TRUE(test_helper->response_body());
EXPECT_EQ("", *test_helper->response_body()); EXPECT_EQ("", *test_helper->response_body());
}
// Also make sure the correct method was sent, with the right content-type. // Also make sure the correct method was sent, with the right content-type.
test_helper = CreateHelperForURL(test_server_.GetURL("/echoall"), "POST"); test_helper = CreateHelperForURL(test_server_.GetURL("/echoall"), "POST");
test_helper->simple_url_loader()->AttachStringForUpload("", "text/plain"); test_helper->simple_url_loader()->AttachStringForUpload("", "text/plain");
test_helper->StartSimpleLoaderAndWait(url_loader_factory_.get()); test_helper->StartSimpleLoaderAndWait(url_loader_factory_.get());
EXPECT_EQ(net::OK, test_helper->simple_url_loader()->NetError()); EXPECT_EQ(net::OK, test_helper->simple_url_loader()->NetError());
if (GetParam() != SimpleLoaderTestHelper::DownloadType::HEADERS_ONLY) {
ASSERT_TRUE(test_helper->response_body()); ASSERT_TRUE(test_helper->response_body());
EXPECT_NE(std::string::npos, EXPECT_NE(std::string::npos,
test_helper->response_body()->find("Content-Type: text/plain")); test_helper->response_body()->find("Content-Type: text/plain"));
EXPECT_NE(std::string::npos, test_helper->response_body()->find("POST /")); EXPECT_NE(std::string::npos, test_helper->response_body()->find("POST /"));
EXPECT_EQ(std::string::npos, test_helper->response_body()->find("PUT /")); EXPECT_EQ(std::string::npos, test_helper->response_body()->find("PUT /"));
}
} }
TEST_P(SimpleURLLoaderTest, UploadShortStringWithRetry) { TEST_P(SimpleURLLoaderTest, UploadShortStringWithRetry) {
...@@ -1457,11 +1337,8 @@ TEST_P(SimpleURLLoaderTest, UploadShortStringWithRetry) { ...@@ -1457,11 +1337,8 @@ TEST_P(SimpleURLLoaderTest, UploadShortStringWithRetry) {
1, SimpleURLLoader::RETRY_ON_5XX); 1, SimpleURLLoader::RETRY_ON_5XX);
test_helper->StartSimpleLoaderAndWait(url_loader_factory_.get()); test_helper->StartSimpleLoaderAndWait(url_loader_factory_.get());
EXPECT_EQ(net::OK, test_helper->simple_url_loader()->NetError()); EXPECT_EQ(net::OK, test_helper->simple_url_loader()->NetError());
if (GetParam() != SimpleLoaderTestHelper::DownloadType::HEADERS_ONLY) {
ASSERT_TRUE(test_helper->response_body()); ASSERT_TRUE(test_helper->response_body());
EXPECT_EQ(kShortUploadBody, *test_helper->response_body()); EXPECT_EQ(kShortUploadBody, *test_helper->response_body());
}
if (GetParam() == SimpleLoaderTestHelper::DownloadType::AS_STREAM) if (GetParam() == SimpleLoaderTestHelper::DownloadType::AS_STREAM)
EXPECT_EQ(1, test_helper->download_as_stream_retries()); EXPECT_EQ(1, test_helper->download_as_stream_retries());
...@@ -1477,11 +1354,8 @@ TEST_P(SimpleURLLoaderTest, UploadLongStringWithRetry) { ...@@ -1477,11 +1354,8 @@ TEST_P(SimpleURLLoaderTest, UploadLongStringWithRetry) {
1, SimpleURLLoader::RETRY_ON_5XX); 1, SimpleURLLoader::RETRY_ON_5XX);
test_helper->StartSimpleLoaderAndWait(url_loader_factory_.get()); test_helper->StartSimpleLoaderAndWait(url_loader_factory_.get());
EXPECT_EQ(net::OK, test_helper->simple_url_loader()->NetError()); EXPECT_EQ(net::OK, test_helper->simple_url_loader()->NetError());
if (GetParam() != SimpleLoaderTestHelper::DownloadType::HEADERS_ONLY) {
ASSERT_TRUE(test_helper->response_body()); ASSERT_TRUE(test_helper->response_body());
EXPECT_EQ(long_string, *test_helper->response_body()); EXPECT_EQ(long_string, *test_helper->response_body());
}
if (GetParam() == SimpleLoaderTestHelper::DownloadType::AS_STREAM) if (GetParam() == SimpleLoaderTestHelper::DownloadType::AS_STREAM)
EXPECT_EQ(1, test_helper->download_as_stream_retries()); EXPECT_EQ(1, test_helper->download_as_stream_retries());
...@@ -1494,11 +1368,8 @@ TEST_P(SimpleURLLoaderTest, UploadFile) { ...@@ -1494,11 +1368,8 @@ TEST_P(SimpleURLLoaderTest, UploadFile) {
"text/plain"); "text/plain");
test_helper->StartSimpleLoaderAndWait(url_loader_factory_.get()); test_helper->StartSimpleLoaderAndWait(url_loader_factory_.get());
EXPECT_EQ(net::OK, test_helper->simple_url_loader()->NetError()); EXPECT_EQ(net::OK, test_helper->simple_url_loader()->NetError());
if (GetParam() != SimpleLoaderTestHelper::DownloadType::HEADERS_ONLY) {
ASSERT_TRUE(test_helper->response_body()); ASSERT_TRUE(test_helper->response_body());
EXPECT_EQ(GetTestFileContents(), *test_helper->response_body()); EXPECT_EQ(GetTestFileContents(), *test_helper->response_body());
}
// Also make sure the correct method was sent, with the right content-type. // Also make sure the correct method was sent, with the right content-type.
test_helper = CreateHelperForURL(test_server_.GetURL("/echoall"), "POST"); test_helper = CreateHelperForURL(test_server_.GetURL("/echoall"), "POST");
...@@ -1506,14 +1377,11 @@ TEST_P(SimpleURLLoaderTest, UploadFile) { ...@@ -1506,14 +1377,11 @@ TEST_P(SimpleURLLoaderTest, UploadFile) {
"text/plain"); "text/plain");
test_helper->StartSimpleLoaderAndWait(url_loader_factory_.get()); test_helper->StartSimpleLoaderAndWait(url_loader_factory_.get());
EXPECT_EQ(net::OK, test_helper->simple_url_loader()->NetError()); EXPECT_EQ(net::OK, test_helper->simple_url_loader()->NetError());
if (GetParam() != SimpleLoaderTestHelper::DownloadType::HEADERS_ONLY) {
ASSERT_TRUE(test_helper->response_body()); ASSERT_TRUE(test_helper->response_body());
EXPECT_NE(std::string::npos, EXPECT_NE(std::string::npos,
test_helper->response_body()->find("Content-Type: text/plain")); test_helper->response_body()->find("Content-Type: text/plain"));
EXPECT_NE(std::string::npos, test_helper->response_body()->find("POST /")); EXPECT_NE(std::string::npos, test_helper->response_body()->find("POST /"));
EXPECT_EQ(std::string::npos, test_helper->response_body()->find("PUT /")); EXPECT_EQ(std::string::npos, test_helper->response_body()->find("PUT /"));
}
} }
TEST_P(SimpleURLLoaderTest, UploadFileWithPut) { TEST_P(SimpleURLLoaderTest, UploadFileWithPut) {
...@@ -1523,11 +1391,8 @@ TEST_P(SimpleURLLoaderTest, UploadFileWithPut) { ...@@ -1523,11 +1391,8 @@ TEST_P(SimpleURLLoaderTest, UploadFileWithPut) {
"text/plain"); "text/plain");
test_helper->StartSimpleLoaderAndWait(url_loader_factory_.get()); test_helper->StartSimpleLoaderAndWait(url_loader_factory_.get());
EXPECT_EQ(net::OK, test_helper->simple_url_loader()->NetError()); EXPECT_EQ(net::OK, test_helper->simple_url_loader()->NetError());
if (GetParam() != SimpleLoaderTestHelper::DownloadType::HEADERS_ONLY) {
ASSERT_TRUE(test_helper->response_body()); ASSERT_TRUE(test_helper->response_body());
EXPECT_EQ(GetTestFileContents(), *test_helper->response_body()); EXPECT_EQ(GetTestFileContents(), *test_helper->response_body());
}
// Also make sure the correct method was sent, with the right content-type. // Also make sure the correct method was sent, with the right content-type.
test_helper = CreateHelperForURL(test_server_.GetURL("/echoall"), "PUT"); test_helper = CreateHelperForURL(test_server_.GetURL("/echoall"), "PUT");
...@@ -1535,8 +1400,6 @@ TEST_P(SimpleURLLoaderTest, UploadFileWithPut) { ...@@ -1535,8 +1400,6 @@ TEST_P(SimpleURLLoaderTest, UploadFileWithPut) {
"text/salted"); "text/salted");
test_helper->StartSimpleLoaderAndWait(url_loader_factory_.get()); test_helper->StartSimpleLoaderAndWait(url_loader_factory_.get());
EXPECT_EQ(net::OK, test_helper->simple_url_loader()->NetError()); EXPECT_EQ(net::OK, test_helper->simple_url_loader()->NetError());
if (GetParam() != SimpleLoaderTestHelper::DownloadType::HEADERS_ONLY) {
ASSERT_TRUE(test_helper->response_body()); ASSERT_TRUE(test_helper->response_body());
EXPECT_NE(std::string::npos, EXPECT_NE(std::string::npos,
test_helper->response_body()->find("Content-Type: text/salted")); test_helper->response_body()->find("Content-Type: text/salted"));
...@@ -1544,7 +1407,6 @@ TEST_P(SimpleURLLoaderTest, UploadFileWithPut) { ...@@ -1544,7 +1407,6 @@ TEST_P(SimpleURLLoaderTest, UploadFileWithPut) {
test_helper->response_body()->find("Content-Type: text/plain")); test_helper->response_body()->find("Content-Type: text/plain"));
EXPECT_EQ(std::string::npos, test_helper->response_body()->find("POST /")); EXPECT_EQ(std::string::npos, test_helper->response_body()->find("POST /"));
EXPECT_NE(std::string::npos, test_helper->response_body()->find("PUT /")); EXPECT_NE(std::string::npos, test_helper->response_body()->find("PUT /"));
}
} }
TEST_P(SimpleURLLoaderTest, UploadFileWithRetry) { TEST_P(SimpleURLLoaderTest, UploadFileWithRetry) {
...@@ -1556,11 +1418,8 @@ TEST_P(SimpleURLLoaderTest, UploadFileWithRetry) { ...@@ -1556,11 +1418,8 @@ TEST_P(SimpleURLLoaderTest, UploadFileWithRetry) {
1, SimpleURLLoader::RETRY_ON_5XX); 1, SimpleURLLoader::RETRY_ON_5XX);
test_helper->StartSimpleLoaderAndWait(url_loader_factory_.get()); test_helper->StartSimpleLoaderAndWait(url_loader_factory_.get());
EXPECT_EQ(net::OK, test_helper->simple_url_loader()->NetError()); EXPECT_EQ(net::OK, test_helper->simple_url_loader()->NetError());
if (GetParam() != SimpleLoaderTestHelper::DownloadType::HEADERS_ONLY) {
ASSERT_TRUE(test_helper->response_body()); ASSERT_TRUE(test_helper->response_body());
EXPECT_EQ(GetTestFileContents(), *test_helper->response_body()); EXPECT_EQ(GetTestFileContents(), *test_helper->response_body());
}
if (GetParam() == SimpleLoaderTestHelper::DownloadType::AS_STREAM) if (GetParam() == SimpleLoaderTestHelper::DownloadType::AS_STREAM)
EXPECT_EQ(1, test_helper->download_as_stream_retries()); EXPECT_EQ(1, test_helper->download_as_stream_retries());
...@@ -2115,17 +1974,13 @@ TEST_P(SimpleURLLoaderTest, CloseClientPipeOrder) { ...@@ -2115,17 +1974,13 @@ TEST_P(SimpleURLLoaderTest, CloseClientPipeOrder) {
} }
if (!allow_partial_results) { if (!allow_partial_results) {
EXPECT_FALSE(test_helper->response_body()); EXPECT_FALSE(test_helper->response_body());
} else if (GetParam() != } else {
SimpleLoaderTestHelper::DownloadType::HEADERS_ONLY) {
ASSERT_TRUE(test_helper->response_body()); ASSERT_TRUE(test_helper->response_body());
EXPECT_EQ(std::string(bytes_received, 'a'), EXPECT_EQ(std::string(bytes_received, 'a'),
*test_helper->response_body()); *test_helper->response_body());
} }
} else { } else {
EXPECT_EQ(net::OK, test_helper->simple_url_loader()->NetError()); EXPECT_EQ(net::OK, test_helper->simple_url_loader()->NetError());
if (GetParam() !=
SimpleLoaderTestHelper::DownloadType::HEADERS_ONLY) {
ASSERT_TRUE(test_helper->response_body()); ASSERT_TRUE(test_helper->response_body());
EXPECT_EQ(std::string(bytes_received, 'a'), EXPECT_EQ(std::string(bytes_received, 'a'),
*test_helper->response_body()); *test_helper->response_body());
...@@ -2134,7 +1989,6 @@ TEST_P(SimpleURLLoaderTest, CloseClientPipeOrder) { ...@@ -2134,7 +1989,6 @@ TEST_P(SimpleURLLoaderTest, CloseClientPipeOrder) {
} }
} }
} }
}
} }
// Make sure the close client pipe message doesn't cause any issues. // Make sure the close client pipe message doesn't cause any issues.
...@@ -2165,11 +2019,8 @@ TEST_P(SimpleURLLoaderTest, SuccessAndCloseClientPipeBeforeBodyComplete) { ...@@ -2165,11 +2019,8 @@ TEST_P(SimpleURLLoaderTest, SuccessAndCloseClientPipeBeforeBodyComplete) {
EXPECT_EQ(net::OK, test_helper->simple_url_loader()->NetError()); EXPECT_EQ(net::OK, test_helper->simple_url_loader()->NetError());
EXPECT_EQ(200, test_helper->GetResponseCode()); EXPECT_EQ(200, test_helper->GetResponseCode());
if (GetParam() != SimpleLoaderTestHelper::DownloadType::HEADERS_ONLY) {
ASSERT_TRUE(test_helper->response_body()); ASSERT_TRUE(test_helper->response_body());
EXPECT_EQ("a", *test_helper->response_body()); EXPECT_EQ("a", *test_helper->response_body());
}
} }
// Make sure the close client pipe message doesn't cause any issues. // Make sure the close client pipe message doesn't cause any issues.
...@@ -2185,11 +2036,8 @@ TEST_P(SimpleURLLoaderTest, SuccessAndCloseClientPipeAfterBodyComplete) { ...@@ -2185,11 +2036,8 @@ TEST_P(SimpleURLLoaderTest, SuccessAndCloseClientPipeAfterBodyComplete) {
EXPECT_EQ(net::OK, test_helper->simple_url_loader()->NetError()); EXPECT_EQ(net::OK, test_helper->simple_url_loader()->NetError());
EXPECT_EQ(200, test_helper->GetResponseCode()); EXPECT_EQ(200, test_helper->GetResponseCode());
if (GetParam() != SimpleLoaderTestHelper::DownloadType::HEADERS_ONLY) {
ASSERT_TRUE(test_helper->response_body()); ASSERT_TRUE(test_helper->response_body());
EXPECT_EQ("a", *test_helper->response_body()); EXPECT_EQ("a", *test_helper->response_body());
}
} }
TEST_P(SimpleURLLoaderTest, DoubleReceivedResponse) { TEST_P(SimpleURLLoaderTest, DoubleReceivedResponse) {
...@@ -2363,11 +2211,8 @@ TEST_P(SimpleURLLoaderTest, RetryOn5xx) { ...@@ -2363,11 +2211,8 @@ TEST_P(SimpleURLLoaderTest, RetryOn5xx) {
if (test_case.expect_success) { if (test_case.expect_success) {
EXPECT_EQ(net::OK, test_helper->simple_url_loader()->NetError()); EXPECT_EQ(net::OK, test_helper->simple_url_loader()->NetError());
EXPECT_EQ(200, test_helper->GetResponseCode()); EXPECT_EQ(200, test_helper->GetResponseCode());
if (GetParam() != SimpleLoaderTestHelper::DownloadType::HEADERS_ONLY) {
ASSERT_TRUE(test_helper->response_body()); ASSERT_TRUE(test_helper->response_body());
EXPECT_EQ(1u, test_helper->response_body()->size()); EXPECT_EQ(1u, test_helper->response_body()->size());
}
} else { } else {
EXPECT_EQ(501, test_helper->GetResponseCode()); EXPECT_EQ(501, test_helper->GetResponseCode());
EXPECT_FALSE(test_helper->response_body()); EXPECT_FALSE(test_helper->response_body());
...@@ -2431,7 +2276,6 @@ TEST_P(SimpleURLLoaderTest, RetryAfterRedirect) { ...@@ -2431,7 +2276,6 @@ TEST_P(SimpleURLLoaderTest, RetryAfterRedirect) {
loader_factory.RunTest(test_helper.get()); loader_factory.RunTest(test_helper.get());
EXPECT_EQ(200, test_helper->GetResponseCode()); EXPECT_EQ(200, test_helper->GetResponseCode());
if (GetParam() != SimpleLoaderTestHelper::DownloadType::HEADERS_ONLY)
EXPECT_TRUE(test_helper->response_body()); EXPECT_TRUE(test_helper->response_body());
EXPECT_EQ(2, num_redirects); EXPECT_EQ(2, num_redirects);
...@@ -2535,11 +2379,8 @@ TEST_P(SimpleURLLoaderTest, RetryOnNetworkChange) { ...@@ -2535,11 +2379,8 @@ TEST_P(SimpleURLLoaderTest, RetryOnNetworkChange) {
if (test_case.expect_success) { if (test_case.expect_success) {
EXPECT_EQ(net::OK, test_helper->simple_url_loader()->NetError()); EXPECT_EQ(net::OK, test_helper->simple_url_loader()->NetError());
EXPECT_EQ(200, test_helper->GetResponseCode()); EXPECT_EQ(200, test_helper->GetResponseCode());
if (GetParam() != SimpleLoaderTestHelper::DownloadType::HEADERS_ONLY) {
ASSERT_TRUE(test_helper->response_body()); ASSERT_TRUE(test_helper->response_body());
EXPECT_EQ(1u, test_helper->response_body()->size()); EXPECT_EQ(1u, test_helper->response_body()->size());
}
} else { } else {
EXPECT_EQ(net::ERR_NETWORK_CHANGED, EXPECT_EQ(net::ERR_NETWORK_CHANGED,
test_helper->simple_url_loader()->NetError()); test_helper->simple_url_loader()->NetError());
...@@ -2626,10 +2467,8 @@ TEST_P(SimpleURLLoaderTest, UploadLongStringStartReadTwice) { ...@@ -2626,10 +2467,8 @@ TEST_P(SimpleURLLoaderTest, UploadLongStringStartReadTwice) {
loader_factory.RunTest(test_helper.get()); loader_factory.RunTest(test_helper.get());
EXPECT_EQ(net::OK, test_helper->simple_url_loader()->NetError()); EXPECT_EQ(net::OK, test_helper->simple_url_loader()->NetError());
if (GetParam() != SimpleLoaderTestHelper::DownloadType::HEADERS_ONLY) {
ASSERT_TRUE(test_helper->response_body()); ASSERT_TRUE(test_helper->response_body());
EXPECT_EQ("", *test_helper->response_body()); EXPECT_EQ("", *test_helper->response_body());
}
} }
// Test the case where DataPipeGetter::Read is called a second time, after only // Test the case where DataPipeGetter::Read is called a second time, after only
...@@ -2655,11 +2494,8 @@ TEST_P(SimpleURLLoaderTest, ...@@ -2655,11 +2494,8 @@ TEST_P(SimpleURLLoaderTest,
loader_factory.RunTest(test_helper.get()); loader_factory.RunTest(test_helper.get());
EXPECT_EQ(net::OK, test_helper->simple_url_loader()->NetError()); EXPECT_EQ(net::OK, test_helper->simple_url_loader()->NetError());
if (GetParam() != SimpleLoaderTestHelper::DownloadType::HEADERS_ONLY) {
ASSERT_TRUE(test_helper->response_body()); ASSERT_TRUE(test_helper->response_body());
EXPECT_EQ("", *test_helper->response_body()); EXPECT_EQ("", *test_helper->response_body());
}
} }
// Test for GetFinalURL. // Test for GetFinalURL.
...@@ -2693,7 +2529,6 @@ INSTANTIATE_TEST_CASE_P( ...@@ -2693,7 +2529,6 @@ INSTANTIATE_TEST_CASE_P(
testing::Values(SimpleLoaderTestHelper::DownloadType::TO_STRING, testing::Values(SimpleLoaderTestHelper::DownloadType::TO_STRING,
SimpleLoaderTestHelper::DownloadType::TO_FILE, SimpleLoaderTestHelper::DownloadType::TO_FILE,
SimpleLoaderTestHelper::DownloadType::TO_TEMP_FILE, SimpleLoaderTestHelper::DownloadType::TO_TEMP_FILE,
SimpleLoaderTestHelper::DownloadType::HEADERS_ONLY,
SimpleLoaderTestHelper::DownloadType::AS_STREAM)); SimpleLoaderTestHelper::DownloadType::AS_STREAM));
class SimpleURLLoaderFileTest : public SimpleURLLoaderTestBase, class SimpleURLLoaderFileTest : public SimpleURLLoaderTestBase,
......
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