Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(71)

Unified Diff: net/base/file_stream_unittest.cc

Issue 1148383003: Only support seeking file streams from the beginning of the file. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix Win DBG build by Pass()-ing file out of CreateForAsyncHandle. Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/base/file_stream_context_win.cc ('k') | net/base/mock_file_stream.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/base/file_stream_unittest.cc
diff --git a/net/base/file_stream_unittest.cc b/net/base/file_stream_unittest.cc
index a1e181557e68bada3e1004ede3670de4e1995ce6..d1985a8ace5b3d9735156cafb94c4229ee214149 100644
--- a/net/base/file_stream_unittest.cc
+++ b/net/base/file_stream_unittest.cc
@@ -79,11 +79,9 @@ TEST_F(FileStreamTest, OpenExplicitClose) {
EXPECT_EQ(ERR_IO_PENDING, rv);
EXPECT_EQ(OK, callback.WaitForResult());
EXPECT_TRUE(stream.IsOpen());
- EXPECT_TRUE(stream.GetFileForTesting().IsValid());
EXPECT_EQ(ERR_IO_PENDING, stream.Close(callback.callback()));
EXPECT_EQ(OK, callback.WaitForResult());
EXPECT_FALSE(stream.IsOpen());
- EXPECT_FALSE(stream.GetFileForTesting().IsValid());
}
TEST_F(FileStreamTest, OpenExplicitCloseOrphaned) {
@@ -96,7 +94,6 @@ TEST_F(FileStreamTest, OpenExplicitCloseOrphaned) {
EXPECT_EQ(ERR_IO_PENDING, rv);
EXPECT_EQ(OK, callback.WaitForResult());
EXPECT_TRUE(stream->IsOpen());
- EXPECT_TRUE(stream->GetFileForTesting().IsValid());
EXPECT_EQ(ERR_IO_PENDING, stream->Close(callback.callback()));
stream.reset();
// File isn't actually closed yet.
@@ -120,9 +117,7 @@ TEST_F(FileStreamTest, UseFileHandle) {
// Seek to the beginning of the file and read.
scoped_ptr<FileStream> read_stream(
new FileStream(file.Pass(), base::ThreadTaskRunnerHandle::Get()));
- ASSERT_EQ(ERR_IO_PENDING,
- read_stream->Seek(base::File::FROM_BEGIN, 0,
- callback64.callback()));
+ ASSERT_EQ(ERR_IO_PENDING, read_stream->Seek(0, callback64.callback()));
ASSERT_EQ(0, callback64.WaitForResult());
// Read into buffer and compare.
scoped_refptr<IOBufferWithSize> read_buffer =
@@ -140,9 +135,7 @@ TEST_F(FileStreamTest, UseFileHandle) {
scoped_ptr<FileStream> write_stream(
new FileStream(file.Pass(), base::ThreadTaskRunnerHandle::Get()));
- ASSERT_EQ(ERR_IO_PENDING,
- write_stream->Seek(base::File::FROM_BEGIN, 0,
- callback64.callback()));
+ ASSERT_EQ(ERR_IO_PENDING, write_stream->Seek(0, callback64.callback()));
ASSERT_EQ(0, callback64.WaitForResult());
scoped_refptr<IOBufferWithSize> write_buffer = CreateTestDataBuffer();
rv = write_stream->Write(write_buffer.get(), kTestDataSize,
@@ -167,7 +160,7 @@ TEST_F(FileStreamTest, UseClosedStream) {
EXPECT_FALSE(stream.IsOpen());
// Try seeking...
- rv = stream.Seek(base::File::FROM_BEGIN, 5, callback64.callback());
+ rv = stream.Seek(5, callback64.callback());
EXPECT_EQ(ERR_UNEXPECTED, callback64.GetResult(rv));
// Try reading...
@@ -244,7 +237,7 @@ TEST_F(FileStreamTest, Read_FromOffset) {
TestInt64CompletionCallback callback64;
const int64_t kOffset = 3;
- rv = stream.Seek(base::File::FROM_BEGIN, kOffset, callback64.callback());
+ rv = stream.Seek(kOffset, callback64.callback());
ASSERT_EQ(ERR_IO_PENDING, rv);
int64_t new_offset = callback64.WaitForResult();
EXPECT_EQ(kOffset, new_offset);
@@ -267,41 +260,6 @@ TEST_F(FileStreamTest, Read_FromOffset) {
EXPECT_EQ(kTestData + kOffset, data_read);
}
-TEST_F(FileStreamTest, SeekAround) {
- FileStream stream(base::ThreadTaskRunnerHandle::Get());
- int flags = base::File::FLAG_OPEN | base::File::FLAG_ASYNC |
- base::File::FLAG_READ;
- TestCompletionCallback callback;
- int rv = stream.Open(temp_file_path(), flags, callback.callback());
- EXPECT_EQ(ERR_IO_PENDING, rv);
- EXPECT_EQ(OK, callback.WaitForResult());
-
- TestInt64CompletionCallback callback64;
-
- const int64_t kOffset = 3;
- rv = stream.Seek(base::File::FROM_BEGIN, kOffset, callback64.callback());
- ASSERT_EQ(ERR_IO_PENDING, rv);
- int64_t new_offset = callback64.WaitForResult();
- EXPECT_EQ(kOffset, new_offset);
-
- rv = stream.Seek(base::File::FROM_CURRENT, kOffset, callback64.callback());
- ASSERT_EQ(ERR_IO_PENDING, rv);
- new_offset = callback64.WaitForResult();
- EXPECT_EQ(2 * kOffset, new_offset);
-
- rv = stream.Seek(base::File::FROM_CURRENT, -kOffset, callback64.callback());
- ASSERT_EQ(ERR_IO_PENDING, rv);
- new_offset = callback64.WaitForResult();
- EXPECT_EQ(kOffset, new_offset);
-
- const int kTestDataLen = arraysize(kTestData) - 1;
-
- rv = stream.Seek(base::File::FROM_END, -kTestDataLen, callback64.callback());
- ASSERT_EQ(ERR_IO_PENDING, rv);
- new_offset = callback64.WaitForResult();
- EXPECT_EQ(0, new_offset);
-}
-
TEST_F(FileStreamTest, Write) {
FileStream stream(base::ThreadTaskRunnerHandle::Get());
int flags = base::File::FLAG_CREATE_ALWAYS | base::File::FLAG_WRITE |
@@ -368,8 +326,8 @@ TEST_F(FileStreamTest, Write_FromOffset) {
EXPECT_EQ(OK, callback.WaitForResult());
TestInt64CompletionCallback callback64;
- const int64_t kOffset = 0;
- rv = stream.Seek(base::File::FROM_END, kOffset, callback64.callback());
+ const int64_t kOffset = kTestDataSize;
+ rv = stream.Seek(kOffset, callback64.callback());
ASSERT_EQ(ERR_IO_PENDING, rv);
int64_t new_offset = callback64.WaitForResult();
EXPECT_EQ(kTestDataSize, new_offset);
@@ -461,7 +419,7 @@ TEST_F(FileStreamTest, BasicWriteRead) {
EXPECT_EQ(OK, callback.WaitForResult());
TestInt64CompletionCallback callback64;
- rv = stream->Seek(base::File::FROM_END, 0, callback64.callback());
+ rv = stream->Seek(file_size, callback64.callback());
ASSERT_EQ(ERR_IO_PENDING, rv);
int64_t offset = callback64.WaitForResult();
EXPECT_EQ(offset, file_size);
@@ -485,7 +443,7 @@ TEST_F(FileStreamTest, BasicWriteRead) {
EXPECT_EQ(kTestDataSize, total_bytes_written);
- rv = stream->Seek(base::File::FROM_BEGIN, 0, callback64.callback());
+ rv = stream->Seek(0, callback64.callback());
ASSERT_EQ(ERR_IO_PENDING, rv);
offset = callback64.WaitForResult();
EXPECT_EQ(0, offset);
@@ -588,9 +546,7 @@ class TestWriteReadCompletionCallback {
*data_read_ += data_read;
} else { // We're done writing all data. Start reading the data.
TestInt64CompletionCallback callback64;
- EXPECT_EQ(ERR_IO_PENDING,
- stream_->Seek(base::File::FROM_BEGIN, 0,
- callback64.callback()));
+ EXPECT_EQ(ERR_IO_PENDING, stream_->Seek(0, callback64.callback()));
{
base::MessageLoop::ScopedNestableTaskAllower allow(
base::MessageLoop::current());
@@ -632,8 +588,7 @@ TEST_F(FileStreamTest, WriteRead) {
EXPECT_EQ(OK, open_callback.WaitForResult());
TestInt64CompletionCallback callback64;
- EXPECT_EQ(ERR_IO_PENDING,
- stream->Seek(base::File::FROM_END, 0, callback64.callback()));
+ EXPECT_EQ(ERR_IO_PENDING, stream->Seek(file_size, callback64.callback()));
EXPECT_EQ(file_size, callback64.WaitForResult());
int total_bytes_written = 0;
@@ -739,8 +694,7 @@ TEST_F(FileStreamTest, WriteClose) {
EXPECT_EQ(OK, open_callback.WaitForResult());
TestInt64CompletionCallback callback64;
- EXPECT_EQ(ERR_IO_PENDING,
- stream->Seek(base::File::FROM_END, 0, callback64.callback()));
+ EXPECT_EQ(ERR_IO_PENDING, stream->Seek(file_size, callback64.callback()));
EXPECT_EQ(file_size, callback64.WaitForResult());
int total_bytes_written = 0;
« no previous file with comments | « net/base/file_stream_context_win.cc ('k') | net/base/mock_file_stream.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698