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

Side by Side Diff: media/audio/cras/cras_unified_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/cras/cras_input_unittest.cc ('k') | media/audio/fake_audio_manager.h » ('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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 <stdint.h> 5 #include <stdint.h>
6 6
7 #include <memory> 7 #include <memory>
8 #include <string> 8 #include <string>
9 9
10 #include "base/macros.h" 10 #include "base/macros.h"
11 #include "base/run_loop.h" 11 #include "base/run_loop.h"
12 #include "base/synchronization/waitable_event.h" 12 #include "base/synchronization/waitable_event.h"
13 #include "base/test/test_message_loop.h" 13 #include "base/test/test_message_loop.h"
14 #include "base/test/test_timeouts.h" 14 #include "base/test/test_timeouts.h"
15 #include "base/threading/thread_task_runner_handle.h" 15 #include "base/threading/thread_task_runner_handle.h"
16 #include "base/time/time.h" 16 #include "base/time/time.h"
17 #include "media/audio/audio_device_description.h" 17 #include "media/audio/audio_device_description.h"
18 #include "media/audio/cras/audio_manager_cras.h" 18 #include "media/audio/cras/audio_manager_cras.h"
19 #include "media/audio/fake_audio_log_factory.h" 19 #include "media/audio/fake_audio_log_factory.h"
20 #include "media/audio/mock_audio_source_callback.h" 20 #include "media/audio/mock_audio_source_callback.h"
21 #include "media/audio/test_audio_thread.h"
21 #include "testing/gmock/include/gmock/gmock.h" 22 #include "testing/gmock/include/gmock/gmock.h"
22 #include "testing/gtest/include/gtest/gtest.h" 23 #include "testing/gtest/include/gtest/gtest.h"
23 24
24 // cras_util.h defines custom min/max macros which break compilation, so ensure 25 // cras_util.h defines custom min/max macros which break compilation, so ensure
25 // it's not included until last. #if avoids presubmit errors. 26 // it's not included until last. #if avoids presubmit errors.
26 #if defined(USE_CRAS) 27 #if defined(USE_CRAS)
27 #include "media/audio/cras/cras_unified.h" 28 #include "media/audio/cras/cras_unified.h"
28 #endif 29 #endif
29 30
30 using testing::_; 31 using testing::_;
31 using testing::DoAll; 32 using testing::DoAll;
32 using testing::InvokeWithoutArgs; 33 using testing::InvokeWithoutArgs;
33 using testing::Return; 34 using testing::Return;
34 using testing::SetArgPointee; 35 using testing::SetArgPointee;
35 using testing::StrictMock; 36 using testing::StrictMock;
36 37
37 namespace media { 38 namespace media {
38 39
39 class MockAudioManagerCras : public AudioManagerCras { 40 class MockAudioManagerCras : public AudioManagerCras {
40 public: 41 public:
41 MockAudioManagerCras() 42 MockAudioManagerCras()
42 : AudioManagerCras(base::ThreadTaskRunnerHandle::Get(), 43 : AudioManagerCras(base::MakeUnique<TestAudioThread>(),
43 base::ThreadTaskRunnerHandle::Get(),
44 &fake_audio_log_factory_) {} 44 &fake_audio_log_factory_) {}
45 45
46 // We need to override this function in order to skip the checking the number 46 // We need to override this function in order to skip the checking the number
47 // of active output streams. It is because the number of active streams 47 // of active output streams. It is because the number of active streams
48 // is managed inside MakeAudioOutputStream, and we don't use 48 // is managed inside MakeAudioOutputStream, and we don't use
49 // MakeAudioOutputStream to create the stream in the tests. 49 // MakeAudioOutputStream to create the stream in the tests.
50 void ReleaseOutputStream(AudioOutputStream* stream) override { 50 void ReleaseOutputStream(AudioOutputStream* stream) override {
51 DCHECK(stream); 51 DCHECK(stream);
52 delete stream; 52 delete stream;
53 } 53 }
54 54
55 private: 55 private:
56 FakeAudioLogFactory fake_audio_log_factory_; 56 FakeAudioLogFactory fake_audio_log_factory_;
57 }; 57 };
58 58
59 class CrasUnifiedStreamTest : public testing::Test { 59 class CrasUnifiedStreamTest : public testing::Test {
60 protected: 60 protected:
61 CrasUnifiedStreamTest() { 61 CrasUnifiedStreamTest() {
62 mock_manager_.reset(new StrictMock<MockAudioManagerCras>()); 62 mock_manager_.reset(new StrictMock<MockAudioManagerCras>());
63 base::RunLoop().RunUntilIdle(); 63 base::RunLoop().RunUntilIdle();
64 } 64 }
65 65
66 ~CrasUnifiedStreamTest() override {} 66 ~CrasUnifiedStreamTest() override { mock_manager_->Shutdown(); }
67 67
68 CrasUnifiedStream* CreateStream(ChannelLayout layout) { 68 CrasUnifiedStream* CreateStream(ChannelLayout layout) {
69 return CreateStream(layout, kTestFramesPerPacket); 69 return CreateStream(layout, kTestFramesPerPacket);
70 } 70 }
71 71
72 CrasUnifiedStream* CreateStream(ChannelLayout layout, 72 CrasUnifiedStream* CreateStream(ChannelLayout layout,
73 int32_t samples_per_packet) { 73 int32_t samples_per_packet) {
74 AudioParameters params(kTestFormat, layout, kTestSampleRate, 74 AudioParameters params(kTestFormat, layout, kTestSampleRate,
75 kTestBitsPerSample, samples_per_packet); 75 kTestBitsPerSample, samples_per_packet);
76 return new CrasUnifiedStream(params, mock_manager_.get(), 76 return new CrasUnifiedStream(params, mock_manager_.get(),
77 AudioDeviceDescription::kDefaultDeviceId); 77 AudioDeviceDescription::kDefaultDeviceId);
78 } 78 }
79 79
80 MockAudioManagerCras& mock_manager() { 80 MockAudioManagerCras& mock_manager() {
81 return *(mock_manager_.get()); 81 return *(mock_manager_.get());
82 } 82 }
83 83
84 static const ChannelLayout kTestChannelLayout; 84 static const ChannelLayout kTestChannelLayout;
85 static const int kTestSampleRate; 85 static const int kTestSampleRate;
86 static const int kTestBitsPerSample; 86 static const int kTestBitsPerSample;
87 static const AudioParameters::Format kTestFormat; 87 static const AudioParameters::Format kTestFormat;
88 static const uint32_t kTestFramesPerPacket; 88 static const uint32_t kTestFramesPerPacket;
89 89
90 base::TestMessageLoop message_loop_; 90 base::TestMessageLoop message_loop_;
91 std::unique_ptr<StrictMock<MockAudioManagerCras>, AudioManagerDeleter> 91 std::unique_ptr<StrictMock<MockAudioManagerCras>> mock_manager_;
92 mock_manager_;
93 92
94 private: 93 private:
95 DISALLOW_COPY_AND_ASSIGN(CrasUnifiedStreamTest); 94 DISALLOW_COPY_AND_ASSIGN(CrasUnifiedStreamTest);
96 }; 95 };
97 96
98 const ChannelLayout CrasUnifiedStreamTest::kTestChannelLayout = 97 const ChannelLayout CrasUnifiedStreamTest::kTestChannelLayout =
99 CHANNEL_LAYOUT_STEREO; 98 CHANNEL_LAYOUT_STEREO;
100 const int CrasUnifiedStreamTest::kTestSampleRate = 99 const int CrasUnifiedStreamTest::kTestSampleRate =
101 AudioParameters::kAudioCDSampleRate; 100 AudioParameters::kAudioCDSampleRate;
102 const int CrasUnifiedStreamTest::kTestBitsPerSample = 16; 101 const int CrasUnifiedStreamTest::kTestBitsPerSample = 16;
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 154
156 // Wait for samples to be captured. 155 // Wait for samples to be captured.
157 EXPECT_TRUE(event.TimedWait(TestTimeouts::action_timeout())); 156 EXPECT_TRUE(event.TimedWait(TestTimeouts::action_timeout()));
158 157
159 test_stream->Stop(); 158 test_stream->Stop();
160 159
161 test_stream->Close(); 160 test_stream->Close();
162 } 161 }
163 162
164 } // namespace media 163 } // namespace media
OLDNEW
« no previous file with comments | « media/audio/cras/cras_input_unittest.cc ('k') | media/audio/fake_audio_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698