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

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: 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
« no previous file with comments | « media/audio/audio_manager_unittest.cc ('k') | media/audio/audio_output_proxy_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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>
11 11
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/environment.h" 13 #include "base/environment.h"
14 #include "base/location.h" 14 #include "base/location.h"
15 #include "base/logging.h" 15 #include "base/logging.h"
16 #include "base/macros.h" 16 #include "base/macros.h"
17 #include "base/memory/ref_counted.h" 17 #include "base/memory/ref_counted.h"
18 #include "base/run_loop.h" 18 #include "base/run_loop.h"
19 #include "base/single_thread_task_runner.h" 19 #include "base/single_thread_task_runner.h"
20 #include "base/test/test_message_loop.h" 20 #include "base/test/test_message_loop.h"
21 #include "base/threading/thread_task_runner_handle.h" 21 #include "base/threading/thread_task_runner_handle.h"
22 #include "base/time/time.h" 22 #include "base/time/time.h"
23 #include "media/audio/audio_device_description.h" 23 #include "media/audio/audio_device_description.h"
24 #include "media/audio/audio_source_diverter.h" 24 #include "media/audio/audio_source_diverter.h"
25 #include "media/audio/test_audio_thread.h"
25 #include "media/base/audio_bus.h" 26 #include "media/base/audio_bus.h"
26 #include "media/base/audio_parameters.h" 27 #include "media/base/audio_parameters.h"
27 #include "testing/gmock/include/gmock/gmock.h" 28 #include "testing/gmock/include/gmock/gmock.h"
28 #include "testing/gtest/include/gtest/gtest.h" 29 #include "testing/gtest/include/gtest/gtest.h"
29 30
30 using ::testing::_; 31 using ::testing::_;
31 using ::testing::AtLeast; 32 using ::testing::AtLeast;
32 using ::testing::DoAll; 33 using ::testing::DoAll;
33 using ::testing::Invoke; 34 using ::testing::Invoke;
34 using ::testing::NotNull; 35 using ::testing::NotNull;
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 arg0->Zero(); 106 arg0->Zero();
106 // Note: To confirm the buffer will be populated in these tests, it's 107 // Note: To confirm the buffer will be populated in these tests, it's
107 // sufficient that only the first float in channel 0 is set to the value. 108 // sufficient that only the first float in channel 0 is set to the value.
108 arg0->channel(0)[0] = kBufferNonZeroData; 109 arg0->channel(0)[0] = kBufferNonZeroData;
109 } 110 }
110 111
111 class AudioOutputControllerTest : public testing::Test { 112 class AudioOutputControllerTest : public testing::Test {
112 public: 113 public:
113 AudioOutputControllerTest() 114 AudioOutputControllerTest()
114 : audio_manager_(AudioManager::CreateForTesting( 115 : audio_manager_(AudioManager::CreateForTesting(
115 base::ThreadTaskRunnerHandle::Get())) { 116 base::MakeUnique<TestAudioThread>())) {
116 base::RunLoop().RunUntilIdle(); 117 base::RunLoop().RunUntilIdle();
117 } 118 }
118 119
119 ~AudioOutputControllerTest() override {} 120 ~AudioOutputControllerTest() override { audio_manager_->Shutdown(); }
120 121
121 protected: 122 protected:
122 void Create(int samples_per_packet) { 123 void Create(int samples_per_packet) {
123 params_ = AudioParameters( 124 params_ = AudioParameters(
124 AudioParameters::AUDIO_FAKE, kChannelLayout, 125 AudioParameters::AUDIO_FAKE, kChannelLayout,
125 kSampleRate, kBitsPerSample, samples_per_packet); 126 kSampleRate, kBitsPerSample, samples_per_packet);
126 127
127 if (params_.IsValid()) { 128 if (params_.IsValid()) {
128 EXPECT_CALL(mock_event_handler_, OnControllerCreated()); 129 EXPECT_CALL(mock_event_handler_, OnControllerCreated());
129 } 130 }
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 257
257 // These help make test sequences more readable. 258 // These help make test sequences more readable.
258 void DivertNeverPlaying() { Divert(false, 0); } 259 void DivertNeverPlaying() { Divert(false, 0); }
259 void DivertWillEventuallyBeTwicePlayed() { Divert(false, 2); } 260 void DivertWillEventuallyBeTwicePlayed() { Divert(false, 2); }
260 void DivertWhilePlaying() { Divert(true, 1); } 261 void DivertWhilePlaying() { Divert(true, 1); }
261 void RevertWasNotPlaying() { Revert(false); } 262 void RevertWasNotPlaying() { Revert(false); }
262 void RevertWhilePlaying() { Revert(true); } 263 void RevertWhilePlaying() { Revert(true); }
263 264
264 private: 265 private:
265 base::TestMessageLoop message_loop_; 266 base::TestMessageLoop message_loop_;
266 ScopedAudioManagerPtr audio_manager_; 267 std::unique_ptr<AudioManager> audio_manager_;
267 MockAudioOutputControllerEventHandler mock_event_handler_; 268 MockAudioOutputControllerEventHandler mock_event_handler_;
268 MockAudioOutputControllerSyncReader mock_sync_reader_; 269 MockAudioOutputControllerSyncReader mock_sync_reader_;
269 MockAudioOutputStream mock_stream_; 270 MockAudioOutputStream mock_stream_;
270 AudioParameters params_; 271 AudioParameters params_;
271 scoped_refptr<AudioOutputController> controller_; 272 scoped_refptr<AudioOutputController> controller_;
272 273
273 DISALLOW_COPY_AND_ASSIGN(AudioOutputControllerTest); 274 DISALLOW_COPY_AND_ASSIGN(AudioOutputControllerTest);
274 }; 275 };
275 276
276 TEST_F(AudioOutputControllerTest, CreateAndClose) { 277 TEST_F(AudioOutputControllerTest, CreateAndClose) {
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 // When diverted stream pulls data, it would trigger a push to sink. 384 // When diverted stream pulls data, it would trigger a push to sink.
384 EXPECT_CALL(mock_sink, OnDataCheck(kBufferNonZeroData)); 385 EXPECT_CALL(mock_sink, OnDataCheck(kBufferNonZeroData));
385 ReadDivertedAudioData(); 386 ReadDivertedAudioData();
386 387
387 StopDuplicating(&mock_sink); 388 StopDuplicating(&mock_sink);
388 RevertWhilePlaying(); 389 RevertWhilePlaying();
389 Close(); 390 Close();
390 } 391 }
391 392
392 } // namespace media 393 } // namespace media
OLDNEW
« no previous file with comments | « media/audio/audio_manager_unittest.cc ('k') | media/audio/audio_output_proxy_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698