#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) { … }
}
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) { … }
TEST_F(MediaStreamDispatcherHostTest, GenerateStreamWithNothing) { … }
TEST_F(MediaStreamDispatcherHostTest, GenerateStreamWithAudioAndVideo) { … }
TEST_F(MediaStreamDispatcherHostTest, GenerateStreamWithDepthVideo) { … }
TEST_F(MediaStreamDispatcherHostTest, GenerateStreamsFromSameRenderId) { … }
TEST_F(MediaStreamDispatcherHostTest,
GenerateStreamAndOpenDeviceFromSameRenderFrame) { … }
TEST_F(MediaStreamDispatcherHostTest, GenerateStreamsDifferentRenderId) { … }
TEST_F(MediaStreamDispatcherHostTest, WebContentsNotFocused) { … }
TEST_F(MediaStreamDispatcherHostTest, WebContentsNotFocusedInBackgroundPage) { … }
TEST_F(MediaStreamDispatcherHostTest, WebContentsFocused) { … }
TEST_F(MediaStreamDispatcherHostTest, GenerateStreamsWithoutWaiting) { … }
TEST_F(MediaStreamDispatcherHostTest, GenerateStreamsWithSourceId) { … }
TEST_F(MediaStreamDispatcherHostTest, GenerateStreamsWithInvalidVideoSourceId) { … }
TEST_F(MediaStreamDispatcherHostTest, GenerateStreamsWithInvalidAudioSourceId) { … }
TEST_F(MediaStreamDispatcherHostTest, GenerateStreamsNoAvailableVideoDevice) { … }
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_F(MediaStreamDispatcherHostTest, VideoDeviceUnplugged) { … }
TEST_F(MediaStreamDispatcherHostTest, Salt) { … }
TEST_F(MediaStreamDispatcherHostTest, GetOpenDeviceWithoutFeatureFails) { … }
TEST_F(MediaStreamDispatcherHostTest, GetOpenDeviceSucceeds) { … }
TEST_F(MediaStreamDispatcherHostTest,
RegisterAndUnregisterWithMediaStreamManager) { … }
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
}