chromium/third_party/blink/renderer/modules/mediastream/media_stream_constraints_util_audio_test.cc

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

#include "third_party/blink/renderer/modules/mediastream/media_stream_constraints_util_audio.h"

#include <algorithm>
#include <cmath>
#include <memory>
#include <string>
#include <utility>

#include "base/containers/contains.h"
#include "base/functional/callback_helpers.h"
#include "base/memory/raw_ptr.h"
#include "base/test/scoped_feature_list.h"
#include "base/types/optional_util.h"
#include "build/build_config.h"
#include "media/base/audio_parameters.h"
#include "media/base/media_switches.h"
#include "media/media_buildflags.h"
#include "media/webrtc/constants.h"
#include "media/webrtc/webrtc_features.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/mojom/mediastream/media_stream.mojom-blink-forward.h"
#include "third_party/blink/public/platform/modules/mediastream/web_platform_media_stream_source.h"
#include "third_party/blink/public/platform/scheduler/test/renderer_scheduler_test_support.h"
#include "third_party/blink/public/platform/web_string.h"
#include "third_party/blink/renderer/core/testing/sim/sim_test.h"
#include "third_party/blink/renderer/modules/mediastream/local_media_stream_audio_source.h"
#include "third_party/blink/renderer/modules/mediastream/media_constraints.h"
#include "third_party/blink/renderer/modules/mediastream/mock_constraint_factory.h"
#include "third_party/blink/renderer/modules/mediastream/processed_local_audio_source.h"
#include "third_party/blink/renderer/modules/webrtc/webrtc_audio_device_impl.h"
#include "third_party/blink/renderer/platform/mediastream/media_stream_audio_source.h"
#include "third_party/blink/renderer/platform/testing/io_task_runner_testing_platform_support.h"
#include "third_party/blink/renderer/platform/wtf/vector.h"
#include "third_party/webrtc/rtc_base/ref_counted_object.h"

namespace blink {

AudioCaptureSettings;
AudioProcessingProperties;
EchoCancellationType;
ProcessingType;

namespace {

BoolSetFunction;
StringSetFunction;
MockFactoryAccessor;

const BoolSetFunction kBoolSetFunctions[] =;

const MockFactoryAccessor kFactoryAccessors[] =;

const bool kBoolValues[] =;

const int kMinChannels =;

AudioSettingsBoolMembers;
AudioPropertiesBoolMembers;

template <typename T>
static bool Contains(const WTF::Vector<T>& vector, T value) {}

}  // namespace

class MediaStreamConstraintsUtilAudioTestBase : public SimTest {};

class MediaStreamConstraintsUtilAudioTest
    : public MediaStreamConstraintsUtilAudioTestBase,
      public testing::WithParamInterface<std::string> {};

enum class ChromeWideAecExperiment {};

class MediaStreamConstraintsRemoteAPMTest
    : public MediaStreamConstraintsUtilAudioTestBase,
      public testing::WithParamInterface<
          std::tuple<std::string, ChromeWideAecExperiment>> {};

// The Unconstrained test checks the default selection criteria.
TEST_P(MediaStreamConstraintsUtilAudioTest, Unconstrained) {}

// This test checks all possible ways to set boolean constraints (except
// echo cancellation constraints, which are not mapped 1:1 to output audio
// processing properties).
TEST_P(MediaStreamConstraintsUtilAudioTest, SingleBoolConstraint) {}

TEST_P(MediaStreamConstraintsUtilAudioTest, SampleSize) {}

TEST_P(MediaStreamConstraintsUtilAudioTest, Channels) {}

TEST_P(MediaStreamConstraintsUtilAudioTest, MultiChannelEchoCancellation) {}

TEST_P(MediaStreamConstraintsUtilAudioTest, ChannelsWithSource) {}

TEST_P(MediaStreamConstraintsUtilAudioTest, SampleRate) {}

TEST_P(MediaStreamConstraintsUtilAudioTest, SampleRateWithSource) {}

TEST_P(MediaStreamConstraintsUtilAudioTest, Latency) {}

TEST_P(MediaStreamConstraintsUtilAudioTest, LatencyWithSource) {}

// DeviceID tests.
TEST_P(MediaStreamConstraintsUtilAudioTest, ExactArbitraryDeviceID) {}

// DeviceID tests check various ways to deal with the device_id constraint.
TEST_P(MediaStreamConstraintsUtilAudioTest, IdealArbitraryDeviceID) {}

TEST_P(MediaStreamConstraintsUtilAudioTest, ExactValidDeviceID) {}

TEST_P(MediaStreamConstraintsUtilAudioTest, ExactGroupID) {}

// Tests the echoCancellation constraint with a device without system echo
// cancellation.
TEST_P(MediaStreamConstraintsUtilAudioTest, EchoCancellationWithWebRtc) {}

// Tests the echoCancellation constraint with a device with system echo
// cancellation.
TEST_P(MediaStreamConstraintsUtilAudioTest, EchoCancellationWithSystem) {}

// Tests the googEchoCancellation constraint with a device without system echo
// cancellation.
TEST_P(MediaStreamConstraintsUtilAudioTest, GoogEchoCancellationWithWebRtc) {}

// Tests the googEchoCancellation constraint with a device with system echo
// cancellation.
TEST_P(MediaStreamConstraintsUtilAudioTest, GoogEchoCancellationWithSystem) {}

// Test that having differing mandatory values for echoCancellation and
// googEchoCancellation fails.
TEST_P(MediaStreamConstraintsUtilAudioTest, ContradictoryEchoCancellation) {}

// Tests that individual boolean audio-processing constraints override the
// default value set by the echoCancellation constraint.
TEST_P(MediaStreamConstraintsUtilAudioTest,
       EchoCancellationAndSingleBoolConstraint) {}

TEST_P(MediaStreamConstraintsUtilAudioTest,
       ReconfigurationSystemEchoCancellation) {}

TEST_P(MediaStreamConstraintsUtilAudioTest, VoiceIsolationControl) {}

// Test advanced constraints sets that can be satisfied.
TEST_P(MediaStreamConstraintsUtilAudioTest, AdvancedCompatibleConstraints) {}

// Test that an advanced constraint set that contradicts a previous constraint
// set is ignored, but that further constraint sets that can be satisfied are
// applied.
TEST_P(MediaStreamConstraintsUtilAudioTest,
       AdvancedConflictingMiddleConstraints) {}

// Test that an advanced constraint set that contradicts a previous constraint
// set with a boolean constraint is ignored.
TEST_P(MediaStreamConstraintsUtilAudioTest, AdvancedConflictingLastConstraint) {}

// NoDevices tests verify that the case with no devices is handled correctly.
TEST_P(MediaStreamConstraintsUtilAudioTest, NoDevicesNoConstraints) {}

TEST_P(MediaStreamConstraintsUtilAudioTest, NoDevicesWithConstraints) {}

// Test functionality to support applyConstraints() for tracks attached to
// sources that have no audio processing.
TEST_P(MediaStreamConstraintsUtilAudioTest, SourceWithNoAudioProcessing) {}

// Test functionality to support applyConstraints() for tracks attached to
// sources that have audio processing.
TEST_P(MediaStreamConstraintsUtilAudioTest, SourceWithAudioProcessing) {}

TEST_P(MediaStreamConstraintsUtilAudioTest, UsedAndUnusedSources) {}

TEST_P(MediaStreamConstraintsUtilAudioTest, ExperimentalEcWithSource) {}

TEST_P(MediaStreamConstraintsUtilAudioTest,
       SelectEligibleSettingsAudioDeviceCapture_NoEligibleDevices) {}

TEST_P(MediaStreamConstraintsUtilAudioTest,
       SelectEligibleSettingsAudioDeviceCapture_IncludesEligibleDevices) {}

TEST_P(MediaStreamConstraintsRemoteAPMTest, DeviceSampleRate) {}

TEST_P(MediaStreamConstraintsRemoteAPMTest,
       WebRtcSampleRateButNotDeviceSampleRate) {}

#if BUILDFLAG(CHROME_WIDE_ECHO_CANCELLATION)
class MediaStreamConstraintsRemoteAPMSampleRateRestrictionTest
    : public MediaStreamConstraintsUtilAudioTestBase,
      public testing::WithParamInterface<bool> {};

TEST_P(MediaStreamConstraintsRemoteAPMSampleRateRestrictionTest,
       ToggleNondivisibleSampleRatesParameter) {}

INSTANTIATE_TEST_SUITE_P();
#endif

TEST_P(MediaStreamConstraintsUtilAudioTest, LatencyConstraint) {}

INSTANTIATE_TEST_SUITE_P();
#if BUILDFLAG(CHROME_WIDE_ECHO_CANCELLATION)
INSTANTIATE_TEST_SUITE_P();
#else
INSTANTIATE_TEST_SUITE_P(
    All,
    MediaStreamConstraintsRemoteAPMTest,
    testing::Combine(testing::Values("",
                                     blink::kMediaStreamSourceTab,
                                     blink::kMediaStreamSourceSystem,
                                     blink::kMediaStreamSourceDesktop),
                     testing::Values(ChromeWideAecExperiment::kDisabled)));
#endif
}  // namespace blink