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

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

Issue 2784433002: Ensures that audio tasks cannot run after AudioManager is deleted. (Closed)
Patch Set: fixes content_browsertests and content_unittests Created 3 years, 8 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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_output_delegate_impl.h" 5 #include "content/browser/renderer_host/media/audio_output_delegate_impl.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <memory> 9 #include <memory>
10 #include <utility> 10 #include <utility>
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 TestBrowserThreadBundle::Options::REAL_IO_THREAD); 113 TestBrowserThreadBundle::Options::REAL_IO_THREAD);
114 audio_thread_ = base::MakeUnique<AudioManagerThread>(); 114 audio_thread_ = base::MakeUnique<AudioManagerThread>();
115 115
116 audio_manager_.reset(new media::FakeAudioManager( 116 audio_manager_.reset(new media::FakeAudioManager(
117 audio_thread_->task_runner(), audio_thread_->worker_task_runner(), 117 audio_thread_->task_runner(), audio_thread_->worker_task_runner(),
118 &log_factory_)); 118 &log_factory_));
119 audio_system_ = media::AudioSystemImpl::Create(audio_manager_.get()); 119 audio_system_ = media::AudioSystemImpl::Create(audio_manager_.get());
120 media_stream_manager_ = 120 media_stream_manager_ =
121 base::MakeUnique<MediaStreamManager>(audio_system_.get()); 121 base::MakeUnique<MediaStreamManager>(audio_system_.get());
122 } 122 }
123 ~AudioOutputDelegateTest() {
124 audio_manager_->GetTaskRunner()->PostTask(
125 FROM_HERE, base::Bind(&media::AudioManager::Shutdown,
126 base::Unretained(audio_manager_.get())));
127 }
123 128
124 // Test bodies are here, so that we can run them on the IO thread. 129 // Test bodies are here, so that we can run them on the IO thread.
125 void CreateTest(base::Closure done) { 130 void CreateTest(base::Closure done) {
126 EXPECT_CALL(media_observer_, 131 EXPECT_CALL(media_observer_,
127 OnCreatingAudioStream(kRenderProcessId, kRenderFrameId)); 132 OnCreatingAudioStream(kRenderProcessId, kRenderFrameId));
128 EXPECT_CALL(event_handler_, 133 EXPECT_CALL(event_handler_,
129 OnStreamCreated(kStreamId, NotNull(), NotNull())); 134 OnStreamCreated(kStreamId, NotNull(), NotNull()));
130 EXPECT_CALL(mirroring_manager_, 135 EXPECT_CALL(mirroring_manager_,
131 AddDiverter(kRenderProcessId, kRenderFrameId, NotNull())); 136 AddDiverter(kRenderProcessId, kRenderFrameId, NotNull()));
132 137
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after
443 } 448 }
444 SyncWithAllThreads(); 449 SyncWithAllThreads();
445 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, done); 450 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, done);
446 } 451 }
447 452
448 protected: 453 protected:
449 // MediaStreamManager uses a DestructionObserver, so it must outlive the 454 // MediaStreamManager uses a DestructionObserver, so it must outlive the
450 // TestBrowserThreadBundle. 455 // TestBrowserThreadBundle.
451 std::unique_ptr<MediaStreamManager> media_stream_manager_; 456 std::unique_ptr<MediaStreamManager> media_stream_manager_;
452 std::unique_ptr<TestBrowserThreadBundle> thread_bundle_; 457 std::unique_ptr<TestBrowserThreadBundle> thread_bundle_;
458 std::unique_ptr<media::AudioManager> audio_manager_;
453 std::unique_ptr<AudioManagerThread> audio_thread_; 459 std::unique_ptr<AudioManagerThread> audio_thread_;
454 media::ScopedAudioManagerPtr audio_manager_;
455 std::unique_ptr<media::AudioSystem> audio_system_; 460 std::unique_ptr<media::AudioSystem> audio_system_;
456 StrictMock<MockAudioMirroringManager> mirroring_manager_; 461 StrictMock<MockAudioMirroringManager> mirroring_manager_;
457 StrictMock<MockEventHandler> event_handler_; 462 StrictMock<MockEventHandler> event_handler_;
458 StrictMock<MockObserver> media_observer_; 463 StrictMock<MockObserver> media_observer_;
459 media::FakeAudioLogFactory log_factory_; 464 media::FakeAudioLogFactory log_factory_;
460 465
461 private: 466 private:
462 void SyncWithAllThreads() { 467 void SyncWithAllThreads() {
463 DCHECK_CURRENTLY_ON(BrowserThread::IO); 468 DCHECK_CURRENTLY_ON(BrowserThread::IO);
464 // New tasks might be posted while we are syncing, but in every iteration at 469 // New tasks might be posted while we are syncing, but in every iteration at
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
573 TEST_F(AudioOutputDelegateTest, ErrorAndDestroy) { 578 TEST_F(AudioOutputDelegateTest, ErrorAndDestroy) {
574 base::RunLoop l; 579 base::RunLoop l;
575 BrowserThread::PostTask( 580 BrowserThread::PostTask(
576 BrowserThread::IO, FROM_HERE, 581 BrowserThread::IO, FROM_HERE,
577 base::Bind(&AudioOutputDelegateTest::PlayAndDestroyTest, 582 base::Bind(&AudioOutputDelegateTest::PlayAndDestroyTest,
578 base::Unretained(this), l.QuitClosure())); 583 base::Unretained(this), l.QuitClosure()));
579 l.Run(); 584 l.Run();
580 } 585 }
581 586
582 } // namespace content 587 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698