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

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

Issue 2784433002: Ensures that audio tasks cannot run after AudioManager is deleted. (Closed)
Patch Set: rebase Created 3 years, 7 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 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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/renderer_audio_output_stream_facto ry_context_impl.h" 5 #include "content/browser/renderer_host/media/renderer_audio_output_stream_facto ry_context_impl.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/memory/shared_memory.h" 10 #include "base/memory/shared_memory.h"
11 #include "base/memory/shared_memory_handle.h" 11 #include "base/memory/shared_memory_handle.h"
12 #include "base/message_loop/message_loop.h" 12 #include "base/message_loop/message_loop.h"
13 #include "base/run_loop.h" 13 #include "base/run_loop.h"
14 #include "base/sync_socket.h" 14 #include "base/sync_socket.h"
15 #include "cc/base/math_util.h" 15 #include "cc/base/math_util.h"
16 #include "content/browser/audio_manager_thread.h"
17 #include "content/browser/renderer_host/media/media_stream_manager.h" 16 #include "content/browser/renderer_host/media/media_stream_manager.h"
18 #include "content/common/media/renderer_audio_output_stream_factory.mojom.h" 17 #include "content/common/media/renderer_audio_output_stream_factory.mojom.h"
19 #include "content/public/browser/browser_thread.h" 18 #include "content/public/browser/browser_thread.h"
20 #include "content/public/test/mock_render_process_host.h" 19 #include "content/public/test/mock_render_process_host.h"
21 #include "content/public/test/test_browser_context.h" 20 #include "content/public/test/test_browser_context.h"
22 #include "content/public/test/test_browser_thread_bundle.h" 21 #include "content/public/test/test_browser_thread_bundle.h"
23 #include "media/audio/audio_manager_base.h" 22 #include "media/audio/audio_manager_base.h"
24 #include "media/audio/audio_output_controller.h" 23 #include "media/audio/audio_output_controller.h"
25 #include "media/audio/audio_system_impl.h" 24 #include "media/audio/audio_system_impl.h"
25 #include "media/audio/audio_thread_impl.h"
26 #include "media/audio/fake_audio_log_factory.h" 26 #include "media/audio/fake_audio_log_factory.h"
27 #include "media/audio/simple_sources.h" 27 #include "media/audio/simple_sources.h"
28 #include "media/base/audio_parameters.h" 28 #include "media/base/audio_parameters.h"
29 #include "media/base/media_switches.h" 29 #include "media/base/media_switches.h"
30 #include "mojo/public/cpp/bindings/binding.h" 30 #include "mojo/public/cpp/bindings/binding.h"
31 #include "mojo/public/cpp/system/platform_handle.h" 31 #include "mojo/public/cpp/system/platform_handle.h"
32 #include "testing/gmock/include/gmock/gmock.h" 32 #include "testing/gmock/include/gmock/gmock.h"
33 #include "testing/gtest/include/gtest/gtest.h" 33 #include "testing/gtest/include/gtest/gtest.h"
34 34
35 namespace content { 35 namespace content {
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 base::MessageLoop::current()); 97 base::MessageLoop::current());
98 base::RunLoop().RunUntilIdle(); 98 base::RunLoop().RunUntilIdle();
99 } 99 }
100 SyncWith(BrowserThread::GetTaskRunnerForThread(BrowserThread::IO)); 100 SyncWith(BrowserThread::GetTaskRunnerForThread(BrowserThread::IO));
101 SyncWith(media::AudioManager::Get()->GetWorkerTaskRunner()); 101 SyncWith(media::AudioManager::Get()->GetWorkerTaskRunner());
102 } 102 }
103 } 103 }
104 104
105 class MockAudioManager : public media::AudioManagerBase { 105 class MockAudioManager : public media::AudioManagerBase {
106 public: 106 public:
107 MockAudioManager( 107 MockAudioManager(std::unique_ptr<media::AudioThread> audio_thread,
108 scoped_refptr<base::SingleThreadTaskRunner> task_runner, 108 media::AudioLogFactory* audio_log_factory)
109 scoped_refptr<base::SingleThreadTaskRunner> worker_task_runner, 109 : media::AudioManagerBase(std::move(audio_thread), audio_log_factory) {
110 media::AudioLogFactory* audio_log_factory)
111 : media::AudioManagerBase(task_runner,
112 worker_task_runner,
113 audio_log_factory) {
114 ON_CALL(*this, HasAudioOutputDevices()).WillByDefault(Return(true)); 110 ON_CALL(*this, HasAudioOutputDevices()).WillByDefault(Return(true));
115 } 111 }
116 112
117 ~MockAudioManager() override { Shutdown(); } 113 ~MockAudioManager() override = default;
118 114
119 MOCK_METHOD2(MakeLinearOutputStream, 115 MOCK_METHOD2(MakeLinearOutputStream,
120 media::AudioOutputStream*(const media::AudioParameters& params, 116 media::AudioOutputStream*(const media::AudioParameters& params,
121 const LogCallback& log_callback)); 117 const LogCallback& log_callback));
122 MOCK_METHOD3(MakeLowLatencyOutputStream, 118 MOCK_METHOD3(MakeLowLatencyOutputStream,
123 media::AudioOutputStream*(const media::AudioParameters& params, 119 media::AudioOutputStream*(const media::AudioParameters& params,
124 const std::string& device_id, 120 const std::string& device_id,
125 const LogCallback& log_callback)); 121 const LogCallback& log_callback));
126 MOCK_METHOD3(MakeLinearInputStream, 122 MOCK_METHOD3(MakeLinearInputStream,
127 media::AudioInputStream*(const media::AudioParameters& params, 123 media::AudioInputStream*(const media::AudioParameters& params,
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 }; 292 };
297 293
298 } // namespace 294 } // namespace
299 295
300 // TODO(maxmorin): Add test for play, pause and set volume. 296 // TODO(maxmorin): Add test for play, pause and set volume.
301 class RendererAudioOutputStreamFactoryIntegrationTest : public Test { 297 class RendererAudioOutputStreamFactoryIntegrationTest : public Test {
302 public: 298 public:
303 RendererAudioOutputStreamFactoryIntegrationTest() 299 RendererAudioOutputStreamFactoryIntegrationTest()
304 : media_stream_manager_(), 300 : media_stream_manager_(),
305 thread_bundle_(TestBrowserThreadBundle::Options::REAL_IO_THREAD), 301 thread_bundle_(TestBrowserThreadBundle::Options::REAL_IO_THREAD),
306 audio_thread_(),
307 log_factory_(), 302 log_factory_(),
308 audio_manager_(new MockAudioManager(audio_thread_.task_runner(), 303 audio_manager_(
309 audio_thread_.worker_task_runner(), 304 new MockAudioManager(base::MakeUnique<media::AudioThreadImpl>(),
310 &log_factory_)), 305 &log_factory_)),
311 audio_system_(media::AudioSystemImpl::Create(audio_manager_.get())) { 306 audio_system_(media::AudioSystemImpl::Create(audio_manager_.get())) {
312 media_stream_manager_ = 307 media_stream_manager_ =
313 base::MakeUnique<MediaStreamManager>(audio_system_.get()); 308 base::MakeUnique<MediaStreamManager>(audio_system_.get());
314 } 309 }
310 ~RendererAudioOutputStreamFactoryIntegrationTest() override {
311 audio_manager_->Shutdown();
312 }
315 313
316 void CreateAndBindFactory(AudioOutputStreamFactoryRequest request) { 314 void CreateAndBindFactory(AudioOutputStreamFactoryRequest request) {
317 factory_context_.reset(new RendererAudioOutputStreamFactoryContextImpl( 315 factory_context_.reset(new RendererAudioOutputStreamFactoryContextImpl(
318 kRenderProcessId, audio_system_.get(), audio_manager_.get(), 316 kRenderProcessId, audio_system_.get(), audio_manager_.get(),
319 media_stream_manager_.get(), kSalt)); 317 media_stream_manager_.get(), kSalt));
320 factory_context_->CreateFactory(kRenderFrameId, std::move(request)); 318 factory_context_->CreateFactory(kRenderFrameId, std::move(request));
321 } 319 }
322 320
323 std::unique_ptr<MediaStreamManager> media_stream_manager_; 321 std::unique_ptr<MediaStreamManager> media_stream_manager_;
324 TestBrowserThreadBundle thread_bundle_; 322 TestBrowserThreadBundle thread_bundle_;
325 AudioManagerThread audio_thread_;
326 media::FakeAudioLogFactory log_factory_; 323 media::FakeAudioLogFactory log_factory_;
327 media::ScopedAudioManagerPtr audio_manager_; 324 std::unique_ptr<media::AudioManager> audio_manager_;
328 std::unique_ptr<media::AudioSystem> audio_system_; 325 std::unique_ptr<media::AudioSystem> audio_system_;
329 std::unique_ptr<RendererAudioOutputStreamFactoryContextImpl, 326 std::unique_ptr<RendererAudioOutputStreamFactoryContextImpl,
330 BrowserThread::DeleteOnIOThread> 327 BrowserThread::DeleteOnIOThread>
331 factory_context_; 328 factory_context_;
332 }; 329 };
333 330
334 TEST_F(RendererAudioOutputStreamFactoryIntegrationTest, StreamIntegrationTest) { 331 TEST_F(RendererAudioOutputStreamFactoryIntegrationTest, StreamIntegrationTest) {
335 // Sets up the factory on the IO thread and runs client code on the UI thread. 332 // Sets up the factory on the IO thread and runs client code on the UI thread.
336 // Send a sine wave from the client and makes sure it's received by the output 333 // Send a sine wave from the client and makes sure it's received by the output
337 // stream. 334 // stream.
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 base::Bind(&TestIPCClient::Start, base::Unretained(&client))); 372 base::Bind(&TestIPCClient::Start, base::Unretained(&client)));
376 SyncWithAllThreads(); 373 SyncWithAllThreads();
377 stream_ptr->Play(); 374 stream_ptr->Play();
378 SyncWithAllThreads(); 375 SyncWithAllThreads();
379 } // Joining client thread. 376 } // Joining client thread.
380 stream_ptr.reset(); 377 stream_ptr.reset();
381 SyncWithAllThreads(); 378 SyncWithAllThreads();
382 } 379 }
383 380
384 } // namespace content 381 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698