| 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 30 matching lines...) Expand all  Loading... | 
| 55  private: | 54  private: | 
| 56   RecordedSamplesCallback cb_; | 55   RecordedSamplesCallback cb_; | 
| 57   bool is_recording_; | 56   bool is_recording_; | 
| 58 | 57 | 
| 59   DISALLOW_COPY_AND_ASSIGN(AudioRecorderStub); | 58   DISALLOW_COPY_AND_ASSIGN(AudioRecorderStub); | 
| 60 }; | 59 }; | 
| 61 | 60 | 
| 62 class AudioManagerTest : public testing::Test { | 61 class AudioManagerTest : public testing::Test { | 
| 63  public: | 62  public: | 
| 64   AudioManagerTest() | 63   AudioManagerTest() | 
| 65       : audio_manager_(new AudioManagerImpl()), | 64       : whispernet_client_(new StubWhispernetClient), | 
|  | 65         audio_manager_(new AudioManagerImpl()), | 
| 66         audible_player_(new AudioPlayerStub), | 66         audible_player_(new AudioPlayerStub), | 
| 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         whispernet_client_.get(), | 
| 75         base::Bind(&AudioManagerTest::EncodeToken, base::Unretained(this))); | 75         base::Bind(&AudioManagerTest::GetTokens, base::Unretained(this))); | 
| 76   } | 76   } | 
|  | 77 | 
| 77   ~AudioManagerTest() override {} | 78   ~AudioManagerTest() override {} | 
| 78 | 79 | 
| 79  protected: | 80  protected: | 
| 80   void EncodeToken(const std::string& token, | 81   void GetTokens(const std::vector<AudioToken>& tokens) { | 
| 81                    AudioType audible, | 82     last_received_decode_type_ = AUDIO_TYPE_UNKNOWN; | 
| 82                    const AudioManager::SamplesCallback& callback) { | 83     for (const auto& token : tokens) { | 
| 83     callback.Run( | 84       if (token.audible && last_received_decode_type_ == INAUDIBLE) { | 
| 84         token, audible, CreateRandomAudioRefCounted(0x1337, 1, 0x7331)); | 85         last_received_decode_type_ = BOTH; | 
| 85   } | 86       } else if (!token.audible && last_received_decode_type_ == AUDIBLE) { | 
| 86 | 87         last_received_decode_type_ = BOTH; | 
| 87   void DecodeSamples(AudioType type, const std::string& /* samples */) { | 88       } else if (token.audible) { | 
| 88     last_received_decode_type_ = type; | 89         last_received_decode_type_ = AUDIBLE; | 
|  | 90       } else { | 
|  | 91         last_received_decode_type_ = INAUDIBLE; | 
|  | 92       } | 
|  | 93     } | 
| 89   } | 94   } | 
| 90 | 95 | 
| 91   base::MessageLoop message_loop_; | 96   base::MessageLoop message_loop_; | 
|  | 97   // Order is important, |whispernet_client_| needs to get destructed *after* | 
|  | 98   // |audio_manager_|. | 
|  | 99   scoped_ptr<WhispernetClient> whispernet_client_; | 
| 92   scoped_ptr<AudioManagerImpl> audio_manager_; | 100   scoped_ptr<AudioManagerImpl> audio_manager_; | 
| 93 | 101 | 
| 94   // These will be deleted by |audio_manager_|'s dtor calling finalize on them. | 102   // These will be deleted by |audio_manager_|'s dtor calling finalize on them. | 
| 95   AudioPlayerStub* audible_player_; | 103   AudioPlayerStub* audible_player_; | 
| 96   AudioPlayerStub* inaudible_player_; | 104   AudioPlayerStub* inaudible_player_; | 
| 97   AudioRecorderStub* recorder_; | 105   AudioRecorderStub* recorder_; | 
| 98 | 106 | 
| 99   AudioType last_received_decode_type_; | 107   AudioType last_received_decode_type_; | 
| 100 | 108 | 
| 101  private: | 109  private: | 
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 142   audio_manager_->StartRecording(INAUDIBLE); | 150   audio_manager_->StartRecording(INAUDIBLE); | 
| 143   recorder_->TriggerDecodeRequest(); | 151   recorder_->TriggerDecodeRequest(); | 
| 144   EXPECT_EQ(BOTH, last_received_decode_type_); | 152   EXPECT_EQ(BOTH, last_received_decode_type_); | 
| 145 | 153 | 
| 146   audio_manager_->StopRecording(AUDIBLE); | 154   audio_manager_->StopRecording(AUDIBLE); | 
| 147   recorder_->TriggerDecodeRequest(); | 155   recorder_->TriggerDecodeRequest(); | 
| 148   EXPECT_EQ(INAUDIBLE, last_received_decode_type_); | 156   EXPECT_EQ(INAUDIBLE, last_received_decode_type_); | 
| 149 } | 157 } | 
| 150 | 158 | 
| 151 }  // namespace copresence | 159 }  // namespace copresence | 
| OLD | NEW | 
|---|