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