| Index: components/copresence/mediums/audio/audio_manager_unittest.cc
|
| diff --git a/components/copresence/mediums/audio/audio_manager_unittest.cc b/components/copresence/mediums/audio/audio_manager_unittest.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..2041e96f44acd12fc98d3dd3dd546484a67c3427
|
| --- /dev/null
|
| +++ b/components/copresence/mediums/audio/audio_manager_unittest.cc
|
| @@ -0,0 +1,110 @@
|
| +// Copyright 2014 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "components/copresence/mediums/audio/audio_manager.h"
|
| +
|
| +#include "base/bind.h"
|
| +#include "base/message_loop/message_loop.h"
|
| +#include "components/copresence/test/audio_test_support.h"
|
| +#include "media/base/audio_bus.h"
|
| +#include "testing/gmock/include/gmock/gmock.h"
|
| +#include "testing/gtest/include/gtest/gtest.h"
|
| +
|
| +using ::testing::_;
|
| +using ::testing::Le;
|
| +
|
| +namespace copresence {
|
| +
|
| +class AudioManagerTest : public testing::Test {
|
| + public:
|
| + AudioManagerTest()
|
| + : audio_manager_(new AudioManager()),
|
| + audible_player_(new TestAudioPlayer),
|
| + inaudible_player_(new TestAudioPlayer),
|
| + recorder_(new TestAudioRecorder),
|
| + last_received_decode_type_(UNKNOWN) {
|
| + audio_manager_->set_player_for_testing(AUDIBLE, audible_player_);
|
| + audio_manager_->set_player_for_testing(INAUDIBLE, inaudible_player_);
|
| + audio_manager_->set_recorder_for_testing(recorder_);
|
| + audio_manager_->Initialize(
|
| + base::Bind(&AudioManagerTest::DecodeSamples, base::Unretained(this)),
|
| + base::Bind(&AudioManagerTest::EncodeToken, base::Unretained(this)));
|
| + }
|
| + virtual ~AudioManagerTest() {}
|
| +
|
| + void DirectiveAdded() {}
|
| +
|
| + protected:
|
| + void EncodeToken(const std::string& token,
|
| + AudioType audible,
|
| + const AudioManager::SamplesCallback& callback) {
|
| + callback.Run(
|
| + token, audible, CreateRandomAudioRefCounted(0x1337, 1, 0x7331));
|
| + }
|
| +
|
| + void DecodeSamples(AudioType type, const std::string& /* samples */) {
|
| + last_received_decode_type_ = type;
|
| + }
|
| +
|
| + base::MessageLoop message_loop_;
|
| + scoped_ptr<AudioManager> audio_manager_;
|
| +
|
| + // These will be deleted by audio_manager_'s dtor calling finalize on them.
|
| + TestAudioPlayer* audible_player_;
|
| + TestAudioPlayer* inaudible_player_;
|
| + TestAudioRecorder* recorder_;
|
| +
|
| + AudioType last_received_decode_type_;
|
| +
|
| + private:
|
| + DISALLOW_COPY_AND_ASSIGN(AudioManagerTest);
|
| +};
|
| +
|
| +TEST_F(AudioManagerTest, Basic) {
|
| + audio_manager_->StartPlaying(AUDIBLE);
|
| + EXPECT_TRUE(audio_manager_->is_playing_for_testing(AUDIBLE));
|
| + EXPECT_FALSE(audio_manager_->is_playing_for_testing(INAUDIBLE));
|
| +
|
| + audio_manager_->StopPlaying(AUDIBLE);
|
| + EXPECT_FALSE(audio_manager_->is_playing_for_testing(AUDIBLE));
|
| +
|
| + audio_manager_->StartRecording(INAUDIBLE);
|
| + EXPECT_TRUE(audio_manager_->is_recording_for_testing(INAUDIBLE));
|
| + EXPECT_FALSE(audio_manager_->is_recording_for_testing(AUDIBLE));
|
| +
|
| + audio_manager_->StopRecording(INAUDIBLE);
|
| + EXPECT_FALSE(audio_manager_->is_recording_for_testing(INAUDIBLE));
|
| +}
|
| +
|
| +TEST_F(AudioManagerTest, EncodeToken) {
|
| + audio_manager_->StartPlaying(AUDIBLE);
|
| + // No token yet, player shouldn't be playing.
|
| + EXPECT_FALSE(audible_player_->IsPlaying());
|
| +
|
| + audio_manager_->SetToken(INAUDIBLE, "abcd");
|
| + // No *audible* token yet, so player still shouldn't be playing.
|
| + EXPECT_FALSE(audible_player_->IsPlaying());
|
| +
|
| + audio_manager_->SetToken(AUDIBLE, "abcd");
|
| + EXPECT_TRUE(audible_player_->IsPlaying());
|
| +}
|
| +
|
| +TEST_F(AudioManagerTest, Record) {
|
| + recorder_->TriggerDecodeRequest();
|
| + EXPECT_EQ(UNKNOWN, last_received_decode_type_);
|
| +
|
| + audio_manager_->StartRecording(AUDIBLE);
|
| + recorder_->TriggerDecodeRequest();
|
| + EXPECT_EQ(AUDIBLE, last_received_decode_type_);
|
| +
|
| + audio_manager_->StartRecording(INAUDIBLE);
|
| + recorder_->TriggerDecodeRequest();
|
| + EXPECT_EQ(BOTH, last_received_decode_type_);
|
| +
|
| + audio_manager_->StopRecording(AUDIBLE);
|
| + recorder_->TriggerDecodeRequest();
|
| + EXPECT_EQ(INAUDIBLE, last_received_decode_type_);
|
| +}
|
| +
|
| +} // namespace copresence
|
|
|