Chromium Code Reviews| Index: ppapi/proxy/talk_resource_unittest.cc |
| diff --git a/ppapi/proxy/talk_resource_unittest.cc b/ppapi/proxy/talk_resource_unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..e3e108a8ceda324da842689464f28bfd694c46a9 |
| --- /dev/null |
| +++ b/ppapi/proxy/talk_resource_unittest.cc |
| @@ -0,0 +1,151 @@ |
| +// Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "ppapi/proxy/locking_resource_releaser.h" |
| +#include "ppapi/proxy/ppapi_messages.h" |
| +#include "ppapi/proxy/ppapi_proxy_test.h" |
| +#include "ppapi/proxy/talk_resource.h" |
| +#include "ppapi/thunk/thunk.h" |
| + |
| +namespace ppapi { |
| +namespace proxy { |
| + |
| +namespace { |
| + |
| +typedef PluginProxyTest TalkResourceTest; |
| + |
| +template <class ResultType> |
| +class CallbackBase { |
| + public: |
| + CallbackBase() : called_(false) { |
| + } |
| + |
| + bool called() { |
| + return called_; |
| + } |
| + |
| + ResultType result() { |
| + return result_; |
| + } |
| + |
| + void Reset() { |
| + called_ = false; |
| + } |
| + |
| + static void Callback(void* user_data, ResultType result) { |
| + CallbackBase* that = reinterpret_cast<CallbackBase*>(user_data); |
| + that->called_ = true; |
| + that->result_ = result; |
| + } |
| + |
| + private: |
| + bool called_; |
| + ResultType result_; |
| +}; |
| + |
| +typedef CallbackBase<int32_t> CompletionCallback; |
| +typedef CallbackBase<PP_TalkEvent> TalkEventCallback; |
| + |
| +} // namespace |
| + |
| +TEST_F(TalkResourceTest, GetPermission) { |
| + const PPB_Talk_Private_1_0* talk = thunk::GetPPB_Talk_Private_1_0_Thunk(); |
| + LockingResourceReleaser res(talk->Create(pp_instance())); |
| + CompletionCallback callback; |
| + |
| + int32_t result = talk->GetPermission( |
| + res.get(), |
| + PP_MakeCompletionCallback(&CompletionCallback::Callback, &callback)); |
| + ASSERT_EQ(PP_OK_COMPLETIONPENDING, result); |
| + |
| + ResourceMessageCallParams params; |
| + IPC::Message msg; |
| + ASSERT_TRUE(sink().GetFirstResourceCallMatching( |
| + PpapiHostMsg_Talk_RequestPermission::ID, ¶ms, &msg)); |
| + PpapiHostMsg_Talk_RequestPermission::Schema::Param args; |
| + ASSERT_TRUE(PpapiHostMsg_Talk_RequestPermission::Schema::Read(&msg, &args)); |
| + ASSERT_EQ(PP_TALKPERMISSION_SCREENCAST, args.a); |
| + |
| + ResourceMessageReplyParams reply_params(params.pp_resource(), |
| + params.sequence()); |
| + reply_params.set_result(1); |
| + IPC::Message reply = PpapiPluginMsg_ResourceReply( |
| + reply_params, PpapiPluginMsg_Talk_RequestPermissionReply()); |
| + ASSERT_TRUE(plugin_dispatcher()->OnMessageReceived(reply)); |
| + |
| + ASSERT_TRUE(callback.called()); |
| + ASSERT_EQ(1, callback.result()); |
| +} |
| + |
| +TEST_F(TalkResourceTest, RequestPermission) { |
| + const PPB_Talk_Private_2_0* talk = thunk::GetPPB_Talk_Private_2_0_Thunk(); |
| + LockingResourceReleaser res(talk->Create(pp_instance())); |
| + CompletionCallback callback; |
| + |
| + int32_t result = talk->RequestPermission( |
| + res.get(), |
| + PP_TALKPERMISSION_REMOTING, |
| + PP_MakeCompletionCallback(&CompletionCallback::Callback, &callback)); |
| + ASSERT_EQ(PP_OK_COMPLETIONPENDING, result); |
| + |
| + ResourceMessageCallParams params; |
| + IPC::Message msg; |
| + ASSERT_TRUE(sink().GetFirstResourceCallMatching( |
| + PpapiHostMsg_Talk_RequestPermission::ID, ¶ms, &msg)); |
| + PpapiHostMsg_Talk_RequestPermission::Schema::Param args; |
| + ASSERT_TRUE(PpapiHostMsg_Talk_RequestPermission::Schema::Read(&msg, &args)); |
| + ASSERT_EQ(PP_TALKPERMISSION_REMOTING, args.a); |
| + |
| + ResourceMessageReplyParams reply_params(params.pp_resource(), |
| + params.sequence()); |
| + reply_params.set_result(1); |
| + IPC::Message reply = PpapiPluginMsg_ResourceReply( |
| + reply_params, PpapiPluginMsg_Talk_RequestPermissionReply()); |
| + ASSERT_TRUE(plugin_dispatcher()->OnMessageReceived(reply)); |
| + |
| + ASSERT_TRUE(callback.called()); |
| + ASSERT_EQ(1, callback.result()); |
|
Josh Horwich
2013/06/04 19:48:37
Please add a test to verify RequestPermission(..,
dcaiafa
2013/06/04 22:38:15
Parameter check is currently done in the host (tes
Josh Horwich
2013/06/04 22:50:09
Ah, got it, thank you for clarifying. Things are n
|
| +} |
|
Josh Horwich
2013/06/04 19:48:37
Should add a test to RequestPermission with a bogu
dcaiafa
2013/06/04 22:38:15
See previous comment.
On 2013/06/04 19:48:37, Jos
Josh Horwich
2013/06/04 22:50:09
Oops, I had originally entered this into coderevie
|
| + |
| +TEST_F(TalkResourceTest, StartStopRemoting) { |
| + const PPB_Talk_Private_2_0* talk = thunk::GetPPB_Talk_Private_2_0_Thunk(); |
| + LockingResourceReleaser res(talk->Create(pp_instance())); |
| + TalkEventCallback callback; |
| + |
| + int32_t result = talk->StartRemoting( |
| + res.get(), &TalkEventCallback::Callback, &callback); |
| + ASSERT_EQ(PP_OK, result); |
| + |
| + ResourceMessageCallParams params; |
| + IPC::Message msg; |
| + ASSERT_TRUE(sink().GetFirstResourceCallMatching( |
| + PpapiHostMsg_Talk_StartRemoting::ID, ¶ms, &msg)); |
| + |
| + ASSERT_FALSE(callback.called()); |
| + ResourceMessageReplyParams notify_params(res.get(), 0); |
| + IPC::Message notify = PpapiPluginMsg_ResourceReply( |
| + notify_params, PpapiPluginMsg_Talk_NotifyEvent(PP_TALKEVENT_ERROR)); |
| + ASSERT_TRUE(plugin_dispatcher()->OnMessageReceived(notify)); |
| + ASSERT_TRUE(callback.called()); |
| + ASSERT_EQ(PP_TALKEVENT_ERROR, callback.result()); |
| + |
| + // Calling |StartRemoting()| again before |StopRemoting()| should fail. |
| + result = talk->StartRemoting( |
| + res.get(), &TalkEventCallback::Callback, &callback); |
| + ASSERT_EQ(PP_ERROR_INPROGRESS, result); |
| + |
| + talk->StopRemoting(res.get()); |
| + |
| + // Test idempotence. |
| + callback.Reset(); |
| + result = talk->StartRemoting( |
| + res.get(), &TalkEventCallback::Callback, &callback); |
| + ASSERT_EQ(PP_OK, result); |
| + ASSERT_TRUE(plugin_dispatcher()->OnMessageReceived(notify)); |
| + ASSERT_TRUE(callback.called()); |
| + ASSERT_EQ(PP_TALKEVENT_ERROR, callback.result()); |
| +} |
| + |
| +} // namespace proxy |
| +} // namespace ppapi |