OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "components/copresence/mediums/audio/audio_manager.h" | |
6 | |
7 #include "base/bind.h" | |
8 #include "base/message_loop/message_loop.h" | |
9 #include "components/copresence/mediums/audio/audio_manager_impl.h" | |
10 #include "components/copresence/mediums/audio/audio_player_stub.h" | |
11 #include "components/copresence/mediums/audio/audio_recorder_stub.h" | |
12 #include "components/copresence/test/audio_test_support.h" | |
13 #include "media/base/audio_bus.h" | |
14 #include "testing/gmock/include/gmock/gmock.h" | |
15 #include "testing/gtest/include/gtest/gtest.h" | |
16 | |
17 using ::testing::_; | |
18 using ::testing::Le; | |
19 | |
20 namespace copresence { | |
21 | |
22 class AudioManagerTest : public testing::Test { | |
23 public: | |
24 AudioManagerTest() | |
25 : audio_manager_(new AudioManagerImpl()), | |
26 audible_player_(new AudioPlayerStub), | |
27 inaudible_player_(new AudioPlayerStub), | |
28 recorder_(new AudioRecorderStub), | |
29 last_received_decode_type_(UNKNOWN) { | |
30 audio_manager_->set_player_for_testing(AUDIBLE, audible_player_); | |
31 audio_manager_->set_player_for_testing(INAUDIBLE, inaudible_player_); | |
32 audio_manager_->set_recorder_for_testing(recorder_); | |
33 audio_manager_->Initialize( | |
34 base::Bind(&AudioManagerTest::DecodeSamples, base::Unretained(this)), | |
35 base::Bind(&AudioManagerTest::EncodeToken, base::Unretained(this))); | |
36 } | |
37 virtual ~AudioManagerTest() {} | |
38 | |
39 void DirectiveAdded() {} | |
Daniel Erat
2014/10/22 16:34:35
did you mean to delete this too?
rkc
2014/10/22 18:21:48
Done.
| |
40 | |
41 protected: | |
42 void EncodeToken(const std::string& token, | |
43 AudioType audible, | |
44 const AudioManager::SamplesCallback& callback) { | |
45 callback.Run( | |
46 token, audible, CreateRandomAudioRefCounted(0x1337, 1, 0x7331)); | |
47 } | |
48 | |
49 void DecodeSamples(AudioType type, const std::string& /* samples */) { | |
50 last_received_decode_type_ = type; | |
51 } | |
52 | |
53 base::MessageLoop message_loop_; | |
54 scoped_ptr<AudioManagerImpl> audio_manager_; | |
55 | |
56 // These will be deleted by audio_manager_'s dtor calling finalize on them. | |
Daniel Erat
2014/10/22 16:34:35
nit: |audio_manager_|
rkc
2014/10/22 18:21:48
Done.
| |
57 AudioPlayerStub* audible_player_; | |
58 AudioPlayerStub* inaudible_player_; | |
59 AudioRecorderStub* recorder_; | |
60 | |
61 AudioType last_received_decode_type_; | |
62 | |
63 private: | |
64 DISALLOW_COPY_AND_ASSIGN(AudioManagerTest); | |
65 }; | |
66 | |
67 TEST_F(AudioManagerTest, Basic) { | |
68 audio_manager_->StartPlaying(AUDIBLE); | |
69 EXPECT_TRUE(audio_manager_->IsPlaying(AUDIBLE)); | |
70 EXPECT_FALSE(audio_manager_->IsPlaying(INAUDIBLE)); | |
71 | |
72 audio_manager_->StopPlaying(AUDIBLE); | |
73 EXPECT_FALSE(audio_manager_->IsPlaying(AUDIBLE)); | |
74 | |
75 audio_manager_->StartRecording(INAUDIBLE); | |
76 EXPECT_TRUE(audio_manager_->IsRecording(INAUDIBLE)); | |
77 EXPECT_FALSE(audio_manager_->IsRecording(AUDIBLE)); | |
78 | |
79 audio_manager_->StopRecording(INAUDIBLE); | |
80 EXPECT_FALSE(audio_manager_->IsRecording(INAUDIBLE)); | |
81 } | |
82 | |
83 TEST_F(AudioManagerTest, EncodeToken) { | |
84 audio_manager_->StartPlaying(AUDIBLE); | |
85 // No token yet, player shouldn't be playing. | |
86 EXPECT_FALSE(audible_player_->IsPlaying()); | |
87 | |
88 audio_manager_->SetToken(INAUDIBLE, "abcd"); | |
89 // No *audible* token yet, so player still shouldn't be playing. | |
90 EXPECT_FALSE(audible_player_->IsPlaying()); | |
91 | |
92 audio_manager_->SetToken(AUDIBLE, "abcd"); | |
93 EXPECT_TRUE(audible_player_->IsPlaying()); | |
94 } | |
95 | |
96 TEST_F(AudioManagerTest, Record) { | |
97 recorder_->TriggerDecodeRequest(); | |
98 EXPECT_EQ(UNKNOWN, last_received_decode_type_); | |
99 | |
100 audio_manager_->StartRecording(AUDIBLE); | |
101 recorder_->TriggerDecodeRequest(); | |
102 EXPECT_EQ(AUDIBLE, last_received_decode_type_); | |
103 | |
104 audio_manager_->StartRecording(INAUDIBLE); | |
105 recorder_->TriggerDecodeRequest(); | |
106 EXPECT_EQ(BOTH, last_received_decode_type_); | |
107 | |
108 audio_manager_->StopRecording(AUDIBLE); | |
109 recorder_->TriggerDecodeRequest(); | |
110 EXPECT_EQ(INAUDIBLE, last_received_decode_type_); | |
111 } | |
112 | |
113 } // namespace copresence | |
OLD | NEW |