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 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
330 | 330 |
331 EXPECT_CALL(*host_, OnVideoDeviceFailed(kRenderId, 0)); | 331 EXPECT_CALL(*host_, OnVideoDeviceFailed(kRenderId, 0)); |
332 int session_id = host_->video_devices_[0].session_id; | 332 int session_id = host_->video_devices_[0].session_id; |
333 media_stream_manager_->video_capture_manager()->Error(session_id); | 333 media_stream_manager_->video_capture_manager()->Error(session_id); |
334 WaitForResult(); | 334 WaitForResult(); |
335 EXPECT_EQ(host_->video_devices_.size(), 0u); | 335 EXPECT_EQ(host_->video_devices_.size(), 0u); |
336 EXPECT_EQ(host_->NumberOfStreams(), 1u); | 336 EXPECT_EQ(host_->NumberOfStreams(), 1u); |
337 | 337 |
338 // TODO(perkj): test audio device failure? | 338 // TODO(perkj): test audio device failure? |
339 | 339 |
| 340 EXPECT_CALL(*media_observer_.get(), OnCaptureDevicesClosed(_, _, _)); |
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, StopGeneratedStreamsOnChannelClosing) { |
| 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 // Wait until the streams are all generated. |
| 381 WaitForResult(); |
| 382 |
| 383 // Calling OnChannelClosing() to cancel all the pending/generated streams. |
| 384 EXPECT_CALL(*media_observer_.get(), OnCaptureDevicesClosed(_, _, _)) |
| 385 .Times(3); |
| 386 host_->OnChannelClosing(); |
| 387 |
| 388 // Streams should have been cleaned up. |
| 389 EXPECT_EQ(host_->NumberOfStreams(), 0u); |
| 390 } |
| 391 |
344 }; // namespace media_stream | 392 }; // namespace media_stream |
OLD | NEW |