Use Persistent::Reset.
[chromium-blink-merge.git] / ppapi / proxy / resource_message_test_sink.h
blobcbbece3134dbeb2b236f74b259ea749b7db09ebe
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"
12 namespace ppapi {
13 namespace proxy {
15 class ResourceMessageCallParams;
16 class ResourceMessageReplyParams;
17 class SerializedHandle;
19 // Extends IPC::TestSink to add extra capabilities for searching for and
20 // decoding resource messages.
21 class ResourceMessageTestSink : public IPC::TestSink {
22 public:
23 ResourceMessageTestSink();
24 virtual ~ResourceMessageTestSink();
26 // IPC::TestSink.
27 // Overridden to handle sync messages.
28 virtual bool Send(IPC::Message* msg) OVERRIDE;
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.
32 void SetSyncReplyMessage(IPC::Message* reply_msg);
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
36 // givem params and nested message.
37 bool GetFirstResourceCallMatching(
38 uint32 id,
39 ResourceMessageCallParams* params,
40 IPC::Message* nested_msg) const;
42 // Like GetFirstResourceCallMatching except for replies.
43 bool GetFirstResourceReplyMatching(
44 uint32 id,
45 ResourceMessageReplyParams* params,
46 IPC::Message* nested_msg);
48 private:
49 scoped_ptr<IPC::Message> sync_reply_msg_;
52 // This is a message handler which generates reply messages for synchronous
53 // resource calls. This allows unit testing of the plugin side of resources
54 // which send sync messages. If you want to reply to a sync message type named
55 // |PpapiHostMsg_X_Y| with |PpapiPluginMsg_X_YReply| then usage would be as
56 // follows (from within |PluginProxyTest|s):
58 // PpapiHostMsg_X_YReply my_reply;
59 // ResourceSyncCallHandler handler(&sink(),
60 // PpapiHostMsg_X_Y::ID,
61 // PP_OK,
62 // my_reply);
63 // sink().AddFilter(&handler);
64 // // Do stuff to send a sync message ...
65 // // You can check handler.last_handled_msg() to ensure the correct message was
66 // // handled.
67 // sink().RemoveFilter(&handler);
68 class ResourceSyncCallHandler : public IPC::Listener {
69 public:
70 ResourceSyncCallHandler(ResourceMessageTestSink* test_sink,
71 uint32 incoming_type,
72 int32_t result,
73 const IPC::Message& reply_msg);
74 virtual ~ResourceSyncCallHandler();
76 // IPC::Listener.
77 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
79 IPC::Message last_handled_msg() { return last_handled_msg_; }
81 // Sets a handle to be appended to the ReplyParams. The pointer is owned by
82 // the caller.
83 void set_serialized_handle(const SerializedHandle* serialized_handle) {
84 serialized_handle_ = serialized_handle;
87 private:
88 ResourceMessageTestSink* test_sink_;
89 uint32 incoming_type_;
90 int32_t result_;
91 const SerializedHandle* serialized_handle_; // Non-owning pointer.
92 IPC::Message reply_msg_;
93 IPC::Message last_handled_msg_;
96 } // namespace proxy
97 } // namespace ppapi
99 #endif // PPAPI_PROXY_RESOURCE_MESSAGE_TEST_SINK_H_