Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(66)

Side by Side Diff: ppapi/proxy/talk_resource_unittest.cc

Issue 16271005: Implement pepper interface and plumbing for HRD's UI on ChromeOS (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 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.
4
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"
10
11 namespace ppapi {
12 namespace proxy {
13
14 namespace {
15
16 typedef PluginProxyTest TalkResourceTest;
17
18 template <class ResultType>
19 class CallbackBase {
20 public:
21 CallbackBase() : called_(false) {
22 }
23
24 bool called() {
25 return called_;
26 }
27
28 ResultType result() {
29 return result_;
30 }
31
32 void Reset() {
33 called_ = false;
34 }
35
36 static void Callback(void* user_data, ResultType result) {
37 CallbackBase* that = reinterpret_cast<CallbackBase*>(user_data);
38 that->called_ = true;
39 that->result_ = result;
40 }
41
42 private:
43 bool called_;
44 ResultType result_;
45 };
46
47 typedef CallbackBase<int32_t> CompletionCallback;
48 typedef CallbackBase<PP_TalkEvent> TalkEventCallback;
49
50 } // namespace
51
52 TEST_F(TalkResourceTest, GetPermission) {
53 const PPB_Talk_Private_1_0* talk = thunk::GetPPB_Talk_Private_1_0_Thunk();
54 LockingResourceReleaser res(talk->Create(pp_instance()));
55 CompletionCallback callback;
56
57 int32_t result = talk->GetPermission(
58 res.get(),
59 PP_MakeCompletionCallback(&CompletionCallback::Callback, &callback));
60 ASSERT_EQ(PP_OK_COMPLETIONPENDING, result);
61
62 ResourceMessageCallParams params;
63 IPC::Message msg;
64 ASSERT_TRUE(sink().GetFirstResourceCallMatching(
65 PpapiHostMsg_Talk_GetPermission::ID, &params, &msg));
66
67 ResourceMessageReplyParams reply_params(params.pp_resource(),
68 params.sequence());
69 reply_params.set_result(1);
70 IPC::Message reply = PpapiPluginMsg_ResourceReply(
71 reply_params, PpapiPluginMsg_Talk_GetPermissionReply());
72 ASSERT_TRUE(plugin_dispatcher()->OnMessageReceived(reply));
73
74 ASSERT_TRUE(callback.called());
75 ASSERT_EQ(1, callback.result());
76 }
77
78 TEST_F(TalkResourceTest, GetRemotingPermission) {
79 const PPB_Talk_Private_2_0* talk = thunk::GetPPB_Talk_Private_2_0_Thunk();
80 LockingResourceReleaser res(talk->Create(pp_instance()));
81 CompletionCallback callback;
82
83 int32_t result = talk->GetRemotingPermission(
84 res.get(),
85 PP_MakeCompletionCallback(&CompletionCallback::Callback, &callback));
86 ASSERT_EQ(PP_OK_COMPLETIONPENDING, result);
87
88 ResourceMessageCallParams params;
89 IPC::Message msg;
90 ASSERT_TRUE(sink().GetFirstResourceCallMatching(
91 PpapiHostMsg_Talk_GetRemotingPermission::ID, &params, &msg));
92
93 ResourceMessageReplyParams reply_params(params.pp_resource(),
94 params.sequence());
95 reply_params.set_result(1);
96 IPC::Message reply = PpapiPluginMsg_ResourceReply(
97 reply_params, PpapiPluginMsg_Talk_GetRemotingPermissionReply());
98 ASSERT_TRUE(plugin_dispatcher()->OnMessageReceived(reply));
99
100 ASSERT_TRUE(callback.called());
101 ASSERT_EQ(1, callback.result());
102 }
103
104 TEST_F(TalkResourceTest, GetRemotingContinuePermission) {
105 const PPB_Talk_Private_2_0* talk = thunk::GetPPB_Talk_Private_2_0_Thunk();
106 LockingResourceReleaser res(talk->Create(pp_instance()));
107 CompletionCallback callback;
108
109 int32_t result = talk->GetRemotingContinuePermission(
110 res.get(),
111 PP_MakeCompletionCallback(&CompletionCallback::Callback, &callback));
112 ASSERT_EQ(PP_OK_COMPLETIONPENDING, result);
113
114 ResourceMessageCallParams params;
115 IPC::Message msg;
116 ASSERT_TRUE(sink().GetFirstResourceCallMatching(
117 PpapiHostMsg_Talk_GetRemotingContinuePermission::ID, &params, &msg));
118
119 ResourceMessageReplyParams reply_params(params.pp_resource(),
120 params.sequence());
121 reply_params.set_result(1);
122 IPC::Message reply = PpapiPluginMsg_ResourceReply(
123 reply_params, PpapiPluginMsg_Talk_GetRemotingContinuePermissionReply());
124 ASSERT_TRUE(plugin_dispatcher()->OnMessageReceived(reply));
125
126 ASSERT_TRUE(callback.called());
127 ASSERT_EQ(1, callback.result());
128 }
129
130 TEST_F(TalkResourceTest, StartStopRemoting) {
131 const PPB_Talk_Private_2_0* talk = thunk::GetPPB_Talk_Private_2_0_Thunk();
132 LockingResourceReleaser res(talk->Create(pp_instance()));
133 TalkEventCallback callback;
134
135 int32_t result = talk->StartRemoting(
136 res.get(), &TalkEventCallback::Callback, &callback);
137 ASSERT_EQ(PP_OK, result);
138
139 ResourceMessageCallParams params;
140 IPC::Message msg;
141 ASSERT_TRUE(sink().GetFirstResourceCallMatching(
142 PpapiHostMsg_Talk_StartRemoting::ID, &params, &msg));
143
144 ASSERT_FALSE(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(callback.called());
150 ASSERT_EQ(PP_TALKEVENT_ERROR, callback.result());
151
152 // Calling |StartRemoting()| again before |StopRemoting()| should fail.
153 result = talk->StartRemoting(
154 res.get(), &TalkEventCallback::Callback, &callback);
155 ASSERT_EQ(PP_ERROR_INPROGRESS, result);
156
157 talk->StopRemoting(res.get());
158
159 // Test idempotence.
160 callback.Reset();
161 result = talk->StartRemoting(
162 res.get(), &TalkEventCallback::Callback, &callback);
163 ASSERT_EQ(PP_OK, result);
164 ASSERT_TRUE(plugin_dispatcher()->OnMessageReceived(notify));
165 ASSERT_TRUE(callback.called());
166 ASSERT_EQ(PP_TALKEVENT_ERROR, callback.result());
167 }
168
169 } // namespace proxy
170 } // namespace ppapi
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698