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

Unified Diff: mojo/common/data_pipe_utils_unittest.cc

Issue 694303002: Allow local file to run though content handler. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Follow review Created 6 years, 1 month 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 | « mojo/common/data_pipe_utils.cc ('k') | mojo/shell/dynamic_application_loader.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
new file mode 100644
index 0000000000000000000000000000000000000000..edfc2c45f47d754b46650fd4d104b9d0b5c91351
--- /dev/null
+++ b/mojo/common/data_pipe_utils_unittest.cc
@@ -0,0 +1,64 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#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();
+}
+
+} // namespace
+} // namespace common
+} // namespace mojo
« no previous file with comments | « mojo/common/data_pipe_utils.cc ('k') | mojo/shell/dynamic_application_loader.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698