| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/macros.h" | 6 #include "base/macros.h" |
| 7 #include "base/run_loop.h" | 7 #include "base/run_loop.h" |
| 8 #include "base/synchronization/waitable_event.h" | 8 #include "base/synchronization/waitable_event.h" |
| 9 #include "base/test/test_message_loop.h" | 9 #include "base/test/test_message_loop.h" |
| 10 #include "base/threading/thread_task_runner_handle.h" | 10 #include "base/threading/thread_task_runner_handle.h" |
| 11 #include "media/audio/audio_device_info_accessor_for_tests.h" | 11 #include "media/audio/audio_device_info_accessor_for_tests.h" |
| 12 #include "media/audio/audio_io.h" | 12 #include "media/audio/audio_io.h" |
| 13 #include "media/audio/audio_manager.h" | 13 #include "media/audio/audio_manager.h" |
| 14 #include "media/audio/audio_unittest_util.h" | 14 #include "media/audio/audio_unittest_util.h" |
| 15 #include "media/audio/mock_audio_source_callback.h" | 15 #include "media/audio/mock_audio_source_callback.h" |
| 16 #include "media/audio/test_audio_thread.h" |
| 16 #include "testing/gmock/include/gmock/gmock.h" | 17 #include "testing/gmock/include/gmock/gmock.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
| 18 | 19 |
| 19 using testing::_; | 20 using testing::_; |
| 20 using testing::DoAll; | 21 using testing::DoAll; |
| 21 using testing::Return; | 22 using testing::Return; |
| 22 | 23 |
| 23 // TODO(crogers): Most of these tests can be made platform agnostic. | 24 // TODO(crogers): Most of these tests can be made platform agnostic. |
| 24 // http://crbug.com/223242 | 25 // http://crbug.com/223242 |
| 25 | 26 |
| 26 namespace media { | 27 namespace media { |
| 27 | 28 |
| 28 ACTION(ZeroBuffer) { | 29 ACTION(ZeroBuffer) { |
| 29 arg3->Zero(); | 30 arg3->Zero(); |
| 30 } | 31 } |
| 31 | 32 |
| 32 ACTION_P3(MaybeSignalEvent, counter, signal_at_count, event) { | 33 ACTION_P3(MaybeSignalEvent, counter, signal_at_count, event) { |
| 33 if (++(*counter) == signal_at_count) | 34 if (++(*counter) == signal_at_count) |
| 34 event->Signal(); | 35 event->Signal(); |
| 35 } | 36 } |
| 36 | 37 |
| 37 class AUHALStreamTest : public testing::Test { | 38 class AUHALStreamTest : public testing::Test { |
| 38 public: | 39 public: |
| 39 AUHALStreamTest() | 40 AUHALStreamTest() |
| 40 : message_loop_(base::MessageLoop::TYPE_UI), | 41 : message_loop_(base::MessageLoop::TYPE_UI), |
| 41 manager_(AudioManager::CreateForTesting( | 42 manager_(AudioManager::CreateForTesting( |
| 42 base::ThreadTaskRunnerHandle::Get())), | 43 base::MakeUnique<TestAudioThread>())), |
| 43 manager_device_info_(manager_.get()) { | 44 manager_device_info_(manager_.get()) { |
| 44 // Wait for the AudioManager to finish any initialization on the audio loop. | 45 // Wait for the AudioManager to finish any initialization on the audio loop. |
| 45 base::RunLoop().RunUntilIdle(); | 46 base::RunLoop().RunUntilIdle(); |
| 46 } | 47 } |
| 47 | 48 |
| 48 ~AUHALStreamTest() override {} | 49 ~AUHALStreamTest() override {} |
| 49 | 50 |
| 50 AudioOutputStream* Create() { | 51 AudioOutputStream* Create() { |
| 51 return manager_->MakeAudioOutputStream( | 52 return manager_->MakeAudioOutputStream( |
| 52 manager_device_info_.GetDefaultOutputStreamParameters(), "", | 53 manager_device_info_.GetDefaultOutputStreamParameters(), "", |
| 53 base::Bind(&AUHALStreamTest::OnLogMessage, base::Unretained(this))); | 54 base::Bind(&AUHALStreamTest::OnLogMessage, base::Unretained(this))); |
| 54 } | 55 } |
| 55 | 56 |
| 56 bool OutputDevicesAvailable() { | 57 bool OutputDevicesAvailable() { |
| 57 return manager_device_info_.HasAudioOutputDevices(); | 58 return manager_device_info_.HasAudioOutputDevices(); |
| 58 } | 59 } |
| 59 | 60 |
| 60 void OnLogMessage(const std::string& message) { log_message_ = message; } | 61 void OnLogMessage(const std::string& message) { log_message_ = message; } |
| 61 | 62 |
| 62 protected: | 63 protected: |
| 63 base::TestMessageLoop message_loop_; | 64 base::TestMessageLoop message_loop_; |
| 64 ScopedAudioManagerPtr manager_; | 65 std::unique_ptr<AudioManager> manager_; |
| 65 AudioDeviceInfoAccessorForTests manager_device_info_; | 66 AudioDeviceInfoAccessorForTests manager_device_info_; |
| 66 MockAudioSourceCallback source_; | 67 MockAudioSourceCallback source_; |
| 67 std::string log_message_; | 68 std::string log_message_; |
| 68 | 69 |
| 69 private: | 70 private: |
| 70 DISALLOW_COPY_AND_ASSIGN(AUHALStreamTest); | 71 DISALLOW_COPY_AND_ASSIGN(AUHALStreamTest); |
| 71 }; | 72 }; |
| 72 | 73 |
| 73 TEST_F(AUHALStreamTest, HardwareSampleRate) { | 74 TEST_F(AUHALStreamTest, HardwareSampleRate) { |
| 74 ABORT_AUDIO_TEST_IF_NOT(OutputDevicesAvailable()); | 75 ABORT_AUDIO_TEST_IF_NOT(OutputDevicesAvailable()); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 stream->Start(&source_); | 112 stream->Start(&source_); |
| 112 event.Wait(); | 113 event.Wait(); |
| 113 | 114 |
| 114 stream->Stop(); | 115 stream->Stop(); |
| 115 stream->Close(); | 116 stream->Close(); |
| 116 | 117 |
| 117 EXPECT_FALSE(log_message_.empty()); | 118 EXPECT_FALSE(log_message_.empty()); |
| 118 } | 119 } |
| 119 | 120 |
| 120 } // namespace media | 121 } // namespace media |
| OLD | NEW |