| 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" |
| 11 #include "base/test/test_message_loop.h" | 11 #include "base/test/test_message_loop.h" |
| 12 #include "base/threading/platform_thread.h" | 12 #include "base/threading/platform_thread.h" |
| 13 #include "base/threading/thread_task_runner_handle.h" | 13 #include "base/threading/thread_task_runner_handle.h" |
| 14 #include "build/build_config.h" | 14 #include "build/build_config.h" |
| 15 #include "media/audio/audio_device_description.h" | 15 #include "media/audio/audio_device_description.h" |
| 16 #include "media/audio/audio_device_info_accessor_for_tests.h" | 16 #include "media/audio/audio_device_info_accessor_for_tests.h" |
| 17 #include "media/audio/audio_io.h" | 17 #include "media/audio/audio_io.h" |
| 18 #include "media/audio/audio_manager.h" | 18 #include "media/audio/audio_manager.h" |
| 19 #include "media/audio/audio_unittest_util.h" | 19 #include "media/audio/audio_unittest_util.h" |
| 20 #include "media/audio/test_audio_thread.h" |
| 20 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
| 21 | 22 |
| 22 namespace media { | 23 namespace media { |
| 23 | 24 |
| 24 // This class allows to find out if the callbacks are occurring as | 25 // This class allows to find out if the callbacks are occurring as |
| 25 // expected and if any error has been reported. | 26 // expected and if any error has been reported. |
| 26 class TestInputCallback : public AudioInputStream::AudioInputCallback { | 27 class TestInputCallback : public AudioInputStream::AudioInputCallback { |
| 27 public: | 28 public: |
| 28 explicit TestInputCallback() | 29 explicit TestInputCallback() |
| 29 : callback_count_(0), | 30 : callback_count_(0), |
| (...skipping 18 matching lines...) Expand all Loading... |
| 48 private: | 49 private: |
| 49 int callback_count_; | 50 int callback_count_; |
| 50 int had_error_; | 51 int had_error_; |
| 51 }; | 52 }; |
| 52 | 53 |
| 53 class AudioInputTest : public testing::Test { | 54 class AudioInputTest : public testing::Test { |
| 54 public: | 55 public: |
| 55 AudioInputTest() | 56 AudioInputTest() |
| 56 : message_loop_(base::MessageLoop::TYPE_UI), | 57 : message_loop_(base::MessageLoop::TYPE_UI), |
| 57 audio_manager_(AudioManager::CreateForTesting( | 58 audio_manager_(AudioManager::CreateForTesting( |
| 58 base::ThreadTaskRunnerHandle::Get())), | 59 base::MakeUnique<TestAudioThread>())), |
| 59 audio_input_stream_(NULL) { | 60 audio_input_stream_(NULL) { |
| 60 base::RunLoop().RunUntilIdle(); | 61 base::RunLoop().RunUntilIdle(); |
| 61 } | 62 } |
| 62 | 63 |
| 63 ~AudioInputTest() override {} | 64 ~AudioInputTest() override { audio_manager_->Shutdown(); } |
| 64 | 65 |
| 65 protected: | 66 protected: |
| 66 bool InputDevicesAvailable() { | 67 bool InputDevicesAvailable() { |
| 67 return AudioDeviceInfoAccessorForTests(audio_manager_.get()) | 68 return AudioDeviceInfoAccessorForTests(audio_manager_.get()) |
| 68 .HasAudioInputDevices(); | 69 .HasAudioInputDevices(); |
| 69 } | 70 } |
| 70 | 71 |
| 71 void MakeAudioInputStreamOnAudioThread() { | 72 void MakeAudioInputStreamOnAudioThread() { |
| 72 RunOnAudioThread( | 73 RunOnAudioThread( |
| 73 base::Bind(&AudioInputTest::MakeAudioInputStream, | 74 base::Bind(&AudioInputTest::MakeAudioInputStream, |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 | 149 |
| 149 // Synchronously runs the provided callback/closure on the audio thread. | 150 // Synchronously runs the provided callback/closure on the audio thread. |
| 150 void RunOnAudioThread(const base::Closure& closure) { | 151 void RunOnAudioThread(const base::Closure& closure) { |
| 151 DCHECK(audio_manager_->GetTaskRunner()->BelongsToCurrentThread()); | 152 DCHECK(audio_manager_->GetTaskRunner()->BelongsToCurrentThread()); |
| 152 closure.Run(); | 153 closure.Run(); |
| 153 } | 154 } |
| 154 | 155 |
| 155 void OnLogMessage(const std::string& message) {} | 156 void OnLogMessage(const std::string& message) {} |
| 156 | 157 |
| 157 base::TestMessageLoop message_loop_; | 158 base::TestMessageLoop message_loop_; |
| 158 ScopedAudioManagerPtr audio_manager_; | 159 std::unique_ptr<AudioManager> audio_manager_; |
| 159 AudioInputStream* audio_input_stream_; | 160 AudioInputStream* audio_input_stream_; |
| 160 | 161 |
| 161 private: | 162 private: |
| 162 DISALLOW_COPY_AND_ASSIGN(AudioInputTest); | 163 DISALLOW_COPY_AND_ASSIGN(AudioInputTest); |
| 163 }; | 164 }; |
| 164 | 165 |
| 165 // Test create and close of an AudioInputStream without recording audio. | 166 // Test create and close of an AudioInputStream without recording audio. |
| 166 TEST_F(AudioInputTest, CreateAndClose) { | 167 TEST_F(AudioInputTest, CreateAndClose) { |
| 167 ABORT_AUDIO_TEST_IF_NOT(InputDevicesAvailable()); | 168 ABORT_AUDIO_TEST_IF_NOT(InputDevicesAvailable()); |
| 168 MakeAudioInputStreamOnAudioThread(); | 169 MakeAudioInputStreamOnAudioThread(); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 FROM_HERE, run_loop.QuitClosure(), | 217 FROM_HERE, run_loop.QuitClosure(), |
| 217 base::TimeDelta::FromMilliseconds(500)); | 218 base::TimeDelta::FromMilliseconds(500)); |
| 218 run_loop.Run(); | 219 run_loop.Run(); |
| 219 EXPECT_GE(test_callback.callback_count(), 2); | 220 EXPECT_GE(test_callback.callback_count(), 2); |
| 220 EXPECT_FALSE(test_callback.had_error()); | 221 EXPECT_FALSE(test_callback.had_error()); |
| 221 | 222 |
| 222 StopAndCloseAudioInputStreamOnAudioThread(); | 223 StopAndCloseAudioInputStreamOnAudioThread(); |
| 223 } | 224 } |
| 224 | 225 |
| 225 } // namespace media | 226 } // namespace media |
| OLD | NEW |