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