Chromium Code Reviews| Index: components/mus/gpu/gpu_type_converters_unittest.cc |
| diff --git a/components/mus/gpu/gpu_type_converters_unittest.cc b/components/mus/gpu/gpu_type_converters_unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..c8d6c028989e5b83ac153c15f4d1b36b2237e08e |
| --- /dev/null |
| +++ b/components/mus/gpu/gpu_type_converters_unittest.cc |
| @@ -0,0 +1,54 @@ |
| +// Copyright 2016 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 <string> |
| + |
| +#include "base/files/scoped_file.h" |
| +#include "components/mus/gpu/gpu_type_converters.h" |
| +#include "build/build_config.h" |
| +#include "ipc/ipc_channel.h" |
| +#include "ipc/ipc_channel_handle.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| + |
| +TEST(MusGpuTypeConvertersTest, ChannelHandle) { |
|
Fady Samuel
2016/04/27 18:05:23
nit: Small description of what this does.
Peng
2016/04/27 18:29:00
Done.
|
| + { |
| + const std::string channel_name = "test_channel_name"; |
| + IPC::ChannelHandle handle(channel_name); |
| + |
| + mus::mojom::ChannelHandlePtr mojo_handle = |
| + mus::mojom::ChannelHandle::From(handle); |
| + ASSERT_EQ(mojo_handle->name, channel_name); |
| + EXPECT_FALSE(mojo_handle->socket.is_valid()); |
| + |
| + handle = mojo_handle.To<IPC::ChannelHandle>(); |
| + ASSERT_EQ(handle.name, channel_name); |
| + ASSERT_EQ(handle.socket.fd, -1); |
| + } |
| + |
| +#if defined(OS_POSIX) |
| + { |
| + const std::string channel_name = "test_channel_name"; |
| + int fd1 = -1; |
| + int fd2 = -1; |
| + bool result = IPC::SocketPair(&fd1, &fd2); |
| + EXPECT_TRUE(result); |
| + |
| + base::ScopedFD scoped_fd1(fd1); |
| + base::ScopedFD scoped_fd2(fd2); |
| + IPC::ChannelHandle handle(channel_name, |
| + base::FileDescriptor(scoped_fd1.get(), false)); |
| + |
| + mus::mojom::ChannelHandlePtr mojo_handle = |
| + mus::mojom::ChannelHandle::From(handle); |
| + ASSERT_EQ(mojo_handle->name, channel_name); |
| + EXPECT_TRUE(mojo_handle->socket.is_valid()); |
| + |
| + handle = mojo_handle.To<IPC::ChannelHandle>(); |
| + ASSERT_EQ(handle.name, channel_name); |
| + ASSERT_NE(handle.socket.fd, -1); |
| + EXPECT_TRUE(handle.socket.auto_close); |
| + base::ScopedFD socped_fd3(handle.socket.fd); |
| + } |
| +#endif |
| +} |