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 2787703004: [Mojo Video Capture] Fix VideoCaptureManager exposing implementation details to clients (Closed)
Patch Set: Rebase to April 5 Created 3 years, 8 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
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 #include "content/browser/renderer_host/media/media_stream_dispatcher_host.h" 5 #include "content/browser/renderer_host/media/media_stream_dispatcher_host.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <memory> 8 #include <memory>
9 #include <queue> 9 #include <queue>
10 #include <string> 10 #include <string>
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 #include "url/origin.h" 46 #include "url/origin.h"
47 47
48 #if defined(OS_CHROMEOS) 48 #if defined(OS_CHROMEOS)
49 #include "chromeos/audio/cras_audio_handler.h" 49 #include "chromeos/audio/cras_audio_handler.h"
50 #endif 50 #endif
51 51
52 using ::testing::_; 52 using ::testing::_;
53 using ::testing::DeleteArg; 53 using ::testing::DeleteArg;
54 using ::testing::DoAll; 54 using ::testing::DoAll;
55 using ::testing::InSequence; 55 using ::testing::InSequence;
56 using ::testing::Invoke;
56 using ::testing::Return; 57 using ::testing::Return;
57 using ::testing::SaveArg; 58 using ::testing::SaveArg;
58 59
59 const int kProcessId = 5;
60 const int kRenderId = 6;
61 const int kPageRequestId = 7;
62
63 namespace content { 60 namespace content {
64 61
65 namespace { 62 namespace {
66 63
64 constexpr int kProcessId = 5;
65 constexpr int kRenderId = 6;
66 constexpr int kPageRequestId = 7;
67 constexpr const char* kRegularVideoDeviceId = "stub_device_0";
68 constexpr const char* kDepthVideoDeviceId = "stub_device_1 (depth)";
69 constexpr media::VideoCaptureApi kStubCaptureApi =
70 media::VideoCaptureApi::LINUX_V4L2_SINGLE_PLANE;
71 constexpr double kStubFocalLengthX = 135.0;
72 constexpr double kStubFocalLengthY = 135.6;
73 constexpr double kStubDepthNear = 0.0;
74 constexpr double kStubDepthFar = 65.535;
75
67 void AudioInputDevicesEnumerated(base::Closure quit_closure, 76 void AudioInputDevicesEnumerated(base::Closure quit_closure,
68 media::AudioDeviceDescriptions* out, 77 media::AudioDeviceDescriptions* out,
69 const MediaDeviceEnumeration& enumeration) { 78 const MediaDeviceEnumeration& enumeration) {
70 for (const auto& info : enumeration[MEDIA_DEVICE_TYPE_AUDIO_INPUT]) { 79 for (const auto& info : enumeration[MEDIA_DEVICE_TYPE_AUDIO_INPUT]) {
71 out->emplace_back(info.label, info.device_id, info.group_id); 80 out->emplace_back(info.label, info.device_id, info.group_id);
72 } 81 }
73 quit_closure.Run(); 82 quit_closure.Run();
74 } 83 }
75 84
76 } // namespace 85 } // anonymous namespace
77 86
78 class MockMediaStreamDispatcherHost : public MediaStreamDispatcherHost, 87 class MockMediaStreamDispatcherHost : public MediaStreamDispatcherHost,
79 public TestContentBrowserClient { 88 public TestContentBrowserClient {
80 public: 89 public:
81 MockMediaStreamDispatcherHost( 90 MockMediaStreamDispatcherHost(
82 const std::string& salt, 91 const std::string& salt,
83 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, 92 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner,
84 MediaStreamManager* manager) 93 MediaStreamManager* manager)
85 : MediaStreamDispatcherHost(kProcessId, salt, manager), 94 : MediaStreamDispatcherHost(kProcessId, salt, manager),
86 task_runner_(task_runner), 95 task_runner_(task_runner),
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 }; 230 };
222 231
223 class MockMediaStreamUIProxy : public FakeMediaStreamUIProxy { 232 class MockMediaStreamUIProxy : public FakeMediaStreamUIProxy {
224 public: 233 public:
225 MOCK_METHOD2( 234 MOCK_METHOD2(
226 OnStarted, 235 OnStarted,
227 void(const base::Closure& stop, 236 void(const base::Closure& stop,
228 const MediaStreamUIProxy::WindowIdCallback& window_id_callback)); 237 const MediaStreamUIProxy::WindowIdCallback& window_id_callback));
229 }; 238 };
230 239
240 class MockVideoCaptureSystem : public media::VideoCaptureSystem {
241 public:
242 MOCK_METHOD1(GetDeviceInfosAsync,
243 void(const base::Callback<
244 void(const std::vector<media::VideoCaptureDeviceInfo>&)>&
245 result_callback));
246
247 MOCK_METHOD1(
248 CreateDevice,
249 std::unique_ptr<media::VideoCaptureDevice>(const std::string& device_id));
250 };
251
231 class MediaStreamDispatcherHostTest : public testing::Test { 252 class MediaStreamDispatcherHostTest : public testing::Test {
232 public: 253 public:
233 MediaStreamDispatcherHostTest() 254 MediaStreamDispatcherHostTest()
234 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), 255 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP),
235 old_browser_client_(NULL), 256 old_browser_client_(NULL),
236 origin_(GURL("https://test.com")) { 257 origin_(GURL("https://test.com")) {
237 audio_manager_.reset( 258 audio_manager_.reset(
238 new media::MockAudioManager(base::ThreadTaskRunnerHandle::Get())); 259 new media::MockAudioManager(base::ThreadTaskRunnerHandle::Get()));
239 audio_system_ = media::AudioSystemImpl::Create(audio_manager_.get()); 260 audio_system_ = media::AudioSystemImpl::Create(audio_manager_.get());
240 // Make sure we use fake devices to avoid long delays. 261 // Make sure we use fake devices to avoid long delays.
241 base::CommandLine::ForCurrentProcess()->AppendSwitch( 262 base::CommandLine::ForCurrentProcess()->AppendSwitch(
242 switches::kUseFakeDeviceForMediaStream); 263 switches::kUseFakeDeviceForMediaStream);
264 auto mock_video_capture_system = base::MakeUnique<MockVideoCaptureSystem>();
265 mock_video_capture_system_ = mock_video_capture_system.get();
243 // Create our own MediaStreamManager. 266 // Create our own MediaStreamManager.
244 media_stream_manager_ = 267 media_stream_manager_ = base::MakeUnique<MediaStreamManager>(
245 base::MakeUnique<MediaStreamManager>(audio_system_.get()); 268 audio_system_.get(), std::move(mock_video_capture_system),
246 video_capture_device_factory_ =
247 static_cast<media::FakeVideoCaptureDeviceFactory*>(
248 media_stream_manager_->video_capture_manager()
249 ->video_capture_device_factory());
250 DCHECK(video_capture_device_factory_);
251 #if defined(OS_WIN)
252 // Override the Video Capture Thread that MediaStreamManager constructs.
253 media_stream_manager_->video_capture_manager()->set_device_task_runner(
254 base::ThreadTaskRunnerHandle::Get()); 269 base::ThreadTaskRunnerHandle::Get());
255 #endif
256 270
257 MockResourceContext* mock_resource_context = 271 MockResourceContext* mock_resource_context =
258 static_cast<MockResourceContext*>( 272 static_cast<MockResourceContext*>(
259 browser_context_.GetResourceContext()); 273 browser_context_.GetResourceContext());
260 274
261 host_ = new MockMediaStreamDispatcherHost( 275 host_ = new MockMediaStreamDispatcherHost(
262 mock_resource_context->GetMediaDeviceIDSalt(), 276 mock_resource_context->GetMediaDeviceIDSalt(),
263 base::ThreadTaskRunnerHandle::Get(), media_stream_manager_.get()); 277 base::ThreadTaskRunnerHandle::Get(), media_stream_manager_.get());
264 278
265 // Use the fake content client and browser. 279 // Use the fake content client and browser.
266 content_client_.reset(new TestContentClient()); 280 content_client_.reset(new TestContentClient());
267 SetContentClient(content_client_.get()); 281 SetContentClient(content_client_.get());
268 old_browser_client_ = SetBrowserClientForTesting(host_.get()); 282 old_browser_client_ = SetBrowserClientForTesting(host_.get());
269 283
270 #if defined(OS_CHROMEOS) 284 #if defined(OS_CHROMEOS)
271 chromeos::CrasAudioHandler::InitializeForTesting(); 285 chromeos::CrasAudioHandler::InitializeForTesting();
272 #endif 286 #endif
273 } 287 }
274 288
275 ~MediaStreamDispatcherHostTest() override { 289 ~MediaStreamDispatcherHostTest() override {
276 #if defined(OS_CHROMEOS) 290 #if defined(OS_CHROMEOS)
277 chromeos::CrasAudioHandler::Shutdown(); 291 chromeos::CrasAudioHandler::Shutdown();
278 #endif 292 #endif
279 } 293 }
280 294
281 void SetUp() override { 295 void SetUp() override {
282 video_capture_device_factory_->GetDeviceDescriptors( 296 stub_video_device_ids_.emplace_back(kRegularVideoDeviceId);
283 &physical_video_devices_); 297 stub_video_device_ids_.emplace_back(kDepthVideoDeviceId);
284 ASSERT_GT(physical_video_devices_.size(), 0u); 298 ON_CALL(*mock_video_capture_system_, GetDeviceInfosAsync(_))
299 .WillByDefault(Invoke(
300 [this](const base::Callback<void(
301 const std::vector<media::VideoCaptureDeviceInfo>&)>&
302 result_callback) {
303 std::vector<media::VideoCaptureDeviceInfo> result;
304 for (const auto& device_id : stub_video_device_ids_) {
305 media::VideoCaptureDeviceInfo info;
306 info.descriptor.device_id = device_id;
307 info.descriptor.capture_api = kStubCaptureApi;
308 if (device_id == kDepthVideoDeviceId) {
309 info.descriptor.camera_calibration.emplace();
310 info.descriptor.camera_calibration->focal_length_x =
311 kStubFocalLengthX;
312 info.descriptor.camera_calibration->focal_length_y =
313 kStubFocalLengthY;
314 info.descriptor.camera_calibration->depth_near =
315 kStubDepthNear;
316 info.descriptor.camera_calibration->depth_far = kStubDepthFar;
317 }
318 result.push_back(info);
319 }
320 result_callback.Run(result);
321 }));
285 322
286 base::RunLoop run_loop; 323 base::RunLoop run_loop;
287 MediaDevicesManager::BoolDeviceTypes devices_to_enumerate; 324 MediaDevicesManager::BoolDeviceTypes devices_to_enumerate;
288 devices_to_enumerate[MEDIA_DEVICE_TYPE_AUDIO_INPUT] = true; 325 devices_to_enumerate[MEDIA_DEVICE_TYPE_AUDIO_INPUT] = true;
289 media_stream_manager_->media_devices_manager()->EnumerateDevices( 326 media_stream_manager_->media_devices_manager()->EnumerateDevices(
290 devices_to_enumerate, 327 devices_to_enumerate,
291 base::Bind(&AudioInputDevicesEnumerated, run_loop.QuitClosure(), 328 base::Bind(&AudioInputDevicesEnumerated, run_loop.QuitClosure(),
292 &physical_audio_devices_)); 329 &audio_device_descriptions_));
293 run_loop.Run(); 330 run_loop.Run();
294 331
295 ASSERT_GT(physical_audio_devices_.size(), 0u); 332 ASSERT_GT(audio_device_descriptions_.size(), 0u);
296 } 333 }
297 334
298 void TearDown() override { host_->OnChannelClosing(); } 335 void TearDown() override { host_->OnChannelClosing(); }
299 336
300 protected: 337 protected:
301 virtual void SetupFakeUI(bool expect_started) { 338 virtual void SetupFakeUI(bool expect_started) {
302 stream_ui_ = new MockMediaStreamUIProxy(); 339 stream_ui_ = new MockMediaStreamUIProxy();
303 if (expect_started) { 340 if (expect_started) {
304 EXPECT_CALL(*stream_ui_, OnStarted(_, _)); 341 EXPECT_CALL(*stream_ui_, OnStarted(_, _));
305 } 342 }
306 media_stream_manager_->UseFakeUIForTests( 343 media_stream_manager_->UseFakeUIForTests(
307 std::unique_ptr<FakeMediaStreamUIProxy>(stream_ui_)); 344 std::unique_ptr<FakeMediaStreamUIProxy>(stream_ui_));
308 } 345 }
309 346
310 void GenerateStreamAndWaitForResult(int render_frame_id, 347 void GenerateStreamAndWaitForResult(int render_frame_id,
311 int page_request_id, 348 int page_request_id,
312 const StreamControls& controls) { 349 const StreamControls& controls) {
313 base::RunLoop run_loop; 350 base::RunLoop run_loop;
314 int expected_audio_array_size = 351 int expected_audio_array_size =
315 (controls.audio.requested && !physical_audio_devices_.empty()) ? 1 : 0; 352 (controls.audio.requested && !audio_device_descriptions_.empty()) ? 1
353 : 0;
316 int expected_video_array_size = 354 int expected_video_array_size =
317 (controls.video.requested && !physical_video_devices_.empty()) ? 1 : 0; 355 (controls.video.requested && !stub_video_device_ids_.empty()) ? 1 : 0;
318 EXPECT_CALL(*host_.get(), OnStreamGenerated(render_frame_id, 356 EXPECT_CALL(*host_.get(), OnStreamGenerated(render_frame_id,
319 page_request_id, 357 page_request_id,
320 expected_audio_array_size, 358 expected_audio_array_size,
321 expected_video_array_size)); 359 expected_video_array_size));
322 host_->OnGenerateStream(render_frame_id, page_request_id, controls, origin_, 360 host_->OnGenerateStream(render_frame_id, page_request_id, controls, origin_,
323 run_loop.QuitClosure()); 361 run_loop.QuitClosure());
324 run_loop.Run(); 362 run_loop.Run();
325 EXPECT_FALSE(DoesContainRawIds(host_->audio_devices_)); 363 EXPECT_FALSE(DoesContainRawIds(host_->audio_devices_));
326 EXPECT_FALSE(DoesContainRawIds(host_->video_devices_)); 364 EXPECT_FALSE(DoesContainRawIds(host_->video_devices_));
327 EXPECT_TRUE(DoesEveryDeviceMapToRawId(host_->audio_devices_, origin_)); 365 EXPECT_TRUE(DoesEveryDeviceMapToRawId(host_->audio_devices_, origin_));
(...skipping 26 matching lines...) Expand all
354 EXPECT_FALSE(DoesContainRawIds(host_->video_devices_)); 392 EXPECT_FALSE(DoesContainRawIds(host_->video_devices_));
355 EXPECT_TRUE(DoesEveryDeviceMapToRawId(host_->video_devices_, origin_)); 393 EXPECT_TRUE(DoesEveryDeviceMapToRawId(host_->video_devices_, origin_));
356 } 394 }
357 395
358 bool DoesContainRawIds(const StreamDeviceInfoArray& devices) { 396 bool DoesContainRawIds(const StreamDeviceInfoArray& devices) {
359 for (size_t i = 0; i < devices.size(); ++i) { 397 for (size_t i = 0; i < devices.size(); ++i) {
360 if (devices[i].device.id != 398 if (devices[i].device.id !=
361 media::AudioDeviceDescription::kDefaultDeviceId && 399 media::AudioDeviceDescription::kDefaultDeviceId &&
362 devices[i].device.id != 400 devices[i].device.id !=
363 media::AudioDeviceDescription::kCommunicationsDeviceId) { 401 media::AudioDeviceDescription::kCommunicationsDeviceId) {
364 for (const auto& audio_device : physical_audio_devices_) { 402 for (const auto& audio_device : audio_device_descriptions_) {
365 if (audio_device.unique_id == devices[i].device.id) 403 if (audio_device.unique_id == devices[i].device.id)
366 return true; 404 return true;
367 } 405 }
368 } 406 }
369 for (const auto& video_device : physical_video_devices_) { 407 for (const std::string& device_id : stub_video_device_ids_) {
370 if (video_device.device_id == devices[i].device.id) 408 if (device_id == devices[i].device.id)
371 return true; 409 return true;
372 } 410 }
373 } 411 }
374 return false; 412 return false;
375 } 413 }
376 414
377 bool DoesEveryDeviceMapToRawId(const StreamDeviceInfoArray& devices, 415 bool DoesEveryDeviceMapToRawId(const StreamDeviceInfoArray& devices,
378 const url::Origin& origin) { 416 const url::Origin& origin) {
379 for (size_t i = 0; i < devices.size(); ++i) { 417 for (size_t i = 0; i < devices.size(); ++i) {
380 bool found_match = false; 418 bool found_match = false;
381 media::AudioDeviceDescriptions::const_iterator audio_it = 419 media::AudioDeviceDescriptions::const_iterator audio_it =
382 physical_audio_devices_.begin(); 420 audio_device_descriptions_.begin();
383 for (; audio_it != physical_audio_devices_.end(); ++audio_it) { 421 for (; audio_it != audio_device_descriptions_.end(); ++audio_it) {
384 if (content::DoesMediaDeviceIDMatchHMAC( 422 if (content::DoesMediaDeviceIDMatchHMAC(
385 browser_context_.GetResourceContext()->GetMediaDeviceIDSalt(), 423 browser_context_.GetResourceContext()->GetMediaDeviceIDSalt(),
386 origin, 424 origin,
387 devices[i].device.id, 425 devices[i].device.id,
388 audio_it->unique_id)) { 426 audio_it->unique_id)) {
389 EXPECT_FALSE(found_match); 427 EXPECT_FALSE(found_match);
390 found_match = true; 428 found_match = true;
391 } 429 }
392 } 430 }
393 media::VideoCaptureDeviceDescriptors::const_iterator video_it = 431 for (const std::string& device_id : stub_video_device_ids_) {
394 physical_video_devices_.begin();
395 for (; video_it != physical_video_devices_.end(); ++video_it) {
396 if (content::DoesMediaDeviceIDMatchHMAC( 432 if (content::DoesMediaDeviceIDMatchHMAC(
397 browser_context_.GetResourceContext()->GetMediaDeviceIDSalt(), 433 browser_context_.GetResourceContext()->GetMediaDeviceIDSalt(),
398 origin, devices[i].device.id, video_it->device_id)) { 434 origin, devices[i].device.id, device_id)) {
399 EXPECT_FALSE(found_match); 435 EXPECT_FALSE(found_match);
400 found_match = true; 436 found_match = true;
401 } 437 }
402 } 438 }
403 if (!found_match) 439 if (!found_match)
404 return false; 440 return false;
405 } 441 }
406 return true; 442 return true;
407 } 443 }
408 444
(...skipping 18 matching lines...) Expand all
427 scoped_refptr<MockMediaStreamDispatcherHost> host_; 463 scoped_refptr<MockMediaStreamDispatcherHost> host_;
428 std::unique_ptr<MediaStreamManager> media_stream_manager_; 464 std::unique_ptr<MediaStreamManager> media_stream_manager_;
429 content::TestBrowserThreadBundle thread_bundle_; 465 content::TestBrowserThreadBundle thread_bundle_;
430 std::unique_ptr<media::AudioManager, media::AudioManagerDeleter> 466 std::unique_ptr<media::AudioManager, media::AudioManagerDeleter>
431 audio_manager_; 467 audio_manager_;
432 std::unique_ptr<media::AudioSystem> audio_system_; 468 std::unique_ptr<media::AudioSystem> audio_system_;
433 MockMediaStreamUIProxy* stream_ui_; 469 MockMediaStreamUIProxy* stream_ui_;
434 ContentBrowserClient* old_browser_client_; 470 ContentBrowserClient* old_browser_client_;
435 std::unique_ptr<ContentClient> content_client_; 471 std::unique_ptr<ContentClient> content_client_;
436 content::TestBrowserContext browser_context_; 472 content::TestBrowserContext browser_context_;
437 media::AudioDeviceDescriptions physical_audio_devices_; 473 media::AudioDeviceDescriptions audio_device_descriptions_;
438 media::VideoCaptureDeviceDescriptors physical_video_devices_; 474 std::vector<std::string> stub_video_device_ids_;
439 url::Origin origin_; 475 url::Origin origin_;
440 media::FakeVideoCaptureDeviceFactory* video_capture_device_factory_; 476 MockVideoCaptureSystem* mock_video_capture_system_;
441 }; 477 };
442 478
443 TEST_F(MediaStreamDispatcherHostTest, GenerateStreamWithVideoOnly) { 479 TEST_F(MediaStreamDispatcherHostTest, GenerateStreamWithVideoOnly) {
444 StreamControls controls(false, true); 480 StreamControls controls(false, true);
445 481
446 SetupFakeUI(true); 482 SetupFakeUI(true);
447 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, controls); 483 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, controls);
448 484
449 EXPECT_EQ(host_->audio_devices_.size(), 0u); 485 EXPECT_EQ(host_->audio_devices_.size(), 0u);
450 EXPECT_EQ(host_->video_devices_.size(), 1u); 486 EXPECT_EQ(host_->video_devices_.size(), 1u);
(...skipping 23 matching lines...) Expand all
474 StreamControls controls(true, true); 510 StreamControls controls(true, true);
475 511
476 SetupFakeUI(true); 512 SetupFakeUI(true);
477 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, controls); 513 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, controls);
478 514
479 EXPECT_EQ(host_->audio_devices_.size(), 1u); 515 EXPECT_EQ(host_->audio_devices_.size(), 1u);
480 EXPECT_EQ(host_->video_devices_.size(), 1u); 516 EXPECT_EQ(host_->video_devices_.size(), 1u);
481 } 517 }
482 518
483 TEST_F(MediaStreamDispatcherHostTest, GenerateStreamWithDepthVideo) { 519 TEST_F(MediaStreamDispatcherHostTest, GenerateStreamWithDepthVideo) {
484 // Video device on index 1 is depth video capture device. The number of fake
485 // devices is 2.
486 physical_video_devices_.clear();
487 video_capture_device_factory_->SetToDefaultDevicesConfig(2);
488 video_capture_device_factory_->GetDeviceDescriptors(&physical_video_devices_);
489 // We specify to generate both audio and video stream. 520 // We specify to generate both audio and video stream.
490 StreamControls controls(true, true); 521 StreamControls controls(true, true);
491 std::string source_id = content::GetHMACForMediaDeviceID( 522 std::string source_id = content::GetHMACForMediaDeviceID(
492 browser_context_.GetResourceContext()->GetMediaDeviceIDSalt(), origin_, 523 browser_context_.GetResourceContext()->GetMediaDeviceIDSalt(), origin_,
493 physical_video_devices_[1].device_id); 524 kDepthVideoDeviceId);
494 // |source_id| is related to depth device (the device on index 1). As we can 525 // |source_id| corresponds to the depth device. As we can generate only one
495 // generate only one video stream using GenerateStreamAndWaitForResult, we 526 // video stream using GenerateStreamAndWaitForResult, we use
496 // use controls.video.source_id to specify that the stream is depth video. 527 // controls.video.source_id to specify that the stream is depth video.
497 // See also MediaStreamManager::GenerateStream and other tests here. 528 // See also MediaStreamManager::GenerateStream and other tests here.
498 controls.video.device_id = source_id; 529 controls.video.device_id = source_id;
499 530
500 SetupFakeUI(true); 531 SetupFakeUI(true);
501 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, controls); 532 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, controls);
502 533
503 // There are two fake devices. We specified the generation and expect to get 534 // We specified the generation and expect to get
504 // one audio and one depth video stream. 535 // one audio and one depth video stream.
505 EXPECT_EQ(host_->audio_devices_.size(), 1u); 536 EXPECT_EQ(host_->audio_devices_.size(), 1u);
506 EXPECT_EQ(host_->video_devices_.size(), 1u); 537 EXPECT_EQ(host_->video_devices_.size(), 1u);
507 // host_->video_devices_[0] contains the information about generated video 538 // host_->video_devices_[0] contains the information about generated video
508 // stream device (the depth device). 539 // stream device (the depth device).
509 const base::Optional<CameraCalibration> calibration = 540 const base::Optional<CameraCalibration> calibration =
510 host_->video_devices_[0].device.camera_calibration; 541 host_->video_devices_[0].device.camera_calibration;
511 EXPECT_TRUE(calibration); 542 EXPECT_TRUE(calibration);
512 EXPECT_EQ(calibration->focal_length_x, 135.0); 543 EXPECT_EQ(calibration->focal_length_x, kStubFocalLengthX);
513 EXPECT_EQ(calibration->focal_length_y, 135.6); 544 EXPECT_EQ(calibration->focal_length_y, kStubFocalLengthY);
514 EXPECT_EQ(calibration->depth_near, 0.0); 545 EXPECT_EQ(calibration->depth_near, kStubDepthNear);
515 EXPECT_EQ(calibration->depth_far, 65.535); 546 EXPECT_EQ(calibration->depth_far, kStubDepthFar);
516 } 547 }
517 548
518 // This test generates two streams with video only using the same render frame 549 // This test generates two streams with video only using the same render frame
519 // id. The same capture device with the same device and session id is expected 550 // id. The same capture device with the same device and session id is expected
520 // to be used. 551 // to be used.
521 TEST_F(MediaStreamDispatcherHostTest, GenerateStreamsFromSameRenderId) { 552 TEST_F(MediaStreamDispatcherHostTest, GenerateStreamsFromSameRenderId) {
522 StreamControls controls(false, true); 553 StreamControls controls(false, true);
523 554
524 // Generate first stream. 555 // Generate first stream.
525 SetupFakeUI(true); 556 SetupFakeUI(true);
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
629 host_->OnGenerateStream(kRenderId, kPageRequestId + 1, controls, origin_, 660 host_->OnGenerateStream(kRenderId, kPageRequestId + 1, controls, origin_,
630 run_loop2.QuitClosure()); 661 run_loop2.QuitClosure());
631 662
632 run_loop1.Run(); 663 run_loop1.Run();
633 run_loop2.Run(); 664 run_loop2.Run();
634 } 665 }
635 666
636 // Test that we can generate streams where a sourceId is specified in 667 // Test that we can generate streams where a sourceId is specified in
637 // the request. 668 // the request.
638 TEST_F(MediaStreamDispatcherHostTest, GenerateStreamsWithSourceId) { 669 TEST_F(MediaStreamDispatcherHostTest, GenerateStreamsWithSourceId) {
639 ASSERT_GE(physical_audio_devices_.size(), 1u); 670 ASSERT_GE(audio_device_descriptions_.size(), 1u);
640 ASSERT_GE(physical_video_devices_.size(), 1u); 671 ASSERT_GE(stub_video_device_ids_.size(), 1u);
641 672
642 media::AudioDeviceDescriptions::const_iterator audio_it = 673 media::AudioDeviceDescriptions::const_iterator audio_it =
643 physical_audio_devices_.begin(); 674 audio_device_descriptions_.begin();
644 for (; audio_it != physical_audio_devices_.end(); ++audio_it) { 675 for (; audio_it != audio_device_descriptions_.end(); ++audio_it) {
645 std::string source_id = content::GetHMACForMediaDeviceID( 676 std::string source_id = content::GetHMACForMediaDeviceID(
646 browser_context_.GetResourceContext()->GetMediaDeviceIDSalt(), 677 browser_context_.GetResourceContext()->GetMediaDeviceIDSalt(),
647 origin_, 678 origin_,
648 audio_it->unique_id); 679 audio_it->unique_id);
649 ASSERT_FALSE(source_id.empty()); 680 ASSERT_FALSE(source_id.empty());
650 StreamControls controls(true, true); 681 StreamControls controls(true, true);
651 controls.audio.device_id = source_id; 682 controls.audio.device_id = source_id;
652 683
653 SetupFakeUI(true); 684 SetupFakeUI(true);
654 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, controls); 685 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, controls);
655 EXPECT_EQ(host_->audio_devices_[0].device.id, source_id); 686 EXPECT_EQ(host_->audio_devices_[0].device.id, source_id);
656 } 687 }
657 688
658 media::VideoCaptureDeviceDescriptors::const_iterator video_it = 689 for (const std::string& device_id : stub_video_device_ids_) {
659 physical_video_devices_.begin();
660 for (; video_it != physical_video_devices_.end(); ++video_it) {
661 std::string source_id = content::GetHMACForMediaDeviceID( 690 std::string source_id = content::GetHMACForMediaDeviceID(
662 browser_context_.GetResourceContext()->GetMediaDeviceIDSalt(), origin_, 691 browser_context_.GetResourceContext()->GetMediaDeviceIDSalt(), origin_,
663 video_it->device_id); 692 device_id);
664 ASSERT_FALSE(source_id.empty()); 693 ASSERT_FALSE(source_id.empty());
665 StreamControls controls(true, true); 694 StreamControls controls(true, true);
666 controls.video.device_id = source_id; 695 controls.video.device_id = source_id;
667 696
668 SetupFakeUI(true); 697 SetupFakeUI(true);
669 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, controls); 698 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, controls);
670 EXPECT_EQ(host_->video_devices_[0].device.id, source_id); 699 EXPECT_EQ(host_->video_devices_[0].device.id, source_id);
671 } 700 }
672 } 701 }
673 702
674 // Test that generating a stream with an invalid video source id fail. 703 // Test that generating a stream with an invalid video source id fail.
675 TEST_F(MediaStreamDispatcherHostTest, GenerateStreamsWithInvalidVideoSourceId) { 704 TEST_F(MediaStreamDispatcherHostTest, GenerateStreamsWithInvalidVideoSourceId) {
676 StreamControls controls(true, true); 705 StreamControls controls(true, true);
677 controls.video.device_id = "invalid source id"; 706 controls.video.device_id = "invalid source id";
678 707
679 GenerateStreamAndWaitForFailure(kRenderId, kPageRequestId, controls, 708 GenerateStreamAndWaitForFailure(kRenderId, kPageRequestId, controls,
680 MEDIA_DEVICE_NO_HARDWARE); 709 MEDIA_DEVICE_NO_HARDWARE);
681 } 710 }
682 711
683 // Test that generating a stream with an invalid audio source id fail. 712 // Test that generating a stream with an invalid audio source id fail.
684 TEST_F(MediaStreamDispatcherHostTest, GenerateStreamsWithInvalidAudioSourceId) { 713 TEST_F(MediaStreamDispatcherHostTest, GenerateStreamsWithInvalidAudioSourceId) {
685 StreamControls controls(true, true); 714 StreamControls controls(true, true);
686 controls.audio.device_id = "invalid source id"; 715 controls.audio.device_id = "invalid source id";
687 716
688 GenerateStreamAndWaitForFailure(kRenderId, kPageRequestId, controls, 717 GenerateStreamAndWaitForFailure(kRenderId, kPageRequestId, controls,
689 MEDIA_DEVICE_NO_HARDWARE); 718 MEDIA_DEVICE_NO_HARDWARE);
690 } 719 }
691 720
692 TEST_F(MediaStreamDispatcherHostTest, GenerateStreamsNoAvailableVideoDevice) { 721 TEST_F(MediaStreamDispatcherHostTest, GenerateStreamsNoAvailableVideoDevice) {
693 physical_video_devices_.clear(); 722 stub_video_device_ids_.clear();
694 video_capture_device_factory_->SetToDefaultDevicesConfig(0);
695 video_capture_device_factory_->GetDeviceDescriptors(&physical_video_devices_);
696 StreamControls controls(true, true); 723 StreamControls controls(true, true);
697 724
698 SetupFakeUI(false); 725 SetupFakeUI(false);
699 GenerateStreamAndWaitForFailure(kRenderId, kPageRequestId, controls, 726 GenerateStreamAndWaitForFailure(kRenderId, kPageRequestId, controls,
700 MEDIA_DEVICE_NO_HARDWARE); 727 MEDIA_DEVICE_NO_HARDWARE);
701 } 728 }
702 729
703 // Test that if a OnStopStreamDevice message is received for a device that has 730 // Test that if a OnStopStreamDevice message is received for a device that has
704 // been opened in a MediaStream and by pepper, the device is only stopped for 731 // been opened in a MediaStream and by pepper, the device is only stopped for
705 // the MediaStream. 732 // the MediaStream.
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
841 868
842 // Test that the dispatcher is notified if a video device that is in use is 869 // Test that the dispatcher is notified if a video device that is in use is
843 // being unplugged. 870 // being unplugged.
844 TEST_F(MediaStreamDispatcherHostTest, VideoDeviceUnplugged) { 871 TEST_F(MediaStreamDispatcherHostTest, VideoDeviceUnplugged) {
845 StreamControls controls(true, true); 872 StreamControls controls(true, true);
846 SetupFakeUI(true); 873 SetupFakeUI(true);
847 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, controls); 874 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, controls);
848 EXPECT_EQ(host_->audio_devices_.size(), 1u); 875 EXPECT_EQ(host_->audio_devices_.size(), 1u);
849 EXPECT_EQ(host_->video_devices_.size(), 1u); 876 EXPECT_EQ(host_->video_devices_.size(), 1u);
850 877
851 video_capture_device_factory_->SetToDefaultDevicesConfig(0); 878 stub_video_device_ids_.clear();
852 879
853 base::RunLoop run_loop; 880 base::RunLoop run_loop;
854 EXPECT_CALL(*host_.get(), OnDeviceStopped(kRenderId)) 881 EXPECT_CALL(*host_.get(), OnDeviceStopped(kRenderId))
855 .WillOnce(testing::InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); 882 .WillOnce(testing::InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit));
856 media_stream_manager_->media_devices_manager()->OnDevicesChanged( 883 media_stream_manager_->media_devices_manager()->OnDevicesChanged(
857 base::SystemMonitor::DEVTYPE_VIDEO_CAPTURE); 884 base::SystemMonitor::DEVTYPE_VIDEO_CAPTURE);
858 885
859 run_loop.Run(); 886 run_loop.Run();
860 } 887 }
861 888
862 }; // namespace content 889 }; // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698