chromium/media/audio/audio_input_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 <stdint.h>

#include <memory>
#include <vector>

#include "base/command_line.h"
#include "base/environment.h"
#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/memory/raw_ptr.h"
#include "base/message_loop/message_pump_type.h"
#include "base/run_loop.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/test_message_loop.h"
#include "base/threading/platform_thread.h"
#include "build/build_config.h"
#include "media/audio/audio_device_description.h"
#include "media/audio/audio_device_info_accessor_for_tests.h"
#include "media/audio/audio_features.h"
#include "media/audio/audio_io.h"
#include "media/audio/audio_manager.h"
#include "media/audio/audio_unittest_util.h"
#include "media/audio/test_audio_thread.h"
#include "media/base/audio_glitch_info.h"
#include "media/base/media_switches.h"
#include "testing/gtest/include/gtest/gtest.h"

#if BUILDFLAG(IS_ANDROID)
#include "media/audio/android/aaudio_stream_wrapper.h"
#include "media/audio/android/audio_manager_android.h"
#endif

#if BUILDFLAG(IS_FUCHSIA)
#include <fuchsia/media/cpp/fidl_test_base.h>

#include "base/fuchsia/scoped_service_binding.h"
#include "base/fuchsia/test_component_context_for_process.h"
#include "media/fuchsia/audio/fake_audio_capturer.h"
#endif  // BUILDFLAG(IS_FUCHSIA)

namespace media {

#if BUILDFLAG(IS_FUCHSIA)
class FakeAudio : public fuchsia::media::testing::Audio_TestBase {
 public:
  FakeAudio()
      : audio_binding_(test_component_context_.additional_services(), this) {}

  // fuchsia::media::testing::Audio_TestBase
  void CreateAudioCapturer(
      fidl::InterfaceRequest<fuchsia::media::AudioCapturer> request,
      bool is_loopback) override {
    capturer_.push_back(
        std::make_unique<FakeAudioCapturer>(std::move(request)));
  }
  void NotImplemented_(const std::string& name) override {
    FAIL() << "Unexpected call to: " << name;
  }

 private:
  base::TestComponentContextForProcess test_component_context_;
  base::ScopedServiceBinding<fuchsia::media::Audio> audio_binding_;
  std::vector<std::unique_ptr<FakeAudioCapturer>> capturer_;
};
#endif  // BUILDFLAG(IS_FUCHSIA)

// This class allows to find out if the callbacks are occurring as
// expected and if any error has been reported.
class TestInputCallback : public AudioInputStream::AudioInputCallback {};

class AudioInputTest : public testing::TestWithParam<bool> {};

// Test create and close of an AudioInputStream without recording audio.
TEST_P(AudioInputTest, CreateAndClose) {}

// Test create, open and close of an AudioInputStream without recording audio.
// TODO(crbug.com/40262701): This test is failing on ios-blink-dbg-fyi bot.
#if BUILDFLAG(IS_IOS)
#define MAYBE_OpenAndClose
#else
#define MAYBE_OpenAndClose
#endif
TEST_P(AudioInputTest, MAYBE_OpenAndClose) {}

// Test create, open, stop and close of an AudioInputStream without recording.
// TODO(crbug.com/40262701): This test is failing on ios-blink-dbg-fyi bot.
#if BUILDFLAG(IS_IOS)
#define MAYBE_OpenStopAndClose
#else
#define MAYBE_OpenStopAndClose
#endif
TEST_P(AudioInputTest, MAYBE_OpenStopAndClose) {}

// Test a normal recording sequence using an AudioInputStream.
// Very simple test which starts capturing and verifies that recording starts.
// TODO(crbug.com/40262701): This test is failing on ios-blink-dbg-fyi bot.
#if BUILDFLAG(IS_IOS)
#define MAYBE_Record
#else
#define MAYBE_Record
#endif
TEST_P(AudioInputTest, MAYBE_Record) {}

// The test parameter is only relevant on Android. It controls whether or not we
// allow the use of AAudio.
INSTANTIATE_TEST_SUITE_P();

#if BUILDFLAG(IS_ANDROID)
// Run tests with AAudio enabled. On Android P and below, these tests should not
// run, as we only use AAudio on Q+.
INSTANTIATE_TEST_SUITE_P(AAudio, AudioInputTest, testing::Values(true));
#endif

}  // namespace media