OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 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 "base/memory/shared_memory.h" |
| 6 #include "base/message_loop/message_loop.h" |
| 7 #include "ppapi/c/pp_errors.h" |
| 8 #include "ppapi/c/ppb_video_decoder.h" |
| 9 #include "ppapi/proxy/locking_resource_releaser.h" |
| 10 #include "ppapi/proxy/plugin_message_filter.h" |
| 11 #include "ppapi/proxy/ppapi_message_utils.h" |
| 12 #include "ppapi/proxy/ppapi_messages.h" |
| 13 #include "ppapi/proxy/ppapi_proxy_test.h" |
| 14 #include "ppapi/proxy/ppb_graphics_3d_proxy.h" |
| 15 #include "ppapi/proxy/video_decoder_resource.h" |
| 16 #include "ppapi/shared_impl/proxy_lock.h" |
| 17 #include "ppapi/thunk/enter.h" |
| 18 #include "ppapi/thunk/ppb_graphics_3d_api.h" |
| 19 #include "ppapi/thunk/ppb_video_decoder_api.h" |
| 20 #include "ppapi/thunk/thunk.h" |
| 21 |
| 22 using ppapi::proxy::ResourceMessageTestSink; |
| 23 using ppapi::thunk::EnterResource; |
| 24 using ppapi::thunk::PPB_VideoDecoder_API; |
| 25 |
| 26 namespace ppapi { |
| 27 namespace proxy { |
| 28 |
| 29 namespace { |
| 30 |
| 31 const PP_Bool kAllowSoftwareFallback = PP_TRUE; |
| 32 const uint32_t kDecodeBufferSize = 16; |
| 33 const uint32_t kDecodeId = 5; |
| 34 const uint32_t kTextureId1 = 11; |
| 35 const uint32_t kTextureId2 = 12; |
| 36 |
| 37 class MockCompletionCallback { |
| 38 public: |
| 39 MockCompletionCallback() : called_(false) {} |
| 40 |
| 41 bool called() { return called_; } |
| 42 int32_t result() { return result_; } |
| 43 |
| 44 void Reset() { called_ = false; } |
| 45 |
| 46 static void Callback(void* user_data, int32_t result) { |
| 47 MockCompletionCallback* that = |
| 48 reinterpret_cast<MockCompletionCallback*>(user_data); |
| 49 that->called_ = true; |
| 50 that->result_ = result; |
| 51 } |
| 52 |
| 53 private: |
| 54 bool called_; |
| 55 int32_t result_; |
| 56 }; |
| 57 |
| 58 class VideoDecoderResourceTest : public PluginProxyTest { |
| 59 public: |
| 60 const PPB_VideoDecoder_0_1* decoder_iface; |
| 61 const PPB_Graphics3D_1_0* graphics3d_iface; |
| 62 |
| 63 VideoDecoderResourceTest() |
| 64 : decoder_iface(thunk::GetPPB_VideoDecoder_0_1_Thunk()), |
| 65 graphics3d_iface(thunk::GetPPB_Graphics3D_1_0_Thunk()) {} |
| 66 |
| 67 void SendReply(const ResourceMessageCallParams& params, |
| 68 int32_t result, |
| 69 const IPC::Message& nested_message) { |
| 70 ResourceMessageReplyParams reply_params(params.pp_resource(), |
| 71 params.sequence()); |
| 72 reply_params.set_result(result); |
| 73 PluginMessageFilter::DispatchResourceReplyForTest(reply_params, |
| 74 nested_message); |
| 75 } |
| 76 |
| 77 void SendReplyWithHandle(const ResourceMessageCallParams& params, |
| 78 int32_t result, |
| 79 const IPC::Message& nested_message, |
| 80 const SerializedHandle& handle) { |
| 81 ResourceMessageReplyParams reply_params(params.pp_resource(), |
| 82 params.sequence()); |
| 83 reply_params.set_result(result); |
| 84 reply_params.AppendHandle(handle); |
| 85 PluginMessageFilter::DispatchResourceReplyForTest(reply_params, |
| 86 nested_message); |
| 87 } |
| 88 |
| 89 PP_Resource CreateDecoder() { return decoder_iface->Create(pp_instance()); } |
| 90 |
| 91 PP_Resource CreateGraphics3d() { |
| 92 ProxyAutoLock lock; |
| 93 |
| 94 HostResource host_resource; |
| 95 host_resource.SetHostResource(pp_instance(), 5); |
| 96 scoped_refptr<ppapi::proxy::Graphics3D> graphics_3d( |
| 97 new ppapi::proxy::Graphics3D(host_resource)); |
| 98 return graphics_3d->GetReference(); |
| 99 } |
| 100 |
| 101 PP_Resource CreateAndInitializeDecoder() { |
| 102 PP_Resource decoder = CreateDecoder(); |
| 103 LockingResourceReleaser graphics3d(CreateGraphics3d()); |
| 104 MockCompletionCallback cb; |
| 105 int32_t result = |
| 106 decoder_iface->Initialize(decoder, |
| 107 graphics3d.get(), |
| 108 PP_VIDEOPROFILE_H264MAIN, |
| 109 PP_TRUE /* allow_software_fallback */, |
| 110 PP_MakeOptionalCompletionCallback( |
| 111 &MockCompletionCallback::Callback, &cb)); |
| 112 if (result != PP_OK_COMPLETIONPENDING) |
| 113 return 0; |
| 114 ResourceMessageCallParams params; |
| 115 IPC::Message msg; |
| 116 if (!sink().GetFirstResourceCallMatching( |
| 117 PpapiHostMsg_VideoDecoder_Initialize::ID, ¶ms, &msg)) |
| 118 return 0; |
| 119 sink().ClearMessages(); |
| 120 SendReply(params, PP_OK, PpapiPluginMsg_VideoDecoder_InitializeReply()); |
| 121 return decoder; |
| 122 } |
| 123 |
| 124 SerializedHandle CreateSharedMemory(uint32_t size) { |
| 125 base::SharedMemory shm; |
| 126 shm.CreateAnonymous(size); |
| 127 base::SharedMemoryHandle shm_handle; |
| 128 shm.ShareToProcess(base::GetCurrentProcessHandle(), &shm_handle); |
| 129 return SerializedHandle(shm_handle, size); |
| 130 } |
| 131 |
| 132 char decode_buffer[kDecodeBufferSize] = {0x55}; |
| 133 |
| 134 int32_t CallDecode(PP_Resource pp_decoder, MockCompletionCallback* cb) { |
| 135 int32_t result = |
| 136 decoder_iface->Decode(pp_decoder, |
| 137 kDecodeId, |
| 138 kDecodeBufferSize, |
| 139 decode_buffer, |
| 140 PP_MakeOptionalCompletionCallback( |
| 141 &MockCompletionCallback::Callback, cb)); |
| 142 return result; |
| 143 } |
| 144 |
| 145 int32_t CallGetPicture(PP_Resource pp_decoder, |
| 146 PP_VideoPicture* picture, |
| 147 MockCompletionCallback* cb) { |
| 148 int32_t result = |
| 149 decoder_iface->GetPicture(pp_decoder, |
| 150 picture, |
| 151 PP_MakeOptionalCompletionCallback( |
| 152 &MockCompletionCallback::Callback, cb)); |
| 153 return result; |
| 154 } |
| 155 |
| 156 void CallRecyclePicture(PP_Resource pp_decoder, |
| 157 const PP_VideoPicture& picture) { |
| 158 decoder_iface->RecyclePicture(pp_decoder, &picture); |
| 159 } |
| 160 |
| 161 int32_t CallFlush(PP_Resource pp_decoder, MockCompletionCallback* cb) { |
| 162 int32_t result = |
| 163 decoder_iface->Flush(pp_decoder, |
| 164 PP_MakeOptionalCompletionCallback( |
| 165 &MockCompletionCallback::Callback, cb)); |
| 166 return result; |
| 167 } |
| 168 |
| 169 int32_t CallReset(PP_Resource pp_decoder, MockCompletionCallback* cb) { |
| 170 int32_t result = |
| 171 decoder_iface->Reset(pp_decoder, |
| 172 PP_MakeOptionalCompletionCallback( |
| 173 &MockCompletionCallback::Callback, cb)); |
| 174 return result; |
| 175 } |
| 176 |
| 177 void SendGetShmReply(const ResourceMessageCallParams& params, uint32_t size) { |
| 178 SendReplyWithHandle(params, |
| 179 PP_OK, |
| 180 PpapiPluginMsg_VideoDecoder_GetShmReply(size), |
| 181 CreateSharedMemory(size)); |
| 182 } |
| 183 |
| 184 void SendDecodeReply(const ResourceMessageCallParams& params, |
| 185 uint32_t shm_id) { |
| 186 SendReply(params, PP_OK, PpapiPluginMsg_VideoDecoder_DecodeReply(shm_id)); |
| 187 } |
| 188 |
| 189 void SendPictureReady(const ResourceMessageCallParams& params, |
| 190 uint32_t shm_id, |
| 191 uint32_t texture_id) { |
| 192 SendReply(params, |
| 193 PP_OK, |
| 194 PpapiPluginMsg_VideoDecoder_PictureReady(shm_id, texture_id)); |
| 195 } |
| 196 |
| 197 void SendFlushReply(const ResourceMessageCallParams& params) { |
| 198 SendReply(params, PP_OK, PpapiPluginMsg_VideoDecoder_FlushReply()); |
| 199 } |
| 200 |
| 201 void SendResetReply(const ResourceMessageCallParams& params) { |
| 202 SendReply(params, PP_OK, PpapiPluginMsg_VideoDecoder_ResetReply()); |
| 203 } |
| 204 |
| 205 void SendNotifyError(const ResourceMessageCallParams& params, int32_t error) { |
| 206 SendReply(params, PP_OK, PpapiPluginMsg_VideoDecoder_NotifyError(error)); |
| 207 } |
| 208 |
| 209 bool CheckGetShmMsg(ResourceMessageCallParams* params, uint32_t* size) { |
| 210 IPC::Message msg; |
| 211 if (!sink().GetFirstResourceCallMatching( |
| 212 PpapiHostMsg_VideoDecoder_GetShm::ID, params, &msg)) |
| 213 return false; |
| 214 sink().ClearMessages(); |
| 215 return UnpackMessage<PpapiHostMsg_VideoDecoder_GetShm>(msg, size); |
| 216 } |
| 217 |
| 218 bool CheckDecodeMsg(ResourceMessageCallParams* params, |
| 219 uint32_t* shm_id, |
| 220 uint32_t* size) { |
| 221 IPC::Message msg; |
| 222 if (!sink().GetFirstResourceCallMatching( |
| 223 PpapiHostMsg_VideoDecoder_Decode::ID, params, &msg)) |
| 224 return false; |
| 225 sink().ClearMessages(); |
| 226 return UnpackMessage<PpapiHostMsg_VideoDecoder_Decode>(msg, shm_id, size); |
| 227 } |
| 228 |
| 229 bool CheckRecyclePictureMsg(ResourceMessageCallParams* params, |
| 230 uint32_t* texture_id) { |
| 231 IPC::Message msg; |
| 232 if (!sink().GetFirstResourceCallMatching( |
| 233 PpapiHostMsg_VideoDecoder_RecyclePicture::ID, params, &msg)) |
| 234 return false; |
| 235 sink().ClearMessages(); |
| 236 return UnpackMessage<PpapiHostMsg_VideoDecoder_RecyclePicture>(msg, |
| 237 texture_id); |
| 238 } |
| 239 |
| 240 bool CheckFlushMsg(ResourceMessageCallParams* params) { |
| 241 return CheckMsg(params, PpapiHostMsg_VideoDecoder_Flush::ID); |
| 242 } |
| 243 |
| 244 bool CheckResetMsg(ResourceMessageCallParams* params) { |
| 245 return CheckMsg(params, PpapiHostMsg_VideoDecoder_Reset::ID); |
| 246 } |
| 247 |
| 248 private: |
| 249 bool CheckMsg(ResourceMessageCallParams* params, int id) { |
| 250 IPC::Message msg; |
| 251 if (!sink().GetFirstResourceCallMatching(id, params, &msg)) |
| 252 return false; |
| 253 sink().ClearMessages(); |
| 254 return true; |
| 255 } |
| 256 }; |
| 257 |
| 258 } // namespace |
| 259 |
| 260 TEST_F(VideoDecoderResourceTest, Initialize) { |
| 261 // Initialize with 0 graphics3d_context should fail. |
| 262 { |
| 263 LockingResourceReleaser decoder(CreateDecoder()); |
| 264 MockCompletionCallback cb; |
| 265 int32_t result = |
| 266 decoder_iface->Initialize(decoder.get(), |
| 267 0 /* invalid 3d graphics */, |
| 268 PP_VIDEOPROFILE_H264MAIN, |
| 269 kAllowSoftwareFallback, |
| 270 PP_MakeOptionalCompletionCallback( |
| 271 &MockCompletionCallback::Callback, &cb)); |
| 272 ASSERT_EQ(PP_ERROR_BADRESOURCE, result); |
| 273 } |
| 274 // Initialize with bad non-zero graphics3d_context should fail. |
| 275 { |
| 276 LockingResourceReleaser decoder(CreateDecoder()); |
| 277 MockCompletionCallback cb; |
| 278 int32_t result = |
| 279 decoder_iface->Initialize(decoder.get(), |
| 280 1 /* invalid 3d graphics */, |
| 281 PP_VIDEOPROFILE_H264MAIN, |
| 282 kAllowSoftwareFallback, |
| 283 PP_MakeOptionalCompletionCallback( |
| 284 &MockCompletionCallback::Callback, &cb)); |
| 285 ASSERT_EQ(PP_ERROR_BADRESOURCE, result); |
| 286 } |
| 287 // Initialize with valid graphics3d_context and profile should succeed. |
| 288 { |
| 289 LockingResourceReleaser decoder(CreateDecoder()); |
| 290 LockingResourceReleaser graphics3d(CreateGraphics3d()); |
| 291 MockCompletionCallback cb; |
| 292 int32_t result = |
| 293 decoder_iface->Initialize(decoder.get(), |
| 294 graphics3d.get(), |
| 295 PP_VIDEOPROFILE_H264MAIN, |
| 296 kAllowSoftwareFallback, |
| 297 PP_MakeOptionalCompletionCallback( |
| 298 &MockCompletionCallback::Callback, &cb)); |
| 299 ASSERT_EQ(PP_OK_COMPLETIONPENDING, result); |
| 300 ASSERT_TRUE(decoder_iface->IsVideoDecoder(decoder.get())); |
| 301 |
| 302 // Another attempt while pending should fail. |
| 303 result = |
| 304 decoder_iface->Initialize(decoder.get(), |
| 305 graphics3d.get(), |
| 306 PP_VIDEOPROFILE_H264MAIN, |
| 307 kAllowSoftwareFallback, |
| 308 PP_MakeOptionalCompletionCallback( |
| 309 &MockCompletionCallback::Callback, &cb)); |
| 310 ASSERT_EQ(PP_ERROR_INPROGRESS, result); |
| 311 |
| 312 // Check for host message and send a reply to complete initialization. |
| 313 ResourceMessageCallParams params; |
| 314 IPC::Message msg; |
| 315 ASSERT_TRUE(sink().GetFirstResourceCallMatching( |
| 316 PpapiHostMsg_VideoDecoder_Initialize::ID, ¶ms, &msg)); |
| 317 sink().ClearMessages(); |
| 318 SendReply(params, PP_OK, PpapiPluginMsg_VideoDecoder_InitializeReply()); |
| 319 ASSERT_TRUE(cb.called()); |
| 320 ASSERT_EQ(PP_OK, cb.result()); |
| 321 } |
| 322 } |
| 323 |
| 324 TEST_F(VideoDecoderResourceTest, Uninitialized) { |
| 325 // Operations on uninitialized decoders should fail. |
| 326 LockingResourceReleaser decoder(CreateDecoder()); |
| 327 MockCompletionCallback uncalled_cb; |
| 328 |
| 329 ASSERT_EQ(PP_ERROR_FAILED, CallDecode(decoder.get(), &uncalled_cb)); |
| 330 ASSERT_FALSE(uncalled_cb.called()); |
| 331 |
| 332 ASSERT_EQ(PP_ERROR_FAILED, CallGetPicture(decoder.get(), NULL, &uncalled_cb)); |
| 333 ASSERT_FALSE(uncalled_cb.called()); |
| 334 |
| 335 ASSERT_EQ(PP_ERROR_FAILED, CallFlush(decoder.get(), &uncalled_cb)); |
| 336 ASSERT_FALSE(uncalled_cb.called()); |
| 337 |
| 338 ASSERT_EQ(PP_ERROR_FAILED, CallReset(decoder.get(), &uncalled_cb)); |
| 339 ASSERT_FALSE(uncalled_cb.called()); |
| 340 } |
| 341 |
| 342 TEST_F(VideoDecoderResourceTest, DecodeAndGetPicture) { |
| 343 LockingResourceReleaser decoder(CreateAndInitializeDecoder()); |
| 344 ResourceMessageCallParams params, params2; // TODO rename? |
| 345 MockCompletionCallback decode_cb, get_picture_cb, uncalled_cb; |
| 346 ASSERT_EQ(PP_OK_COMPLETIONPENDING, CallDecode(decoder.get(), &decode_cb)); |
| 347 ASSERT_FALSE(decode_cb.called()); |
| 348 |
| 349 // Calling Decode when another Decode is pending should fail. |
| 350 ASSERT_EQ(PP_ERROR_INPROGRESS, CallDecode(decoder.get(), &uncalled_cb)); |
| 351 ASSERT_FALSE(uncalled_cb.called()); |
| 352 |
| 353 // Check for host message to create shm and send a reply with handle. |
| 354 uint32_t shm_buffer_size; |
| 355 ASSERT_TRUE(CheckGetShmMsg(¶ms, &shm_buffer_size)); |
| 356 ASSERT_GE(shm_buffer_size, kDecodeBufferSize); |
| 357 SendGetShmReply(params, shm_buffer_size); |
| 358 // The decoder should copy the user data and send a Decode message. |
| 359 uint32_t shm_id; |
| 360 uint32_t decode_size; |
| 361 ASSERT_TRUE(CheckDecodeMsg(¶ms, &shm_id, &decode_size)); |
| 362 // Buffer id is 0. |
| 363 ASSERT_EQ(0U, shm_id); |
| 364 ASSERT_EQ(kDecodeBufferSize, decode_size); |
| 365 // The decoder should run the callback. |
| 366 ASSERT_TRUE(decode_cb.called()); |
| 367 ASSERT_EQ(PP_OK, decode_cb.result()); |
| 368 decode_cb.Reset(); |
| 369 |
| 370 // The decoder only has 1 shm buffer and it is still in use. The next Decode |
| 371 // call should also cause a shm buffer to be created. |
| 372 ASSERT_EQ(PP_OK_COMPLETIONPENDING, CallDecode(decoder.get(), &decode_cb)); |
| 373 ASSERT_FALSE(decode_cb.called()); |
| 374 // Check for another host message to create shm and send a reply with handle. |
| 375 ASSERT_TRUE(CheckGetShmMsg(¶ms2, &shm_buffer_size)); |
| 376 SendGetShmReply(params2, shm_buffer_size); |
| 377 |
| 378 // The decoder should copy the user data and send the host message to Decode. |
| 379 ASSERT_TRUE(CheckDecodeMsg(¶ms2, &shm_id, &decode_size)); |
| 380 // Buffer id should be 1. |
| 381 ASSERT_EQ(1U, shm_id); |
| 382 ASSERT_EQ(kDecodeBufferSize, decode_size); |
| 383 // The decoder should run the plugin's callback. |
| 384 ASSERT_TRUE(decode_cb.called()); |
| 385 ASSERT_EQ(PP_OK, decode_cb.result()); |
| 386 decode_cb.Reset(); |
| 387 |
| 388 // Now send a reply for both in-flight decodes. This should free up shm |
| 389 // buffers 0 and 1, and set the picture ids for them. |
| 390 SendDecodeReply(params, 0U); |
| 391 SendDecodeReply(params2, 1U); |
| 392 |
| 393 // Calling Decode when a shm buffer is available should complete |
| 394 // synchronously. |
| 395 ASSERT_EQ(PP_OK, CallDecode(decoder.get(), &uncalled_cb)); |
| 396 ASSERT_FALSE(uncalled_cb.called()); |
| 397 |
| 398 // Now try to get a picture. No picture ready message has been received yet. |
| 399 PP_VideoPicture picture; |
| 400 ASSERT_EQ(PP_OK_COMPLETIONPENDING, |
| 401 CallGetPicture(decoder.get(), &picture, &get_picture_cb)); |
| 402 ASSERT_FALSE(get_picture_cb.called()); |
| 403 // Calling GetPicture when another GetPicture is pending should fail. |
| 404 ASSERT_EQ(PP_ERROR_INPROGRESS, |
| 405 CallGetPicture(decoder.get(), &picture, &uncalled_cb)); |
| 406 ASSERT_FALSE(uncalled_cb.called()); |
| 407 // Send a picture ready message for shm 0. The callback should complete. |
| 408 SendPictureReady(params, 0U, kTextureId1); |
| 409 ASSERT_TRUE(get_picture_cb.called()); |
| 410 ASSERT_EQ(PP_OK, get_picture_cb.result()); |
| 411 ASSERT_EQ(kDecodeId, picture.decode_id); |
| 412 get_picture_cb.Reset(); |
| 413 |
| 414 // Send another picture ready message. Since there is no pending GetPicture |
| 415 // call, the picture should be queued. |
| 416 SendPictureReady(params, 1U, kTextureId2); |
| 417 // The next GetPicture should return synchronously. |
| 418 ASSERT_EQ(PP_OK, CallGetPicture(decoder.get(), &picture, &uncalled_cb)); |
| 419 ASSERT_FALSE(uncalled_cb.called()); |
| 420 ASSERT_EQ(kDecodeId, picture.decode_id); |
| 421 } |
| 422 |
| 423 TEST_F(VideoDecoderResourceTest, RecyclePicture) { |
| 424 LockingResourceReleaser decoder(CreateAndInitializeDecoder()); |
| 425 ResourceMessageCallParams params; |
| 426 MockCompletionCallback cb; |
| 427 |
| 428 // Call GetPicture and send reply to create a texture to recycle. |
| 429 PP_VideoPicture picture; |
| 430 CallGetPicture(decoder.get(), &picture, &cb); |
| 431 SendPictureReady(params, 0U, kTextureId1); |
| 432 |
| 433 CallRecyclePicture(decoder.get(), picture); |
| 434 uint32_t texture_id; |
| 435 ASSERT_TRUE(CheckRecyclePictureMsg(¶ms, &texture_id)); |
| 436 } |
| 437 |
| 438 TEST_F(VideoDecoderResourceTest, Flush) { |
| 439 LockingResourceReleaser decoder(CreateAndInitializeDecoder()); |
| 440 ResourceMessageCallParams params, params2; |
| 441 MockCompletionCallback flush_cb, get_picture_cb, uncalled_cb; |
| 442 |
| 443 ASSERT_EQ(PP_OK_COMPLETIONPENDING, CallFlush(decoder.get(), &flush_cb)); |
| 444 ASSERT_FALSE(flush_cb.called()); |
| 445 ASSERT_TRUE(CheckFlushMsg(¶ms)); |
| 446 |
| 447 ASSERT_EQ(PP_ERROR_FAILED, CallDecode(decoder.get(), &uncalled_cb)); |
| 448 ASSERT_FALSE(uncalled_cb.called()); |
| 449 |
| 450 // Plugin can call GetPicture while Flush is pending. |
| 451 ASSERT_EQ(PP_OK_COMPLETIONPENDING, |
| 452 CallGetPicture(decoder.get(), NULL, &get_picture_cb)); |
| 453 ASSERT_FALSE(get_picture_cb.called()); |
| 454 |
| 455 ASSERT_EQ(PP_ERROR_INPROGRESS, CallFlush(decoder.get(), &uncalled_cb)); |
| 456 ASSERT_FALSE(uncalled_cb.called()); |
| 457 |
| 458 ASSERT_EQ(PP_ERROR_FAILED, CallReset(decoder.get(), &uncalled_cb)); |
| 459 ASSERT_FALSE(uncalled_cb.called()); |
| 460 |
| 461 // Plugin can call RecyclePicture while Flush is pending. |
| 462 PP_VideoPicture picture; |
| 463 picture.texture_id = kTextureId1; |
| 464 CallRecyclePicture(decoder.get(), picture); |
| 465 uint32_t texture_id; |
| 466 ASSERT_TRUE(CheckRecyclePictureMsg(¶ms2, &texture_id)); |
| 467 |
| 468 SendFlushReply(params); |
| 469 // Any pending GetPicture call is aborted. |
| 470 ASSERT_TRUE(get_picture_cb.called()); |
| 471 ASSERT_EQ(PP_ERROR_ABORTED, get_picture_cb.result()); |
| 472 ASSERT_TRUE(flush_cb.called()); |
| 473 ASSERT_EQ(PP_OK, flush_cb.result()); |
| 474 } |
| 475 |
| 476 TEST_F(VideoDecoderResourceTest, Reset) { |
| 477 LockingResourceReleaser decoder(CreateAndInitializeDecoder()); |
| 478 ResourceMessageCallParams params; |
| 479 MockCompletionCallback reset_cb, decode_cb, get_picture_cb, uncalled_cb; |
| 480 |
| 481 // Call Decode and GetPicture to have some pending requests. |
| 482 ASSERT_EQ(PP_OK_COMPLETIONPENDING, CallDecode(decoder.get(), &decode_cb)); |
| 483 ASSERT_EQ(PP_OK_COMPLETIONPENDING, |
| 484 CallGetPicture(decoder.get(), NULL, &get_picture_cb)); |
| 485 |
| 486 ASSERT_EQ(PP_OK_COMPLETIONPENDING, CallReset(decoder.get(), &reset_cb)); |
| 487 ASSERT_FALSE(reset_cb.called()); |
| 488 ASSERT_TRUE(CheckResetMsg(¶ms)); |
| 489 // Pending calls should be aborted. |
| 490 ASSERT_TRUE(decode_cb.called()); |
| 491 ASSERT_EQ(PP_ERROR_ABORTED, decode_cb.result()); |
| 492 ASSERT_TRUE(get_picture_cb.called()); |
| 493 ASSERT_EQ(PP_ERROR_ABORTED, get_picture_cb.result()); |
| 494 |
| 495 // No calls can be made while Reset is pending. |
| 496 ASSERT_EQ(PP_ERROR_FAILED, CallDecode(decoder.get(), &uncalled_cb)); |
| 497 ASSERT_FALSE(uncalled_cb.called()); |
| 498 ASSERT_EQ(PP_ERROR_FAILED, CallGetPicture(decoder.get(), NULL, &uncalled_cb)); |
| 499 ASSERT_FALSE(uncalled_cb.called()); |
| 500 ASSERT_EQ(PP_ERROR_FAILED, CallFlush(decoder.get(), &uncalled_cb)); |
| 501 ASSERT_FALSE(uncalled_cb.called()); |
| 502 ASSERT_EQ(PP_ERROR_INPROGRESS, CallReset(decoder.get(), &uncalled_cb)); |
| 503 ASSERT_FALSE(uncalled_cb.called()); |
| 504 |
| 505 SendResetReply(params); |
| 506 ASSERT_TRUE(reset_cb.called()); |
| 507 ASSERT_EQ(PP_OK, reset_cb.result()); |
| 508 } |
| 509 |
| 510 TEST_F(VideoDecoderResourceTest, NotifyError) { |
| 511 LockingResourceReleaser decoder(CreateAndInitializeDecoder()); |
| 512 ResourceMessageCallParams params; |
| 513 MockCompletionCallback decode_cb, get_picture_cb, uncalled_cb; |
| 514 |
| 515 // Call Decode and GetPicture to have some pending requests. |
| 516 ASSERT_EQ(PP_OK_COMPLETIONPENDING, CallDecode(decoder.get(), &decode_cb)); |
| 517 ASSERT_FALSE(decode_cb.called()); |
| 518 ASSERT_EQ(PP_OK_COMPLETIONPENDING, |
| 519 CallGetPicture(decoder.get(), NULL, &get_picture_cb)); |
| 520 ASSERT_FALSE(get_picture_cb.called()); |
| 521 |
| 522 // Send the decoder resource an unsolicited notify error message. We first |
| 523 // need to initialize 'params' so the message is routed to the decoder. |
| 524 uint32_t shm_buffer_size; |
| 525 CheckGetShmMsg(¶ms, &shm_buffer_size); |
| 526 SendNotifyError(params, PP_ERROR_PLATFORM_FAILED); |
| 527 |
| 528 // Both pending messages should be run with the reported error. |
| 529 ASSERT_TRUE(decode_cb.called()); |
| 530 ASSERT_EQ(PP_ERROR_PLATFORM_FAILED, decode_cb.result()); |
| 531 ASSERT_TRUE(get_picture_cb.called()); |
| 532 ASSERT_EQ(PP_ERROR_PLATFORM_FAILED, get_picture_cb.result()); |
| 533 |
| 534 // All further calls return the reported error. |
| 535 ASSERT_EQ(PP_ERROR_PLATFORM_FAILED, CallDecode(decoder.get(), &uncalled_cb)); |
| 536 ASSERT_FALSE(uncalled_cb.called()); |
| 537 ASSERT_EQ(PP_ERROR_PLATFORM_FAILED, |
| 538 CallGetPicture(decoder.get(), NULL, &uncalled_cb)); |
| 539 ASSERT_FALSE(uncalled_cb.called()); |
| 540 ASSERT_EQ(PP_ERROR_PLATFORM_FAILED, CallFlush(decoder.get(), &uncalled_cb)); |
| 541 ASSERT_FALSE(uncalled_cb.called()); |
| 542 ASSERT_EQ(PP_ERROR_PLATFORM_FAILED, CallReset(decoder.get(), &uncalled_cb)); |
| 543 ASSERT_FALSE(uncalled_cb.called()); |
| 544 } |
| 545 |
| 546 } // namespace proxy |
| 547 } // namespace ppapi |
OLD | NEW |