Commit d7b2118c authored by Maks Orlovich's avatar Maks Orlovich Committed by Commit Bot

TestURLLoaderFactory: set decoded_body_length in advanced AddResponse.

All other methods do the same, and so it was surprising when doing AddResponse
with same arguments that would work in SimulateResponseForPendingRequest
produced a fetch failure (especially when many layers were involved).

Cq-Include-Trybots: luci.chromium.try:linux_mojo
Change-Id: I9faf75cb3ea415f2b04d87aa7f8fcd895bfc7438
Reviewed-on: https://chromium-review.googlesource.com/1169312Reviewed-by: default avatarMatt Menke <mmenke@chromium.org>
Commit-Queue: Maks Orlovich <morlovich@chromium.org>
Cr-Commit-Position: refs/heads/master@{#582128}
parent c23d1b73
...@@ -42,6 +42,7 @@ void TestURLLoaderFactory::AddResponse(const GURL& url, ...@@ -42,6 +42,7 @@ void TestURLLoaderFactory::AddResponse(const GURL& url,
response.head = head; response.head = head;
response.content = content; response.content = content;
response.status = status; response.status = status;
response.status.decoded_body_length = content.size();
response.flags = flags; response.flags = flags;
responses_[url] = response; responses_[url] = response;
...@@ -60,7 +61,6 @@ void TestURLLoaderFactory::AddResponse(const std::string& url, ...@@ -60,7 +61,6 @@ void TestURLLoaderFactory::AddResponse(const std::string& url,
ResourceResponseHead head = CreateResourceResponseHead(http_status); ResourceResponseHead head = CreateResourceResponseHead(http_status);
head.mime_type = "text/html"; head.mime_type = "text/html";
URLLoaderCompletionStatus status; URLLoaderCompletionStatus status;
status.decoded_body_length = content.size();
AddResponse(GURL(url), head, content, status); AddResponse(GURL(url), head, content, status);
} }
......
...@@ -41,6 +41,9 @@ class TestURLLoaderFactoryTest : public testing::Test { ...@@ -41,6 +41,9 @@ class TestURLLoaderFactoryTest : public testing::Test {
EXPECT_TRUE(client->response_body().is_valid()); EXPECT_TRUE(client->response_body().is_valid());
EXPECT_TRUE( EXPECT_TRUE(
mojo::BlockingCopyToString(client->response_body_release(), &response)); mojo::BlockingCopyToString(client->response_body_release(), &response));
EXPECT_EQ(
static_cast<size_t>(client->completion_status().decoded_body_length),
response.length());
return response; return response;
} }
...@@ -72,6 +75,20 @@ TEST_F(TestURLLoaderFactoryTest, Simple) { ...@@ -72,6 +75,20 @@ TEST_F(TestURLLoaderFactoryTest, Simple) {
EXPECT_EQ(GetData(&client2), data); EXPECT_EQ(GetData(&client2), data);
} }
TEST_F(TestURLLoaderFactoryTest, AddResponseAdvanced) {
std::string url = "http://example.com";
std::string body = "Happy robot";
// Test the full-featured version of AddResponse.
factory()->AddResponse(GURL(url), CreateResourceResponseHead(net::HTTP_OK),
body, URLLoaderCompletionStatus(net::OK));
StartRequest(url);
client()->RunUntilComplete();
ASSERT_TRUE(client()->response_head().headers != nullptr);
EXPECT_EQ(net::HTTP_OK, client()->response_head().headers->response_code());
EXPECT_EQ(body, GetData(client()));
}
TEST_F(TestURLLoaderFactoryTest, AddResponse404) { TEST_F(TestURLLoaderFactoryTest, AddResponse404) {
std::string url = "http://foo"; std::string url = "http://foo";
std::string body = "Sad robot"; std::string body = "Sad robot";
...@@ -125,7 +142,6 @@ TEST_F(TestURLLoaderFactoryTest, Redirects) { ...@@ -125,7 +142,6 @@ TEST_F(TestURLLoaderFactoryTest, Redirects) {
{redirect_info, ResourceResponseHead()}}; {redirect_info, ResourceResponseHead()}};
URLLoaderCompletionStatus status; URLLoaderCompletionStatus status;
std::string content = "foo"; std::string content = "foo";
status.decoded_body_length = content.size();
factory()->AddResponse(url, ResourceResponseHead(), content, status, factory()->AddResponse(url, ResourceResponseHead(), content, status,
redirects); redirects);
StartRequest(url.spec()); StartRequest(url.spec());
......
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