Commit 3fb6d9e3 authored by Antonio Gomes's avatar Antonio Gomes Committed by Commit Bot

Allow TestURLLoaderFactory::SimulateResponse's mock responses to fail

This CL makes the TestURLLoaderFactory::SimulateResponse API more flexible in the following ways:

- it starts to actually use the |net_error| parameter (to build the URLLoaderCompletionatus
  instance)
- it adds an extra (also optional) net::HttpStatusCode parameter, so that
  one can more easily mock failing responses.
- one can see it in action in [1].

[1] https://crrev.com/c/1114998/components/autofill/core/browser/autofill_download_manager_unittest.cc#283

Bug: 773295
Cq-Include-Trybots: luci.chromium.try:linux_mojo
Change-Id: Iba4edf640b3ff82e035ffbe26c3066d404f18ce7
Reviewed-on: https://chromium-review.googlesource.com/1120916
Commit-Queue: Antonio Gomes <tonikitoo@igalia.com>
Reviewed-by: default avatarAntonio Gomes <tonikitoo@igalia.com>
Reviewed-by: default avatarMatt Menke <mmenke@chromium.org>
Cr-Commit-Position: refs/heads/master@{#571635}
parent 5c0a0a10
......@@ -133,9 +133,10 @@ bool TestURLLoaderFactory::CreateLoaderAndStartInternal(
void TestURLLoaderFactory::SimulateResponse(
TestURLLoaderFactory::PendingRequest request,
std::string content,
int net_error) {
network::URLLoaderCompletionStatus status(net::OK);
ResourceResponseHead head = CreateResourceResponseHead(net::HTTP_OK);
int net_error,
net::HttpStatusCode http_status) {
network::URLLoaderCompletionStatus status(net_error);
ResourceResponseHead head = CreateResourceResponseHead(http_status);
status.decoded_body_length = content.size();
SimulateResponseImpl(request.client.get(), TestURLLoaderFactory::Redirects(),
head, content, status);
......
......@@ -78,7 +78,8 @@ class TestURLLoaderFactory : public mojom::URLLoaderFactory {
// pending_requests(). Prefer using AddResponse.
static void SimulateResponse(PendingRequest request,
std::string content,
int net_error = net::OK);
int net_error = net::OK,
net::HttpStatusCode status = net::HTTP_OK);
static ResourceResponseHead CreateResourceResponseHead(
net::HttpStatusCode http_status);
......
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