Commit 89c761e4 authored by Adrienne Walker's avatar Adrienne Walker Committed by Commit Bot

Update memory file stream reader to behave like local

As I'm adding a 4th file stream reader unittest, I thought I would
combine all of the similar-but-not-exactly-the-same sets of file stream
reader unittests.  This is one behavior difference between all of the
file stream readers, so I thought I would clean it up first.

This return value is how file system file stream reader and local file
stream reader behave when seeking past the end.

Change-Id: Ife39c7c82b8aee161dd26aa67e001c09e93d30ad
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2406703
Commit-Queue: enne <enne@chromium.org>
Commit-Queue: Marijn Kruisselbrink <mek@chromium.org>
Auto-Submit: enne <enne@chromium.org>
Reviewed-by: default avatarMarijn Kruisselbrink <mek@chromium.org>
Cr-Commit-Position: refs/heads/master@{#806395}
parent b6fd2b3d
......@@ -235,7 +235,8 @@ TEST_F(MemoryFileStreamReaderTest, ReadWithNegativeOffset) {
int result = 0;
std::string data;
ReadFromReader(reader.get(), &data, 1, &result);
ASSERT_EQ(net::ERR_REQUEST_RANGE_NOT_SATISFIABLE, result);
ASSERT_EQ(net::ERR_INVALID_ARGUMENT, result);
ASSERT_EQ(data.size(), 0u);
}
TEST_F(MemoryFileStreamReaderTest, ReadWithOffsetLargerThanFile) {
......@@ -244,7 +245,8 @@ TEST_F(MemoryFileStreamReaderTest, ReadWithOffsetLargerThanFile) {
int result = 0;
std::string data;
ReadFromReader(reader.get(), &data, 1, &result);
ASSERT_EQ(net::ERR_REQUEST_RANGE_NOT_SATISFIABLE, result);
ASSERT_EQ(net::OK, result);
ASSERT_EQ(data.size(), 0u);
}
} // namespace storage
......@@ -456,8 +456,13 @@ int ObfuscatedFileUtilMemoryDelegate::ReadFile(const base::FilePath& path,
return net::ERR_FILE_NOT_FOUND;
int64_t remaining = dp->entry->file_content.size() - offset;
if (offset < 0 || remaining < 0)
return net::ERR_REQUEST_RANGE_NOT_SATISFIABLE;
if (offset < 0)
return net::ERR_INVALID_ARGUMENT;
// Seeking past the end of the file is ok, but returns nothing.
// This matches FileStream::Context behavior.
if (remaining < 0)
return 0;
if (buf_len > remaining)
buf_len = static_cast<int>(remaining);
......
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