chromium/third_party/blink/renderer/modules/mediastream/user_media_client_test.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 "third_party/blink/renderer/modules/mediastream/user_media_client.h"

#include <stddef.h>

#include <memory>
#include <string>
#include <utility>
#include <vector>

#include "base/functional/bind.h"
#include "base/memory/ptr_util.h"
#include "base/memory/raw_ptr.h"
#include "base/rand_util.h"
#include "base/run_loop.h"
#include "base/strings/strcat.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/bind.h"
#include "base/test/scoped_feature_list.h"
#include "build/build_config.h"
#include "media/audio/audio_device_description.h"
#include "media/capture/mojom/video_capture_types.mojom-blink.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/common/mediastream/media_device_id.h"
#include "third_party/blink/public/common/mediastream/media_devices.h"
#include "third_party/blink/public/mojom/media/capture_handle_config.mojom-blink.h"
#include "third_party/blink/public/mojom/mediastream/media_devices.mojom-blink.h"
#include "third_party/blink/public/mojom/mediastream/media_stream.mojom-blink.h"
#include "third_party/blink/public/platform/modules/mediastream/web_media_stream_source.h"
#include "third_party/blink/public/platform/modules/mediastream/web_media_stream_track.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/public/platform/web_vector.h"
#include "third_party/blink/public/web/modules/mediastream/web_media_stream_device_observer.h"
#include "third_party/blink/public/web/web_heap.h"
#include "third_party/blink/renderer/core/frame/local_dom_window.h"
#include "third_party/blink/renderer/core/frame/local_frame.h"
#include "third_party/blink/renderer/core/loader/empty_clients.h"
#include "third_party/blink/renderer/core/testing/dummy_page_holder.h"
#include "third_party/blink/renderer/modules/mediastream/media_stream_constraints_util.h"
#include "third_party/blink/renderer/modules/mediastream/media_stream_constraints_util_video_content.h"
#include "third_party/blink/renderer/modules/mediastream/media_stream_track_impl.h"
#include "third_party/blink/renderer/modules/mediastream/media_stream_video_track.h"
#include "third_party/blink/renderer/modules/mediastream/mock_constraint_factory.h"
#include "third_party/blink/renderer/modules/mediastream/mock_media_stream_video_source.h"
#include "third_party/blink/renderer/modules/mediastream/mock_mojo_media_stream_dispatcher_host.h"
#include "third_party/blink/renderer/modules/mediastream/user_media_request.h"
#include "third_party/blink/renderer/platform/heap/garbage_collected.h"
#include "third_party/blink/renderer/platform/mediastream/media_stream_audio_processor_options.h"
#include "third_party/blink/renderer/platform/mediastream/media_stream_audio_source.h"
#include "third_party/blink/renderer/platform/mediastream/media_stream_audio_track.h"
#include "third_party/blink/renderer/platform/mediastream/media_stream_component.h"
#include "third_party/blink/renderer/platform/mediastream/media_stream_descriptor.h"
#include "third_party/blink/renderer/platform/mediastream/media_stream_track_platform.h"
#include "third_party/blink/renderer/platform/testing/io_task_runner_testing_platform_support.h"
#include "third_party/blink/renderer/platform/testing/task_environment.h"
#include "third_party/blink/renderer/platform/wtf/functional.h"
#include "third_party/blink/renderer/platform/wtf/text/wtf_string.h"
#include "ui/display/screen_info.h"

SubCaptureTargetType;
_;
Mock;

namespace blink {

EchoCancellationType;

namespace {

MediaConstraints CreateDefaultConstraints() {}

MediaConstraints CreateDeviceConstraints(
    const String& basic_exact_value,
    const String& basic_ideal_value = g_empty_string,
    const String& advanced_exact_value = g_empty_string) {}

MediaConstraints CreateFacingModeConstraints(
    const char* basic_exact_value,
    const char* basic_ideal_value = nullptr,
    const char* advanced_exact_value = nullptr) {}

void CheckVideoSource(blink::MediaStreamVideoSource* source,
                      int expected_source_width,
                      int expected_source_height,
                      double expected_source_frame_rate) {}

void CheckVideoSourceAndTrack(blink::MediaStreamVideoSource* source,
                              int expected_source_width,
                              int expected_source_height,
                              double expected_source_frame_rate,
                              MediaStreamComponent* component,
                              int expected_track_width,
                              int expected_track_height,
                              double expected_track_frame_rate) {}

class MockLocalMediaStreamAudioSource : public blink::MediaStreamAudioSource {};

class MockMediaStreamVideoCapturerSource
    : public blink::MockMediaStreamVideoSource {};

String MakeValidDeviceId(std::string_view id) {}

class FakeDeviceIds {};

class MediaDevicesDispatcherHostMock
    : public mojom::blink::MediaDevicesDispatcherHost {};

class MockMediaDevicesDispatcherHost
    : public mojom::blink::MediaDevicesDispatcherHost {};

enum RequestState {};

class UserMediaProcessorUnderTest : public UserMediaProcessor {};

class UserMediaClientUnderTest : public UserMediaClient {};

class UserMediaChromeClient : public EmptyChromeClient {};

}  // namespace

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

TEST_F(UserMediaClientTest, GenerateMediaStream) {}

// Test that the same source object is used if two MediaStreams are generated
// using the same source.
TEST_F(UserMediaClientTest, GenerateTwoMediaStreamsWithSameSource) {}

// Test that the same source object is not used if two MediaStreams are
// generated using different sources.
TEST_F(UserMediaClientTest, GenerateTwoMediaStreamsWithDifferentSources) {}

TEST_F(UserMediaClientTest, StopLocalTracks) {}

// This test that a source is not stopped even if the tracks in a
// MediaStream is stopped if there are two MediaStreams with tracks using the
// same device. The source is stopped
// if there are no more MediaStream tracks using the device.
TEST_F(UserMediaClientTest, StopLocalTracksWhenTwoStreamUseSameDevices) {}

TEST_F(UserMediaClientTest, StopSourceWhenMediaStreamGoesOutOfScope) {}

// Test that the MediaStreams are deleted if a new document is loaded in the
// frame.
TEST_F(UserMediaClientTest, LoadNewDocumentInFrame) {}

// This test what happens if a video source to a MediaSteam fails to start.
TEST_F(UserMediaClientTest, MediaVideoSourceFailToStart) {}

// This test what happens if an audio source fail to initialize.
TEST_F(UserMediaClientTest, MediaAudioSourceFailToInitialize) {}

// This test what happens if UserMediaClient is deleted before a source has
// started.
TEST_F(UserMediaClientTest, MediaStreamImplShutDown) {}

// This test what happens if a new document is loaded in the frame while the
// MediaStream is being generated by the blink::WebMediaStreamDeviceObserver.
TEST_F(UserMediaClientTest, ReloadFrameWhileGeneratingStream) {}

// This test what happens if a newdocument is loaded in the frame while the
// sources are being started.
TEST_F(UserMediaClientTest, ReloadFrameWhileGeneratingSources) {}

// This test what happens if stop is called on a track after the frame has
// been reloaded.
TEST_F(UserMediaClientTest, StopTrackAfterReload) {}

TEST_F(UserMediaClientTest, DefaultConstraintsPropagate) {}

TEST_F(UserMediaClientTest, DefaultTabCapturePropagate) {}

TEST_F(UserMediaClientTest, DefaultDesktopCapturePropagate) {}

TEST_F(UserMediaClientTest, NonDefaultAudioConstraintsPropagate) {}

TEST_F(UserMediaClientTest, CreateWithMandatoryInvalidAudioDeviceId) {}

TEST_F(UserMediaClientTest, CreateWithMandatoryInvalidVideoDeviceId) {}

TEST_F(UserMediaClientTest, CreateWithMandatoryValidDeviceIds) {}

TEST_F(UserMediaClientTest, CreateWithBasicIdealValidDeviceId) {}

TEST_F(UserMediaClientTest, CreateWithAdvancedExactValidDeviceId) {}

TEST_F(UserMediaClientTest, CreateWithAllOptionalInvalidDeviceId) {}

TEST_F(UserMediaClientTest, CreateWithFacingModeUser) {}

TEST_F(UserMediaClientTest, CreateWithFacingModeEnvironment) {}

TEST_F(UserMediaClientTest, ApplyConstraintsVideoDeviceSingleTrack) {}

TEST_F(UserMediaClientTest, ApplyConstraintsVideoDeviceTwoTracks) {}

TEST_F(UserMediaClientTest, ApplyConstraintsVideoDeviceFailsToStopForRestart) {}

TEST_F(UserMediaClientTest,
       ApplyConstraintsVideoDeviceFailsToRestartAfterStop) {}

TEST_F(UserMediaClientTest, ApplyConstraintsVideoDeviceStopped) {}

// These tests check that the associated output device id is
// set according to the renderToAssociatedSink constrainable property.
TEST_F(UserMediaClientTest,
       RenderToAssociatedSinkTrueAssociatedOutputDeviceId) {}

TEST_F(UserMediaClientTest,
       RenderToAssociatedSinkFalseAssociatedOutputDeviceId) {}

TEST_F(UserMediaClientTest, IsCapturing) {}

TEST_F(UserMediaClientTest, DesktopCaptureChangeSource) {}

TEST_F(UserMediaClientTest, DesktopCaptureChangeSourceWithoutAudio) {}

TEST_F(UserMediaClientTest, PanConstraintRequestPanTiltZoomPermission) {}

TEST_F(UserMediaClientTest, TiltConstraintRequestPanTiltZoomPermission) {}

TEST_F(UserMediaClientTest, ZoomConstraintRequestPanTiltZoomPermission) {}

TEST_F(UserMediaClientTest, MultiDeviceOnStreamsGenerated) {}

#if !BUILDFLAG(IS_ANDROID) && !BUILDFLAG(IS_CHROMEOS) && !BUILDFLAG(IS_FUCHSIA)

class UserMediaClientDeferredDeviceSelectionTest : public UserMediaClientTest {};

TEST_F(UserMediaClientDeferredDeviceSelectionTest, GenerateMediaStream) {}

TEST_F(UserMediaClientDeferredDeviceSelectionTest,
       CreateWithMandatoryInvalidAudioDeviceId) {}

TEST_F(UserMediaClientDeferredDeviceSelectionTest,
       CreateWithMandatoryInvalidVideoDeviceId) {}

TEST_F(UserMediaClientDeferredDeviceSelectionTest,
       CreateWithMandatoryValidDeviceIds) {}

#endif
}  // namespace blink