Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2012 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 "ppapi/c/pp_errors.h" | |
| 6 #include "ppapi/c/private/ppb_flash.h" | |
| 7 #include "ppapi/proxy/ppapi_messages.h" | |
| 8 #include "ppapi/proxy/ppapi_proxy_test.h" | |
| 9 #include "ppapi/proxy/ppb_video_capture_proxy.h" | |
| 10 #include "ppapi/shared_impl/scoped_pp_resource.h" | |
| 11 #include "ppapi/thunk/thunk.h" | |
| 12 | |
| 13 namespace ppapi { | |
| 14 namespace proxy { | |
| 15 | |
| 16 namespace { | |
| 17 | |
| 18 typedef PluginProxyTest FlashResourceTest; | |
| 19 | |
| 20 // This simulates the creation reply message of a VideoCapture resource. This | |
| 21 // won't be necessary once VideoCapture is converted to the new-style proxy. | |
| 22 class VideoCaptureCreationHandler : public IPC::Listener { | |
| 23 public: | |
| 24 VideoCaptureCreationHandler(ResourceMessageTestSink* test_sink, | |
| 25 PP_Instance instance) | |
| 26 : test_sink_(test_sink), | |
| 27 instance_(instance) { | |
| 28 } | |
| 29 virtual ~VideoCaptureCreationHandler() {} | |
| 30 | |
| 31 virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE { | |
| 32 if (msg.type() != ::PpapiHostMsg_PPBVideoCapture_Create::ID) | |
| 33 return false; | |
| 34 | |
| 35 IPC::Message* reply_msg = IPC::SyncMessage::GenerateReply(&msg); | |
| 36 HostResource resource; | |
| 37 resource.SetHostResource(instance_, 12345); | |
| 38 ::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.
| |
| 39 resource); | |
| 40 test_sink_->SetSyncReplyMessage(reply_msg); | |
| 41 return true; | |
| 42 } | |
| 43 private: | |
| 44 ResourceMessageTestSink* test_sink_; | |
| 45 PP_Instance instance_; | |
| 46 }; | |
| 47 | |
| 48 void* Unused(void* user_data, uint32_t element_count, uint32_t element_size) { | |
| 49 return NULL; | |
| 50 } | |
| 51 | |
| 52 } // namespace | |
| 53 | |
| 54 // Does a test of EnumerateVideoDevicesSync() and reply functionality in | |
| 55 // the plugin side using the public C interfaces. | |
| 56 TEST_F(FlashResourceTest, EnumerateVideoDevicesSync) { | |
| 57 // TODO(raymes): This doesn't actually check that the data is converted from | |
| 58 // |ppapi::DeviceRefData| to |PPB_DeviceRef| correctly, just that the right | |
| 59 // messages are sent. | |
| 60 | |
| 61 // Set up a sync call handler that should return this message. | |
| 62 std::vector<ppapi::DeviceRefData> reply_device_ref_data; | |
| 63 int32_t expected_result = PP_OK; | |
| 64 PpapiPluginMsg_Flash_EnumerateVideoDevicesSyncReply reply_msg( | |
| 65 reply_device_ref_data); | |
| 66 ResourceSyncCallHandler enumerate_video_devices_handler( | |
| 67 &sink(), | |
| 68 PpapiHostMsg_Flash_EnumerateVideoDevicesSync::ID, | |
| 69 expected_result, | |
| 70 reply_msg); | |
| 71 sink().AddFilter(&enumerate_video_devices_handler); | |
| 72 | |
| 73 // Setup the handler to simulate creation of the video resource. | |
| 74 VideoCaptureCreationHandler video_creation_handler(&sink(), pp_instance()); | |
| 75 sink().AddFilter(&video_creation_handler); | |
| 76 | |
| 77 // Set up the arguments to the call. | |
| 78 ScopedPPResource video_capture(ScopedPPResource::PassRef(), | |
| 79 PPB_VideoCapture_Proxy::CreateProxyResource(pp_instance())); | |
| 80 std::vector<PP_Resource> device_ref_resources; | |
| 81 PP_ArrayOutput output; | |
| 82 output.GetDataBuffer = &Unused; | |
| 83 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!
| |
| 84 | |
| 85 // Make the call. | |
| 86 const PPB_Flash_12_6* flash_iface = ::ppapi::thunk::GetPPB_Flash_12_6_Thunk(); | |
| 87 int32_t actual_result = flash_iface->EnumerateVideoDevicesSync( | |
| 88 pp_instance(), video_capture.get(), output); | |
| 89 | |
| 90 // Check the result is as expected. | |
| 91 EXPECT_EQ(expected_result, actual_result); | |
| 92 | |
| 93 // Should have sent an "EnumerateVideoDevicesSync" message. | |
| 94 ASSERT_TRUE(enumerate_video_devices_handler.last_handled_msg().type() == | |
| 95 PpapiHostMsg_Flash_EnumerateVideoDevicesSync::ID); | |
| 96 | |
| 97 // Remove the filter or it will be destroyed before the sink() is destroyed. | |
| 98 sink().RemoveFilter(&enumerate_video_devices_handler); | |
| 99 sink().RemoveFilter(&video_creation_handler); | |
| 100 } | |
| 101 | |
| 102 } // namespace proxy | |
| 103 } // namespace ppapi | |
| OLD | NEW |