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

Side by Side Diff: content/renderer/pepper_plugin_delegate_impl_unittest.cc

Issue 8436008: Add check on invalid file descriptor at both broker and renderer sides. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Split failure and success cases to two different tests. Created 9 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 unified diff | Download patch
OLDNEW
(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));
piman 2011/11/11 22:42:10 nit: remove trailing );
xhwang 2011/11/11 22:53:28 Done.
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 // Try to initialize BrokerDispatcherWrapper with invalid ChannelHandle.
23 // Initialization should fail.
24 TEST_F(PepperPluginDelegateImplTest, BrokerDispatcherWrapperInitFailure) {
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 LOG(FATAL),
piman 2011/11/11 22:42:10 nit:invalide->invalid
xhwang 2011/11/11 22:53:28 Done.
30 // such 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 go through the LOG(FATAL) path.
33 EXPECT_FALSE(dispatcher_wrapper.Init(broker_process_handle, invalid_channel));
34 EXPECT_FALSE(dispatcher_wrapper.Init(broker_process_handle, invalid_channel));
35 }
36
37 // On valid ChannelHandle, initialization should succeed.
38 TEST_F(PepperPluginDelegateImplTest, BrokerDispatcherWrapperInitSuccess) {
39 BrokerDispatcherWrapper dispatcher_wrapper;
40 base::ProcessHandle broker_process_handle = base::kNullProcessHandle;
41 const char kChannelName[] = "PepperPluginDelegateImplTestChannelName";
42 #if defined(OS_POSIX)
43 int fds[2] = {-1, -1};
44 ASSERT_EQ(0, socketpair(AF_UNIX, SOCK_STREAM, 0, fds));
45 // Channel::ChannelImpl::CreatePipe needs the fd to be non-blocking.
46 ASSERT_EQ(0, fcntl(fds[1], F_SETFL, O_NONBLOCK));
47 base::FileDescriptor file_descriptor(fds[1], true); // Auto close.
48 IPC::ChannelHandle valid_channel(kChannelName, file_descriptor);
49 #else
50 IPC::ChannelHandle valid_channel(kChannelName);
51 #endif // defined(OS_POSIX));
52
53 EXPECT_TRUE(dispatcher_wrapper.Init(broker_process_handle, valid_channel));
54
55 #if defined(OS_POSIX)
56 EXPECT_EQ(0, ::close(fds[0]));
57 #endif // defined(OS_POSIX));
58 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698