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