| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #ifndef IPC_IPC_TEST_SINK_H_ | 5 #ifndef IPC_IPC_TEST_SINK_H_ |
| 6 #define IPC_IPC_TEST_SINK_H_ | 6 #define IPC_IPC_TEST_SINK_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <utility> | 9 #include <utility> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 // // this: IPC_MESSAGE_ROUTED2(ViewMsg_Foo, bool, int) | 35 // // this: IPC_MESSAGE_ROUTED2(ViewMsg_Foo, bool, int) |
| 36 // IPC::Message* msg = test_sink.GetFirstMessageMatching(ViewMsg_Foo::ID)); | 36 // IPC::Message* msg = test_sink.GetFirstMessageMatching(ViewMsg_Foo::ID)); |
| 37 // ASSERT_TRUE(msg); | 37 // ASSERT_TRUE(msg); |
| 38 // bool first_param; | 38 // bool first_param; |
| 39 // int second_param; | 39 // int second_param; |
| 40 // ViewMsg_Foo::Read(msg, &first_param, &second_param); | 40 // ViewMsg_Foo::Read(msg, &first_param, &second_param); |
| 41 // | 41 // |
| 42 // // Go on to the next phase of the test. | 42 // // Go on to the next phase of the test. |
| 43 // test_sink.ClearMessages(); | 43 // test_sink.ClearMessages(); |
| 44 // | 44 // |
| 45 // To read a sync reply, do this: |
| 46 // |
| 47 // IPC::Message* msg = test_sink.GetUniqueMessageMatching(IPC_REPLY_ID); |
| 48 // ASSERT_TRUE(msg); |
| 49 // TupleTypes<ViewHostMsg_Foo::ReplyParam>::ValueType reply_data; |
| 50 // EXPECT_TRUE(ViewHostMsg_Foo::ReadReplyParam(msg, &reply_data)); |
| 51 // |
| 45 // You can also register to be notified when messages are posted to the sink. | 52 // You can also register to be notified when messages are posted to the sink. |
| 46 // This can be useful if you need to wait for a particular message that will | 53 // This can be useful if you need to wait for a particular message that will |
| 47 // be posted asynchronously. Example usage: | 54 // be posted asynchronously. Example usage: |
| 48 // | 55 // |
| 49 // class MyListener : public IPC::Channel::Listener { | 56 // class MyListener : public IPC::Channel::Listener { |
| 50 // public: | 57 // public: |
| 51 // virtual bool OnMessageReceived(const IPC::Message& msg) { | 58 // virtual bool OnMessageReceived(const IPC::Message& msg) { |
| 52 // <do something with the message> | 59 // <do something with the message> |
| 53 // MessageLoop::current()->Quit(); | 60 // MessageLoop::current()->Quit(); |
| 54 // return false; // to store the message in the sink, or true to drop it | 61 // return false; // to store the message in the sink, or true to drop it |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 // The actual list of received messages. | 121 // The actual list of received messages. |
| 115 std::vector<Message> messages_; | 122 std::vector<Message> messages_; |
| 116 ObserverList<Channel::Listener> filter_list_; | 123 ObserverList<Channel::Listener> filter_list_; |
| 117 | 124 |
| 118 DISALLOW_COPY_AND_ASSIGN(TestSink); | 125 DISALLOW_COPY_AND_ASSIGN(TestSink); |
| 119 }; | 126 }; |
| 120 | 127 |
| 121 } // namespace IPC | 128 } // namespace IPC |
| 122 | 129 |
| 123 #endif // IPC_IPC_TEST_SINK_H_ | 130 #endif // IPC_IPC_TEST_SINK_H_ |
| OLD | NEW |