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: 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: Synced and resolved conflict. 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/renderer/pepper_plugin_delegate_impl.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/renderer/pepper_plugin_delegate_impl_unittest.cc
diff --git a/content/renderer/pepper_plugin_delegate_impl_unittest.cc b/content/renderer/pepper_plugin_delegate_impl_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..73baa2510bddfa4f08bf7c2eaa3e0f2b627571f0
--- /dev/null
+++ b/content/renderer/pepper_plugin_delegate_impl_unittest.cc
@@ -0,0 +1,58 @@
+// Copyright (c) 2011 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 "content/renderer/pepper_plugin_delegate_impl.h"
+
+#if defined(OS_POSIX)
+#include <fcntl.h>
+#include <sys/socket.h>
+#endif // defined(OS_POSIX)
+
+#include "content/test/mock_render_process.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+class PepperPluginDelegateImplTest : public ::testing::Test {
+ protected:
+ MessageLoopForIO message_loop_;
+ // We need a render process for ppapi::proxy::ProxyChannel to work.
+ MockRenderProcess mock_process_;
+};
+
+// Try to initialize BrokerDispatcherWrapper with invalid ChannelHandle.
+// Initialization should fail.
+TEST_F(PepperPluginDelegateImplTest, BrokerDispatcherWrapperInitFailure) {
+ BrokerDispatcherWrapper dispatcher_wrapper;
+ base::ProcessHandle broker_process_handle = base::kNullProcessHandle;
+ IPC::ChannelHandle invalid_channel; // Invalid by default.
+
+ // An invalid handle should result in a failure (false) without a LOG(FATAL),
+ // such as the one in CreatePipe(). Call it twice because without the invalid
+ // handle check, the posix code would hit a one-time path due to a static
+ // variable and go through the LOG(FATAL) path.
+ EXPECT_FALSE(dispatcher_wrapper.Init(broker_process_handle, invalid_channel));
+ EXPECT_FALSE(dispatcher_wrapper.Init(broker_process_handle, invalid_channel));
+}
+
+// On valid ChannelHandle, initialization should succeed.
+TEST_F(PepperPluginDelegateImplTest, BrokerDispatcherWrapperInitSuccess) {
+ BrokerDispatcherWrapper dispatcher_wrapper;
+ base::ProcessHandle broker_process_handle = base::kNullProcessHandle;
+ const char kChannelName[] = "PepperPluginDelegateImplTestChannelName";
+#if defined(OS_POSIX)
+ int fds[2] = {-1, -1};
+ ASSERT_EQ(0, socketpair(AF_UNIX, SOCK_STREAM, 0, fds));
+ // Channel::ChannelImpl::CreatePipe needs the fd to be non-blocking.
+ ASSERT_EQ(0, fcntl(fds[1], F_SETFL, O_NONBLOCK));
+ base::FileDescriptor file_descriptor(fds[1], true); // Auto close.
+ IPC::ChannelHandle valid_channel(kChannelName, file_descriptor);
+#else
+ IPC::ChannelHandle valid_channel(kChannelName);
+#endif // defined(OS_POSIX));
+
+ EXPECT_TRUE(dispatcher_wrapper.Init(broker_process_handle, valid_channel));
+
+#if defined(OS_POSIX)
+ EXPECT_EQ(0, ::close(fds[0]));
+#endif // defined(OS_POSIX));
+}
« no previous file with comments | « content/renderer/pepper_plugin_delegate_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698