Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(81)

Side by Side Diff: services/video_capture/test/mock_device_unittest.cc

Issue 2844813002: Revert of [Mojo Video Capture] Adapt video_capture service to refactored video capture stack (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/run_loop.h" 5 #include "base/run_loop.h"
6 #include "services/video_capture/test/mock_device_test.h" 6 #include "services/video_capture/test/mock_device_test.h"
7 7
8 using testing::_; 8 using testing::_;
9 using testing::Invoke; 9 using testing::Invoke;
10 10
11 namespace video_capture { 11 namespace video_capture {
12 12
13 // This alias ensures test output is easily attributed to this service's tests. 13 // This alias ensures test output is easily attributed to this service's tests.
14 // TODO(rockot/chfremer): Consider just renaming the type. 14 // TODO(rockot/chfremer): Consider just renaming the type.
15 using MockVideoCaptureDeviceTest = MockDeviceTest; 15 using MockVideoCaptureDeviceTest = MockDeviceTest;
16 16
17 // Tests that the service stops the capture device when the client closes the 17 // Tests that the service stops the capture device when the client closes the
18 // connection to the device proxy. 18 // connection to the device proxy.
19 TEST_F(MockVideoCaptureDeviceTest, DeviceIsStoppedWhenDiscardingDeviceProxy) { 19 TEST_F(MockVideoCaptureDeviceTest,
20 DISABLED_DeviceIsStoppedWhenDiscardingDeviceProxy) {
20 base::RunLoop wait_loop; 21 base::RunLoop wait_loop;
21 22
22 EXPECT_CALL(mock_device_, DoStopAndDeAllocate()) 23 // The mock device must hold on to the device client that is passed to it.
24 std::unique_ptr<media::VideoCaptureDevice::Client> device_client;
25 EXPECT_CALL(mock_device_, DoAllocateAndStart(_, _))
26 .WillOnce(Invoke([&device_client](
27 const media::VideoCaptureParams& params,
28 std::unique_ptr<media::VideoCaptureDevice::Client>* client) {
29 device_client.reset(client->release());
30 }));
31 EXPECT_CALL(mock_device_, StopAndDeAllocate())
23 .WillOnce(Invoke([&wait_loop]() { wait_loop.Quit(); })); 32 .WillOnce(Invoke([&wait_loop]() { wait_loop.Quit(); }));
24 33
25 device_proxy_->Start(requested_settings_, std::move(mock_receiver_proxy_)); 34 device_proxy_->Start(requested_settings_, std::move(mock_receiver_proxy_));
26 device_proxy_.reset(); 35 device_proxy_.reset();
27 36
28 wait_loop.Run(); 37 wait_loop.Run();
29 } 38 }
30 39
31 // Tests that the service stops the capture device when the client closes the 40 // Tests that the service stops the capture device when the client closes the
32 // connection to the client proxy it provided to the service. 41 // connection to the client proxy it provided to the service.
33 TEST_F(MockVideoCaptureDeviceTest, DeviceIsStoppedWhenDiscardingDeviceClient) { 42 TEST_F(MockVideoCaptureDeviceTest,
43 DISABLED_DeviceIsStoppedWhenDiscardingDeviceClient) {
34 base::RunLoop wait_loop; 44 base::RunLoop wait_loop;
35 45
36 EXPECT_CALL(mock_device_, DoStopAndDeAllocate()) 46 // The mock device must hold on to the device client that is passed to it.
47 std::unique_ptr<media::VideoCaptureDevice::Client> device_client;
48 EXPECT_CALL(mock_device_, DoAllocateAndStart(_, _))
49 .WillOnce(Invoke([&device_client](
50 const media::VideoCaptureParams& params,
51 std::unique_ptr<media::VideoCaptureDevice::Client>* client) {
52 device_client.reset(client->release());
53 }));
54 EXPECT_CALL(mock_device_, StopAndDeAllocate())
37 .WillOnce(Invoke([&wait_loop]() { wait_loop.Quit(); })); 55 .WillOnce(Invoke([&wait_loop]() { wait_loop.Quit(); }));
38 56
39 device_proxy_->Start(requested_settings_, std::move(mock_receiver_proxy_)); 57 device_proxy_->Start(requested_settings_, std::move(mock_receiver_proxy_));
40 mock_receiver_.reset(); 58 mock_receiver_.reset();
41 59
42 wait_loop.Run(); 60 wait_loop.Run();
43 } 61 }
44 62
45 // Tests that a utilization reported to a video_capture.mojom.Device via
46 // OnReceiverReportingUtilization() arrives at the corresponding
47 // media::VideoCaptureDevice.
48 TEST_F(MockVideoCaptureDeviceTest, ReceiverUtilizationIsForwardedToDevice) {
49 base::RunLoop run_loop;
50 const media::VideoCaptureFormat stub_frame_format(gfx::Size(320, 200), 25.0f,
51 media::PIXEL_FORMAT_I420);
52 const int arbitrary_rotation = 0;
53 const int arbitrary_frame_feedback_id = 654;
54 const double arbitrary_utilization = 0.12345;
55
56 EXPECT_CALL(*mock_receiver_, DoOnFrameReadyInBuffer(_, _, _, _))
57 .WillOnce(Invoke([this, &arbitrary_utilization](
58 int32_t buffer_id, int32_t frame_feedback_id,
59 mojom::ScopedAccessPermissionPtr*,
60 media::mojom::VideoFrameInfoPtr*) {
61 device_proxy_->OnReceiverReportingUtilization(frame_feedback_id,
62 arbitrary_utilization);
63 }));
64
65 EXPECT_CALL(mock_device_, OnUtilizationReport(arbitrary_frame_feedback_id,
66 arbitrary_utilization))
67 .Times(1);
68
69 device_proxy_->Start(requested_settings_, std::move(mock_receiver_proxy_));
70 run_loop.RunUntilIdle();
71
72 // Simulate device sending a frame, which should trigger |mock_receiver|
73 // DoOnFrameReadyInBuffer() getting called.
74 base::RunLoop run_loop_2;
75 mock_device_.SendStubFrame(stub_frame_format, arbitrary_rotation,
76 arbitrary_frame_feedback_id);
77 run_loop_2.RunUntilIdle();
78
79 base::RunLoop run_loop_3;
80 mock_receiver_.reset();
81 run_loop_3.RunUntilIdle();
82 }
83
84 } // namespace video_capture 63 } // namespace video_capture
OLDNEW
« no previous file with comments | « services/video_capture/test/mock_device_test.cc ('k') | services/video_capture/test/mock_receiver.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698