#include "third_party/blink/renderer/modules/mediastream/media_stream_track_impl.h"
#include <tuple>
#include "base/run_loop.h"
#include "base/test/gmock_callback_support.h"
#include "base/test/scoped_feature_list.h"
#include "media/base/video_frame.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/mojom/mediastream/media_devices.mojom-blink.h"
#include "third_party/blink/public/platform/scheduler/test/renderer_scheduler_test_support.h"
#include "third_party/blink/public/web/modules/mediastream/media_stream_video_source.h"
#include "third_party/blink/public/web/web_heap.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/v8_binding_for_testing.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_constrain_long_range.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_media_track_constraints.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_union_constrainlongrange_long.h"
#include "third_party/blink/renderer/core/streams/readable_stream.h"
#include "third_party/blink/renderer/core/streams/readable_stream_default_reader.h"
#include "third_party/blink/renderer/modules/mediastream/apply_constraints_processor.h"
#include "third_party/blink/renderer/modules/mediastream/local_media_stream_audio_source.h"
#include "third_party/blink/renderer/modules/mediastream/media_constraints.h"
#include "third_party/blink/renderer/modules/mediastream/media_constraints_impl.h"
#include "third_party/blink/renderer/modules/mediastream/media_stream_constraints_util_video_content.h"
#include "third_party/blink/renderer/modules/mediastream/media_stream_video_track.h"
#include "third_party/blink/renderer/modules/mediastream/mock_media_stream_video_sink.h"
#include "third_party/blink/renderer/modules/mediastream/mock_media_stream_video_source.h"
#include "third_party/blink/renderer/platform/bindings/exception_state.h"
#include "third_party/blink/renderer/platform/mediastream/media_stream_audio_source.h"
#include "third_party/blink/renderer/platform/mediastream/media_stream_audio_track.h"
#include "third_party/blink/renderer/platform/mediastream/media_stream_component_impl.h"
#include "third_party/blink/renderer/platform/mediastream/media_stream_source.h"
#include "third_party/blink/renderer/platform/testing/io_task_runner_testing_platform_support.h"
#include "third_party/blink/renderer/platform/testing/task_environment.h"
_;
namespace blink {
namespace {
const gfx::Size kTestScreenSize{ … };
constexpr int kReducedWidth = …;
constexpr int kReducedHeight = …;
constexpr float kAspectRatio = …;
constexpr float kMaxFrameRate = …;
constexpr float kMinFrameRate = …;
class TestObserver : public GarbageCollected<TestObserver>,
public MediaStreamTrack::Observer { … };
std::unique_ptr<MockMediaStreamVideoSource> MakeMockMediaStreamVideoSource() { … }
std::unique_ptr<blink::LocalMediaStreamAudioSource>
MakeLocalMediaStreamAudioSource() { … }
MediaStreamComponent* MakeMockVideoComponent() { … }
MediaStreamComponent* MakeMockAudioComponent() { … }
media::VideoCaptureFormat GetDefaultVideoContentCaptureFormat() { … }
std::tuple<MediaStreamComponent*, MockMediaStreamVideoSource*>
MakeMockDisplayVideoCaptureComponent() { … }
MediaTrackConstraints* MakeMediaTrackConstraints(
std::optional<int> exact_width,
std::optional<int> exact_height,
std::optional<float> min_frame_rate,
std::optional<float> max_frame_rate,
std::optional<float> aspect_ratio = std::nullopt) { … }
}
class MediaStreamTrackImplTest : public testing::Test { … };
TEST_F(MediaStreamTrackImplTest, StopTrackTriggersObservers) { … }
TEST_F(MediaStreamTrackImplTest, StopTrackSynchronouslyDisablesMedia) { … }
TEST_F(MediaStreamTrackImplTest, MutedStateUpdates) { … }
TEST_F(MediaStreamTrackImplTest, MutedDoesntUpdateAfterEnding) { … }
TEST_F(MediaStreamTrackImplTest, CloneVideoTrack) { … }
TEST_F(MediaStreamTrackImplTest, CloneAudioTrack) { … }
TEST_F(MediaStreamTrackImplTest, CloningPreservesConstraints) { … }
TEST_F(MediaStreamTrackImplTest, ApplyConstraintsUpdatesSourceFormat) { … }
TEST_F(MediaStreamTrackImplTest,
ApplyConstraintsFramerateDoesNotAffectResolution) { … }
TEST_F(MediaStreamTrackImplTest,
ApplyConstraintsResolutionDoesNotAffectFramerate) { … }
TEST_F(MediaStreamTrackImplTest,
ApplyConstraintsWidthDoesNotAffectAspectRatio) { … }
TEST_F(MediaStreamTrackImplTest, ApplyConstraintsWidthAndAspectRatio) { … }
#if BUILDFLAG(IS_ANDROID)
#define MAYBE_ApplyConstraintsDoesNotUpdateFormatForCroppedSources …
#else
#define MAYBE_ApplyConstraintsDoesNotUpdateFormatForCroppedSources …
#endif
TEST_F(MediaStreamTrackImplTest,
MAYBE_ApplyConstraintsDoesNotUpdateFormatForCroppedSources) { … }
TEST_F(MediaStreamTrackImplTest,
ApplyConstraintsDoesNotUpdateSourceFormatIfDisabled) { … }
TEST_F(MediaStreamTrackImplTest, ApplyConstraintsWithUnchangedConstraints) { … }
TEST_F(MediaStreamTrackImplTest, ApplyConstraintsCannotRestartSource) { … }
TEST_F(MediaStreamTrackImplTest, ApplyConstraintsUpdatesMinFps) { … }
}