Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(153)

Side by Side Diff: components/copresence/handlers/audio/audio_directive_handler_unittest.cc

Issue 704923002: Add polling and audio check to copresence. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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;
62 51
63 directive_handler_.reset(new AudioDirectiveHandlerImpl( 52 directive_handler_.reset(new AudioDirectiveHandlerImpl(
64 make_scoped_ptr<AudioManager>(manager_ptr_), 53 make_scoped_ptr<AudioManager>(manager_ptr_),
65 make_scoped_ptr<base::Timer>(timer_ptr_), 54 make_scoped_ptr<base::Timer>(timer_ptr_),
66 make_scoped_refptr(new TickClockRefCounted(clock_ptr_)))); 55 make_scoped_refptr(new TickClockRefCounted(clock_ptr_))));
67 directive_handler_->Initialize(base::Bind(&DecodeSamples), 56 directive_handler_->Initialize(NULL, TokensCallback());
Charlie 2014/11/06 17:28:22 Pass a StubWhispernetClient here instead (owned by
rkc 2014/11/06 19:58:24 Why do I need to pass in a Stub to DCHECK in the A
Charlie 2014/11/06 21:53:14 In the real implementation, WhispernetClient shoul
rkc 2014/11/06 21:58:33 We will never get to the point that Whispernet wil
68 base::Bind(&EncodeToken));
69 } 57 }
70 ~AudioDirectiveHandlerTest() override {} 58 ~AudioDirectiveHandlerTest() override {}
71 59
72 protected: 60 protected:
73 TokenInstruction CreateTransmitInstruction(const std::string& token, 61 TokenInstruction CreateTransmitInstruction(const std::string& token,
74 bool audible) { 62 bool audible) {
75 TokenInstruction instruction; 63 TokenInstruction instruction;
76 instruction.set_token_instruction_type(TRANSMIT); 64 instruction.set_token_instruction_type(TRANSMIT);
77 instruction.set_token_id(token); 65 instruction.set_token_id(token);
78 instruction.set_medium(audible ? AUDIO_AUDIBLE_DTMF 66 instruction.set_medium(audible ? AUDIO_AUDIBLE_DTMF
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 180
193 // We are now at base + 2676ms. 181 // We are now at base + 2676ms.
194 timer_ptr_->Fire(); 182 timer_ptr_->Fire();
195 EXPECT_FALSE(IsRecording(AUDIBLE)); 183 EXPECT_FALSE(IsRecording(AUDIBLE));
196 } 184 }
197 185
198 // TODO(rkc): Write more tests that check more convoluted sequences of 186 // TODO(rkc): Write more tests that check more convoluted sequences of
199 // transmits/receives. 187 // transmits/receives.
200 188
201 } // namespace copresence 189 } // namespace copresence
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698