OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "ipc/mojo/ipc_channel_mojo.h" | 5 #include "ipc/mojo/ipc_channel_mojo.h" |
6 | 6 |
7 #include "base/base_paths.h" | 7 #include "base/base_paths.h" |
8 #include "base/files/file.h" | 8 #include "base/files/file.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
11 #include "base/pickle.h" | 11 #include "base/pickle.h" |
12 #include "base/threading/thread.h" | 12 #include "base/threading/thread.h" |
13 #include "ipc/ipc_message.h" | 13 #include "ipc/ipc_message.h" |
14 #include "ipc/ipc_test_base.h" | 14 #include "ipc/ipc_test_base.h" |
15 #include "ipc/ipc_test_channel_listener.h" | 15 #include "ipc/ipc_test_channel_listener.h" |
16 | 16 |
17 #if defined(OS_POSIX) | 17 #if defined(OS_POSIX) |
18 #include "base/file_descriptor_posix.h" | 18 #include "base/file_descriptor_posix.h" |
19 #endif | 19 #endif |
20 | 20 |
21 namespace { | 21 namespace { |
22 | 22 |
23 class ListenerThatExpectsOK : public IPC::Listener { | 23 class ListenerThatExpectsOK : public IPC::Listener { |
24 public: | 24 public: |
25 ListenerThatExpectsOK() {} | 25 ListenerThatExpectsOK() |
| 26 : received_ok_(false) {} |
26 | 27 |
27 virtual ~ListenerThatExpectsOK() {} | 28 virtual ~ListenerThatExpectsOK() {} |
28 | 29 |
29 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE { | 30 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE { |
30 PickleIterator iter(message); | 31 PickleIterator iter(message); |
31 std::string should_be_ok; | 32 std::string should_be_ok; |
32 EXPECT_TRUE(iter.ReadString(&should_be_ok)); | 33 EXPECT_TRUE(iter.ReadString(&should_be_ok)); |
33 EXPECT_EQ(should_be_ok, "OK"); | 34 EXPECT_EQ(should_be_ok, "OK"); |
| 35 received_ok_ = true; |
34 base::MessageLoop::current()->Quit(); | 36 base::MessageLoop::current()->Quit(); |
35 return true; | 37 return true; |
36 } | 38 } |
37 | 39 |
38 virtual void OnChannelError() OVERRIDE { | 40 virtual void OnChannelError() OVERRIDE { |
39 NOTREACHED(); | 41 // The connection should be healthy while the listener is waiting |
| 42 // message. An error can occur after that because the peer |
| 43 // process dies. |
| 44 DCHECK(received_ok_); |
40 } | 45 } |
41 | 46 |
42 static void SendOK(IPC::Sender* sender) { | 47 static void SendOK(IPC::Sender* sender) { |
43 IPC::Message* message = new IPC::Message( | 48 IPC::Message* message = new IPC::Message( |
44 0, 2, IPC::Message::PRIORITY_NORMAL); | 49 0, 2, IPC::Message::PRIORITY_NORMAL); |
45 message->WriteString(std::string("OK")); | 50 message->WriteString(std::string("OK")); |
46 ASSERT_TRUE(sender->Send(message)); | 51 ASSERT_TRUE(sender->Send(message)); |
47 } | 52 } |
| 53 |
| 54 private: |
| 55 bool received_ok_; |
48 }; | 56 }; |
49 | 57 |
50 class ListenerThatShouldBeNeverCalled : public IPC::Listener { | 58 class ListenerThatShouldBeNeverCalled : public IPC::Listener { |
51 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE { | 59 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE { |
52 NOTREACHED(); | 60 NOTREACHED(); |
53 return true; | 61 return true; |
54 } | 62 } |
55 | 63 |
56 virtual void OnChannelError() OVERRIDE { | 64 virtual void OnChannelError() OVERRIDE { |
57 NOTREACHED(); | 65 NOTREACHED(); |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 client.Connect(); | 259 client.Connect(); |
252 listener.set_sender(client.channel()); | 260 listener.set_sender(client.channel()); |
253 | 261 |
254 base::MessageLoop::current()->Run(); | 262 base::MessageLoop::current()->Run(); |
255 | 263 |
256 return 0; | 264 return 0; |
257 } | 265 } |
258 #endif | 266 #endif |
259 | 267 |
260 } // namespace | 268 } // namespace |
OLD | NEW |