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

Side by Side Diff: content/browser/renderer_host/media/audio_renderer_host_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 (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
(...skipping 11 matching lines...) Expand all
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/audio_system_impl.h"
30 #include "media/audio/fake_audio_log_factory.h" 30 #include "media/audio/fake_audio_log_factory.h"
31 #include "media/audio/fake_audio_manager.h" 31 #include "media/audio/fake_audio_manager.h"
32 #include "media/audio/test_audio_thread.h"
32 #include "media/base/bind_to_current_loop.h" 33 #include "media/base/bind_to_current_loop.h"
33 #include "media/base/media_switches.h" 34 #include "media/base/media_switches.h"
34 #include "testing/gmock/include/gmock/gmock.h" 35 #include "testing/gmock/include/gmock/gmock.h"
35 #include "testing/gtest/include/gtest/gtest.h" 36 #include "testing/gtest/include/gtest/gtest.h"
36 37
37 using ::testing::_; 38 using ::testing::_;
38 using ::testing::Assign; 39 using ::testing::Assign;
39 using ::testing::AtLeast; 40 using ::testing::AtLeast;
40 using ::testing::DoAll; 41 using ::testing::DoAll;
41 using ::testing::NotNull; 42 using ::testing::NotNull;
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 MockRenderProcessHost::ShutdownForBadMessage(crash_report_mode); 91 MockRenderProcessHost::ShutdownForBadMessage(crash_report_mode);
91 auth_run_loop_->Quit(); 92 auth_run_loop_->Quit();
92 } 93 }
93 94
94 private: 95 private:
95 base::RunLoop* auth_run_loop_; 96 base::RunLoop* auth_run_loop_;
96 }; 97 };
97 98
98 class FakeAudioManagerWithAssociations : public media::FakeAudioManager { 99 class FakeAudioManagerWithAssociations : public media::FakeAudioManager {
99 public: 100 public:
100 FakeAudioManagerWithAssociations( 101 FakeAudioManagerWithAssociations(media::AudioLogFactory* factory)
101 scoped_refptr<base::SingleThreadTaskRunner> task_runner, 102 : FakeAudioManager(base::MakeUnique<media::TestAudioThread>(), factory) {}
102 media::AudioLogFactory* factory)
103 : FakeAudioManager(task_runner, task_runner, factory) {}
104 103
105 void CreateDeviceAssociation(const std::string& input_device_id, 104 void CreateDeviceAssociation(const std::string& input_device_id,
106 const std::string& output_device_id) { 105 const std::string& output_device_id) {
107 // We shouldn't accidentally add hashed ids, since the audio manager 106 // We shouldn't accidentally add hashed ids, since the audio manager
108 // works with raw ids. 107 // works with raw ids.
109 EXPECT_FALSE(IsValidDeviceId(input_device_id)); 108 EXPECT_FALSE(IsValidDeviceId(input_device_id));
110 EXPECT_FALSE(IsValidDeviceId(output_device_id)); 109 EXPECT_FALSE(IsValidDeviceId(output_device_id));
111 110
112 associations_[input_device_id] = output_device_id; 111 associations_[input_device_id] = output_device_id;
113 } 112 }
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 base::RunLoop* auth_run_loop_; // Used to wait for authorization. 228 base::RunLoop* auth_run_loop_; // Used to wait for authorization.
230 229
231 DISALLOW_COPY_AND_ASSIGN(MockAudioRendererHost); 230 DISALLOW_COPY_AND_ASSIGN(MockAudioRendererHost);
232 }; 231 };
233 232
234 class AudioRendererHostTest : public testing::Test { 233 class AudioRendererHostTest : public testing::Test {
235 public: 234 public:
236 AudioRendererHostTest() 235 AudioRendererHostTest()
237 : log_factory(base::MakeUnique<media::FakeAudioLogFactory>()), 236 : log_factory(base::MakeUnique<media::FakeAudioLogFactory>()),
238 audio_manager_(base::MakeUnique<FakeAudioManagerWithAssociations>( 237 audio_manager_(base::MakeUnique<FakeAudioManagerWithAssociations>(
239 base::ThreadTaskRunnerHandle::Get(),
240 log_factory.get())), 238 log_factory.get())),
241 audio_system_(media::AudioSystemImpl::Create(audio_manager_.get())), 239 audio_system_(media::AudioSystemImpl::Create(audio_manager_.get())),
242 render_process_host_(&browser_context_, &auth_run_loop_) { 240 render_process_host_(&browser_context_, &auth_run_loop_) {
243 base::CommandLine::ForCurrentProcess()->AppendSwitch( 241 base::CommandLine::ForCurrentProcess()->AppendSwitch(
244 switches::kUseFakeDeviceForMediaStream); 242 switches::kUseFakeDeviceForMediaStream);
245 media_stream_manager_ = 243 media_stream_manager_ =
246 base::MakeUnique<MediaStreamManager>(audio_system_.get()); 244 base::MakeUnique<MediaStreamManager>(audio_system_.get());
247 host_ = new MockAudioRendererHost( 245 host_ = new MockAudioRendererHost(
248 &auth_run_loop_, render_process_host_.GetID(), audio_manager_.get(), 246 &auth_run_loop_, render_process_host_.GetID(), audio_manager_.get(),
249 audio_system_.get(), &mirroring_manager_, media_stream_manager_.get(), 247 audio_system_.get(), &mirroring_manager_, media_stream_manager_.get(),
250 kSalt); 248 kSalt);
251 249
252 // Simulate IPC channel connected. 250 // Simulate IPC channel connected.
253 host_->set_peer_process_for_testing(base::Process::Current()); 251 host_->set_peer_process_for_testing(base::Process::Current());
254 } 252 }
255 253
256 ~AudioRendererHostTest() override { 254 ~AudioRendererHostTest() override {
257 // Simulate closing the IPC channel and give the audio thread time to close 255 // Simulate closing the IPC channel and give the audio thread time to close
258 // the underlying streams. 256 // the underlying streams.
259 host_->OnChannelClosing(); 257 host_->OnChannelClosing();
260 SyncWithAudioThread(); 258 audio_manager_->Shutdown();
261 // To correctly clean up the audio manager, we first put it in a
262 // ScopedAudioManagerPtr. It will immediately destruct, cleaning up the
263 // audio manager correctly.
264 media::ScopedAudioManagerPtr(audio_manager_.release());
265 259
266 // Release the reference to the mock object. The object will be destructed 260 // Release the reference to the mock object. The object will be destructed
267 // on message_loop_. 261 // on message_loop_.
268 host_ = nullptr; 262 host_ = nullptr;
269 } 263 }
270 264
271 protected: 265 protected:
272 void OverrideDevicePermissions(bool has_permissions) { 266 void OverrideDevicePermissions(bool has_permissions) {
273 host_->OverrideDevicePermissionsForTesting(has_permissions); 267 host_->OverrideDevicePermissionsForTesting(has_permissions);
274 } 268 }
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after
623 } 617 }
624 618
625 TEST_F(AudioRendererHostTest, CreateFailsForInvalidRenderFrame) { 619 TEST_F(AudioRendererHostTest, CreateFailsForInvalidRenderFrame) {
626 CreateWithInvalidRenderFrameId(); 620 CreateWithInvalidRenderFrameId();
627 Close(); 621 Close();
628 } 622 }
629 623
630 // TODO(hclam): Add tests for data conversation in low latency mode. 624 // TODO(hclam): Add tests for data conversation in low latency mode.
631 625
632 } // namespace content 626 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698