| 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/media_stream_dispatcher_host.h" | 10 #include "content/browser/renderer_host/media/media_stream_dispatcher_host.h" |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 | 200 |
| 201 scoped_refptr<MockMediaStreamDispatcherHost> host_; | 201 scoped_refptr<MockMediaStreamDispatcherHost> host_; |
| 202 scoped_ptr<MessageLoop> message_loop_; | 202 scoped_ptr<MessageLoop> message_loop_; |
| 203 scoped_ptr<BrowserThreadImpl> ui_thread_; | 203 scoped_ptr<BrowserThreadImpl> ui_thread_; |
| 204 scoped_ptr<BrowserThreadImpl> io_thread_; | 204 scoped_ptr<BrowserThreadImpl> io_thread_; |
| 205 scoped_ptr<media::AudioManager> audio_manager_; | 205 scoped_ptr<media::AudioManager> audio_manager_; |
| 206 content::MockResourceContext resource_context_; | 206 content::MockResourceContext resource_context_; |
| 207 }; | 207 }; |
| 208 | 208 |
| 209 TEST_F(MediaStreamDispatcherHostTest, GenerateStream) { | 209 TEST_F(MediaStreamDispatcherHostTest, GenerateStream) { |
| 210 StreamOptions options(false, StreamOptions::kFacingUser); | 210 StreamOptions options(false, true); |
| 211 | 211 |
| 212 EXPECT_CALL(*host_, OnStreamGenerated(kRenderId, kPageRequestId, 0, 1)); | 212 EXPECT_CALL(*host_, OnStreamGenerated(kRenderId, kPageRequestId, 0, 1)); |
| 213 host_->OnGenerateStream(kPageRequestId, options); | 213 host_->OnGenerateStream(kPageRequestId, options); |
| 214 | 214 |
| 215 WaitForResult(); | 215 WaitForResult(); |
| 216 | 216 |
| 217 std::string label = host_->label_; | 217 std::string label = host_->label_; |
| 218 | 218 |
| 219 EXPECT_EQ(host_->audio_devices_.size(), 0u); | 219 EXPECT_EQ(host_->audio_devices_.size(), 0u); |
| 220 EXPECT_EQ(host_->video_devices_.size(), 1u); | 220 EXPECT_EQ(host_->video_devices_.size(), 1u); |
| 221 EXPECT_EQ(host_->NumberOfStreams(), 1u); | 221 EXPECT_EQ(host_->NumberOfStreams(), 1u); |
| 222 | 222 |
| 223 host_->OnStopGeneratedStream(label); | 223 host_->OnStopGeneratedStream(label); |
| 224 EXPECT_EQ(host_->NumberOfStreams(), 0u); | 224 EXPECT_EQ(host_->NumberOfStreams(), 0u); |
| 225 } | 225 } |
| 226 | 226 |
| 227 TEST_F(MediaStreamDispatcherHostTest, GenerateThreeStreams) { | 227 TEST_F(MediaStreamDispatcherHostTest, GenerateThreeStreams) { |
| 228 // This test opens three video capture devices. Two fake devices exists and it | 228 // This test opens three video capture devices. Two fake devices exists and it |
| 229 // is expected the last call to |Open()| will open the first device again, but | 229 // is expected the last call to |Open()| will open the first device again, but |
| 230 // with a different label. | 230 // with a different label. |
| 231 StreamOptions options(false, StreamOptions::kFacingUser); | 231 StreamOptions options(false, true); |
| 232 | 232 |
| 233 // Generate first stream. | 233 // Generate first stream. |
| 234 EXPECT_CALL(*host_, OnStreamGenerated(kRenderId, kPageRequestId, 0, 1)); | 234 EXPECT_CALL(*host_, OnStreamGenerated(kRenderId, kPageRequestId, 0, 1)); |
| 235 host_->OnGenerateStream(kPageRequestId, options); | 235 host_->OnGenerateStream(kPageRequestId, options); |
| 236 | 236 |
| 237 WaitForResult(); | 237 WaitForResult(); |
| 238 | 238 |
| 239 // Check the latest generated stream. | 239 // Check the latest generated stream. |
| 240 EXPECT_EQ(host_->audio_devices_.size(), 0u); | 240 EXPECT_EQ(host_->audio_devices_.size(), 0u); |
| 241 EXPECT_EQ(host_->video_devices_.size(), 1u); | 241 EXPECT_EQ(host_->video_devices_.size(), 1u); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 281 // Check that we now have three opened streams. | 281 // Check that we now have three opened streams. |
| 282 EXPECT_EQ(host_->NumberOfStreams(), 3u); | 282 EXPECT_EQ(host_->NumberOfStreams(), 3u); |
| 283 | 283 |
| 284 host_->OnStopGeneratedStream(label1); | 284 host_->OnStopGeneratedStream(label1); |
| 285 host_->OnStopGeneratedStream(label2); | 285 host_->OnStopGeneratedStream(label2); |
| 286 host_->OnStopGeneratedStream(label3); | 286 host_->OnStopGeneratedStream(label3); |
| 287 EXPECT_EQ(host_->NumberOfStreams(), 0u); | 287 EXPECT_EQ(host_->NumberOfStreams(), 0u); |
| 288 } | 288 } |
| 289 | 289 |
| 290 TEST_F(MediaStreamDispatcherHostTest, FailDevice) { | 290 TEST_F(MediaStreamDispatcherHostTest, FailDevice) { |
| 291 StreamOptions options(false, StreamOptions::kFacingUser); | 291 StreamOptions options(false, true); |
| 292 | 292 |
| 293 EXPECT_CALL(*host_, OnStreamGenerated(kRenderId, kPageRequestId, 0, 1)); | 293 EXPECT_CALL(*host_, OnStreamGenerated(kRenderId, kPageRequestId, 0, 1)); |
| 294 host_->OnGenerateStream(kPageRequestId, options); | 294 host_->OnGenerateStream(kPageRequestId, options); |
| 295 WaitForResult(); | 295 WaitForResult(); |
| 296 std::string label = host_->label_; | 296 std::string label = host_->label_; |
| 297 | 297 |
| 298 EXPECT_EQ(host_->audio_devices_.size(), 0u); | 298 EXPECT_EQ(host_->audio_devices_.size(), 0u); |
| 299 EXPECT_EQ(host_->video_devices_.size(), 1u); | 299 EXPECT_EQ(host_->video_devices_.size(), 1u); |
| 300 EXPECT_EQ(host_->NumberOfStreams(), 1u); | 300 EXPECT_EQ(host_->NumberOfStreams(), 1u); |
| 301 | 301 |
| 302 EXPECT_CALL(*host_, OnVideoDeviceFailed(kRenderId, 0)); | 302 EXPECT_CALL(*host_, OnVideoDeviceFailed(kRenderId, 0)); |
| 303 int session_id = host_->video_devices_[0].session_id; | 303 int session_id = host_->video_devices_[0].session_id; |
| 304 MediaStreamManager::GetForResourceContext( | 304 MediaStreamManager::GetForResourceContext( |
| 305 &resource_context_, audio_manager_.get())-> | 305 &resource_context_, audio_manager_.get())-> |
| 306 video_capture_manager()->Error(session_id); | 306 video_capture_manager()->Error(session_id); |
| 307 WaitForResult(); | 307 WaitForResult(); |
| 308 EXPECT_EQ(host_->video_devices_.size(), 0u); | 308 EXPECT_EQ(host_->video_devices_.size(), 0u); |
| 309 EXPECT_EQ(host_->NumberOfStreams(), 1u); | 309 EXPECT_EQ(host_->NumberOfStreams(), 1u); |
| 310 | 310 |
| 311 // TODO(perkj): test audio device failure? | 311 // TODO(perkj): test audio device failure? |
| 312 | 312 |
| 313 host_->OnStopGeneratedStream(label); | 313 host_->OnStopGeneratedStream(label); |
| 314 EXPECT_EQ(host_->NumberOfStreams(), 0u); | 314 EXPECT_EQ(host_->NumberOfStreams(), 0u); |
| 315 } | 315 } |
| 316 | 316 |
| 317 }; // namespace media_stream | 317 }; // namespace media_stream |
| OLD | NEW |