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
3 // found in the LICENSE file.
5 #ifndef PPAPI_PROXY_RESOURCE_MESSAGE_TEST_SINK_H_
6 #define PPAPI_PROXY_RESOURCE_MESSAGE_TEST_SINK_H_
8 #include "ipc/ipc_listener.h"
9 #include "ipc/ipc_test_sink.h"
10 #include "ppapi/c/pp_stdint.h"
15 class ResourceMessageCallParams
;
16 class ResourceMessageReplyParams
;
18 // Extends IPC::TestSink to add extra capabilities for searching for and
19 // decoding resource messages.
20 class ResourceMessageTestSink
: public IPC::TestSink
{
22 ResourceMessageTestSink();
23 virtual ~ResourceMessageTestSink();
26 // Overridden to handle sync messages.
27 virtual bool Send(IPC::Message
* msg
) OVERRIDE
;
29 // Sets the reply message that will be returned to the next sync message sent.
30 // This test sink owns any reply messages passed into this method.
31 void SetSyncReplyMessage(IPC::Message
* reply_msg
);
33 // Searches the queue for the first resource call message with a nested
34 // message matching the given ID. On success, returns true and populates the
35 // givem params and nested message.
36 bool GetFirstResourceCallMatching(
38 ResourceMessageCallParams
* params
,
39 IPC::Message
* nested_msg
) const;
41 // Like GetFirstResourceCallMatching except for replies.
42 bool GetFirstResourceReplyMatching(
44 ResourceMessageReplyParams
* params
,
45 IPC::Message
* nested_msg
);
48 scoped_ptr
<IPC::Message
> sync_reply_msg_
;
51 // This is a message handler which generates reply messages for synchronous
52 // resource calls. This allows unit testing of the plugin side of resources
53 // which send sync messages. If you want to reply to a sync message type named
54 // |PpapiHostMsg_X_Y| with |PpapiPluginMsg_X_YReply| then usage would be as
55 // follows (from within |PluginProxyTest|s):
57 // PpapiHostMsg_X_YReply my_reply;
58 // ResourceSyncCallHandler handler(&sink(),
59 // PpapiHostMsg_X_Y::ID,
62 // sink().AddFilter(&handler);
63 // // Do stuff to send a sync message ...
64 // // You can check handler.last_handled_msg() to ensure the correct message was
66 // sink().RemoveFilter(&handler);
67 class ResourceSyncCallHandler
: public IPC::Listener
{
69 ResourceSyncCallHandler(ResourceMessageTestSink
* test_sink
,
72 const IPC::Message
& reply_msg
);
73 virtual ~ResourceSyncCallHandler();
76 virtual bool OnMessageReceived(const IPC::Message
& message
) OVERRIDE
;
78 IPC::Message
last_handled_msg() { return last_handled_msg_
; }
81 ResourceMessageTestSink
* test_sink_
;
82 uint32 incoming_type_
;
84 IPC::Message reply_msg_
;
85 IPC::Message last_handled_msg_
;
91 #endif // PPAPI_PROXY_RESOURCE_MESSAGE_TEST_SINK_H_