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

Unified 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: Don't use IPC::Message::Schema::Read in unittest - build break 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ppapi/proxy/talk_resource.cc ('k') | ppapi/tests/test_talk_private.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..fd8341b9cabbe29afde321785344e3a42aac60df
--- /dev/null
+++ b/ppapi/proxy/talk_resource_unittest.cc
@@ -0,0 +1,173 @@
+// 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 {
+
+template <class ResultType>
+class MockCallbackBase {
+ public:
+ MockCallbackBase() : called_(false) {
+ }
+
+ bool called() {
+ return called_;
+ }
+
+ ResultType result() {
+ return result_;
+ }
+
+ void Reset() {
+ called_ = false;
+ }
+
+ static void Callback(void* user_data, ResultType result) {
+ MockCallbackBase* that = reinterpret_cast<MockCallbackBase*>(user_data);
+ that->called_ = true;
+ that->result_ = result;
+ }
+
+ private:
+ bool called_;
+ ResultType result_;
+};
+
+typedef MockCallbackBase<int32_t> MockCompletionCallback;
+typedef MockCallbackBase<PP_TalkEvent> TalkEventCallback;
+
+class TalkResourceTest : public PluginProxyTest {
+ public:
+ void SendReply(
+ uint32_t id,
+ const IPC::Message& reply,
+ int32_t result) {
+ IPC::Message msg;
+ ResourceMessageCallParams params;
+ ASSERT_TRUE(sink().GetFirstResourceCallMatching(id, &params, &msg));
+
+ ResourceMessageReplyParams reply_params(params.pp_resource(),
+ params.sequence());
+ reply_params.set_result(result);
+ IPC::Message reply_msg = PpapiPluginMsg_ResourceReply(reply_params, reply);
+ ASSERT_TRUE(plugin_dispatcher()->OnMessageReceived(reply_msg));
+ }
+};
+
+
+} // 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()));
+ MockCompletionCallback callback;
+
+ int32_t result = talk->GetPermission(
+ res.get(),
+ PP_MakeCompletionCallback(&MockCompletionCallback::Callback, &callback));
+ ASSERT_EQ(PP_OK_COMPLETIONPENDING, result);
+
+ ResourceMessageCallParams params;
+ IPC::Message msg;
+ ASSERT_TRUE(sink().GetFirstResourceCallMatching(
+ PpapiHostMsg_Talk_RequestPermission::ID, &params, &msg));
+
+ 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()));
+ MockCompletionCallback callback;
+
+ int32_t result = talk->RequestPermission(
+ res.get(),
+ PP_TALKPERMISSION_REMOTING_CONTINUE,
+ PP_MakeCompletionCallback(&MockCompletionCallback::Callback, &callback));
+ ASSERT_EQ(PP_OK_COMPLETIONPENDING, result);
+
+ ResourceMessageCallParams params;
+ IPC::Message msg;
+ ASSERT_TRUE(sink().GetFirstResourceCallMatching(
+ PpapiHostMsg_Talk_RequestPermission::ID, &params, &msg));
+
+ 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, StartStopRemoting) {
+ const PPB_Talk_Private_2_0* talk = thunk::GetPPB_Talk_Private_2_0_Thunk();
+ LockingResourceReleaser res(talk->Create(pp_instance()));
+ MockCompletionCallback callback;
+ TalkEventCallback event_callback;
+
+ // Start
+ int32_t result = talk->StartRemoting(
+ res.get(),
+ &TalkEventCallback::Callback,
+ &event_callback,
+ PP_MakeCompletionCallback(&MockCompletionCallback::Callback, &callback));
+ ASSERT_EQ(PP_OK_COMPLETIONPENDING, result);
+
+ SendReply(PpapiHostMsg_Talk_StartRemoting::ID,
+ PpapiPluginMsg_Talk_StartRemotingReply(),
+ PP_OK);
+
+ ASSERT_TRUE(callback.called());
+ ASSERT_EQ(PP_OK, callback.result());
+
+ // Receive an event
+ ASSERT_FALSE(event_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(event_callback.called());
+ ASSERT_EQ(PP_TALKEVENT_ERROR, event_callback.result());
+
+ // Stop
+ callback.Reset();
+ result = talk->StopRemoting(
+ res.get(),
+ PP_MakeCompletionCallback(&MockCompletionCallback::Callback, &callback));
+ ASSERT_EQ(PP_OK_COMPLETIONPENDING, result);
+
+ SendReply(PpapiHostMsg_Talk_StopRemoting::ID,
+ PpapiPluginMsg_Talk_StopRemotingReply(),
+ PP_OK);
+
+ ASSERT_TRUE(callback.called());
+ ASSERT_EQ(PP_OK, callback.result());
+
+ // Events should be discarded at this point
+ event_callback.Reset();
+ ASSERT_TRUE(plugin_dispatcher()->OnMessageReceived(notify));
+ ASSERT_FALSE(event_callback.called());
+}
+
+} // namespace proxy
+} // namespace ppapi
« no previous file with comments | « ppapi/proxy/talk_resource.cc ('k') | ppapi/tests/test_talk_private.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698