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

Unified Diff: net/base/file_stream_unittest.cc

Issue 23872004: Remove base::WorkerPool use from FileStream tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 3 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 | « no previous file | no next file » | 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 a091e7a42aab291ded75234a57a9945a0f5e8220..23612add3a4236ad732c215866cac5a5c84c58d8 100644
--- a/net/base/file_stream_unittest.cc
+++ b/net/base/file_stream_unittest.cc
@@ -7,11 +7,13 @@
#include "base/bind.h"
#include "base/callback.h"
#include "base/file_util.h"
-#include "base/message_loop/message_loop.h"
#include "base/path_service.h"
#include "base/platform_file.h"
+#include "base/run_loop.h"
#include "base/synchronization/waitable_event.h"
+#include "base/task_runner.h"
#include "base/test/test_timeouts.h"
+#include "base/threading/thread.h"
#include "net/base/capturing_net_log.h"
#include "net/base/io_buffer.h"
#include "net/base/net_errors.h"
@@ -37,22 +39,40 @@ IOBufferWithSize* CreateTestDataBuffer() {
class FileStreamTest : public PlatformTest {
public:
+ FileStreamTest() : file_thread_("FileStreamTestFileThread") {}
virtual void SetUp() {
PlatformTest::SetUp();
+ file_thread_.Start();
file_util::CreateTemporaryFile(&temp_file_path_);
file_util::WriteFile(temp_file_path_, kTestData, kTestDataSize);
}
virtual void TearDown() {
EXPECT_TRUE(base::DeleteFile(temp_file_path_, false));
+ TestCompletionCallback callback;
+
+ file_task_runner()->PostTaskAndReply(FROM_HERE, base::Bind(DoNothing),
+ base::Bind(callback.callback(), 0));
+ callback.WaitForResult();
+ base::RunLoop().RunUntilIdle();
+ file_thread_.Stop();
+ base::RunLoop().RunUntilIdle();
+
PlatformTest::TearDown();
}
+ static void DoNothing() {};
+
const base::FilePath temp_file_path() const { return temp_file_path_; }
+ scoped_refptr<base::TaskRunner> file_task_runner() const {
+ CHECK(file_thread_.message_loop_proxy().get());
+ return file_thread_.message_loop_proxy();
+ }
private:
base::FilePath temp_file_path_;
+ base::Thread file_thread_;
Ryan Sleevi 2013/09/06 20:46:38 The only requirement for this interface is that th
};
namespace {
@@ -60,7 +80,7 @@ namespace {
TEST_F(FileStreamTest, BasicOpenClose) {
base::PlatformFile file = base::kInvalidPlatformFileValue;
{
- FileStream stream(NULL);
+ FileStream stream(NULL, file_task_runner());
int rv = stream.OpenSync(temp_file_path(),
base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ);
EXPECT_EQ(OK, rv);
@@ -83,7 +103,7 @@ TEST_F(FileStreamTest, FileHandleNotLeftOpen) {
{
// Seek to the beginning of the file and read.
- FileStream read_stream(file, flags, NULL);
+ FileStream read_stream(file, flags, NULL, file_task_runner());
EXPECT_TRUE(read_stream.IsOpen());
}
@@ -105,7 +125,8 @@ TEST_F(FileStreamTest, UseFileHandle) {
temp_file_path(), flags, &created, NULL);
// Seek to the beginning of the file and read.
- scoped_ptr<FileStream> read_stream(new FileStream(file, flags, NULL));
+ scoped_ptr<FileStream> read_stream(
+ new FileStream(file, flags, NULL, file_task_runner()));
ASSERT_EQ(0, read_stream->SeekSync(FROM_BEGIN, 0));
ASSERT_EQ(kTestDataSize, read_stream->Available());
// Read into buffer and compare.
@@ -120,7 +141,8 @@ TEST_F(FileStreamTest, UseFileHandle) {
flags = base::PLATFORM_FILE_OPEN_ALWAYS | base::PLATFORM_FILE_WRITE;
file = base::CreatePlatformFile(temp_file_path(), flags, &created, NULL);
- scoped_ptr<FileStream> write_stream(new FileStream(file, flags, NULL));
+ scoped_ptr<FileStream> write_stream(
+ new FileStream(file, flags, NULL, file_task_runner()));
ASSERT_EQ(0, write_stream->SeekSync(FROM_BEGIN, 0));
ASSERT_EQ(kTestDataSize,
write_stream->WriteSync(kTestData, kTestDataSize));
@@ -133,7 +155,7 @@ TEST_F(FileStreamTest, UseFileHandle) {
}
TEST_F(FileStreamTest, UseClosedStream) {
- FileStream stream(NULL);
+ FileStream stream(NULL, file_task_runner());
EXPECT_FALSE(stream.IsOpen());
@@ -156,7 +178,7 @@ TEST_F(FileStreamTest, BasicRead) {
bool ok = file_util::GetFileSize(temp_file_path(), &file_size);
EXPECT_TRUE(ok);
- FileStream stream(NULL);
+ FileStream stream(NULL, file_task_runner());
int flags = base::PLATFORM_FILE_OPEN |
base::PLATFORM_FILE_READ;
int rv = stream.OpenSync(temp_file_path(), flags);
@@ -186,7 +208,7 @@ TEST_F(FileStreamTest, AsyncRead) {
bool ok = file_util::GetFileSize(temp_file_path(), &file_size);
EXPECT_TRUE(ok);
- FileStream stream(NULL);
+ FileStream stream(NULL, file_task_runner());
int flags = base::PLATFORM_FILE_OPEN |
base::PLATFORM_FILE_READ |
base::PLATFORM_FILE_ASYNC;
@@ -221,7 +243,7 @@ TEST_F(FileStreamTest, AsyncRead_EarlyDelete) {
bool ok = file_util::GetFileSize(temp_file_path(), &file_size);
EXPECT_TRUE(ok);
- scoped_ptr<FileStream> stream(new FileStream(NULL));
+ scoped_ptr<FileStream> stream(new FileStream(NULL, file_task_runner()));
int flags = base::PLATFORM_FILE_OPEN |
base::PLATFORM_FILE_READ |
base::PLATFORM_FILE_ASYNC;
@@ -239,7 +261,7 @@ TEST_F(FileStreamTest, AsyncRead_EarlyDelete) {
if (rv < 0) {
EXPECT_EQ(ERR_IO_PENDING, rv);
// The callback should not be called if the request is cancelled.
- base::MessageLoop::current()->RunUntilIdle();
+ base::RunLoop().RunUntilIdle();
EXPECT_FALSE(callback.have_result());
} else {
EXPECT_EQ(std::string(kTestData, rv), std::string(buf->data(), rv));
@@ -251,7 +273,7 @@ TEST_F(FileStreamTest, BasicRead_FromOffset) {
bool ok = file_util::GetFileSize(temp_file_path(), &file_size);
EXPECT_TRUE(ok);
- FileStream stream(NULL);
+ FileStream stream(NULL, file_task_runner());
int flags = base::PLATFORM_FILE_OPEN |
base::PLATFORM_FILE_READ;
int rv = stream.OpenSync(temp_file_path(), flags);
@@ -286,7 +308,7 @@ TEST_F(FileStreamTest, AsyncRead_FromOffset) {
bool ok = file_util::GetFileSize(temp_file_path(), &file_size);
EXPECT_TRUE(ok);
- FileStream stream(NULL);
+ FileStream stream(NULL, file_task_runner());
int flags = base::PLATFORM_FILE_OPEN |
base::PLATFORM_FILE_READ |
base::PLATFORM_FILE_ASYNC;
@@ -324,7 +346,7 @@ TEST_F(FileStreamTest, AsyncRead_FromOffset) {
}
TEST_F(FileStreamTest, SeekAround) {
- FileStream stream(NULL);
+ FileStream stream(NULL, file_task_runner());
int flags = base::PLATFORM_FILE_OPEN |
base::PLATFORM_FILE_READ;
int rv = stream.OpenSync(temp_file_path(), flags);
@@ -347,7 +369,7 @@ TEST_F(FileStreamTest, SeekAround) {
}
TEST_F(FileStreamTest, AsyncSeekAround) {
- FileStream stream(NULL);
+ FileStream stream(NULL, file_task_runner());
int flags = base::PLATFORM_FILE_OPEN |
base::PLATFORM_FILE_ASYNC |
base::PLATFORM_FILE_READ;
@@ -383,7 +405,7 @@ TEST_F(FileStreamTest, AsyncSeekAround) {
}
TEST_F(FileStreamTest, BasicWrite) {
- scoped_ptr<FileStream> stream(new FileStream(NULL));
+ scoped_ptr<FileStream> stream(new FileStream(NULL, file_task_runner()));
int flags = base::PLATFORM_FILE_CREATE_ALWAYS |
base::PLATFORM_FILE_WRITE;
int rv = stream->OpenSync(temp_file_path(), flags);
@@ -404,7 +426,7 @@ TEST_F(FileStreamTest, BasicWrite) {
}
TEST_F(FileStreamTest, AsyncWrite) {
- FileStream stream(NULL);
+ FileStream stream(NULL, file_task_runner());
int flags = base::PLATFORM_FILE_CREATE_ALWAYS |
base::PLATFORM_FILE_WRITE |
base::PLATFORM_FILE_ASYNC;
@@ -440,7 +462,7 @@ TEST_F(FileStreamTest, AsyncWrite) {
}
TEST_F(FileStreamTest, AsyncWrite_EarlyDelete) {
- scoped_ptr<FileStream> stream(new FileStream(NULL));
+ scoped_ptr<FileStream> stream(new FileStream(NULL, file_task_runner()));
int flags = base::PLATFORM_FILE_CREATE_ALWAYS |
base::PLATFORM_FILE_WRITE |
base::PLATFORM_FILE_ASYNC;
@@ -460,7 +482,7 @@ TEST_F(FileStreamTest, AsyncWrite_EarlyDelete) {
if (rv < 0) {
EXPECT_EQ(ERR_IO_PENDING, rv);
// The callback should not be called if the request is cancelled.
- base::MessageLoop::current()->RunUntilIdle();
+ base::RunLoop().RunUntilIdle();
EXPECT_FALSE(callback.have_result());
} else {
ok = file_util::GetFileSize(temp_file_path(), &file_size);
@@ -470,7 +492,7 @@ TEST_F(FileStreamTest, AsyncWrite_EarlyDelete) {
}
TEST_F(FileStreamTest, BasicWrite_FromOffset) {
- scoped_ptr<FileStream> stream(new FileStream(NULL));
+ scoped_ptr<FileStream> stream(new FileStream(NULL, file_task_runner()));
int flags = base::PLATFORM_FILE_OPEN |
base::PLATFORM_FILE_WRITE;
int rv = stream->OpenSync(temp_file_path(), flags);
@@ -499,7 +521,7 @@ TEST_F(FileStreamTest, AsyncWrite_FromOffset) {
bool ok = file_util::GetFileSize(temp_file_path(), &file_size);
EXPECT_TRUE(ok);
- FileStream stream(NULL);
+ FileStream stream(NULL, file_task_runner());
int flags = base::PLATFORM_FILE_OPEN |
base::PLATFORM_FILE_WRITE |
base::PLATFORM_FILE_ASYNC;
@@ -541,7 +563,7 @@ TEST_F(FileStreamTest, BasicReadWrite) {
bool ok = file_util::GetFileSize(temp_file_path(), &file_size);
EXPECT_TRUE(ok);
- scoped_ptr<FileStream> stream(new FileStream(NULL));
+ scoped_ptr<FileStream> stream(new FileStream(NULL, file_task_runner()));
int flags = base::PLATFORM_FILE_OPEN |
base::PLATFORM_FILE_READ |
base::PLATFORM_FILE_WRITE;
@@ -580,7 +602,7 @@ TEST_F(FileStreamTest, BasicWriteRead) {
bool ok = file_util::GetFileSize(temp_file_path(), &file_size);
EXPECT_TRUE(ok);
- scoped_ptr<FileStream> stream(new FileStream(NULL));
+ scoped_ptr<FileStream> stream(new FileStream(NULL, file_task_runner()));
int flags = base::PLATFORM_FILE_OPEN |
base::PLATFORM_FILE_READ |
base::PLATFORM_FILE_WRITE;
@@ -628,7 +650,7 @@ TEST_F(FileStreamTest, BasicAsyncReadWrite) {
bool ok = file_util::GetFileSize(temp_file_path(), &file_size);
EXPECT_TRUE(ok);
- scoped_ptr<FileStream> stream(new FileStream(NULL));
+ scoped_ptr<FileStream> stream(new FileStream(NULL, file_task_runner()));
int flags = base::PLATFORM_FILE_OPEN |
base::PLATFORM_FILE_READ |
base::PLATFORM_FILE_WRITE |
@@ -687,7 +709,7 @@ TEST_F(FileStreamTest, BasicAsyncWriteRead) {
bool ok = file_util::GetFileSize(temp_file_path(), &file_size);
EXPECT_TRUE(ok);
- scoped_ptr<FileStream> stream(new FileStream(NULL));
+ scoped_ptr<FileStream> stream(new FileStream(NULL, file_task_runner()));
int flags = base::PLATFORM_FILE_OPEN |
base::PLATFORM_FILE_READ |
base::PLATFORM_FILE_WRITE |
@@ -778,7 +800,7 @@ class TestWriteReadCompletionCallback {
DCHECK(!waiting_for_result_);
while (!have_result_) {
waiting_for_result_ = true;
- base::MessageLoop::current()->Run();
+ base::RunLoop().Run();
waiting_for_result_ = false;
}
have_result_ = false; // auto-reset for next callback
@@ -853,7 +875,7 @@ TEST_F(FileStreamTest, AsyncWriteRead) {
bool ok = file_util::GetFileSize(temp_file_path(), &file_size);
EXPECT_TRUE(ok);
- scoped_ptr<FileStream> stream(new FileStream(NULL));
+ scoped_ptr<FileStream> stream(new FileStream(NULL, file_task_runner()));
int flags = base::PLATFORM_FILE_OPEN |
base::PLATFORM_FILE_READ |
base::PLATFORM_FILE_WRITE |
@@ -911,7 +933,7 @@ class TestWriteCloseCompletionCallback {
DCHECK(!waiting_for_result_);
while (!have_result_) {
waiting_for_result_ = true;
- base::MessageLoop::current()->Run();
+ base::RunLoop().Run();
waiting_for_result_ = false;
}
have_result_ = false; // auto-reset for next callback
@@ -962,7 +984,7 @@ TEST_F(FileStreamTest, AsyncWriteClose) {
bool ok = file_util::GetFileSize(temp_file_path(), &file_size);
EXPECT_TRUE(ok);
- scoped_ptr<FileStream> stream(new FileStream(NULL));
+ scoped_ptr<FileStream> stream(new FileStream(NULL, file_task_runner()));
int flags = base::PLATFORM_FILE_OPEN |
base::PLATFORM_FILE_READ |
base::PLATFORM_FILE_WRITE |
@@ -999,7 +1021,7 @@ TEST_F(FileStreamTest, AsyncWriteClose) {
TEST_F(FileStreamTest, Truncate) {
int flags = base::PLATFORM_FILE_CREATE_ALWAYS | base::PLATFORM_FILE_WRITE;
- scoped_ptr<FileStream> write_stream(new FileStream(NULL));
+ scoped_ptr<FileStream> write_stream(new FileStream(NULL, file_task_runner()));
ASSERT_EQ(OK, write_stream->OpenSync(temp_file_path(), flags));
// Write some data to the file.
@@ -1023,7 +1045,7 @@ TEST_F(FileStreamTest, Truncate) {
}
TEST_F(FileStreamTest, AsyncOpenAndDelete) {
- scoped_ptr<FileStream> stream(new FileStream(NULL));
+ scoped_ptr<FileStream> stream(new FileStream(NULL, file_task_runner()));
int flags = base::PLATFORM_FILE_OPEN |
base::PLATFORM_FILE_WRITE |
base::PLATFORM_FILE_ASYNC;
@@ -1035,13 +1057,13 @@ TEST_F(FileStreamTest, AsyncOpenAndDelete) {
// complete. Should be safe.
stream.reset();
// open_callback won't be called.
- base::MessageLoop::current()->RunUntilIdle();
+ base::RunLoop().RunUntilIdle();
EXPECT_FALSE(open_callback.have_result());
}
// Verify that async Write() errors are mapped correctly.
TEST_F(FileStreamTest, AsyncWriteError) {
- scoped_ptr<FileStream> stream(new FileStream(NULL));
+ scoped_ptr<FileStream> stream(new FileStream(NULL, file_task_runner()));
int flags = base::PLATFORM_FILE_CREATE_ALWAYS |
base::PLATFORM_FILE_WRITE |
base::PLATFORM_FILE_ASYNC;
@@ -1060,7 +1082,7 @@ TEST_F(FileStreamTest, AsyncWriteError) {
// Verify that async Read() errors are mapped correctly.
TEST_F(FileStreamTest, AsyncReadError) {
- scoped_ptr<FileStream> stream(new FileStream(NULL));
+ scoped_ptr<FileStream> stream(new FileStream(NULL, file_task_runner()));
int flags = base::PLATFORM_FILE_OPEN |
base::PLATFORM_FILE_READ |
base::PLATFORM_FILE_ASYNC;
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698