summaryrefslogtreecommitdiffstats
path: root/chrome/renderer/renderer_main_unittest.cc
diff options
context:
space:
mode:
authorjeremy@chromium.org <jeremy@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-02-04 23:16:29 +0000
committerjeremy@chromium.org <jeremy@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-02-04 23:16:29 +0000
commit9629c0e4f8952045296a3c89d861bad68360b1c2 (patch)
treedcf6fb4079f8ecb9849856f06855c8f2450bc348 /chrome/renderer/renderer_main_unittest.cc
parent5d3e4b9a6dd76360e609cfe0bfadf30a47b216ec (diff)
downloadchromium_src-9629c0e4f8952045296a3c89d861bad68360b1c2.zip
chromium_src-9629c0e4f8952045296a3c89d861bad68360b1c2.tar.gz
chromium_src-9629c0e4f8952045296a3c89d861bad68360b1c2.tar.bz2
Add a very simple test for renderer_main, in the interests of bringup.
Also bring up ipc_sync_channel_unittest on OS X. Review URL: http://codereview.chromium.org/21060 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@9184 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/renderer/renderer_main_unittest.cc')
-rw-r--r--chrome/renderer/renderer_main_unittest.cc113
1 files changed, 113 insertions, 0 deletions
diff --git a/chrome/renderer/renderer_main_unittest.cc b/chrome/renderer/renderer_main_unittest.cc
new file mode 100644
index 0000000..f003015
--- /dev/null
+++ b/chrome/renderer/renderer_main_unittest.cc
@@ -0,0 +1,113 @@
+// Copyright (c) 2009 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 "base/message_loop.h"
+#include "base/multiprocess_test.h"
+#include "base/process_util.h"
+#include "chrome/common/chrome_switches.h"
+#include "chrome/common/ipc_channel.h"
+#include "chrome/common/main_function_params.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+// TODO(port): Bring up this test this on other platforms.
+#if defined(OS_MACOSX)
+
+using base::ProcessHandle;
+
+const std::wstring kRendererTestChannelName(L"test");
+
+extern int RendererMain(const MainFunctionParams& parameters);
+
+// TODO(port): The IPC Channel tests have a class with extremely similar
+// functionality, we should combine them.
+class RendererMainTest : public MultiProcessTest {
+ protected:
+
+ // Create a new MessageLoopForIO For each test.
+ virtual void SetUp();
+ virtual void TearDown();
+
+ // Spawns a child process of the specified type
+ base::ProcessHandle SpawnChild(const std::wstring &procname,
+ IPC::Channel *channel);
+
+ // Created around each test instantiation.
+ MessageLoopForIO *message_loop_;
+};
+
+void RendererMainTest::SetUp() {
+ MultiProcessTest::SetUp();
+
+ // Construct a fresh IO Message loop for the duration of each test.
+ message_loop_ = new MessageLoopForIO();
+}
+
+void RendererMainTest::TearDown() {
+ delete message_loop_;
+ message_loop_ = NULL;
+
+ MultiProcessTest::TearDown();
+}
+
+ProcessHandle RendererMainTest::SpawnChild(const std::wstring &procname,
+ IPC::Channel *channel) {
+ base::file_handle_mapping_vector fds_to_map;
+ int src_fd;
+ int dest_fd;
+ channel->GetClientFileDescriptorMapping(&src_fd, &dest_fd);
+ if (src_fd > -1) {
+ fds_to_map.push_back(std::pair<int,int>(src_fd, dest_fd));
+ }
+
+ return MultiProcessTest::SpawnChild(procname, fds_to_map, false);
+}
+
+// Listener class that kills the message loop when it connects.
+class SuicidalListener : public IPC::Channel::Listener {
+ public:
+ void OnChannelConnected(int32 peer_pid) {
+ MessageLoop::current()->Quit();
+ }
+
+ void OnMessageReceived(const IPC::Message& message) {
+ // We shouldn't receive any messages
+ ASSERT_TRUE(false);
+ }
+};
+
+MULTIPROCESS_TEST_MAIN(SimpleRenderer) {
+ SandboxInitWrapper dummy_sandbox_init;
+ CommandLine command_line(L"");
+ command_line.AppendSwitchWithValue(switches::kProcessChannelID,
+ kRendererTestChannelName);
+ MainFunctionParams dummy_params(command_line,
+ dummy_sandbox_init);
+ return RendererMain(dummy_params);
+}
+
+TEST_F(RendererMainTest, CreateDestroy) {
+ SuicidalListener listener;
+ IPC::Channel control_channel(kRendererTestChannelName,
+ IPC::Channel::MODE_SERVER,
+ &listener);
+ base::ProcessHandle renderer_pid = SpawnChild(L"SimpleRenderer",
+ &control_channel);
+
+ control_channel.Connect();
+ MessageLoop::current()->Run();
+
+ // The renderer should exit when we close the channel.
+ control_channel.Close();
+
+ // TODO(playmobil): Remove this.
+ // The renderer should shut down automatically when the Channel is closed
+ // but there are still issues with this, leave in the kill for bringup.
+ base::KillProcess(renderer_pid, 9, true);
+
+ // TODO(playmobil): Enable this.
+ // see comment above KillProcess()
+ // EXPECT_TRUE(base::WaitForSingleProcess(renderer_pid, 5000));
+}
+
+#endif // defined(OS_MACOSX)