| 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 <memory> | 7 #include <memory> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| 11 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
| 12 #include "base/run_loop.h" | 12 #include "base/run_loop.h" |
| 13 #include "base/single_thread_task_runner.h" | 13 #include "base/single_thread_task_runner.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_manager.h" | 16 #include "media/audio/audio_manager.h" |
| 17 #include "media/audio/audio_manager_base.h" | 17 #include "media/audio/audio_manager_base.h" |
| 18 #include "media/audio/audio_output_dispatcher_impl.h" | 18 #include "media/audio/audio_output_dispatcher_impl.h" |
| 19 #include "media/audio/audio_output_proxy.h" | 19 #include "media/audio/audio_output_proxy.h" |
| 20 #include "media/audio/audio_output_resampler.h" | 20 #include "media/audio/audio_output_resampler.h" |
| 21 #include "media/audio/fake_audio_log_factory.h" | 21 #include "media/audio/fake_audio_log_factory.h" |
| 22 #include "media/audio/fake_audio_output_stream.h" | 22 #include "media/audio/fake_audio_output_stream.h" |
| 23 #include "media/audio/test_audio_thread.h" |
| 23 #include "testing/gmock/include/gmock/gmock.h" | 24 #include "testing/gmock/include/gmock/gmock.h" |
| 24 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
| 25 | 26 |
| 26 using ::testing::_; | 27 using ::testing::_; |
| 27 using ::testing::AllOf; | 28 using ::testing::AllOf; |
| 28 using ::testing::DoAll; | 29 using ::testing::DoAll; |
| 29 using ::testing::Field; | 30 using ::testing::Field; |
| 30 using ::testing::Mock; | 31 using ::testing::Mock; |
| 31 using ::testing::NotNull; | 32 using ::testing::NotNull; |
| 32 using ::testing::Return; | 33 using ::testing::Return; |
| 33 using ::testing::SetArrayArgument; | 34 using ::testing::SetArrayArgument; |
| 34 using media::AudioBus; | 35 using media::AudioBus; |
| 35 using media::AudioInputStream; | 36 using media::AudioInputStream; |
| 36 using media::AudioManager; | 37 using media::AudioManager; |
| 37 using media::AudioManagerBase; | 38 using media::AudioManagerBase; |
| 38 using media::AudioOutputDispatcher; | 39 using media::AudioOutputDispatcher; |
| 39 using media::AudioOutputProxy; | 40 using media::AudioOutputProxy; |
| 40 using media::AudioOutputStream; | 41 using media::AudioOutputStream; |
| 41 using media::AudioParameters; | 42 using media::AudioParameters; |
| 42 using media::FakeAudioOutputStream; | 43 using media::FakeAudioOutputStream; |
| 44 using media::TestAudioThread; |
| 43 | 45 |
| 44 namespace { | 46 namespace { |
| 45 | 47 |
| 46 static const int kTestCloseDelayMs = 10; | 48 static const int kTestCloseDelayMs = 10; |
| 47 | 49 |
| 48 // Delay between callbacks to AudioSourceCallback::OnMoreData. | 50 // Delay between callbacks to AudioSourceCallback::OnMoreData. |
| 49 static const int kOnMoreDataCallbackDelayMs = 10; | 51 static const int kOnMoreDataCallbackDelayMs = 10; |
| 50 | 52 |
| 51 // Let start run long enough for many OnMoreData callbacks to occur. | 53 // Let start run long enough for many OnMoreData callbacks to occur. |
| 52 static const int kStartRunTimeMs = kOnMoreDataCallbackDelayMs * 10; | 54 static const int kStartRunTimeMs = kOnMoreDataCallbackDelayMs * 10; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 private: | 93 private: |
| 92 bool start_called_; | 94 bool start_called_; |
| 93 bool stop_called_; | 95 bool stop_called_; |
| 94 AudioParameters params_; | 96 AudioParameters params_; |
| 95 std::unique_ptr<AudioOutputStream> fake_output_stream_; | 97 std::unique_ptr<AudioOutputStream> fake_output_stream_; |
| 96 }; | 98 }; |
| 97 | 99 |
| 98 class MockAudioManager : public AudioManagerBase { | 100 class MockAudioManager : public AudioManagerBase { |
| 99 public: | 101 public: |
| 100 MockAudioManager() | 102 MockAudioManager() |
| 101 : AudioManagerBase(base::ThreadTaskRunnerHandle::Get(), | 103 : AudioManagerBase(base::MakeUnique<TestAudioThread>(), |
| 102 base::ThreadTaskRunnerHandle::Get(), | |
| 103 &fake_audio_log_factory_) {} | 104 &fake_audio_log_factory_) {} |
| 104 ~MockAudioManager() override { Shutdown(); } | 105 ~MockAudioManager() override { Shutdown(); } |
| 105 | 106 |
| 106 MOCK_METHOD3(MakeAudioOutputStream, | 107 MOCK_METHOD3(MakeAudioOutputStream, |
| 107 AudioOutputStream*(const AudioParameters& params, | 108 AudioOutputStream*(const AudioParameters& params, |
| 108 const std::string& device_id, | 109 const std::string& device_id, |
| 109 const LogCallback& log_callback)); | 110 const LogCallback& log_callback)); |
| 110 MOCK_METHOD2(MakeAudioOutputStreamProxy, AudioOutputStream*( | 111 MOCK_METHOD2(MakeAudioOutputStreamProxy, AudioOutputStream*( |
| 111 const AudioParameters& params, | 112 const AudioParameters& params, |
| 112 const std::string& device_id)); | 113 const std::string& device_id)); |
| (...skipping 729 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 842 .WillOnce(Return(&real_stream)); | 843 .WillOnce(Return(&real_stream)); |
| 843 | 844 |
| 844 // Stream1 should be able to successfully open and start. | 845 // Stream1 should be able to successfully open and start. |
| 845 EXPECT_CALL(real_stream, Open()).WillOnce(Return(true)); | 846 EXPECT_CALL(real_stream, Open()).WillOnce(Return(true)); |
| 846 proxy = resampler_->CreateStreamProxy(); | 847 proxy = resampler_->CreateStreamProxy(); |
| 847 EXPECT_TRUE(proxy->Open()); | 848 EXPECT_TRUE(proxy->Open()); |
| 848 CloseAndWaitForCloseTimer(proxy, &real_stream); | 849 CloseAndWaitForCloseTimer(proxy, &real_stream); |
| 849 } | 850 } |
| 850 | 851 |
| 851 } // namespace media | 852 } // namespace media |
| OLD | NEW |