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

Side by Side Diff: chromecast/media/audio/cast_audio_mixer_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 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 "chromecast/media/audio/cast_audio_mixer.h" 5 #include "chromecast/media/audio/cast_audio_mixer.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <memory> 10 #include <memory>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/bind.h" 13 #include "base/bind.h"
14 #include "base/memory/ptr_util.h"
14 #include "base/message_loop/message_loop.h" 15 #include "base/message_loop/message_loop.h"
15 #include "base/run_loop.h" 16 #include "base/run_loop.h"
16 #include "base/time/time.h" 17 #include "base/time/time.h"
17 #include "chromecast/media/audio/cast_audio_manager.h" 18 #include "chromecast/media/audio/cast_audio_manager.h"
18 #include "chromecast/media/audio/cast_audio_output_stream.h" 19 #include "chromecast/media/audio/cast_audio_output_stream.h"
20 #include "media/audio/test_audio_thread.h"
19 #include "testing/gmock/include/gmock/gmock.h" 21 #include "testing/gmock/include/gmock/gmock.h"
20 #include "testing/gtest/include/gtest/gtest.h" 22 #include "testing/gtest/include/gtest/gtest.h"
21 23
22 namespace chromecast { 24 namespace chromecast {
23 namespace media { 25 namespace media {
24 namespace { 26 namespace {
25 27
26 using ::testing::_; 28 using ::testing::_;
27 using ::testing::Invoke; 29 using ::testing::Invoke;
28 using ::testing::Return; 30 using ::testing::Return;
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 audio_bus.get()); 80 audio_bus.get());
79 } 81 }
80 82
81 void SignalError(AudioSourceCallback* source_callback) { 83 void SignalError(AudioSourceCallback* source_callback) {
82 source_callback->OnError(this); 84 source_callback->OnError(this);
83 } 85 }
84 }; 86 };
85 87
86 class MockCastAudioManager : public CastAudioManager { 88 class MockCastAudioManager : public CastAudioManager {
87 public: 89 public:
88 MockCastAudioManager(scoped_refptr<base::SingleThreadTaskRunner> task_runner, 90 MockCastAudioManager(CastAudioMixer* audio_mixer)
89 CastAudioMixer* audio_mixer) 91 : CastAudioManager(base::MakeUnique<::media::TestAudioThread>(),
90 : CastAudioManager(task_runner,
91 task_runner,
92 nullptr, 92 nullptr,
93 nullptr, 93 nullptr,
94 audio_mixer) { 94 audio_mixer) {
95 ON_CALL(*this, ReleaseOutputStream(_)) 95 ON_CALL(*this, ReleaseOutputStream(_))
96 .WillByDefault( 96 .WillByDefault(
97 Invoke(this, &MockCastAudioManager::ReleaseOutputStreamConcrete)); 97 Invoke(this, &MockCastAudioManager::ReleaseOutputStreamConcrete));
98 } 98 }
99 99
100 MOCK_METHOD1( 100 MOCK_METHOD1(
101 MakeMixerOutputStream, 101 MakeMixerOutputStream,
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 public: 134 public:
135 CastAudioMixerTest() {} 135 CastAudioMixerTest() {}
136 ~CastAudioMixerTest() override {} 136 ~CastAudioMixerTest() override {}
137 137
138 protected: 138 protected:
139 void SetUp() override { 139 void SetUp() override {
140 // |this| will outlive |mock_mixer_| 140 // |this| will outlive |mock_mixer_|
141 mock_mixer_ = new StrictMock<MockCastAudioMixer>( 141 mock_mixer_ = new StrictMock<MockCastAudioMixer>(
142 base::Bind(&CastAudioMixerTest::MakeMixerOutputStreamProxy, 142 base::Bind(&CastAudioMixerTest::MakeMixerOutputStreamProxy,
143 base::Unretained(this))); 143 base::Unretained(this)));
144 mock_manager_.reset(new StrictMock<MockCastAudioManager>( 144 mock_manager_.reset(new StrictMock<MockCastAudioManager>(mock_mixer_));
145 message_loop_.task_runner(), mock_mixer_));
146 mock_mixer_stream_.reset(new StrictMock<MockCastAudioOutputStream>( 145 mock_mixer_stream_.reset(new StrictMock<MockCastAudioOutputStream>(
147 GetAudioParams(), mock_manager_.get())); 146 GetAudioParams(), mock_manager_.get()));
148 } 147 }
149 148
150 void TearDown() override { mock_manager_.reset(); } 149 void TearDown() override { mock_manager_->Shutdown(); }
151 150
152 MockCastAudioManager& mock_manager() { return *mock_manager_; } 151 MockCastAudioManager& mock_manager() { return *mock_manager_; }
153 152
154 MockCastAudioMixer& mock_mixer() { return *mock_mixer_; } 153 MockCastAudioMixer& mock_mixer() { return *mock_mixer_; }
155 154
156 MockCastAudioOutputStream& mock_mixer_stream() { return *mock_mixer_stream_; } 155 MockCastAudioOutputStream& mock_mixer_stream() { return *mock_mixer_stream_; }
157 156
158 ::media::AudioOutputStream* CreateMixerStream() { 157 ::media::AudioOutputStream* CreateMixerStream() {
159 EXPECT_CALL(*mock_mixer_, MakeStream(_, &mock_manager())); 158 EXPECT_CALL(*mock_mixer_, MakeStream(_, &mock_manager()));
160 return mock_manager_->MakeAudioOutputStream( 159 return mock_manager_->MakeAudioOutputStream(
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
455 454
456 EXPECT_CALL(mock_mixer_stream(), Stop()); 455 EXPECT_CALL(mock_mixer_stream(), Stop());
457 EXPECT_CALL(mock_mixer_stream(), Close()); 456 EXPECT_CALL(mock_mixer_stream(), Close());
458 EXPECT_CALL(mock_manager(), ReleaseOutputStream(stream)); 457 EXPECT_CALL(mock_manager(), ReleaseOutputStream(stream));
459 stream->Close(); 458 stream->Close();
460 } 459 }
461 460
462 } // namespace 461 } // namespace
463 } // namespace media 462 } // namespace media
464 } // namespace chromecast 463 } // namespace chromecast
OLDNEW
« no previous file with comments | « chromecast/media/audio/cast_audio_manager.cc ('k') | chromecast/media/audio/cast_audio_output_stream_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698