chromium/services/audio/output_controller_unittest.cc

// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "services/audio/output_controller.h"

#include <stdint.h>

#include <memory>
#include <optional>
#include <string_view>
#include <vector>

#include "base/barrier_closure.h"
#include "base/check.h"
#include "base/environment.h"
#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/location.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/ref_counted.h"
#include "base/notreached.h"
#include "base/run_loop.h"
#include "base/task/single_thread_task_runner.h"
#include "base/test/gmock_callback_support.h"
#include "base/test/task_environment.h"
#include "base/test/test_message_loop.h"
#include "base/threading/thread.h"
#include "base/time/time.h"
#include "base/unguessable_token.h"
#include "media/audio/audio_device_description.h"
#include "media/audio/fake_audio_log_factory.h"
#include "media/audio/fake_audio_manager.h"
#include "media/audio/test_audio_thread.h"
#include "media/base/audio_bus.h"
#include "media/base/audio_parameters.h"
#include "services/audio/loopback_group_member.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"

_;
AtLeast;
Invoke;
Mock;
NiceMock;
Return;
StrictMock;

AudioBus;
AudioManager;
AudioOutputStream;
AudioParameters;

RunClosure;
RunOnceClosure;

namespace audio {
namespace {

constexpr int kSampleRate =;
const media::ChannelLayoutConfig kChannelLayoutConfig =;
constexpr int kSamplesPerPacket =;
constexpr double kTestVolume =;
constexpr float kBufferNonZeroData =;

AudioParameters GetTestParams() {}

class MockOutputControllerEventHandler : public OutputController::EventHandler {};

class MockOutputControllerSyncReader : public OutputController::SyncReader {};

class MockStreamFactory {};

// Wraps an AudioOutputStream instance, calling DidXYZ() mock methods for test
// verification of controller behavior. If a null AudioOutputStream pointer is
// provided to the constructor, a "data pump" thread will be run between the
// Start() and Stop() calls to simulate an AudioOutputStream not owned by the
// AudioManager.
class MockAudioOutputStream : public AudioOutputStream,
                              public AudioOutputStream::AudioSourceCallback {};

class MockSnooper : public Snoopable::Snooper {};

// A FakeAudioManager that produces MockAudioOutputStreams, and tracks the last
// stream that was created and the last stream that was closed.
class AudioManagerForControllerTest final : public media::FakeAudioManager {};

ACTION(PopulateBuffer) {}

class OutputControllerTest : public ::testing::Test {};

TEST_F(OutputControllerTest, CreateAndClose) {}

TEST_F(OutputControllerTest, PlayAndClose) {}

TEST_F(OutputControllerTest, PlayPauseClose) {}

TEST_F(OutputControllerTest, PlayPausePlayClose) {}

TEST_F(OutputControllerTest, PlayDeviceChangeClose) {}

TEST_F(OutputControllerTest, PlayDeviceChangeDeviceChangeClose) {}

TEST_F(OutputControllerTest, PlayPauseDeviceChangeClose) {}

TEST_F(OutputControllerTest, CreateDeviceChangeClose) {}

TEST_F(OutputControllerTest, SwitchDeviceClose) {}

TEST_F(OutputControllerTest, SwitchDevicePlayClose) {}

TEST_F(OutputControllerTest, PlayPauseSwitchDevicePlayClose) {}

TEST_F(OutputControllerTest, PlaySwitchDeviceSwitchDevice2Close) {}

TEST_F(OutputControllerTest, PlaySwitchDevicePausePlayPauseClose) {}

TEST_F(OutputControllerTest, PlaySwitchDeviceSwitchDeviceClose) {}

// Syntactic convenience.
double GetStreamVolume(AudioOutputStream* stream) {}

// Tests that muting before the stream is created will result in only the
// "muting stream" being created, and not any local playout streams (that might
// possibly cause an audible blip).
TEST_F(OutputControllerTest, MuteCreatePlayClose) {}

// Tests that a local playout stream is shut-down and replaced with a "muting
// stream" if StartMuting() is called after playback begins.
TEST_F(OutputControllerTest, CreatePlayMuteClose) {}

// Tests that the "muting stream" is shut down and replaced with the normal
// playout stream after StopMuting() is called.
TEST_F(OutputControllerTest, MutePlayUnmuteClose) {}

TEST_F(OutputControllerTest, SnoopCreatePlayStopClose) {}

TEST_F(OutputControllerTest, CreatePlaySnoopStopClose) {}

TEST_F(OutputControllerTest, CreatePlaySnoopCloseStop) {}

TEST_F(OutputControllerTest, TwoSnoopers_StartAtDifferentTimes) {}

TEST_F(OutputControllerTest, TwoSnoopers_StopAtDifferentTimes) {}

TEST_F(OutputControllerTest, SnoopWhileMuting) {}

TEST_F(OutputControllerTest, FlushWhenStreamIsPlayingTriggersError) {}

TEST_F(OutputControllerTest, FlushesWhenStreamIsNotPlaying) {}

TEST_F(OutputControllerTest, FlushesAfterDeviceChange) {}

class MockAudioOutputStreamForMixing : public AudioOutputStream {};

TEST(OutputControllerMixingTest,
     ControllerUsesProvidedCManagedDeviceOutputStreamCreateCallbackCorrectly) {}

TEST(OutputControllerMixingTest,
     ControllerForwardsMixingFlagAndGlitchesToSyncReader) {}

TEST(OutputControllerMixingTest,
     SwitchDeviceIdManagedDeviceOutputStreamCreateCallbackCorrectly) {}

}  // namespace
}  // namespace audio