cc: Added inline to Tile::IsReadyToDraw
[chromium-blink-merge.git] / ppapi / proxy / talk_resource_unittest.cc
blobe81a8a6aca35f9e4d9eced36358c3df8d45a5bbb
1 // Copyright 2013 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 #include "ppapi/proxy/locking_resource_releaser.h"
6 #include "ppapi/proxy/ppapi_messages.h"
7 #include "ppapi/proxy/ppapi_proxy_test.h"
8 #include "ppapi/proxy/talk_resource.h"
9 #include "ppapi/thunk/thunk.h"
11 namespace ppapi {
12 namespace proxy {
14 namespace {
16 template <class ResultType>
17 class MockCallbackBase {
18 public:
19 MockCallbackBase() : called_(false) {
22 bool called() {
23 return called_;
26 ResultType result() {
27 return result_;
30 void Reset() {
31 called_ = false;
34 static void Callback(void* user_data, ResultType result) {
35 MockCallbackBase* that = reinterpret_cast<MockCallbackBase*>(user_data);
36 that->called_ = true;
37 that->result_ = result;
40 private:
41 bool called_;
42 ResultType result_;
45 typedef MockCallbackBase<int32_t> MockCompletionCallback;
46 typedef MockCallbackBase<PP_TalkEvent> TalkEventCallback;
48 class TalkResourceTest : public PluginProxyTest {
49 public:
50 void SendReply(
51 uint32_t id,
52 const IPC::Message& reply,
53 int32_t result) {
54 IPC::Message msg;
55 ResourceMessageCallParams params;
56 ASSERT_TRUE(sink().GetFirstResourceCallMatching(id, &params, &msg));
58 ResourceMessageReplyParams reply_params(params.pp_resource(),
59 params.sequence());
60 reply_params.set_result(result);
61 IPC::Message reply_msg = PpapiPluginMsg_ResourceReply(reply_params, reply);
62 ASSERT_TRUE(plugin_dispatcher()->OnMessageReceived(reply_msg));
67 } // namespace
69 TEST_F(TalkResourceTest, GetPermission) {
70 const PPB_Talk_Private_1_0* talk = thunk::GetPPB_Talk_Private_1_0_Thunk();
71 LockingResourceReleaser res(talk->Create(pp_instance()));
72 MockCompletionCallback callback;
74 int32_t result = talk->GetPermission(
75 res.get(),
76 PP_MakeCompletionCallback(&MockCompletionCallback::Callback, &callback));
77 ASSERT_EQ(PP_OK_COMPLETIONPENDING, result);
79 ResourceMessageCallParams params;
80 IPC::Message msg;
81 ASSERT_TRUE(sink().GetFirstResourceCallMatching(
82 PpapiHostMsg_Talk_RequestPermission::ID, &params, &msg));
84 ResourceMessageReplyParams reply_params(params.pp_resource(),
85 params.sequence());
86 reply_params.set_result(1);
87 IPC::Message reply = PpapiPluginMsg_ResourceReply(
88 reply_params, PpapiPluginMsg_Talk_RequestPermissionReply());
89 ASSERT_TRUE(plugin_dispatcher()->OnMessageReceived(reply));
91 ASSERT_TRUE(callback.called());
92 ASSERT_EQ(1, callback.result());
95 TEST_F(TalkResourceTest, RequestPermission) {
96 const PPB_Talk_Private_2_0* talk = thunk::GetPPB_Talk_Private_2_0_Thunk();
97 LockingResourceReleaser res(talk->Create(pp_instance()));
98 MockCompletionCallback callback;
100 int32_t result = talk->RequestPermission(
101 res.get(),
102 PP_TALKPERMISSION_REMOTING_CONTINUE,
103 PP_MakeCompletionCallback(&MockCompletionCallback::Callback, &callback));
104 ASSERT_EQ(PP_OK_COMPLETIONPENDING, result);
106 ResourceMessageCallParams params;
107 IPC::Message msg;
108 ASSERT_TRUE(sink().GetFirstResourceCallMatching(
109 PpapiHostMsg_Talk_RequestPermission::ID, &params, &msg));
111 ResourceMessageReplyParams reply_params(params.pp_resource(),
112 params.sequence());
113 reply_params.set_result(1);
114 IPC::Message reply = PpapiPluginMsg_ResourceReply(
115 reply_params, PpapiPluginMsg_Talk_RequestPermissionReply());
116 ASSERT_TRUE(plugin_dispatcher()->OnMessageReceived(reply));
118 ASSERT_TRUE(callback.called());
119 ASSERT_EQ(1, callback.result());
122 TEST_F(TalkResourceTest, StartStopRemoting) {
123 const PPB_Talk_Private_2_0* talk = thunk::GetPPB_Talk_Private_2_0_Thunk();
124 LockingResourceReleaser res(talk->Create(pp_instance()));
125 MockCompletionCallback callback;
126 TalkEventCallback event_callback;
128 // Start
129 int32_t result = talk->StartRemoting(
130 res.get(),
131 &TalkEventCallback::Callback,
132 &event_callback,
133 PP_MakeCompletionCallback(&MockCompletionCallback::Callback, &callback));
134 ASSERT_EQ(PP_OK_COMPLETIONPENDING, result);
136 SendReply(PpapiHostMsg_Talk_StartRemoting::ID,
137 PpapiPluginMsg_Talk_StartRemotingReply(),
138 PP_OK);
140 ASSERT_TRUE(callback.called());
141 ASSERT_EQ(PP_OK, callback.result());
143 // Receive an event
144 ASSERT_FALSE(event_callback.called());
145 ResourceMessageReplyParams notify_params(res.get(), 0);
146 IPC::Message notify = PpapiPluginMsg_ResourceReply(
147 notify_params, PpapiPluginMsg_Talk_NotifyEvent(PP_TALKEVENT_ERROR));
148 ASSERT_TRUE(plugin_dispatcher()->OnMessageReceived(notify));
149 ASSERT_TRUE(event_callback.called());
150 ASSERT_EQ(PP_TALKEVENT_ERROR, event_callback.result());
152 // Stop
153 callback.Reset();
154 result = talk->StopRemoting(
155 res.get(),
156 PP_MakeCompletionCallback(&MockCompletionCallback::Callback, &callback));
157 ASSERT_EQ(PP_OK_COMPLETIONPENDING, result);
159 SendReply(PpapiHostMsg_Talk_StopRemoting::ID,
160 PpapiPluginMsg_Talk_StopRemotingReply(),
161 PP_OK);
163 ASSERT_TRUE(callback.called());
164 ASSERT_EQ(PP_OK, callback.result());
166 // Events should be discarded at this point
167 event_callback.Reset();
168 ASSERT_TRUE(plugin_dispatcher()->OnMessageReceived(notify));
169 ASSERT_FALSE(event_callback.called());
172 } // namespace proxy
173 } // namespace ppapi