OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/bind.h" | 5 #include "base/bind.h" |
6 #include "base/memory/scoped_ptr.h" | 6 #include "base/memory/scoped_ptr.h" |
7 #include "base/run_loop.h" | 7 #include "base/run_loop.h" |
8 #include "base/test/test_timeouts.h" | 8 #include "base/test/test_timeouts.h" |
9 #include "base/threading/thread.h" | 9 #include "base/threading/thread.h" |
10 #include "media/base/video_capture_types.h" | 10 #include "media/base/video_capture_types.h" |
11 #include "media/video/capture/fake_video_capture_device.h" | 11 #include "media/video/capture/fake_video_capture_device.h" |
12 #include "media/video/capture/fake_video_capture_device_factory.h" | 12 #include "media/video/capture/fake_video_capture_device_factory.h" |
13 #include "media/video/capture/video_capture_device.h" | 13 #include "media/video/capture/video_capture_device.h" |
14 #include "testing/gmock/include/gmock/gmock.h" | 14 #include "testing/gmock/include/gmock/gmock.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
16 | 16 |
17 using ::testing::_; | 17 using ::testing::_; |
18 using ::testing::SaveArg; | 18 using ::testing::SaveArg; |
19 | 19 |
20 namespace media { | 20 namespace media { |
21 | 21 |
22 namespace { | 22 namespace { |
23 | 23 |
24 class MockClient : public VideoCaptureDevice::Client { | 24 class MockClient : public VideoCaptureDevice::Client { |
25 public: | 25 public: |
26 MOCK_METHOD9(OnIncomingCapturedYuvData, | |
27 void (const uint8* y_data, | |
28 const uint8* u_data, | |
29 const uint8* v_data, | |
30 size_t y_stride, | |
31 size_t u_stride, | |
32 size_t v_stride, | |
33 const VideoCaptureFormat& frame_format, | |
34 int clockwise_rotation, | |
35 const base::TimeTicks& timestamp)); | |
36 MOCK_METHOD2(ReserveOutputBuffer, | 26 MOCK_METHOD2(ReserveOutputBuffer, |
37 scoped_refptr<Buffer>(VideoFrame::Format format, | 27 scoped_refptr<Buffer>(VideoFrame::Format format, |
38 const gfx::Size& dimensions)); | 28 const gfx::Size& dimensions)); |
39 MOCK_METHOD3(OnIncomingCapturedVideoFrame, | 29 MOCK_METHOD3(OnIncomingCapturedVideoFrame, |
40 void(const scoped_refptr<Buffer>& buffer, | 30 void(const scoped_refptr<Buffer>& buffer, |
41 const scoped_refptr<media::VideoFrame>& frame, | 31 const scoped_refptr<media::VideoFrame>& frame, |
42 const base::TimeTicks& timestamp)); | 32 const base::TimeTicks& timestamp)); |
43 MOCK_METHOD1(OnError, void(const std::string& reason)); | 33 MOCK_METHOD1(OnError, void(const std::string& reason)); |
44 | 34 |
45 explicit MockClient(base::Callback<void(const VideoCaptureFormat&)> frame_cb) | 35 explicit MockClient(base::Callback<void(const VideoCaptureFormat&)> frame_cb) |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 FakeVideoCaptureDeviceTest() | 73 FakeVideoCaptureDeviceTest() |
84 : loop_(new base::MessageLoop()), | 74 : loop_(new base::MessageLoop()), |
85 client_(new MockClient( | 75 client_(new MockClient( |
86 base::Bind(&FakeVideoCaptureDeviceTest::OnFrameCaptured, | 76 base::Bind(&FakeVideoCaptureDeviceTest::OnFrameCaptured, |
87 base::Unretained(this)))), | 77 base::Unretained(this)))), |
88 video_capture_device_factory_(new FakeVideoCaptureDeviceFactory()) { | 78 video_capture_device_factory_(new FakeVideoCaptureDeviceFactory()) { |
89 device_enumeration_listener_ = new DeviceEnumerationListener(); | 79 device_enumeration_listener_ = new DeviceEnumerationListener(); |
90 } | 80 } |
91 | 81 |
92 void SetUp() override { | 82 void SetUp() override { |
93 EXPECT_CALL(*client_, OnIncomingCapturedYuvData(_,_,_,_,_,_,_,_,_)) | |
94 .Times(0); | |
95 EXPECT_CALL(*client_, ReserveOutputBuffer(_,_)).Times(0); | 83 EXPECT_CALL(*client_, ReserveOutputBuffer(_,_)).Times(0); |
96 EXPECT_CALL(*client_, OnIncomingCapturedVideoFrame(_,_,_)).Times(0); | 84 EXPECT_CALL(*client_, OnIncomingCapturedVideoFrame(_,_,_)).Times(0); |
97 } | 85 } |
98 | 86 |
99 void OnFrameCaptured(const VideoCaptureFormat& format) { | 87 void OnFrameCaptured(const VideoCaptureFormat& format) { |
100 last_format_ = format; | 88 last_format_ = format; |
101 run_loop_->QuitClosure().Run(); | 89 run_loop_->QuitClosure().Run(); |
102 } | 90 } |
103 | 91 |
104 void WaitForCapturedFrame() { | 92 void WaitForCapturedFrame() { |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 | 199 |
212 // We set TimeWait to 200 action timeouts and this should be enough for at | 200 // We set TimeWait to 200 action timeouts and this should be enough for at |
213 // least action_count/kFakeCaptureCapabilityChangePeriod calls. | 201 // least action_count/kFakeCaptureCapabilityChangePeriod calls. |
214 for (int i = 0; i < action_count; ++i) { | 202 for (int i = 0; i < action_count; ++i) { |
215 WaitForCapturedFrame(); | 203 WaitForCapturedFrame(); |
216 } | 204 } |
217 device->StopAndDeAllocate(); | 205 device->StopAndDeAllocate(); |
218 } | 206 } |
219 | 207 |
220 }; // namespace media | 208 }; // namespace media |
OLD | NEW |