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 "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/memory/scoped_ptr.h" | 6 #include "base/memory/scoped_ptr.h" |
| 7 #include "base/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
| 8 #include "base/test/simple_test_tick_clock.h" | 8 #include "base/test/simple_test_tick_clock.h" |
| 9 #include "base/timer/mock_timer.h" | 9 #include "base/timer/mock_timer.h" |
| 10 #include "components/copresence/handlers/audio/audio_directive_handler_impl.h" | 10 #include "components/copresence/handlers/audio/audio_directive_handler_impl.h" |
| 11 #include "components/copresence/handlers/audio/tick_clock_ref_counted.h" | 11 #include "components/copresence/handlers/audio/tick_clock_ref_counted.h" |
| 12 #include "components/copresence/mediums/audio/audio_manager.h" | 12 #include "components/copresence/mediums/audio/audio_manager.h" |
| 13 #include "components/copresence/proto/data.pb.h" | 13 #include "components/copresence/proto/data.pb.h" |
| 14 #include "components/copresence/test/audio_test_support.h" | 14 #include "components/copresence/test/audio_test_support.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 namespace { | |
| 20 | |
| 21 // Callback stubs to pass into the directive handler. | |
| 22 void DecodeSamples(AudioType, const std::string&) { | |
| 23 } | |
| 24 void EncodeToken(const std::string&, | |
| 25 AudioType, | |
| 26 const AudioManager::SamplesCallback&) { | |
| 27 } | |
| 28 | |
| 29 } // namespace | |
| 30 | |
| 31 class AudioManagerStub final : public AudioManager { | 19 class AudioManagerStub final : public AudioManager { |
| 32 public: | 20 public: |
| 33 AudioManagerStub() {} | 21 AudioManagerStub() {} |
| 34 ~AudioManagerStub() override {} | 22 ~AudioManagerStub() override {} |
| 35 | 23 |
| 36 // AudioManager overrides: | 24 // AudioManager overrides: |
| 37 void Initialize(const DecodeSamplesCallback& decode_cb, | 25 void Initialize(WhispernetClient* whispernet_client, |
| 38 const EncodeTokenCallback& encode_cb) override {} | 26 const TokensCallback& tokens_cb) override {} |
| 39 void StartPlaying(AudioType type) override { playing_[type] = true; } | 27 void StartPlaying(AudioType type) override { playing_[type] = true; } |
| 40 void StopPlaying(AudioType type) override { playing_[type] = false; } | 28 void StopPlaying(AudioType type) override { playing_[type] = false; } |
| 41 void StartRecording(AudioType type) override { recording_[type] = true; } | 29 void StartRecording(AudioType type) override { recording_[type] = true; } |
| 42 void StopRecording(AudioType type) override { recording_[type] = false; } | 30 void StopRecording(AudioType type) override { recording_[type] = false; } |
| 43 void SetToken(AudioType type, const std::string& url_unsafe_token) override {} | 31 void SetToken(AudioType type, const std::string& url_unsafe_token) override {} |
| 44 const std::string GetToken(AudioType type) override { return std::string(); } | 32 const std::string GetToken(AudioType type) override { return std::string(); } |
| 45 bool IsRecording(AudioType type) override { return recording_[type]; } | 33 bool IsRecording(AudioType type) override { return recording_[type]; } |
| 46 bool IsPlaying(AudioType type) override { return playing_[type]; } | 34 bool IsPlaying(AudioType type) override { return playing_[type]; } |
| 35 bool IsPlayingTokenHeard(AudioType type) override { return false; } | |
| 47 | 36 |
| 48 private: | 37 private: |
| 49 // Indexed using enum AudioType. | 38 // Indexed using enum AudioType. |
| 50 bool playing_[2]; | 39 bool playing_[2]; |
| 51 bool recording_[2]; | 40 bool recording_[2]; |
| 52 | 41 |
| 53 DISALLOW_COPY_AND_ASSIGN(AudioManagerStub); | 42 DISALLOW_COPY_AND_ASSIGN(AudioManagerStub); |
| 54 }; | 43 }; |
| 55 | 44 |
| 56 class AudioDirectiveHandlerTest : public testing::Test { | 45 class AudioDirectiveHandlerTest : public testing::Test { |
| 57 public: | 46 public: |
| 58 AudioDirectiveHandlerTest() { | 47 AudioDirectiveHandlerTest() { |
| 59 manager_ptr_ = new AudioManagerStub; | 48 manager_ptr_ = new AudioManagerStub; |
| 60 timer_ptr_ = new base::MockTimer(false, false); | 49 timer_ptr_ = new base::MockTimer(false, false); |
| 61 clock_ptr_ = new base::SimpleTestTickClock; | 50 clock_ptr_ = new base::SimpleTestTickClock; |
| 51 // whispernet_client_.reset(new StubWhispernetClient); | |
|
xiyuan
2014/11/06 21:27:50
nit: Remove?
rkc
2014/11/06 21:45:05
Done.
| |
| 62 | 52 |
| 63 directive_handler_.reset(new AudioDirectiveHandlerImpl( | 53 directive_handler_.reset(new AudioDirectiveHandlerImpl( |
| 64 make_scoped_ptr<AudioManager>(manager_ptr_), | 54 make_scoped_ptr<AudioManager>(manager_ptr_), |
| 65 make_scoped_ptr<base::Timer>(timer_ptr_), | 55 make_scoped_ptr<base::Timer>(timer_ptr_), |
| 66 make_scoped_refptr(new TickClockRefCounted(clock_ptr_)))); | 56 make_scoped_refptr(new TickClockRefCounted(clock_ptr_)))); |
| 67 directive_handler_->Initialize(base::Bind(&DecodeSamples), | 57 directive_handler_->Initialize(nullptr, TokensCallback()); |
| 68 base::Bind(&EncodeToken)); | |
| 69 } | 58 } |
| 70 ~AudioDirectiveHandlerTest() override {} | 59 ~AudioDirectiveHandlerTest() override {} |
| 71 | 60 |
| 72 protected: | 61 protected: |
| 73 TokenInstruction CreateTransmitInstruction(const std::string& token, | 62 TokenInstruction CreateTransmitInstruction(const std::string& token, |
| 74 bool audible) { | 63 bool audible) { |
| 75 TokenInstruction instruction; | 64 TokenInstruction instruction; |
| 76 instruction.set_token_instruction_type(TRANSMIT); | 65 instruction.set_token_instruction_type(TRANSMIT); |
| 77 instruction.set_token_id(token); | 66 instruction.set_token_id(token); |
| 78 instruction.set_medium(audible ? AUDIO_AUDIBLE_DTMF | 67 instruction.set_medium(audible ? AUDIO_AUDIBLE_DTMF |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 192 | 181 |
| 193 // We are now at base + 2676ms. | 182 // We are now at base + 2676ms. |
| 194 timer_ptr_->Fire(); | 183 timer_ptr_->Fire(); |
| 195 EXPECT_FALSE(IsRecording(AUDIBLE)); | 184 EXPECT_FALSE(IsRecording(AUDIBLE)); |
| 196 } | 185 } |
| 197 | 186 |
| 198 // TODO(rkc): Write more tests that check more convoluted sequences of | 187 // TODO(rkc): Write more tests that check more convoluted sequences of |
| 199 // transmits/receives. | 188 // transmits/receives. |
| 200 | 189 |
| 201 } // namespace copresence | 190 } // namespace copresence |
| OLD | NEW |