OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/renderer/pepper/pepper_broker.h" | 5 #include "content/renderer/pepper/pepper_broker.h" |
6 | 6 |
7 #if defined(OS_POSIX) | 7 #if defined(OS_POSIX) |
8 #include <fcntl.h> | 8 #include <fcntl.h> |
9 #include <sys/socket.h> | 9 #include <sys/socket.h> |
10 #endif // defined(OS_POSIX) | 10 #endif // defined(OS_POSIX) |
(...skipping 21 matching lines...) Expand all Loading... |
32 // such as the one in CreatePipe(). Call it twice because without the invalid | 32 // such as the one in CreatePipe(). Call it twice because without the invalid |
33 // handle check, the posix code would hit a one-time path due to a static | 33 // handle check, the posix code would hit a one-time path due to a static |
34 // variable and go through the LOG(FATAL) path. | 34 // variable and go through the LOG(FATAL) path. |
35 EXPECT_FALSE(dispatcher_wrapper.Init(base::kNullProcessId, invalid_channel)); | 35 EXPECT_FALSE(dispatcher_wrapper.Init(base::kNullProcessId, invalid_channel)); |
36 EXPECT_FALSE(dispatcher_wrapper.Init(base::kNullProcessId, invalid_channel)); | 36 EXPECT_FALSE(dispatcher_wrapper.Init(base::kNullProcessId, invalid_channel)); |
37 } | 37 } |
38 | 38 |
39 // On valid ChannelHandle, initialization should succeed. | 39 // On valid ChannelHandle, initialization should succeed. |
40 TEST_F(PepperBrokerTest, InitSuccess) { | 40 TEST_F(PepperBrokerTest, InitSuccess) { |
41 PepperBrokerDispatcherWrapper dispatcher_wrapper; | 41 PepperBrokerDispatcherWrapper dispatcher_wrapper; |
42 const char kChannelName[] = "PepperHelperImplTestChannelName"; | 42 mojo::MessagePipe pipe; |
43 #if defined(OS_POSIX) | 43 IPC::ChannelHandle valid_channel(pipe.handle0.release()); |
44 int fds[2] = {-1, -1}; | |
45 ASSERT_EQ(0, socketpair(AF_UNIX, SOCK_STREAM, 0, fds)); | |
46 // Channel::ChannelImpl::CreatePipe needs the fd to be non-blocking. | |
47 ASSERT_EQ(0, fcntl(fds[1], F_SETFL, O_NONBLOCK)); | |
48 base::FileDescriptor file_descriptor(fds[1], true); // Auto close. | |
49 IPC::ChannelHandle valid_channel(kChannelName, file_descriptor); | |
50 #else | |
51 IPC::ChannelHandle valid_channel(kChannelName); | |
52 #endif // defined(OS_POSIX)); | |
53 | 44 |
54 EXPECT_TRUE(dispatcher_wrapper.Init(base::kNullProcessId, valid_channel)); | 45 EXPECT_TRUE(dispatcher_wrapper.Init(base::kNullProcessId, valid_channel)); |
55 | |
56 #if defined(OS_POSIX) | |
57 EXPECT_EQ(0, ::close(fds[0])); | |
58 #endif // defined(OS_POSIX)); | |
59 } | 46 } |
60 | 47 |
61 } // namespace content | 48 } // namespace content |
OLD | NEW |