chromium/content/browser/media/captured_surface_controller_unittest.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 "content/browser/media/captured_surface_controller.h"

#include <limits>
#include <list>
#include <memory>

#include "base/functional/bind.h"
#include "base/notreached.h"
#include "base/run_loop.h"
#include "base/test/scoped_feature_list.h"
#include "content/browser/host_zoom_map_impl.h"
#include "content/browser/media/captured_surface_control_permission_manager.h"
#include "content/common/features.h"
#include "content/public/browser/global_routing_id.h"
#include "content/public/test/browser_task_environment.h"
#include "content/test/test_web_contents.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/common/page/page_zoom.h"
#include "third_party/blink/public/mojom/mediastream/media_stream.mojom.h"
#include "url/gurl.h"

namespace content {
namespace {

CapturedWheelAction;
CapturedWheelActionPtr;
CSCResult;
CSCPermissionResult;

const char* const kUrlString =;

enum class Boundary {};

// Make an arbitrary valid CapturedWheelAction.
CapturedWheelActionPtr MakeCapturedWheelActionPtr() {}

class InputObserver : public RenderWidgetHost::InputEventObserver {};

class TestView : public TestRenderWidgetHostView {};

// Simulates a tab.
//
// Wraps a `WebContents`, which is the main object of interest, along with a
// `TestView`, which is essentially a `RenderWidgetHostView` that allows us to
// set a custom size, which is needed when testing SendWheel().
//
// This object records the original `RenderWidgetHostView` and injects it back
// from the destructor. This prevents LSAN/ASAN failures. This functionality is
// the main value proposition of this class.
class TestTab {};

class MockCapturedSurfaceControlPermissionManager
    : public CapturedSurfaceControlPermissionManager {};

MockPermissionManager;

class MockObserver : public content::WebContentsObserver {};

// Make a callback that expects `result` and then unblock `run_loop`.
base::OnceCallback<void(CSCResult)> MakeCallbackExpectingResult(
    base::RunLoop* run_loop,
    CSCResult expected_result) {}

class CapturedSurfaceControllerTestBase : public RenderViewHostTestHarness {};

class CapturedSurfaceControllerSendWheelTest
    : public CapturedSurfaceControllerTestBase {};

TEST_F(CapturedSurfaceControllerSendWheelTest, CorrectScaling) {}

TEST_F(CapturedSurfaceControllerSendWheelTest,
       GracefullyHandleZeroWidthCapturedSurface) {}

TEST_F(CapturedSurfaceControllerSendWheelTest,
       GracefullyHandleZeroHeightCapturedSurface) {}

TEST_F(CapturedSurfaceControllerSendWheelTest,
       GracefullyHandleExtremelyNarrowCapturedSurface) {}

TEST_F(CapturedSurfaceControllerSendWheelTest,
       GracefullyHandleExtremelyShortCapturedSurface) {}

class CapturedSurfaceControllerZoomEventTest
    : public CapturedSurfaceControllerTestBase {};

TEST_F(CapturedSurfaceControllerZoomEventTest, ZoomEvent) {}

TEST_F(CapturedSurfaceControllerZoomEventTest, ZoomEventUpdateTarget) {}

class CapturedSurfaceControllerSetZoomLevelTest
    : public CapturedSurfaceControllerTestBase,
      public ::testing::WithParamInterface<int> {};

INSTANTIATE_TEST_SUITE_P();

TEST_P(CapturedSurfaceControllerSetZoomLevelTest, SetZoomLevelSuccess) {}

class CapturedSurfaceControllerSetZoomTemporarinessTest
    : public CapturedSurfaceControllerTestBase,
      public ::testing::WithParamInterface<bool> {};

INSTANTIATE_TEST_SUITE_P();

TEST_P(CapturedSurfaceControllerSetZoomTemporarinessTest,
       TemporarinessDependsOnConfiguration) {}

enum class CapturedSurfaceControlAPI {};

class CapturedSurfaceControllerInterfaceTestBase
    : public CapturedSurfaceControllerTestBase {};

class CapturedSurfaceControllerInterfaceTest
    : public CapturedSurfaceControllerInterfaceTestBase,
      public ::testing::WithParamInterface<CapturedSurfaceControlAPI> {};

INSTANTIATE_TEST_SUITE_P();

TEST_P(CapturedSurfaceControllerInterfaceTest, SuccessReportedIfPermitted) {}

TEST_P(CapturedSurfaceControllerInterfaceTest, NoPermissionReportedIfDenied) {}

TEST_P(CapturedSurfaceControllerInterfaceTest,
       UnknownErrorReportedIfPermissionError) {}

// Simulate the captured tab being closed after permission is granted but before
// the controller has time to process the response from the permission manager.
TEST_P(CapturedSurfaceControllerInterfaceTest,
       SurfaceNotFoundReportedIfTabClosedBeforePromptResponseHandled) {}

TEST_P(CapturedSurfaceControllerInterfaceTest,
       SurfaceNotFoundReportedIfCaptureTargetUpdatedToNonTabSurface) {}

TEST_P(CapturedSurfaceControllerInterfaceTest,
       CapturerNotFoundErrorReportedIfCapturerClosed) {}

// Test suite ensuring that API calls before/after the WebContents ID is
// resolved to a base::WeakPtr<WebContents> behave as expected.
class CapturedSurfaceControllerWebContentsResolutionTest
    : public CapturedSurfaceControllerInterfaceTestBase,
      public ::testing::WithParamInterface<CapturedSurfaceControlAPI> {};

INSTANTIATE_TEST_SUITE_P();

TEST_P(CapturedSurfaceControllerWebContentsResolutionTest,
       ApiInvocationAfterWebContentsResolutionSucceeds) {}

TEST_P(CapturedSurfaceControllerWebContentsResolutionTest,
       ApiInvocationPriorToWebContentsResolutionFails) {}

TEST_P(
    CapturedSurfaceControllerWebContentsResolutionTest,
    ApiInvocationPriorToWebContentsResolutionFailsButSubsequentCallsAreNotBlocked) {}

TEST_P(CapturedSurfaceControllerWebContentsResolutionTest,
       MultiplePendingResolutions) {}

// Similar to CapturedSurfaceControllerWebContentsResolutionTest,
// but focuses on calls to UpdateCaptureTarget(), which also trigger resolution.
class CapturedSurfaceControllerWebContentsResolutionOfUpdatesTest
    : public CapturedSurfaceControllerInterfaceTestBase,
      public ::testing::WithParamInterface<CapturedSurfaceControlAPI> {};

INSTANTIATE_TEST_SUITE_P();

TEST_P(
    CapturedSurfaceControllerWebContentsResolutionOfUpdatesTest,
    AfterUpdateCaptureTargetApiInvocationAfterToWebContentsResolutionSucceeds) {}

TEST_P(CapturedSurfaceControllerWebContentsResolutionOfUpdatesTest,
       AfterUpdateCaptureTargetApiInvocationPriorToWebContentsResolutionFails) {}

// Test suite ensuring that API calls before/after the WebContents ID is
// resolved to a base::WeakPtr<WebContents> behave as expected.
class CapturedSurfaceControllerSelfCaptureTest
    : public CapturedSurfaceControllerInterfaceTestBase,
      public ::testing::WithParamInterface<CapturedSurfaceControlAPI> {};

INSTANTIATE_TEST_SUITE_P();

TEST_P(CapturedSurfaceControllerSelfCaptureTest, SelfCaptureDisallowed) {}

TEST_P(CapturedSurfaceControllerSelfCaptureTest,
       UpdateCaptureTargetToOtherTabEnablesCapturedSurfaceControl) {}

TEST_P(CapturedSurfaceControllerSelfCaptureTest,
       UpdateCaptureTargetToCapturingTabDisablesCapturedSurfaceControl) {}

// This test suite checks correct clamping of x/y wheel-deltas to min/max.
//
// The suite is parameterized on the *zoom* level because that affects
// the values that will ultimately be fed into the UI system, and checking
// at both the min/max zoom levels increases coverage somewhat.
//
// The suite is *not* parameterized on the wheel deltas themselves, as that
// would increase test complexity and reduce confidence in test correctness.
class CapturedSurfaceControllerSendWheelClampTest
    : public CapturedSurfaceControllerSendWheelTest,
      public ::testing::WithParamInterface<Boundary> {};

INSTANTIATE_TEST_SUITE_P();

TEST_P(CapturedSurfaceControllerSendWheelClampTest, ClampMinWheelDeltaX) {}

TEST_P(CapturedSurfaceControllerSendWheelClampTest, ClampMaxWheelDeltaX) {}

TEST_P(CapturedSurfaceControllerSendWheelClampTest, ClampMinWheelDeltaY) {}

TEST_P(CapturedSurfaceControllerSendWheelClampTest, ClampMaxWheelDeltaY) {}

class WebContentsObserverCscNotifiedTest
    : public CapturedSurfaceControllerTestBase {};

TEST_F(WebContentsObserverCscNotifiedTest, NotifiedBySendWheelIfSuccessful) {}

TEST_F(WebContentsObserverCscNotifiedTest, NotifiedBySetZoomLevelIfSuccessful) {}

TEST_F(WebContentsObserverCscNotifiedTest,
       NotNotifiedBySendWheelIfUnsuccessful) {}

TEST_F(WebContentsObserverCscNotifiedTest,
       NotNotifiedBySetZoomLevelIfUnsuccessful) {}

}  // namespace
}  // namespace content