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

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

Issue 263323003: Revert of Refactor video capturing code in the render process (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 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 | Annotate | Revision Log
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 "base/message_loop/message_loop.h" 5 #include "base/message_loop/message_loop.h"
6 #include "base/run_loop.h"
6 #include "content/child/child_process.h" 7 #include "content/child/child_process.h"
7 #include "content/common/media/video_capture_messages.h" 8 #include "content/common/media/video_capture_messages.h"
8 #include "content/renderer/media/video_capture_impl.h" 9 #include "content/renderer/media/video_capture_impl.h"
9 #include "media/base/bind_to_current_loop.h" 10 #include "media/base/bind_to_current_loop.h"
11 #include "media/video/capture/mock_video_capture_event_handler.h"
10 #include "testing/gmock/include/gmock/gmock.h" 12 #include "testing/gmock/include/gmock/gmock.h"
11 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
12 14
13 using ::testing::_; 15 using ::testing::_;
14 using ::testing::AtLeast; 16 using ::testing::AtLeast;
15 using ::testing::InvokeWithoutArgs; 17 using ::testing::InvokeWithoutArgs;
16 using ::testing::Return; 18 using ::testing::Return;
17 using ::testing::SaveArg; 19 using ::testing::SaveArg;
20 using media::MockVideoCaptureEventHandler;
18 21
19 namespace content { 22 namespace content {
20 23
21 class MockVideoCaptureMessageFilter : public VideoCaptureMessageFilter { 24 class MockVideoCaptureMessageFilter : public VideoCaptureMessageFilter {
22 public: 25 public:
23 MockVideoCaptureMessageFilter() : VideoCaptureMessageFilter() {} 26 MockVideoCaptureMessageFilter() : VideoCaptureMessageFilter() {}
24 27
25 // Filter implementation. 28 // Filter implementation.
26 MOCK_METHOD1(Send, bool(IPC::Message* message)); 29 MOCK_METHOD1(Send, bool(IPC::Message* message));
27 30
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 IPC_MESSAGE_UNHANDLED(handled = false) 65 IPC_MESSAGE_UNHANDLED(handled = false)
63 IPC_END_MESSAGE_MAP() 66 IPC_END_MESSAGE_MAP()
64 EXPECT_TRUE(handled); 67 EXPECT_TRUE(handled);
65 delete message; 68 delete message;
66 } 69 }
67 70
68 void DeviceStartCapture(int device_id, 71 void DeviceStartCapture(int device_id,
69 media::VideoCaptureSessionId session_id, 72 media::VideoCaptureSessionId session_id,
70 const media::VideoCaptureParams& params) { 73 const media::VideoCaptureParams& params) {
71 OnStateChanged(VIDEO_CAPTURE_STATE_STARTED); 74 OnStateChanged(VIDEO_CAPTURE_STATE_STARTED);
72 capture_params_ = params;
73 } 75 }
74 76
75 void DevicePauseCapture(int device_id) {} 77 void DevicePauseCapture(int device_id) {}
76 78
77 void DeviceStopCapture(int device_id) { 79 void DeviceStopCapture(int device_id) {
78 OnStateChanged(VIDEO_CAPTURE_STATE_STOPPED); 80 OnStateChanged(VIDEO_CAPTURE_STATE_STOPPED);
79 } 81 }
80 82
81 void DeviceReceiveEmptyBuffer(int device_id, 83 void DeviceReceiveEmptyBuffer(int device_id,
82 int buffer_id, 84 int buffer_id,
83 uint32 sync_point) {} 85 uint32 sync_point) {}
84 86
85 void DeviceGetSupportedFormats(int device_id, 87 void DeviceGetSupportedFormats(int device_id,
86 media::VideoCaptureSessionId session_id) { 88 media::VideoCaptureSessionId session_id) {
87 // When the mock message filter receives a request for the device 89 // When the mock message filter receives a request for the device
88 // supported formats, replies immediately with an empty format list. 90 // supported formats, replies immediately with an empty format list.
89 OnDeviceSupportedFormatsEnumerated( 91 OnDeviceSupportedFormatsEnumerated(
90 media::VideoCaptureFormats()); 92 media::VideoCaptureFormats());
91 } 93 }
92 94
93 void DeviceGetFormatsInUse(int device_id, 95 void DeviceGetFormatsInUse(int device_id,
94 media::VideoCaptureSessionId session_id) { 96 media::VideoCaptureSessionId session_id) {
95 OnDeviceFormatsInUseReceived(media::VideoCaptureFormats()); 97 OnDeviceFormatsInUseReceived(media::VideoCaptureFormats());
96 } 98 }
97
98 const media::VideoCaptureParams& capture_params() const {
99 return capture_params_;
100 }
101
102 private:
103 media::VideoCaptureParams capture_params_;
104 }; 99 };
105 100
106 VideoCaptureImplTest() { 101 VideoCaptureImplTest() {
107 params_small_.requested_format = media::VideoCaptureFormat( 102 params_small_.requested_format = media::VideoCaptureFormat(
108 gfx::Size(176, 144), 30, media::PIXEL_FORMAT_I420); 103 gfx::Size(176, 144), 30, media::PIXEL_FORMAT_I420);
109 104
110 params_large_.requested_format = media::VideoCaptureFormat( 105 params_large_.requested_format = media::VideoCaptureFormat(
111 gfx::Size(320, 240), 30, media::PIXEL_FORMAT_I420); 106 gfx::Size(320, 240), 30, media::PIXEL_FORMAT_I420);
112 107
113 child_process_.reset(new ChildProcess()); 108 child_process_.reset(new ChildProcess());
114 109
115 message_filter_ = new MockVideoCaptureMessageFilter; 110 message_filter_ = new MockVideoCaptureMessageFilter;
116 session_id_ = 1; 111 session_id_ = 1;
117 112
118 video_capture_impl_.reset(new MockVideoCaptureImpl( 113 video_capture_impl_ = new MockVideoCaptureImpl(
119 session_id_, message_filter_.get())); 114 session_id_, message_filter_.get());
120 115
121 video_capture_impl_->device_id_ = 2; 116 video_capture_impl_->device_id_ = 2;
122 } 117 }
123 118
124 virtual ~VideoCaptureImplTest() { 119 virtual ~VideoCaptureImplTest() {
120 delete video_capture_impl_;
125 } 121 }
126 122
127 protected: 123 protected:
128 MOCK_METHOD2(OnFrameReady,
129 void(const scoped_refptr<media::VideoFrame>&,
130 const media::VideoCaptureFormat&));
131 MOCK_METHOD1(OnStateUpdate, void(VideoCaptureState));
132 MOCK_METHOD1(OnDeviceFormatsInUse,
133 void(const media::VideoCaptureFormats&));
134 MOCK_METHOD1(OnDeviceSupportedFormats,
135 void(const media::VideoCaptureFormats&));
136
137 void Init() {
138 video_capture_impl_->Init();
139 }
140
141 void StartCapture(int client_id,
142 const media::VideoCaptureParams& params) {
143 video_capture_impl_->StartCapture(
144 client_id, params,
145 base::Bind(&VideoCaptureImplTest::OnStateUpdate,
146 base::Unretained(this)),
147 base::Bind(&VideoCaptureImplTest::OnFrameReady,
148 base::Unretained(this)));
149 }
150
151 void StopCapture(int client_id) {
152 video_capture_impl_->StopCapture(client_id);
153 }
154
155 void DeInit() {
156 video_capture_impl_->DeInit();
157 }
158
159 void GetDeviceSupportedFormats() {
160 const base::Callback<void(const media::VideoCaptureFormats&)>
161 callback = base::Bind(
162 &VideoCaptureImplTest::OnDeviceSupportedFormats,
163 base::Unretained(this));
164 video_capture_impl_->GetDeviceSupportedFormats(callback);
165 }
166
167 void GetDeviceFormatsInUse() {
168 const base::Callback<void(const media::VideoCaptureFormats&)>
169 callback = base::Bind(
170 &VideoCaptureImplTest::OnDeviceFormatsInUse,
171 base::Unretained(this));
172 video_capture_impl_->GetDeviceFormatsInUse(callback);
173 }
174
175 base::MessageLoop message_loop_; 124 base::MessageLoop message_loop_;
125 base::RunLoop run_loop_;
176 scoped_ptr<ChildProcess> child_process_; 126 scoped_ptr<ChildProcess> child_process_;
177 scoped_refptr<MockVideoCaptureMessageFilter> message_filter_; 127 scoped_refptr<MockVideoCaptureMessageFilter> message_filter_;
178 media::VideoCaptureSessionId session_id_; 128 media::VideoCaptureSessionId session_id_;
179 scoped_ptr<MockVideoCaptureImpl> video_capture_impl_; 129 MockVideoCaptureImpl* video_capture_impl_;
180 media::VideoCaptureParams params_small_; 130 media::VideoCaptureParams params_small_;
181 media::VideoCaptureParams params_large_; 131 media::VideoCaptureParams params_large_;
182 132
183 private: 133 private:
184 DISALLOW_COPY_AND_ASSIGN(VideoCaptureImplTest); 134 DISALLOW_COPY_AND_ASSIGN(VideoCaptureImplTest);
185 }; 135 };
186 136
187 TEST_F(VideoCaptureImplTest, Simple) { 137 TEST_F(VideoCaptureImplTest, Simple) {
188 // Execute SetCapture() and StopCapture() for one client. 138 // Execute SetCapture() and StopCapture() for one client.
189 EXPECT_CALL(*this, OnStateUpdate(VIDEO_CAPTURE_STATE_STARTED)); 139 scoped_ptr<MockVideoCaptureEventHandler> client(
190 EXPECT_CALL(*this, OnStateUpdate(VIDEO_CAPTURE_STATE_STOPPED)); 140 new MockVideoCaptureEventHandler);
191 141
192 Init(); 142 EXPECT_CALL(*client, OnStarted(_));
193 StartCapture(0, params_small_); 143 EXPECT_CALL(*client, OnStopped(_));
194 StopCapture(0); 144 EXPECT_CALL(*client, OnRemoved(_));
195 DeInit(); 145
146 video_capture_impl_->StartCapture(client.get(), params_small_);
147 video_capture_impl_->StopCapture(client.get());
148 video_capture_impl_->DeInit(
149 media::BindToCurrentLoop(run_loop_.QuitClosure()));
150 run_loop_.Run();
196 } 151 }
197 152
198 TEST_F(VideoCaptureImplTest, TwoClientsInSequence) { 153 TEST_F(VideoCaptureImplTest, TwoClientsInSequence) {
199 EXPECT_CALL(*this, OnStateUpdate(VIDEO_CAPTURE_STATE_STARTED)).Times(2); 154 // Execute SetCapture() and StopCapture() for 2 clients in sequence.
200 EXPECT_CALL(*this, OnStateUpdate(VIDEO_CAPTURE_STATE_STOPPED)).Times(2); 155 scoped_ptr<MockVideoCaptureEventHandler> client1(
156 new MockVideoCaptureEventHandler);
157 scoped_ptr<MockVideoCaptureEventHandler> client2(
158 new MockVideoCaptureEventHandler);
201 159
202 Init(); 160 EXPECT_CALL(*client1, OnStarted(_));
203 StartCapture(0, params_small_); 161 EXPECT_CALL(*client1, OnStopped(_));
204 StopCapture(0); 162 EXPECT_CALL(*client1, OnRemoved(_));
205 StartCapture(1, params_small_); 163 EXPECT_CALL(*client2, OnStarted(_));
206 StopCapture(1); 164 EXPECT_CALL(*client2, OnStopped(_));
207 DeInit(); 165 EXPECT_CALL(*client2, OnRemoved(_));
166
167 video_capture_impl_->StartCapture(client1.get(), params_small_);
168 video_capture_impl_->StopCapture(client1.get());
169 video_capture_impl_->StartCapture(client2.get(), params_small_);
170 video_capture_impl_->StopCapture(client2.get());
171 video_capture_impl_->DeInit(
172 media::BindToCurrentLoop(run_loop_.QuitClosure()));
173 run_loop_.Run();
208 } 174 }
209 175
210 TEST_F(VideoCaptureImplTest, LargeAndSmall) { 176 TEST_F(VideoCaptureImplTest, LargeAndSmall) {
211 EXPECT_CALL(*this, OnStateUpdate(VIDEO_CAPTURE_STATE_STARTED)).Times(2); 177 // Execute SetCapture() and StopCapture() for 2 clients simultaneously.
212 EXPECT_CALL(*this, OnStateUpdate(VIDEO_CAPTURE_STATE_STOPPED)).Times(2); 178 // The large client starts first and stops first.
179 scoped_ptr<MockVideoCaptureEventHandler> client_small(
180 new MockVideoCaptureEventHandler);
181 scoped_ptr<MockVideoCaptureEventHandler> client_large(
182 new MockVideoCaptureEventHandler);
213 183
214 Init(); 184 EXPECT_CALL(*client_large, OnStarted(_));
215 StartCapture(0, params_large_); 185 EXPECT_CALL(*client_small, OnStarted(_));
216 StopCapture(0); 186 EXPECT_CALL(*client_large, OnStopped(_));
217 StartCapture(1, params_small_); 187 EXPECT_CALL(*client_large, OnRemoved(_));
218 StopCapture(1); 188 EXPECT_CALL(*client_small, OnStopped(_));
219 DeInit(); 189 EXPECT_CALL(*client_small, OnRemoved(_));
190
191 video_capture_impl_->StartCapture(client_large.get(), params_large_);
192 video_capture_impl_->StartCapture(client_small.get(), params_small_);
193 video_capture_impl_->StopCapture(client_large.get());
194 video_capture_impl_->StopCapture(client_small.get());
195 video_capture_impl_->DeInit(
196 media::BindToCurrentLoop(run_loop_.QuitClosure()));
197 run_loop_.Run();
220 } 198 }
221 199
222 TEST_F(VideoCaptureImplTest, SmallAndLarge) { 200 TEST_F(VideoCaptureImplTest, SmallAndLarge) {
223 EXPECT_CALL(*this, OnStateUpdate(VIDEO_CAPTURE_STATE_STARTED)).Times(2); 201 // Execute SetCapture() and StopCapture() for 2 clients simultaneously.
224 EXPECT_CALL(*this, OnStateUpdate(VIDEO_CAPTURE_STATE_STOPPED)).Times(2); 202 // The small client starts first and stops first.
203 scoped_ptr<MockVideoCaptureEventHandler> client_small(
204 new MockVideoCaptureEventHandler);
205 scoped_ptr<MockVideoCaptureEventHandler> client_large(
206 new MockVideoCaptureEventHandler);
225 207
226 Init(); 208 EXPECT_CALL(*client_small, OnStarted(_));
227 StartCapture(0, params_small_); 209 EXPECT_CALL(*client_large, OnStarted(_));
228 StopCapture(0); 210 EXPECT_CALL(*client_small, OnStopped(_));
229 StartCapture(1, params_large_); 211 EXPECT_CALL(*client_small, OnRemoved(_));
230 StopCapture(1); 212 EXPECT_CALL(*client_large, OnStopped(_));
231 DeInit(); 213 EXPECT_CALL(*client_large, OnRemoved(_));
214
215 video_capture_impl_->StartCapture(client_small.get(), params_small_);
216 video_capture_impl_->StartCapture(client_large.get(), params_large_);
217 video_capture_impl_->StopCapture(client_small.get());
218 video_capture_impl_->StopCapture(client_large.get());
219 video_capture_impl_->DeInit(
220 media::BindToCurrentLoop(run_loop_.QuitClosure()));
221 run_loop_.Run();
232 } 222 }
233 223
234 // Check that a request to GetDeviceSupportedFormats() ends up eventually in the 224 // Check that a request to GetDeviceSupportedFormats() ends up eventually in the
235 // provided callback. 225 // provided callback.
236 TEST_F(VideoCaptureImplTest, GetDeviceFormats) { 226 TEST_F(VideoCaptureImplTest, GetDeviceFormats) {
237 EXPECT_CALL(*this, OnDeviceSupportedFormats(_)); 227 scoped_ptr<MockVideoCaptureEventHandler> client(
228 new MockVideoCaptureEventHandler);
238 229
239 Init(); 230 EXPECT_CALL(*client, OnDeviceSupportedFormatsEnumerated(_));
240 GetDeviceSupportedFormats(); 231
241 DeInit(); 232 const base::Callback<void(const media::VideoCaptureFormats&)>
233 callback = base::Bind(
234 &MockVideoCaptureEventHandler::OnDeviceSupportedFormatsEnumerated,
235 base::Unretained(client.get()));
236 video_capture_impl_->GetDeviceSupportedFormats(callback);
237 video_capture_impl_->DeInit(
238 media::BindToCurrentLoop(run_loop_.QuitClosure()));
239 run_loop_.Run();
242 } 240 }
243 241
244 // Check that two requests to GetDeviceSupportedFormats() end up eventually 242 // Check that two requests to GetDeviceSupportedFormats() end up eventually
245 // calling the provided callbacks. 243 // calling the provided callbacks.
246 TEST_F(VideoCaptureImplTest, TwoClientsGetDeviceFormats) { 244 TEST_F(VideoCaptureImplTest, TwoClientsGetDeviceFormats) {
247 EXPECT_CALL(*this, OnDeviceSupportedFormats(_)).Times(2); 245 scoped_ptr<MockVideoCaptureEventHandler> client1(
246 new MockVideoCaptureEventHandler);
247 scoped_ptr<MockVideoCaptureEventHandler> client2(
248 new MockVideoCaptureEventHandler);
248 249
249 Init(); 250 EXPECT_CALL(*client1, OnDeviceSupportedFormatsEnumerated(_));
250 GetDeviceSupportedFormats(); 251 EXPECT_CALL(*client2, OnDeviceSupportedFormatsEnumerated(_));
251 GetDeviceSupportedFormats(); 252
252 DeInit(); 253 const base::Callback<void(const media::VideoCaptureFormats&)>
254 callback1 = base::Bind(
255 &MockVideoCaptureEventHandler::OnDeviceSupportedFormatsEnumerated,
256 base::Unretained(client1.get()));
257 const base::Callback<void(const media::VideoCaptureFormats&)>
258 callback2 = base::Bind(
259 &MockVideoCaptureEventHandler::OnDeviceSupportedFormatsEnumerated,
260 base::Unretained(client2.get()));
261
262 video_capture_impl_->GetDeviceSupportedFormats(callback1);
263 video_capture_impl_->GetDeviceSupportedFormats(callback2);
264 video_capture_impl_->DeInit(
265 media::BindToCurrentLoop(run_loop_.QuitClosure()));
266 run_loop_.Run();
253 } 267 }
254 268
255 // Check that a request to GetDeviceFormatsInUse() ends up eventually in the 269 // Check that a request to GetDeviceFormatsInUse() ends up eventually in the
256 // provided callback. 270 // provided callback.
257 TEST_F(VideoCaptureImplTest, GetDeviceFormatsInUse) { 271 TEST_F(VideoCaptureImplTest, GetDeviceFormatsInUse) {
258 EXPECT_CALL(*this, OnDeviceFormatsInUse(_)); 272 scoped_ptr<MockVideoCaptureEventHandler> client(
273 new MockVideoCaptureEventHandler);
259 274
260 Init(); 275 media::VideoCaptureFormats formats_in_use;
261 GetDeviceFormatsInUse(); 276 EXPECT_CALL(*client, OnDeviceFormatsInUseReceived(_))
262 DeInit(); 277 .WillOnce(SaveArg<0>(&formats_in_use));
263 }
264 278
265 TEST_F(VideoCaptureImplTest, AlreadyStarted) { 279 const base::Callback<void(const media::VideoCaptureFormats&)> callback =
266 EXPECT_CALL(*this, OnStateUpdate(VIDEO_CAPTURE_STATE_STARTED)).Times(2); 280 base::Bind(&MockVideoCaptureEventHandler::OnDeviceFormatsInUseReceived,
267 EXPECT_CALL(*this, OnStateUpdate(VIDEO_CAPTURE_STATE_STOPPED)).Times(2); 281 base::Unretained(client.get()));
282 video_capture_impl_->GetDeviceFormatsInUse(callback);
283 video_capture_impl_->DeInit(
284 media::BindToCurrentLoop(run_loop_.QuitClosure()));
285 run_loop_.Run();
268 286
269 Init(); 287 EXPECT_TRUE(formats_in_use.empty());
270 StartCapture(0, params_small_);
271 StartCapture(1, params_large_);
272 StopCapture(0);
273 StopCapture(1);
274 DeInit();
275 DCHECK(video_capture_impl_->capture_params().requested_format
276 .frame_size ==
277 params_small_.requested_format.frame_size);
278 } 288 }
279 289
280 } // namespace content 290 } // 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