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

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: Implemented requested changes. 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;
dmichael (off chromium) 2013/06/05 21:02:13 Could you name this something else, to avoid confu
dcaiafa 2013/06/06 01:24:32 Done.
48 typedef CallbackBase<PP_TalkEvent> TalkEventCallback;
dmichael (off chromium) 2013/06/05 21:02:13 same prefix here might also be clearer
dcaiafa 2013/06/06 01:24:32 Done.
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_RequestPermission::ID, &params, &msg));
66 PpapiHostMsg_Talk_RequestPermission::Schema::Param args;
67 ASSERT_TRUE(PpapiHostMsg_Talk_RequestPermission::Schema::Read(&msg, &args));
68 ASSERT_EQ(PP_TALKPERMISSION_SCREENCAST, args.a);
69
70 ResourceMessageReplyParams reply_params(params.pp_resource(),
71 params.sequence());
72 reply_params.set_result(1);
73 IPC::Message reply = PpapiPluginMsg_ResourceReply(
74 reply_params, PpapiPluginMsg_Talk_RequestPermissionReply());
75 ASSERT_TRUE(plugin_dispatcher()->OnMessageReceived(reply));
76
77 ASSERT_TRUE(callback.called());
78 ASSERT_EQ(1, callback.result());
79 }
80
81 TEST_F(TalkResourceTest, RequestPermission) {
82 const PPB_Talk_Private_2_0* talk = thunk::GetPPB_Talk_Private_2_0_Thunk();
83 LockingResourceReleaser res(talk->Create(pp_instance()));
84 CompletionCallback callback;
85
86 int32_t result = talk->RequestPermission(
87 res.get(),
88 PP_TALKPERMISSION_REMOTING_CONTINUE,
89 PP_MakeCompletionCallback(&CompletionCallback::Callback, &callback));
90 ASSERT_EQ(PP_OK_COMPLETIONPENDING, result);
91
92 ResourceMessageCallParams params;
93 IPC::Message msg;
94 ASSERT_TRUE(sink().GetFirstResourceCallMatching(
95 PpapiHostMsg_Talk_RequestPermission::ID, &params, &msg));
96 PpapiHostMsg_Talk_RequestPermission::Schema::Param args;
97 ASSERT_TRUE(PpapiHostMsg_Talk_RequestPermission::Schema::Read(&msg, &args));
98 ASSERT_EQ(PP_TALKPERMISSION_REMOTING_CONTINUE, args.a);
99
100 ResourceMessageReplyParams reply_params(params.pp_resource(),
101 params.sequence());
102 reply_params.set_result(1);
103 IPC::Message reply = PpapiPluginMsg_ResourceReply(
104 reply_params, PpapiPluginMsg_Talk_RequestPermissionReply());
105 ASSERT_TRUE(plugin_dispatcher()->OnMessageReceived(reply));
106
107 ASSERT_TRUE(callback.called());
108 ASSERT_EQ(1, callback.result());
109 }
110
111 TEST_F(TalkResourceTest, StartStopRemoting) {
112 const PPB_Talk_Private_2_0* talk = thunk::GetPPB_Talk_Private_2_0_Thunk();
113 LockingResourceReleaser res(talk->Create(pp_instance()));
114 TalkEventCallback callback;
115
116 int32_t result = talk->StartRemoting(
117 res.get(), &TalkEventCallback::Callback, &callback);
118 ASSERT_EQ(PP_OK, result);
119
120 ResourceMessageCallParams params;
121 IPC::Message msg;
122 ASSERT_TRUE(sink().GetFirstResourceCallMatching(
123 PpapiHostMsg_Talk_StartRemoting::ID, &params, &msg));
124
125 ASSERT_FALSE(callback.called());
126 ResourceMessageReplyParams notify_params(res.get(), 0);
127 IPC::Message notify = PpapiPluginMsg_ResourceReply(
128 notify_params, PpapiPluginMsg_Talk_NotifyEvent(PP_TALKEVENT_ERROR));
129 ASSERT_TRUE(plugin_dispatcher()->OnMessageReceived(notify));
130 ASSERT_TRUE(callback.called());
131 ASSERT_EQ(PP_TALKEVENT_ERROR, callback.result());
132
133 // Calling |StartRemoting()| again before |StopRemoting()| should fail.
134 result = talk->StartRemoting(
135 res.get(), &TalkEventCallback::Callback, &callback);
136 ASSERT_EQ(PP_ERROR_INPROGRESS, result);
137
138 talk->StopRemoting(res.get());
139
140 // Test idempotence.
141 callback.Reset();
142 result = talk->StartRemoting(
143 res.get(), &TalkEventCallback::Callback, &callback);
144 ASSERT_EQ(PP_OK, result);
145 ASSERT_TRUE(plugin_dispatcher()->OnMessageReceived(notify));
146 ASSERT_TRUE(callback.called());
147 ASSERT_EQ(PP_TALKEVENT_ERROR, callback.result());
148 }
149
150 } // namespace proxy
151 } // namespace ppapi
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698