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

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

Issue 46433002: Support using TrackedCallbacks as hints to determine the handling thread of resource reply messages (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years 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 | Annotate | Revision Log
« no previous file with comments | « ppapi/proxy/resource_reply_thread_registrar.cc ('k') | ppapi/proxy/tcp_socket_resource_base.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ppapi/proxy/locking_resource_releaser.h" 5 #include "ppapi/proxy/locking_resource_releaser.h"
6 #include "ppapi/proxy/plugin_message_filter.h"
6 #include "ppapi/proxy/ppapi_messages.h" 7 #include "ppapi/proxy/ppapi_messages.h"
7 #include "ppapi/proxy/ppapi_proxy_test.h" 8 #include "ppapi/proxy/ppapi_proxy_test.h"
8 #include "ppapi/proxy/talk_resource.h" 9 #include "ppapi/proxy/talk_resource.h"
9 #include "ppapi/thunk/thunk.h" 10 #include "ppapi/thunk/thunk.h"
10 11
11 namespace ppapi { 12 namespace ppapi {
12 namespace proxy { 13 namespace proxy {
13 14
14 namespace { 15 namespace {
15 16
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 uint32_t id, 52 uint32_t id,
52 const IPC::Message& reply, 53 const IPC::Message& reply,
53 int32_t result) { 54 int32_t result) {
54 IPC::Message msg; 55 IPC::Message msg;
55 ResourceMessageCallParams params; 56 ResourceMessageCallParams params;
56 ASSERT_TRUE(sink().GetFirstResourceCallMatching(id, &params, &msg)); 57 ASSERT_TRUE(sink().GetFirstResourceCallMatching(id, &params, &msg));
57 58
58 ResourceMessageReplyParams reply_params(params.pp_resource(), 59 ResourceMessageReplyParams reply_params(params.pp_resource(),
59 params.sequence()); 60 params.sequence());
60 reply_params.set_result(result); 61 reply_params.set_result(result);
61 IPC::Message reply_msg = PpapiPluginMsg_ResourceReply(reply_params, reply); 62 PluginMessageFilter::DispatchResourceReplyForTest(reply_params, reply);
62 ASSERT_TRUE(plugin_dispatcher()->OnMessageReceived(reply_msg));
63 } 63 }
64 }; 64 };
65 65
66 66
67 } // namespace 67 } // namespace
68 68
69 TEST_F(TalkResourceTest, GetPermission) { 69 TEST_F(TalkResourceTest, GetPermission) {
70 const PPB_Talk_Private_1_0* talk = thunk::GetPPB_Talk_Private_1_0_Thunk(); 70 const PPB_Talk_Private_1_0* talk = thunk::GetPPB_Talk_Private_1_0_Thunk();
71 LockingResourceReleaser res(talk->Create(pp_instance())); 71 LockingResourceReleaser res(talk->Create(pp_instance()));
72 MockCompletionCallback callback; 72 MockCompletionCallback callback;
73 73
74 int32_t result = talk->GetPermission( 74 int32_t result = talk->GetPermission(
75 res.get(), 75 res.get(),
76 PP_MakeCompletionCallback(&MockCompletionCallback::Callback, &callback)); 76 PP_MakeCompletionCallback(&MockCompletionCallback::Callback, &callback));
77 ASSERT_EQ(PP_OK_COMPLETIONPENDING, result); 77 ASSERT_EQ(PP_OK_COMPLETIONPENDING, result);
78 78
79 ResourceMessageCallParams params; 79 ResourceMessageCallParams params;
80 IPC::Message msg; 80 IPC::Message msg;
81 ASSERT_TRUE(sink().GetFirstResourceCallMatching( 81 ASSERT_TRUE(sink().GetFirstResourceCallMatching(
82 PpapiHostMsg_Talk_RequestPermission::ID, &params, &msg)); 82 PpapiHostMsg_Talk_RequestPermission::ID, &params, &msg));
83 83
84 ResourceMessageReplyParams reply_params(params.pp_resource(), 84 ResourceMessageReplyParams reply_params(params.pp_resource(),
85 params.sequence()); 85 params.sequence());
86 reply_params.set_result(1); 86 reply_params.set_result(1);
87 IPC::Message reply = PpapiPluginMsg_ResourceReply( 87 PluginMessageFilter::DispatchResourceReplyForTest(
88 reply_params, PpapiPluginMsg_Talk_RequestPermissionReply()); 88 reply_params, PpapiPluginMsg_Talk_RequestPermissionReply());
89 ASSERT_TRUE(plugin_dispatcher()->OnMessageReceived(reply));
90 89
91 ASSERT_TRUE(callback.called()); 90 ASSERT_TRUE(callback.called());
92 ASSERT_EQ(1, callback.result()); 91 ASSERT_EQ(1, callback.result());
93 } 92 }
94 93
95 TEST_F(TalkResourceTest, RequestPermission) { 94 TEST_F(TalkResourceTest, RequestPermission) {
96 const PPB_Talk_Private_2_0* talk = thunk::GetPPB_Talk_Private_2_0_Thunk(); 95 const PPB_Talk_Private_2_0* talk = thunk::GetPPB_Talk_Private_2_0_Thunk();
97 LockingResourceReleaser res(talk->Create(pp_instance())); 96 LockingResourceReleaser res(talk->Create(pp_instance()));
98 MockCompletionCallback callback; 97 MockCompletionCallback callback;
99 98
100 int32_t result = talk->RequestPermission( 99 int32_t result = talk->RequestPermission(
101 res.get(), 100 res.get(),
102 PP_TALKPERMISSION_REMOTING_CONTINUE, 101 PP_TALKPERMISSION_REMOTING_CONTINUE,
103 PP_MakeCompletionCallback(&MockCompletionCallback::Callback, &callback)); 102 PP_MakeCompletionCallback(&MockCompletionCallback::Callback, &callback));
104 ASSERT_EQ(PP_OK_COMPLETIONPENDING, result); 103 ASSERT_EQ(PP_OK_COMPLETIONPENDING, result);
105 104
106 ResourceMessageCallParams params; 105 ResourceMessageCallParams params;
107 IPC::Message msg; 106 IPC::Message msg;
108 ASSERT_TRUE(sink().GetFirstResourceCallMatching( 107 ASSERT_TRUE(sink().GetFirstResourceCallMatching(
109 PpapiHostMsg_Talk_RequestPermission::ID, &params, &msg)); 108 PpapiHostMsg_Talk_RequestPermission::ID, &params, &msg));
110 109
111 ResourceMessageReplyParams reply_params(params.pp_resource(), 110 ResourceMessageReplyParams reply_params(params.pp_resource(),
112 params.sequence()); 111 params.sequence());
113 reply_params.set_result(1); 112 reply_params.set_result(1);
114 IPC::Message reply = PpapiPluginMsg_ResourceReply( 113 PluginMessageFilter::DispatchResourceReplyForTest(
115 reply_params, PpapiPluginMsg_Talk_RequestPermissionReply()); 114 reply_params, PpapiPluginMsg_Talk_RequestPermissionReply());
116 ASSERT_TRUE(plugin_dispatcher()->OnMessageReceived(reply));
117 115
118 ASSERT_TRUE(callback.called()); 116 ASSERT_TRUE(callback.called());
119 ASSERT_EQ(1, callback.result()); 117 ASSERT_EQ(1, callback.result());
120 } 118 }
121 119
122 TEST_F(TalkResourceTest, StartStopRemoting) { 120 TEST_F(TalkResourceTest, StartStopRemoting) {
123 const PPB_Talk_Private_2_0* talk = thunk::GetPPB_Talk_Private_2_0_Thunk(); 121 const PPB_Talk_Private_2_0* talk = thunk::GetPPB_Talk_Private_2_0_Thunk();
124 LockingResourceReleaser res(talk->Create(pp_instance())); 122 LockingResourceReleaser res(talk->Create(pp_instance()));
125 MockCompletionCallback callback; 123 MockCompletionCallback callback;
126 TalkEventCallback event_callback; 124 TalkEventCallback event_callback;
127 125
128 // Start 126 // Start
129 int32_t result = talk->StartRemoting( 127 int32_t result = talk->StartRemoting(
130 res.get(), 128 res.get(),
131 &TalkEventCallback::Callback, 129 &TalkEventCallback::Callback,
132 &event_callback, 130 &event_callback,
133 PP_MakeCompletionCallback(&MockCompletionCallback::Callback, &callback)); 131 PP_MakeCompletionCallback(&MockCompletionCallback::Callback, &callback));
134 ASSERT_EQ(PP_OK_COMPLETIONPENDING, result); 132 ASSERT_EQ(PP_OK_COMPLETIONPENDING, result);
135 133
136 SendReply(PpapiHostMsg_Talk_StartRemoting::ID, 134 SendReply(PpapiHostMsg_Talk_StartRemoting::ID,
137 PpapiPluginMsg_Talk_StartRemotingReply(), 135 PpapiPluginMsg_Talk_StartRemotingReply(),
138 PP_OK); 136 PP_OK);
139 137
140 ASSERT_TRUE(callback.called()); 138 ASSERT_TRUE(callback.called());
141 ASSERT_EQ(PP_OK, callback.result()); 139 ASSERT_EQ(PP_OK, callback.result());
142 140
143 // Receive an event 141 // Receive an event
144 ASSERT_FALSE(event_callback.called()); 142 ASSERT_FALSE(event_callback.called());
145 ResourceMessageReplyParams notify_params(res.get(), 0); 143 ResourceMessageReplyParams notify_params(res.get(), 0);
146 IPC::Message notify = PpapiPluginMsg_ResourceReply( 144 PluginMessageFilter::DispatchResourceReplyForTest(
147 notify_params, PpapiPluginMsg_Talk_NotifyEvent(PP_TALKEVENT_ERROR)); 145 notify_params, PpapiPluginMsg_Talk_NotifyEvent(PP_TALKEVENT_ERROR));
148 ASSERT_TRUE(plugin_dispatcher()->OnMessageReceived(notify));
149 ASSERT_TRUE(event_callback.called()); 146 ASSERT_TRUE(event_callback.called());
150 ASSERT_EQ(PP_TALKEVENT_ERROR, event_callback.result()); 147 ASSERT_EQ(PP_TALKEVENT_ERROR, event_callback.result());
151 148
152 // Stop 149 // Stop
153 callback.Reset(); 150 callback.Reset();
154 result = talk->StopRemoting( 151 result = talk->StopRemoting(
155 res.get(), 152 res.get(),
156 PP_MakeCompletionCallback(&MockCompletionCallback::Callback, &callback)); 153 PP_MakeCompletionCallback(&MockCompletionCallback::Callback, &callback));
157 ASSERT_EQ(PP_OK_COMPLETIONPENDING, result); 154 ASSERT_EQ(PP_OK_COMPLETIONPENDING, result);
158 155
159 SendReply(PpapiHostMsg_Talk_StopRemoting::ID, 156 SendReply(PpapiHostMsg_Talk_StopRemoting::ID,
160 PpapiPluginMsg_Talk_StopRemotingReply(), 157 PpapiPluginMsg_Talk_StopRemotingReply(),
161 PP_OK); 158 PP_OK);
162 159
163 ASSERT_TRUE(callback.called()); 160 ASSERT_TRUE(callback.called());
164 ASSERT_EQ(PP_OK, callback.result()); 161 ASSERT_EQ(PP_OK, callback.result());
165 162
166 // Events should be discarded at this point 163 // Events should be discarded at this point
167 event_callback.Reset(); 164 event_callback.Reset();
168 ASSERT_TRUE(plugin_dispatcher()->OnMessageReceived(notify)); 165 PluginMessageFilter::DispatchResourceReplyForTest(
166 notify_params, PpapiPluginMsg_Talk_NotifyEvent(PP_TALKEVENT_ERROR));
169 ASSERT_FALSE(event_callback.called()); 167 ASSERT_FALSE(event_callback.called());
170 } 168 }
171 169
172 } // namespace proxy 170 } // namespace proxy
173 } // namespace ppapi 171 } // namespace ppapi
OLDNEW
« no previous file with comments | « ppapi/proxy/resource_reply_thread_registrar.cc ('k') | ppapi/proxy/tcp_socket_resource_base.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698