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

Unified Diff: components/audio_modem/modem_unittest.cc

Issue 2131993002: Delete the audio modem and copresence private APIs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@eol
Patch Set: Sync again Created 4 years, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/audio_modem/modem_impl.cc ('k') | components/audio_modem/public/audio_modem_types.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/audio_modem/modem_unittest.cc
diff --git a/components/audio_modem/modem_unittest.cc b/components/audio_modem/modem_unittest.cc
deleted file mode 100644
index b18c7f85f57f6ac4f1c18dd66ab9500841f37d91..0000000000000000000000000000000000000000
--- a/components/audio_modem/modem_unittest.cc
+++ /dev/null
@@ -1,155 +0,0 @@
-// Copyright 2015 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/audio_modem/public/modem.h"
-
-#include <memory>
-#include <vector>
-
-#include "base/bind.h"
-#include "base/macros.h"
-#include "base/message_loop/message_loop.h"
-#include "components/audio_modem/audio_player.h"
-#include "components/audio_modem/audio_recorder.h"
-#include "components/audio_modem/modem_impl.h"
-#include "components/audio_modem/test/random_samples.h"
-#include "components/audio_modem/test/stub_whispernet_client.h"
-#include "media/base/audio_bus.h"
-#include "testing/gtest/include/gtest/gtest.h"
-
-namespace audio_modem {
-
-class AudioPlayerStub final : public AudioPlayer {
- public:
- AudioPlayerStub() : is_playing_(false) {}
- ~AudioPlayerStub() override {}
-
- // AudioPlayer overrides:
- void Initialize() override {}
- void Play(const scoped_refptr<media::AudioBusRefCounted>&) override {
- is_playing_ = true;
- }
- void Stop() override { is_playing_ = false; }
- void Finalize() override { delete this; }
-
- bool IsPlaying() { return is_playing_; }
-
- private:
- bool is_playing_;
- DISALLOW_COPY_AND_ASSIGN(AudioPlayerStub);
-};
-
-class AudioRecorderStub final : public AudioRecorder {
- public:
- AudioRecorderStub() : is_recording_(false) {}
- ~AudioRecorderStub() override {}
-
- // AudioRecorder overrides:
- void Initialize(const RecordedSamplesCallback& cb) override { cb_ = cb; }
- void Record() override { is_recording_ = true; }
- void Stop() override { is_recording_ = false; }
- void Finalize() override { delete this; }
-
- bool IsRecording() { return is_recording_; }
-
- void TriggerDecodeRequest() {
- if (!cb_.is_null())
- cb_.Run(std::string(0x1337, 'a'));
- }
-
- private:
- RecordedSamplesCallback cb_;
- bool is_recording_;
-
- DISALLOW_COPY_AND_ASSIGN(AudioRecorderStub);
-};
-
-class ModemTest : public testing::Test {
- public:
- ModemTest()
- : modem_(new ModemImpl),
- audible_player_(new AudioPlayerStub),
- inaudible_player_(new AudioPlayerStub),
- recorder_(new AudioRecorderStub),
- last_received_decode_type_(AUDIO_TYPE_UNKNOWN) {
- std::vector<AudioToken> tokens;
- tokens.push_back(AudioToken("abcdef", true));
- tokens.push_back(AudioToken("123456", false));
- client_.reset(new StubWhispernetClient(
- CreateRandomAudioRefCounted(0x123, 1, 0x321), tokens));
-
- // TODO(ckehoe): Pass these into the Modem constructor instead.
- modem_->set_player_for_testing(AUDIBLE, audible_player_);
- modem_->set_player_for_testing(INAUDIBLE, inaudible_player_);
- modem_->set_recorder_for_testing(recorder_);
- modem_->Initialize(
- client_.get(),
- base::Bind(&ModemTest::GetTokens, base::Unretained(this)));
- }
-
- ~ModemTest() override {}
-
- protected:
- void GetTokens(const std::vector<AudioToken>& tokens) {
- last_received_decode_type_ = AUDIO_TYPE_UNKNOWN;
- for (const auto& token : tokens) {
- if (token.audible && last_received_decode_type_ == INAUDIBLE) {
- last_received_decode_type_ = BOTH;
- } else if (!token.audible && last_received_decode_type_ == AUDIBLE) {
- last_received_decode_type_ = BOTH;
- } else if (token.audible) {
- last_received_decode_type_ = AUDIBLE;
- } else {
- last_received_decode_type_ = INAUDIBLE;
- }
- }
- }
-
- base::MessageLoop message_loop_;
- // This order is important. The WhispernetClient needs to outlive the Modem.
- std::unique_ptr<WhispernetClient> client_;
- std::unique_ptr<ModemImpl> modem_;
-
- // These will be deleted by the Modem's destructor calling finalize on them.
- AudioPlayerStub* audible_player_;
- AudioPlayerStub* inaudible_player_;
- AudioRecorderStub* recorder_;
-
- AudioType last_received_decode_type_;
-
- private:
- DISALLOW_COPY_AND_ASSIGN(ModemTest);
-};
-
-TEST_F(ModemTest, EncodeToken) {
- modem_->StartPlaying(AUDIBLE);
- // No token yet, player shouldn't be playing.
- EXPECT_FALSE(audible_player_->IsPlaying());
-
- modem_->SetToken(INAUDIBLE, "abcd");
- // No *audible* token yet, so player still shouldn't be playing.
- EXPECT_FALSE(audible_player_->IsPlaying());
-
- modem_->SetToken(AUDIBLE, "abcd");
- EXPECT_TRUE(audible_player_->IsPlaying());
-}
-
-TEST_F(ModemTest, Record) {
- recorder_->TriggerDecodeRequest();
- EXPECT_EQ(AUDIO_TYPE_UNKNOWN, last_received_decode_type_);
-
- modem_->StartRecording(AUDIBLE);
- recorder_->TriggerDecodeRequest();
- EXPECT_EQ(AUDIBLE, last_received_decode_type_);
-
- modem_->StartRecording(INAUDIBLE);
- recorder_->TriggerDecodeRequest();
- EXPECT_EQ(BOTH, last_received_decode_type_);
-
- modem_->StopRecording(AUDIBLE);
- recorder_->TriggerDecodeRequest();
- EXPECT_EQ(INAUDIBLE, last_received_decode_type_);
-}
-
-} // namespace audio_modem
« no previous file with comments | « components/audio_modem/modem_impl.cc ('k') | components/audio_modem/public/audio_modem_types.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698