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

Side by Side Diff: media/audio/audio_output_controller_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 (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 "media/audio/audio_output_controller.h" 5 #include "media/audio/audio_output_controller.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <memory> 9 #include <memory>
10 #include <vector> 10 #include <vector>
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 } 109 }
110 110
111 class AudioOutputControllerTest : public testing::Test { 111 class AudioOutputControllerTest : public testing::Test {
112 public: 112 public:
113 AudioOutputControllerTest() 113 AudioOutputControllerTest()
114 : audio_manager_(AudioManager::CreateForTesting( 114 : audio_manager_(AudioManager::CreateForTesting(
115 base::ThreadTaskRunnerHandle::Get())) { 115 base::ThreadTaskRunnerHandle::Get())) {
116 base::RunLoop().RunUntilIdle(); 116 base::RunLoop().RunUntilIdle();
117 } 117 }
118 118
119 ~AudioOutputControllerTest() override {} 119 ~AudioOutputControllerTest() override { audio_manager_->Shutdown(); }
120 120
121 protected: 121 protected:
122 void Create(int samples_per_packet) { 122 void Create(int samples_per_packet) {
123 params_ = AudioParameters( 123 params_ = AudioParameters(
124 AudioParameters::AUDIO_FAKE, kChannelLayout, 124 AudioParameters::AUDIO_FAKE, kChannelLayout,
125 kSampleRate, kBitsPerSample, samples_per_packet); 125 kSampleRate, kBitsPerSample, samples_per_packet);
126 126
127 if (params_.IsValid()) { 127 if (params_.IsValid()) {
128 EXPECT_CALL(mock_event_handler_, OnControllerCreated()); 128 EXPECT_CALL(mock_event_handler_, OnControllerCreated());
129 } 129 }
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 270
271 // These help make test sequences more readable. 271 // These help make test sequences more readable.
272 void DivertNeverPlaying() { Divert(false, 0); } 272 void DivertNeverPlaying() { Divert(false, 0); }
273 void DivertWillEventuallyBeTwicePlayed() { Divert(false, 2); } 273 void DivertWillEventuallyBeTwicePlayed() { Divert(false, 2); }
274 void DivertWhilePlaying() { Divert(true, 1); } 274 void DivertWhilePlaying() { Divert(true, 1); }
275 void RevertWasNotPlaying() { Revert(false); } 275 void RevertWasNotPlaying() { Revert(false); }
276 void RevertWhilePlaying() { Revert(true); } 276 void RevertWhilePlaying() { Revert(true); }
277 277
278 private: 278 private:
279 base::TestMessageLoop message_loop_; 279 base::TestMessageLoop message_loop_;
280 ScopedAudioManagerPtr audio_manager_; 280 std::unique_ptr<AudioManager> audio_manager_;
281 MockAudioOutputControllerEventHandler mock_event_handler_; 281 MockAudioOutputControllerEventHandler mock_event_handler_;
282 MockAudioOutputControllerSyncReader mock_sync_reader_; 282 MockAudioOutputControllerSyncReader mock_sync_reader_;
283 MockAudioOutputStream mock_stream_; 283 MockAudioOutputStream mock_stream_;
284 AudioParameters params_; 284 AudioParameters params_;
285 scoped_refptr<AudioOutputController> controller_; 285 scoped_refptr<AudioOutputController> controller_;
286 286
287 DISALLOW_COPY_AND_ASSIGN(AudioOutputControllerTest); 287 DISALLOW_COPY_AND_ASSIGN(AudioOutputControllerTest);
288 }; 288 };
289 289
290 TEST_F(AudioOutputControllerTest, CreateAndClose) { 290 TEST_F(AudioOutputControllerTest, CreateAndClose) {
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
430 // Switching device would trigger a read, and in turn it would trigger a push 430 // Switching device would trigger a read, and in turn it would trigger a push
431 // to sink. 431 // to sink.
432 EXPECT_CALL(mock_sink, OnDataCheck(kBufferNonZeroData)); 432 EXPECT_CALL(mock_sink, OnDataCheck(kBufferNonZeroData));
433 SwitchDevice(false); 433 SwitchDevice(false);
434 434
435 StopDuplicating(&mock_sink); 435 StopDuplicating(&mock_sink);
436 Close(); 436 Close();
437 } 437 }
438 438
439 } // namespace media 439 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698