#include "third_party/blink/renderer/modules/mediastream/browser_capture_media_stream_track.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/uuid.h"
#include "build/build_config.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/web/web_heap.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/modules/mediastream/crop_target.h"
#include "third_party/blink/renderer/modules/mediastream/media_stream_video_track.h"
#include "third_party/blink/renderer/modules/mediastream/mock_media_stream_video_source.h"
#include "third_party/blink/renderer/modules/mediastream/sub_capture_target.h"
#include "third_party/blink/renderer/platform/mediastream/media_stream_component_impl.h"
#include "third_party/blink/renderer/platform/region_capture_crop_id.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 {
_;
Args;
Invoke;
Mock;
Return;
std::unique_ptr<MockMediaStreamVideoSource> MakeMockMediaStreamVideoSource() { … }
BrowserCaptureMediaStreamTrack* MakeTrack(
V8TestingScope& v8_scope,
std::unique_ptr<MockMediaStreamVideoSource> media_stream_video_source) { … }
}
class BrowserCaptureMediaStreamTrackTest
: public testing::Test,
public testing::WithParamInterface<SubCaptureTarget::Type> { … };
INSTANTIATE_TEST_SUITE_P(…);
#if !BUILDFLAG(IS_ANDROID)
TEST_P(BrowserCaptureMediaStreamTrackTest,
ApplySubCaptureTargetOnValidIdResultFirst) { … }
TEST_P(BrowserCaptureMediaStreamTrackTest,
ApplySubCaptureTargetRejectsIfResultFromBrowserProcessIsNotSuccess) { … }
TEST_P(
BrowserCaptureMediaStreamTrackTest,
ApplySubCaptureTargetRejectsIfSourceReturnsNulloptForNextSubCaptureTargetVersion) { … }
#else
TEST_P(BrowserCaptureMediaStreamTrackTest,
ApplySubCaptureTargetFailsOnAndroid) {
V8TestingScope v8_scope;
const base::Uuid valid_id = base::Uuid::GenerateRandomV4();
std::unique_ptr<MockMediaStreamVideoSource> media_stream_video_source =
MakeMockMediaStreamVideoSource();
EXPECT_CALL(*media_stream_video_source, ApplySubCaptureTarget(type_, _, _, _))
.Times(0);
BrowserCaptureMediaStreamTrack* const track =
MakeTrack(v8_scope, std::move(media_stream_video_source));
const ScriptPromiseUntyped promise = ApplySubCaptureTarget(
v8_scope, *track, WTF::String(valid_id.AsLowercaseString()));
ScriptPromiseTester script_promise_tester(v8_scope.GetScriptState(), promise);
script_promise_tester.WaitUntilSettled();
EXPECT_TRUE(script_promise_tester.IsRejected());
CheckHistograms(
1,
BrowserCaptureMediaStreamTrack::ApplySubCaptureTargetResult::
kUnsupportedPlatform);
}
#endif
TEST_P(BrowserCaptureMediaStreamTrackTest, CloningPreservesConstraints) { … }
}