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::InSequence; | 18 using ::testing::InSequence; |
19 using ::testing::Invoke; | 19 using ::testing::Invoke; |
20 using ::testing::InvokeWithoutArgs; | 20 using ::testing::InvokeWithoutArgs; |
21 using ::testing::SaveArg; | 21 using ::testing::SaveArg; |
22 using ::testing::WithArgs; | 22 using ::testing::WithArgs; |
23 | 23 |
24 namespace content { | 24 namespace content { |
25 | 25 |
26 const int kSessionId = 11; | 26 const int kSessionId = 11; |
27 | 27 |
28 void RunEmptyFormatsCallback(const VideoCaptureDeviceFormatsCB& callback) { | 28 void RunEmptyFormatsCallback( |
| 29 mojom::VideoCaptureHost::GetDeviceSupportedFormatsCallback& callback) { |
29 media::VideoCaptureFormats formats; | 30 media::VideoCaptureFormats formats; |
30 callback.Run(formats); | 31 std::move(callback).Run(formats); |
31 } | 32 } |
32 | 33 |
33 ACTION(DoNothing) {} | 34 ACTION(DoNothing) {} |
34 | 35 |
35 // Mock implementation of the Mojo Host service. | 36 // Mock implementation of the Mojo Host service. |
36 class MockMojoVideoCaptureHost : public mojom::VideoCaptureHost { | 37 class MockMojoVideoCaptureHost : public mojom::VideoCaptureHost { |
37 public: | 38 public: |
38 MockMojoVideoCaptureHost() : released_buffer_count_(0) { | 39 MockMojoVideoCaptureHost() : released_buffer_count_(0) { |
39 ON_CALL(*this, GetDeviceSupportedFormats(_, _, _)) | 40 ON_CALL(*this, GetDeviceSupportedFormatsMock(_, _, _)) |
40 .WillByDefault(WithArgs<2>(Invoke(RunEmptyFormatsCallback))); | 41 .WillByDefault(WithArgs<2>(Invoke(RunEmptyFormatsCallback))); |
41 ON_CALL(*this, GetDeviceFormatsInUse(_, _, _)) | 42 ON_CALL(*this, GetDeviceFormatsInUseMock(_, _, _)) |
42 .WillByDefault(WithArgs<2>(Invoke(RunEmptyFormatsCallback))); | 43 .WillByDefault(WithArgs<2>(Invoke(RunEmptyFormatsCallback))); |
43 ON_CALL(*this, ReleaseBuffer(_, _, _)) | 44 ON_CALL(*this, ReleaseBuffer(_, _, _)) |
44 .WillByDefault(InvokeWithoutArgs( | 45 .WillByDefault(InvokeWithoutArgs( |
45 this, &MockMojoVideoCaptureHost::increase_released_buffer_count)); | 46 this, &MockMojoVideoCaptureHost::increase_released_buffer_count)); |
46 } | 47 } |
47 | 48 |
48 // Start() can't be mocked directly due to move-only |observer|. | 49 // Start() can't be mocked directly due to move-only |observer|. |
49 void Start(int32_t device_id, | 50 void Start(int32_t device_id, |
50 int32_t session_id, | 51 int32_t session_id, |
51 const media::VideoCaptureParams& params, | 52 const media::VideoCaptureParams& params, |
52 mojom::VideoCaptureObserverPtr observer) override { | 53 mojom::VideoCaptureObserverPtr observer) override { |
53 DoStart(device_id, session_id, params); | 54 DoStart(device_id, session_id, params); |
54 } | 55 } |
55 MOCK_METHOD3(DoStart, | 56 MOCK_METHOD3(DoStart, |
56 void(int32_t, int32_t, const media::VideoCaptureParams&)); | 57 void(int32_t, int32_t, const media::VideoCaptureParams&)); |
57 MOCK_METHOD1(Stop, void(int32_t)); | 58 MOCK_METHOD1(Stop, void(int32_t)); |
58 MOCK_METHOD1(Pause, void(int32_t)); | 59 MOCK_METHOD1(Pause, void(int32_t)); |
59 MOCK_METHOD3(Resume, | 60 MOCK_METHOD3(Resume, |
60 void(int32_t, int32_t, const media::VideoCaptureParams&)); | 61 void(int32_t, int32_t, const media::VideoCaptureParams&)); |
61 MOCK_METHOD1(RequestRefreshFrame, void(int32_t)); | 62 MOCK_METHOD1(RequestRefreshFrame, void(int32_t)); |
62 MOCK_METHOD3(ReleaseBuffer, void(int32_t, int32_t, double)); | 63 MOCK_METHOD3(ReleaseBuffer, void(int32_t, int32_t, double)); |
63 MOCK_METHOD3(GetDeviceSupportedFormats, | 64 MOCK_METHOD3(GetDeviceSupportedFormatsMock, |
64 void(int32_t, | 65 void(int32_t, int32_t, GetDeviceSupportedFormatsCallback&)); |
65 int32_t, | 66 MOCK_METHOD3(GetDeviceFormatsInUseMock, |
66 const GetDeviceSupportedFormatsCallback&)); | 67 void(int32_t, int32_t, GetDeviceFormatsInUseCallback&)); |
67 MOCK_METHOD3(GetDeviceFormatsInUse, | 68 |
68 void(int32_t, int32_t, const GetDeviceFormatsInUseCallback&)); | 69 void GetDeviceSupportedFormats( |
| 70 int32_t arg1, |
| 71 int32_t arg2, |
| 72 GetDeviceSupportedFormatsCallback arg3) override { |
| 73 GetDeviceSupportedFormatsMock(arg1, arg2, arg3); |
| 74 } |
| 75 |
| 76 void GetDeviceFormatsInUse(int32_t arg1, |
| 77 int32_t arg2, |
| 78 GetDeviceFormatsInUseCallback arg3) override { |
| 79 GetDeviceFormatsInUseMock(arg1, arg2, arg3); |
| 80 } |
69 | 81 |
70 int released_buffer_count() const { return released_buffer_count_; } | 82 int released_buffer_count() const { return released_buffer_count_; } |
71 void increase_released_buffer_count() { released_buffer_count_++; } | 83 void increase_released_buffer_count() { released_buffer_count_++; } |
72 | 84 |
73 private: | 85 private: |
74 int released_buffer_count_; | 86 int released_buffer_count_; |
75 | 87 |
76 DISALLOW_COPY_AND_ASSIGN(MockMojoVideoCaptureHost); | 88 DISALLOW_COPY_AND_ASSIGN(MockMojoVideoCaptureHost); |
77 }; | 89 }; |
78 | 90 |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 StopCapture(0); | 238 StopCapture(0); |
227 StartCapture(1, params_large_); | 239 StartCapture(1, params_large_); |
228 StopCapture(1); | 240 StopCapture(1); |
229 } | 241 } |
230 | 242 |
231 // Checks that a request to GetDeviceSupportedFormats() ends up eventually in | 243 // Checks that a request to GetDeviceSupportedFormats() ends up eventually in |
232 // the provided callback. | 244 // the provided callback. |
233 TEST_F(VideoCaptureImplTest, GetDeviceFormats) { | 245 TEST_F(VideoCaptureImplTest, GetDeviceFormats) { |
234 EXPECT_CALL(*this, OnDeviceSupportedFormats(_)); | 246 EXPECT_CALL(*this, OnDeviceSupportedFormats(_)); |
235 EXPECT_CALL(mock_video_capture_host_, | 247 EXPECT_CALL(mock_video_capture_host_, |
236 GetDeviceSupportedFormats(_, kSessionId, _)); | 248 GetDeviceSupportedFormatsMock(_, kSessionId, _)); |
237 | 249 |
238 GetDeviceSupportedFormats(); | 250 GetDeviceSupportedFormats(); |
239 } | 251 } |
240 | 252 |
241 // Checks that two requests to GetDeviceSupportedFormats() end up eventually | 253 // Checks that two requests to GetDeviceSupportedFormats() end up eventually |
242 // calling the provided callbacks. | 254 // calling the provided callbacks. |
243 TEST_F(VideoCaptureImplTest, TwoClientsGetDeviceFormats) { | 255 TEST_F(VideoCaptureImplTest, TwoClientsGetDeviceFormats) { |
244 EXPECT_CALL(*this, OnDeviceSupportedFormats(_)).Times(2); | 256 EXPECT_CALL(*this, OnDeviceSupportedFormats(_)).Times(2); |
245 EXPECT_CALL(mock_video_capture_host_, | 257 EXPECT_CALL(mock_video_capture_host_, |
246 GetDeviceSupportedFormats(_, kSessionId, _)) | 258 GetDeviceSupportedFormatsMock(_, kSessionId, _)) |
247 .Times(2); | 259 .Times(2); |
248 | 260 |
249 GetDeviceSupportedFormats(); | 261 GetDeviceSupportedFormats(); |
250 GetDeviceSupportedFormats(); | 262 GetDeviceSupportedFormats(); |
251 } | 263 } |
252 | 264 |
253 // Checks that a request to GetDeviceFormatsInUse() ends up eventually in the | 265 // Checks that a request to GetDeviceFormatsInUse() ends up eventually in the |
254 // provided callback. | 266 // provided callback. |
255 TEST_F(VideoCaptureImplTest, GetDeviceFormatsInUse) { | 267 TEST_F(VideoCaptureImplTest, GetDeviceFormatsInUse) { |
256 EXPECT_CALL(*this, OnDeviceFormatsInUse(_)); | 268 EXPECT_CALL(*this, OnDeviceFormatsInUse(_)); |
257 EXPECT_CALL(mock_video_capture_host_, | 269 EXPECT_CALL(mock_video_capture_host_, |
258 GetDeviceFormatsInUse(_, kSessionId, _)); | 270 GetDeviceFormatsInUseMock(_, kSessionId, _)); |
259 | 271 |
260 GetDeviceFormatsInUse(); | 272 GetDeviceFormatsInUse(); |
261 } | 273 } |
262 | 274 |
263 TEST_F(VideoCaptureImplTest, BufferReceived) { | 275 TEST_F(VideoCaptureImplTest, BufferReceived) { |
264 const int kBufferId = 11; | 276 const int kBufferId = 11; |
265 | 277 |
266 base::SharedMemory shm; | 278 base::SharedMemory shm; |
267 const size_t frame_size = media::VideoFrame::AllocationSize( | 279 const size_t frame_size = media::VideoFrame::AllocationSize( |
268 media::PIXEL_FORMAT_I420, params_small_.requested_format.frame_size); | 280 media::PIXEL_FORMAT_I420, params_small_.requested_format.frame_size); |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
377 EXPECT_CALL(*this, OnStateUpdate(VIDEO_CAPTURE_STATE_STARTED)); | 389 EXPECT_CALL(*this, OnStateUpdate(VIDEO_CAPTURE_STATE_STARTED)); |
378 EXPECT_CALL(mock_video_capture_host_, RequestRefreshFrame(_)); | 390 EXPECT_CALL(mock_video_capture_host_, RequestRefreshFrame(_)); |
379 video_capture_impl_->OnStateChanged(mojom::VideoCaptureState::STARTED); | 391 video_capture_impl_->OnStateChanged(mojom::VideoCaptureState::STARTED); |
380 | 392 |
381 EXPECT_CALL(*this, OnStateUpdate(VIDEO_CAPTURE_STATE_STOPPED)); | 393 EXPECT_CALL(*this, OnStateUpdate(VIDEO_CAPTURE_STATE_STOPPED)); |
382 EXPECT_CALL(mock_video_capture_host_, Stop(_)); | 394 EXPECT_CALL(mock_video_capture_host_, Stop(_)); |
383 StopCapture(0); | 395 StopCapture(0); |
384 } | 396 } |
385 | 397 |
386 } // namespace content | 398 } // namespace content |
OLD | NEW |