Commit 9d31a5ee authored by Yoichi Osato's avatar Yoichi Osato Committed by Commit Bot

Add fetch uploading big arraybuffer test in LoaderBrowserTest.

This CL adds fetch uploading 150Mbytes arraybuffer test.

Since similar layouttest was so slow, I decided to test it in browser
test.

Bug: 919361
Change-Id: I693e67666e71b999276f25cfe0c0ff56436c4369
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2490964
Commit-Queue: Yoichi Osato <yoichio@chromium.org>
Reviewed-by: default avatarMatt Menke <mmenke@chromium.org>
Cr-Commit-Position: refs/heads/master@{#821648}
parent 80c364fa
......@@ -75,6 +75,17 @@ class LoaderBrowserTest : public ContentBrowserTest,
host_resolver()->AddRule("*", "127.0.0.1");
}
void WaitForTitleTest(const base::string16& expected_title,
const std::vector<base::string16> additional_titles) {
TitleWatcher title_watcher(shell()->web_contents(), expected_title);
for (const auto& title : additional_titles) {
title_watcher.AlsoWaitForTitle(title);
}
base::string16 actual_title = title_watcher.WaitAndGetTitle();
EXPECT_EQ(expected_title, actual_title);
}
void CheckTitleTest(const GURL& url, const std::string& expected_title) {
base::string16 expected_title16(ASCIIToUTF16(expected_title));
TitleWatcher title_watcher(shell()->web_contents(), expected_title16);
......@@ -641,8 +652,7 @@ namespace {
// Creates a valid filesystem URL.
GURL CreateFileSystemURL(Shell* window) {
std::string filesystem_url_string;
EXPECT_TRUE(
ExecuteScriptAndExtractString(window, R"(
EXPECT_TRUE(ExecuteScriptAndExtractString(window, R"(
var blob = new Blob(['<html><body>hello</body></html>'],
{type: 'text/html'});
window.webkitRequestFileSystem(TEMPORARY, blob.size, fs => {
......@@ -654,7 +664,8 @@ GURL CreateFileSystemURL(Shell* window) {
}
});
});
});)", &filesystem_url_string));
});)",
&filesystem_url_string));
GURL filesystem_url(filesystem_url_string);
EXPECT_TRUE(filesystem_url.is_valid());
EXPECT_TRUE(filesystem_url.SchemeIsFileSystem());
......@@ -1266,4 +1277,31 @@ IN_PROC_BROWSER_TEST_F(LoaderBrowserTest, URLLoaderThrottleRedirectModify) {
SetBrowserClientForTesting(old_content_browser_client);
}
IN_PROC_BROWSER_TEST_F(LoaderBrowserTest, FetchUpload150MB) {
ASSERT_TRUE(embedded_test_server()->Start());
ASSERT_TRUE(
NavigateToURL(shell(), embedded_test_server()->GetURL("/title2.html")));
EXPECT_EQ(shell()->web_contents()->GetTitle(), ASCIIToUTF16("Title Of Awesomeness"));
ASSERT_TRUE(ExecuteScript(
shell(), base::StringPrintf(R"JS(
const length = 150*1000*1000; // 150 MB;
async function run() {
const array = new Uint8Array(length);
const response = await fetch('%s', { method: 'POST', body: array });
const text = await response.text();
if (text != length.toString())
throw `Content-Length actual:${text}, expected:${length.toString()}.`
};
run().then(() => { document.title = 'PASS'; },
(e) => { console.log(e); document.title = 'FAIL'; });
)JS",
embedded_test_server()
->GetURL("/echoheader?Content-Length")
.spec()
.c_str())));
WaitForTitleTest(ASCIIToUTF16("PASS"), {ASCIIToUTF16("FAIL")});
}
} // namespace content
......@@ -19,8 +19,6 @@ namespace test_server {
namespace {
size_t kRequestSizeLimit = 64 * 1024 * 1024; // 64 mb.
// Helper function used to trim tokens in http request headers.
std::string Trim(const std::string& value) {
std::string result;
......@@ -30,9 +28,7 @@ std::string Trim(const std::string& value) {
} // namespace
HttpRequest::HttpRequest() : method(METHOD_UNKNOWN),
has_content(false) {
}
HttpRequest::HttpRequest() : method(METHOD_UNKNOWN), has_content(false) {}
HttpRequest::HttpRequest(const HttpRequest& other) = default;
......@@ -54,8 +50,6 @@ HttpRequestParser::~HttpRequestParser() = default;
void HttpRequestParser::ProcessChunk(const base::StringPiece& data) {
buffer_.append(data.data(), data.size());
DCHECK_LE(buffer_.size() + data.size(), kRequestSizeLimit) <<
"The HTTP request is too large.";
}
std::string HttpRequestParser::ShiftLine() {
......@@ -116,8 +110,8 @@ HttpRequestParser::ParseResult HttpRequestParser::ParseHeaders() {
// Protocol.
const std::string protocol = base::ToLowerASCII(header_line_tokens[2]);
CHECK(protocol == "http/1.0" || protocol == "http/1.1") <<
"Protocol not supported: " << protocol;
CHECK(protocol == "http/1.0" || protocol == "http/1.1")
<< "Protocol not supported: " << protocol;
}
// Parse further headers.
......@@ -140,8 +134,7 @@ HttpRequestParser::ParseResult HttpRequestParser::ParseHeaders() {
DCHECK_NE(std::string::npos, delimiter_pos) << "Syntax error.";
header_name = Trim(header_line.substr(0, delimiter_pos));
std::string header_value = Trim(header_line.substr(
delimiter_pos + 1,
header_line.size() - delimiter_pos - 1));
delimiter_pos + 1, header_line.size() - delimiter_pos - 1));
http_request_->headers[header_name] = header_value;
}
}
......@@ -152,8 +145,7 @@ HttpRequestParser::ParseResult HttpRequestParser::ParseHeaders() {
if (http_request_->headers.count("Content-Length") > 0) {
http_request_->has_content = true;
const bool success = base::StringToSizeT(
http_request_->headers["Content-Length"],
&declared_content_length_);
http_request_->headers["Content-Length"], &declared_content_length_);
if (!success) {
declared_content_length_ = 0;
LOG(WARNING) << "Malformed Content-Length header's value.";
......@@ -199,11 +191,10 @@ HttpRequestParser::ParseResult HttpRequestParser::ParseContent() {
return WAITING;
}
const size_t fetch_bytes = std::min(
available_bytes,
declared_content_length_ - http_request_->content.size());
http_request_->content.append(buffer_.data() + buffer_position_,
fetch_bytes);
const size_t fetch_bytes =
std::min(available_bytes,
declared_content_length_ - http_request_->content.size());
http_request_->content.append(buffer_.data() + buffer_position_, fetch_bytes);
buffer_position_ += fetch_bytes;
if (declared_content_length_ == http_request_->content.size()) {
......
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