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