chromium/services/audio/input_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/input_controller.h"

#include <memory>
#include <string_view>
#include <utility>

#include "base/run_loop.h"
#include "base/task/sequenced_task_runner.h"
#include "base/test/bind.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/task_environment.h"
#include "base/time/time.h"
#include "media/audio/aecdump_recording_manager.h"
#include "media/audio/audio_io.h"
#include "media/audio/audio_manager.h"
#include "media/audio/fake_audio_input_stream.h"
#include "media/audio/fake_audio_log_factory.h"
#include "media/audio/fake_audio_manager.h"
#include "media/audio/mock_audio_manager.h"
#include "media/audio/test_audio_thread.h"
#include "media/base/audio_glitch_info.h"
#include "media/base/audio_processing.h"
#include "media/base/media_switches.h"
#include "media/base/user_input_monitor.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "services/audio/device_output_listener.h"
#include "services/audio/processing_audio_fifo.h"
#include "services/audio/reference_output.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"

_;
AtLeast;
Exactly;
InvokeWithoutArgs;
NiceMock;
NotNull;
StrictMock;

namespace audio {

namespace {

const int kSampleRate =;
const media::ChannelLayoutConfig kChannelLayoutConfig =;
const int kSamplesPerPacket =;

// InputController will poll once every second, so wait at most a bit
// more than that for the callbacks.
constexpr base::TimeDelta kOnMutePollInterval =;

enum class ChromeWideEchoCancellationSetting {};

enum class DecreaseFifoSizeSetting {};

#if BUILDFLAG(CHROME_WIDE_ECHO_CANCELLATION)
const std::string kFifoSizeParameter =;
#endif

}  // namespace

class MockInputControllerEventHandler : public InputController::EventHandler {};

class MockSyncWriter : public InputController::SyncWriter {};

class MockUserInputMonitor : public media::UserInputMonitor {};

class MockAudioInputStream : public media::AudioInputStream {};

enum class AudioManagerType {};

template <base::test::TaskEnvironment::TimeSource TimeSource =
              base::test::TaskEnvironment::TimeSource::MOCK_TIME,
          AudioManagerType audio_manager_type = AudioManagerType::FAKE>
class TimeSourceInputControllerTest
    : public ::testing::TestWithParam<
          std::tuple<ChromeWideEchoCancellationSetting,
                     DecreaseFifoSizeSetting>> {};

auto test_name_generator =::string name_suffix =;

SystemTimeInputControllerTest;
InputControllerTest;
InputControllerTestWithMockAudioManager;

TEST_P(InputControllerTest, CreateAndCloseWithoutRecording) {}

// Test a normal call sequence of create, record and close.
// Note: Must use system time as MOCK_TIME does not support the threads created
// by the FakeAudioInputStream. The callbacks to sync_writer_.Write() are on
// that thread, and thus we must use SYSTEM_TIME.
TEST_P(SystemTimeInputControllerTest, CreateRecordAndClose) {}

TEST_P(InputControllerTestWithMockAudioManager, PropagatesGlitchInfo) {}

TEST_P(InputControllerTest, RecordTwice) {}

TEST_P(InputControllerTest, CloseTwice) {}

// Test that InputController sends OnMute callbacks properly.
TEST_P(InputControllerTest, TestOnmutedCallbackInitiallyUnmuted) {}

TEST_P(InputControllerTest, TestOnmutedCallbackInitiallyMuted) {}

auto test_values =;

INSTANTIATE_TEST_SUITE_P();

INSTANTIATE_TEST_SUITE_P();

INSTANTIATE_TEST_SUITE_P();

#if BUILDFLAG(CHROME_WIDE_ECHO_CANCELLATION)
class InputControllerTestHelper {};

class MockDeviceOutputListener : public DeviceOutputListener {};

template <base::test::TaskEnvironment::TimeSource TimeSource =
              base::test::TaskEnvironment::TimeSource::MOCK_TIME>
class TimeSourceInputControllerTestWithDeviceListener
    : public TimeSourceInputControllerTest<TimeSource> {};

SystemTimeInputControllerTestWithDeviceListener;
InputControllerTestWithDeviceListener;

TEST_P(InputControllerTestWithDeviceListener,
       CreateWithAudioProcessingConfig_WithSomeEffectsEnabled) {}

TEST_P(InputControllerTestWithDeviceListener,
       CreateWithAudioProcessingConfig_WithoutEnablingEffects) {}

TEST_P(InputControllerTestWithDeviceListener,
       CreateWithAudioProcessingConfig_VerifyFifoUsage) {}

TEST_P(
    InputControllerTestWithDeviceListener,
    CreateWithAudioProcessingConfig_DoesNotListenForPlayoutReferenceIfNotRequired) {}

TEST_P(InputControllerTestWithDeviceListener, RecordBeforeSetOutputForAec) {}

TEST_P(InputControllerTestWithDeviceListener, RecordAfterSetOutputForAec) {}

TEST_P(InputControllerTestWithDeviceListener, FifoSize) {}

TEST_P(InputControllerTestWithDeviceListener, ChangeOutputForAec) {}

// Test a normal call sequence of create, record and close when audio processing
// is enabled.
// Note: Must use system time as MOCK_TIME does not support the threads created
// by the FakeAudioInputStream. The callbacks to sync_writer_.Write() are on
// that thread, and thus we must use SYSTEM_TIME.
TEST_P(SystemTimeInputControllerTestWithDeviceListener, CreateRecordAndClose) {}

INSTANTIATE_TEST_SUITE_P();

INSTANTIATE_TEST_SUITE_P();

#endif  // BUILDFLAG(CHROME_WIDE_ECHO_CANCELLATION)

}  // namespace audio