| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <stddef.h> | 5 #include <stddef.h> |
| 6 | 6 |
| 7 #include "base/macros.h" | 7 #include "base/macros.h" |
| 8 #include "base/memory/shared_memory.h" | 8 #include "base/memory/shared_memory.h" |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "content/child/child_process.h" | 10 #include "content/child/child_process.h" |
| 11 #include "content/common/video_capture.mojom.h" | 11 #include "content/common/video_capture.mojom.h" |
| 12 #include "content/renderer/media/video_capture_impl.h" | 12 #include "content/renderer/media/video_capture_impl.h" |
| 13 #include "mojo/public/cpp/system/platform_handle.h" | 13 #include "mojo/public/cpp/system/platform_handle.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::Invoke; | 18 using ::testing::Invoke; |
| 19 using ::testing::InvokeWithoutArgs; | 19 using ::testing::InvokeWithoutArgs; |
| 20 using ::testing::SaveArg; | 20 using ::testing::SaveArg; |
| 21 using ::testing::WithArgs; | 21 using ::testing::WithArgs; |
| 22 | 22 |
| 23 namespace content { | 23 namespace content { |
| 24 | 24 |
| 25 const int kSessionId = 1; | 25 const int kSessionId = 11; |
| 26 | 26 |
| 27 void RunEmptyFormatsCallback(const VideoCaptureDeviceFormatsCB& callback) { | 27 void RunEmptyFormatsCallback(const VideoCaptureDeviceFormatsCB& callback) { |
| 28 media::VideoCaptureFormats formats; | 28 media::VideoCaptureFormats formats; |
| 29 callback.Run(formats); | 29 callback.Run(formats); |
| 30 } | 30 } |
| 31 | 31 |
| 32 // Mock implementation of the Mojo Host service. | 32 // Mock implementation of the Mojo Host service. |
| 33 class MockMojoVideoCaptureHost : public mojom::VideoCaptureHost { | 33 class MockMojoVideoCaptureHost : public mojom::VideoCaptureHost { |
| 34 public: | 34 public: |
| 35 MockMojoVideoCaptureHost() : released_buffer_count_(0) { | 35 MockMojoVideoCaptureHost() : released_buffer_count_(0) { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 void increase_released_buffer_count() { released_buffer_count_++; } | 69 void increase_released_buffer_count() { released_buffer_count_++; } |
| 70 | 70 |
| 71 private: | 71 private: |
| 72 int released_buffer_count_; | 72 int released_buffer_count_; |
| 73 | 73 |
| 74 DISALLOW_COPY_AND_ASSIGN(MockMojoVideoCaptureHost); | 74 DISALLOW_COPY_AND_ASSIGN(MockMojoVideoCaptureHost); |
| 75 }; | 75 }; |
| 76 | 76 |
| 77 // This class encapsulates a VideoCaptureImpl under test and the necessary | 77 // This class encapsulates a VideoCaptureImpl under test and the necessary |
| 78 // accessory classes, namely: | 78 // accessory classes, namely: |
| 79 // - a VideoCaptureMessageFilter; | |
| 80 // - a MockMojoVideoCaptureHost, mimicking the RendererHost; | 79 // - a MockMojoVideoCaptureHost, mimicking the RendererHost; |
| 81 // - a few callbacks that are bound when calling operations of VideoCaptureImpl | 80 // - a few callbacks that are bound when calling operations of VideoCaptureImpl |
| 82 // and on which we set expectations. | 81 // and on which we set expectations. |
| 83 class VideoCaptureImplTest : public ::testing::Test { | 82 class VideoCaptureImplTest : public ::testing::Test { |
| 84 public: | 83 public: |
| 85 VideoCaptureImplTest() | 84 VideoCaptureImplTest() |
| 86 : message_filter_(new VideoCaptureMessageFilter), | 85 : video_capture_impl_(new VideoCaptureImpl(kSessionId)) { |
| 87 video_capture_impl_( | |
| 88 new VideoCaptureImpl(kSessionId, | |
| 89 message_filter_.get(), | |
| 90 base::ThreadTaskRunnerHandle::Get())) { | |
| 91 params_small_.requested_format = media::VideoCaptureFormat( | 86 params_small_.requested_format = media::VideoCaptureFormat( |
| 92 gfx::Size(176, 144), 30, media::PIXEL_FORMAT_I420); | 87 gfx::Size(176, 144), 30, media::PIXEL_FORMAT_I420); |
| 93 params_large_.requested_format = media::VideoCaptureFormat( | 88 params_large_.requested_format = media::VideoCaptureFormat( |
| 94 gfx::Size(320, 240), 30, media::PIXEL_FORMAT_I420); | 89 gfx::Size(320, 240), 30, media::PIXEL_FORMAT_I420); |
| 95 | 90 |
| 96 video_capture_impl_->SetVideoCaptureHostForTesting( | 91 video_capture_impl_->SetVideoCaptureHostForTesting( |
| 97 &mock_video_capture_host_); | 92 &mock_video_capture_host_); |
| 98 video_capture_impl_->device_id_ = 2; | |
| 99 } | 93 } |
| 100 | 94 |
| 101 protected: | 95 protected: |
| 102 // These four mocks are used to create callbacks for the different oeprations. | 96 // These four mocks are used to create callbacks for the different oeprations. |
| 103 MOCK_METHOD2(OnFrameReady, | 97 MOCK_METHOD2(OnFrameReady, |
| 104 void(const scoped_refptr<media::VideoFrame>&, base::TimeTicks)); | 98 void(const scoped_refptr<media::VideoFrame>&, base::TimeTicks)); |
| 105 MOCK_METHOD1(OnStateUpdate, void(VideoCaptureState)); | 99 MOCK_METHOD1(OnStateUpdate, void(VideoCaptureState)); |
| 106 MOCK_METHOD1(OnDeviceFormatsInUse, void(const media::VideoCaptureFormats&)); | 100 MOCK_METHOD1(OnDeviceFormatsInUse, void(const media::VideoCaptureFormats&)); |
| 107 MOCK_METHOD1(OnDeviceSupportedFormats, | 101 MOCK_METHOD1(OnDeviceSupportedFormats, |
| 108 void(const media::VideoCaptureFormats&)); | 102 void(const media::VideoCaptureFormats&)); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 base::Unretained(this)); | 158 base::Unretained(this)); |
| 165 video_capture_impl_->GetDeviceFormatsInUse(callback); | 159 video_capture_impl_->GetDeviceFormatsInUse(callback); |
| 166 } | 160 } |
| 167 | 161 |
| 168 void OnStateChanged(mojom::VideoCaptureState state) { | 162 void OnStateChanged(mojom::VideoCaptureState state) { |
| 169 video_capture_impl_->OnStateChanged(state); | 163 video_capture_impl_->OnStateChanged(state); |
| 170 } | 164 } |
| 171 | 165 |
| 172 const base::MessageLoop message_loop_; | 166 const base::MessageLoop message_loop_; |
| 173 const ChildProcess child_process_; | 167 const ChildProcess child_process_; |
| 174 const scoped_refptr<VideoCaptureMessageFilter> message_filter_; | |
| 175 const std::unique_ptr<VideoCaptureImpl> video_capture_impl_; | 168 const std::unique_ptr<VideoCaptureImpl> video_capture_impl_; |
| 176 MockMojoVideoCaptureHost mock_video_capture_host_; | 169 MockMojoVideoCaptureHost mock_video_capture_host_; |
| 177 media::VideoCaptureParams params_small_; | 170 media::VideoCaptureParams params_small_; |
| 178 media::VideoCaptureParams params_large_; | 171 media::VideoCaptureParams params_large_; |
| 179 | 172 |
| 180 private: | 173 private: |
| 181 DISALLOW_COPY_AND_ASSIGN(VideoCaptureImplTest); | 174 DISALLOW_COPY_AND_ASSIGN(VideoCaptureImplTest); |
| 182 }; | 175 }; |
| 183 | 176 |
| 184 TEST_F(VideoCaptureImplTest, Simple) { | 177 TEST_F(VideoCaptureImplTest, Simple) { |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 342 EXPECT_CALL(mock_video_capture_host_, DoStart(_, kSessionId, params_small_)); | 335 EXPECT_CALL(mock_video_capture_host_, DoStart(_, kSessionId, params_small_)); |
| 343 | 336 |
| 344 StartCapture(0, params_small_); | 337 StartCapture(0, params_small_); |
| 345 | 338 |
| 346 OnStateChanged(mojom::VideoCaptureState::FAILED); | 339 OnStateChanged(mojom::VideoCaptureState::FAILED); |
| 347 | 340 |
| 348 StopCapture(0); | 341 StopCapture(0); |
| 349 } | 342 } |
| 350 | 343 |
| 351 } // namespace content | 344 } // namespace content |
| OLD | NEW |