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