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