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

Unified Diff: mojo/system/embedder_unittest.cc

Issue 140403002: Mojo: Add the ability to hook up a channel to the embedder API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: win Created 6 years, 11 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 | « mojo/system/embedder.cc ('k') | mojo/system/raw_channel_posix_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/system/embedder_unittest.cc
diff --git a/mojo/system/embedder_unittest.cc b/mojo/system/embedder_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..ddd889fce4f87820e8010fc35b9e664f20b04cff
--- /dev/null
+++ b/mojo/system/embedder_unittest.cc
@@ -0,0 +1,102 @@
+// 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/system/embedder.h"
+
+#include <string.h>
+
+#include "base/bind.h"
+#include "base/location.h"
+#include "base/logging.h"
+// TODO(vtl): Remove build_config.h include when fully implemented on Windows.
+#include "build/build_config.h"
+#include "mojo/public/system/core.h"
+#include "mojo/system/platform_channel_pair.h"
+#include "mojo/system/test_embedder.h"
+#include "mojo/system/test_utils.h"
+
+namespace mojo {
+namespace embedder {
+namespace {
+
+typedef system::test::TestWithIOThreadBase EmbedderTest;
+
+void StoreChannelInfo(ChannelInfo** store_channel_info_here,
+ ChannelInfo* channel_info) {
+ CHECK(store_channel_info_here);
+ CHECK(channel_info);
+ *store_channel_info_here = channel_info;
+}
+
+TEST_F(EmbedderTest, ChannelsBasic) {
+ Init();
+
+// TODO(vtl): |PlatformChannelPair| not implemented on Windows yet.
+#if !defined(OS_WIN)
+ system::PlatformChannelPair channel_pair;
+ system::ScopedPlatformHandle server_handle = channel_pair.PassServerHandle();
+ system::ScopedPlatformHandle client_handle = channel_pair.PassClientHandle();
+
+ ChannelInfo* server_channel_info = NULL;
+ MojoHandle server_mp = CreateChannel(server_handle.Pass(),
+ io_thread_task_runner(),
+ base::Bind(&StoreChannelInfo,
+ &server_channel_info));
+ EXPECT_NE(server_mp, MOJO_HANDLE_INVALID);
+
+ ChannelInfo* client_channel_info = NULL;
+ MojoHandle client_mp = CreateChannel(client_handle.Pass(),
+ io_thread_task_runner(),
+ base::Bind(&StoreChannelInfo,
+ &client_channel_info));
+ EXPECT_NE(client_mp, MOJO_HANDLE_INVALID);
+
+ // We can write to a message pipe handle immediately.
+ const char kHello[] = "hello";
+ EXPECT_EQ(MOJO_RESULT_OK,
+ MojoWriteMessage(server_mp, kHello,
+ static_cast<uint32_t>(sizeof(kHello)), NULL, 0u,
+ MOJO_WRITE_MESSAGE_FLAG_NONE));
+
+ // Now wait for the other side to become readable.
+ EXPECT_EQ(MOJO_RESULT_OK,
+ MojoWait(client_mp, MOJO_WAIT_FLAG_READABLE,
+ MOJO_DEADLINE_INDEFINITE));
+
+ char buffer[1000] = {};
+ uint32_t num_bytes = static_cast<uint32_t>(sizeof(kHello));
+ EXPECT_EQ(MOJO_RESULT_OK,
+ MojoReadMessage(client_mp, buffer, &num_bytes, NULL, NULL,
+ MOJO_READ_MESSAGE_FLAG_NONE));
+ EXPECT_EQ(sizeof(kHello), num_bytes);
+ EXPECT_EQ(0, memcmp(buffer, kHello, num_bytes));
+
+ // TODO(vtl): FIXME -- This rapid-fire closing leads to a warning: "Received a
+ // message for nonexistent local destination ID 1". This is due to a race
+ // condition (in channel.cc/message_pipe.cc).
+ EXPECT_EQ(MOJO_RESULT_OK, MojoClose(server_mp));
+ EXPECT_EQ(MOJO_RESULT_OK, MojoClose(client_mp));
+
+ EXPECT_TRUE(server_channel_info != NULL);
+ system::test::PostTaskAndWait(io_thread_task_runner(),
+ FROM_HERE,
+ base::Bind(&DestroyChannelOnIOThread,
+ server_channel_info));
+
+ EXPECT_TRUE(client_channel_info != NULL);
+ system::test::PostTaskAndWait(io_thread_task_runner(),
+ FROM_HERE,
+ base::Bind(&DestroyChannelOnIOThread,
+ client_channel_info));
+#endif // !defined(OS_WIN)
+
+ test::Shutdown();
+}
+
+// TODO(vtl): Test immediate write & close.
+// TODO(vtl): Test broken-connection cases.
+
+} // namespace
+} // namespace embedder
+} // namespace mojo
« no previous file with comments | « mojo/system/embedder.cc ('k') | mojo/system/raw_channel_posix_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698