Chromium Code Reviews| Index: net/base/file_stream_unittest.cc |
| diff --git a/net/base/file_stream_unittest.cc b/net/base/file_stream_unittest.cc |
| index 10427846c37c0931ba04f0835fafca53ea402957..c4552df903ae8457d1349ded376b0fc340ae13b8 100644 |
| --- a/net/base/file_stream_unittest.cc |
| +++ b/net/base/file_stream_unittest.cc |
| @@ -33,46 +33,6 @@ IOBufferWithSize* CreateTestDataBuffer() { |
| return buf; |
| } |
| -// This NetLog is used for notifying when a file stream is closed |
| -// (i.e. TYPE_FILE_STREAM_CLOSE event is recorded). |
| -class NetLogForNotifyingFileClosure : public NetLog { |
| - public: |
| - NetLogForNotifyingFileClosure() |
| - : last_id_(0), |
| - on_closure_(false /* manual_reset */, false /* initially_signaled */) { |
| - } |
| - |
| - // Wait until a file closure event is recorded. |
| - bool WaitForClosure() { |
| - const base::TimeDelta timeout(TestTimeouts::action_max_timeout()); |
| - return on_closure_.TimedWait(timeout); |
| - } |
| - |
| - // NetLog overrides: |
| - virtual void OnAddEntry(const net::NetLog::Entry& entry) OVERRIDE { |
| - if (entry.type() == TYPE_FILE_STREAM_CLOSE) |
| - on_closure_.Signal(); |
| - } |
| - |
| - virtual uint32 NextID() OVERRIDE { return ++last_id_; } |
| - virtual LogLevel GetLogLevel() const OVERRIDE { return LOG_ALL; } |
| - virtual void AddThreadSafeObserver(ThreadSafeObserver* observer, |
| - LogLevel log_level) OVERRIDE { |
| - NOTIMPLEMENTED(); |
| - } |
| - virtual void SetObserverLogLevel(ThreadSafeObserver* observer, |
| - LogLevel log_level) OVERRIDE { |
| - NOTIMPLEMENTED(); |
| - } |
| - virtual void RemoveThreadSafeObserver(ThreadSafeObserver* observer) OVERRIDE { |
| - NOTIMPLEMENTED(); |
| - } |
| - |
| - private: |
| - uint32 last_id_; |
| - base::WaitableEvent on_closure_; |
| -}; |
| - |
| } // namespace |
| class FileStreamTest : public PlatformTest { |
| @@ -113,7 +73,7 @@ TEST_F(FileStreamTest, BasicOpenClose) { |
| EXPECT_FALSE(base::GetPlatformFileInfo(file, &info)); |
| } |
| -TEST_F(FileStreamTest, FileHandleLeftOpen) { |
| +TEST_F(FileStreamTest, FileHandleNotLeftOpen) { |
| bool created = false; |
| ASSERT_EQ(kTestDataSize, |
| file_util::WriteFile(temp_file_path(), kTestData, kTestDataSize)); |
| @@ -129,10 +89,9 @@ TEST_F(FileStreamTest, FileHandleLeftOpen) { |
| EXPECT_NE(base::kInvalidPlatformFileValue, file); |
| base::PlatformFileInfo info; |
| - // The file should still be open. |
| - EXPECT_TRUE(base::GetPlatformFileInfo(file, &info)); |
| - // Clean up. |
| - EXPECT_TRUE(base::ClosePlatformFile(file)); |
| + // The file should be closed. |
| + EXPECT_FALSE(base::GetPlatformFileInfo(file, &info)); |
| + EXPECT_FALSE(base::ClosePlatformFile(file)); |
| } |
| // Test the use of FileStream with a file handle provided at construction. |
| @@ -147,26 +106,26 @@ TEST_F(FileStreamTest, UseFileHandle) { |
| temp_file_path(), flags, &created, NULL); |
| // Seek to the beginning of the file and read. |
| - FileStream read_stream(file, flags, NULL); |
| - ASSERT_EQ(0, read_stream.SeekSync(FROM_BEGIN, 0)); |
| - ASSERT_EQ(kTestDataSize, read_stream.Available()); |
| + scoped_ptr<FileStream> read_stream(new FileStream(file, flags, NULL)); |
| + ASSERT_EQ(0, read_stream->SeekSync(FROM_BEGIN, 0)); |
| + ASSERT_EQ(kTestDataSize, read_stream->Available()); |
| // Read into buffer and compare. |
| char buffer[kTestDataSize]; |
| ASSERT_EQ(kTestDataSize, |
| - read_stream.ReadSync(buffer, kTestDataSize)); |
| + read_stream->ReadSync(buffer, kTestDataSize)); |
| ASSERT_EQ(0, memcmp(kTestData, buffer, kTestDataSize)); |
| - read_stream.CloseSync(); |
| + read_stream.reset(); |
| // 2. Test writing with a file handle. |
| file_util::Delete(temp_file_path(), false); |
| flags = base::PLATFORM_FILE_OPEN_ALWAYS | base::PLATFORM_FILE_WRITE; |
| file = base::CreatePlatformFile(temp_file_path(), flags, &created, NULL); |
| - FileStream write_stream(file, flags, NULL); |
| - ASSERT_EQ(0, write_stream.SeekSync(FROM_BEGIN, 0)); |
| + scoped_ptr<FileStream> write_stream(new FileStream(file, flags, NULL)); |
| + ASSERT_EQ(0, write_stream->SeekSync(FROM_BEGIN, 0)); |
| ASSERT_EQ(kTestDataSize, |
| - write_stream.WriteSync(kTestData, kTestDataSize)); |
| - write_stream.CloseSync(); |
| + write_stream->WriteSync(kTestData, kTestDataSize)); |
| + write_stream.reset(); |
| // Read into buffer and compare to make sure the handle worked fine. |
| ASSERT_EQ(kTestDataSize, |
| @@ -258,38 +217,6 @@ TEST_F(FileStreamTest, AsyncRead) { |
| EXPECT_EQ(kTestData, data_read); |
| } |
| -TEST_F(FileStreamTest, AsyncRead_EarlyClose) { |
| - int64 file_size; |
| - bool ok = file_util::GetFileSize(temp_file_path(), &file_size); |
| - EXPECT_TRUE(ok); |
| - |
| - FileStream stream(NULL); |
| - int flags = base::PLATFORM_FILE_OPEN | |
| - base::PLATFORM_FILE_READ | |
| - base::PLATFORM_FILE_ASYNC; |
| - int rv = stream.OpenSync(temp_file_path(), flags); |
| - EXPECT_EQ(OK, rv); |
| - |
| - int64 total_bytes_avail = stream.Available(); |
| - EXPECT_EQ(file_size, total_bytes_avail); |
| - |
| - TestCompletionCallback callback; |
| - |
| - scoped_refptr<IOBufferWithSize> buf = new IOBufferWithSize(4); |
| - rv = stream.Read(buf, buf->size(), callback.callback()); |
| - stream.CloseSync(); |
| - if (rv < 0) { |
| - EXPECT_EQ(ERR_IO_PENDING, rv); |
| - // The callback should not be called if the request is cancelled. |
| - MessageLoop::current()->RunAllPending(); |
| - EXPECT_FALSE(callback.have_result()); |
| - } else { |
| - EXPECT_EQ(std::string(kTestData, rv), std::string(buf->data(), rv)); |
| - } |
| -} |
| - |
| -// Similar to AsyncRead_EarlyClose but deletes a stream instead, to ensure |
| -// that deleting a stream is safe while an async read is in flight. |
| TEST_F(FileStreamTest, AsyncRead_EarlyDelete) { |
| int64 file_size; |
| bool ok = file_util::GetFileSize(temp_file_path(), &file_size); |
| @@ -320,47 +247,6 @@ TEST_F(FileStreamTest, AsyncRead_EarlyDelete) { |
| } |
| } |
| -// Similar to AsyncRead_EarlyDelete but using a given file handler rather than |
| -// calling FileStream::Open, to ensure that deleting a stream with in-flight |
| -// operation without auto-closing feature is also ok. |
| -TEST_F(FileStreamTest, AsyncRead_EarlyDelete_NoAutoClose) { |
| - int64 file_size; |
| - bool ok = file_util::GetFileSize(temp_file_path(), &file_size); |
| - EXPECT_TRUE(ok); |
| - |
| - bool created = false; |
| - int flags = base::PLATFORM_FILE_OPEN | |
| - base::PLATFORM_FILE_READ | |
| - base::PLATFORM_FILE_ASYNC; |
| - base::PlatformFileError error_code = base::PLATFORM_FILE_ERROR_FAILED; |
| - base::PlatformFile file = base::CreatePlatformFile( |
| - temp_file_path(), flags, &created, &error_code); |
| - EXPECT_EQ(base::PLATFORM_FILE_OK, error_code); |
| - |
| - scoped_ptr<FileStream> stream(new FileStream(file, flags, NULL)); |
| - int64 total_bytes_avail = stream->Available(); |
| - EXPECT_EQ(file_size, total_bytes_avail); |
| - |
| - TestCompletionCallback callback; |
| - scoped_refptr<IOBufferWithSize> buf = new IOBufferWithSize(4); |
| - int rv = stream->Read(buf, buf->size(), callback.callback()); |
| - stream.reset(); // Delete instead of closing it. |
| - if (rv < 0) { |
| - EXPECT_EQ(ERR_IO_PENDING, rv); |
| - // The callback should not be called if the request is cancelled. |
| - MessageLoop::current()->RunAllPending(); |
| - EXPECT_FALSE(callback.have_result()); |
| - } else { |
| - EXPECT_EQ(std::string(kTestData, rv), std::string(buf->data(), rv)); |
| - } |
| - |
| - base::PlatformFileInfo info; |
| - // The file should still be open. |
| - EXPECT_TRUE(base::GetPlatformFileInfo(file, &info)); |
| - // Clean up. |
| - EXPECT_TRUE(base::ClosePlatformFile(file)); |
| -} |
| - |
| TEST_F(FileStreamTest, BasicRead_FromOffset) { |
| int64 file_size; |
| bool ok = file_util::GetFileSize(temp_file_path(), &file_size); |
| @@ -496,10 +382,10 @@ TEST_F(FileStreamTest, AsyncSeekAround) { |
| } |
| TEST_F(FileStreamTest, BasicWrite) { |
| - FileStream stream(NULL); |
| + scoped_ptr<FileStream> stream(new FileStream(NULL)); |
| int flags = base::PLATFORM_FILE_CREATE_ALWAYS | |
| base::PLATFORM_FILE_WRITE; |
| - int rv = stream.OpenSync(temp_file_path(), flags); |
| + int rv = stream->OpenSync(temp_file_path(), flags); |
| EXPECT_EQ(OK, rv); |
| int64 file_size; |
| @@ -507,9 +393,9 @@ TEST_F(FileStreamTest, BasicWrite) { |
| EXPECT_TRUE(ok); |
| EXPECT_EQ(0, file_size); |
| - rv = stream.WriteSync(kTestData, kTestDataSize); |
| + rv = stream->WriteSync(kTestData, kTestDataSize); |
| EXPECT_EQ(kTestDataSize, rv); |
| - stream.CloseSync(); |
| + stream.reset(); |
| ok = file_util::GetFileSize(temp_file_path(), &file_size); |
| EXPECT_TRUE(ok); |
| @@ -551,12 +437,12 @@ TEST_F(FileStreamTest, AsyncWrite) { |
| EXPECT_EQ(file_size, total_bytes_written); |
| } |
| -TEST_F(FileStreamTest, AsyncWrite_EarlyClose) { |
| - FileStream stream(NULL); |
| +TEST_F(FileStreamTest, AsyncWrite_EarlyDelete) { |
| + scoped_ptr<FileStream> stream(new FileStream(NULL)); |
| int flags = base::PLATFORM_FILE_CREATE_ALWAYS | |
| base::PLATFORM_FILE_WRITE | |
| base::PLATFORM_FILE_ASYNC; |
| - int rv = stream.OpenSync(temp_file_path(), flags); |
| + int rv = stream->OpenSync(temp_file_path(), flags); |
| EXPECT_EQ(OK, rv); |
| int64 file_size; |
| @@ -567,8 +453,8 @@ TEST_F(FileStreamTest, AsyncWrite_EarlyClose) { |
| TestCompletionCallback callback; |
| scoped_refptr<IOBufferWithSize> buf = CreateTestDataBuffer(); |
| - rv = stream.Write(buf, buf->size(), callback.callback()); |
| - stream.CloseSync(); |
| + rv = stream->Write(buf, buf->size(), callback.callback()); |
| + stream.reset(); |
| if (rv < 0) { |
| EXPECT_EQ(ERR_IO_PENDING, rv); |
| // The callback should not be called if the request is cancelled. |
| @@ -582,10 +468,10 @@ TEST_F(FileStreamTest, AsyncWrite_EarlyClose) { |
| } |
| TEST_F(FileStreamTest, BasicWrite_FromOffset) { |
| - FileStream stream(NULL); |
| + scoped_ptr<FileStream> stream(new FileStream(NULL)); |
| int flags = base::PLATFORM_FILE_OPEN | |
| base::PLATFORM_FILE_WRITE; |
| - int rv = stream.OpenSync(temp_file_path(), flags); |
| + int rv = stream->OpenSync(temp_file_path(), flags); |
| EXPECT_EQ(OK, rv); |
| int64 file_size; |
| @@ -594,12 +480,12 @@ TEST_F(FileStreamTest, BasicWrite_FromOffset) { |
| EXPECT_EQ(kTestDataSize, file_size); |
| const int64 kOffset = 0; |
| - int64 new_offset = stream.SeekSync(FROM_END, kOffset); |
| + int64 new_offset = stream->SeekSync(FROM_END, kOffset); |
| EXPECT_EQ(kTestDataSize, new_offset); |
| - rv = stream.WriteSync(kTestData, kTestDataSize); |
| + rv = stream->WriteSync(kTestData, kTestDataSize); |
| EXPECT_EQ(kTestDataSize, rv); |
| - stream.CloseSync(); |
| + stream.reset(); |
| ok = file_util::GetFileSize(temp_file_path(), &file_size); |
| EXPECT_TRUE(ok); |
| @@ -652,14 +538,14 @@ TEST_F(FileStreamTest, BasicReadWrite) { |
| bool ok = file_util::GetFileSize(temp_file_path(), &file_size); |
| EXPECT_TRUE(ok); |
| - FileStream stream(NULL); |
| + scoped_ptr<FileStream> stream(new FileStream(NULL)); |
| int flags = base::PLATFORM_FILE_OPEN | |
| base::PLATFORM_FILE_READ | |
| base::PLATFORM_FILE_WRITE; |
| - int rv = stream.OpenSync(temp_file_path(), flags); |
| + int rv = stream->OpenSync(temp_file_path(), flags); |
| EXPECT_EQ(OK, rv); |
| - int64 total_bytes_avail = stream.Available(); |
| + int64 total_bytes_avail = stream->Available(); |
| EXPECT_EQ(file_size, total_bytes_avail); |
| int total_bytes_read = 0; |
| @@ -667,7 +553,7 @@ TEST_F(FileStreamTest, BasicReadWrite) { |
| std::string data_read; |
| for (;;) { |
| char buf[4]; |
| - rv = stream.ReadSync(buf, arraysize(buf)); |
| + rv = stream->ReadSync(buf, arraysize(buf)); |
| EXPECT_LE(0, rv); |
| if (rv <= 0) |
| break; |
| @@ -677,9 +563,9 @@ TEST_F(FileStreamTest, BasicReadWrite) { |
| EXPECT_EQ(file_size, total_bytes_read); |
| EXPECT_TRUE(data_read == kTestData); |
| - rv = stream.WriteSync(kTestData, kTestDataSize); |
| + rv = stream->WriteSync(kTestData, kTestDataSize); |
| EXPECT_EQ(kTestDataSize, rv); |
| - stream.CloseSync(); |
| + stream.reset(); |
| ok = file_util::GetFileSize(temp_file_path(), &file_size); |
| EXPECT_TRUE(ok); |
| @@ -691,23 +577,23 @@ TEST_F(FileStreamTest, BasicWriteRead) { |
| bool ok = file_util::GetFileSize(temp_file_path(), &file_size); |
| EXPECT_TRUE(ok); |
| - FileStream stream(NULL); |
| + scoped_ptr<FileStream> stream(new FileStream(NULL)); |
| int flags = base::PLATFORM_FILE_OPEN | |
| base::PLATFORM_FILE_READ | |
| base::PLATFORM_FILE_WRITE; |
| - int rv = stream.OpenSync(temp_file_path(), flags); |
| + int rv = stream->OpenSync(temp_file_path(), flags); |
| EXPECT_EQ(OK, rv); |
| - int64 total_bytes_avail = stream.Available(); |
| + int64 total_bytes_avail = stream->Available(); |
| EXPECT_EQ(file_size, total_bytes_avail); |
| - int64 offset = stream.SeekSync(FROM_END, 0); |
| + int64 offset = stream->SeekSync(FROM_END, 0); |
| EXPECT_EQ(offset, file_size); |
| - rv = stream.WriteSync(kTestData, kTestDataSize); |
| + rv = stream->WriteSync(kTestData, kTestDataSize); |
| EXPECT_EQ(kTestDataSize, rv); |
| - offset = stream.SeekSync(FROM_BEGIN, 0); |
| + offset = stream->SeekSync(FROM_BEGIN, 0); |
| EXPECT_EQ(0, offset); |
| int64 total_bytes_read = 0; |
| @@ -715,14 +601,14 @@ TEST_F(FileStreamTest, BasicWriteRead) { |
| std::string data_read; |
| for (;;) { |
| char buf[4]; |
| - rv = stream.ReadSync(buf, arraysize(buf)); |
| + rv = stream->ReadSync(buf, arraysize(buf)); |
| EXPECT_LE(0, rv); |
| if (rv <= 0) |
| break; |
| total_bytes_read += rv; |
| data_read.append(buf, rv); |
| } |
| - stream.CloseSync(); |
| + stream.reset(); |
| ok = file_util::GetFileSize(temp_file_path(), &file_size); |
| EXPECT_TRUE(ok); |
| @@ -739,15 +625,15 @@ TEST_F(FileStreamTest, BasicAsyncReadWrite) { |
| bool ok = file_util::GetFileSize(temp_file_path(), &file_size); |
| EXPECT_TRUE(ok); |
| - FileStream stream(NULL); |
| + scoped_ptr<FileStream> stream(new FileStream(NULL)); |
| int flags = base::PLATFORM_FILE_OPEN | |
| base::PLATFORM_FILE_READ | |
| base::PLATFORM_FILE_WRITE | |
| base::PLATFORM_FILE_ASYNC; |
| - int rv = stream.OpenSync(temp_file_path(), flags); |
| + int rv = stream->OpenSync(temp_file_path(), flags); |
| EXPECT_EQ(OK, rv); |
| - int64 total_bytes_avail = stream.Available(); |
| + int64 total_bytes_avail = stream->Available(); |
| EXPECT_EQ(file_size, total_bytes_avail); |
| TestCompletionCallback callback; |
| @@ -756,7 +642,7 @@ TEST_F(FileStreamTest, BasicAsyncReadWrite) { |
| std::string data_read; |
| for (;;) { |
| scoped_refptr<IOBufferWithSize> buf = new IOBufferWithSize(4); |
| - rv = stream.Read(buf, buf->size(), callback.callback()); |
| + rv = stream->Read(buf, buf->size(), callback.callback()); |
| if (rv == ERR_IO_PENDING) |
| rv = callback.WaitForResult(); |
| EXPECT_LE(0, rv); |
| @@ -774,8 +660,8 @@ TEST_F(FileStreamTest, BasicAsyncReadWrite) { |
| scoped_refptr<DrainableIOBuffer> drainable = |
| new DrainableIOBuffer(buf, buf->size()); |
| while (total_bytes_written != kTestDataSize) { |
| - rv = stream.Write(drainable, drainable->BytesRemaining(), |
| - callback.callback()); |
| + rv = stream->Write(drainable, drainable->BytesRemaining(), |
| + callback.callback()); |
| if (rv == ERR_IO_PENDING) |
| rv = callback.WaitForResult(); |
| EXPECT_LT(0, rv); |
| @@ -785,7 +671,7 @@ TEST_F(FileStreamTest, BasicAsyncReadWrite) { |
| total_bytes_written += rv; |
| } |
| - stream.CloseSync(); |
| + stream.reset(); |
| ok = file_util::GetFileSize(temp_file_path(), &file_size); |
| EXPECT_TRUE(ok); |
| @@ -797,19 +683,19 @@ TEST_F(FileStreamTest, BasicAsyncWriteRead) { |
| bool ok = file_util::GetFileSize(temp_file_path(), &file_size); |
| EXPECT_TRUE(ok); |
| - FileStream stream(NULL); |
| + scoped_ptr<FileStream> stream(new FileStream(NULL)); |
| int flags = base::PLATFORM_FILE_OPEN | |
| base::PLATFORM_FILE_READ | |
| base::PLATFORM_FILE_WRITE | |
| base::PLATFORM_FILE_ASYNC; |
| - int rv = stream.OpenSync(temp_file_path(), flags); |
| + int rv = stream->OpenSync(temp_file_path(), flags); |
| EXPECT_EQ(OK, rv); |
| - int64 total_bytes_avail = stream.Available(); |
| + int64 total_bytes_avail = stream->Available(); |
| EXPECT_EQ(file_size, total_bytes_avail); |
| TestInt64CompletionCallback callback64; |
| - rv = stream.Seek(FROM_END, 0, callback64.callback()); |
| + rv = stream->Seek(FROM_END, 0, callback64.callback()); |
| ASSERT_EQ(ERR_IO_PENDING, rv); |
| int64 offset = callback64.WaitForResult(); |
| EXPECT_EQ(offset, file_size); |
| @@ -821,7 +707,7 @@ TEST_F(FileStreamTest, BasicAsyncWriteRead) { |
| scoped_refptr<DrainableIOBuffer> drainable = |
| new DrainableIOBuffer(buf, buf->size()); |
| while (total_bytes_written != kTestDataSize) { |
| - rv = stream.Write(drainable, drainable->BytesRemaining(), |
| + rv = stream->Write(drainable, drainable->BytesRemaining(), |
| callback.callback()); |
| if (rv == ERR_IO_PENDING) |
| rv = callback.WaitForResult(); |
| @@ -834,7 +720,7 @@ TEST_F(FileStreamTest, BasicAsyncWriteRead) { |
| EXPECT_EQ(kTestDataSize, total_bytes_written); |
| - rv = stream.Seek(FROM_BEGIN, 0, callback64.callback()); |
| + rv = stream->Seek(FROM_BEGIN, 0, callback64.callback()); |
| ASSERT_EQ(ERR_IO_PENDING, rv); |
| offset = callback64.WaitForResult(); |
| EXPECT_EQ(0, offset); |
| @@ -844,7 +730,7 @@ TEST_F(FileStreamTest, BasicAsyncWriteRead) { |
| std::string data_read; |
| for (;;) { |
| scoped_refptr<IOBufferWithSize> buf = new IOBufferWithSize(4); |
| - rv = stream.Read(buf, buf->size(), callback.callback()); |
| + rv = stream->Read(buf, buf->size(), callback.callback()); |
| if (rv == ERR_IO_PENDING) |
| rv = callback.WaitForResult(); |
| EXPECT_LE(0, rv); |
| @@ -853,7 +739,7 @@ TEST_F(FileStreamTest, BasicAsyncWriteRead) { |
| total_bytes_read += rv; |
| data_read.append(buf->data(), rv); |
| } |
| - stream.CloseSync(); |
| + stream.reset(); |
| ok = file_util::GetFileSize(temp_file_path(), &file_size); |
| EXPECT_TRUE(ok); |
| @@ -963,34 +849,34 @@ TEST_F(FileStreamTest, AsyncWriteRead) { |
| bool ok = file_util::GetFileSize(temp_file_path(), &file_size); |
| EXPECT_TRUE(ok); |
| - FileStream stream(NULL); |
| + scoped_ptr<FileStream> stream(new FileStream(NULL)); |
| int flags = base::PLATFORM_FILE_OPEN | |
| base::PLATFORM_FILE_READ | |
| base::PLATFORM_FILE_WRITE | |
| base::PLATFORM_FILE_ASYNC; |
| - int rv = stream.OpenSync(temp_file_path(), flags); |
| + int rv = stream->OpenSync(temp_file_path(), flags); |
| EXPECT_EQ(OK, rv); |
| - int64 total_bytes_avail = stream.Available(); |
| + int64 total_bytes_avail = stream->Available(); |
| EXPECT_EQ(file_size, total_bytes_avail); |
| - int64 offset = stream.SeekSync(FROM_END, 0); |
| + int64 offset = stream->SeekSync(FROM_END, 0); |
| EXPECT_EQ(offset, file_size); |
| int total_bytes_written = 0; |
| int total_bytes_read = 0; |
| std::string data_read; |
| - TestWriteReadCompletionCallback callback(&stream, &total_bytes_written, |
| + TestWriteReadCompletionCallback callback(stream.get(), &total_bytes_written, |
| &total_bytes_read, &data_read); |
| scoped_refptr<IOBufferWithSize> buf = CreateTestDataBuffer(); |
| - rv = stream.Write(buf, buf->size(), callback.callback()); |
| + rv = stream->Write(buf, buf->size(), callback.callback()); |
| if (rv == ERR_IO_PENDING) |
| rv = callback.WaitForResult(); |
| EXPECT_LT(0, rv); |
| EXPECT_EQ(kTestDataSize, total_bytes_written); |
| - stream.CloseSync(); |
| + stream.reset(); |
| ok = file_util::GetFileSize(temp_file_path(), &file_size); |
| EXPECT_TRUE(ok); |
| @@ -1046,8 +932,6 @@ class TestWriteCloseCompletionCallback { |
| rv = callback.WaitForResult(); |
| drainable_->DidConsume(total_bytes_written); |
| *total_bytes_written_ += total_bytes_written; |
| - } else { // We're done writing all data. Close the file. |
| - stream_->CloseSync(); |
| } |
| result_ = *total_bytes_written_; |
| @@ -1073,30 +957,32 @@ TEST_F(FileStreamTest, AsyncWriteClose) { |
| bool ok = file_util::GetFileSize(temp_file_path(), &file_size); |
| EXPECT_TRUE(ok); |
| - FileStream stream(NULL); |
| + scoped_ptr<FileStream> stream(new FileStream(NULL)); |
| int flags = base::PLATFORM_FILE_OPEN | |
| base::PLATFORM_FILE_READ | |
| base::PLATFORM_FILE_WRITE | |
| base::PLATFORM_FILE_ASYNC; |
| - int rv = stream.OpenSync(temp_file_path(), flags); |
| + int rv = stream->OpenSync(temp_file_path(), flags); |
| EXPECT_EQ(OK, rv); |
| - int64 total_bytes_avail = stream.Available(); |
| + int64 total_bytes_avail = stream->Available(); |
| EXPECT_EQ(file_size, total_bytes_avail); |
| - int64 offset = stream.SeekSync(FROM_END, 0); |
| + int64 offset = stream->SeekSync(FROM_END, 0); |
| EXPECT_EQ(offset, file_size); |
| int total_bytes_written = 0; |
| - TestWriteCloseCompletionCallback callback(&stream, &total_bytes_written); |
| + TestWriteCloseCompletionCallback callback(stream.get(), &total_bytes_written); |
| scoped_refptr<IOBufferWithSize> buf = CreateTestDataBuffer(); |
| - rv = stream.Write(buf, buf->size(), callback.callback()); |
| + rv = stream->Write(buf, buf->size(), callback.callback()); |
| if (rv == ERR_IO_PENDING) |
| total_bytes_written = callback.WaitForResult(); |
| EXPECT_LT(0, total_bytes_written); |
| EXPECT_EQ(kTestDataSize, total_bytes_written); |
| + stream.reset(); |
| + |
| ok = file_util::GetFileSize(temp_file_path(), &file_size); |
| EXPECT_TRUE(ok); |
| EXPECT_EQ(kTestDataSize * 2, file_size); |
| @@ -1106,21 +992,21 @@ TEST_F(FileStreamTest, AsyncWriteClose) { |
| TEST_F(FileStreamTest, Truncate) { |
| int flags = base::PLATFORM_FILE_CREATE_ALWAYS | base::PLATFORM_FILE_WRITE; |
| - FileStream write_stream(NULL); |
| - ASSERT_EQ(OK, write_stream.OpenSync(temp_file_path(), flags)); |
| + scoped_ptr<FileStream> write_stream(new FileStream(NULL)); |
| + ASSERT_EQ(OK, write_stream->OpenSync(temp_file_path(), flags)); |
| // Write some data to the file. |
| const char test_data[] = "0123456789"; |
| - write_stream.WriteSync(test_data, arraysize(test_data)); |
| + write_stream->WriteSync(test_data, arraysize(test_data)); |
| // Truncate the file. |
| - ASSERT_EQ(4, write_stream.Truncate(4)); |
| + ASSERT_EQ(4, write_stream->Truncate(4)); |
| // Write again. |
| - write_stream.WriteSync(test_data, 4); |
| + write_stream->WriteSync(test_data, 4); |
| // Close the stream. |
| - write_stream.CloseSync(); |
| + write_stream.reset(); |
| // Read in the contents and make sure we get back what we expected. |
| std::string read_contents; |
| @@ -1129,97 +1015,6 @@ TEST_F(FileStreamTest, Truncate) { |
| EXPECT_EQ("01230123", read_contents); |
| } |
| -TEST_F(FileStreamTest, AsyncBasicOpenClose) { |
|
willchan no longer on Chromium
2012/10/30 18:01:27
Why are all of these deleted again? I forget :(
pivanof
2012/10/30 18:54:21
Basically everything except AsyncRead_EarlyDelete_
|
| - FileStream stream(NULL); |
| - int flags = base::PLATFORM_FILE_OPEN | |
| - base::PLATFORM_FILE_READ | |
| - base::PLATFORM_FILE_ASYNC; |
| - TestCompletionCallback callback; |
| - int rv = stream.Open(temp_file_path(), flags, callback.callback()); |
| - EXPECT_EQ(ERR_IO_PENDING, rv); |
| - EXPECT_EQ(OK, callback.WaitForResult()); |
| - EXPECT_TRUE(stream.IsOpen()); |
| - |
| - stream.Close(callback.callback()); |
| - EXPECT_EQ(OK, callback.WaitForResult()); |
| - EXPECT_FALSE(stream.IsOpen()); |
| -} |
| - |
| -TEST_F(FileStreamTest, SyncCloseTwice) { |
| - FileStream stream(NULL); |
| - int flags = base::PLATFORM_FILE_OPEN | |
| - base::PLATFORM_FILE_READ; |
| - int rv = stream.OpenSync(temp_file_path(), flags); |
| - EXPECT_EQ(OK, rv); |
| - EXPECT_TRUE(stream.IsOpen()); |
| - |
| - // Closing twice should be safe. |
| - stream.CloseSync(); |
| - EXPECT_FALSE(stream.IsOpen()); |
| - |
| - stream.CloseSync(); |
| - EXPECT_FALSE(stream.IsOpen()); |
| -} |
| - |
| -TEST_F(FileStreamTest, AsyncCloseTwice) { |
| - FileStream stream(NULL); |
| - int flags = base::PLATFORM_FILE_OPEN | |
| - base::PLATFORM_FILE_READ | |
| - base::PLATFORM_FILE_ASYNC; |
| - TestCompletionCallback callback; |
| - int rv = stream.Open(temp_file_path(), flags, callback.callback()); |
| - EXPECT_EQ(ERR_IO_PENDING, rv); |
| - EXPECT_EQ(OK, callback.WaitForResult()); |
| - EXPECT_TRUE(stream.IsOpen()); |
| - |
| - // Closing twice should be safe. |
| - stream.Close(callback.callback()); |
| - EXPECT_EQ(OK, callback.WaitForResult()); |
| - EXPECT_FALSE(stream.IsOpen()); |
| - |
| - stream.Close(callback.callback()); |
| - EXPECT_EQ(OK, callback.WaitForResult()); |
| - EXPECT_FALSE(stream.IsOpen()); |
| -} |
| - |
| -// TODO(satorux): This should be gone once all once all async clients are |
| -// migrated to use Close(). crbug.com/114783 |
| -TEST_F(FileStreamTest, AsyncWriteAndCloseSync) { |
| - FileStream stream(NULL); |
| - int flags = base::PLATFORM_FILE_OPEN | |
| - base::PLATFORM_FILE_WRITE | |
| - base::PLATFORM_FILE_ASYNC; |
| - TestCompletionCallback callback; |
| - int rv = stream.Open(temp_file_path(), flags, callback.callback()); |
| - EXPECT_EQ(ERR_IO_PENDING, rv); |
| - EXPECT_EQ(OK, callback.WaitForResult()); |
| - EXPECT_TRUE(stream.IsOpen()); |
| - |
| - // Write some data asynchronously. |
| - scoped_refptr<IOBufferWithSize> buf = CreateTestDataBuffer(); |
| - stream.Write(buf, buf->size(), callback.callback()); |
| - |
| - // Close the stream without waiting for the completion. |
| - stream.CloseSync(); |
| -} |
| - |
| -// TODO(satorux): This should be gone once all once all async clients are |
| -// migrated to use Close(). crbug.com/114783 |
| -TEST_F(FileStreamTest, AsyncOpenAndCloseSync) { |
| - FileStream stream(NULL); |
| - int flags = base::PLATFORM_FILE_OPEN | |
| - base::PLATFORM_FILE_WRITE | |
| - base::PLATFORM_FILE_ASYNC; |
| - TestCompletionCallback open_callback; |
| - int rv = stream.Open(temp_file_path(), flags, open_callback.callback()); |
| - EXPECT_EQ(ERR_IO_PENDING, rv); |
| - |
| - // Close the stream without waiting for the completion. Should be safe. |
| - stream.CloseSync(); |
| - // open_callback won't be called. |
| - EXPECT_FALSE(open_callback.have_result()); |
| -} |
| - |
| TEST_F(FileStreamTest, AsyncOpenAndDelete) { |
| scoped_ptr<FileStream> stream(new FileStream(NULL)); |
| int flags = base::PLATFORM_FILE_OPEN | |
| @@ -1233,30 +1028,10 @@ TEST_F(FileStreamTest, AsyncOpenAndDelete) { |
| // complete. Should be safe. |
| stream.reset(); |
| // open_callback won't be called. |
| + MessageLoop::current()->RunAllPending(); |
| EXPECT_FALSE(open_callback.have_result()); |
| } |
| -TEST_F(FileStreamTest, AsyncCloseAndDelete) { |
| - scoped_ptr<FileStream> stream(new FileStream(NULL)); |
| - int flags = base::PLATFORM_FILE_OPEN | |
| - base::PLATFORM_FILE_WRITE | |
| - base::PLATFORM_FILE_ASYNC; |
| - TestCompletionCallback open_callback; |
| - int rv = stream->Open(temp_file_path(), flags, open_callback.callback()); |
| - EXPECT_EQ(ERR_IO_PENDING, rv); |
| - EXPECT_EQ(OK, open_callback.WaitForResult()); |
| - EXPECT_TRUE(stream->IsOpen()); |
| - |
| - TestCompletionCallback close_callback; |
| - stream->Close(close_callback.callback()); |
| - |
| - // Delete the stream without waiting for the close operation to be |
| - // complete. Should be safe. |
| - stream.reset(); |
| - // close_callback won't be called. |
| - EXPECT_FALSE(close_callback.have_result()); |
| -} |
| - |
| } // namespace |
| } // namespace net |