Chromium Code Reviews| 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/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
| 12 #include "base/run_loop.h" | 12 #include "base/run_loop.h" |
| 13 #include "base/synchronization/waitable_event.h" | 13 #include "base/synchronization/waitable_event.h" |
| 14 #include "base/threading/platform_thread.h" | 14 #include "base/threading/platform_thread.h" |
| 15 #include "build/build_config.h" | 15 #include "build/build_config.h" |
| 16 #include "media/audio/audio_io.h" | 16 #include "media/audio/audio_io.h" |
| 17 #include "media/audio/audio_manager_base.h" | 17 #include "media/audio/audio_manager_base.h" |
| 18 #include "media/audio/audio_unittest_util.h" | 18 #include "media/audio/audio_unittest_util.h" |
| 19 #include "media/audio/fake_audio_log_factory.h" | |
| 19 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
| 20 | 21 |
| 21 namespace media { | 22 namespace media { |
| 22 | 23 |
| 23 // This class allows to find out if the callbacks are occurring as | 24 // This class allows to find out if the callbacks are occurring as |
| 24 // expected and if any error has been reported. | 25 // expected and if any error has been reported. |
| 25 class TestInputCallback : public AudioInputStream::AudioInputCallback { | 26 class TestInputCallback : public AudioInputStream::AudioInputCallback { |
| 26 public: | 27 public: |
| 27 explicit TestInputCallback() | 28 explicit TestInputCallback() |
| 28 : callback_count_(0), | 29 : callback_count_(0), |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 43 int had_error() const { | 44 int had_error() const { |
| 44 return had_error_; | 45 return had_error_; |
| 45 } | 46 } |
| 46 | 47 |
| 47 private: | 48 private: |
| 48 int callback_count_; | 49 int callback_count_; |
| 49 int had_error_; | 50 int had_error_; |
| 50 }; | 51 }; |
| 51 | 52 |
| 52 class AudioInputTest : public testing::Test { | 53 class AudioInputTest : public testing::Test { |
| 53 public: | 54 public: |
|
tommi (sloooow) - chröme
2016/03/19 02:32:41
this should be indented by 1 space, but since it i
alokp
2016/03/22 21:47:06
Done.
| |
| 54 AudioInputTest() : | 55 AudioInputTest() |
| 55 message_loop_(base::MessageLoop::TYPE_UI), | 56 : message_loop_(base::MessageLoop::TYPE_UI), |
| 56 audio_manager_(AudioManager::CreateForTesting()), | 57 audio_manager_(AudioManager::Create(nullptr, |
| 57 audio_input_stream_(NULL) { | 58 nullptr, |
| 58 // Wait for the AudioManager to finish any initialization on the audio loop. | 59 nullptr, |
| 59 base::RunLoop().RunUntilIdle(); | 60 &fake_audio_log_factory_)), |
| 60 } | 61 audio_input_stream_(NULL) { |
| 62 // Wait for the AudioManager to finish any initialization on the audio | |
| 63 // loop. | |
| 64 base::RunLoop().RunUntilIdle(); | |
| 65 } | |
| 61 | 66 |
| 62 ~AudioInputTest() override { base::RunLoop().RunUntilIdle(); } | 67 ~AudioInputTest() override { base::RunLoop().RunUntilIdle(); } |
| 63 | 68 |
| 64 protected: | 69 protected: |
| 65 bool InputDevicesAvailable() { | 70 bool InputDevicesAvailable() { |
| 66 return audio_manager_->HasAudioInputDevices(); | 71 return audio_manager_->HasAudioInputDevices(); |
| 67 } | 72 } |
| 68 | 73 |
| 69 void MakeAudioInputStreamOnAudioThread() { | 74 void MakeAudioInputStreamOnAudioThread() { |
| 70 RunOnAudioThread( | 75 RunOnAudioThread( |
| 71 base::Bind(&AudioInputTest::MakeAudioInputStream, | 76 base::Bind(&AudioInputTest::MakeAudioInputStream, |
| 72 base::Unretained(this))); | 77 base::Unretained(this))); |
| 73 } | 78 } |
| 74 | 79 |
| 75 void CloseAudioInputStreamOnAudioThread() { | 80 void CloseAudioInputStreamOnAudioThread() { |
| 76 RunOnAudioThread( | 81 RunOnAudioThread( |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 159 } | 164 } |
| 160 | 165 |
| 161 void RunOnAudioThreadImpl(const base::Closure& closure, | 166 void RunOnAudioThreadImpl(const base::Closure& closure, |
| 162 base::WaitableEvent* event) { | 167 base::WaitableEvent* event) { |
| 163 DCHECK(audio_manager_->GetTaskRunner()->BelongsToCurrentThread()); | 168 DCHECK(audio_manager_->GetTaskRunner()->BelongsToCurrentThread()); |
| 164 closure.Run(); | 169 closure.Run(); |
| 165 event->Signal(); | 170 event->Signal(); |
| 166 } | 171 } |
| 167 | 172 |
| 168 base::MessageLoop message_loop_; | 173 base::MessageLoop message_loop_; |
| 169 scoped_ptr<AudioManager> audio_manager_; | 174 FakeAudioLogFactory fake_audio_log_factory_; |
| 175 ScopedAudioManagerPtr audio_manager_; | |
| 170 AudioInputStream* audio_input_stream_; | 176 AudioInputStream* audio_input_stream_; |
| 171 | 177 |
| 172 private: | 178 private: |
| 173 DISALLOW_COPY_AND_ASSIGN(AudioInputTest); | 179 DISALLOW_COPY_AND_ASSIGN(AudioInputTest); |
| 174 }; | 180 }; |
| 175 | 181 |
| 176 // Test create and close of an AudioInputStream without recording audio. | 182 // Test create and close of an AudioInputStream without recording audio. |
| 177 TEST_F(AudioInputTest, CreateAndClose) { | 183 TEST_F(AudioInputTest, CreateAndClose) { |
| 178 ABORT_AUDIO_TEST_IF_NOT(InputDevicesAvailable()); | 184 ABORT_AUDIO_TEST_IF_NOT(InputDevicesAvailable()); |
| 179 MakeAudioInputStreamOnAudioThread(); | 185 MakeAudioInputStreamOnAudioThread(); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 226 base::MessageLoop::QuitWhenIdleClosure(), | 232 base::MessageLoop::QuitWhenIdleClosure(), |
| 227 base::TimeDelta::FromMilliseconds(500)); | 233 base::TimeDelta::FromMilliseconds(500)); |
| 228 message_loop_.Run(); | 234 message_loop_.Run(); |
| 229 EXPECT_GE(test_callback.callback_count(), 2); | 235 EXPECT_GE(test_callback.callback_count(), 2); |
| 230 EXPECT_FALSE(test_callback.had_error()); | 236 EXPECT_FALSE(test_callback.had_error()); |
| 231 | 237 |
| 232 StopAndCloseAudioInputStreamOnAudioThread(); | 238 StopAndCloseAudioInputStreamOnAudioThread(); |
| 233 } | 239 } |
| 234 | 240 |
| 235 } // namespace media | 241 } // namespace media |
| OLD | NEW |