| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/copresence/mediums/audio/audio_manager.h" | 5 #include "components/copresence/mediums/audio/audio_manager.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "components/copresence/mediums/audio/audio_manager_impl.h" | 9 #include "components/copresence/mediums/audio/audio_manager_impl.h" |
| 10 #include "components/copresence/mediums/audio/audio_player.h" | 10 #include "components/copresence/mediums/audio/audio_player.h" |
| 11 #include "components/copresence/mediums/audio/audio_recorder.h" | 11 #include "components/copresence/mediums/audio/audio_recorder.h" |
| 12 #include "components/copresence/test/audio_test_support.h" | 12 #include "components/copresence/test/audio_test_support.h" |
| 13 #include "media/base/audio_bus.h" | 13 #include "media/base/audio_bus.h" |
| 14 //#include "testing/gmock/include/gmock/gmock.h" | 14 //#include "testing/gmock/include/gmock/gmock.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 16 | 16 |
| 17 namespace copresence { | 17 namespace copresence { |
| 18 | 18 |
| 19 class AudioPlayerStub final : public AudioPlayer { | 19 class AudioPlayerStub final : public AudioPlayer { |
| 20 public: | 20 public: |
| 21 AudioPlayerStub() : is_playing_(false) {} | 21 AudioPlayerStub() : is_playing_(false) {} |
| 22 virtual ~AudioPlayerStub() {} | 22 ~AudioPlayerStub() override {} |
| 23 | 23 |
| 24 // AudioPlayer overrides: | 24 // AudioPlayer overrides: |
| 25 void Initialize() override {} | 25 void Initialize() override {} |
| 26 void Play(const scoped_refptr<media::AudioBusRefCounted>&) override { | 26 void Play(const scoped_refptr<media::AudioBusRefCounted>&) override { |
| 27 is_playing_ = true; | 27 is_playing_ = true; |
| 28 } | 28 } |
| 29 void Stop() override { is_playing_ = false; } | 29 void Stop() override { is_playing_ = false; } |
| 30 void Finalize() override { delete this; } | 30 void Finalize() override { delete this; } |
| 31 bool IsPlaying() override { return is_playing_; } | 31 bool IsPlaying() override { return is_playing_; } |
| 32 | 32 |
| 33 private: | 33 private: |
| 34 bool is_playing_; | 34 bool is_playing_; |
| 35 DISALLOW_COPY_AND_ASSIGN(AudioPlayerStub); | 35 DISALLOW_COPY_AND_ASSIGN(AudioPlayerStub); |
| 36 }; | 36 }; |
| 37 | 37 |
| 38 class AudioRecorderStub final : public AudioRecorder { | 38 class AudioRecorderStub final : public AudioRecorder { |
| 39 public: | 39 public: |
| 40 AudioRecorderStub() : is_recording_(false) {} | 40 AudioRecorderStub() : is_recording_(false) {} |
| 41 virtual ~AudioRecorderStub() {} | 41 ~AudioRecorderStub() override {} |
| 42 | 42 |
| 43 // AudioRecorder overrides: | 43 // AudioRecorder overrides: |
| 44 void Initialize(const RecordedSamplesCallback& cb) override { cb_ = cb; } | 44 void Initialize(const RecordedSamplesCallback& cb) override { cb_ = cb; } |
| 45 void Record() override { is_recording_ = true; } | 45 void Record() override { is_recording_ = true; } |
| 46 void Stop() override { is_recording_ = false; } | 46 void Stop() override { is_recording_ = false; } |
| 47 void Finalize() override { delete this; } | 47 void Finalize() override { delete this; } |
| 48 bool IsRecording() override { return is_recording_; } | 48 bool IsRecording() override { return is_recording_; } |
| 49 | 49 |
| 50 void TriggerDecodeRequest() { | 50 void TriggerDecodeRequest() { |
| 51 if (!cb_.is_null()) | 51 if (!cb_.is_null()) |
| (...skipping 15 matching lines...) Expand all Loading... |
| 67 inaudible_player_(new AudioPlayerStub), | 67 inaudible_player_(new AudioPlayerStub), |
| 68 recorder_(new AudioRecorderStub), | 68 recorder_(new AudioRecorderStub), |
| 69 last_received_decode_type_(AUDIO_TYPE_UNKNOWN) { | 69 last_received_decode_type_(AUDIO_TYPE_UNKNOWN) { |
| 70 audio_manager_->set_player_for_testing(AUDIBLE, audible_player_); | 70 audio_manager_->set_player_for_testing(AUDIBLE, audible_player_); |
| 71 audio_manager_->set_player_for_testing(INAUDIBLE, inaudible_player_); | 71 audio_manager_->set_player_for_testing(INAUDIBLE, inaudible_player_); |
| 72 audio_manager_->set_recorder_for_testing(recorder_); | 72 audio_manager_->set_recorder_for_testing(recorder_); |
| 73 audio_manager_->Initialize( | 73 audio_manager_->Initialize( |
| 74 base::Bind(&AudioManagerTest::DecodeSamples, base::Unretained(this)), | 74 base::Bind(&AudioManagerTest::DecodeSamples, base::Unretained(this)), |
| 75 base::Bind(&AudioManagerTest::EncodeToken, base::Unretained(this))); | 75 base::Bind(&AudioManagerTest::EncodeToken, base::Unretained(this))); |
| 76 } | 76 } |
| 77 virtual ~AudioManagerTest() {} | 77 ~AudioManagerTest() override {} |
| 78 | 78 |
| 79 protected: | 79 protected: |
| 80 void EncodeToken(const std::string& token, | 80 void EncodeToken(const std::string& token, |
| 81 AudioType audible, | 81 AudioType audible, |
| 82 const AudioManager::SamplesCallback& callback) { | 82 const AudioManager::SamplesCallback& callback) { |
| 83 callback.Run( | 83 callback.Run( |
| 84 token, audible, CreateRandomAudioRefCounted(0x1337, 1, 0x7331)); | 84 token, audible, CreateRandomAudioRefCounted(0x1337, 1, 0x7331)); |
| 85 } | 85 } |
| 86 | 86 |
| 87 void DecodeSamples(AudioType type, const std::string& /* samples */) { | 87 void DecodeSamples(AudioType type, const std::string& /* samples */) { |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 audio_manager_->StartRecording(INAUDIBLE); | 142 audio_manager_->StartRecording(INAUDIBLE); |
| 143 recorder_->TriggerDecodeRequest(); | 143 recorder_->TriggerDecodeRequest(); |
| 144 EXPECT_EQ(BOTH, last_received_decode_type_); | 144 EXPECT_EQ(BOTH, last_received_decode_type_); |
| 145 | 145 |
| 146 audio_manager_->StopRecording(AUDIBLE); | 146 audio_manager_->StopRecording(AUDIBLE); |
| 147 recorder_->TriggerDecodeRequest(); | 147 recorder_->TriggerDecodeRequest(); |
| 148 EXPECT_EQ(INAUDIBLE, last_received_decode_type_); | 148 EXPECT_EQ(INAUDIBLE, last_received_decode_type_); |
| 149 } | 149 } |
| 150 | 150 |
| 151 } // namespace copresence | 151 } // namespace copresence |
| OLD | NEW |