Index: mojo/common/data_pipe_utils_unittest.cc |
diff --git a/mojo/common/data_pipe_utils_unittest.cc b/mojo/common/data_pipe_utils_unittest.cc |
index 61f0afa5ccfdb205660cbe3ab686318fd1c763bf..bd9ea8e955963a7540b8341169d140b6d8a4a045 100644 |
--- a/mojo/common/data_pipe_utils_unittest.cc |
+++ b/mojo/common/data_pipe_utils_unittest.cc |
@@ -4,12 +4,68 @@ |
#include "mojo/common/data_pipe_utils.h" |
+#include "base/bind.h" |
+#include "base/files/file_util.h" |
+#include "base/files/scoped_temp_dir.h" |
+#include "base/message_loop/message_loop.h" |
+#include "base/synchronization/condition_variable.h" |
+#include "base/threading/sequenced_worker_pool.h" |
+#include "base/time/time.h" |
#include "testing/gtest/include/gtest/gtest.h" |
namespace mojo { |
namespace common { |
+ |
namespace { |
+void TransferBooleanValueAndExecute(const base::Closure& closure, |
+ bool* to_write, |
+ bool value) { |
+ *to_write = value; |
+ if (!closure.is_null()) { |
+ closure.Run(); |
+ } |
+} |
+ |
+TEST(DataPipeUtilsTest, AsyncFileTransfer) { |
+ const char kData[] = "Hello world."; |
+ base::ScopedTempDir temp_dir; |
+ ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
+ base::FilePath input; |
+ base::FilePath output; |
+ ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir.path(), &input)); |
+ ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir.path(), &output)); |
+ ASSERT_TRUE(base::WriteFile(input, kData, arraysize(kData))); |
+ base::MessageLoop loop; |
+ scoped_refptr<base::SequencedWorkerPool> blocking_pool = |
+ new base::SequencedWorkerPool(2, "blocking_pool"); |
+ |
+ bool write_succeded = false; |
+ bool read_succeded = false; |
+ |
+ DataPipe pipes; |
+ CopyFromFile(input, |
+ pipes.producer_handle.Pass(), |
+ 0, |
+ blocking_pool.get(), |
+ base::Bind(&TransferBooleanValueAndExecute, |
+ base::Closure(), |
+ base::Unretained(&write_succeded))); |
+ CopyToFile(pipes.consumer_handle.Pass(), |
+ output, |
+ blocking_pool.get(), |
+ base::Bind(&TransferBooleanValueAndExecute, |
+ base::MessageLoop::QuitClosure(), |
+ base::Unretained(&read_succeded))); |
+ loop.Run(); |
+ |
+ EXPECT_TRUE(write_succeded); |
+ EXPECT_TRUE(read_succeded); |
+ EXPECT_TRUE(base::ContentsEqual(input, output)); |
+ |
+ blocking_pool->Shutdown(); |
+} |
+ |
/* |
TEST(DataPipePeek, PeekNBytes) { |
DataPipe data_pipe; |
@@ -104,6 +160,8 @@ TEST(DataPipePeek, PeekLine) { |
EXPECT_FALSE(BlockingPeekLine(consumer, &str, max_str_length, timeout)); |
} |
*/ |
+ |
} // namespace |
+ |
} // namespace common |
} // namespace mojo |