| 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 <stddef.h> | 5 #include <stddef.h> |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/location.h" | 11 #include "base/location.h" |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/run_loop.h" | 13 #include "base/run_loop.h" |
| 14 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
| 15 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
| 16 #include "base/thread_task_runner_handle.h" | 16 #include "base/thread_task_runner_handle.h" |
| 17 #include "build/build_config.h" | 17 #include "build/build_config.h" |
| 18 #include "content/browser/browser_thread_impl.h" | 18 #include "content/browser/browser_thread_impl.h" |
| 19 #include "content/browser/renderer_host/media/media_stream_manager.h" | 19 #include "content/browser/renderer_host/media/media_stream_manager.h" |
| 20 #include "content/browser/renderer_host/media/media_stream_requester.h" | 20 #include "content/browser/renderer_host/media/media_stream_requester.h" |
| 21 #include "content/browser/renderer_host/media/media_stream_ui_proxy.h" | 21 #include "content/browser/renderer_host/media/media_stream_ui_proxy.h" |
| 22 #include "content/common/media/media_stream_options.h" | 22 #include "content/common/media/media_stream_options.h" |
| 23 #include "content/public/common/content_switches.h" | 23 #include "content/public/common/content_switches.h" |
| 24 #include "content/public/test/test_browser_thread_bundle.h" | 24 #include "content/public/test/test_browser_thread_bundle.h" |
| 25 #include "media/audio/audio_manager_base.h" | 25 #include "media/audio/audio_device_description.h" |
| 26 #include "media/audio/fake_audio_log_factory.h" | 26 #include "media/audio/fake_audio_log_factory.h" |
| 27 #include "media/base/media_switches.h" | 27 #include "media/base/media_switches.h" |
| 28 #include "testing/gmock/include/gmock/gmock.h" | 28 #include "testing/gmock/include/gmock/gmock.h" |
| 29 #include "testing/gtest/include/gtest/gtest.h" | 29 #include "testing/gtest/include/gtest/gtest.h" |
| 30 | 30 |
| 31 #if defined(USE_ALSA) | 31 #if defined(USE_ALSA) |
| 32 #include "media/audio/alsa/audio_manager_alsa.h" | 32 #include "media/audio/alsa/audio_manager_alsa.h" |
| 33 #elif defined(OS_ANDROID) | 33 #elif defined(OS_ANDROID) |
| 34 #include "media/audio/android/audio_manager_android.h" | 34 #include "media/audio/android/audio_manager_android.h" |
| 35 #elif defined(OS_MACOSX) | 35 #elif defined(OS_MACOSX) |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 &fake_audio_log_factory_), | 76 &fake_audio_log_factory_), |
| 77 num_output_devices_(2), | 77 num_output_devices_(2), |
| 78 num_input_devices_(2) {} | 78 num_input_devices_(2) {} |
| 79 ~MockAudioManager() override {} | 79 ~MockAudioManager() override {} |
| 80 | 80 |
| 81 void GetAudioInputDeviceNames( | 81 void GetAudioInputDeviceNames( |
| 82 media::AudioDeviceNames* device_names) override { | 82 media::AudioDeviceNames* device_names) override { |
| 83 DCHECK(device_names->empty()); | 83 DCHECK(device_names->empty()); |
| 84 | 84 |
| 85 // AudioManagers add a default device when there is at least one real device | 85 // AudioManagers add a default device when there is at least one real device |
| 86 if (num_input_devices_ > 0) { | 86 if (num_input_devices_ > 0) |
| 87 device_names->push_back(media::AudioDeviceName( | 87 device_names->push_back(media::AudioDeviceName::CreateDefault()); |
| 88 "Default", AudioManagerBase::kDefaultDeviceId)); | 88 |
| 89 } | |
| 90 for (size_t i = 0; i < num_input_devices_; i++) { | 89 for (size_t i = 0; i < num_input_devices_; i++) { |
| 91 device_names->push_back(media::AudioDeviceName( | 90 device_names->push_back(media::AudioDeviceName( |
| 92 std::string("fake_device_name_") + base::SizeTToString(i), | 91 std::string("fake_device_name_") + base::SizeTToString(i), |
| 93 std::string("fake_device_id_") + base::SizeTToString(i))); | 92 std::string("fake_device_id_") + base::SizeTToString(i))); |
| 94 } | 93 } |
| 95 } | 94 } |
| 96 | 95 |
| 97 void GetAudioOutputDeviceNames( | 96 void GetAudioOutputDeviceNames( |
| 98 media::AudioDeviceNames* device_names) override { | 97 media::AudioDeviceNames* device_names) override { |
| 99 DCHECK(device_names->empty()); | 98 DCHECK(device_names->empty()); |
| 100 | 99 |
| 101 // AudioManagers add a default device when there is at least one real device | 100 // AudioManagers add a default device when there is at least one real device |
| 102 if (num_output_devices_ > 0) { | 101 if (num_output_devices_ > 0) |
| 103 device_names->push_back(media::AudioDeviceName( | 102 device_names->push_back(media::AudioDeviceName::CreateDefault()); |
| 104 "Default", AudioManagerBase::kDefaultDeviceId)); | 103 |
| 105 } | |
| 106 for (size_t i = 0; i < num_output_devices_; i++) { | 104 for (size_t i = 0; i < num_output_devices_; i++) { |
| 107 device_names->push_back(media::AudioDeviceName( | 105 device_names->push_back(media::AudioDeviceName( |
| 108 std::string("fake_device_name_") + base::SizeTToString(i), | 106 std::string("fake_device_name_") + base::SizeTToString(i), |
| 109 std::string("fake_device_id_") + base::SizeTToString(i))); | 107 std::string("fake_device_id_") + base::SizeTToString(i))); |
| 110 } | 108 } |
| 111 } | 109 } |
| 112 | 110 |
| 113 media::AudioParameters GetDefaultOutputStreamParameters() override { | 111 media::AudioParameters GetDefaultOutputStreamParameters() override { |
| 114 return media::AudioParameters(media::AudioParameters::AUDIO_PCM_LOW_LATENCY, | 112 return media::AudioParameters(media::AudioParameters::AUDIO_PCM_LOW_LATENCY, |
| 115 media::CHANNEL_LAYOUT_STEREO, 48000, 16, 128); | 113 media::CHANNEL_LAYOUT_STEREO, 48000, 16, 128); |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 307 | 305 |
| 308 // Expecting the callback from the second request will be triggered and | 306 // Expecting the callback from the second request will be triggered and |
| 309 // quit the test. | 307 // quit the test. |
| 310 EXPECT_CALL(*this, Response(1)); | 308 EXPECT_CALL(*this, Response(1)); |
| 311 run_loop_.Run(); | 309 run_loop_.Run(); |
| 312 } | 310 } |
| 313 | 311 |
| 314 TEST_F(MediaStreamManagerTest, DeviceID) { | 312 TEST_F(MediaStreamManagerTest, DeviceID) { |
| 315 GURL security_origin("http://localhost"); | 313 GURL security_origin("http://localhost"); |
| 316 const std::string unique_default_id( | 314 const std::string unique_default_id( |
| 317 media::AudioManagerBase::kDefaultDeviceId); | 315 media::AudioDeviceDescription::kDefaultDeviceId); |
| 318 const std::string hashed_default_id = | 316 const std::string hashed_default_id = |
| 319 MediaStreamManager::GetHMACForMediaDeviceID( | 317 MediaStreamManager::GetHMACForMediaDeviceID( |
| 320 GetMockSaltCallback(), security_origin, unique_default_id); | 318 GetMockSaltCallback(), security_origin, unique_default_id); |
| 321 EXPECT_TRUE(MediaStreamManager::DoesMediaDeviceIDMatchHMAC( | 319 EXPECT_TRUE(MediaStreamManager::DoesMediaDeviceIDMatchHMAC( |
| 322 GetMockSaltCallback(), security_origin, hashed_default_id, | 320 GetMockSaltCallback(), security_origin, hashed_default_id, |
| 323 unique_default_id)); | 321 unique_default_id)); |
| 324 EXPECT_EQ(unique_default_id, hashed_default_id); | 322 EXPECT_EQ(unique_default_id, hashed_default_id); |
| 325 | 323 |
| 326 const std::string unique_communications_id( | 324 const std::string unique_communications_id( |
| 327 media::AudioManagerBase::kCommunicationsDeviceId); | 325 media::AudioDeviceDescription::kCommunicationsDeviceId); |
| 328 const std::string hashed_communications_id = | 326 const std::string hashed_communications_id = |
| 329 MediaStreamManager::GetHMACForMediaDeviceID( | 327 MediaStreamManager::GetHMACForMediaDeviceID( |
| 330 GetMockSaltCallback(), security_origin, unique_communications_id); | 328 GetMockSaltCallback(), security_origin, unique_communications_id); |
| 331 EXPECT_TRUE(MediaStreamManager::DoesMediaDeviceIDMatchHMAC( | 329 EXPECT_TRUE(MediaStreamManager::DoesMediaDeviceIDMatchHMAC( |
| 332 GetMockSaltCallback(), security_origin, hashed_communications_id, | 330 GetMockSaltCallback(), security_origin, hashed_communications_id, |
| 333 unique_communications_id)); | 331 unique_communications_id)); |
| 334 EXPECT_EQ(unique_communications_id, hashed_communications_id); | 332 EXPECT_EQ(unique_communications_id, hashed_communications_id); |
| 335 | 333 |
| 336 const std::string unique_other_id("other-unique-id"); | 334 const std::string unique_other_id("other-unique-id"); |
| 337 const std::string hashed_other_id = | 335 const std::string hashed_other_id = |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 421 MockDevicesEnumerated(render_frame_id, page_request_id, _, _)); | 419 MockDevicesEnumerated(render_frame_id, page_request_id, _, _)); |
| 422 std::string label = media_stream_manager_->EnumerateDevices( | 420 std::string label = media_stream_manager_->EnumerateDevices( |
| 423 &requester, render_process_id, render_frame_id, GetMockSaltCallback(), | 421 &requester, render_process_id, render_frame_id, GetMockSaltCallback(), |
| 424 page_request_id, MEDIA_DEVICE_AUDIO_CAPTURE, security_origin); | 422 page_request_id, MEDIA_DEVICE_AUDIO_CAPTURE, security_origin); |
| 425 run_loop.Run(); | 423 run_loop.Run(); |
| 426 media_stream_manager_->CancelRequest(label); | 424 media_stream_manager_->CancelRequest(label); |
| 427 } | 425 } |
| 428 } | 426 } |
| 429 | 427 |
| 430 } // namespace content | 428 } // namespace content |
| OLD | NEW |