Chromium Code Reviews| 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/stub_whispernet_client.h" |
| 13 #include "media/base/audio_bus.h" | 13 #include "media/base/audio_bus.h" |
| 14 //#include "testing/gmock/include/gmock/gmock.h" | |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 16 | 15 |
| 17 namespace copresence { | 16 namespace copresence { |
| 18 | 17 |
| 19 class AudioPlayerStub final : public AudioPlayer { | 18 class AudioPlayerStub final : public AudioPlayer { |
| 20 public: | 19 public: |
| 21 AudioPlayerStub() : is_playing_(false) {} | 20 AudioPlayerStub() : is_playing_(false) {} |
| 22 ~AudioPlayerStub() override {} | 21 ~AudioPlayerStub() override {} |
| 23 | 22 |
| 24 // AudioPlayer overrides: | 23 // AudioPlayer overrides: |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 64 AudioManagerTest() | 63 AudioManagerTest() |
| 65 : audio_manager_(new AudioManagerImpl()), | 64 : audio_manager_(new AudioManagerImpl()), |
| 66 audible_player_(new AudioPlayerStub), | 65 audible_player_(new AudioPlayerStub), |
| 67 inaudible_player_(new AudioPlayerStub), | 66 inaudible_player_(new AudioPlayerStub), |
| 68 recorder_(new AudioRecorderStub), | 67 recorder_(new AudioRecorderStub), |
| 69 last_received_decode_type_(AUDIO_TYPE_UNKNOWN) { | 68 last_received_decode_type_(AUDIO_TYPE_UNKNOWN) { |
| 70 audio_manager_->set_player_for_testing(AUDIBLE, audible_player_); | 69 audio_manager_->set_player_for_testing(AUDIBLE, audible_player_); |
| 71 audio_manager_->set_player_for_testing(INAUDIBLE, inaudible_player_); | 70 audio_manager_->set_player_for_testing(INAUDIBLE, inaudible_player_); |
| 72 audio_manager_->set_recorder_for_testing(recorder_); | 71 audio_manager_->set_recorder_for_testing(recorder_); |
| 73 audio_manager_->Initialize( | 72 audio_manager_->Initialize( |
| 74 base::Bind(&AudioManagerTest::DecodeSamples, base::Unretained(this)), | 73 new StubWhispernetClient, |
|
Charlie
2014/11/06 17:28:23
Keep this in a local scoped_ptr. Otherwise it will
rkc
2014/11/06 19:58:24
Done.
| |
| 75 base::Bind(&AudioManagerTest::EncodeToken, base::Unretained(this))); | 74 base::Bind(&AudioManagerTest::GetTokens, base::Unretained(this))); |
| 76 } | 75 } |
| 77 ~AudioManagerTest() override {} | 76 ~AudioManagerTest() override {} |
| 78 | 77 |
| 79 protected: | 78 protected: |
| 80 void EncodeToken(const std::string& token, | 79 void GetTokens(const std::vector<AudioToken>& tokens) { |
|
Charlie
2014/11/06 17:28:23
Shouldn't we start by setting last_received_decode
rkc
2014/11/06 19:58:24
Done.
| |
| 81 AudioType audible, | 80 for (const auto& token : tokens) { |
| 82 const AudioManager::SamplesCallback& callback) { | 81 if (token.audible && last_received_decode_type_ == INAUDIBLE) { |
| 83 callback.Run( | 82 last_received_decode_type_ = BOTH; |
| 84 token, audible, CreateRandomAudioRefCounted(0x1337, 1, 0x7331)); | 83 } else if (!token.audible && last_received_decode_type_ == AUDIBLE) { |
| 85 } | 84 last_received_decode_type_ = BOTH; |
| 86 | 85 } else if (token.audible) { |
| 87 void DecodeSamples(AudioType type, const std::string& /* samples */) { | 86 last_received_decode_type_ = AUDIBLE; |
| 88 last_received_decode_type_ = type; | 87 } else { |
| 88 last_received_decode_type_ = INAUDIBLE; | |
| 89 } | |
| 90 } | |
| 89 } | 91 } |
| 90 | 92 |
| 91 base::MessageLoop message_loop_; | 93 base::MessageLoop message_loop_; |
| 92 scoped_ptr<AudioManagerImpl> audio_manager_; | 94 scoped_ptr<AudioManagerImpl> audio_manager_; |
| 93 | 95 |
| 94 // These will be deleted by |audio_manager_|'s dtor calling finalize on them. | 96 // These will be deleted by |audio_manager_|'s dtor calling finalize on them. |
| 95 AudioPlayerStub* audible_player_; | 97 AudioPlayerStub* audible_player_; |
| 96 AudioPlayerStub* inaudible_player_; | 98 AudioPlayerStub* inaudible_player_; |
| 97 AudioRecorderStub* recorder_; | 99 AudioRecorderStub* recorder_; |
| 98 | 100 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 142 audio_manager_->StartRecording(INAUDIBLE); | 144 audio_manager_->StartRecording(INAUDIBLE); |
| 143 recorder_->TriggerDecodeRequest(); | 145 recorder_->TriggerDecodeRequest(); |
| 144 EXPECT_EQ(BOTH, last_received_decode_type_); | 146 EXPECT_EQ(BOTH, last_received_decode_type_); |
| 145 | 147 |
| 146 audio_manager_->StopRecording(AUDIBLE); | 148 audio_manager_->StopRecording(AUDIBLE); |
| 147 recorder_->TriggerDecodeRequest(); | 149 recorder_->TriggerDecodeRequest(); |
| 148 EXPECT_EQ(INAUDIBLE, last_received_decode_type_); | 150 EXPECT_EQ(INAUDIBLE, last_received_decode_type_); |
| 149 } | 151 } |
| 150 | 152 |
| 151 } // namespace copresence | 153 } // namespace copresence |
| OLD | NEW |