Refactor android test results logging.
[chromium-blink-merge.git] / ppapi / proxy / resource_message_test_sink.h
blobf5f97cfb507b423f982b6211d653ac4d580d12f4
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;
18 // Extends IPC::TestSink to add extra capabilities for searching for and
19 // decoding resource messages.
20 class ResourceMessageTestSink : public IPC::TestSink {
21 public:
22 ResourceMessageTestSink();
23 virtual ~ResourceMessageTestSink();
25 // IPC::TestSink.
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(
37 uint32 id,
38 ResourceMessageCallParams* params,
39 IPC::Message* nested_msg) const;
41 // Like GetFirstResourceCallMatching except for replies.
42 bool GetFirstResourceReplyMatching(
43 uint32 id,
44 ResourceMessageReplyParams* params,
45 IPC::Message* nested_msg);
47 private:
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,
60 // PP_OK,
61 // my_reply);
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
65 // // handled.
66 // sink().RemoveFilter(&handler);
67 class ResourceSyncCallHandler : public IPC::Listener {
68 public:
69 ResourceSyncCallHandler(ResourceMessageTestSink* test_sink,
70 uint32 incoming_type,
71 int32_t result,
72 const IPC::Message& reply_msg);
73 virtual ~ResourceSyncCallHandler();
75 // IPC::Listener.
76 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
78 IPC::Message last_handled_msg() { return last_handled_msg_; }
80 private:
81 ResourceMessageTestSink* test_sink_;
82 uint32 incoming_type_;
83 int32_t result_;
84 IPC::Message reply_msg_;
85 IPC::Message last_handled_msg_;
88 } // namespace proxy
89 } // namespace ppapi
91 #endif // PPAPI_PROXY_RESOURCE_MESSAGE_TEST_SINK_H_