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

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

Issue 8400084: refactor video capture in renderer process (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: code review Created 9 years, 1 month 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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.h" 5 #include "base/message_loop.h"
6 #include "content/common/media/video_capture_messages.h" 6 #include "content/common/media/video_capture_messages.h"
7 #include "content/renderer/media/video_capture_impl.h" 7 #include "content/renderer/media/video_capture_impl.h"
8 #include "testing/gmock/include/gmock/gmock.h" 8 #include "testing/gmock/include/gmock/gmock.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 10
11 using ::testing::_; 11 using ::testing::_;
12 using ::testing::AtLeast; 12 using ::testing::AtLeast;
13 using ::testing::Return; 13 using ::testing::Return;
14 14
15 #define DEFAULT_CAPABILITY_REGULAR {176, 144, 30, 0, media::VideoFrame::I420, \ 15 #define CAPABILITY_SMALL {176, 144, 30, 0, media::VideoFrame::I420, \
16 false, false } 16 false }
17 #define DEFAULT_CAPABILITY_MASTER {320, 240, 20, 0, media::VideoFrame::I420, \ 17 #define CAPABILITY_LARGE {320, 240, 30, 0, media::VideoFrame::I420, \
18 false, true } 18 false }
19 19
20 class MockVideoCaptureMessageFilter : public VideoCaptureMessageFilter { 20 class MockVideoCaptureMessageFilter : public VideoCaptureMessageFilter {
21 public: 21 public:
22 MockVideoCaptureMessageFilter() : VideoCaptureMessageFilter() {} 22 MockVideoCaptureMessageFilter() : VideoCaptureMessageFilter() {}
23 virtual ~MockVideoCaptureMessageFilter() {} 23 virtual ~MockVideoCaptureMessageFilter() {}
24 24
25 // Filter implementation. 25 // Filter implementation.
26 MOCK_METHOD1(Send, bool(IPC::Message* message)); 26 MOCK_METHOD1(Send, bool(IPC::Message* message));
27 27
28 private: 28 private:
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 MockVideoCaptureImpl* video_capture_impl_; 126 MockVideoCaptureImpl* video_capture_impl_;
127 127
128 private: 128 private:
129 DISALLOW_COPY_AND_ASSIGN(VideoCaptureImplTest); 129 DISALLOW_COPY_AND_ASSIGN(VideoCaptureImplTest);
130 }; 130 };
131 131
132 TEST_F(VideoCaptureImplTest, Simple) { 132 TEST_F(VideoCaptureImplTest, Simple) {
133 // Execute SetCapture() and StopCapture() for one client. 133 // Execute SetCapture() and StopCapture() for one client.
134 scoped_ptr<MockVideoCaptureClient> client(new MockVideoCaptureClient); 134 scoped_ptr<MockVideoCaptureClient> client(new MockVideoCaptureClient);
135 media::VideoCapture::VideoCaptureCapability capability = 135 media::VideoCapture::VideoCaptureCapability capability =
136 DEFAULT_CAPABILITY_REGULAR; 136 CAPABILITY_SMALL;
137 137
138 EXPECT_CALL(*client, OnStarted(_)) 138 EXPECT_CALL(*client, OnStarted(_))
139 .WillOnce(Return()); 139 .WillOnce(Return());
140 EXPECT_CALL(*client, OnDeviceInfoReceived(_,_)) 140 EXPECT_CALL(*client, OnDeviceInfoReceived(_,_))
141 .WillOnce(Return()); 141 .WillOnce(Return());
142 142
143 video_capture_impl_->StartCapture(client.get(), capability); 143 video_capture_impl_->StartCapture(client.get(), capability);
144 message_loop_->RunAllPending(); 144 message_loop_->RunAllPending();
145 145
146 EXPECT_CALL(*client, OnStopped(_)) 146 EXPECT_CALL(*client, OnStopped(_))
147 .WillOnce(Return()); 147 .WillOnce(Return());
148 EXPECT_CALL(*client, OnRemoved(_)) 148 EXPECT_CALL(*client, OnRemoved(_))
149 .WillOnce(Return()); 149 .WillOnce(Return());
150 150
151 video_capture_impl_->StopCapture(client.get()); 151 video_capture_impl_->StopCapture(client.get());
152 message_loop_->RunAllPending(); 152 message_loop_->RunAllPending();
153 } 153 }
154 154
155 TEST_F(VideoCaptureImplTest, TwoClientsInSequence) { 155 TEST_F(VideoCaptureImplTest, TwoClientsInSequence) {
156 // Execute SetCapture() and StopCapture() for 2 clients in sequence. 156 // Execute SetCapture() and StopCapture() for 2 clients in sequence.
157 scoped_ptr<MockVideoCaptureClient> client(new MockVideoCaptureClient); 157 scoped_ptr<MockVideoCaptureClient> client(new MockVideoCaptureClient);
158 media::VideoCapture::VideoCaptureCapability capability = 158 media::VideoCapture::VideoCaptureCapability capability =
159 DEFAULT_CAPABILITY_REGULAR; 159 CAPABILITY_SMALL;
160 160
161 EXPECT_CALL(*client, OnStarted(_)) 161 EXPECT_CALL(*client, OnStarted(_))
162 .WillOnce(Return()); 162 .WillOnce(Return());
163 EXPECT_CALL(*client, OnDeviceInfoReceived(_,_)) 163 EXPECT_CALL(*client, OnDeviceInfoReceived(_,_))
164 .WillOnce(Return()); 164 .WillOnce(Return());
165 165
166 video_capture_impl_->StartCapture(client.get(), capability); 166 video_capture_impl_->StartCapture(client.get(), capability);
167 message_loop_->RunAllPending(); 167 message_loop_->RunAllPending();
168 168
169 EXPECT_CALL(*client, OnStopped(_)) 169 EXPECT_CALL(*client, OnStopped(_))
(...skipping 14 matching lines...) Expand all
184 184
185 EXPECT_CALL(*client, OnStopped(_)) 185 EXPECT_CALL(*client, OnStopped(_))
186 .WillOnce(Return()); 186 .WillOnce(Return());
187 EXPECT_CALL(*client, OnRemoved(_)) 187 EXPECT_CALL(*client, OnRemoved(_))
188 .WillOnce(Return()); 188 .WillOnce(Return());
189 189
190 video_capture_impl_->StopCapture(client.get()); 190 video_capture_impl_->StopCapture(client.get());
191 message_loop_->RunAllPending(); 191 message_loop_->RunAllPending();
192 } 192 }
193 193
194 TEST_F(VideoCaptureImplTest, MasterAndRegular) { 194 TEST_F(VideoCaptureImplTest, LargeAndSmall) {
195 // Execute SetCapture() and StopCapture() for 2 clients simultaneously. 195 // Execute SetCapture() and StopCapture() for 2 clients simultaneously.
196 // The master client starts first and stops first. 196 // The large client starts first and stops first.
197 scoped_ptr<MockVideoCaptureClient> client_regular(new MockVideoCaptureClient); 197 scoped_ptr<MockVideoCaptureClient> client_small(new MockVideoCaptureClient);
198 scoped_ptr<MockVideoCaptureClient> client_master(new MockVideoCaptureClient); 198 scoped_ptr<MockVideoCaptureClient> client_large(new MockVideoCaptureClient);
199 media::VideoCapture::VideoCaptureCapability capability_regular = 199 media::VideoCapture::VideoCaptureCapability capability_small =
200 DEFAULT_CAPABILITY_REGULAR; 200 CAPABILITY_SMALL;
201 media::VideoCapture::VideoCaptureCapability capability_master = 201 media::VideoCapture::VideoCaptureCapability capability_large =
202 DEFAULT_CAPABILITY_MASTER; 202 CAPABILITY_LARGE;
203 203
204 EXPECT_CALL(*client_master, OnStarted(_)) 204 EXPECT_CALL(*client_large, OnStarted(_))
205 .WillOnce(Return()); 205 .WillOnce(Return());
206 EXPECT_CALL(*client_master, OnDeviceInfoReceived(_,_)) 206 EXPECT_CALL(*client_large, OnDeviceInfoReceived(_,_))
207 .WillOnce(Return()); 207 .WillOnce(Return());
208 EXPECT_CALL(*client_regular, OnStarted(_)) 208 EXPECT_CALL(*client_small, OnStarted(_))
209 .WillOnce(Return()); 209 .WillOnce(Return());
210 EXPECT_CALL(*client_regular, OnDeviceInfoReceived(_,_)) 210 EXPECT_CALL(*client_small, OnDeviceInfoReceived(_,_))
211 .WillOnce(Return()); 211 .WillOnce(Return());
212 212
213 video_capture_impl_->StartCapture(client_master.get(), capability_master); 213 video_capture_impl_->StartCapture(client_large.get(), capability_large);
214 video_capture_impl_->StartCapture(client_regular.get(), capability_regular); 214 video_capture_impl_->StartCapture(client_small.get(), capability_small);
215 message_loop_->RunAllPending(); 215 message_loop_->RunAllPending();
216 216
217 EXPECT_CALL(*client_master, OnStopped(_)) 217 EXPECT_CALL(*client_large, OnStopped(_))
218 .WillOnce(Return()); 218 .WillOnce(Return());
219 EXPECT_CALL(*client_master, OnRemoved(_)) 219 EXPECT_CALL(*client_large, OnRemoved(_))
220 .WillOnce(Return()); 220 .WillOnce(Return());
221 EXPECT_CALL(*client_regular, OnStopped(_)) 221 EXPECT_CALL(*client_small, OnStopped(_))
222 .WillOnce(Return()); 222 .WillOnce(Return());
223 EXPECT_CALL(*client_regular, OnRemoved(_)) 223 EXPECT_CALL(*client_small, OnRemoved(_))
224 .WillOnce(Return()); 224 .WillOnce(Return());
225 225
226 video_capture_impl_->StopCapture(client_master.get()); 226 video_capture_impl_->StopCapture(client_large.get());
227 video_capture_impl_->StopCapture(client_regular.get()); 227 video_capture_impl_->StopCapture(client_small.get());
228 message_loop_->RunAllPending(); 228 message_loop_->RunAllPending();
229 } 229 }
230 230
231 TEST_F(VideoCaptureImplTest, RegularAndMaster) { 231 TEST_F(VideoCaptureImplTest, SmallAndLarge) {
232 // Execute SetCapture() and StopCapture() for 2 clients simultaneously. 232 // Execute SetCapture() and StopCapture() for 2 clients simultaneously.
233 // The regular client starts first and stops first. 233 // The small client starts first and stops first.
234 scoped_ptr<MockVideoCaptureClient> client_regular(new MockVideoCaptureClient); 234 scoped_ptr<MockVideoCaptureClient> client_small(new MockVideoCaptureClient);
235 scoped_ptr<MockVideoCaptureClient> client_master(new MockVideoCaptureClient); 235 scoped_ptr<MockVideoCaptureClient> client_large(new MockVideoCaptureClient);
236 media::VideoCapture::VideoCaptureCapability capability_regular = 236 media::VideoCapture::VideoCaptureCapability capability_small =
237 DEFAULT_CAPABILITY_REGULAR; 237 CAPABILITY_SMALL;
238 media::VideoCapture::VideoCaptureCapability capability_master = 238 media::VideoCapture::VideoCaptureCapability capability_large =
239 DEFAULT_CAPABILITY_MASTER; 239 CAPABILITY_LARGE;
240 240
241 EXPECT_CALL(*client_master, OnStarted(_)) 241 EXPECT_CALL(*client_large, OnStarted(_))
242 .WillOnce(Return()); 242 .WillOnce(Return());
243 EXPECT_CALL(*client_master, OnDeviceInfoReceived(_,_)) 243 EXPECT_CALL(*client_large, OnDeviceInfoReceived(_,_))
244 .WillOnce(Return()); 244 .WillOnce(Return());
245 EXPECT_CALL(*client_regular, OnStarted(_)) 245 EXPECT_CALL(*client_small, OnStarted(_))
246 .WillOnce(Return()); 246 .WillOnce(Return());
247 EXPECT_CALL(*client_regular, OnDeviceInfoReceived(_,_)) 247 EXPECT_CALL(*client_small, OnDeviceInfoReceived(_,_))
248 .Times(AtLeast(1)) 248 .Times(AtLeast(1))
249 .WillRepeatedly(Return()); 249 .WillRepeatedly(Return());
250 250
251 video_capture_impl_->StartCapture(client_regular.get(), capability_regular); 251 video_capture_impl_->StartCapture(client_small.get(), capability_small);
252 video_capture_impl_->StartCapture(client_master.get(), capability_master); 252 video_capture_impl_->StartCapture(client_large.get(), capability_large);
253 message_loop_->RunAllPending(); 253 message_loop_->RunAllPending();
254 254
255 EXPECT_CALL(*client_master, OnStopped(_)) 255 EXPECT_CALL(*client_large, OnStopped(_))
256 .WillOnce(Return()); 256 .WillOnce(Return());
257 EXPECT_CALL(*client_master, OnRemoved(_)) 257 EXPECT_CALL(*client_large, OnRemoved(_))
258 .WillOnce(Return()); 258 .WillOnce(Return());
259 EXPECT_CALL(*client_regular, OnStopped(_)) 259 EXPECT_CALL(*client_small, OnStopped(_))
260 .WillOnce(Return()); 260 .WillOnce(Return());
261 EXPECT_CALL(*client_regular, OnRemoved(_)) 261 EXPECT_CALL(*client_small, OnRemoved(_))
262 .WillOnce(Return()); 262 .WillOnce(Return());
263 263
264 video_capture_impl_->StopCapture(client_regular.get()); 264 video_capture_impl_->StopCapture(client_small.get());
265 video_capture_impl_->StopCapture(client_master.get()); 265 video_capture_impl_->StopCapture(client_large.get());
266 message_loop_->RunAllPending(); 266 message_loop_->RunAllPending();
267 } 267 }
268 268
269 TEST_F(VideoCaptureImplTest, Master1AndMaster2) { 269 TEST_F(VideoCaptureImplTest, TwoClientsWithSameSize) {
270 // Execute SetCapture() and StopCapture() for 2 master clients simultaneously. 270 // Execute SetCapture() and StopCapture() for 2 clients simultaneously.
271 // The two clients have different resolution. The second client is expected to 271 // The client1 starts first and stops first.
272 // recevie an error. 272 scoped_ptr<MockVideoCaptureClient> client1(new MockVideoCaptureClient);
273 scoped_ptr<MockVideoCaptureClient> client_master1(new MockVideoCaptureClient); 273 scoped_ptr<MockVideoCaptureClient> client2(new MockVideoCaptureClient);
274 scoped_ptr<MockVideoCaptureClient> client_master2(new MockVideoCaptureClient); 274 media::VideoCapture::VideoCaptureCapability capability = CAPABILITY_SMALL;
275 media::VideoCapture::VideoCaptureCapability capability1 =
276 DEFAULT_CAPABILITY_MASTER;
277 media::VideoCapture::VideoCaptureCapability capability2 =
278 DEFAULT_CAPABILITY_MASTER;
279 capability2.width++;
280 275
281 EXPECT_CALL(*client_master1, OnStarted(_)) 276 EXPECT_CALL(*client1, OnStarted(_))
282 .WillOnce(Return()); 277 .WillOnce(Return());
283 EXPECT_CALL(*client_master1, OnDeviceInfoReceived(_,_)) 278 EXPECT_CALL(*client1, OnDeviceInfoReceived(_,_))
284 .WillOnce(Return()); 279 .WillOnce(Return());
285 EXPECT_CALL(*client_master2, OnError(_,_)) 280 EXPECT_CALL(*client2, OnStarted(_))
286 .WillOnce(Return()); 281 .WillOnce(Return());
287 EXPECT_CALL(*client_master2, OnRemoved(_)) 282 EXPECT_CALL(*client2, OnDeviceInfoReceived(_,_))
288 .WillOnce(Return()); 283 .WillOnce(Return());
289 284
290 video_capture_impl_->StartCapture(client_master1.get(), capability1); 285 video_capture_impl_->StartCapture(client1.get(), capability);
291 video_capture_impl_->StartCapture(client_master2.get(), capability2); 286 video_capture_impl_->StartCapture(client2.get(), capability);
292 message_loop_->RunAllPending(); 287 message_loop_->RunAllPending();
293 288
294 EXPECT_CALL(*client_master1, OnStopped(_)) 289 EXPECT_CALL(*client1, OnStopped(_))
295 .WillOnce(Return()); 290 .WillOnce(Return());
296 EXPECT_CALL(*client_master1, OnRemoved(_)) 291 EXPECT_CALL(*client1, OnRemoved(_))
297 .WillOnce(Return()); 292 .WillOnce(Return());
298 EXPECT_CALL(*client_master2, OnStopped(_)) 293 EXPECT_CALL(*client2, OnStopped(_))
299 .Times(0); 294 .WillOnce(Return());
295 EXPECT_CALL(*client2, OnRemoved(_))
296 .WillOnce(Return());
300 297
301 video_capture_impl_->StopCapture(client_master1.get()); 298 video_capture_impl_->StopCapture(client1.get());
302 video_capture_impl_->StopCapture(client_master2.get()); 299 video_capture_impl_->StopCapture(client2.get());
303 message_loop_->RunAllPending(); 300 message_loop_->RunAllPending();
304 } 301 }
OLDNEW
« no previous file with comments | « content/renderer/media/video_capture_impl.cc ('k') | content/renderer/media/video_capture_module_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698