| 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_listener.h" | 8 #include "ipc/ipc_listener.h" |
| 9 #include "ipc/ipc_test_sink.h" | 9 #include "ipc/ipc_test_sink.h" |
| 10 #include "ppapi/c/pp_stdint.h" | 10 #include "ppapi/c/pp_stdint.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 // Overridden to handle sync messages. | 27 // Overridden to handle sync messages. |
| 28 bool Send(IPC::Message* msg) override; | 28 bool Send(IPC::Message* msg) override; |
| 29 | 29 |
| 30 // Sets the reply message that will be returned to the next sync message sent. | 30 // Sets the reply message that will be returned to the next sync message sent. |
| 31 // This test sink owns any reply messages passed into this method. | 31 // This test sink owns any reply messages passed into this method. |
| 32 void SetSyncReplyMessage(IPC::Message* reply_msg); | 32 void SetSyncReplyMessage(IPC::Message* reply_msg); |
| 33 | 33 |
| 34 // Searches the queue for the first resource call message with a nested | 34 // Searches the queue for the first resource call message with a nested |
| 35 // message matching the given ID. On success, returns true and populates the | 35 // message matching the given ID. On success, returns true and populates the |
| 36 // given params and nested message. | 36 // given params and nested message. |
| 37 bool GetFirstResourceCallMatching( | 37 bool GetFirstResourceCallMatching(uint32_t id, |
| 38 uint32 id, | 38 ResourceMessageCallParams* params, |
| 39 ResourceMessageCallParams* params, | 39 IPC::Message* nested_msg) const; |
| 40 IPC::Message* nested_msg) const; | |
| 41 | 40 |
| 42 // Like GetFirstResourceCallMatching except for replies. | 41 // Like GetFirstResourceCallMatching except for replies. |
| 43 bool GetFirstResourceReplyMatching( | 42 bool GetFirstResourceReplyMatching(uint32_t id, |
| 44 uint32 id, | 43 ResourceMessageReplyParams* params, |
| 45 ResourceMessageReplyParams* params, | 44 IPC::Message* nested_msg); |
| 46 IPC::Message* nested_msg); | |
| 47 | 45 |
| 48 // Searches the queue for all resource call messages with a nested message | 46 // Searches the queue for all resource call messages with a nested message |
| 49 // matching the given ID. | 47 // matching the given ID. |
| 50 typedef std::pair<ResourceMessageCallParams, IPC::Message> ResourceCall; | 48 typedef std::pair<ResourceMessageCallParams, IPC::Message> ResourceCall; |
| 51 typedef std::vector<ResourceCall> ResourceCallVector; | 49 typedef std::vector<ResourceCall> ResourceCallVector; |
| 52 ResourceCallVector GetAllResourceCallsMatching(uint32 id); | 50 ResourceCallVector GetAllResourceCallsMatching(uint32_t id); |
| 53 | 51 |
| 54 // Like GetAllResourceCallsMatching except for replies. | 52 // Like GetAllResourceCallsMatching except for replies. |
| 55 typedef std::pair<ResourceMessageReplyParams, IPC::Message> ResourceReply; | 53 typedef std::pair<ResourceMessageReplyParams, IPC::Message> ResourceReply; |
| 56 typedef std::vector<ResourceReply> ResourceReplyVector; | 54 typedef std::vector<ResourceReply> ResourceReplyVector; |
| 57 ResourceReplyVector GetAllResourceRepliesMatching(uint32 id); | 55 ResourceReplyVector GetAllResourceRepliesMatching(uint32_t id); |
| 58 | 56 |
| 59 private: | 57 private: |
| 60 scoped_ptr<IPC::Message> sync_reply_msg_; | 58 scoped_ptr<IPC::Message> sync_reply_msg_; |
| 61 }; | 59 }; |
| 62 | 60 |
| 63 // This is a message handler which generates reply messages for synchronous | 61 // This is a message handler which generates reply messages for synchronous |
| 64 // resource calls. This allows unit testing of the plugin side of resources | 62 // resource calls. This allows unit testing of the plugin side of resources |
| 65 // which send sync messages. If you want to reply to a sync message type named | 63 // which send sync messages. If you want to reply to a sync message type named |
| 66 // |PpapiHostMsg_X_Y| with |PpapiPluginMsg_X_YReply| then usage would be as | 64 // |PpapiHostMsg_X_Y| with |PpapiPluginMsg_X_YReply| then usage would be as |
| 67 // follows (from within |PluginProxyTest|s): | 65 // follows (from within |PluginProxyTest|s): |
| 68 // | 66 // |
| 69 // PpapiHostMsg_X_YReply my_reply; | 67 // PpapiHostMsg_X_YReply my_reply; |
| 70 // ResourceSyncCallHandler handler(&sink(), | 68 // ResourceSyncCallHandler handler(&sink(), |
| 71 // PpapiHostMsg_X_Y::ID, | 69 // PpapiHostMsg_X_Y::ID, |
| 72 // PP_OK, | 70 // PP_OK, |
| 73 // my_reply); | 71 // my_reply); |
| 74 // sink().AddFilter(&handler); | 72 // sink().AddFilter(&handler); |
| 75 // // Do stuff to send a sync message ... | 73 // // Do stuff to send a sync message ... |
| 76 // // You can check handler.last_handled_msg() to ensure the correct message was | 74 // // You can check handler.last_handled_msg() to ensure the correct message was |
| 77 // // handled. | 75 // // handled. |
| 78 // sink().RemoveFilter(&handler); | 76 // sink().RemoveFilter(&handler); |
| 79 class ResourceSyncCallHandler : public IPC::Listener { | 77 class ResourceSyncCallHandler : public IPC::Listener { |
| 80 public: | 78 public: |
| 81 ResourceSyncCallHandler(ResourceMessageTestSink* test_sink, | 79 ResourceSyncCallHandler(ResourceMessageTestSink* test_sink, |
| 82 uint32 incoming_type, | 80 uint32_t incoming_type, |
| 83 int32_t result, | 81 int32_t result, |
| 84 const IPC::Message& reply_msg); | 82 const IPC::Message& reply_msg); |
| 85 ~ResourceSyncCallHandler() override; | 83 ~ResourceSyncCallHandler() override; |
| 86 | 84 |
| 87 // IPC::Listener. | 85 // IPC::Listener. |
| 88 bool OnMessageReceived(const IPC::Message& message) override; | 86 bool OnMessageReceived(const IPC::Message& message) override; |
| 89 | 87 |
| 90 IPC::Message last_handled_msg() { return last_handled_msg_; } | 88 IPC::Message last_handled_msg() { return last_handled_msg_; } |
| 91 | 89 |
| 92 // Sets a handle to be appended to the ReplyParams. The pointer is owned by | 90 // Sets a handle to be appended to the ReplyParams. The pointer is owned by |
| 93 // the caller. | 91 // the caller. |
| 94 void set_serialized_handle(const SerializedHandle* serialized_handle) { | 92 void set_serialized_handle(const SerializedHandle* serialized_handle) { |
| 95 serialized_handle_ = serialized_handle; | 93 serialized_handle_ = serialized_handle; |
| 96 } | 94 } |
| 97 | 95 |
| 98 private: | 96 private: |
| 99 ResourceMessageTestSink* test_sink_; | 97 ResourceMessageTestSink* test_sink_; |
| 100 uint32 incoming_type_; | 98 uint32_t incoming_type_; |
| 101 int32_t result_; | 99 int32_t result_; |
| 102 const SerializedHandle* serialized_handle_; // Non-owning pointer. | 100 const SerializedHandle* serialized_handle_; // Non-owning pointer. |
| 103 IPC::Message reply_msg_; | 101 IPC::Message reply_msg_; |
| 104 IPC::Message last_handled_msg_; | 102 IPC::Message last_handled_msg_; |
| 105 }; | 103 }; |
| 106 | 104 |
| 107 } // namespace proxy | 105 } // namespace proxy |
| 108 } // namespace ppapi | 106 } // namespace ppapi |
| 109 | 107 |
| 110 #endif // PPAPI_PROXY_RESOURCE_MESSAGE_TEST_SINK_H_ | 108 #endif // PPAPI_PROXY_RESOURCE_MESSAGE_TEST_SINK_H_ |
| OLD | NEW |