#include "content/browser/renderer_host/media/video_capture_manager.h"
#include <stdint.h>
#include <memory>
#include <string>
#include <vector>
#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/ref_counted.h"
#include "base/ranges/algorithm.h"
#include "base/run_loop.h"
#include "base/task/single_thread_task_runner.h"
#include "base/test/bind.h"
#include "base/test/scoped_feature_list.h"
#include "build/android_buildflags.h"
#include "build/build_config.h"
#include "content/browser/renderer_host/media/fake_video_capture_provider.h"
#include "content/browser/renderer_host/media/in_process_video_capture_provider.h"
#include "content/browser/renderer_host/media/media_stream_provider.h"
#include "content/browser/renderer_host/media/video_capture_controller_event_handler.h"
#include "content/browser/renderer_host/media/video_capture_provider_switcher.h"
#include "content/browser/screenlock_monitor/screenlock_monitor.h"
#include "content/browser/screenlock_monitor/screenlock_monitor_source.h"
#include "content/common/buildflags.h"
#include "content/public/browser/content_browser_client.h"
#include "content/public/browser/desktop_media_id.h"
#include "content/public/common/content_client.h"
#include "content/public/test/browser_task_environment.h"
#include "content/public/test/test_browser_context.h"
#include "media/base/media_switches.h"
#include "media/capture/video/fake_video_capture_device_factory.h"
#include "media/capture/video/video_capture_system_impl.h"
#include "services/video_effects/public/mojom/video_effects_processor.mojom-forward.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"
_;
AnyNumber;
DoAll;
InSequence;
InvokeWithoutArgs;
Mock;
NiceMock;
Return;
SaveArg;
namespace content {
namespace {
class WrappedDeviceFactory final : public media::FakeVideoCaptureDeviceFactory { … };
class MockMediaStreamProviderListener : public MediaStreamProviderListener { … };
class MockFrameObserver : public VideoCaptureControllerEventHandler { … };
class MockVideoCaptureObserver : public media::VideoCaptureObserver { … };
class ScreenlockMonitorTestSource : public ScreenlockMonitorSource { … };
#if !BUILDFLAG(IS_ANDROID)
class MockBrowserClient : public content::ContentBrowserClient { … };
#endif
}
class VideoCaptureManagerTest : public testing::Test { … };
TEST_F(VideoCaptureManagerTest, CreateAndClose) { … }
#if !BUILDFLAG(IS_CHROMEOS) && !BUILDFLAG(IS_ANDROID) && !BUILDFLAG(IS_FUCHSIA)
TEST_F(VideoCaptureManagerTest, CreateWithVideoEffectsProcessor) { … }
#endif
TEST_F(VideoCaptureManagerTest, CreateAndCloseMultipleTimes) { … }
TEST_F(VideoCaptureManagerTest, CreateAndAbort) { … }
TEST_F(VideoCaptureManagerTest, AddObserver) { … }
TEST_F(VideoCaptureManagerTest, OpenTwice) { … }
TEST_F(VideoCaptureManagerTest, ConnectAndDisconnectDevices) { … }
TEST_F(VideoCaptureManagerTest, ManipulateDeviceAndCheckCapabilities) { … }
TEST_F(VideoCaptureManagerTest,
ManipulateDeviceAndCheckCapabilitiesWithDeviceId) { … }
TEST_F(VideoCaptureManagerTest, StartDeviceAndGetDeviceFormatInUse) { … }
TEST_F(VideoCaptureManagerTest,
StartDeviceAndGetDeviceFormatInUseWithDeviceId) { … }
TEST_F(VideoCaptureManagerTest, OpenTwo) { … }
TEST_F(VideoCaptureManagerTest, OpenNotExisting) { … }
TEST_F(VideoCaptureManagerTest, StartInvalidSession) { … }
TEST_F(VideoCaptureManagerTest, CloseWithoutStop) { … }
TEST_F(VideoCaptureManagerTest, PauseAndResumeClient) { … }
#if BUILDFLAG(IS_ANDROID) && !BUILDFLAG(IS_DESKTOP_ANDROID)
TEST_F(VideoCaptureManagerTest, PauseAndResumeDevice) {
InSequence s;
EXPECT_CALL(*listener_,
Opened(blink::mojom::MediaStreamType::DEVICE_VIDEO_CAPTURE, _));
EXPECT_CALL(*frame_observer_, OnStarted(_));
EXPECT_CALL(*listener_,
Closed(blink::mojom::MediaStreamType::DEVICE_VIDEO_CAPTURE, _));
base::UnguessableToken video_session_id = vcm_->Open(devices_.front());
VideoCaptureControllerID client_id = StartClient(video_session_id, true);
ApplicationStateChange(
base::android::APPLICATION_STATE_HAS_RUNNING_ACTIVITIES);
ApplicationStateChange(
base::android::APPLICATION_STATE_HAS_STOPPED_ACTIVITIES);
ApplicationStateChange(
base::android::APPLICATION_STATE_HAS_STOPPED_ACTIVITIES);
ApplicationStateChange(
base::android::APPLICATION_STATE_HAS_RUNNING_ACTIVITIES);
ApplicationStateChange(
base::android::APPLICATION_STATE_HAS_RUNNING_ACTIVITIES);
StopClient(client_id);
vcm_->Close(video_session_id);
base::RunLoop().RunUntilIdle();
vcm_->UnregisterListener(listener_.get());
}
#elif !BUILDFLAG(IS_DESKTOP_ANDROID)
TEST_F(VideoCaptureManagerTest, PauseAndResumeDeviceOnScreenLock) { … }
TEST_F(VideoCaptureManagerTest, ScreenLockDoesNothingBeforeTimeout) { … }
#endif
TEST_F(VideoCaptureManagerTest, DeviceCaptureDeviceNotClosedOnScreenlock) { … }
#if BUILDFLAG(ENABLE_SCREEN_CAPTURE) && !BUILDFLAG(IS_ANDROID)
TEST_F(VideoCaptureManagerTest, DesktopCaptureDeviceClosedOnScreenlock) { … }
#endif
}