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

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: Created 7 years, 7 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
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..6784773955264b7bd436458f02665af20e778337
--- /dev/null
+++ b/ppapi/proxy/talk_resource_unittest.cc
@@ -0,0 +1,170 @@
+// 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_GetPermission::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_GetPermissionReply());
+ ASSERT_TRUE(plugin_dispatcher()->OnMessageReceived(reply));
+
+ ASSERT_TRUE(callback.called());
+ ASSERT_EQ(1, callback.result());
+}
+
+TEST_F(TalkResourceTest, GetRemotingPermission) {
+ 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->GetRemotingPermission(
+ res.get(),
+ PP_MakeCompletionCallback(&CompletionCallback::Callback, &callback));
+ ASSERT_EQ(PP_OK_COMPLETIONPENDING, result);
+
+ ResourceMessageCallParams params;
+ IPC::Message msg;
+ ASSERT_TRUE(sink().GetFirstResourceCallMatching(
+ PpapiHostMsg_Talk_GetRemotingPermission::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_GetRemotingPermissionReply());
+ ASSERT_TRUE(plugin_dispatcher()->OnMessageReceived(reply));
+
+ ASSERT_TRUE(callback.called());
+ ASSERT_EQ(1, callback.result());
+}
+
+TEST_F(TalkResourceTest, GetRemotingContinuePermission) {
+ 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->GetRemotingContinuePermission(
+ res.get(),
+ PP_MakeCompletionCallback(&CompletionCallback::Callback, &callback));
+ ASSERT_EQ(PP_OK_COMPLETIONPENDING, result);
+
+ ResourceMessageCallParams params;
+ IPC::Message msg;
+ ASSERT_TRUE(sink().GetFirstResourceCallMatching(
+ PpapiHostMsg_Talk_GetRemotingContinuePermission::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_GetRemotingContinuePermissionReply());
+ 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()));
+ 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, &params, &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

Powered by Google App Engine
This is Rietveld 408576698