OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
| 5 #include "base/compiler_specific.h" |
5 #include "base/message_loop.h" | 6 #include "base/message_loop.h" |
6 #include "base/process_util.h" | 7 #include "base/process_util.h" |
7 #include "base/test/multiprocess_test.h" | 8 #include "base/test/multiprocess_test.h" |
8 #include "base/test/test_timeouts.h" | 9 #include "base/test/test_timeouts.h" |
9 #include "chrome/common/chrome_switches.h" | 10 #include "chrome/common/chrome_switches.h" |
10 #include "chrome/common/main_function_params.h" | 11 #include "chrome/common/main_function_params.h" |
11 #include "ipc/ipc_channel.h" | 12 #include "ipc/ipc_channel.h" |
12 #include "ipc/ipc_switches.h" | 13 #include "ipc/ipc_switches.h" |
13 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
14 #include "testing/multiprocess_func_list.h" | 15 #include "testing/multiprocess_func_list.h" |
(...skipping 14 matching lines...) Expand all Loading... |
29 RendererMainTest() {} | 30 RendererMainTest() {} |
30 | 31 |
31 // Create a new MessageLoopForIO For each test. | 32 // Create a new MessageLoopForIO For each test. |
32 virtual void SetUp(); | 33 virtual void SetUp(); |
33 virtual void TearDown(); | 34 virtual void TearDown(); |
34 | 35 |
35 // Spawns a child process of the specified type | 36 // Spawns a child process of the specified type |
36 base::ProcessHandle SpawnChild(const std::string& procname, | 37 base::ProcessHandle SpawnChild(const std::string& procname, |
37 IPC::Channel* channel); | 38 IPC::Channel* channel); |
38 | 39 |
| 40 virtual CommandLine MakeCmdLine(const std::string& procname, |
| 41 bool debug_on_start) OVERRIDE; |
| 42 |
39 // Created around each test instantiation. | 43 // Created around each test instantiation. |
40 MessageLoopForIO *message_loop_; | 44 MessageLoopForIO *message_loop_; |
41 }; | 45 }; |
42 | 46 |
43 void RendererMainTest::SetUp() { | 47 void RendererMainTest::SetUp() { |
44 MultiProcessTest::SetUp(); | 48 MultiProcessTest::SetUp(); |
45 | 49 |
46 // Construct a fresh IO Message loop for the duration of each test. | 50 // Construct a fresh IO Message loop for the duration of each test. |
47 message_loop_ = new MessageLoopForIO(); | 51 message_loop_ = new MessageLoopForIO(); |
48 } | 52 } |
49 | 53 |
50 void RendererMainTest::TearDown() { | 54 void RendererMainTest::TearDown() { |
51 delete message_loop_; | 55 delete message_loop_; |
52 message_loop_ = NULL; | 56 message_loop_ = NULL; |
53 | 57 |
54 MultiProcessTest::TearDown(); | 58 MultiProcessTest::TearDown(); |
55 } | 59 } |
56 | 60 |
57 ProcessHandle RendererMainTest::SpawnChild(const std::string& procname, | 61 ProcessHandle RendererMainTest::SpawnChild(const std::string& procname, |
58 IPC::Channel* channel) { | 62 IPC::Channel* channel) { |
59 base::file_handle_mapping_vector fds_to_map; | 63 base::file_handle_mapping_vector fds_to_map; |
60 const int ipcfd = channel->GetClientFileDescriptor(); | 64 const int ipcfd = channel->GetClientFileDescriptor(); |
61 if (ipcfd > -1) { | 65 if (ipcfd > -1) { |
62 fds_to_map.push_back(std::pair<int,int>(ipcfd, 3)); | 66 fds_to_map.push_back(std::pair<int,int>(ipcfd, 3)); |
63 } | 67 } |
64 | 68 |
65 return MultiProcessTest::SpawnChild(procname, fds_to_map, false); | 69 return MultiProcessTest::SpawnChild(procname, fds_to_map, false); |
66 } | 70 } |
67 | 71 |
| 72 CommandLine RendererMainTest::MakeCmdLine(const std::string& procname, |
| 73 bool debug_on_start) { |
| 74 CommandLine command_line = |
| 75 MultiProcessTest::MakeCmdLine(procname, debug_on_start); |
| 76 #if defined(USE_SECCOMP_SANDBOX) |
| 77 // Turn off seccomp for this test. It's just a problem of refactoring, |
| 78 // not a bug. |
| 79 // http://code.google.com/p/chromium/issues/detail?id=59376 |
| 80 command_line.AppendSwitch(switches::kDisableSeccompSandbox); |
| 81 #endif |
| 82 return command_line; |
| 83 } |
| 84 |
68 // Listener class that kills the message loop when it connects. | 85 // Listener class that kills the message loop when it connects. |
69 class SuicidalListener : public IPC::Channel::Listener { | 86 class SuicidalListener : public IPC::Channel::Listener { |
70 public: | 87 public: |
71 void OnChannelConnected(int32 peer_pid) { | 88 void OnChannelConnected(int32 peer_pid) { |
72 MessageLoop::current()->Quit(); | 89 MessageLoop::current()->Quit(); |
73 } | 90 } |
74 | 91 |
75 void OnMessageReceived(const IPC::Message& message) { | 92 void OnMessageReceived(const IPC::Message& message) { |
76 // We shouldn't receive any messages | 93 // We shouldn't receive any messages |
77 ASSERT_TRUE(false); | 94 ASSERT_TRUE(false); |
(...skipping 23 matching lines...) Expand all Loading... |
101 TestTimeouts::action_timeout_ms()); | 118 TestTimeouts::action_timeout_ms()); |
102 MessageLoop::current()->Run(); | 119 MessageLoop::current()->Run(); |
103 | 120 |
104 // The renderer should exit when we close the channel. | 121 // The renderer should exit when we close the channel. |
105 control_channel.Close(); | 122 control_channel.Close(); |
106 | 123 |
107 EXPECT_TRUE(base::WaitForSingleProcess(renderer_pid, | 124 EXPECT_TRUE(base::WaitForSingleProcess(renderer_pid, |
108 TestTimeouts::action_timeout_ms())); | 125 TestTimeouts::action_timeout_ms())); |
109 } | 126 } |
110 #endif // defined(OS_POSIX) | 127 #endif // defined(OS_POSIX) |
OLD | NEW |