chromium/third_party/blink/renderer/core/html/media/video_wake_lock_test.cc

// Copyright 2018 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/core/html/media/video_wake_lock.h"

#include <memory>
#include <utility>

#include "cc/layers/layer.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/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/mojom/picture_in_picture/picture_in_picture.mojom-blink.h"
#include "third_party/blink/public/platform/browser_interface_broker_proxy.h"
#include "third_party/blink/renderer/core/css_value_keywords.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/local_dom_window.h"
#include "third_party/blink/renderer/core/frame/local_frame.h"
#include "third_party/blink/renderer/core/frame/picture_in_picture_controller.h"
#include "third_party/blink/renderer/core/html/html_div_element.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/testing/wait_for_event.h"
#include "third_party/blink/renderer/platform/heap/garbage_collected.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/task_environment.h"
#include "third_party/blink/renderer/platform/testing/unit_test_helpers.h"

namespace blink {

constexpr gfx::Size kWindowSize(800, 600);
constexpr gfx::Size kNormalVideoSize(640, 480);
constexpr gfx::Size kSmallVideoSize(320, 240);  // Too small to take wake lock.

// The VideoWakeLockPictureInPictureSession 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 VideoWakeLockPictureInPictureSession final
    : public mojom::blink::PictureInPictureSession {};

// The VideoWakeLockPictureInPictureService 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 VideoWakeLockPictureInPictureService final
    : public mojom::blink::PictureInPictureService {};

class VideoWakeLockMediaPlayer final : public EmptyWebMediaPlayer {};

class VideoWakeLockFrameClient : public test::MediaStubLocalFrameClient {};

class VideoWakeLockTestWebFrameClient
    : public frame_test_helpers::TestWebFrameClient {};

class VideoWakeLockTest : public testing::Test,
                          public testing::WithParamInterface<bool>,
                          private ScopedIntersectionOptimizationForTest {};

INSTANTIATE_TEST_SUITE_P();

TEST_P(VideoWakeLockTest, NoLockByDefault) {}

TEST_P(VideoWakeLockTest, PlayingVideoRequestsLock) {}

TEST_P(VideoWakeLockTest, PausingVideoCancelsLock) {}

TEST_P(VideoWakeLockTest, HiddingPageCancelsLock) {}

TEST_P(VideoWakeLockTest, PlayingWhileHiddenDoesNotRequestLock) {}

TEST_P(VideoWakeLockTest, ShowingPageRequestsLock) {}

TEST_P(VideoWakeLockTest, ShowingPageDoNotRequestsLockIfPaused) {}

TEST_P(VideoWakeLockTest, RemotePlaybackDisconnectedDoesNotCancelLock) {}

TEST_P(VideoWakeLockTest, RemotePlaybackConnectingDoesNotCancelLock) {}

TEST_P(VideoWakeLockTest, ActiveRemotePlaybackCancelsLock) {}

TEST_P(VideoWakeLockTest, LeavingRemotePlaybackResumesLock) {}

TEST_P(VideoWakeLockTest, PictureInPictureLocksWhenPageNotVisible) {}

TEST_P(VideoWakeLockTest, PictureInPictureDoesNoLockWhenPaused) {}

TEST_P(VideoWakeLockTest, LeavingPictureInPictureCancelsLock) {}

TEST_P(VideoWakeLockTest, RemotingVideoInPictureInPictureDoesNotRequestLock) {}

TEST_P(VideoWakeLockTest, PausingContextCancelsLock) {}

TEST_P(VideoWakeLockTest, ResumingContextResumesLock) {}

TEST_P(VideoWakeLockTest, DestroyingContextCancelsLock) {}

TEST_P(VideoWakeLockTest, LoadingCancelsLock) {}

TEST_P(VideoWakeLockTest, MutedHiddenVideoDoesNotTakeLock) {}

TEST_P(VideoWakeLockTest, AudibleHiddenVideoTakesLock) {}

TEST_P(VideoWakeLockTest, UnmutingHiddenVideoTakesLock) {}

TEST_P(VideoWakeLockTest, MutingHiddenVideoReleasesLock) {}

TEST_P(VideoWakeLockTest, HidingAudibleVideoDoesNotReleaseLock) {}

TEST_P(VideoWakeLockTest, HidingMutedVideoReleasesLock) {}

TEST_P(VideoWakeLockTest, HiddenMutedVideoAlwaysVisibleInPictureInPicture) {}

TEST_P(VideoWakeLockTest, VideoWithNoFramesReleasesLock) {}

TEST_P(VideoWakeLockTest, VideoWithFramesTakesLock) {}

TEST_P(VideoWakeLockTest, HidingVideoOnlyReleasesLock) {}

TEST_P(VideoWakeLockTest, SmallMutedVideoDoesNotTakeLock) {}

TEST_P(VideoWakeLockTest, SizeChangeTakesLock) {}

TEST_P(VideoWakeLockTest, MutedVideoTooFarOffscreenDoesNotTakeLock) {}

TEST_P(VideoWakeLockTest, WakeLockTracksDocumentsPage) {}

TEST_P(VideoWakeLockTest, VideoOnlyMediaStreamAlwaysTakesLock) {}

}  // namespace blink