chromium/third_party/blink/renderer/modules/mediastream/capture_controller_test.cc

// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#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 {};

// TODO(crbug.com/1505223): Avoid this helper's duplication throughout Blink.
bool IsDOMException(ScriptState* script_state,
                    const ScriptValue& value,
                    DOMExceptionCode code) {}

bool IsDOMException(V8TestingScope& v8_scope,
                    const ScriptValue& value,
                    DOMExceptionCode code) {}

// Note that we don't actually care what the message is. We use this as a way
// to sanity-check the tests themselves against false-positives through
// failures on different code paths that yield the same DOMException.
String GetDOMExceptionMessage(ScriptState* script_state,
                              const ScriptValue& value) {}
String GetDOMExceptionMessage(V8TestingScope& v8_scope,
                              const ScriptValue& value) {}

// Extract the MediaStreamVideoTrack which the test has previously injected
// into the track. CHECKs and casts used here are valid because this is a
// controlled test environment.
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)) {}

}  // namespace

class CaptureControllerTestSupport {};

class CaptureControllerBaseTest : public testing::Test,
                                  public CaptureControllerTestSupport {};

// Test suite for CaptureController functionality from the Captured Surface
// Control spec, focusing on reading the supported zoom levels.
class CaptureControllerGetSupportedZoomLevelsTest
    : public CaptureControllerBaseTest {};

TEST_F(CaptureControllerGetSupportedZoomLevelsTest,
       ReturnsMonotonicallyIncreasingSequence) {}

// Test suite for CaptureController functionality from the
// Captured Surface Control spec, focusing on GetZoomLevel.
class CaptureControllerGetZoomLevelTest : public CaptureControllerBaseTest {};

TEST_F(CaptureControllerGetZoomLevelTest,
       GetZoomLevelFailsIfCaptureControllerNotBound) {}

TEST_F(CaptureControllerGetZoomLevelTest,
       GetZoomLevelFailsIfCaptureControllerBoundButNoVideoTrack) {}

TEST_F(CaptureControllerGetZoomLevelTest, GetZoomLevelFailsIfVideoTrackEnded) {}

TEST_F(CaptureControllerGetZoomLevelTest, GetZoomLevelSuccessInitialZoomLevel) {}

TEST_F(CaptureControllerGetZoomLevelTest, GetZoomLevelSuccessZoomLevelUpdate) {}

// Note that the setup differs from that of GetZoomLevelSuccessInitialZoomLevel
// only in the SurfaceType provided to MakeTrack().
TEST_F(CaptureControllerGetZoomLevelTest, GetZoomLevelFailsIfCapturingWindow) {}

// Note that the setup differs from that of GetZoomLevelSuccessInitialZoomLevel
// only in the SurfaceType provided to MakeTrack().
TEST_F(CaptureControllerGetZoomLevelTest, GetZoomLevelFailsIfCapturingMonitor) {}

// Test suite for CaptureController functionality from the Captured Surface
// Control spec, focusing on OnCapturedZoomLevelChange events.
class CaptureControllerOnCapturedZoomLevelChangeTest
    : public CaptureControllerBaseTest {};

TEST_F(CaptureControllerOnCapturedZoomLevelChangeTest, NoEventOnInit) {}

TEST_F(CaptureControllerOnCapturedZoomLevelChangeTest,
       EventWhenDifferentFromInitValue) {}

TEST_F(CaptureControllerOnCapturedZoomLevelChangeTest,
       NoEventWhenSameAsInitValue) {}

TEST_F(CaptureControllerOnCapturedZoomLevelChangeTest,
       EventWhenDifferentFromPreviousUpdate) {}

TEST_F(CaptureControllerOnCapturedZoomLevelChangeTest,
       EventWhenSameAsPreviousUpdate) {}

// Test suite for CaptureController functionality from the
// Captured Surface Control spec, focusing on SetZoomLevel.
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) {}

// This test is distinct from SetZoomLevelFailsIfLevelTooLow and
// SetZoomLevelFailsIfLevelTooHigh in that it uses a value that's within the
// permitted range, thereby ensuring that the validation does not just check
// the range, but rather actually uses the supported value as an allowlist.
TEST_F(CaptureControllerSetZoomLevelTest, SetZoomLevelFailsIfUnsupportedValue) {}

// Note that the setup differs from that of SetZoomLevelSuccess only in the
// SurfaceType provided to MakeTrack().
TEST_F(CaptureControllerSetZoomLevelTest, SetZoomLevelFailsIfCapturingWindow) {}

// Note that the setup differs from that of SetZoomLevelSuccess only in the
// SurfaceType provided to MakeTrack().
TEST_F(CaptureControllerSetZoomLevelTest, SetZoomLevelFailsIfCapturingMonitor) {}

// Note that the setup differs from that of SetZoomLevelSuccess only in the
// simulated result from the browser process.
TEST_F(CaptureControllerSetZoomLevelTest, SimulatedFailureFromDispatcherHost) {}

TEST_F(CaptureControllerSetZoomLevelTest, SetZoomLevelFailsWithoutSessionId) {}

// Test suite for CaptureController functionality from the
// Captured Surface Control spec, focusing on scroll-control.
class CaptureControllerScrollTest : public CaptureControllerBaseTest {};

TEST_F(CaptureControllerScrollTest, SendWheelFailsIfCaptureControllerNotBound) {}

TEST_F(CaptureControllerScrollTest,
       SendWheelFailsIfCaptureControllerBoundButNoVideoTrack) {}

TEST_F(CaptureControllerScrollTest, SendWheelFailsIfVideoTrackEnded) {}

TEST_F(CaptureControllerScrollTest, SendWheelSuccess) {}

// Note that the setup differs from that of SendWheelSuccess only in the
// SurfaceType provided to MakeTrack().
TEST_F(CaptureControllerScrollTest, SendWheelFailsIfCapturingWindow) {}

// Note that the setup differs from that of SendWheelSuccess only in the
// SurfaceType provided to MakeTrack().
TEST_F(CaptureControllerScrollTest, SendWheelFailsIfCapturingMonitor) {}

// Note that the setup differs from that of SendWheelSuccess only in the
// simulated result from the browser process.
TEST_F(CaptureControllerScrollTest, SimulatedFailureFromDispatcherHost) {}

// Note that the setup differs from that of SendWheelSuccess only in the
// absence of a call to SimulateFrameArrival().
TEST_F(CaptureControllerScrollTest, SendWheelFailsBeforeReceivingFrames) {}

// This test:
// * Simulates the arrival of a frame of a given size.
// * Simulates a call to sendWheel() at a specific point.
// * Expects scaling.
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) {}

// Test the validation of sendWheel() parameters.
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();
}  // namespace

TEST_P(CaptureControllerScrollParametersValidationTest, ValidateCoordinates) {}

}  // namespace blink