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

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

Powered by Google App Engine
This is Rietveld 408576698