| 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 "base/basictypes.h" | 5 #include "base/basictypes.h" |
| 6 #include "base/environment.h" | 6 #include "base/environment.h" |
| 7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
| 10 #include "base/synchronization/waitable_event.h" | 10 #include "base/synchronization/waitable_event.h" |
| 11 #include "base/threading/platform_thread.h" | 11 #include "base/threading/platform_thread.h" |
| 12 #include "media/audio/audio_io.h" | 12 #include "media/audio/audio_io.h" |
| 13 #include "media/audio/audio_manager_base.h" | 13 #include "media/audio/audio_manager_base.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 15 | 15 |
| 16 namespace media { | 16 namespace media { |
| 17 | 17 |
| 18 // This class allows to find out if the callbacks are occurring as | 18 // This class allows to find out if the callbacks are occurring as |
| 19 // expected and if any error has been reported. | 19 // expected and if any error has been reported. |
| 20 class TestInputCallback : public AudioInputStream::AudioInputCallback { | 20 class TestInputCallback : public AudioInputStream::AudioInputCallback { |
| 21 public: | 21 public: |
| 22 explicit TestInputCallback() | 22 explicit TestInputCallback() |
| 23 : callback_count_(0), | 23 : callback_count_(0), |
| 24 had_error_(0) { | 24 had_error_(0) { |
| 25 } | 25 } |
| 26 virtual void OnData(AudioInputStream* stream, | 26 void OnData(AudioInputStream* stream, |
| 27 const AudioBus* source, | 27 const AudioBus* source, |
| 28 uint32 hardware_delay_bytes, | 28 uint32 hardware_delay_bytes, |
| 29 double volume) override { | 29 double volume) override { |
| 30 ++callback_count_; | 30 ++callback_count_; |
| 31 } | 31 } |
| 32 virtual void OnError(AudioInputStream* stream) override { | 32 void OnError(AudioInputStream* stream) override { ++had_error_; } |
| 33 ++had_error_; | |
| 34 } | |
| 35 // Returns how many times OnData() has been called. | 33 // Returns how many times OnData() has been called. |
| 36 int callback_count() const { | 34 int callback_count() const { |
| 37 return callback_count_; | 35 return callback_count_; |
| 38 } | 36 } |
| 39 // Returns how many times the OnError callback was called. | 37 // Returns how many times the OnError callback was called. |
| 40 int had_error() const { | 38 int had_error() const { |
| 41 return had_error_; | 39 return had_error_; |
| 42 } | 40 } |
| 43 | 41 |
| 44 private: | 42 private: |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 base::MessageLoop::QuitClosure(), | 232 base::MessageLoop::QuitClosure(), |
| 235 base::TimeDelta::FromMilliseconds(500)); | 233 base::TimeDelta::FromMilliseconds(500)); |
| 236 message_loop_.Run(); | 234 message_loop_.Run(); |
| 237 EXPECT_GE(test_callback.callback_count(), 2); | 235 EXPECT_GE(test_callback.callback_count(), 2); |
| 238 EXPECT_FALSE(test_callback.had_error()); | 236 EXPECT_FALSE(test_callback.had_error()); |
| 239 | 237 |
| 240 StopAndCloseAudioInputStreamOnAudioThread(); | 238 StopAndCloseAudioInputStreamOnAudioThread(); |
| 241 } | 239 } |
| 242 | 240 |
| 243 } // namespace media | 241 } // namespace media |
| OLD | NEW |