chromium/third_party/blink/renderer/modules/document_picture_in_picture/picture_in_picture_controller_test.cc

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

#include <memory>
#include <utility>

#include "base/containers/contains.h"
#include "base/memory/raw_ptr.h"
#include "media/mojo/mojom/media_player.mojom-blink.h"
#include "mojo/public/cpp/bindings/pending_associated_remote.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/platform/browser_interface_broker_proxy.h"
#include "third_party/blink/renderer/bindings/core/v8/script_promise.h"
#include "third_party/blink/renderer/bindings/core/v8/script_promise_resolver.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/core/dom/dom_exception.h"
#include "third_party/blink/renderer/core/dom/events/event.h"
#include "third_party/blink/renderer/core/frame/frame_test_helpers.h"
#include "third_party/blink/renderer/core/frame/web_local_frame_impl.h"
#include "third_party/blink/renderer/core/html/media/html_media_test_helper.h"
#include "third_party/blink/renderer/core/html/media/html_video_element.h"
#include "third_party/blink/renderer/core/layout/layout_image.h"
#include "third_party/blink/renderer/core/loader/empty_clients.h"
#include "third_party/blink/renderer/core/loader/resource/image_resource_content.h"
#include "third_party/blink/renderer/core/testing/core_unit_test_helper.h"
#include "third_party/blink/renderer/core/testing/wait_for_event.h"
#include "third_party/blink/renderer/modules/document_picture_in_picture/document_picture_in_picture.h"
#include "third_party/blink/renderer/modules/document_picture_in_picture/picture_in_picture_controller_impl.h"
#include "third_party/blink/renderer/platform/graphics/unaccelerated_static_bitmap_image.h"
#include "third_party/blink/renderer/platform/heap/garbage_collected.h"
#include "third_party/blink/renderer/platform/mediastream/media_stream_component.h"
#include "third_party/blink/renderer/platform/mediastream/media_stream_descriptor.h"
#include "third_party/blink/renderer/platform/testing/empty_web_media_player.h"
#include "third_party/blink/renderer/platform/testing/runtime_enabled_features_test_helpers.h"
#include "third_party/blink/renderer/platform/testing/unit_test_helpers.h"
#include "third_party/blink/renderer/platform/testing/url_test_helpers.h"

#if !BUILDFLAG(TARGET_OS_IS_ANDROID)
#include "third_party/blink/renderer/bindings/modules/v8/v8_document_picture_in_picture_options.h"
#endif  // !BUILDFLAG(TARGET_OS_IS_ANDROID)

_;

namespace blink {

namespace {
#if !BUILDFLAG(TARGET_OS_IS_ANDROID)
KURL GetOpenerURL() {}

LocalDOMWindow* OpenDocumentPictureInPictureWindow(
    V8TestingScope& v8_scope,
    Document& document,
    KURL opener_url = GetOpenerURL()) {}
#endif  // !BUILDFLAG(TARGET_OS_IS_ANDROID)

}  // namespace

viz::SurfaceId TestSurfaceId() {}

// The MockPictureInPictureSession implements a PictureInPicture session in the
// same process as the test and guarantees that the callbacks are called in
// order for the events to be fired.
class MockPictureInPictureSession
    : public mojom::blink::PictureInPictureSession {};

// The MockPictureInPictureService implements the PictureInPicture service in
// the same process as the test and guarantees that the callbacks are called in
// order for the events to be fired.
class MockPictureInPictureService
    : public mojom::blink::PictureInPictureService {};

class PictureInPictureControllerFrameClient
    : public test::MediaStubLocalFrameClient {};

class PictureInPictureControllerPlayer final : public EmptyWebMediaPlayer {};

class PictureInPictureTestWebFrameClient
    : public frame_test_helpers::TestWebFrameClient {};

// PictureInPictureController tests that require a Widget.
// Video PiP tests typically do, while Document PiP tests typically do not.
// If you need to mock the ChromeClient, then this is not the right test harness
// for you. If you need to mock the client and have a Widget, then you'll
// probably need to modify `WebViewHelper`.
class PictureInPictureControllerTestWithWidget : public RenderingTest {};

TEST_F(PictureInPictureControllerTestWithWidget,
       EnterPictureInPictureFiresEvent) {}

TEST_F(PictureInPictureControllerTestWithWidget,
       FrameThrottlingIsSetProperlyWithoutSetup) {}

TEST_F(PictureInPictureControllerTestWithWidget,
       ExitPictureInPictureFiresEvent) {}

TEST_F(PictureInPictureControllerTestWithWidget, StartObserving) {}

TEST_F(PictureInPictureControllerTestWithWidget, StopObserving) {}

TEST_F(PictureInPictureControllerTestWithWidget,
       PlayPauseButton_InfiniteDuration) {}

TEST_F(PictureInPictureControllerTestWithWidget, PlayPauseButton_MediaSource) {}

TEST_F(PictureInPictureControllerTestWithWidget, PerformMediaPlayerAction) {}

TEST_F(PictureInPictureControllerTestWithWidget,
       EnterPictureInPictureAfterResettingWMP) {}

TEST_F(PictureInPictureControllerTestWithWidget,
       EnterPictureInPictureProvideSourceBoundsSetToBoundsInWidget) {}

TEST_F(PictureInPictureControllerTestWithWidget,
       EnterPictureInPictureProvideSourceBoundsSetToReplacedContentRect) {}

TEST_F(PictureInPictureControllerTestWithWidget, VideoIsNotAllowedIfAutoPip) {}

#if !BUILDFLAG(TARGET_OS_IS_ANDROID)
TEST_F(PictureInPictureControllerTestWithWidget,
       DocumentPiPDoesNotAllowVizThrottling) {}

TEST_F(PictureInPictureControllerTestWithWidget,
       DocumentPiPDoesOpenWithFileUrl) {}

class PictureInPictureControllerChromeClient
    : public RenderingTestChromeClient {};

// Tests for Picture in Picture with a mockable chrome client.  This makes it
// easy to mock things like `SetWindowRect` on the client.  However, it skips
// the setup in `WebViewHelper` that provides a Widget.  `WebViewHelper` makes
// it hard to mock the client, since it provides a real `ChromeClient`.
class PictureInPictureControllerTestWithChromeClient : public RenderingTest {};

TEST_F(PictureInPictureControllerTestWithChromeClient,
       CreateDocumentPictureInPictureWindow) {}

TEST_F(PictureInPictureControllerTestWithChromeClient,
       CreateDocumentPictureInPictureWindowThrowsExceptionWhenDomWindowNull) {}

TEST_F(PictureInPictureControllerTestWithChromeClient, RequiresUserGesture) {}

TEST_F(PictureInPictureControllerTestWithChromeClient,
       OpenDocumentPiPTwiceSynchronouslyDoesNotCrash) {}

TEST_F(PictureInPictureControllerTestWithChromeClient, CopiesAutoplayFlags) {}
#endif  // !BUILDFLAG(TARGET_OS_IS_ANDROID)

}  // namespace blink