OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // | |
5 // Unit test for SyncChannel. | |
6 | 4 |
7 #include "ipc/ipc_sync_channel.h" | 5 #include "ipc/ipc_sync_channel.h" |
8 | 6 |
9 #include <string> | 7 #include <string> |
10 #include <vector> | 8 #include <vector> |
11 | 9 |
12 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
13 #include "base/bind.h" | 11 #include "base/bind.h" |
14 #include "base/logging.h" | 12 #include "base/logging.h" |
15 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
16 #include "base/message_loop.h" | 14 #include "base/message_loop.h" |
17 #include "base/process_util.h" | 15 #include "base/process_util.h" |
| 16 #include "base/run_loop.h" |
18 #include "base/string_util.h" | 17 #include "base/string_util.h" |
19 #include "base/threading/platform_thread.h" | 18 #include "base/threading/platform_thread.h" |
20 #include "base/threading/thread.h" | 19 #include "base/threading/thread.h" |
21 #include "base/synchronization/waitable_event.h" | 20 #include "base/synchronization/waitable_event.h" |
22 #include "ipc/ipc_listener.h" | 21 #include "ipc/ipc_listener.h" |
23 #include "ipc/ipc_message.h" | 22 #include "ipc/ipc_message.h" |
24 #include "ipc/ipc_sender.h" | 23 #include "ipc/ipc_sender.h" |
25 #include "ipc/ipc_sync_message_filter.h" | 24 #include "ipc/ipc_sync_message_filter.h" |
26 #include "ipc/ipc_sync_message_unittest.h" | 25 #include "ipc/ipc_sync_message_unittest.h" |
27 #include "testing/gtest/include/gtest/gtest.h" | 26 #include "testing/gtest/include/gtest/gtest.h" |
28 | 27 |
29 using base::WaitableEvent; | 28 using base::WaitableEvent; |
30 using namespace IPC; | |
31 | 29 |
| 30 namespace IPC { |
32 namespace { | 31 namespace { |
33 | 32 |
34 // Base class for a "process" with listener and IPC threads. | 33 // Base class for a "process" with listener and IPC threads. |
35 class Worker : public Listener, public Sender { | 34 class Worker : public Listener, public Sender { |
36 public: | 35 public: |
37 // Will create a channel without a name. | 36 // Will create a channel without a name. |
38 Worker(Channel::Mode mode, const std::string& thread_name) | 37 Worker(Channel::Mode mode, const std::string& thread_name) |
39 : done_(new WaitableEvent(false, false)), | 38 : done_(new WaitableEvent(false, false)), |
40 channel_created_(new WaitableEvent(false, false)), | 39 channel_created_(new WaitableEvent(false, false)), |
41 mode_(mode), | 40 mode_(mode), |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 channel_.reset(CreateChannel()); | 173 channel_.reset(CreateChannel()); |
175 channel_created_->Signal(); | 174 channel_created_->Signal(); |
176 Run(); | 175 Run(); |
177 } | 176 } |
178 | 177 |
179 void OnListenerThreadShutdown1(WaitableEvent* listener_event, | 178 void OnListenerThreadShutdown1(WaitableEvent* listener_event, |
180 WaitableEvent* ipc_event) { | 179 WaitableEvent* ipc_event) { |
181 // SyncChannel needs to be destructed on the thread that it was created on. | 180 // SyncChannel needs to be destructed on the thread that it was created on. |
182 channel_.reset(); | 181 channel_.reset(); |
183 | 182 |
184 MessageLoop::current()->RunUntilIdle(); | 183 base::RunLoop().RunUntilIdle(); |
185 | 184 |
186 ipc_thread_.message_loop()->PostTask( | 185 ipc_thread_.message_loop()->PostTask( |
187 FROM_HERE, base::Bind(&Worker::OnIPCThreadShutdown, this, | 186 FROM_HERE, base::Bind(&Worker::OnIPCThreadShutdown, this, |
188 listener_event, ipc_event)); | 187 listener_event, ipc_event)); |
189 } | 188 } |
190 | 189 |
191 void OnIPCThreadShutdown(WaitableEvent* listener_event, | 190 void OnIPCThreadShutdown(WaitableEvent* listener_event, |
192 WaitableEvent* ipc_event) { | 191 WaitableEvent* ipc_event) { |
193 MessageLoop::current()->RunUntilIdle(); | 192 base::RunLoop().RunUntilIdle(); |
194 ipc_event->Signal(); | 193 ipc_event->Signal(); |
195 | 194 |
196 listener_thread_.message_loop()->PostTask( | 195 listener_thread_.message_loop()->PostTask( |
197 FROM_HERE, base::Bind(&Worker::OnListenerThreadShutdown2, this, | 196 FROM_HERE, base::Bind(&Worker::OnListenerThreadShutdown2, this, |
198 listener_event)); | 197 listener_event)); |
199 } | 198 } |
200 | 199 |
201 void OnListenerThreadShutdown2(WaitableEvent* listener_event) { | 200 void OnListenerThreadShutdown2(WaitableEvent* listener_event) { |
202 MessageLoop::current()->RunUntilIdle(); | 201 base::RunLoop().RunUntilIdle(); |
203 listener_event->Signal(); | 202 listener_event->Signal(); |
204 } | 203 } |
205 | 204 |
206 virtual bool OnMessageReceived(const Message& message) OVERRIDE { | 205 virtual bool OnMessageReceived(const Message& message) OVERRIDE { |
207 IPC_BEGIN_MESSAGE_MAP(Worker, message) | 206 IPC_BEGIN_MESSAGE_MAP(Worker, message) |
208 IPC_MESSAGE_HANDLER_DELAY_REPLY(SyncChannelTestMsg_Double, OnDoubleDelay) | 207 IPC_MESSAGE_HANDLER_DELAY_REPLY(SyncChannelTestMsg_Double, OnDoubleDelay) |
209 IPC_MESSAGE_HANDLER_DELAY_REPLY(SyncChannelTestMsg_AnswerToLife, | 208 IPC_MESSAGE_HANDLER_DELAY_REPLY(SyncChannelTestMsg_AnswerToLife, |
210 OnAnswerDelay) | 209 OnAnswerDelay) |
211 IPC_MESSAGE_HANDLER_DELAY_REPLY(SyncChannelNestedTestMsg_String, | 210 IPC_MESSAGE_HANDLER_DELAY_REPLY(SyncChannelNestedTestMsg_String, |
212 OnNestedTestMsg) | 211 OnNestedTestMsg) |
(...skipping 1667 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1880 RunTest(workers); | 1879 RunTest(workers); |
1881 } | 1880 } |
1882 | 1881 |
1883 // Windows needs to send an out-of-band secret to verify the client end of the | 1882 // Windows needs to send an out-of-band secret to verify the client end of the |
1884 // channel. Test that we still connect correctly in that case. | 1883 // channel. Test that we still connect correctly in that case. |
1885 TEST_F(IPCSyncChannelTest, Verified) { | 1884 TEST_F(IPCSyncChannelTest, Verified) { |
1886 Verified(); | 1885 Verified(); |
1887 } | 1886 } |
1888 | 1887 |
1889 } // namespace | 1888 } // namespace |
| 1889 } // namespace IPC |
OLD | NEW |