Commit 96c04c00 authored by Yoichi Osato's avatar Yoichi Osato Committed by Commit Bot

Enable fetch send ArrayBuffer more than 128 MB

This CL introduces mojo_base.mojom.BigBuffer instead of array<uint>
so that fetch can send big ArrayBuffer.

Bug: 919361
Change-Id: I45c3c560ca787858453c677cc0c7fbc8c1983063
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2415810Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Reviewed-by: default avatarYutaka Hirano <yhirano@chromium.org>
Commit-Queue: Yoichi Osato <yoichio@chromium.org>
Cr-Commit-Position: refs/heads/master@{#815479}
parent f5d3fa2b
......@@ -270,8 +270,12 @@ bool StructTraits<network::mojom::DataElementDataView, network::DataElement>::
return false;
}
if (data.type() == network::mojom::DataElementType::kBytes) {
if (!data.ReadBuf(&out->buf_))
mojo_base::BigBufferView big_buffer;
if (!data.ReadBuf(&big_buffer))
return false;
out->buf_.clear();
out->buf_.insert(out->buf_.end(), big_buffer.data().begin(),
big_buffer.data().end());
}
out->type_ = data.type();
out->data_pipe_getter_ = data.TakeDataPipeGetter<
......
......@@ -10,6 +10,7 @@
#include "base/component_export.h"
#include "base/memory/scoped_refptr.h"
#include "mojo/public/cpp/base/big_buffer_mojom_traits.h"
#include "mojo/public/cpp/base/file_mojom_traits.h"
#include "mojo/public/cpp/base/file_path_mojom_traits.h"
#include "mojo/public/cpp/base/time_mojom_traits.h"
......@@ -308,8 +309,8 @@ struct COMPONENT_EXPORT(NETWORK_CPP_BASE)
const network::DataElement& element) {
return element.type_;
}
static const std::vector<uint8_t>& buf(const network::DataElement& element) {
return element.buf_;
static mojo_base::BigBufferView buf(const network::DataElement& element) {
return mojo_base::BigBufferView(element.buf_);
}
static const base::FilePath& path(const network::DataElement& element) {
return element.path_;
......
......@@ -423,7 +423,7 @@ struct DataElement {
DataElementType type;
// For kBytes.
array<uint8> buf;
mojo_base.mojom.BigBuffer buf;
// For kFile
mojo_base.mojom.FilePath path;
// For kDataPipe
......
......@@ -542,3 +542,10 @@ crbug.com/1093478 external/wpt/quirks/unitless-length/limited-quirks.html [ Slow
crbug.com/1133836 external/wpt/scroll-to-text-fragment/redirects.html [ Slow ]
crbug.com/1134580 virtual/eye-dropper/color-picker-show-eye-dropper.html [ Slow ]
crbug.com/919361 [ Mac ] http/tests/fetch/serviceworker/fetch_upload-base-https-other-https.html [ Slow ]
crbug.com/919361 [ Mac ] http/tests/fetch/serviceworker/fetch_upload.html [ Slow ]
crbug.com/919361 [ Mac ] http/tests/fetch/window/fetch_upload-base-https-other-https.html [ Slow ]
crbug.com/919361 [ Mac ] http/tests/fetch/window/fetch_upload.html [ Slow ]
crbug.com/919361 [ Mac ] http/tests/fetch/workers/fetch_upload-base-https-other-https.html [ Slow ]
crbug.com/919361 [ Mac ] http/tests/fetch/workers/fetch_upload.html [ Slow ]
; Let <meta charset> work. A charset provided in Content-Type takes precedence, and PHP 5.6+ defaults to UTF-8.
default_charset = ""
memory_limit = 512M
\ No newline at end of file
......@@ -69,27 +69,63 @@ function hash256(array) {
return crypto.subtle.digest('SHA-256', array);
}
promise_test(async () => {
const length = 1000 * 1000; // 1Mbytes
const array = random_values_array(length);
const stream = create_stream([array]);
const response = await fetch_echo(stream);
function compare(a, b) {
if (a.length != b.length)
return [false, 'length is not equal'];
for (let i = 0; - 1 < i; i -= 1) {
if ((a[i] !== b[i]))
return [false, `a[${i}](${a[i]}) != b[${i}](${b[i]})`];
}
return [true, ''];
}
async function compare_long_array(a, b, description) {
const a_hash = await hash256(a);
const b_hash = await hash256(b);
const [eq, fail_reason] = compare(a_hash, b_hash);
if (eq)
return;
const [raw_eq, raw_fail_reason] = compare(a, b);
assert_false(raw_eq);
assert_(false, description + ': ' + raw_fail_reason);
}
async function test_echo_long_array(upload_body, expected_array) {
const response = await fetch_echo(upload_body);
const reader = response.body.getReader();
let index = 0;
while (index < length) {
while (index < expected_array.length) {
const chunk = await reader.read();
assert_false(chunk.done);
assert_false(chunk.done, `chunk.done@${index}/${expected_array.length}`);
const chunk_length = chunk.value.length;
const chunk_hash = await hash256(chunk.value);
const src_hash = await hash256(array.subarray(index, index + chunk_length));
assert_array_equals(
new Uint8Array(chunk_hash), new Uint8Array(src_hash),
`Array of [${index}, ${index + length - 1}] should be same.`);
await compare_long_array(
chunk.value, expected_array.subarray(index, index + chunk_length),
`Array of [${index}, ${index + chunk_length - 1}] should be same.`);
index += chunk_length;
}
const final_chunk = await reader.read();
assert_true(final_chunk.done);
}, 'Fetch with ReadableStream body with long Uint8Array');
assert_true(final_chunk.done, 'final_chunk.done');
}
promise_test(async () => {
const length = 1000 * 1000; // 1Mbytes
const array = random_values_array(length);
const stream = create_stream([array]);
await test_echo_long_array(stream, array);
}, 'Fetch with ReadableStream body with 1Mbytes Uint8Array');
promise_test(async () => {
const length = 1000 * 1000; // 1 Mbytes
const array = random_values_array(length);
await test_echo_long_array(array, array);
}, 'Fetch with Array body with 1 Mbytes Uint8Array');
promise_test(async () => {
const length = 150 * 1000 * 1000; // 150 Mbytes
const array = random_values_array(length);
await test_echo_long_array(array, array);
}, 'Fetch with Array body with 150 Mbytes Uint8Array');
promise_test(async (t) => {
const stream = create_stream(['Foobar']);
......
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