#include <stddef.h>
#include <memory>
#include <string>
#include <utility>
#include "base/command_line.h"
#include "base/functional/bind.h"
#include "base/location.h"
#include "base/memory/raw_ptr.h"
#include "base/run_loop.h"
#include "base/strings/strcat.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/task/sequenced_task_runner.h"
#include "base/task/single_thread_task_runner.h"
#include "base/test/bind.h"
#include "base/test/mock_callback.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 "content/browser/media/media_devices_util.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/common/features.h"
#include "content/public/browser/content_browser_client.h"
#include "content/public/browser/media_observer.h"
#include "content/public/browser/media_request_state.h"
#include "content/public/common/content_client.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_browser_context.h"
#include "content/test/test_web_contents.h"
#include "media/audio/audio_device_description.h"
#include "media/audio/audio_system_impl.h"
#include "media/audio/fake_audio_log_factory.h"
#include "media/audio/test_audio_thread.h"
#include "media/base/media_switches.h"
#include "media/capture/content/screen_enumerator.h"
#include "media/capture/mojom/video_capture_types.mojom.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/common/mediastream/media_stream_request.h"
#include "third_party/blink/public/mojom/mediastream/media_stream.mojom.h"
#include "ui/gfx/native_widget_types.h"
#include "url/gurl.h"
#include "url/origin.h"
#if BUILDFLAG(IS_CHROMEOS_LACROS)
#include "chromeos/lacros/lacros_test_helper.h"
#endif
#if defined(USE_ALSA)
#include "media/audio/alsa/audio_manager_alsa.h"
#elif BUILDFLAG(IS_ANDROID)
#include "media/audio/android/audio_manager_android.h"
#elif BUILDFLAG(IS_MAC)
#include "media/audio/mac/audio_manager_mac.h"
#elif BUILDFLAG(IS_WIN)
#include "media/audio/win/audio_manager_win.h"
#else
#include "media/audio/fake_audio_manager.h"
#endif
CapturedSurfaceControlResult;
MediaStreamType;
StreamSelectionInfo;
StreamSelectionInfoPtr;
_;
ElementsAre;
Invoke;
#if !BUILDFLAG(IS_ANDROID) && !BUILDFLAG(IS_IOS)
CapturedWheelAction;
CapturedWheelActionPtr;
CapturedSurfaceControllerFactoryCallback;
#endif
DeviceStoppedCallback;
namespace content {
#if defined(USE_ALSA)
typedef media::AudioManagerAlsa AudioManagerPlatform;
#elif BUILDFLAG(IS_MAC)
typedef media::AudioManagerMac AudioManagerPlatform;
#elif BUILDFLAG(IS_WIN)
typedef media::AudioManagerWin AudioManagerPlatform;
#elif BUILDFLAG(IS_ANDROID)
typedef media::AudioManagerAndroid AudioManagerPlatform;
#else
AudioManagerPlatform;
#endif
namespace {
const char kFakeDeviceIdPrefix[] = …;
const GlobalRenderFrameHostId kRenderFrameHostId{ … };
std::string GetAudioInputDeviceId(size_t index) { … }
std::string GetAudioInputDeviceName(size_t index) { … }
class MockAudioManager : public AudioManagerPlatform { … };
class MockMediaObserver : public MediaObserver { … };
class ScreenEnumeratorMock : public media::ScreenEnumerator { … };
class MediaStreamProviderListenerMock
: public content::MediaStreamProviderListener { … };
class TestBrowserClient : public ContentBrowserClient { … };
class MockMediaStreamUIProxy : public FakeMediaStreamUIProxy { … };
class TestMediaStreamDispatcherHost
: public blink::mojom::MediaStreamDispatcherHost { … };
class TestVideoCaptureHost : public media::mojom::VideoCaptureHost { … };
blink::StreamControls GetVideoStreamControls(std::string hmac_device_id) { … }
blink::StreamControls GetAudioStreamControls(std::string hmac_device_id) { … }
#if !BUILDFLAG(IS_ANDROID) && !BUILDFLAG(IS_IOS)
enum class CapturedSurfaceControlAPI { … };
CapturedWheelActionPtr MakeCapturedWheelActionPtr() { … }
#endif
blink::mojom::StreamSelectionInfoPtr NewSearchBySessionId(
base::flat_map<std::string, base::UnguessableToken> session_id_map) { … }
}
class MediaStreamManagerTest : public ::testing::Test { … };
TEST_F(MediaStreamManagerTest, MakeMediaAccessRequest) { … }
TEST_F(MediaStreamManagerTest, MakeAndCancelMediaAccessRequest) { … }
TEST_F(MediaStreamManagerTest, MakeMultipleRequests) { … }
TEST_F(MediaStreamManagerTest, MakeAndCancelMultipleRequests) { … }
TEST_F(MediaStreamManagerTest, GenerateSameStreamForAudioDevice) { … }
TEST_F(MediaStreamManagerTest, GenerateDifferentStreamsForAudioDevice) { … }
TEST_F(MediaStreamManagerTest, GenerateAndReuseStreamForAudioDevice) { … }
TEST_F(MediaStreamManagerTest, GetDisplayMediaRequestVideoOnly) { … }
TEST_F(MediaStreamManagerTest, GetDisplayMediaRequestAudioAndVideo) { … }
TEST_F(MediaStreamManagerTest,
GetDisplayMediaRequestAudioAndVideoNoAudioShare) { … }
TEST_F(MediaStreamManagerTest, GetDisplayMediaRequestCallsUIProxy) { … }
TEST_F(MediaStreamManagerTest, DesktopCaptureDeviceStopped) { … }
TEST_F(MediaStreamManagerTest, DesktopCaptureDeviceChanged) { … }
TEST_F(MediaStreamManagerTest, MultiCaptureOnMediaStreamUIWindowId) { … }
TEST_F(MediaStreamManagerTest, MultiCaptureAllDevicesOpened) { … }
TEST_F(MediaStreamManagerTest, MultiCaptureNotAllDevicesOpened) { … }
TEST_F(MediaStreamManagerTest, MultiCaptureIntermediateErrorOnOpening) { … }
TEST_F(MediaStreamManagerTest, RegisterUnregisterHosts) { … }
class MediaStreamManagerTestWithWebContents : public MediaStreamManagerTest { … };
TEST_F(MediaStreamManagerTestWithWebContents,
GetRawDeviceIdsOpenedForFrame_AudioCapture) { … }
TEST_F(MediaStreamManagerTestWithWebContents,
GetRawDeviceIdsOpenedForFrame_VideoCapture) { … }
class MediaStreamManagerTestForTransfers : public MediaStreamManagerTest { … };
TEST_F(MediaStreamManagerTestForTransfers,
GetOpenDeviceForScreenCaptureTypeStreamFails) { … }
TEST_F(MediaStreamManagerTestForTransfers,
GetOpenDeviceForWindowCaptureTypeStreamFails) { … }
TEST_F(MediaStreamManagerTestForTransfers,
GetOpenDeviceForBrowserCaptureTypeStreamReturnsDevice) { … }
TEST_F(MediaStreamManagerTestForTransfers,
GetOpenDeviceForDeviceCaptureTypeStreamFails) { … }
TEST_F(MediaStreamManagerTestForTransfers,
GetDisplayMediaAudioAndVideoAndGetOpenDeviceVideoReturnsDevice) { … }
TEST_F(MediaStreamManagerTestForTransfers,
GetDisplayMediaVideoAndGetOpenDeviceVideoReturnsDevice) { … }
TEST_F(MediaStreamManagerTestForTransfers,
GetOpenDeviceWhenKeepAliveAfterStopDoesNotReturnDevice) { … }
TEST_F(MediaStreamManagerTestForTransfers,
GetOpenDeviceWhenKeepAliveBeforeStopReturnsDevice) { … }
TEST_F(MediaStreamManagerTestForTransfers,
GetOpenDeviceWithoutKeepAliveReturnsDeviceButDoesNotStop) { … }
TEST_F(MediaStreamManagerTestForTransfers,
GetOpenDeviceWithKeepAliveAfterStopReturnsDevice) { … }
TEST_F(MediaStreamManagerTestForTransfers,
GetOpenDeviceForNonExistentDeviceReturnsInvalidState) { … }
#if !BUILDFLAG(IS_ANDROID) && !BUILDFLAG(IS_IOS)
class MediaStreamManagerCapturedSurfaceControlTest
: public MediaStreamManagerTest { … };
TEST_F(MediaStreamManagerCapturedSurfaceControlTest, ZoomLevelChangeEvent) { … }
class MediaStreamManagerCapturedSurfaceControlActionTest
: public MediaStreamManagerCapturedSurfaceControlTest,
public testing::WithParamInterface<CapturedSurfaceControlAPI> { … };
INSTANTIATE_TEST_SUITE_P(…);
TEST_P(MediaStreamManagerCapturedSurfaceControlActionTest, SuccessfulIfValid) { … }
TEST_P(MediaStreamManagerCapturedSurfaceControlActionTest,
FailsIfInvalidSessionId) { … }
TEST_P(MediaStreamManagerCapturedSurfaceControlActionTest,
FailsIfNotCapturerRfhId) { … }
TEST_P(MediaStreamManagerCapturedSurfaceControlActionTest,
DISABLED_FailsIfSelfCapture) { … }
TEST_P(MediaStreamManagerCapturedSurfaceControlActionTest,
FailsIfCapturingWindow) { … }
TEST_P(MediaStreamManagerCapturedSurfaceControlActionTest,
FailsIfCapturingScreen) { … }
#endif
}