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

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

Issue 2578983003: Add AudioStreamRegistry. Move stream counting logic (Closed)
Patch Set: Thread checking. Created 4 years 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/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/run_loop.h" 14 #include "base/run_loop.h"
15 #include "base/sync_socket.h" 15 #include "base/sync_socket.h"
16 #include "content/browser/media/capture/audio_mirroring_manager.h" 16 #include "content/browser/media/capture/audio_mirroring_manager.h"
17 #include "content/browser/media/media_internals.h" 17 #include "content/browser/media/media_internals.h"
18 #include "content/browser/renderer_host/media/audio_input_device_manager.h" 18 #include "content/browser/renderer_host/media/audio_input_device_manager.h"
19 #include "content/browser/renderer_host/media/audio_stream_registry_impl.h"
19 #include "content/browser/renderer_host/media/media_stream_manager.h" 20 #include "content/browser/renderer_host/media/media_stream_manager.h"
20 #include "content/common/media/audio_messages.h" 21 #include "content/common/media/audio_messages.h"
21 #include "content/public/browser/media_device_id.h" 22 #include "content/public/browser/media_device_id.h"
22 #include "content/public/common/content_switches.h" 23 #include "content/public/common/content_switches.h"
23 #include "content/public/test/mock_render_process_host.h" 24 #include "content/public/test/mock_render_process_host.h"
24 #include "content/public/test/test_browser_context.h" 25 #include "content/public/test/test_browser_context.h"
25 #include "content/public/test/test_browser_thread_bundle.h" 26 #include "content/public/test/test_browser_thread_bundle.h"
26 #include "ipc/ipc_message_utils.h" 27 #include "ipc/ipc_message_utils.h"
27 #include "media/audio/fake_audio_log_factory.h" 28 #include "media/audio/fake_audio_log_factory.h"
28 #include "media/audio/fake_audio_manager.h" 29 #include "media/audio/fake_audio_manager.h"
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 private: 119 private:
119 std::map<std::string, std::string> associations_; 120 std::map<std::string, std::string> associations_;
120 }; 121 };
121 122
122 } // namespace 123 } // namespace
123 124
124 class MockAudioRendererHost : public AudioRendererHost { 125 class MockAudioRendererHost : public AudioRendererHost {
125 public: 126 public:
126 MockAudioRendererHost(base::RunLoop* auth_run_loop, 127 MockAudioRendererHost(base::RunLoop* auth_run_loop,
127 int render_process_id, 128 int render_process_id,
129 AudioStreamRegistry* stream_registry,
128 media::AudioManager* audio_manager, 130 media::AudioManager* audio_manager,
129 AudioMirroringManager* mirroring_manager, 131 AudioMirroringManager* mirroring_manager,
130 MediaStreamManager* media_stream_manager, 132 MediaStreamManager* media_stream_manager,
131 const std::string& salt) 133 const std::string& salt)
132 : AudioRendererHost(render_process_id, 134 : AudioRendererHost(render_process_id,
135 stream_registry,
133 audio_manager, 136 audio_manager,
134 mirroring_manager, 137 mirroring_manager,
135 media_stream_manager, 138 media_stream_manager,
136 salt), 139 salt),
137 shared_memory_length_(0), 140 shared_memory_length_(0),
138 auth_run_loop_(auth_run_loop) { 141 auth_run_loop_(auth_run_loop) {
139 set_render_frame_id_validate_function_for_testing(&ValidateRenderFrameId); 142 set_render_frame_id_validate_function_for_testing(&ValidateRenderFrameId);
140 } 143 }
141 144
142 // A list of mock methods. 145 // A list of mock methods.
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 DISALLOW_COPY_AND_ASSIGN(MockAudioRendererHost); 229 DISALLOW_COPY_AND_ASSIGN(MockAudioRendererHost);
227 }; 230 };
228 231
229 class AudioRendererHostTest : public testing::Test { 232 class AudioRendererHostTest : public testing::Test {
230 public: 233 public:
231 AudioRendererHostTest() 234 AudioRendererHostTest()
232 : log_factory(base::MakeUnique<media::FakeAudioLogFactory>()), 235 : log_factory(base::MakeUnique<media::FakeAudioLogFactory>()),
233 audio_manager_(base::MakeUnique<FakeAudioManagerWithAssociations>( 236 audio_manager_(base::MakeUnique<FakeAudioManagerWithAssociations>(
234 base::ThreadTaskRunnerHandle::Get(), 237 base::ThreadTaskRunnerHandle::Get(),
235 log_factory.get())), 238 log_factory.get())),
236 render_process_host_(&browser_context_, &auth_run_loop_) { 239 render_process_host_(&browser_context_, &auth_run_loop_),
240 stream_registry_(render_process_host_.GetID()) {
237 base::CommandLine::ForCurrentProcess()->AppendSwitch( 241 base::CommandLine::ForCurrentProcess()->AppendSwitch(
238 switches::kUseFakeDeviceForMediaStream); 242 switches::kUseFakeDeviceForMediaStream);
239 media_stream_manager_.reset(new MediaStreamManager(audio_manager_.get())); 243 media_stream_manager_.reset(new MediaStreamManager(audio_manager_.get()));
240 host_ = new MockAudioRendererHost( 244 host_ = new MockAudioRendererHost(
241 &auth_run_loop_, render_process_host_.GetID(), audio_manager_.get(), 245 &auth_run_loop_, render_process_host_.GetID(), &stream_registry_,
242 &mirroring_manager_, media_stream_manager_.get(), kSalt); 246 audio_manager_.get(), &mirroring_manager_, media_stream_manager_.get(),
247 kSalt);
243 248
244 // Simulate IPC channel connected. 249 // Simulate IPC channel connected.
245 host_->set_peer_process_for_testing(base::Process::Current()); 250 host_->set_peer_process_for_testing(base::Process::Current());
246 } 251 }
247 252
248 ~AudioRendererHostTest() override { 253 ~AudioRendererHostTest() override {
249 // Simulate closing the IPC channel and give the audio thread time to close 254 // Simulate closing the IPC channel and give the audio thread time to close
250 // the underlying streams. 255 // the underlying streams.
251 host_->OnChannelClosing(); 256 host_->OnChannelClosing();
252 SyncWithAudioThread(); 257 SyncWithAudioThread();
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
505 // MediaStreamManager uses a DestructionObserver, so it must outlive the 510 // MediaStreamManager uses a DestructionObserver, so it must outlive the
506 // TestBrowserThreadBundle. 511 // TestBrowserThreadBundle.
507 std::unique_ptr<MediaStreamManager> media_stream_manager_; 512 std::unique_ptr<MediaStreamManager> media_stream_manager_;
508 TestBrowserThreadBundle thread_bundle_; 513 TestBrowserThreadBundle thread_bundle_;
509 TestBrowserContext browser_context_; 514 TestBrowserContext browser_context_;
510 std::unique_ptr<media::FakeAudioLogFactory> log_factory; 515 std::unique_ptr<media::FakeAudioLogFactory> log_factory;
511 std::unique_ptr<FakeAudioManagerWithAssociations> audio_manager_; 516 std::unique_ptr<FakeAudioManagerWithAssociations> audio_manager_;
512 MockAudioMirroringManager mirroring_manager_; 517 MockAudioMirroringManager mirroring_manager_;
513 base::RunLoop auth_run_loop_; 518 base::RunLoop auth_run_loop_;
514 MockRenderProcessHostWithSignaling render_process_host_; 519 MockRenderProcessHostWithSignaling render_process_host_;
520 AudioStreamRegistryImpl stream_registry_;
515 scoped_refptr<MockAudioRendererHost> host_; 521 scoped_refptr<MockAudioRendererHost> host_;
516 522
517 DISALLOW_COPY_AND_ASSIGN(AudioRendererHostTest); 523 DISALLOW_COPY_AND_ASSIGN(AudioRendererHostTest);
518 }; 524 };
519 525
520 TEST_F(AudioRendererHostTest, CreateAndClose) { 526 TEST_F(AudioRendererHostTest, CreateAndClose) {
521 Create(); 527 Create();
522 Close(); 528 Close();
523 } 529 }
524 530
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
614 } 620 }
615 621
616 TEST_F(AudioRendererHostTest, CreateFailsForInvalidRenderFrame) { 622 TEST_F(AudioRendererHostTest, CreateFailsForInvalidRenderFrame) {
617 CreateWithInvalidRenderFrameId(); 623 CreateWithInvalidRenderFrameId();
618 Close(); 624 Close();
619 } 625 }
620 626
621 // TODO(hclam): Add tests for data conversation in low latency mode. 627 // TODO(hclam): Add tests for data conversation in low latency mode.
622 628
623 } // namespace content 629 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698