 Chromium Code Reviews
 Chromium Code Reviews Issue 11039012:
  Implement plugin side of sync EnumerateVideoCaptureDevices  (Closed) 
  Base URL: svn://svn.chromium.org/chrome/trunk/src
    
  
    Issue 11039012:
  Implement plugin side of sync EnumerateVideoCaptureDevices  (Closed) 
  Base URL: svn://svn.chromium.org/chrome/trunk/src| Index: ppapi/proxy/flash_resource_unittest.cc | 
| diff --git a/ppapi/proxy/flash_resource_unittest.cc b/ppapi/proxy/flash_resource_unittest.cc | 
| new file mode 100644 | 
| index 0000000000000000000000000000000000000000..03912feb14266c9649fd71a6aaccd801f0a5fb85 | 
| --- /dev/null | 
| +++ b/ppapi/proxy/flash_resource_unittest.cc | 
| @@ -0,0 +1,103 @@ | 
| +// Copyright (c) 2012 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/c/pp_errors.h" | 
| +#include "ppapi/c/private/ppb_flash.h" | 
| +#include "ppapi/proxy/ppapi_messages.h" | 
| +#include "ppapi/proxy/ppapi_proxy_test.h" | 
| +#include "ppapi/proxy/ppb_video_capture_proxy.h" | 
| +#include "ppapi/shared_impl/scoped_pp_resource.h" | 
| +#include "ppapi/thunk/thunk.h" | 
| + | 
| +namespace ppapi { | 
| +namespace proxy { | 
| + | 
| +namespace { | 
| + | 
| +typedef PluginProxyTest FlashResourceTest; | 
| + | 
| +// This simulates the creation reply message of a VideoCapture resource. This | 
| +// won't be necessary once VideoCapture is converted to the new-style proxy. | 
| +class VideoCaptureCreationHandler : public IPC::Listener { | 
| + public: | 
| + VideoCaptureCreationHandler(ResourceMessageTestSink* test_sink, | 
| + PP_Instance instance) | 
| + : test_sink_(test_sink), | 
| + instance_(instance) { | 
| + } | 
| + virtual ~VideoCaptureCreationHandler() {} | 
| + | 
| + virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE { | 
| + if (msg.type() != ::PpapiHostMsg_PPBVideoCapture_Create::ID) | 
| + return false; | 
| + | 
| + IPC::Message* reply_msg = IPC::SyncMessage::GenerateReply(&msg); | 
| + HostResource resource; | 
| + resource.SetHostResource(instance_, 12345); | 
| + ::PpapiHostMsg_PPBVideoCapture_Create::WriteReplyParams(reply_msg, | 
| 
yzshen1
2012/10/05 18:16:46
nit: unless necessary you don't need to use ::. I
 
raymes
2012/10/08 17:08:50
Done.
 | 
| + resource); | 
| + test_sink_->SetSyncReplyMessage(reply_msg); | 
| + return true; | 
| + } | 
| + private: | 
| + ResourceMessageTestSink* test_sink_; | 
| + PP_Instance instance_; | 
| +}; | 
| + | 
| +void* Unused(void* user_data, uint32_t element_count, uint32_t element_size) { | 
| + return NULL; | 
| +} | 
| + | 
| +} // namespace | 
| + | 
| +// Does a test of EnumerateVideoDevicesSync() and reply functionality in | 
| +// the plugin side using the public C interfaces. | 
| +TEST_F(FlashResourceTest, EnumerateVideoDevicesSync) { | 
| + // TODO(raymes): This doesn't actually check that the data is converted from | 
| + // |ppapi::DeviceRefData| to |PPB_DeviceRef| correctly, just that the right | 
| + // messages are sent. | 
| + | 
| + // Set up a sync call handler that should return this message. | 
| + std::vector<ppapi::DeviceRefData> reply_device_ref_data; | 
| + int32_t expected_result = PP_OK; | 
| + PpapiPluginMsg_Flash_EnumerateVideoDevicesSyncReply reply_msg( | 
| + reply_device_ref_data); | 
| + ResourceSyncCallHandler enumerate_video_devices_handler( | 
| + &sink(), | 
| + PpapiHostMsg_Flash_EnumerateVideoDevicesSync::ID, | 
| + expected_result, | 
| + reply_msg); | 
| + sink().AddFilter(&enumerate_video_devices_handler); | 
| + | 
| + // Setup the handler to simulate creation of the video resource. | 
| + VideoCaptureCreationHandler video_creation_handler(&sink(), pp_instance()); | 
| + sink().AddFilter(&video_creation_handler); | 
| + | 
| + // Set up the arguments to the call. | 
| + ScopedPPResource video_capture(ScopedPPResource::PassRef(), | 
| + PPB_VideoCapture_Proxy::CreateProxyResource(pp_instance())); | 
| + std::vector<PP_Resource> device_ref_resources; | 
| + PP_ArrayOutput output; | 
| + output.GetDataBuffer = &Unused; | 
| + output.user_data = &device_ref_resources; | 
| 
yzshen1
2012/10/05 18:16:46
Why we need device_ref_resources?
 
raymes
2012/10/08 17:08:50
There are some checks to make sure the PP_ArrayOut
 
yzshen1
2012/10/08 19:44:25
Ah, I didn't know. Thanks!
 | 
| + | 
| + // Make the call. | 
| + const PPB_Flash_12_6* flash_iface = ::ppapi::thunk::GetPPB_Flash_12_6_Thunk(); | 
| + int32_t actual_result = flash_iface->EnumerateVideoDevicesSync( | 
| + pp_instance(), video_capture.get(), output); | 
| + | 
| + // Check the result is as expected. | 
| + EXPECT_EQ(expected_result, actual_result); | 
| + | 
| + // Should have sent an "EnumerateVideoDevicesSync" message. | 
| + ASSERT_TRUE(enumerate_video_devices_handler.last_handled_msg().type() == | 
| + PpapiHostMsg_Flash_EnumerateVideoDevicesSync::ID); | 
| + | 
| + // Remove the filter or it will be destroyed before the sink() is destroyed. | 
| + sink().RemoveFilter(&enumerate_video_devices_handler); | 
| + sink().RemoveFilter(&video_creation_handler); | 
| +} | 
| + | 
| +} // namespace proxy | 
| +} // namespace ppapi |