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

Side by Side Diff: content/renderer/media/video_capture_impl_unittest.cc

Issue 2400443006: VideoCapture: moar VideoCapture renderer-->host messages to mojo, part 3 (Closed)
Patch Set: minor rebase Created 4 years, 2 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 (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/media/video_capture_messages.h" 11 #include "content/common/media/video_capture_messages.h"
12 #include "content/common/video_capture.mojom.h" 12 #include "content/common/video_capture.mojom.h"
13 #include "content/renderer/media/video_capture_impl.h" 13 #include "content/renderer/media/video_capture_impl.h"
14 #include "media/base/bind_to_current_loop.h" 14 #include "media/base/bind_to_current_loop.h"
15 #include "testing/gmock/include/gmock/gmock.h" 15 #include "testing/gmock/include/gmock/gmock.h"
16 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
17 17
18 using ::testing::_; 18 using ::testing::_;
19 using ::testing::Invoke;
19 using ::testing::SaveArg; 20 using ::testing::SaveArg;
21 using ::testing::WithArgs;
20 22
21 namespace content { 23 namespace content {
22 24
23 const int kSessionId = 1; 25 const int kSessionId = 1;
24 26
27 void RunEmptyFormatsCallback(const VideoCaptureDeviceFormatsCB& callback) {
28 media::VideoCaptureFormats formats;
29 callback.Run(formats);
30 }
31
25 // Mock implementation of the Mojo service. TODO(mcasas): Replace completely 32 // Mock implementation of the Mojo service. TODO(mcasas): Replace completely
26 // MockVideoCaptureMessageFilter, https://crbug.com/651897 33 // MockVideoCaptureMessageFilter, https://crbug.com/651897
27 class MockMojoVideoCaptureHost : public mojom::VideoCaptureHost { 34 class MockMojoVideoCaptureHost : public mojom::VideoCaptureHost {
28 public: 35 public:
29 MockMojoVideoCaptureHost() = default; 36 MockMojoVideoCaptureHost() {
37 ON_CALL(*this, GetDeviceSupportedFormats(_, _, _))
38 .WillByDefault(WithArgs<2>(Invoke(RunEmptyFormatsCallback)));
39 ON_CALL(*this, GetDeviceFormatsInUse(_, _, _))
40 .WillByDefault(WithArgs<2>(Invoke(RunEmptyFormatsCallback)));
41 }
30 42
31 MOCK_METHOD3(Start, void(int32_t, int32_t, const media::VideoCaptureParams&)); 43 MOCK_METHOD3(Start, void(int32_t, int32_t, const media::VideoCaptureParams&));
32 MOCK_METHOD1(Stop, void(int32_t)); 44 MOCK_METHOD1(Stop, void(int32_t));
33 MOCK_METHOD1(Pause, void(int32_t)); 45 MOCK_METHOD1(Pause, void(int32_t));
34 MOCK_METHOD3(Resume, 46 MOCK_METHOD3(Resume,
35 void(int32_t, int32_t, const media::VideoCaptureParams&)); 47 void(int32_t, int32_t, const media::VideoCaptureParams&));
36 MOCK_METHOD1(RequestRefreshFrame, void(int32_t)); 48 MOCK_METHOD1(RequestRefreshFrame, void(int32_t));
49 MOCK_METHOD3(GetDeviceSupportedFormats,
50 void(int32_t,
51 int32_t,
52 const GetDeviceSupportedFormatsCallback&));
53 MOCK_METHOD3(GetDeviceFormatsInUse,
54 void(int32_t, int32_t, const GetDeviceFormatsInUseCallback&));
37 55
38 private: 56 private:
39 DISALLOW_COPY_AND_ASSIGN(MockMojoVideoCaptureHost); 57 DISALLOW_COPY_AND_ASSIGN(MockMojoVideoCaptureHost);
40 }; 58 };
41 59
42 class MockVideoCaptureMessageFilter : public VideoCaptureMessageFilter { 60 class MockVideoCaptureMessageFilter : public VideoCaptureMessageFilter {
43 public: 61 public:
44 MockVideoCaptureMessageFilter() : VideoCaptureMessageFilter() {} 62 MockVideoCaptureMessageFilter() : VideoCaptureMessageFilter() {}
45 63
46 // Filter implementation. 64 // Filter implementation.
(...skipping 14 matching lines...) Expand all
61 VideoCaptureMessageFilter* filter) 79 VideoCaptureMessageFilter* filter)
62 : VideoCaptureImpl(id, filter, base::ThreadTaskRunnerHandle::Get()), 80 : VideoCaptureImpl(id, filter, base::ThreadTaskRunnerHandle::Get()),
63 received_buffer_count_(0) {} 81 received_buffer_count_(0) {}
64 ~MockVideoCaptureImpl() override {} 82 ~MockVideoCaptureImpl() override {}
65 83
66 void Send(IPC::Message* message) override { 84 void Send(IPC::Message* message) override {
67 bool handled = true; 85 bool handled = true;
68 IPC_BEGIN_MESSAGE_MAP(MockVideoCaptureImpl, *message) 86 IPC_BEGIN_MESSAGE_MAP(MockVideoCaptureImpl, *message)
69 IPC_MESSAGE_HANDLER(VideoCaptureHostMsg_BufferReady, 87 IPC_MESSAGE_HANDLER(VideoCaptureHostMsg_BufferReady,
70 DeviceReceiveEmptyBuffer) 88 DeviceReceiveEmptyBuffer)
71 IPC_MESSAGE_HANDLER(VideoCaptureHostMsg_GetDeviceSupportedFormats,
72 DeviceGetSupportedFormats)
73 IPC_MESSAGE_HANDLER(VideoCaptureHostMsg_GetDeviceFormatsInUse,
74 DeviceGetFormatsInUse)
75 IPC_MESSAGE_UNHANDLED(handled = false) 89 IPC_MESSAGE_UNHANDLED(handled = false)
76 IPC_END_MESSAGE_MAP() 90 IPC_END_MESSAGE_MAP()
77 EXPECT_TRUE(handled); 91 EXPECT_TRUE(handled);
78 delete message; 92 delete message;
79 } 93 }
80 94
81 void DeviceReceiveEmptyBuffer(int device_id, 95 void DeviceReceiveEmptyBuffer(int device_id,
82 int buffer_id, 96 int buffer_id,
83 const gpu::SyncToken& release_sync_token, 97 const gpu::SyncToken& release_sync_token,
84 double consumer_resource_utilization) { 98 double consumer_resource_utilization) {
85 received_buffer_count_++; 99 received_buffer_count_++;
86 } 100 }
87 101
88 void DeviceGetSupportedFormats(int device_id,
89 media::VideoCaptureSessionId session_id) {
90 // When the mock message filter receives a request for the device
91 // supported formats, replies immediately with an empty format list.
92 OnDeviceSupportedFormatsEnumerated(media::VideoCaptureFormats());
93 }
94
95 void DeviceGetFormatsInUse(int device_id,
96 media::VideoCaptureSessionId session_id) {
97 OnDeviceFormatsInUseReceived(media::VideoCaptureFormats());
98 }
99
100 void ReceiveStateChangeMessage(VideoCaptureState state) { 102 void ReceiveStateChangeMessage(VideoCaptureState state) {
101 OnStateChanged(state); 103 OnStateChanged(state);
102 } 104 }
103 105
104 int received_buffer_count() const { return received_buffer_count_; } 106 int received_buffer_count() const { return received_buffer_count_; }
105 107
106 private: 108 private:
107 int received_buffer_count_; 109 int received_buffer_count_;
108 }; 110 };
109 111
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 StartCapture(0, params_small_); 239 StartCapture(0, params_small_);
238 StopCapture(0); 240 StopCapture(0);
239 StartCapture(1, params_large_); 241 StartCapture(1, params_large_);
240 StopCapture(1); 242 StopCapture(1);
241 } 243 }
242 244
243 // Checks that a request to GetDeviceSupportedFormats() ends up eventually in 245 // Checks that a request to GetDeviceSupportedFormats() ends up eventually in
244 // the provided callback. 246 // the provided callback.
245 TEST_F(VideoCaptureImplTest, GetDeviceFormats) { 247 TEST_F(VideoCaptureImplTest, GetDeviceFormats) {
246 EXPECT_CALL(*this, OnDeviceSupportedFormats(_)); 248 EXPECT_CALL(*this, OnDeviceSupportedFormats(_));
249 EXPECT_CALL(mock_video_capture_host_,
250 GetDeviceSupportedFormats(_, kSessionId, _));
247 251
248 GetDeviceSupportedFormats(); 252 GetDeviceSupportedFormats();
249 } 253 }
250 254
251 // Checks that two requests to GetDeviceSupportedFormats() end up eventually 255 // Checks that two requests to GetDeviceSupportedFormats() end up eventually
252 // calling the provided callbacks. 256 // calling the provided callbacks.
253 TEST_F(VideoCaptureImplTest, TwoClientsGetDeviceFormats) { 257 TEST_F(VideoCaptureImplTest, TwoClientsGetDeviceFormats) {
254 EXPECT_CALL(*this, OnDeviceSupportedFormats(_)).Times(2); 258 EXPECT_CALL(*this, OnDeviceSupportedFormats(_)).Times(2);
259 EXPECT_CALL(mock_video_capture_host_,
260 GetDeviceSupportedFormats(_, kSessionId, _))
261 .Times(2);
255 262
256 GetDeviceSupportedFormats(); 263 GetDeviceSupportedFormats();
257 GetDeviceSupportedFormats(); 264 GetDeviceSupportedFormats();
258 } 265 }
259 266
260 // Checks that a request to GetDeviceFormatsInUse() ends up eventually in the 267 // Checks that a request to GetDeviceFormatsInUse() ends up eventually in the
261 // provided callback. 268 // provided callback.
262 TEST_F(VideoCaptureImplTest, GetDeviceFormatsInUse) { 269 TEST_F(VideoCaptureImplTest, GetDeviceFormatsInUse) {
263 EXPECT_CALL(*this, OnDeviceFormatsInUse(_)); 270 EXPECT_CALL(*this, OnDeviceFormatsInUse(_));
271 EXPECT_CALL(mock_video_capture_host_,
272 GetDeviceFormatsInUse(_, kSessionId, _));
264 273
265 GetDeviceFormatsInUse(); 274 GetDeviceFormatsInUse();
266 } 275 }
267 276
268 TEST_F(VideoCaptureImplTest, BufferReceived) { 277 TEST_F(VideoCaptureImplTest, BufferReceived) {
269 base::SharedMemory shm; 278 base::SharedMemory shm;
270 const size_t frame_size = media::VideoFrame::AllocationSize( 279 const size_t frame_size = media::VideoFrame::AllocationSize(
271 media::PIXEL_FORMAT_I420, params_small_.requested_format.frame_size); 280 media::PIXEL_FORMAT_I420, params_small_.requested_format.frame_size);
272 ASSERT_TRUE(shm.CreateAndMapAnonymous(frame_size)); 281 ASSERT_TRUE(shm.CreateAndMapAnonymous(frame_size));
273 282
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 EXPECT_CALL(mock_video_capture_host_, Start(_, kSessionId, params_small_)); 347 EXPECT_CALL(mock_video_capture_host_, Start(_, kSessionId, params_small_));
339 348
340 StartCapture(0, params_small_); 349 StartCapture(0, params_small_);
341 350
342 video_capture_impl_->ReceiveStateChangeMessage(VIDEO_CAPTURE_STATE_ERROR); 351 video_capture_impl_->ReceiveStateChangeMessage(VIDEO_CAPTURE_STATE_ERROR);
343 352
344 StopCapture(0); 353 StopCapture(0);
345 } 354 }
346 355
347 } // namespace content 356 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/media/video_capture_impl_manager_unittest.cc ('k') | content/renderer/media/video_capture_message_filter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698