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

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

Issue 2820163002: Move MediaDeviceIDSalt from ProfileIOData to ProfileImpl. (Closed)
Patch Set: Fix 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>
11 #include <utility> 11 #include <utility>
12 12
13 #include "base/bind.h" 13 #include "base/bind.h"
14 #include "base/callback_helpers.h" 14 #include "base/callback_helpers.h"
15 #include "base/command_line.h" 15 #include "base/command_line.h"
16 #include "base/location.h" 16 #include "base/location.h"
17 #include "base/run_loop.h" 17 #include "base/run_loop.h"
18 #include "base/single_thread_task_runner.h" 18 #include "base/single_thread_task_runner.h"
19 #include "base/system_monitor/system_monitor.h" 19 #include "base/system_monitor/system_monitor.h"
20 #include "base/threading/thread_task_runner_handle.h" 20 #include "base/threading/thread_task_runner_handle.h"
21 #include "build/build_config.h" 21 #include "build/build_config.h"
22 #include "content/browser/browser_thread_impl.h" 22 #include "content/browser/browser_thread_impl.h"
23 #include "content/browser/renderer_host/media/audio_input_device_manager.h" 23 #include "content/browser/renderer_host/media/audio_input_device_manager.h"
24 #include "content/browser/renderer_host/media/media_stream_manager.h" 24 #include "content/browser/renderer_host/media/media_stream_manager.h"
25 #include "content/browser/renderer_host/media/media_stream_ui_proxy.h" 25 #include "content/browser/renderer_host/media/media_stream_ui_proxy.h"
26 #include "content/browser/renderer_host/media/video_capture_manager.h" 26 #include "content/browser/renderer_host/media/video_capture_manager.h"
27 #include "content/common/media/media_stream_messages.h" 27 #include "content/common/media/media_stream_messages.h"
28 #include "content/common/media/media_stream_options.h" 28 #include "content/common/media/media_stream_options.h"
29 #include "content/public/browser/browser_context.h"
29 #include "content/public/browser/media_device_id.h" 30 #include "content/public/browser/media_device_id.h"
30 #include "content/public/common/content_switches.h" 31 #include "content/public/common/content_switches.h"
31 #include "content/public/test/mock_resource_context.h"
32 #include "content/public/test/test_browser_context.h" 32 #include "content/public/test/test_browser_context.h"
33 #include "content/public/test/test_browser_thread_bundle.h" 33 #include "content/public/test/test_browser_thread_bundle.h"
34 #include "content/test/test_content_browser_client.h" 34 #include "content/test/test_content_browser_client.h"
35 #include "content/test/test_content_client.h" 35 #include "content/test/test_content_client.h"
36 #include "ipc/ipc_message_macros.h" 36 #include "ipc/ipc_message_macros.h"
37 #include "media/audio/audio_device_description.h" 37 #include "media/audio/audio_device_description.h"
38 #include "media/audio/audio_system_impl.h" 38 #include "media/audio/audio_system_impl.h"
39 #include "media/audio/mock_audio_manager.h" 39 #include "media/audio/mock_audio_manager.h"
40 #include "media/base/media_switches.h" 40 #include "media/base/media_switches.h"
41 #include "media/capture/video/fake_video_capture_device_factory.h" 41 #include "media/capture/video/fake_video_capture_device_factory.h"
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 // Make sure we use fake devices to avoid long delays. 262 // Make sure we use fake devices to avoid long delays.
263 base::CommandLine::ForCurrentProcess()->AppendSwitch( 263 base::CommandLine::ForCurrentProcess()->AppendSwitch(
264 switches::kUseFakeDeviceForMediaStream); 264 switches::kUseFakeDeviceForMediaStream);
265 auto mock_video_capture_provider = 265 auto mock_video_capture_provider =
266 base::MakeUnique<MockVideoCaptureProvider>(); 266 base::MakeUnique<MockVideoCaptureProvider>();
267 mock_video_capture_provider_ = mock_video_capture_provider.get(); 267 mock_video_capture_provider_ = mock_video_capture_provider.get();
268 // Create our own MediaStreamManager. 268 // Create our own MediaStreamManager.
269 media_stream_manager_ = base::MakeUnique<MediaStreamManager>( 269 media_stream_manager_ = base::MakeUnique<MediaStreamManager>(
270 audio_system_.get(), std::move(mock_video_capture_provider)); 270 audio_system_.get(), std::move(mock_video_capture_provider));
271 271
272 MockResourceContext* mock_resource_context =
273 static_cast<MockResourceContext*>(
274 browser_context_.GetResourceContext());
275
276 host_ = new MockMediaStreamDispatcherHost( 272 host_ = new MockMediaStreamDispatcherHost(
277 mock_resource_context->GetMediaDeviceIDSalt(), 273 browser_context_.GetMediaDeviceIDSalt(),
278 base::ThreadTaskRunnerHandle::Get(), media_stream_manager_.get()); 274 base::ThreadTaskRunnerHandle::Get(), media_stream_manager_.get());
279 275
280 // Use the fake content client and browser. 276 // Use the fake content client and browser.
281 content_client_.reset(new TestContentClient()); 277 content_client_.reset(new TestContentClient());
282 SetContentClient(content_client_.get()); 278 SetContentClient(content_client_.get());
283 old_browser_client_ = SetBrowserClientForTesting(host_.get()); 279 old_browser_client_ = SetBrowserClientForTesting(host_.get());
284 280
285 #if defined(OS_CHROMEOS) 281 #if defined(OS_CHROMEOS)
286 chromeos::CrasAudioHandler::InitializeForTesting(); 282 chromeos::CrasAudioHandler::InitializeForTesting();
287 #endif 283 #endif
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
414 } 410 }
415 411
416 bool DoesEveryDeviceMapToRawId(const StreamDeviceInfoArray& devices, 412 bool DoesEveryDeviceMapToRawId(const StreamDeviceInfoArray& devices,
417 const url::Origin& origin) { 413 const url::Origin& origin) {
418 for (size_t i = 0; i < devices.size(); ++i) { 414 for (size_t i = 0; i < devices.size(); ++i) {
419 bool found_match = false; 415 bool found_match = false;
420 media::AudioDeviceDescriptions::const_iterator audio_it = 416 media::AudioDeviceDescriptions::const_iterator audio_it =
421 audio_device_descriptions_.begin(); 417 audio_device_descriptions_.begin();
422 for (; audio_it != audio_device_descriptions_.end(); ++audio_it) { 418 for (; audio_it != audio_device_descriptions_.end(); ++audio_it) {
423 if (content::DoesMediaDeviceIDMatchHMAC( 419 if (content::DoesMediaDeviceIDMatchHMAC(
424 browser_context_.GetResourceContext()->GetMediaDeviceIDSalt(), 420 browser_context_.GetMediaDeviceIDSalt(), origin,
425 origin, 421 devices[i].device.id, audio_it->unique_id)) {
426 devices[i].device.id,
427 audio_it->unique_id)) {
428 EXPECT_FALSE(found_match); 422 EXPECT_FALSE(found_match);
429 found_match = true; 423 found_match = true;
430 } 424 }
431 } 425 }
432 for (const std::string& device_id : stub_video_device_ids_) { 426 for (const std::string& device_id : stub_video_device_ids_) {
433 if (content::DoesMediaDeviceIDMatchHMAC( 427 if (content::DoesMediaDeviceIDMatchHMAC(
434 browser_context_.GetResourceContext()->GetMediaDeviceIDSalt(), 428 browser_context_.GetMediaDeviceIDSalt(), origin,
435 origin, devices[i].device.id, device_id)) { 429 devices[i].device.id, device_id)) {
436 EXPECT_FALSE(found_match); 430 EXPECT_FALSE(found_match);
437 found_match = true; 431 found_match = true;
438 } 432 }
439 } 433 }
440 if (!found_match) 434 if (!found_match)
441 return false; 435 return false;
442 } 436 }
443 return true; 437 return true;
444 } 438 }
445 439
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
514 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, controls); 508 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, controls);
515 509
516 EXPECT_EQ(host_->audio_devices_.size(), 1u); 510 EXPECT_EQ(host_->audio_devices_.size(), 1u);
517 EXPECT_EQ(host_->video_devices_.size(), 1u); 511 EXPECT_EQ(host_->video_devices_.size(), 1u);
518 } 512 }
519 513
520 TEST_F(MediaStreamDispatcherHostTest, GenerateStreamWithDepthVideo) { 514 TEST_F(MediaStreamDispatcherHostTest, GenerateStreamWithDepthVideo) {
521 // We specify to generate both audio and video stream. 515 // We specify to generate both audio and video stream.
522 StreamControls controls(true, true); 516 StreamControls controls(true, true);
523 std::string source_id = content::GetHMACForMediaDeviceID( 517 std::string source_id = content::GetHMACForMediaDeviceID(
524 browser_context_.GetResourceContext()->GetMediaDeviceIDSalt(), origin_, 518 browser_context_.GetMediaDeviceIDSalt(), origin_, kDepthVideoDeviceId);
525 kDepthVideoDeviceId);
526 // |source_id| corresponds to the depth device. As we can generate only one 519 // |source_id| corresponds to the depth device. As we can generate only one
527 // video stream using GenerateStreamAndWaitForResult, we use 520 // video stream using GenerateStreamAndWaitForResult, we use
528 // controls.video.source_id to specify that the stream is depth video. 521 // controls.video.source_id to specify that the stream is depth video.
529 // See also MediaStreamManager::GenerateStream and other tests here. 522 // See also MediaStreamManager::GenerateStream and other tests here.
530 controls.video.device_id = source_id; 523 controls.video.device_id = source_id;
531 524
532 SetupFakeUI(true); 525 SetupFakeUI(true);
533 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, controls); 526 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, controls);
534 527
535 // We specified the generation and expect to get 528 // We specified the generation and expect to get
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
668 // Test that we can generate streams where a sourceId is specified in 661 // Test that we can generate streams where a sourceId is specified in
669 // the request. 662 // the request.
670 TEST_F(MediaStreamDispatcherHostTest, GenerateStreamsWithSourceId) { 663 TEST_F(MediaStreamDispatcherHostTest, GenerateStreamsWithSourceId) {
671 ASSERT_GE(audio_device_descriptions_.size(), 1u); 664 ASSERT_GE(audio_device_descriptions_.size(), 1u);
672 ASSERT_GE(stub_video_device_ids_.size(), 1u); 665 ASSERT_GE(stub_video_device_ids_.size(), 1u);
673 666
674 media::AudioDeviceDescriptions::const_iterator audio_it = 667 media::AudioDeviceDescriptions::const_iterator audio_it =
675 audio_device_descriptions_.begin(); 668 audio_device_descriptions_.begin();
676 for (; audio_it != audio_device_descriptions_.end(); ++audio_it) { 669 for (; audio_it != audio_device_descriptions_.end(); ++audio_it) {
677 std::string source_id = content::GetHMACForMediaDeviceID( 670 std::string source_id = content::GetHMACForMediaDeviceID(
678 browser_context_.GetResourceContext()->GetMediaDeviceIDSalt(), 671 browser_context_.GetMediaDeviceIDSalt(), origin_, audio_it->unique_id);
679 origin_,
680 audio_it->unique_id);
681 ASSERT_FALSE(source_id.empty()); 672 ASSERT_FALSE(source_id.empty());
682 StreamControls controls(true, true); 673 StreamControls controls(true, true);
683 controls.audio.device_id = source_id; 674 controls.audio.device_id = source_id;
684 675
685 SetupFakeUI(true); 676 SetupFakeUI(true);
686 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, controls); 677 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, controls);
687 EXPECT_EQ(host_->audio_devices_[0].device.id, source_id); 678 EXPECT_EQ(host_->audio_devices_[0].device.id, source_id);
688 } 679 }
689 680
690 for (const std::string& device_id : stub_video_device_ids_) { 681 for (const std::string& device_id : stub_video_device_ids_) {
691 std::string source_id = content::GetHMACForMediaDeviceID( 682 std::string source_id = content::GetHMACForMediaDeviceID(
692 browser_context_.GetResourceContext()->GetMediaDeviceIDSalt(), origin_, 683 browser_context_.GetMediaDeviceIDSalt(), origin_, device_id);
693 device_id);
694 ASSERT_FALSE(source_id.empty()); 684 ASSERT_FALSE(source_id.empty());
695 StreamControls controls(true, true); 685 StreamControls controls(true, true);
696 controls.video.device_id = source_id; 686 controls.video.device_id = source_id;
697 687
698 SetupFakeUI(true); 688 SetupFakeUI(true);
699 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, controls); 689 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, controls);
700 EXPECT_EQ(host_->video_devices_[0].device.id, source_id); 690 EXPECT_EQ(host_->video_devices_[0].device.id, source_id);
701 } 691 }
702 } 692 }
703 693
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
881 base::RunLoop run_loop; 871 base::RunLoop run_loop;
882 EXPECT_CALL(*host_.get(), OnDeviceStopped(kRenderId)) 872 EXPECT_CALL(*host_.get(), OnDeviceStopped(kRenderId))
883 .WillOnce(testing::InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); 873 .WillOnce(testing::InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit));
884 media_stream_manager_->media_devices_manager()->OnDevicesChanged( 874 media_stream_manager_->media_devices_manager()->OnDevicesChanged(
885 base::SystemMonitor::DEVTYPE_VIDEO_CAPTURE); 875 base::SystemMonitor::DEVTYPE_VIDEO_CAPTURE);
886 876
887 run_loop.Run(); 877 run_loop.Run();
888 } 878 }
889 879
890 }; // namespace content 880 }; // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698