OLD | NEW |
---|---|
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 <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/renderer_host/media/audio_input_device_manager.h" | 10 #include "content/browser/renderer_host/media/audio_input_device_manager.h" |
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
314 } | 314 } |
315 | 315 |
316 TEST_F(MediaStreamDispatcherHostTest, FailDevice) { | 316 TEST_F(MediaStreamDispatcherHostTest, FailDevice) { |
317 StreamOptions options(false, true); | 317 StreamOptions options(false, true); |
318 | 318 |
319 EXPECT_CALL(*host_, GetMediaObserver()) | 319 EXPECT_CALL(*host_, GetMediaObserver()) |
320 .WillRepeatedly(Return(media_observer_.get())); | 320 .WillRepeatedly(Return(media_observer_.get())); |
321 EXPECT_CALL(*host_, OnStreamGenerated(kRenderId, kPageRequestId, 0, 1)); | 321 EXPECT_CALL(*host_, OnStreamGenerated(kRenderId, kPageRequestId, 0, 1)); |
322 host_->OnGenerateStream(kPageRequestId, options); | 322 host_->OnGenerateStream(kPageRequestId, options); |
323 EXPECT_CALL(*media_observer_.get(), OnCaptureDevicesOpened(_, _, _)); | 323 EXPECT_CALL(*media_observer_.get(), OnCaptureDevicesOpened(_, _, _)); |
324 EXPECT_CALL(*media_observer_.get(), OnCaptureDevicesClosed(_, _, _)); | |
perkj_chrome
2012/08/10 07:09:31
Move this to just before OnStopGeneratedStream
no longer working on chromium
2012/08/10 11:50:56
Done.
| |
324 WaitForResult(); | 325 WaitForResult(); |
325 std::string label = host_->label_; | 326 std::string label = host_->label_; |
326 | 327 |
327 EXPECT_EQ(host_->audio_devices_.size(), 0u); | 328 EXPECT_EQ(host_->audio_devices_.size(), 0u); |
328 EXPECT_EQ(host_->video_devices_.size(), 1u); | 329 EXPECT_EQ(host_->video_devices_.size(), 1u); |
329 EXPECT_EQ(host_->NumberOfStreams(), 1u); | 330 EXPECT_EQ(host_->NumberOfStreams(), 1u); |
330 | 331 |
331 EXPECT_CALL(*host_, OnVideoDeviceFailed(kRenderId, 0)); | 332 EXPECT_CALL(*host_, OnVideoDeviceFailed(kRenderId, 0)); |
332 int session_id = host_->video_devices_[0].session_id; | 333 int session_id = host_->video_devices_[0].session_id; |
333 media_stream_manager_->video_capture_manager()->Error(session_id); | 334 media_stream_manager_->video_capture_manager()->Error(session_id); |
334 WaitForResult(); | 335 WaitForResult(); |
335 EXPECT_EQ(host_->video_devices_.size(), 0u); | 336 EXPECT_EQ(host_->video_devices_.size(), 0u); |
336 EXPECT_EQ(host_->NumberOfStreams(), 1u); | 337 EXPECT_EQ(host_->NumberOfStreams(), 1u); |
337 | 338 |
338 // TODO(perkj): test audio device failure? | 339 // TODO(perkj): test audio device failure? |
339 | 340 |
340 host_->OnStopGeneratedStream(label); | 341 host_->OnStopGeneratedStream(label); |
341 EXPECT_EQ(host_->NumberOfStreams(), 0u); | 342 EXPECT_EQ(host_->NumberOfStreams(), 0u); |
342 } | 343 } |
343 | 344 |
345 TEST_F(MediaStreamDispatcherHostTest, CancelPendingStreamsOnChannelClosing) { | |
346 StreamOptions options(false, true); | |
347 | |
348 EXPECT_CALL(*host_, GetMediaObserver()) | |
349 .WillRepeatedly(Return(media_observer_.get())); | |
350 | |
351 // Create multiple GenerateStream requests. | |
352 size_t streams = 5; | |
353 for (size_t i = 1; i <= streams; ++i) { | |
354 host_->OnGenerateStream(kPageRequestId + i, options); | |
355 EXPECT_EQ(host_->NumberOfStreams(), i); | |
356 } | |
357 | |
358 // Calling OnChannelClosing() to cancel all the pending requests. | |
359 host_->OnChannelClosing(); | |
360 | |
361 // Streams should have been cleaned up. | |
362 EXPECT_EQ(host_->NumberOfStreams(), 0u); | |
363 } | |
364 | |
365 TEST_F(MediaStreamDispatcherHostTest, StopAllStreamsOnChannelClosing) { | |
366 StreamOptions options(false, true); | |
367 | |
368 EXPECT_CALL(*host_, GetMediaObserver()) | |
369 .WillRepeatedly(Return(media_observer_.get())); | |
370 | |
371 // Create first group of streams. | |
372 size_t generated_streams = 3; | |
373 for (size_t i = 0; i < generated_streams; ++i) { | |
374 EXPECT_CALL(*host_, OnStreamGenerated(kRenderId, kPageRequestId + i, 0, 1)); | |
375 host_->OnGenerateStream(kPageRequestId + i, options); | |
376 } | |
377 EXPECT_EQ(host_->NumberOfStreams(), generated_streams); | |
378 EXPECT_CALL(*media_observer_.get(), OnCaptureDevicesOpened(_, _, _)) | |
379 .Times(3); | |
380 EXPECT_CALL(*media_observer_.get(), OnCaptureDevicesClosed(_, _, _)) | |
perkj_chrome
2012/08/10 07:09:31
Move this expect to just before host->OnChannelClo
no longer working on chromium
2012/08/10 11:50:56
Done.
| |
381 .Times(3); | |
382 // Wait until the streams are all generated. | |
383 WaitForResult(); | |
384 | |
385 // Create second group of streams. | |
386 size_t pending_streams = 3; | |
perkj_chrome
2012/08/10 07:09:31
No need to test CancelPendingStreams again. You ha
no longer working on chromium
2012/08/10 11:50:56
Done.
| |
387 for (size_t i = 1; i <= pending_streams; ++i) { | |
388 host_->OnGenerateStream(kPageRequestId + generated_streams + i, options); | |
389 } | |
390 EXPECT_EQ(host_->NumberOfStreams(), pending_streams + generated_streams); | |
391 | |
392 // Calling OnChannelClosing() to cancel all the pending/generated streams. | |
393 host_->OnChannelClosing(); | |
394 | |
395 // Streams should have been cleaned up. | |
396 EXPECT_EQ(host_->NumberOfStreams(), 0u); | |
397 } | |
398 | |
344 }; // namespace media_stream | 399 }; // namespace media_stream |
OLD | NEW |