| 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/macros.h" | 5 #include "base/macros.h" |
| 6 #include "base/memory/scoped_ptr.h" | 6 #include "base/memory/scoped_ptr.h" |
| 7 #include "base/message_loop/message_loop.h" | |
| 8 #include "base/run_loop.h" | 7 #include "base/run_loop.h" |
| 9 #include "base/synchronization/waitable_event.h" | 8 #include "base/synchronization/waitable_event.h" |
| 9 #include "base/test/test_message_loop.h" |
| 10 #include "base/thread_task_runner_handle.h" |
| 10 #include "media/audio/audio_io.h" | 11 #include "media/audio/audio_io.h" |
| 11 #include "media/audio/audio_manager.h" | 12 #include "media/audio/audio_manager.h" |
| 12 #include "media/audio/audio_unittest_util.h" | 13 #include "media/audio/audio_unittest_util.h" |
| 13 #include "media/audio/mock_audio_source_callback.h" | 14 #include "media/audio/mock_audio_source_callback.h" |
| 14 #include "testing/gmock/include/gmock/gmock.h" | 15 #include "testing/gmock/include/gmock/gmock.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 16 | 17 |
| 17 using testing::_; | 18 using testing::_; |
| 18 using testing::DoAll; | 19 using testing::DoAll; |
| 19 using testing::Return; | 20 using testing::Return; |
| 20 | 21 |
| 21 // TODO(crogers): Most of these tests can be made platform agnostic. | 22 // TODO(crogers): Most of these tests can be made platform agnostic. |
| 22 // http://crbug.com/223242 | 23 // http://crbug.com/223242 |
| 23 | 24 |
| 24 namespace media { | 25 namespace media { |
| 25 | 26 |
| 26 ACTION(ZeroBuffer) { | 27 ACTION(ZeroBuffer) { |
| 27 arg0->Zero(); | 28 arg0->Zero(); |
| 28 } | 29 } |
| 29 | 30 |
| 30 ACTION_P(SignalEvent, event) { | 31 ACTION_P(SignalEvent, event) { |
| 31 event->Signal(); | 32 event->Signal(); |
| 32 } | 33 } |
| 33 | 34 |
| 34 class AUHALStreamTest : public testing::Test { | 35 class AUHALStreamTest : public testing::Test { |
| 35 public: | 36 public: |
| 36 AUHALStreamTest() | 37 AUHALStreamTest() |
| 37 : message_loop_(base::MessageLoop::TYPE_UI), | 38 : message_loop_(base::MessageLoop::TYPE_UI), |
| 38 manager_(AudioManager::CreateForTesting()) { | 39 manager_(AudioManager::CreateForTesting( |
| 40 base::ThreadTaskRunnerHandle::Get())) { |
| 39 // Wait for the AudioManager to finish any initialization on the audio loop. | 41 // Wait for the AudioManager to finish any initialization on the audio loop. |
| 40 base::RunLoop().RunUntilIdle(); | 42 base::RunLoop().RunUntilIdle(); |
| 41 } | 43 } |
| 42 | 44 |
| 43 ~AUHALStreamTest() override { base::RunLoop().RunUntilIdle(); } | 45 ~AUHALStreamTest() override {} |
| 44 | 46 |
| 45 AudioOutputStream* Create() { | 47 AudioOutputStream* Create() { |
| 46 return manager_->MakeAudioOutputStream( | 48 return manager_->MakeAudioOutputStream( |
| 47 manager_->GetDefaultOutputStreamParameters(), ""); | 49 manager_->GetDefaultOutputStreamParameters(), ""); |
| 48 } | 50 } |
| 49 | 51 |
| 50 bool OutputDevicesAvailable() { | 52 bool OutputDevicesAvailable() { |
| 51 return manager_->HasAudioOutputDevices(); | 53 return manager_->HasAudioOutputDevices(); |
| 52 } | 54 } |
| 53 | 55 |
| 54 protected: | 56 protected: |
| 55 base::MessageLoop message_loop_; | 57 base::TestMessageLoop message_loop_; |
| 56 scoped_ptr<AudioManager> manager_; | 58 ScopedAudioManagerPtr manager_; |
| 57 MockAudioSourceCallback source_; | 59 MockAudioSourceCallback source_; |
| 58 | 60 |
| 59 private: | 61 private: |
| 60 DISALLOW_COPY_AND_ASSIGN(AUHALStreamTest); | 62 DISALLOW_COPY_AND_ASSIGN(AUHALStreamTest); |
| 61 }; | 63 }; |
| 62 | 64 |
| 63 TEST_F(AUHALStreamTest, HardwareSampleRate) { | 65 TEST_F(AUHALStreamTest, HardwareSampleRate) { |
| 64 ABORT_AUDIO_TEST_IF_NOT(OutputDevicesAvailable()); | 66 ABORT_AUDIO_TEST_IF_NOT(OutputDevicesAvailable()); |
| 65 const AudioParameters preferred_params = | 67 const AudioParameters preferred_params = |
| 66 manager_->GetDefaultOutputStreamParameters(); | 68 manager_->GetDefaultOutputStreamParameters(); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 92 .WillOnce(DoAll(ZeroBuffer(), SignalEvent(&event), Return(0))); | 94 .WillOnce(DoAll(ZeroBuffer(), SignalEvent(&event), Return(0))); |
| 93 EXPECT_CALL(source_, OnError(_)).Times(0); | 95 EXPECT_CALL(source_, OnError(_)).Times(0); |
| 94 stream->Start(&source_); | 96 stream->Start(&source_); |
| 95 event.Wait(); | 97 event.Wait(); |
| 96 | 98 |
| 97 stream->Stop(); | 99 stream->Stop(); |
| 98 stream->Close(); | 100 stream->Close(); |
| 99 } | 101 } |
| 100 | 102 |
| 101 } // namespace media | 103 } // namespace media |
| OLD | NEW |