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 | 4 |
5 #ifndef PPAPI_PROXY_RESOURCE_MESSAGE_TEST_SINK_H_ | 5 #ifndef PPAPI_PROXY_RESOURCE_MESSAGE_TEST_SINK_H_ |
6 #define PPAPI_PROXY_RESOURCE_MESSAGE_TEST_SINK_H_ | 6 #define PPAPI_PROXY_RESOURCE_MESSAGE_TEST_SINK_H_ |
7 | 7 |
8 #include "ipc/ipc_test_sink.h" | 8 #include "ipc/ipc_test_sink.h" |
9 | 9 |
10 namespace ppapi { | 10 namespace ppapi { |
11 namespace proxy { | 11 namespace proxy { |
12 | 12 |
13 class ResourceMessageCallParams; | 13 class ResourceMessageCallParams; |
14 class ResourceMessageReplyParams; | 14 class ResourceMessageReplyParams; |
15 | 15 |
16 // Extends IPC::TestSink to add extra capabilities for searching for and | 16 // Extends IPC::TestSink to add extra capabilities for searching for and |
17 // decoding resource messages. | 17 // decoding resource messages. |
18 class ResourceMessageTestSink : public IPC::TestSink { | 18 class ResourceMessageTestSink : public IPC::TestSink { |
19 public: | 19 public: |
20 ResourceMessageTestSink(); | 20 ResourceMessageTestSink(); |
21 virtual ~ResourceMessageTestSink(); | 21 virtual ~ResourceMessageTestSink(); |
22 | 22 |
| 23 // IPC::TestSink. |
| 24 // Overridden to handle sync messages. |
| 25 virtual bool Send(IPC::Message* msg) OVERRIDE; |
| 26 |
| 27 // Sets the reply message that will be returned to the next sync message sent. |
| 28 // This test sink owns any reply messages passed into this method. |
| 29 void SetSyncReplyMessage(IPC::Message* reply_msg); |
| 30 |
23 // Searches the queue for the first resource call message with a nested | 31 // Searches the queue for the first resource call message with a nested |
24 // message matching the given ID. On success, returns true and populates the | 32 // message matching the given ID. On success, returns true and populates the |
25 // givem params and nested message. | 33 // givem params and nested message. |
26 bool GetFirstResourceCallMatching( | 34 bool GetFirstResourceCallMatching( |
27 uint32 id, | 35 uint32 id, |
28 ResourceMessageCallParams* params, | 36 ResourceMessageCallParams* params, |
29 IPC::Message* nested_msg) const; | 37 IPC::Message* nested_msg) const; |
30 | 38 |
31 // Like GetFirstResourceCallMatching except for replies. | 39 // Like GetFirstResourceCallMatching except for replies. |
32 bool GetFirstResourceReplyMatching( | 40 bool GetFirstResourceReplyMatching( |
33 uint32 id, | 41 uint32 id, |
34 ResourceMessageReplyParams* params, | 42 ResourceMessageReplyParams* params, |
35 IPC::Message* nested_msg); | 43 IPC::Message* nested_msg); |
| 44 |
| 45 private: |
| 46 scoped_ptr<IPC::Message> sync_reply_msg_; |
| 47 }; |
| 48 |
| 49 // This is a message handler which generates reply messages for synchronous |
| 50 // resource calls. This allows unit testing of the plugin side of resources |
| 51 // which send sync messages. If you want to reply to a sync message type named |
| 52 // |PpapiHostMsg_X_Y| with |PpapiPluginMsg_X_YReply| then usage would be as |
| 53 // follows (from within |PluginProxyTest|s): |
| 54 // |
| 55 // PpapiHostMsg_X_YReply my_reply; |
| 56 // ResourceSyncCallHandler handler(&sink(), |
| 57 // PpapiHostMsg_X_Y::ID, |
| 58 // PP_OK, |
| 59 // my_reply); |
| 60 // sink().AddFilter(&handler); |
| 61 // // Do stuff to send a sync message ... |
| 62 // // You can check handler.last_handled_msg() to ensure the correct message was |
| 63 // // handled. |
| 64 // sink().RemoveFilter(&handler); |
| 65 class ResourceSyncCallHandler : public IPC::Listener { |
| 66 public: |
| 67 ResourceSyncCallHandler(ResourceMessageTestSink* test_sink, |
| 68 uint32 incoming_type, |
| 69 int32_t result, |
| 70 const IPC::Message& reply_msg); |
| 71 virtual ~ResourceSyncCallHandler(); |
| 72 |
| 73 // IPC::Listener. |
| 74 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
| 75 |
| 76 IPC::Message last_handled_msg() { return last_handled_msg_; } |
| 77 |
| 78 private: |
| 79 ResourceMessageTestSink* test_sink_; |
| 80 uint32 incoming_type_; |
| 81 int32_t result_; |
| 82 IPC::Message reply_msg_; |
| 83 IPC::Message last_handled_msg_; |
36 }; | 84 }; |
37 | 85 |
38 } // namespace proxy | 86 } // namespace proxy |
39 } // namespace ppapi | 87 } // namespace ppapi |
40 | 88 |
41 #endif // PPAPI_PROXY_RESOURCE_MESSAGE_TEST_SINK_H_ | 89 #endif // PPAPI_PROXY_RESOURCE_MESSAGE_TEST_SINK_H_ |
OLD | NEW |