OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "base/memory/ref_counted.h" | 5 #include "base/memory/ref_counted.h" |
6 #include "base/run_loop.h" | 6 #include "base/run_loop.h" |
7 #include "services/video_capture/public/interfaces/video_capture_device_factory.
mojom.h" | 7 #include "services/video_capture/public/interfaces/video_capture_device_factory.
mojom.h" |
8 #include "services/video_capture/video_capture_service_test.h" | 8 #include "services/video_capture/video_capture_service_test.h" |
9 | 9 |
10 using testing::Exactly; | 10 using testing::Exactly; |
(...skipping 10 matching lines...) Expand all Loading... |
21 | 21 |
22 // Tests that an answer arrives from the service when calling | 22 // Tests that an answer arrives from the service when calling |
23 // EnumerateDeviceDescriptors(). | 23 // EnumerateDeviceDescriptors(). |
24 TEST_F(VideoCaptureServiceTest, EnumerateDeviceDescriptorsCallbackArrives) { | 24 TEST_F(VideoCaptureServiceTest, EnumerateDeviceDescriptorsCallbackArrives) { |
25 base::RunLoop wait_loop; | 25 base::RunLoop wait_loop; |
26 EXPECT_CALL(descriptor_receiver_, OnEnumerateDeviceDescriptorsCallback(_)) | 26 EXPECT_CALL(descriptor_receiver_, OnEnumerateDeviceDescriptorsCallback(_)) |
27 .Times(Exactly(1)) | 27 .Times(Exactly(1)) |
28 .WillOnce(InvokeWithoutArgs([&wait_loop]() { wait_loop.Quit(); })); | 28 .WillOnce(InvokeWithoutArgs([&wait_loop]() { wait_loop.Quit(); })); |
29 | 29 |
30 factory_->EnumerateDeviceDescriptors(base::Bind( | 30 factory_->EnumerateDeviceDescriptors(base::Bind( |
31 &MockDeviceDescriptorReceiver::HandleEnumerateDeviceDescriptorsCallback, | 31 &MockDeviceDescriptorReceiver::OnEnumerateDeviceDescriptorsCallback, |
32 base::Unretained(&descriptor_receiver_))); | 32 base::Unretained(&descriptor_receiver_))); |
33 wait_loop.Run(); | 33 wait_loop.Run(); |
34 } | 34 } |
35 | 35 |
36 TEST_F(VideoCaptureServiceTest, FakeDeviceFactoryEnumeratesOneDevice) { | 36 TEST_F(VideoCaptureServiceTest, FakeDeviceFactoryEnumeratesOneDevice) { |
37 base::RunLoop wait_loop; | 37 base::RunLoop wait_loop; |
38 size_t num_devices_enumerated = 0; | 38 size_t num_devices_enumerated = 0; |
39 EXPECT_CALL(descriptor_receiver_, OnEnumerateDeviceDescriptorsCallback(_)) | 39 EXPECT_CALL(descriptor_receiver_, OnEnumerateDeviceDescriptorsCallback(_)) |
40 .Times(Exactly(1)) | 40 .Times(Exactly(1)) |
41 .WillOnce(Invoke([&wait_loop, &num_devices_enumerated]( | 41 .WillOnce(Invoke([&wait_loop, &num_devices_enumerated]( |
42 const std::vector<mojom::VideoCaptureDeviceDescriptorPtr>& | 42 const std::vector<media::VideoCaptureDeviceDescriptor>& descriptors) { |
43 descriptors) { | |
44 num_devices_enumerated = descriptors.size(); | 43 num_devices_enumerated = descriptors.size(); |
45 wait_loop.Quit(); | 44 wait_loop.Quit(); |
46 })); | 45 })); |
47 | 46 |
48 factory_->EnumerateDeviceDescriptors(base::Bind( | 47 factory_->EnumerateDeviceDescriptors(base::Bind( |
49 &MockDeviceDescriptorReceiver::HandleEnumerateDeviceDescriptorsCallback, | 48 &MockDeviceDescriptorReceiver::OnEnumerateDeviceDescriptorsCallback, |
50 base::Unretained(&descriptor_receiver_))); | 49 base::Unretained(&descriptor_receiver_))); |
51 wait_loop.Run(); | 50 wait_loop.Run(); |
52 ASSERT_EQ(1u, num_devices_enumerated); | 51 ASSERT_EQ(1u, num_devices_enumerated); |
53 } | 52 } |
54 | 53 |
55 // Tests that VideoCaptureDeviceFactory::CreateDeviceProxy() returns an error | 54 // Tests that VideoCaptureDeviceFactory::CreateDeviceProxy() returns an error |
56 // code when trying to create a device for an invalid descriptor. | 55 // code when trying to create a device for an invalid descriptor. |
57 TEST_F(VideoCaptureServiceTest, ErrorCodeOnCreateDeviceForInvalidDescriptor) { | 56 TEST_F(VideoCaptureServiceTest, ErrorCodeOnCreateDeviceForInvalidDescriptor) { |
58 auto invalid_descriptor = mojom::VideoCaptureDeviceDescriptor::New(); | 57 media::VideoCaptureDeviceDescriptor invalid_descriptor; |
59 invalid_descriptor->device_id = "invalid"; | 58 invalid_descriptor.device_id = "invalid"; |
60 invalid_descriptor->model_id = "invalid"; | 59 invalid_descriptor.model_id = "invalid"; |
61 base::RunLoop wait_loop; | 60 base::RunLoop wait_loop; |
62 mojom::VideoCaptureDeviceProxyPtr fake_device_proxy; | 61 mojom::VideoCaptureDeviceProxyPtr fake_device_proxy; |
63 MockCreateDeviceProxyCallback create_device_proxy_callback; | 62 MockCreateDeviceProxyCallback create_device_proxy_callback; |
64 EXPECT_CALL(create_device_proxy_callback, | 63 EXPECT_CALL(create_device_proxy_callback, |
65 Run(mojom::DeviceAccessResultCode::ERROR_DEVICE_NOT_FOUND)) | 64 Run(mojom::DeviceAccessResultCode::ERROR_DEVICE_NOT_FOUND)) |
66 .Times(1) | 65 .Times(1) |
67 .WillOnce(InvokeWithoutArgs([&wait_loop]() { wait_loop.Quit(); })); | 66 .WillOnce(InvokeWithoutArgs([&wait_loop]() { wait_loop.Quit(); })); |
68 factory_->CreateDeviceProxy( | 67 factory_->CreateDeviceProxy( |
69 std::move(invalid_descriptor), mojo::GetProxy(&fake_device_proxy), | 68 std::move(invalid_descriptor), mojo::GetProxy(&fake_device_proxy), |
70 base::Bind(&MockCreateDeviceProxyCallback::Run, | 69 base::Bind(&MockCreateDeviceProxyCallback::Run, |
71 base::Unretained(&create_device_proxy_callback))); | 70 base::Unretained(&create_device_proxy_callback))); |
72 wait_loop.Run(); | 71 wait_loop.Run(); |
73 } | 72 } |
74 | 73 |
75 } // namespace video_capture | 74 } // namespace video_capture |
OLD | NEW |