OLD | NEW |
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 "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/environment.h" | 8 #include "base/environment.h" |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 class AudioInputTest : public testing::Test { | 52 class AudioInputTest : public testing::Test { |
53 public: | 53 public: |
54 AudioInputTest() | 54 AudioInputTest() |
55 : message_loop_(base::MessageLoop::TYPE_UI), | 55 : message_loop_(base::MessageLoop::TYPE_UI), |
56 audio_manager_(AudioManager::CreateForTesting( | 56 audio_manager_(AudioManager::CreateForTesting( |
57 base::ThreadTaskRunnerHandle::Get())), | 57 base::ThreadTaskRunnerHandle::Get())), |
58 audio_input_stream_(NULL) { | 58 audio_input_stream_(NULL) { |
59 base::RunLoop().RunUntilIdle(); | 59 base::RunLoop().RunUntilIdle(); |
60 } | 60 } |
61 | 61 |
62 ~AudioInputTest() override {} | 62 ~AudioInputTest() override { audio_manager_->Shutdown(); } |
63 | 63 |
64 protected: | 64 protected: |
65 bool InputDevicesAvailable() { | 65 bool InputDevicesAvailable() { |
66 return audio_manager_->HasAudioInputDevices(); | 66 return audio_manager_->HasAudioInputDevices(); |
67 } | 67 } |
68 | 68 |
69 void MakeAudioInputStreamOnAudioThread() { | 69 void MakeAudioInputStreamOnAudioThread() { |
70 RunOnAudioThread( | 70 RunOnAudioThread( |
71 base::Bind(&AudioInputTest::MakeAudioInputStream, | 71 base::Bind(&AudioInputTest::MakeAudioInputStream, |
72 base::Unretained(this))); | 72 base::Unretained(this))); |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 | 145 |
146 // Synchronously runs the provided callback/closure on the audio thread. | 146 // Synchronously runs the provided callback/closure on the audio thread. |
147 void RunOnAudioThread(const base::Closure& closure) { | 147 void RunOnAudioThread(const base::Closure& closure) { |
148 DCHECK(audio_manager_->GetTaskRunner()->BelongsToCurrentThread()); | 148 DCHECK(audio_manager_->GetTaskRunner()->BelongsToCurrentThread()); |
149 closure.Run(); | 149 closure.Run(); |
150 } | 150 } |
151 | 151 |
152 void OnLogMessage(const std::string& message) {} | 152 void OnLogMessage(const std::string& message) {} |
153 | 153 |
154 base::TestMessageLoop message_loop_; | 154 base::TestMessageLoop message_loop_; |
155 ScopedAudioManagerPtr audio_manager_; | 155 std::unique_ptr<AudioManager> audio_manager_; |
156 AudioInputStream* audio_input_stream_; | 156 AudioInputStream* audio_input_stream_; |
157 | 157 |
158 private: | 158 private: |
159 DISALLOW_COPY_AND_ASSIGN(AudioInputTest); | 159 DISALLOW_COPY_AND_ASSIGN(AudioInputTest); |
160 }; | 160 }; |
161 | 161 |
162 // Test create and close of an AudioInputStream without recording audio. | 162 // Test create and close of an AudioInputStream without recording audio. |
163 TEST_F(AudioInputTest, CreateAndClose) { | 163 TEST_F(AudioInputTest, CreateAndClose) { |
164 ABORT_AUDIO_TEST_IF_NOT(InputDevicesAvailable()); | 164 ABORT_AUDIO_TEST_IF_NOT(InputDevicesAvailable()); |
165 MakeAudioInputStreamOnAudioThread(); | 165 MakeAudioInputStreamOnAudioThread(); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 FROM_HERE, run_loop.QuitClosure(), | 213 FROM_HERE, run_loop.QuitClosure(), |
214 base::TimeDelta::FromMilliseconds(500)); | 214 base::TimeDelta::FromMilliseconds(500)); |
215 run_loop.Run(); | 215 run_loop.Run(); |
216 EXPECT_GE(test_callback.callback_count(), 2); | 216 EXPECT_GE(test_callback.callback_count(), 2); |
217 EXPECT_FALSE(test_callback.had_error()); | 217 EXPECT_FALSE(test_callback.had_error()); |
218 | 218 |
219 StopAndCloseAudioInputStreamOnAudioThread(); | 219 StopAndCloseAudioInputStreamOnAudioThread(); |
220 } | 220 } |
221 | 221 |
222 } // namespace media | 222 } // namespace media |
OLD | NEW |