OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "base/memory/ref_counted.h" | |
6 #include "base/run_loop.h" | |
7 #include "services/video_capture/public/interfaces/video_capture_device_factory.
mojom.h" | |
8 #include "services/video_capture/video_capture_service_test.h" | |
9 | |
10 using testing::Exactly; | |
11 using testing::_; | |
12 using testing::Invoke; | |
13 using testing::InvokeWithoutArgs; | |
14 | |
15 namespace video_capture { | |
16 | |
17 class MockCreateDeviceProxyCallback { | |
18 public: | |
19 MOCK_METHOD1(Run, void(mojom::DeviceAccessResultCode result_code)); | |
20 }; | |
21 | |
22 // Tests that an answer arrives from the service when calling | |
23 // EnumerateDeviceDescriptors(). | |
24 TEST_F(VideoCaptureServiceTest, EnumerateDeviceDescriptorsCallbackArrives) { | |
25 base::RunLoop wait_loop; | |
26 EXPECT_CALL(descriptor_receiver_, OnEnumerateDeviceDescriptorsCallback(_)) | |
27 .Times(Exactly(1)) | |
28 .WillOnce(InvokeWithoutArgs([&wait_loop]() { wait_loop.Quit(); })); | |
29 | |
30 factory_->EnumerateDeviceDescriptors(base::Bind( | |
31 &MockDeviceDescriptorReceiver::OnEnumerateDeviceDescriptorsCallback, | |
32 base::Unretained(&descriptor_receiver_))); | |
33 wait_loop.Run(); | |
34 } | |
35 | |
36 TEST_F(VideoCaptureServiceTest, FakeDeviceFactoryEnumeratesOneDevice) { | |
37 base::RunLoop wait_loop; | |
38 size_t num_devices_enumerated = 0; | |
39 EXPECT_CALL(descriptor_receiver_, OnEnumerateDeviceDescriptorsCallback(_)) | |
40 .Times(Exactly(1)) | |
41 .WillOnce(Invoke([&wait_loop, &num_devices_enumerated]( | |
42 const std::vector<media::VideoCaptureDeviceDescriptor>& descriptors) { | |
43 num_devices_enumerated = descriptors.size(); | |
44 wait_loop.Quit(); | |
45 })); | |
46 | |
47 factory_->EnumerateDeviceDescriptors(base::Bind( | |
48 &MockDeviceDescriptorReceiver::OnEnumerateDeviceDescriptorsCallback, | |
49 base::Unretained(&descriptor_receiver_))); | |
50 wait_loop.Run(); | |
51 ASSERT_EQ(1u, num_devices_enumerated); | |
52 } | |
53 | |
54 // Tests that VideoCaptureDeviceFactory::CreateDeviceProxy() returns an error | |
55 // code when trying to create a device for an invalid descriptor. | |
56 TEST_F(VideoCaptureServiceTest, ErrorCodeOnCreateDeviceForInvalidDescriptor) { | |
57 const std::string invalid_device_id = "invalid"; | |
58 base::RunLoop wait_loop; | |
59 mojom::VideoCaptureDeviceProxyPtr fake_device_proxy; | |
60 MockCreateDeviceProxyCallback create_device_proxy_callback; | |
61 EXPECT_CALL(create_device_proxy_callback, | |
62 Run(mojom::DeviceAccessResultCode::ERROR_DEVICE_NOT_FOUND)) | |
63 .Times(1) | |
64 .WillOnce(InvokeWithoutArgs([&wait_loop]() { wait_loop.Quit(); })); | |
65 factory_->CreateDeviceProxy( | |
66 invalid_device_id, mojo::GetProxy(&fake_device_proxy), | |
67 base::Bind(&MockCreateDeviceProxyCallback::Run, | |
68 base::Unretained(&create_device_proxy_callback))); | |
69 wait_loop.Run(); | |
70 } | |
71 | |
72 } // namespace video_capture | |
OLD | NEW |