Skip to content

Commit

Permalink
Prepare /storage/browser/fileapi for TestCompletionCallback with non-…
Browse files Browse the repository at this point in the history
…repeating callbacks

Make sure that we don't re-use the callbacks from TestCompletionCallback,
so that we're prepared for when they become non-repeating callbacks (i.e.
base::CompletionOnceCallback), instead of base::CompletionCallback.

This CL was uploaded by git cl split.

TBR=tzik@chromium.org

Bug: 807724
Change-Id: Id1ce48998eeda76b142fc0ec91de903a47411344
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1541113
Commit-Queue: Mario Sanchez Prada <mario@igalia.com>
Reviewed-by: Bence Béky <bnc@chromium.org>
Auto-Submit: Mario Sanchez Prada <mario@igalia.com>
Cr-Commit-Position: refs/heads/master@{#645230}
  • Loading branch information
mariospr authored and Commit Bot committed Mar 28, 2019
1 parent 40cd9d7 commit 2d99e51
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 12 deletions.
2 changes: 1 addition & 1 deletion storage/browser/fileapi/file_stream_reader_test_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ void ReadFromReader(FileStreamReader* reader,
ASSERT_TRUE(reader != nullptr);
ASSERT_TRUE(result != nullptr);
*result = net::OK;
net::TestCompletionCallback callback;
size_t total_bytes_read = 0;
while (total_bytes_read < size) {
scoped_refptr<net::IOBufferWithSize> buf(
base::MakeRefCounted<net::IOBufferWithSize>(size - total_bytes_read));
net::TestCompletionCallback callback;
int rv = reader->Read(buf.get(), buf->size(), callback.callback());
if (rv == net::ERR_IO_PENDING)
rv = callback.WaitForResult();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,17 +169,18 @@ TEST_F(FileSystemFileStreamReaderTest, GetLengthAfterModified) {

std::unique_ptr<FileSystemFileStreamReader> reader(
CreateFileReader(kTestFileName, 0, fake_expected_modification_time));
net::TestInt64CompletionCallback callback;
int64_t result = reader->GetLength(callback.callback());
net::TestInt64CompletionCallback callback1;
int64_t result = reader->GetLength(callback1.callback());
if (result == net::ERR_IO_PENDING)
result = callback.WaitForResult();
result = callback1.WaitForResult();
ASSERT_EQ(net::ERR_UPLOAD_FILE_CHANGED, result);

// With nullptr expected modification time this should work.
reader.reset(CreateFileReader(kTestFileName, 0, base::Time()));
result = reader->GetLength(callback.callback());
net::TestInt64CompletionCallback callback2;
result = reader->GetLength(callback2.callback());
if (result == net::ERR_IO_PENDING)
result = callback.WaitForResult();
result = callback2.WaitForResult();
ASSERT_EQ(kTestDataSize, result);
}

Expand Down
2 changes: 1 addition & 1 deletion storage/browser/fileapi/file_writer_impl_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,10 @@ class FileWriterImplTest : public testing::Test {
std::unique_ptr<FileStreamReader> reader =
file_system_context_->CreateFileStreamReader(
url, 0, std::numeric_limits<int64_t>::max(), base::Time());
net::TestCompletionCallback callback;
std::string result;
while (true) {
auto buf = base::MakeRefCounted<net::IOBufferWithSize>(4096);
net::TestCompletionCallback callback;
int rv = reader->Read(buf.get(), buf->size(), callback.callback());
if (rv == net::ERR_IO_PENDING)
rv = callback.WaitForResult();
Expand Down
11 changes: 6 additions & 5 deletions storage/browser/fileapi/local_file_stream_reader_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -160,17 +160,18 @@ TEST_F(LocalFileStreamReaderTest, GetLengthAfterModified) {

std::unique_ptr<LocalFileStreamReader> reader(
CreateFileReader(test_path(), 0, test_file_modification_time()));
net::TestInt64CompletionCallback callback;
int64_t result = reader->GetLength(callback.callback());
net::TestInt64CompletionCallback callback1;
int64_t result = reader->GetLength(callback1.callback());
if (result == net::ERR_IO_PENDING)
result = callback.WaitForResult();
result = callback1.WaitForResult();
ASSERT_EQ(net::ERR_UPLOAD_FILE_CHANGED, result);

// With nullptr expected modification time this should work.
reader.reset(CreateFileReader(test_path(), 0, base::Time()));
result = reader->GetLength(callback.callback());
net::TestInt64CompletionCallback callback2;
result = reader->GetLength(callback2.callback());
if (result == net::ERR_IO_PENDING)
result = callback.WaitForResult();
result = callback2.WaitForResult();
ASSERT_EQ(kTestDataSize, result);
}

Expand Down

0 comments on commit 2d99e51

Please sign in to comment.