| 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)); |
| 26 MOCK_METHOD2(ReserveOutputBuffer, | 36 MOCK_METHOD2(ReserveOutputBuffer, |
| 27 scoped_refptr<Buffer>(VideoFrame::Format format, | 37 scoped_refptr<Buffer>(VideoFrame::Format format, |
| 28 const gfx::Size& dimensions)); | 38 const gfx::Size& dimensions)); |
| 29 MOCK_METHOD3(OnIncomingCapturedVideoFrame, | 39 MOCK_METHOD3(OnIncomingCapturedVideoFrame, |
| 30 void(const scoped_refptr<Buffer>& buffer, | 40 void(const scoped_refptr<Buffer>& buffer, |
| 31 const scoped_refptr<media::VideoFrame>& frame, | 41 const scoped_refptr<media::VideoFrame>& frame, |
| 32 const base::TimeTicks& timestamp)); | 42 const base::TimeTicks& timestamp)); |
| 33 MOCK_METHOD1(OnError, void(const std::string& reason)); | 43 MOCK_METHOD1(OnError, void(const std::string& reason)); |
| 34 | 44 |
| 35 explicit MockClient(base::Callback<void(const VideoCaptureFormat&)> frame_cb) | 45 explicit MockClient(base::Callback<void(const VideoCaptureFormat&)> frame_cb) |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 FakeVideoCaptureDeviceTest() | 83 FakeVideoCaptureDeviceTest() |
| 74 : loop_(new base::MessageLoop()), | 84 : loop_(new base::MessageLoop()), |
| 75 client_(new MockClient( | 85 client_(new MockClient( |
| 76 base::Bind(&FakeVideoCaptureDeviceTest::OnFrameCaptured, | 86 base::Bind(&FakeVideoCaptureDeviceTest::OnFrameCaptured, |
| 77 base::Unretained(this)))), | 87 base::Unretained(this)))), |
| 78 video_capture_device_factory_(new FakeVideoCaptureDeviceFactory()) { | 88 video_capture_device_factory_(new FakeVideoCaptureDeviceFactory()) { |
| 79 device_enumeration_listener_ = new DeviceEnumerationListener(); | 89 device_enumeration_listener_ = new DeviceEnumerationListener(); |
| 80 } | 90 } |
| 81 | 91 |
| 82 void SetUp() override { | 92 void SetUp() override { |
| 93 EXPECT_CALL(*client_, OnIncomingCapturedYuvData(_,_,_,_,_,_,_,_,_)) |
| 94 .Times(0); |
| 83 EXPECT_CALL(*client_, ReserveOutputBuffer(_,_)).Times(0); | 95 EXPECT_CALL(*client_, ReserveOutputBuffer(_,_)).Times(0); |
| 84 EXPECT_CALL(*client_, OnIncomingCapturedVideoFrame(_,_,_)).Times(0); | 96 EXPECT_CALL(*client_, OnIncomingCapturedVideoFrame(_,_,_)).Times(0); |
| 85 } | 97 } |
| 86 | 98 |
| 87 void OnFrameCaptured(const VideoCaptureFormat& format) { | 99 void OnFrameCaptured(const VideoCaptureFormat& format) { |
| 88 last_format_ = format; | 100 last_format_ = format; |
| 89 run_loop_->QuitClosure().Run(); | 101 run_loop_->QuitClosure().Run(); |
| 90 } | 102 } |
| 91 | 103 |
| 92 void WaitForCapturedFrame() { | 104 void WaitForCapturedFrame() { |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 | 211 |
| 200 // We set TimeWait to 200 action timeouts and this should be enough for at | 212 // We set TimeWait to 200 action timeouts and this should be enough for at |
| 201 // least action_count/kFakeCaptureCapabilityChangePeriod calls. | 213 // least action_count/kFakeCaptureCapabilityChangePeriod calls. |
| 202 for (int i = 0; i < action_count; ++i) { | 214 for (int i = 0; i < action_count; ++i) { |
| 203 WaitForCapturedFrame(); | 215 WaitForCapturedFrame(); |
| 204 } | 216 } |
| 205 device->StopAndDeAllocate(); | 217 device->StopAndDeAllocate(); |
| 206 } | 218 } |
| 207 | 219 |
| 208 }; // namespace media | 220 }; // namespace media |
| OLD | NEW |