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

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

Issue 8695004: Let fake UI allow a video capture device to be opened several times. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years 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 <string> 5 #include <string>
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "content/browser/browser_thread_impl.h" 9 #include "content/browser/browser_thread_impl.h"
10 #include "content/browser/mock_resource_context.h" 10 #include "content/browser/mock_resource_context.h"
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 std::string label = host_->label_; 215 std::string label = host_->label_;
216 216
217 EXPECT_EQ(host_->audio_devices_.size(), 0u); 217 EXPECT_EQ(host_->audio_devices_.size(), 0u);
218 EXPECT_EQ(host_->video_devices_.size(), 1u); 218 EXPECT_EQ(host_->video_devices_.size(), 1u);
219 EXPECT_EQ(host_->NumberOfStreams(), 1u); 219 EXPECT_EQ(host_->NumberOfStreams(), 1u);
220 220
221 host_->OnStopGeneratedStream(label); 221 host_->OnStopGeneratedStream(label);
222 EXPECT_EQ(host_->NumberOfStreams(), 0u); 222 EXPECT_EQ(host_->NumberOfStreams(), 0u);
223 } 223 }
224 224
225 TEST_F(MediaStreamDispatcherHostTest, GenerateTwoStreams) { 225 TEST_F(MediaStreamDispatcherHostTest, GenerateThreeStreams) {
226 // This test opens three video capture devices. Two fake devices exists and it
227 // is expected the last call to |Open()| will open the first device again, but
228 // with a different label.
226 StreamOptions options(false, StreamOptions::kFacingUser); 229 StreamOptions options(false, StreamOptions::kFacingUser);
227 230
228 // Generate first stream. 231 // Generate first stream.
229 EXPECT_CALL(*host_, OnStreamGenerated(kRenderId, kPageRequestId, 0, 1)); 232 EXPECT_CALL(*host_, OnStreamGenerated(kRenderId, kPageRequestId, 0, 1));
230 host_->OnGenerateStream(kPageRequestId, options); 233 host_->OnGenerateStream(kPageRequestId, options);
231 234
232 WaitForResult(); 235 WaitForResult();
233 236
234 // Check the latest generated stream. 237 // Check the latest generated stream.
235 EXPECT_EQ(host_->audio_devices_.size(), 0u); 238 EXPECT_EQ(host_->audio_devices_.size(), 0u);
236 EXPECT_EQ(host_->video_devices_.size(), 1u); 239 EXPECT_EQ(host_->video_devices_.size(), 1u);
240 std::string label1 = host_->label_;
241 std::string device_id1 = host_->video_devices_.front().device_id;
242
237 // Check that we now have one opened streams. 243 // Check that we now have one opened streams.
238 EXPECT_EQ(host_->NumberOfStreams(), 1u); 244 EXPECT_EQ(host_->NumberOfStreams(), 1u);
239 std::string label1 = host_->label_;
240 245
241 // Generate second stream. 246 // Generate second stream.
242 EXPECT_CALL(*host_, OnStreamGenerated(kRenderId, kPageRequestId+1, 0, 1)); 247 EXPECT_CALL(*host_, OnStreamGenerated(kRenderId, kPageRequestId+1, 0, 1));
scherkus (not reviewing) 2011/11/29 02:39:53 spaces around binary operators
mflodman_chromium_OOO 2011/11/29 23:31:00 Done.
243 host_->OnGenerateStream(kPageRequestId+1, options); 248 host_->OnGenerateStream(kPageRequestId+1, options);
244 249
245 WaitForResult(); 250 WaitForResult();
246 std::string label2 = host_->label_;
247 251
248 // Check the latest generated stream. 252 // Check the latest generated stream.
249 EXPECT_EQ(host_->audio_devices_.size(), 0u); 253 EXPECT_EQ(host_->audio_devices_.size(), 0u);
250 EXPECT_EQ(host_->video_devices_.size(), 1u); 254 EXPECT_EQ(host_->video_devices_.size(), 1u);
255 std::string label2 = host_->label_;
256 std::string device_id2 = host_->video_devices_.front().device_id;
257 EXPECT_NE(device_id1, device_id2);
258 EXPECT_NE(label1, label2);
259
251 // Check that we now have two opened streams. 260 // Check that we now have two opened streams.
252 EXPECT_EQ(host_->NumberOfStreams(), 2u); 261 EXPECT_EQ(host_->NumberOfStreams(), 2u);
253 262
263 // Generate third stream.
264 EXPECT_CALL(*host_, OnStreamGenerated(kRenderId, kPageRequestId+2, 0, 1));
scherkus (not reviewing) 2011/11/29 02:39:53 spaces around binary operators
mflodman_chromium_OOO 2011/11/29 23:31:00 Done.
265 host_->OnGenerateStream(kPageRequestId+2, options);
266
267 WaitForResult();
268
269 // Check the latest generated stream.
270 EXPECT_EQ(host_->audio_devices_.size(), 0u);
271 EXPECT_EQ(host_->video_devices_.size(), 1u);
272 std::string label3 = host_->label_;
273 std::string device_id3 = host_->video_devices_.front().device_id;
274 EXPECT_EQ(device_id1, device_id3);
275 EXPECT_NE(device_id2, device_id3);
276 EXPECT_NE(label1, label3);
277 EXPECT_NE(label2, label3);
278
279 // Check that we now have three opened streams.
280 EXPECT_EQ(host_->NumberOfStreams(), 3u);
281
254 host_->OnStopGeneratedStream(label1); 282 host_->OnStopGeneratedStream(label1);
255 host_->OnStopGeneratedStream(label2); 283 host_->OnStopGeneratedStream(label2);
284 host_->OnStopGeneratedStream(label3);
256 EXPECT_EQ(host_->NumberOfStreams(), 0u); 285 EXPECT_EQ(host_->NumberOfStreams(), 0u);
257 } 286 }
258 287
259 TEST_F(MediaStreamDispatcherHostTest, FailDevice) { 288 TEST_F(MediaStreamDispatcherHostTest, FailDevice) {
260 StreamOptions options(false, StreamOptions::kFacingUser); 289 StreamOptions options(false, StreamOptions::kFacingUser);
261 290
262 EXPECT_CALL(*host_, OnStreamGenerated(kRenderId, kPageRequestId, 0, 1)); 291 EXPECT_CALL(*host_, OnStreamGenerated(kRenderId, kPageRequestId, 0, 1));
263 host_->OnGenerateStream(kPageRequestId, options); 292 host_->OnGenerateStream(kPageRequestId, options);
264 WaitForResult(); 293 WaitForResult();
265 std::string label = host_->label_; 294 std::string label = host_->label_;
(...skipping 10 matching lines...) Expand all
276 EXPECT_EQ(host_->video_devices_.size(), 0u); 305 EXPECT_EQ(host_->video_devices_.size(), 0u);
277 EXPECT_EQ(host_->NumberOfStreams(), 1u); 306 EXPECT_EQ(host_->NumberOfStreams(), 1u);
278 307
279 // TODO(perkj): test audio device failure? 308 // TODO(perkj): test audio device failure?
280 309
281 host_->OnStopGeneratedStream(label); 310 host_->OnStopGeneratedStream(label);
282 EXPECT_EQ(host_->NumberOfStreams(), 0u); 311 EXPECT_EQ(host_->NumberOfStreams(), 0u);
283 } 312 }
284 313
285 }; // namespace media_stream 314 }; // namespace media_stream
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698