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

Side by Side Diff: media/audio/cras/cras_input_unittest.cc

Issue 1806313003: Pass task runners to AudioManager constructor. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 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 <stdint.h> 5 #include <stdint.h>
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/message_loop/message_loop.h"
10 #include "base/synchronization/waitable_event.h" 11 #include "base/synchronization/waitable_event.h"
11 #include "base/test/test_timeouts.h" 12 #include "base/test/test_timeouts.h"
13 #include "base/thread_task_runner_handle.h"
12 #include "base/time/time.h" 14 #include "base/time/time.h"
13 #include "media/audio/cras/audio_manager_cras.h" 15 #include "media/audio/cras/audio_manager_cras.h"
14 #include "media/audio/fake_audio_log_factory.h" 16 #include "media/audio/fake_audio_log_factory.h"
15 #include "testing/gmock/include/gmock/gmock.h" 17 #include "testing/gmock/include/gmock/gmock.h"
16 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
17 19
18 // cras_util.h defines custom min/max macros which break compilation, so ensure 20 // cras_util.h defines custom min/max macros which break compilation, so ensure
19 // it's not included until last. #if avoids presubmit errors. 21 // it's not included until last. #if avoids presubmit errors.
20 #if defined(USE_CRAS) 22 #if defined(USE_CRAS)
21 #include "media/audio/cras/cras_input.h" 23 #include "media/audio/cras/cras_input.h"
22 #endif 24 #endif
23 25
24 using testing::_; 26 using testing::_;
25 using testing::AtLeast; 27 using testing::AtLeast;
26 using testing::Ge; 28 using testing::Ge;
27 using testing::InvokeWithoutArgs; 29 using testing::InvokeWithoutArgs;
28 using testing::StrictMock; 30 using testing::StrictMock;
29 31
30 namespace media { 32 namespace media {
31 33
32 class MockAudioInputCallback : public AudioInputStream::AudioInputCallback { 34 class MockAudioInputCallback : public AudioInputStream::AudioInputCallback {
33 public: 35 public:
34 MOCK_METHOD4(OnData, 36 MOCK_METHOD4(OnData,
35 void(AudioInputStream*, const AudioBus*, uint32_t, double)); 37 void(AudioInputStream*, const AudioBus*, uint32_t, double));
36 MOCK_METHOD1(OnError, void(AudioInputStream*)); 38 MOCK_METHOD1(OnError, void(AudioInputStream*));
37 }; 39 };
38 40
39 class MockAudioManagerCrasInput : public AudioManagerCras { 41 class MockAudioManagerCrasInput : public AudioManagerCras {
40 public: 42 public:
41 MockAudioManagerCrasInput() : AudioManagerCras(&fake_audio_log_factory_) {} 43 MockAudioManagerCrasInput()
44 : AudioManagerCras(base::ThreadTaskRunnerHandle::Get(),
45 base::ThreadTaskRunnerHandle::Get(),
46 &fake_audio_log_factory_) {}
42 47
43 // We need to override this function in order to skip checking the number 48 // We need to override this function in order to skip checking the number
44 // of active output streams. It is because the number of active streams 49 // of active output streams. It is because the number of active streams
45 // is managed inside MakeAudioInputStream, and we don't use 50 // is managed inside MakeAudioInputStream, and we don't use
46 // MakeAudioInputStream to create the stream in the tests. 51 // MakeAudioInputStream to create the stream in the tests.
47 void ReleaseInputStream(AudioInputStream* stream) override { 52 void ReleaseInputStream(AudioInputStream* stream) override {
48 DCHECK(stream); 53 DCHECK(stream);
49 delete stream; 54 delete stream;
50 } 55 }
51 56
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 test_stream->Close(); 113 test_stream->Close();
109 } 114 }
110 115
111 static const unsigned int kTestBitsPerSample; 116 static const unsigned int kTestBitsPerSample;
112 static const unsigned int kTestCaptureDurationMs; 117 static const unsigned int kTestCaptureDurationMs;
113 static const ChannelLayout kTestChannelLayout; 118 static const ChannelLayout kTestChannelLayout;
114 static const AudioParameters::Format kTestFormat; 119 static const AudioParameters::Format kTestFormat;
115 static const uint32_t kTestFramesPerPacket; 120 static const uint32_t kTestFramesPerPacket;
116 static const int kTestSampleRate; 121 static const int kTestSampleRate;
117 122
123 base::MessageLoop message_loop_;
118 scoped_ptr<StrictMock<MockAudioManagerCrasInput> > mock_manager_; 124 scoped_ptr<StrictMock<MockAudioManagerCrasInput> > mock_manager_;
119 125
120 private: 126 private:
121 DISALLOW_COPY_AND_ASSIGN(CrasInputStreamTest); 127 DISALLOW_COPY_AND_ASSIGN(CrasInputStreamTest);
122 }; 128 };
123 129
124 const unsigned int CrasInputStreamTest::kTestBitsPerSample = 16; 130 const unsigned int CrasInputStreamTest::kTestBitsPerSample = 16;
125 const unsigned int CrasInputStreamTest::kTestCaptureDurationMs = 250; 131 const unsigned int CrasInputStreamTest::kTestCaptureDurationMs = 250;
126 const ChannelLayout CrasInputStreamTest::kTestChannelLayout = 132 const ChannelLayout CrasInputStreamTest::kTestChannelLayout =
127 CHANNEL_LAYOUT_STEREO; 133 CHANNEL_LAYOUT_STEREO;
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 TEST_F(CrasInputStreamTest, CaptureLoopback) { 217 TEST_F(CrasInputStreamTest, CaptureLoopback) {
212 CrasInputStream* test_stream = CreateStream( 218 CrasInputStream* test_stream = CreateStream(
213 CHANNEL_LAYOUT_STEREO, 219 CHANNEL_LAYOUT_STEREO,
214 kTestFramesPerPacket, 220 kTestFramesPerPacket,
215 AudioManagerBase::kLoopbackInputDeviceId); 221 AudioManagerBase::kLoopbackInputDeviceId);
216 EXPECT_TRUE(test_stream->Open()); 222 EXPECT_TRUE(test_stream->Open());
217 test_stream->Close(); 223 test_stream->Close();
218 } 224 }
219 225
220 } // namespace media 226 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698