#include "third_party/blink/renderer/modules/mediastream/media_devices.h"
#include <memory>
#include <utility>
#include "base/test/metrics/histogram_tester.h"
#include "build/build_config.h"
#include "media/base/video_types.h"
#include "media/capture/mojom/video_capture_types.mojom.h"
#include "media/capture/video/video_capture_device_descriptor.h"
#include "media/capture/video_capture_types.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.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-forward.h"
#include "third_party/blink/public/mojom/mediastream/media_devices.mojom-blink.h"
#include "third_party/blink/public/mojom/mediastream/media_devices.mojom-shared.h"
#include "third_party/blink/renderer/bindings/core/v8/idl_types.h"
#include "third_party/blink/renderer/bindings/core/v8/native_value_traits.h"
#include "third_party/blink/renderer/bindings/core/v8/script_promise.h"
#include "third_party/blink/renderer/bindings/core/v8/script_promise_tester.h"
#include "third_party/blink/renderer/bindings/core/v8/to_v8_traits.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_binding_for_testing.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_capture_handle_config.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_crop_target.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_double_range.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_long_range.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_media_device_info.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_media_track_capabilities.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_restriction_target.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_user_media_stream_constraints.h"
#include "third_party/blink/renderer/core/dom/events/event.h"
#include "third_party/blink/renderer/core/dom/events/event_listener.h"
#include "third_party/blink/renderer/core/dom/events/native_event_listener.h"
#include "third_party/blink/renderer/core/event_type_names.h"
#include "third_party/blink/renderer/core/frame/local_dom_window.h"
#include "third_party/blink/renderer/core/html/html_element.h"
#include "third_party/blink/renderer/core/testing/page_test_base.h"
#include "third_party/blink/renderer/modules/mediastream/crop_target.h"
#include "third_party/blink/renderer/modules/mediastream/input_device_info.h"
#include "third_party/blink/renderer/modules/mediastream/media_device_info.h"
#include "third_party/blink/renderer/modules/mediastream/restriction_target.h"
#include "third_party/blink/renderer/platform/bindings/exception_state.h"
#include "third_party/blink/renderer/platform/testing/runtime_enabled_features_test_helpers.h"
#include "third_party/blink/renderer/platform/testing/testing_platform_support.h"
#include "third_party/blink/renderer/platform/weborigin/security_origin.h"
#include "third_party/blink/renderer/platform/wtf/functional.h"
#include "ui/gfx/geometry/mojom/geometry.mojom.h"
namespace blink {
HistogramTester;
MediaDeviceInfoPtr;
_;
ElementsAre;
StrictMock;
MediaDeviceType;
namespace {
String MaxLengthCaptureHandle() { … }
class MockMediaDevicesDispatcherHost final
: public mojom::blink::MediaDevicesDispatcherHost { … };
class MockDeviceChangeEventListener : public NativeEventListener { … };
String ToString(MediaDeviceType type) { … }
void VerifyFacingMode(const Vector<String>& js_facing_mode,
blink::mojom::FacingMode cpp_facing_mode) { … }
void VerifyDeviceInfo(const MediaDeviceInfo* device,
const WebMediaDeviceInfo& expected,
MediaDeviceType type) { … }
void VerifyVideoInputCapabilities(
const MediaDeviceInfo* device,
const WebMediaDeviceInfo& expected_device_info,
const mojom::blink::VideoInputDeviceCapabilitiesPtr&
expected_capabilities) { … }
#if !BUILDFLAG(IS_ANDROID) && !BUILDFLAG(IS_IOS)
SubCaptureTarget* ToSubCaptureTarget(const blink::ScriptValue& value) { … }
#endif
ScriptPromiseUntyped ProduceSubCaptureTargetAndGetPromise(
V8TestingScope& scope,
SubCaptureTarget::Type type,
MediaDevices* media_devices,
Element* element) { … }
#if !BUILDFLAG(IS_ANDROID) && !BUILDFLAG(IS_IOS)
void ProduceSubCaptureTargetAndGetTester(
V8TestingScope& scope,
SubCaptureTarget::Type type,
MediaDevices* media_devices,
Element* element,
std::optional<ScriptPromiseTester>& tester) { … }
#endif
}
class MediaDevicesTest : public PageTestBase { … };
TEST_F(MediaDevicesTest, GetUserMediaCanBeCalled) { … }
TEST_F(MediaDevicesTest, EnumerateDevices) { … }
TEST_F(MediaDevicesTest, EnumerateDevicesAfterConnectionError) { … }
TEST_F(MediaDevicesTest, SetCaptureHandleConfigAfterConnectionError) { … }
TEST_F(MediaDevicesTest, ObserveDeviceChangeEvent) { … }
TEST_F(MediaDevicesTest, RemoveDeviceFiresDeviceChange) { … }
TEST_F(MediaDevicesTest, RenameDeviceIDFiresDeviceChange) { … }
TEST_F(MediaDevicesTest, RenameLabelFiresDeviceChange) { … }
TEST_F(MediaDevicesTest, SetCaptureHandleConfigEmpty) { … }
TEST_F(MediaDevicesTest, SetCaptureHandleConfigWithExposeOrigin) { … }
TEST_F(MediaDevicesTest, SetCaptureHandleConfigCaptureWithHandle) { … }
TEST_F(MediaDevicesTest, SetCaptureHandleConfigCaptureWithMaxHandle) { … }
TEST_F(MediaDevicesTest,
SetCaptureHandleConfigCaptureWithOverMaxHandleRejected) { … }
TEST_F(MediaDevicesTest,
SetCaptureHandleConfigCaptureWithPermittedOriginsWildcard) { … }
TEST_F(MediaDevicesTest, SetCaptureHandleConfigCaptureWithPermittedOrigins) { … }
TEST_F(MediaDevicesTest,
SetCaptureHandleConfigCaptureWithWildcardAndSomethingElseRejected) { … }
TEST_F(MediaDevicesTest,
SetCaptureHandleConfigCaptureWithMalformedOriginRejected) { … }
#if !BUILDFLAG(IS_ANDROID) && !BUILDFLAG(IS_IOS)
TEST_F(MediaDevicesTest, DistinctIdsForDistinctTypes) { … }
#endif
class ProduceSubCaptureTargetTest
: public MediaDevicesTest,
public testing::WithParamInterface<
std::pair<SubCaptureTarget::Type, bool>> { … };
INSTANTIATE_TEST_SUITE_P(…);
TEST_P(ProduceSubCaptureTargetTest, IdUnsupportedOnAndroid) { … }
#if !BUILDFLAG(IS_ANDROID) && !BUILDFLAG(IS_IOS)
TEST_P(ProduceSubCaptureTargetTest, IdWithValidElement) { … }
TEST_P(ProduceSubCaptureTargetTest, IdRejectedIfDifferentWindow) { … }
TEST_P(ProduceSubCaptureTargetTest, DuplicateId) { … }
TEST_P(ProduceSubCaptureTargetTest, CorrectTokenClassInstantiated) { … }
TEST_P(ProduceSubCaptureTargetTest, IdStringFormat) { … }
#endif
}