#include "third_party/blink/renderer/modules/mediastream/capture_controller.h"
#include <tuple>
#include "base/run_loop.h"
#include "base/test/gmock_callback_support.h"
#include "base/unguessable_token.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/common/input/web_mouse_wheel_event.h"
#include "third_party/blink/public/mojom/mediastream/media_stream.mojom-blink.h"
#include "third_party/blink/renderer/bindings/core/v8/script_promise_tester.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_binding_for_core.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_binding_for_testing.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_dom_exception.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_wheel_event_init.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_captured_wheel_action.h"
#include "third_party/blink/renderer/core/dom/dom_exception.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/events/wheel_event.h"
#include "third_party/blink/renderer/core/execution_context/execution_context.h"
#include "third_party/blink/renderer/core/html/html_div_element.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/browser_capture_media_stream_track.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/mock_mojo_media_stream_dispatcher_host.h"
#include "third_party/blink/renderer/platform/mediastream/media_stream_component_impl.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"
#include "third_party/blink/renderer/platform/testing/testing_platform_support.h"
#include "ui/gfx/geometry/point.h"
#include "ui/gfx/geometry/size.h"
namespace blink {
namespace {
SurfaceType;
RunOnceCallback;
RunOnceCallbackRepeatedly;
_;
Combine;
DoAll;
Invoke;
Mock;
SaveArgPointee;
StrictMock;
Values;
WithParamInterface;
CscResult;
enum class ScrollDirection { … };
class MockEventListener : public NativeEventListener { … };
bool IsDOMException(ScriptState* script_state,
const ScriptValue& value,
DOMExceptionCode code) { … }
bool IsDOMException(V8TestingScope& v8_scope,
const ScriptValue& value,
DOMExceptionCode code) { … }
String GetDOMExceptionMessage(ScriptState* script_state,
const ScriptValue& value) { … }
String GetDOMExceptionMessage(V8TestingScope& v8_scope,
const ScriptValue& value) { … }
MediaStreamVideoTrack* GetMediaStreamVideoTrack(MediaStreamTrack* track) { … }
MediaStreamTrack* MakeTrack(
ExecutionContext* execution_context,
SurfaceType display_surface,
int initial_zoom_level = CaptureController::getSupportedZoomLevels()[0],
bool use_session_id = true) { … }
MediaStreamTrack* MakeTrack(
V8TestingScope& testing_scope,
SurfaceType display_surface,
int initial_zoom_level = CaptureController::getSupportedZoomLevels()[0],
bool use_session_id = true) { … }
void SimulateFrameArrival(MediaStreamTrack* track,
gfx::Size frame_size = gfx::Size(1000, 1000)) { … }
}
class CaptureControllerTestSupport { … };
class CaptureControllerBaseTest : public testing::Test,
public CaptureControllerTestSupport { … };
class CaptureControllerGetSupportedZoomLevelsTest
: public CaptureControllerBaseTest { … };
TEST_F(CaptureControllerGetSupportedZoomLevelsTest,
ReturnsMonotonicallyIncreasingSequence) { … }
class CaptureControllerGetZoomLevelTest : public CaptureControllerBaseTest { … };
TEST_F(CaptureControllerGetZoomLevelTest,
GetZoomLevelFailsIfCaptureControllerNotBound) { … }
TEST_F(CaptureControllerGetZoomLevelTest,
GetZoomLevelFailsIfCaptureControllerBoundButNoVideoTrack) { … }
TEST_F(CaptureControllerGetZoomLevelTest, GetZoomLevelFailsIfVideoTrackEnded) { … }
TEST_F(CaptureControllerGetZoomLevelTest, GetZoomLevelSuccessInitialZoomLevel) { … }
TEST_F(CaptureControllerGetZoomLevelTest, GetZoomLevelSuccessZoomLevelUpdate) { … }
TEST_F(CaptureControllerGetZoomLevelTest, GetZoomLevelFailsIfCapturingWindow) { … }
TEST_F(CaptureControllerGetZoomLevelTest, GetZoomLevelFailsIfCapturingMonitor) { … }
class CaptureControllerOnCapturedZoomLevelChangeTest
: public CaptureControllerBaseTest { … };
TEST_F(CaptureControllerOnCapturedZoomLevelChangeTest, NoEventOnInit) { … }
TEST_F(CaptureControllerOnCapturedZoomLevelChangeTest,
EventWhenDifferentFromInitValue) { … }
TEST_F(CaptureControllerOnCapturedZoomLevelChangeTest,
NoEventWhenSameAsInitValue) { … }
TEST_F(CaptureControllerOnCapturedZoomLevelChangeTest,
EventWhenDifferentFromPreviousUpdate) { … }
TEST_F(CaptureControllerOnCapturedZoomLevelChangeTest,
EventWhenSameAsPreviousUpdate) { … }
class CaptureControllerSetZoomLevelTest : public CaptureControllerBaseTest { … };
TEST_F(CaptureControllerSetZoomLevelTest,
SetZoomLevelFailsIfCaptureControllerNotBound) { … }
TEST_F(CaptureControllerSetZoomLevelTest,
SetZoomLevelFailsIfCaptureControllerBoundButNoVideoTrack) { … }
TEST_F(CaptureControllerSetZoomLevelTest, SetZoomLevelFailsIfVideoTrackEnded) { … }
TEST_F(CaptureControllerSetZoomLevelTest, SetZoomLevelSuccessIfSupportedValue) { … }
TEST_F(CaptureControllerSetZoomLevelTest, SetZoomLevelFailsIfLevelTooLow) { … }
TEST_F(CaptureControllerSetZoomLevelTest, SetZoomLevelFailsIfLevelTooHigh) { … }
TEST_F(CaptureControllerSetZoomLevelTest, SetZoomLevelFailsIfUnsupportedValue) { … }
TEST_F(CaptureControllerSetZoomLevelTest, SetZoomLevelFailsIfCapturingWindow) { … }
TEST_F(CaptureControllerSetZoomLevelTest, SetZoomLevelFailsIfCapturingMonitor) { … }
TEST_F(CaptureControllerSetZoomLevelTest, SimulatedFailureFromDispatcherHost) { … }
TEST_F(CaptureControllerSetZoomLevelTest, SetZoomLevelFailsWithoutSessionId) { … }
class CaptureControllerScrollTest : public CaptureControllerBaseTest { … };
TEST_F(CaptureControllerScrollTest, SendWheelFailsIfCaptureControllerNotBound) { … }
TEST_F(CaptureControllerScrollTest,
SendWheelFailsIfCaptureControllerBoundButNoVideoTrack) { … }
TEST_F(CaptureControllerScrollTest, SendWheelFailsIfVideoTrackEnded) { … }
TEST_F(CaptureControllerScrollTest, SendWheelSuccess) { … }
TEST_F(CaptureControllerScrollTest, SendWheelFailsIfCapturingWindow) { … }
TEST_F(CaptureControllerScrollTest, SendWheelFailsIfCapturingMonitor) { … }
TEST_F(CaptureControllerScrollTest, SimulatedFailureFromDispatcherHost) { … }
TEST_F(CaptureControllerScrollTest, SendWheelFailsBeforeReceivingFrames) { … }
TEST_F(CaptureControllerScrollTest, SendWheelScalesCorrectly) { … }
TEST_F(CaptureControllerScrollTest, SendWheelFailsWithoutSessionId) { … }
class CaptureConstrollerCaptureWheelTest : public PageTestBase,
public CaptureControllerTestSupport { … };
TEST_F(CaptureConstrollerCaptureWheelTest, Success) { … }
TEST_F(CaptureConstrollerCaptureWheelTest, SuccessWithNoElement) { … }
TEST_F(CaptureConstrollerCaptureWheelTest, BackendError) { … }
TEST_F(CaptureConstrollerCaptureWheelTest, NoSessionId) { … }
TEST_F(CaptureConstrollerCaptureWheelTest, NoTrack) { … }
TEST_F(CaptureConstrollerCaptureWheelTest, StoppedTrack) { … }
class CaptureControllerScrollParametersValidationTest
: public CaptureControllerScrollTest,
public WithParamInterface<
std::tuple<std::tuple<ScrollDirection, ScrollDirection>,
std::tuple<gfx::Point, bool>>> { … };
namespace {
constexpr int kLeftmost = …;
constexpr int kRightmost = …;
constexpr int kTop = …;
constexpr int kBottom = …;
INSTANTIATE_TEST_SUITE_P(…);
}
TEST_P(CaptureControllerScrollParametersValidationTest, ValidateCoordinates) { … }
}