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

Side by Side Diff: content/browser/renderer_host/media/video_capture_manager_unittest.cc

Issue 10912004: Begin adding support for tab mirroring via the MediaStream audio/video capturing (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: REBASE Created 8 years, 3 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 // Unit test for VideoCaptureManager. 5 // Unit test for VideoCaptureManager.
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/memory/ref_counted.h" 10 #include "base/memory/ref_counted.h"
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 }; 102 };
103 103
104 // Test cases 104 // Test cases
105 105
106 // Try to open, start, stop and close a device. 106 // Try to open, start, stop and close a device.
107 TEST_F(VideoCaptureManagerTest, CreateAndClose) { 107 TEST_F(VideoCaptureManagerTest, CreateAndClose) {
108 InSequence s; 108 InSequence s;
109 EXPECT_CALL(*listener_, DevicesEnumerated(_)) 109 EXPECT_CALL(*listener_, DevicesEnumerated(_))
110 .Times(1); 110 .Times(1);
111 EXPECT_CALL(*listener_, 111 EXPECT_CALL(*listener_,
112 Opened(content::MEDIA_STREAM_DEVICE_TYPE_VIDEO_CAPTURE, _)) 112 Opened(content::MEDIA_DEVICE_VIDEO_CAPTURE, _))
113 .Times(1); 113 .Times(1);
114 EXPECT_CALL(*listener_, 114 EXPECT_CALL(*listener_,
115 Closed(content::MEDIA_STREAM_DEVICE_TYPE_VIDEO_CAPTURE, _)) 115 Closed(content::MEDIA_DEVICE_VIDEO_CAPTURE, _))
116 .Times(1); 116 .Times(1);
117 117
118 vcm_->EnumerateDevices(); 118 vcm_->EnumerateDevices();
119 119
120 // Wait to get device callback. 120 // Wait to get device callback.
121 message_loop_->RunAllPending(); 121 message_loop_->RunAllPending();
122 122
123 int video_session_id = vcm_->Open(listener_->devices_.front()); 123 int video_session_id = vcm_->Open(listener_->devices_.front());
124 124
125 media::VideoCaptureParams capture_params; 125 media::VideoCaptureParams capture_params;
(...skipping 10 matching lines...) Expand all
136 message_loop_->RunAllPending(); 136 message_loop_->RunAllPending();
137 vcm_->Unregister(); 137 vcm_->Unregister();
138 } 138 }
139 139
140 // Open the same device twice. 140 // Open the same device twice.
141 TEST_F(VideoCaptureManagerTest, OpenTwice) { 141 TEST_F(VideoCaptureManagerTest, OpenTwice) {
142 InSequence s; 142 InSequence s;
143 EXPECT_CALL(*listener_, DevicesEnumerated(_)) 143 EXPECT_CALL(*listener_, DevicesEnumerated(_))
144 .Times(1); 144 .Times(1);
145 EXPECT_CALL(*listener_, 145 EXPECT_CALL(*listener_,
146 Opened(content::MEDIA_STREAM_DEVICE_TYPE_VIDEO_CAPTURE, _)) 146 Opened(content::MEDIA_DEVICE_VIDEO_CAPTURE, _))
147 .Times(2); 147 .Times(2);
148 EXPECT_CALL(*listener_, 148 EXPECT_CALL(*listener_,
149 Closed(content::MEDIA_STREAM_DEVICE_TYPE_VIDEO_CAPTURE, _)) 149 Closed(content::MEDIA_DEVICE_VIDEO_CAPTURE, _))
150 .Times(2); 150 .Times(2);
151 151
152 vcm_->EnumerateDevices(); 152 vcm_->EnumerateDevices();
153 153
154 // Wait to get device callback. 154 // Wait to get device callback.
155 message_loop_->RunAllPending(); 155 message_loop_->RunAllPending();
156 156
157 int video_session_id_first = vcm_->Open(listener_->devices_.front()); 157 int video_session_id_first = vcm_->Open(listener_->devices_.front());
158 158
159 // This should trigger an error callback with error code 159 // This should trigger an error callback with error code
160 // 'kDeviceAlreadyInUse'. 160 // 'kDeviceAlreadyInUse'.
161 int video_session_id_second = vcm_->Open(listener_->devices_.front()); 161 int video_session_id_second = vcm_->Open(listener_->devices_.front());
162 EXPECT_NE(video_session_id_first, video_session_id_second); 162 EXPECT_NE(video_session_id_first, video_session_id_second);
163 163
164 vcm_->Close(video_session_id_first); 164 vcm_->Close(video_session_id_first);
165 vcm_->Close(video_session_id_second); 165 vcm_->Close(video_session_id_second);
166 166
167 // Wait to check callbacks before removing the listener. 167 // Wait to check callbacks before removing the listener.
168 message_loop_->RunAllPending(); 168 message_loop_->RunAllPending();
169 vcm_->Unregister(); 169 vcm_->Unregister();
170 } 170 }
171 171
172 // Open two different devices. 172 // Open two different devices.
173 TEST_F(VideoCaptureManagerTest, OpenTwo) { 173 TEST_F(VideoCaptureManagerTest, OpenTwo) {
174 InSequence s; 174 InSequence s;
175 EXPECT_CALL(*listener_, DevicesEnumerated(_)) 175 EXPECT_CALL(*listener_, DevicesEnumerated(_))
176 .Times(1); 176 .Times(1);
177 EXPECT_CALL(*listener_, 177 EXPECT_CALL(*listener_,
178 Opened(content::MEDIA_STREAM_DEVICE_TYPE_VIDEO_CAPTURE, _)) 178 Opened(content::MEDIA_DEVICE_VIDEO_CAPTURE, _))
179 .Times(2); 179 .Times(2);
180 EXPECT_CALL(*listener_, 180 EXPECT_CALL(*listener_,
181 Closed(content::MEDIA_STREAM_DEVICE_TYPE_VIDEO_CAPTURE, _)) 181 Closed(content::MEDIA_DEVICE_VIDEO_CAPTURE, _))
182 .Times(2); 182 .Times(2);
183 183
184 vcm_->EnumerateDevices(); 184 vcm_->EnumerateDevices();
185 185
186 // Wait to get device callback. 186 // Wait to get device callback.
187 message_loop_->RunAllPending(); 187 message_loop_->RunAllPending();
188 188
189 media_stream::StreamDeviceInfoArray::iterator it = 189 media_stream::StreamDeviceInfoArray::iterator it =
190 listener_->devices_.begin(); 190 listener_->devices_.begin();
191 191
192 int video_session_id_first = vcm_->Open(*it); 192 int video_session_id_first = vcm_->Open(*it);
193 ++it; 193 ++it;
194 int video_session_id_second = vcm_->Open(*it); 194 int video_session_id_second = vcm_->Open(*it);
195 195
196 vcm_->Close(video_session_id_first); 196 vcm_->Close(video_session_id_first);
197 vcm_->Close(video_session_id_second); 197 vcm_->Close(video_session_id_second);
198 198
199 // Wait to check callbacks before removing the listener. 199 // Wait to check callbacks before removing the listener.
200 message_loop_->RunAllPending(); 200 message_loop_->RunAllPending();
201 vcm_->Unregister(); 201 vcm_->Unregister();
202 } 202 }
203 203
204 // Try open a non-existing device. 204 // Try open a non-existing device.
205 TEST_F(VideoCaptureManagerTest, OpenNotExisting) { 205 TEST_F(VideoCaptureManagerTest, OpenNotExisting) {
206 InSequence s; 206 InSequence s;
207 EXPECT_CALL(*listener_, DevicesEnumerated(_)) 207 EXPECT_CALL(*listener_, DevicesEnumerated(_))
208 .Times(1); 208 .Times(1);
209 EXPECT_CALL(*listener_, Error(content::MEDIA_STREAM_DEVICE_TYPE_VIDEO_CAPTURE, 209 EXPECT_CALL(*listener_, Error(content::MEDIA_DEVICE_VIDEO_CAPTURE,
210 _, media_stream::kDeviceNotAvailable)) 210 _, media_stream::kDeviceNotAvailable))
211 .Times(1); 211 .Times(1);
212 212
213 vcm_->EnumerateDevices(); 213 vcm_->EnumerateDevices();
214 214
215 // Wait to get device callback. 215 // Wait to get device callback.
216 message_loop_->RunAllPending(); 216 message_loop_->RunAllPending();
217 217
218 media_stream::MediaStreamType stream_type = 218 media_stream::MediaStreamType stream_type =
219 content::MEDIA_STREAM_DEVICE_TYPE_VIDEO_CAPTURE; 219 content::MEDIA_DEVICE_VIDEO_CAPTURE;
220 std::string device_name("device_doesnt_exist"); 220 std::string device_name("device_doesnt_exist");
221 std::string device_id("id_doesnt_exist"); 221 std::string device_id("id_doesnt_exist");
222 media_stream::StreamDeviceInfo dummy_device(stream_type, device_name, 222 media_stream::StreamDeviceInfo dummy_device(stream_type, device_name,
223 device_id, false); 223 device_id, false);
224 224
225 // This should fail with error code 'kDeviceNotAvailable'. 225 // This should fail with error code 'kDeviceNotAvailable'.
226 vcm_->Open(dummy_device); 226 vcm_->Open(dummy_device);
227 227
228 // Wait to check callbacks before removing the listener. 228 // Wait to check callbacks before removing the listener.
229 message_loop_->RunAllPending(); 229 message_loop_->RunAllPending();
230 vcm_->Unregister(); 230 vcm_->Unregister();
231 } 231 }
232 232
233 // Start a device using "magic" id, i.e. call Start without calling Open. 233 // Start a device using "magic" id, i.e. call Start without calling Open.
234 TEST_F(VideoCaptureManagerTest, StartUsingId) { 234 TEST_F(VideoCaptureManagerTest, StartUsingId) {
235 InSequence s; 235 InSequence s;
236 EXPECT_CALL(*listener_, 236 EXPECT_CALL(*listener_,
237 Opened(content::MEDIA_STREAM_DEVICE_TYPE_VIDEO_CAPTURE, _)) 237 Opened(content::MEDIA_DEVICE_VIDEO_CAPTURE, _))
238 .Times(1); 238 .Times(1);
239 EXPECT_CALL(*listener_, 239 EXPECT_CALL(*listener_,
240 Closed(content::MEDIA_STREAM_DEVICE_TYPE_VIDEO_CAPTURE, _)) 240 Closed(content::MEDIA_DEVICE_VIDEO_CAPTURE, _))
241 .Times(1); 241 .Times(1);
242 242
243 media::VideoCaptureParams capture_params; 243 media::VideoCaptureParams capture_params;
244 capture_params.session_id = 244 capture_params.session_id =
245 media_stream::VideoCaptureManager::kStartOpenSessionId; 245 media_stream::VideoCaptureManager::kStartOpenSessionId;
246 capture_params.width = 320; 246 capture_params.width = 320;
247 capture_params.height = 240; 247 capture_params.height = 240;
248 capture_params.frame_per_second = 30; 248 capture_params.frame_per_second = 30;
249 249
250 // Start shall trigger the Open callback. 250 // Start shall trigger the Open callback.
251 vcm_->Start(capture_params, frame_observer_.get()); 251 vcm_->Start(capture_params, frame_observer_.get());
252 252
253 // Stop shall trigger the Close callback 253 // Stop shall trigger the Close callback
254 vcm_->Stop(media_stream::VideoCaptureManager::kStartOpenSessionId, 254 vcm_->Stop(media_stream::VideoCaptureManager::kStartOpenSessionId,
255 base::Closure()); 255 base::Closure());
256 256
257 // Wait to check callbacks before removing the listener. 257 // Wait to check callbacks before removing the listener.
258 message_loop_->RunAllPending(); 258 message_loop_->RunAllPending();
259 vcm_->Unregister(); 259 vcm_->Unregister();
260 } 260 }
261 261
262 // Open and start a device, close it before calling Stop. 262 // Open and start a device, close it before calling Stop.
263 TEST_F(VideoCaptureManagerTest, CloseWithoutStop) { 263 TEST_F(VideoCaptureManagerTest, CloseWithoutStop) {
264 InSequence s; 264 InSequence s;
265 EXPECT_CALL(*listener_, DevicesEnumerated(_)) 265 EXPECT_CALL(*listener_, DevicesEnumerated(_))
266 .Times(1); 266 .Times(1);
267 EXPECT_CALL(*listener_, 267 EXPECT_CALL(*listener_,
268 Opened(content::MEDIA_STREAM_DEVICE_TYPE_VIDEO_CAPTURE, _)) 268 Opened(content::MEDIA_DEVICE_VIDEO_CAPTURE, _))
269 .Times(1); 269 .Times(1);
270 EXPECT_CALL(*listener_, 270 EXPECT_CALL(*listener_,
271 Closed(content::MEDIA_STREAM_DEVICE_TYPE_VIDEO_CAPTURE, _)) 271 Closed(content::MEDIA_DEVICE_VIDEO_CAPTURE, _))
272 .Times(1); 272 .Times(1);
273 273
274 vcm_->EnumerateDevices(); 274 vcm_->EnumerateDevices();
275 275
276 // Wait to get device callback. 276 // Wait to get device callback.
277 message_loop_->RunAllPending(); 277 message_loop_->RunAllPending();
278 278
279 int video_session_id = vcm_->Open(listener_->devices_.front()); 279 int video_session_id = vcm_->Open(listener_->devices_.front());
280 280
281 media::VideoCaptureParams capture_params; 281 media::VideoCaptureParams capture_params;
282 capture_params.session_id = video_session_id; 282 capture_params.session_id = video_session_id;
283 capture_params.width = 320; 283 capture_params.width = 320;
284 capture_params.height = 240; 284 capture_params.height = 240;
285 capture_params.frame_per_second = 30; 285 capture_params.frame_per_second = 30;
286 vcm_->Start(capture_params, frame_observer_.get()); 286 vcm_->Start(capture_params, frame_observer_.get());
287 287
288 // Close will stop the running device, an assert will be triggered in 288 // Close will stop the running device, an assert will be triggered in
289 // VideoCaptureManager destructor otherwise. 289 // VideoCaptureManager destructor otherwise.
290 vcm_->Close(video_session_id); 290 vcm_->Close(video_session_id);
291 vcm_->Stop(video_session_id, base::Closure()); 291 vcm_->Stop(video_session_id, base::Closure());
292 292
293 // Wait to check callbacks before removing the listener 293 // Wait to check callbacks before removing the listener
294 message_loop_->RunAllPending(); 294 message_loop_->RunAllPending();
295 vcm_->Unregister(); 295 vcm_->Unregister();
296 } 296 }
297 297
298 } // namespace 298 } // namespace
OLDNEW
« no previous file with comments | « content/browser/renderer_host/media/video_capture_manager.cc ('k') | content/common/media/media_stream_messages.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698