Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "content/renderer/pepper_plugin_delegate_impl.h" | |
| 6 | |
| 7 #if defined(OS_POSIX) | |
| 8 #include <fcntl.h> | |
| 9 #include <sys/socket.h> | |
| 10 #endif // defined(OS_POSIX)); | |
| 11 | |
| 12 #include "content/test/mock_render_process.h" | |
| 13 #include "testing/gtest/include/gtest/gtest.h" | |
| 14 | |
| 15 class PepperPluginDelegateImplTest : public ::testing::Test { | |
| 16 protected: | |
| 17 MessageLoopForIO message_loop_; | |
| 18 // We need a render process for ppapi::proxy::ProxyChannel to work. | |
| 19 MockRenderProcess mock_process_; | |
| 20 }; | |
| 21 | |
| 22 TEST_F(PepperPluginDelegateImplTest, BrokerDispatcherWrapperInitFailure) { | |
| 23 // Try to initialize BrokerDispatcherWrapper with invalid ChannelHandle. | |
|
ddorwin
2011/11/07 23:54:07
This is a test-level comment and should be above t
xhwang
2011/11/08 00:45:39
Done.
| |
| 24 // Initialization should fail. | |
| 25 BrokerDispatcherWrapper dispatcher_wrapper; | |
| 26 base::ProcessHandle broker_process_handle = base::kNullProcessHandle; | |
| 27 IPC::ChannelHandle invalid_channel; // Invalid by default. | |
| 28 | |
| 29 // An invalide handle should result in a failure (false) without a CHECK, such | |
|
ddorwin
2011/11/07 23:54:07
invalid
"CHECK" is misleading since it's a LOG(FAT
xhwang
2011/11/08 00:45:39
Done.
| |
| 30 // as the one in CreatePipe(). Call it twice because without the invalid | |
| 31 // handle check, the posix code would hit a one-time path due to a static | |
| 32 // variable and cause a LOG(FATAL). | |
|
ddorwin
2011/11/07 23:54:07
... and not go through the LOG(FATAL) path.
xhwang
2011/11/08 00:45:39
Done.
| |
| 33 EXPECT_FALSE(dispatcher_wrapper.Init(broker_process_handle, invalid_channel)); | |
| 34 EXPECT_FALSE(dispatcher_wrapper.Init(broker_process_handle, invalid_channel)); | |
| 35 | |
| 36 // On valid ChannelHandle, initialization should succeed. | |
|
ddorwin
2011/11/07 23:54:07
Success should be a different test - something lik
xhwang
2011/11/08 00:45:39
Done.
| |
| 37 const char kChannelName[] = "/tmp/PepperPluginDelegateImplTestChannelName"; | |
|
ddorwin
2011/11/07 23:54:07
Is this a file or just a string? This is weird on
xhwang
2011/11/08 00:45:39
Done.
| |
| 38 #if defined(OS_POSIX) | |
| 39 int fds[2] = {-1, -1}; | |
|
ddorwin
2011/11/07 23:54:07
Is there a CreateSocketPair() or something like th
xhwang
2011/11/08 00:45:39
bool SocketPair(int* fd1, int* fd2) is defined in
| |
| 40 ASSERT_EQ(0, socketpair(AF_UNIX, SOCK_STREAM, 0, fds)); | |
| 41 // Channel::ChannelImpl::CreatePipe needs the fd to be non-blocking. | |
| 42 ASSERT_EQ(0, fcntl(fds[1], F_SETFL, O_NONBLOCK)); | |
| 43 base::FileDescriptor file_descriptor(fds[1], true); // Auto close. | |
| 44 IPC::ChannelHandle valid_channel(kChannelName, file_descriptor); | |
| 45 #else | |
| 46 IPC::ChannelHandle valid_channel(kChannelName); | |
| 47 #endif // defined(OS_POSIX)); | |
| 48 | |
| 49 EXPECT_TRUE(dispatcher_wrapper.Init(broker_process_handle, valid_channel)); | |
| 50 | |
| 51 #if defined(OS_POSIX) | |
| 52 EXPECT_EQ(0, ::close(fds[0])); | |
| 53 #endif // defined(OS_POSIX)); | |
| 54 } | |
| OLD | NEW |