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..81e1fdb130986f7d82dfe6d82aaf8f472ef1de43 |
--- /dev/null |
+++ b/content/renderer/pepper_plugin_delegate_impl_unittest.cc |
@@ -0,0 +1,34 @@ |
+// 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" |
+#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 channel_handle; // Invalid by default. |
+ |
+ // Try BrokerDispatcherWrapper.Init() TWICE to trigger the LOG(FATAL) |
+ // of "Denying attempt to reuse initial IPC channel for ..." in |
+ // IPC::Channel::ChannelImpl::CreatePipe() in case invalid ChannelHandle is |
+ // not checked properly. If invalid ChannelHandle is not checked and passed |
+ // all the way down to IPC::Channel::ChannelImpl::CreatePipe(), CreatePipe |
+ // will be called in client mode with channel_handle.socket.fd == -1. There |
+ // is a static variable "bool used_initial_channel = false" in this function. |
+ // In the first test it will be set to true. In the second test the |
+ // LOG(FATAL) error will be triggered. |
+ EXPECT_FALSE(dispatcher_wrapper.Init(broker_process_handle, channel_handle)); |
+ EXPECT_FALSE(dispatcher_wrapper.Init(broker_process_handle, channel_handle)); |
+} |