| 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 "content/browser/renderer_host/media/audio_renderer_host.h" | 5 #include "content/browser/renderer_host/media/audio_renderer_host.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 | 10 |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/memory/ptr_util.h" | 14 #include "base/memory/ptr_util.h" |
| 15 #include "base/run_loop.h" | 15 #include "base/run_loop.h" |
| 16 #include "base/sync_socket.h" | 16 #include "base/sync_socket.h" |
| 17 #include "base/threading/thread_task_runner_handle.h" | 17 #include "base/threading/thread_task_runner_handle.h" |
| 18 #include "content/browser/media/capture/audio_mirroring_manager.h" | 18 #include "content/browser/media/capture/audio_mirroring_manager.h" |
| 19 #include "content/browser/media/media_internals.h" | 19 #include "content/browser/media/media_internals.h" |
| 20 #include "content/browser/renderer_host/media/audio_input_device_manager.h" | 20 #include "content/browser/renderer_host/media/audio_input_device_manager.h" |
| 21 #include "content/browser/renderer_host/media/media_stream_manager.h" | 21 #include "content/browser/renderer_host/media/media_stream_manager.h" |
| 22 #include "content/common/media/audio_messages.h" | 22 #include "content/common/media/audio_messages.h" |
| 23 #include "content/public/browser/media_device_id.h" | 23 #include "content/public/browser/media_device_id.h" |
| 24 #include "content/public/common/content_switches.h" | 24 #include "content/public/common/content_switches.h" |
| 25 #include "content/public/test/mock_render_process_host.h" | 25 #include "content/public/test/mock_render_process_host.h" |
| 26 #include "content/public/test/test_browser_context.h" | 26 #include "content/public/test/test_browser_context.h" |
| 27 #include "content/public/test/test_browser_thread_bundle.h" | 27 #include "content/public/test/test_browser_thread_bundle.h" |
| 28 #include "ipc/ipc_message_utils.h" | 28 #include "ipc/ipc_message_utils.h" |
| 29 #include "media/audio/audio_system_impl.h" |
| 29 #include "media/audio/fake_audio_log_factory.h" | 30 #include "media/audio/fake_audio_log_factory.h" |
| 30 #include "media/audio/fake_audio_manager.h" | 31 #include "media/audio/fake_audio_manager.h" |
| 31 #include "media/base/bind_to_current_loop.h" | 32 #include "media/base/bind_to_current_loop.h" |
| 32 #include "media/base/media_switches.h" | 33 #include "media/base/media_switches.h" |
| 33 #include "testing/gmock/include/gmock/gmock.h" | 34 #include "testing/gmock/include/gmock/gmock.h" |
| 34 #include "testing/gtest/include/gtest/gtest.h" | 35 #include "testing/gtest/include/gtest/gtest.h" |
| 35 | 36 |
| 36 using ::testing::_; | 37 using ::testing::_; |
| 37 using ::testing::Assign; | 38 using ::testing::Assign; |
| 38 using ::testing::AtLeast; | 39 using ::testing::AtLeast; |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 std::map<std::string, std::string> associations_; | 122 std::map<std::string, std::string> associations_; |
| 122 }; | 123 }; |
| 123 | 124 |
| 124 } // namespace | 125 } // namespace |
| 125 | 126 |
| 126 class MockAudioRendererHost : public AudioRendererHost { | 127 class MockAudioRendererHost : public AudioRendererHost { |
| 127 public: | 128 public: |
| 128 MockAudioRendererHost(base::RunLoop* auth_run_loop, | 129 MockAudioRendererHost(base::RunLoop* auth_run_loop, |
| 129 int render_process_id, | 130 int render_process_id, |
| 130 media::AudioManager* audio_manager, | 131 media::AudioManager* audio_manager, |
| 132 media::AudioSystem* audio_system, |
| 131 AudioMirroringManager* mirroring_manager, | 133 AudioMirroringManager* mirroring_manager, |
| 132 MediaStreamManager* media_stream_manager, | 134 MediaStreamManager* media_stream_manager, |
| 133 const std::string& salt) | 135 const std::string& salt) |
| 134 : AudioRendererHost(render_process_id, | 136 : AudioRendererHost(render_process_id, |
| 135 audio_manager, | 137 audio_manager, |
| 138 audio_system, |
| 136 mirroring_manager, | 139 mirroring_manager, |
| 137 media_stream_manager, | 140 media_stream_manager, |
| 138 salt), | 141 salt), |
| 139 shared_memory_length_(0), | 142 shared_memory_length_(0), |
| 140 auth_run_loop_(auth_run_loop) { | 143 auth_run_loop_(auth_run_loop) { |
| 141 set_render_frame_id_validate_function_for_testing(&ValidateRenderFrameId); | 144 set_render_frame_id_validate_function_for_testing(&ValidateRenderFrameId); |
| 142 } | 145 } |
| 143 | 146 |
| 144 // A list of mock methods. | 147 // A list of mock methods. |
| 145 MOCK_METHOD4(OnDeviceAuthorized, | 148 MOCK_METHOD4(OnDeviceAuthorized, |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 DISALLOW_COPY_AND_ASSIGN(MockAudioRendererHost); | 231 DISALLOW_COPY_AND_ASSIGN(MockAudioRendererHost); |
| 229 }; | 232 }; |
| 230 | 233 |
| 231 class AudioRendererHostTest : public testing::Test { | 234 class AudioRendererHostTest : public testing::Test { |
| 232 public: | 235 public: |
| 233 AudioRendererHostTest() | 236 AudioRendererHostTest() |
| 234 : log_factory(base::MakeUnique<media::FakeAudioLogFactory>()), | 237 : log_factory(base::MakeUnique<media::FakeAudioLogFactory>()), |
| 235 audio_manager_(base::MakeUnique<FakeAudioManagerWithAssociations>( | 238 audio_manager_(base::MakeUnique<FakeAudioManagerWithAssociations>( |
| 236 base::ThreadTaskRunnerHandle::Get(), | 239 base::ThreadTaskRunnerHandle::Get(), |
| 237 log_factory.get())), | 240 log_factory.get())), |
| 241 audio_system_(media::AudioSystemImpl::Create(audio_manager_.get())), |
| 238 render_process_host_(&browser_context_, &auth_run_loop_) { | 242 render_process_host_(&browser_context_, &auth_run_loop_) { |
| 239 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 243 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 240 switches::kUseFakeDeviceForMediaStream); | 244 switches::kUseFakeDeviceForMediaStream); |
| 241 media_stream_manager_.reset(new MediaStreamManager(audio_manager_.get())); | 245 media_stream_manager_.reset(new MediaStreamManager(audio_manager_.get())); |
| 242 host_ = new MockAudioRendererHost( | 246 host_ = new MockAudioRendererHost( |
| 243 &auth_run_loop_, render_process_host_.GetID(), audio_manager_.get(), | 247 &auth_run_loop_, render_process_host_.GetID(), audio_manager_.get(), |
| 244 &mirroring_manager_, media_stream_manager_.get(), kSalt); | 248 audio_system_.get(), &mirroring_manager_, media_stream_manager_.get(), |
| 249 kSalt); |
| 245 | 250 |
| 246 // Simulate IPC channel connected. | 251 // Simulate IPC channel connected. |
| 247 host_->set_peer_process_for_testing(base::Process::Current()); | 252 host_->set_peer_process_for_testing(base::Process::Current()); |
| 248 } | 253 } |
| 249 | 254 |
| 250 ~AudioRendererHostTest() override { | 255 ~AudioRendererHostTest() override { |
| 251 // Simulate closing the IPC channel and give the audio thread time to close | 256 // Simulate closing the IPC channel and give the audio thread time to close |
| 252 // the underlying streams. | 257 // the underlying streams. |
| 253 host_->OnChannelClosing(); | 258 host_->OnChannelClosing(); |
| 254 SyncWithAudioThread(); | 259 SyncWithAudioThread(); |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 504 } | 509 } |
| 505 | 510 |
| 506 private: | 511 private: |
| 507 // MediaStreamManager uses a DestructionObserver, so it must outlive the | 512 // MediaStreamManager uses a DestructionObserver, so it must outlive the |
| 508 // TestBrowserThreadBundle. | 513 // TestBrowserThreadBundle. |
| 509 std::unique_ptr<MediaStreamManager> media_stream_manager_; | 514 std::unique_ptr<MediaStreamManager> media_stream_manager_; |
| 510 TestBrowserThreadBundle thread_bundle_; | 515 TestBrowserThreadBundle thread_bundle_; |
| 511 TestBrowserContext browser_context_; | 516 TestBrowserContext browser_context_; |
| 512 std::unique_ptr<media::FakeAudioLogFactory> log_factory; | 517 std::unique_ptr<media::FakeAudioLogFactory> log_factory; |
| 513 std::unique_ptr<FakeAudioManagerWithAssociations> audio_manager_; | 518 std::unique_ptr<FakeAudioManagerWithAssociations> audio_manager_; |
| 519 std::unique_ptr<media::AudioSystem> audio_system_; |
| 514 MockAudioMirroringManager mirroring_manager_; | 520 MockAudioMirroringManager mirroring_manager_; |
| 515 base::RunLoop auth_run_loop_; | 521 base::RunLoop auth_run_loop_; |
| 516 MockRenderProcessHostWithSignaling render_process_host_; | 522 MockRenderProcessHostWithSignaling render_process_host_; |
| 517 scoped_refptr<MockAudioRendererHost> host_; | 523 scoped_refptr<MockAudioRendererHost> host_; |
| 518 | 524 |
| 519 DISALLOW_COPY_AND_ASSIGN(AudioRendererHostTest); | 525 DISALLOW_COPY_AND_ASSIGN(AudioRendererHostTest); |
| 520 }; | 526 }; |
| 521 | 527 |
| 522 TEST_F(AudioRendererHostTest, CreateAndClose) { | 528 TEST_F(AudioRendererHostTest, CreateAndClose) { |
| 523 Create(); | 529 Create(); |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 616 } | 622 } |
| 617 | 623 |
| 618 TEST_F(AudioRendererHostTest, CreateFailsForInvalidRenderFrame) { | 624 TEST_F(AudioRendererHostTest, CreateFailsForInvalidRenderFrame) { |
| 619 CreateWithInvalidRenderFrameId(); | 625 CreateWithInvalidRenderFrameId(); |
| 620 Close(); | 626 Close(); |
| 621 } | 627 } |
| 622 | 628 |
| 623 // TODO(hclam): Add tests for data conversation in low latency mode. | 629 // TODO(hclam): Add tests for data conversation in low latency mode. |
| 624 | 630 |
| 625 } // namespace content | 631 } // namespace content |
| OLD | NEW |