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

Side by Side Diff: components/copresence/mediums/audio/audio_manager_unittest.cc

Issue 637223011: Redesign the copresence audio handlers. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git/+/master
Patch Set: Created 6 years, 2 months 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
(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/test/audio_test_support.h"
10 #include "media/base/audio_bus.h"
11 #include "testing/gmock/include/gmock/gmock.h"
12 #include "testing/gtest/include/gtest/gtest.h"
13
14 using ::testing::_;
15 using ::testing::Le;
16
17 namespace copresence {
18
19 class AudioManagerTest : public testing::Test {
20 public:
21 AudioManagerTest()
22 : audio_manager_(new AudioManager()),
23 audible_player_(new TestAudioPlayer),
24 inaudible_player_(new TestAudioPlayer),
25 recorder_(new TestAudioRecorder),
26 last_received_decode_type_(UNKNOWN) {
27 audio_manager_->set_player_for_testing(AUDIBLE, audible_player_);
28 audio_manager_->set_player_for_testing(INAUDIBLE, inaudible_player_);
29 audio_manager_->set_recorder_for_testing(recorder_);
30 audio_manager_->Initialize(
31 base::Bind(&AudioManagerTest::DecodeSamples, base::Unretained(this)),
32 base::Bind(&AudioManagerTest::EncodeToken, base::Unretained(this)));
33 }
34 virtual ~AudioManagerTest() {}
35
36 void DirectiveAdded() {}
37
38 protected:
39 void EncodeToken(const std::string& token,
40 AudioType audible,
41 const AudioManager::SamplesCallback& callback) {
42 callback.Run(
43 token, audible, CreateRandomAudioRefCounted(0x1337, 1, 0x7331));
44 }
45
46 void DecodeSamples(AudioType type, const std::string& /* samples */) {
47 last_received_decode_type_ = type;
48 }
49
50 base::MessageLoop message_loop_;
51 scoped_ptr<AudioManager> audio_manager_;
52
53 // These will be deleted by audio_manager_'s dtor calling finalize on them.
54 TestAudioPlayer* audible_player_;
55 TestAudioPlayer* inaudible_player_;
56 TestAudioRecorder* recorder_;
57
58 AudioType last_received_decode_type_;
59
60 private:
61 DISALLOW_COPY_AND_ASSIGN(AudioManagerTest);
62 };
63
64 TEST_F(AudioManagerTest, Basic) {
65 audio_manager_->StartPlaying(AUDIBLE);
66 EXPECT_TRUE(audio_manager_->is_playing_for_testing(AUDIBLE));
67 EXPECT_FALSE(audio_manager_->is_playing_for_testing(INAUDIBLE));
68
69 audio_manager_->StopPlaying(AUDIBLE);
70 EXPECT_FALSE(audio_manager_->is_playing_for_testing(AUDIBLE));
71
72 audio_manager_->StartRecording(INAUDIBLE);
73 EXPECT_TRUE(audio_manager_->is_recording_for_testing(INAUDIBLE));
74 EXPECT_FALSE(audio_manager_->is_recording_for_testing(AUDIBLE));
75
76 audio_manager_->StopRecording(INAUDIBLE);
77 EXPECT_FALSE(audio_manager_->is_recording_for_testing(INAUDIBLE));
78 }
79
80 TEST_F(AudioManagerTest, EncodeToken) {
81 audio_manager_->StartPlaying(AUDIBLE);
82 // No token yet, player shouldn't be playing.
83 EXPECT_FALSE(audible_player_->IsPlaying());
84
85 audio_manager_->SetToken(INAUDIBLE, "abcd");
86 // No *audible* token yet, so player still shouldn't be playing.
87 EXPECT_FALSE(audible_player_->IsPlaying());
88
89 audio_manager_->SetToken(AUDIBLE, "abcd");
90 EXPECT_TRUE(audible_player_->IsPlaying());
91 }
92
93 TEST_F(AudioManagerTest, Record) {
94 recorder_->TriggerDecodeRequest();
95 EXPECT_EQ(UNKNOWN, last_received_decode_type_);
96
97 audio_manager_->StartRecording(AUDIBLE);
98 recorder_->TriggerDecodeRequest();
99 EXPECT_EQ(AUDIBLE, last_received_decode_type_);
100
101 audio_manager_->StartRecording(INAUDIBLE);
102 recorder_->TriggerDecodeRequest();
103 EXPECT_EQ(BOTH, last_received_decode_type_);
104
105 audio_manager_->StopRecording(AUDIBLE);
106 recorder_->TriggerDecodeRequest();
107 EXPECT_EQ(INAUDIBLE, last_received_decode_type_);
108 }
109
110 } // namespace copresence
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698