chromium/content/browser/renderer_host/media/media_stream_dispatcher_host_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 "content/browser/renderer_host/media/media_stream_dispatcher_host.h"

#include <stddef.h>
#include <stdint.h>

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

#include "base/command_line.h"
#include "base/containers/queue.h"
#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/memory/raw_ptr.h"
#include "base/ranges/algorithm.h"
#include "base/run_loop.h"
#include "base/system/system_monitor.h"
#include "base/task/single_thread_task_runner.h"
#include "base/test/bind.h"
#include "base/test/gmock_move_support.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/test_future.h"
#include "base/unguessable_token.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "content/browser/media/media_devices_util.h"
#include "content/browser/renderer_host/media/audio_input_device_manager.h"
#include "content/browser/renderer_host/media/media_stream_manager.h"
#include "content/browser/renderer_host/media/media_stream_ui_proxy.h"
#include "content/browser/renderer_host/media/mock_video_capture_provider.h"
#include "content/browser/renderer_host/media/video_capture_manager.h"
#include "content/browser/renderer_host/render_frame_host_impl.h"
#include "content/public/browser/content_browser_client.h"
#include "content/public/browser/global_routing_id.h"
#include "content/public/browser/media_device_id.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/common/content_features.h"
#include "content/public/common/content_switches.h"
#include "content/public/test/browser_task_environment.h"
#include "content/public/test/mock_captured_surface_controller.h"
#include "content/public/test/test_renderer_host.h"
#include "media/audio/audio_device_description.h"
#include "media/audio/audio_system_impl.h"
#include "media/audio/mock_audio_manager.h"
#include "media/audio/test_audio_thread.h"
#include "media/base/media_switches.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/common/features.h"
#include "third_party/blink/public/common/mediastream/media_stream_request.h"
#include "third_party/blink/public/mojom/mediastream/media_stream.mojom-shared.h"
#include "third_party/blink/public/mojom/mediastream/media_stream.mojom.h"
#include "url/gurl.h"
#include "url/origin.h"

#if BUILDFLAG(IS_CHROMEOS_ASH)
#include "chromeos/ash/components/audio/cras_audio_handler.h"
#include "chromeos/ash/components/dbus/audio/cras_audio_client.h"
#endif

CapturedSurfaceControlResult;
_;
InSequence;
Invoke;
InvokeWithoutArgs;
Return;

namespace content {

namespace {

const GlobalRenderFrameHostId kRenderFrameHostId{};
constexpr int kRequesterId =;
constexpr int kPageRequestId =;
constexpr const char* kRegularVideoDeviceId1 =;
constexpr const char* kRegularVideoDeviceId2 =;
constexpr const char* kDepthVideoDeviceId =;
constexpr media::VideoCaptureApi kStubCaptureApi =;

bool DoStreamDevicesHaveSameTypes(const blink::mojom::StreamDevices& lhs,
                                  const blink::mojom::StreamDevices& rhs) {}

MATCHER_P(SameTypesAs,
          expected_stream_devices_set_ref,
          "Compares if two StreamDevices objects contain the same number and "
          "type of MediaStreamDevice objects.") {}

void AudioInputDevicesEnumerated(base::OnceClosure quit_closure,
                                 media::AudioDeviceDescriptions* out,
                                 const MediaDeviceEnumeration& enumeration) {}

}  // anonymous namespace

class MockMediaStreamDispatcherHost
    : public MediaStreamDispatcherHost,
      public blink::mojom::MediaStreamDeviceObserver {};

class MockMediaStreamUIProxy : public FakeMediaStreamUIProxy {};

class MediaStreamDispatcherHostTest : public testing::Test {};

TEST_F(MediaStreamDispatcherHostTest, GenerateStreamWithVideoOnly) {}

TEST_F(MediaStreamDispatcherHostTest, GenerateStreamWithAudioOnly) {}

TEST_F(MediaStreamDispatcherHostTest,
       BadMessageIfAudioNotRequestedAndSuppressLocalAudioPlayback) {}

TEST_F(MediaStreamDispatcherHostTest,
       BadMessageIfAudioNotRequestedAndHotwordEnabled) {}

TEST_F(MediaStreamDispatcherHostTest,
       BadMessageIfAudioNotRequestedAndDisableLocalEcho) {}

// This test simulates a shutdown scenario: we don't setup a fake UI proxy for
// MediaStreamManager, so it will create an ordinary one which will not find
// a RenderFrameHostDelegate. This normally should only be the case at shutdown.
TEST_F(MediaStreamDispatcherHostTest, GenerateStreamWithNothing) {}

TEST_F(MediaStreamDispatcherHostTest, GenerateStreamWithAudioAndVideo) {}

TEST_F(MediaStreamDispatcherHostTest, GenerateStreamWithDepthVideo) {}

// This test generates two streams with video only using the same render frame
// id. The same capture device with the same device and session id is expected
// to be used.
TEST_F(MediaStreamDispatcherHostTest, GenerateStreamsFromSameRenderId) {}

TEST_F(MediaStreamDispatcherHostTest,
       GenerateStreamAndOpenDeviceFromSameRenderFrame) {}

// This test generates two streams with video only using two separate render
// frame ids. The same device id but different session ids are expected.
TEST_F(MediaStreamDispatcherHostTest, GenerateStreamsDifferentRenderId) {}

TEST_F(MediaStreamDispatcherHostTest, WebContentsNotFocused) {}

TEST_F(MediaStreamDispatcherHostTest, WebContentsNotFocusedInBackgroundPage) {}

TEST_F(MediaStreamDispatcherHostTest, WebContentsFocused) {}

// This test request two streams with video only without waiting for the first
// stream to be generated before requesting the second.
// The same device id and session ids are expected.
TEST_F(MediaStreamDispatcherHostTest, GenerateStreamsWithoutWaiting) {}

// Test that we can generate streams where a sourceId is specified in
// the request.
TEST_F(MediaStreamDispatcherHostTest, GenerateStreamsWithSourceId) {}

// Test that generating a stream with an invalid video source id fail.
TEST_F(MediaStreamDispatcherHostTest, GenerateStreamsWithInvalidVideoSourceId) {}

// Test that generating a stream with an invalid audio source id fail.
TEST_F(MediaStreamDispatcherHostTest, GenerateStreamsWithInvalidAudioSourceId) {}

TEST_F(MediaStreamDispatcherHostTest, GenerateStreamsNoAvailableVideoDevice) {}

// Test that if a OnStopStreamDevice message is received for a device that has
// been opened in a MediaStream and by pepper, the device is only stopped for
// the MediaStream.
TEST_F(MediaStreamDispatcherHostTest, StopDeviceInStream) {}

TEST_F(MediaStreamDispatcherHostTest, StopDeviceInStreamAndRestart) {}

TEST_F(MediaStreamDispatcherHostTest,
       GenerateTwoStreamsAndStopDeviceWhileWaitingForSecondStream) {}

TEST_F(MediaStreamDispatcherHostTest, CancelPendingStreams) {}

TEST_F(MediaStreamDispatcherHostTest, StopGeneratedStreams) {}

TEST_F(MediaStreamDispatcherHostTest, CloseFromUI) {}

// Test that the observer is notified if a video device that is in use is
// being unplugged.
TEST_F(MediaStreamDispatcherHostTest, VideoDeviceUnplugged) {}

// Test that changing the salt invalidates device IDs. Attempts to open an
// invalid device ID result in failure.
TEST_F(MediaStreamDispatcherHostTest, Salt) {}

TEST_F(MediaStreamDispatcherHostTest, GetOpenDeviceWithoutFeatureFails) {}

TEST_F(MediaStreamDispatcherHostTest, GetOpenDeviceSucceeds) {}

TEST_F(MediaStreamDispatcherHostTest,
       RegisterAndUnregisterWithMediaStreamManager) {}

// TODO(crbug.com/40216442): Add test cases for multi stream generation.

class MediaStreamDispatcherHostStreamTypeCombinationTest
    : public MediaStreamDispatcherHostTest,
      public ::testing::WithParamInterface<std::tuple<int, int>> {};

TEST_P(MediaStreamDispatcherHostStreamTypeCombinationTest,
       GenerateStreamWithStreamTypeCombination) {}

INSTANTIATE_TEST_SUITE_P();

class MockContentBrowserClient : public ContentBrowserClient {};

class MediaStreamDispatcherHostMultiCaptureTest
    : public RenderViewHostTestHarness {};

TEST_F(MediaStreamDispatcherHostMultiCaptureTest,
       NoRenderFrameHostMultiCaptureNotAllowed) {}

TEST_F(MediaStreamDispatcherHostMultiCaptureTest,
       RenderFrameHostExistsButNoPolicySetMultiCaptureNotAllowed) {}

TEST_F(MediaStreamDispatcherHostMultiCaptureTest,
       PolicySetMultiCaptureAllowed) {}

#if !BUILDFLAG(IS_ANDROID) && !BUILDFLAG(IS_IOS)
class MediaStreamDispatcherHostCapturedSurfaceControlTest
    : public MediaStreamDispatcherHostTest {};

TEST_F(MediaStreamDispatcherHostCapturedSurfaceControlTest,
       RequestPermissionIsForwarded) {}
#endif  // !BUILDFLAG(IS_ANDROID) && !BUILDFLAG(IS_IOS)

}  // namespace content