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

Side by Side Diff: content/browser/renderer_host/media/media_stream_dispatcher_host_unittest.cc

Issue 143003031: Allow retrieval of media device ID salt even after ResourceContext has gone away. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add TODO about proper fix. Created 6 years, 10 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 | Annotate | Revision Log
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 <string> 5 #include <string>
6 #include <queue> 6 #include <queue>
7 7
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/callback_helpers.h" 9 #include "base/callback_helpers.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 } 325 }
326 326
327 bool DoesEveryDeviceMapToRawId(const StreamDeviceInfoArray& devices, 327 bool DoesEveryDeviceMapToRawId(const StreamDeviceInfoArray& devices,
328 const GURL& origin) { 328 const GURL& origin) {
329 for (size_t i = 0; i < devices.size(); ++i) { 329 for (size_t i = 0; i < devices.size(); ++i) {
330 bool found_match = false; 330 bool found_match = false;
331 media::AudioDeviceNames::const_iterator audio_it = 331 media::AudioDeviceNames::const_iterator audio_it =
332 physical_audio_devices_.begin(); 332 physical_audio_devices_.begin();
333 for (; audio_it != physical_audio_devices_.end(); ++audio_it) { 333 for (; audio_it != physical_audio_devices_.end(); ++audio_it) {
334 if (content::DoesMediaDeviceIDMatchHMAC( 334 if (content::DoesMediaDeviceIDMatchHMAC(
335 browser_context_.GetResourceContext(), 335 browser_context_.GetResourceContext()->GetMediaDeviceIDSalt(),
336 origin, 336 origin,
337 devices[i].device.id, 337 devices[i].device.id,
338 audio_it->unique_id)) { 338 audio_it->unique_id)) {
339 EXPECT_FALSE(found_match); 339 EXPECT_FALSE(found_match);
340 found_match = true; 340 found_match = true;
341 } 341 }
342 } 342 }
343 media::VideoCaptureDevice::Names::const_iterator video_it = 343 media::VideoCaptureDevice::Names::const_iterator video_it =
344 physical_video_devices_.begin(); 344 physical_video_devices_.begin();
345 for (; video_it != physical_video_devices_.end(); ++video_it) { 345 for (; video_it != physical_video_devices_.end(); ++video_it) {
346 if (content::DoesMediaDeviceIDMatchHMAC( 346 if (content::DoesMediaDeviceIDMatchHMAC(
347 browser_context_.GetResourceContext(), 347 browser_context_.GetResourceContext()->GetMediaDeviceIDSalt(),
348 origin, 348 origin,
349 devices[i].device.id, 349 devices[i].device.id,
350 video_it->id())) { 350 video_it->id())) {
351 EXPECT_FALSE(found_match); 351 EXPECT_FALSE(found_match);
352 found_match = true; 352 found_match = true;
353 } 353 }
354 } 354 }
355 if (!found_match) 355 if (!found_match)
356 return false; 356 return false;
357 } 357 }
358 return true; 358 return true;
359 } 359 }
360 360
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
530 // Test that we can generate streams where a mandatory sourceId is specified in 530 // Test that we can generate streams where a mandatory sourceId is specified in
531 // the request. 531 // the request.
532 TEST_F(MediaStreamDispatcherHostTest, GenerateStreamsWithMandatorySourceId) { 532 TEST_F(MediaStreamDispatcherHostTest, GenerateStreamsWithMandatorySourceId) {
533 ASSERT_GE(physical_audio_devices_.size(), 1u); 533 ASSERT_GE(physical_audio_devices_.size(), 1u);
534 ASSERT_GE(physical_video_devices_.size(), 1u); 534 ASSERT_GE(physical_video_devices_.size(), 1u);
535 535
536 media::AudioDeviceNames::const_iterator audio_it = 536 media::AudioDeviceNames::const_iterator audio_it =
537 physical_audio_devices_.begin(); 537 physical_audio_devices_.begin();
538 for (; audio_it != physical_audio_devices_.end(); ++audio_it) { 538 for (; audio_it != physical_audio_devices_.end(); ++audio_it) {
539 std::string source_id = content::GetHMACForMediaDeviceID( 539 std::string source_id = content::GetHMACForMediaDeviceID(
540 browser_context_.GetResourceContext(), 540 browser_context_.GetResourceContext()->GetMediaDeviceIDSalt(),
541 origin_, 541 origin_,
542 audio_it->unique_id); 542 audio_it->unique_id);
543 ASSERT_FALSE(source_id.empty()); 543 ASSERT_FALSE(source_id.empty());
544 StreamOptions options(true, true); 544 StreamOptions options(true, true);
545 AddSourceIdConstraint(source_id, &options.mandatory_audio); 545 AddSourceIdConstraint(source_id, &options.mandatory_audio);
546 546
547 SetupFakeUI(true); 547 SetupFakeUI(true);
548 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, options); 548 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, options);
549 EXPECT_EQ(host_->audio_devices_[0].device.id, source_id); 549 EXPECT_EQ(host_->audio_devices_[0].device.id, source_id);
550 } 550 }
551 551
552 media::VideoCaptureDevice::Names::const_iterator video_it = 552 media::VideoCaptureDevice::Names::const_iterator video_it =
553 physical_video_devices_.begin(); 553 physical_video_devices_.begin();
554 for (; video_it != physical_video_devices_.end(); ++video_it) { 554 for (; video_it != physical_video_devices_.end(); ++video_it) {
555 std::string source_id = content::GetHMACForMediaDeviceID( 555 std::string source_id = content::GetHMACForMediaDeviceID(
556 browser_context_.GetResourceContext(), 556 browser_context_.GetResourceContext()->GetMediaDeviceIDSalt(),
557 origin_, 557 origin_,
558 video_it->id()); 558 video_it->id());
559 ASSERT_FALSE(source_id.empty()); 559 ASSERT_FALSE(source_id.empty());
560 StreamOptions options(true, true); 560 StreamOptions options(true, true);
561 AddSourceIdConstraint(source_id, &options.mandatory_video); 561 AddSourceIdConstraint(source_id, &options.mandatory_video);
562 562
563 SetupFakeUI(true); 563 SetupFakeUI(true);
564 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, options); 564 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, options);
565 EXPECT_EQ(host_->video_devices_[0].device.id, source_id); 565 EXPECT_EQ(host_->video_devices_[0].device.id, source_id);
566 } 566 }
567 } 567 }
568 568
569 // Test that we can generate streams where a optional sourceId is specified in 569 // Test that we can generate streams where a optional sourceId is specified in
570 // the request. 570 // the request.
571 TEST_F(MediaStreamDispatcherHostTest, GenerateStreamsWithOptionalSourceId) { 571 TEST_F(MediaStreamDispatcherHostTest, GenerateStreamsWithOptionalSourceId) {
572 ASSERT_GE(physical_audio_devices_.size(), 1u); 572 ASSERT_GE(physical_audio_devices_.size(), 1u);
573 ASSERT_GE(physical_video_devices_.size(), 1u); 573 ASSERT_GE(physical_video_devices_.size(), 1u);
574 574
575 media::AudioDeviceNames::const_iterator audio_it = 575 media::AudioDeviceNames::const_iterator audio_it =
576 physical_audio_devices_.begin(); 576 physical_audio_devices_.begin();
577 for (; audio_it != physical_audio_devices_.end(); ++audio_it) { 577 for (; audio_it != physical_audio_devices_.end(); ++audio_it) {
578 std::string source_id = content::GetHMACForMediaDeviceID( 578 std::string source_id = content::GetHMACForMediaDeviceID(
579 browser_context_.GetResourceContext(), 579 browser_context_.GetResourceContext()->GetMediaDeviceIDSalt(),
580 origin_, 580 origin_,
581 audio_it->unique_id); 581 audio_it->unique_id);
582 ASSERT_FALSE(source_id.empty()); 582 ASSERT_FALSE(source_id.empty());
583 StreamOptions options(true, true); 583 StreamOptions options(true, true);
584 AddSourceIdConstraint(source_id, &options.optional_audio); 584 AddSourceIdConstraint(source_id, &options.optional_audio);
585 585
586 SetupFakeUI(true); 586 SetupFakeUI(true);
587 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, options); 587 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, options);
588 EXPECT_EQ(host_->audio_devices_[0].device.id, source_id); 588 EXPECT_EQ(host_->audio_devices_[0].device.id, source_id);
589 } 589 }
590 590
591 media::VideoCaptureDevice::Names::const_iterator video_it = 591 media::VideoCaptureDevice::Names::const_iterator video_it =
592 physical_video_devices_.begin(); 592 physical_video_devices_.begin();
593 for (; video_it != physical_video_devices_.end(); ++video_it) { 593 for (; video_it != physical_video_devices_.end(); ++video_it) {
594 std::string source_id = content::GetHMACForMediaDeviceID( 594 std::string source_id = content::GetHMACForMediaDeviceID(
595 browser_context_.GetResourceContext(), 595 browser_context_.GetResourceContext()->GetMediaDeviceIDSalt(),
596 origin_, 596 origin_,
597 video_it->id()); 597 video_it->id());
598 ASSERT_FALSE(source_id.empty()); 598 ASSERT_FALSE(source_id.empty());
599 StreamOptions options(true, true); 599 StreamOptions options(true, true);
600 AddSourceIdConstraint(source_id, &options.optional_video); 600 AddSourceIdConstraint(source_id, &options.optional_video);
601 601
602 SetupFakeUI(true); 602 SetupFakeUI(true);
603 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, options); 603 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, options);
604 EXPECT_EQ(host_->video_devices_[0].device.id, source_id); 604 EXPECT_EQ(host_->video_devices_[0].device.id, source_id);
605 } 605 }
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
824 EnumerateDevicesAndWaitForResult(kRenderId, kPageRequestId, 824 EnumerateDevicesAndWaitForResult(kRenderId, kPageRequestId,
825 MEDIA_DEVICE_AUDIO_CAPTURE); 825 MEDIA_DEVICE_AUDIO_CAPTURE);
826 } 826 }
827 827
828 TEST_F(MediaStreamDispatcherHostTest, EnumerateVideoDevices) { 828 TEST_F(MediaStreamDispatcherHostTest, EnumerateVideoDevices) {
829 EnumerateDevicesAndWaitForResult(kRenderId, kPageRequestId, 829 EnumerateDevicesAndWaitForResult(kRenderId, kPageRequestId,
830 MEDIA_DEVICE_VIDEO_CAPTURE); 830 MEDIA_DEVICE_VIDEO_CAPTURE);
831 } 831 }
832 832
833 }; // namespace content 833 }; // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698