chromium/third_party/blink/renderer/platform/media/watch_time_reporter_unittest.cc

// Copyright 2016 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 "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/scoped_refptr.h"
#include "base/run_loop.h"
#include "base/task/single_thread_task_runner.h"
#include "base/test/task_environment.h"
#include "base/time/time.h"
#include "media/base/mock_media_log.h"
#include "media/base/pipeline_status.h"
#include "media/base/test_helpers.h"
#include "media/base/watch_time_keys.h"
#include "media/mojo/mojom/media_metrics_provider.mojom.h"
#include "media/mojo/mojom/watch_time_recorder.mojom.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/self_owned_receiver.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/common/media/display_type.h"
#include "third_party/blink/public/common/media/watch_time_component.h"
#include "third_party/blink/public/common/media/watch_time_reporter.h"
#include "third_party/blink/public/platform/scheduler/test/renderer_scheduler_test_support.h"

namespace blink {

WatchTimeKey;
_;

constexpr gfx::Size kSizeTooSmall =;
constexpr gfx::Size kSizeJustRight =;

#define EXPECT_WATCH_TIME(key, value)

#define EXPECT_MUTED_WATCH_TIME_IF_AUDIO_VIDEO(key, value)

#define EXPECT_WATCH_TIME_IF_VIDEO(key, value)

#define EXPECT_BACKGROUND_WATCH_TIME(key, value)

#define EXPECT_WATCH_TIME_IF_AUDIO_VIDEO_MEDIAFOUNDATION(key, value)

#define EXPECT_WATCH_TIME_FINALIZED()

// The following macros have .Times() values equal to the number of keys that a
// finalize event is expected to finalize.
#define EXPECT_POWER_WATCH_TIME_FINALIZED()

#define EXPECT_CONTROLS_WATCH_TIME_FINALIZED()

#define EXPECT_DISPLAY_WATCH_TIME_FINALIZED()

WatchTimeReporterTestData;
class WatchTimeReporterTest
    : public testing::TestWithParam<WatchTimeReporterTestData> {};

class DisplayTypeWatchTimeReporterTest : public WatchTimeReporterTest {};

// Tests that watch time reporting is appropriately enabled or disabled.
TEST_P(WatchTimeReporterTest, WatchTimeReporter) {}

TEST_P(WatchTimeReporterTest, WatchTimeReporterInfiniteStartTime) {}

TEST_P(WatchTimeReporterTest, WatchTimeReporterBasic) {}

TEST_P(WatchTimeReporterTest, WatchTimeReporterStatsOffsetCorrectly) {}

TEST_P(WatchTimeReporterTest, WatchTimeReporterDuration) {}

TEST_P(WatchTimeReporterTest, WatchTimeReporterUnderflow) {}

TEST_P(WatchTimeReporterTest, WatchTimeReporterUnderflowSpansFinalize) {}

TEST_P(WatchTimeReporterTest, WatchTimeReporterUnderflowTooLong) {}

TEST_P(WatchTimeReporterTest, WatchTimeReporterNoUnderflowDoubleReport) {}

// Verify secondary properties pass through correctly.
TEST_P(WatchTimeReporterTest, WatchTimeReporterSecondaryProperties) {}

TEST_P(WatchTimeReporterTest, SecondaryProperties_SizeIncreased) {}

TEST_P(WatchTimeReporterTest, SecondaryProperties_SizeDecreased) {}

TEST_P(WatchTimeReporterTest, WatchTimeReporterAutoplayInitiated) {}

TEST_P(WatchTimeReporterTest, WatchTimeReporterShownHidden) {}

TEST_P(WatchTimeReporterTest, WatchTimeReporterBackgroundHysteresis) {}

TEST_P(WatchTimeReporterTest, WatchTimeReporterShownHiddenBackground) {}

TEST_P(WatchTimeReporterTest, WatchTimeReporterHiddenPausedBackground) {}

TEST_P(WatchTimeReporterTest, WatchTimeReporterHiddenSeekedBackground) {}

TEST_P(WatchTimeReporterTest, WatchTimeReporterHiddenPowerBackground) {}

TEST_P(WatchTimeReporterTest, WatchTimeReporterHiddenControlsBackground) {}

TEST_P(DisplayTypeWatchTimeReporterTest,
       WatchTimeReporterHiddenDisplayTypeBackground) {}

TEST_P(WatchTimeReporterTest, WatchTimeReporterHiddenMuted) {}

TEST_P(WatchTimeReporterTest, WatchTimeReporterMultiplePartialFinalize) {}

// Tests that starting from a non-zero base works.
TEST_P(WatchTimeReporterTest, WatchTimeReporterNonZeroStart) {}

// Tests that seeking causes an immediate finalization.
TEST_P(WatchTimeReporterTest, SeekFinalizes) {}

// Tests that seeking can't be undone by anything other than OnPlaying().
TEST_P(WatchTimeReporterTest, SeekOnlyClearedByPlaying) {}

// Tests that seeking causes an immediate finalization, but does not trample a
// previously set finalize time.
TEST_P(WatchTimeReporterTest, SeekFinalizeDoesNotTramplePreviousFinalize) {}

// Tests that watch time is finalized upon destruction.
TEST_P(WatchTimeReporterTest, WatchTimeReporterFinalizeOnDestruction) {}

// Tests that watch time categories are mapped correctly.
TEST_P(WatchTimeReporterTest, WatchTimeCategoryMapping) {}

TEST_P(WatchTimeReporterTest, PlayPauseHysteresisContinuation) {}

TEST_P(WatchTimeReporterTest, PlayPauseHysteresisFinalized) {}

TEST_P(WatchTimeReporterTest, OnVolumeChangeHysteresisContinuation) {}

TEST_P(WatchTimeReporterTest, OnVolumeChangeHysteresisFinalized) {}

TEST_P(WatchTimeReporterTest, OnShownHiddenHysteresisContinuation) {}

TEST_P(WatchTimeReporterTest, OnShownHiddenHysteresisFinalized) {}

TEST_P(WatchTimeReporterTest, OnPowerStateChangeHysteresisBatteryContinuation) {}

TEST_P(WatchTimeReporterTest, OnPowerStateChangeHysteresisBatteryFinalized) {}

TEST_P(WatchTimeReporterTest, OnPowerStateChangeHysteresisAcContinuation) {}

TEST_P(WatchTimeReporterTest, OnPowerStateChangeHysteresisAcFinalized) {}

TEST_P(WatchTimeReporterTest, OnPowerStateChangeBatteryTransitions) {}

TEST_P(WatchTimeReporterTest, OnPowerStateChangeAcTransitions) {}

TEST_P(WatchTimeReporterTest, OnControlsChangeHysteresisNativeContinuation) {}

TEST_P(WatchTimeReporterTest, OnControlsChangeHysteresisNativeFinalized) {}

TEST_P(WatchTimeReporterTest, OnControlsChangeHysteresisNativeOffContinuation) {}

TEST_P(WatchTimeReporterTest, OnControlsChangeHysteresisNativeOffFinalized) {}

TEST_P(WatchTimeReporterTest, OnControlsChangeToNativeOff) {}

TEST_P(WatchTimeReporterTest, OnControlsChangeToNative) {}

TEST_P(DisplayTypeWatchTimeReporterTest,
       OnDisplayTypeChangeHysteresisFullscreenContinuation) {}

TEST_P(DisplayTypeWatchTimeReporterTest,
       OnDisplayTypeChangeHysteresisNativeFinalized) {}

TEST_P(DisplayTypeWatchTimeReporterTest,
       OnDisplayTypeChangeHysteresisInlineContinuation) {}

TEST_P(DisplayTypeWatchTimeReporterTest,
       OnDisplayTypeChangeHysteresisNativeOffFinalized) {}

TEST_P(DisplayTypeWatchTimeReporterTest,
       OnDisplayTypeChangeInlineToFullscreen) {}

TEST_P(DisplayTypeWatchTimeReporterTest,
       OnDisplayTypeChangeFullscreenToInline) {}

// Tests that the first finalize is the only one that matters.
TEST_P(WatchTimeReporterTest, HysteresisFinalizedWithEarliest) {}

// Tests that if a stop, stop, start sequence occurs, the middle stop is not
// undone and thus finalize still occurs.
TEST_P(WatchTimeReporterTest, HysteresisPartialExitStillFinalizes) {}

// Tests Media Foundation related Keys being used and given to recorder.
TEST_P(WatchTimeReporterTest, WatchTimeReporterMediaFoundation) {}

// Tests Media Foundation related keys given no EME.
TEST_P(WatchTimeReporterTest, WatchTimeReporterMediaFoundationNoEme) {}

class MutedWatchTimeReporterTest : public WatchTimeReporterTest {};

TEST_P(MutedWatchTimeReporterTest, MutedHysteresis) {}

TEST_P(MutedWatchTimeReporterTest, MuteUnmute) {}

TEST_P(MutedWatchTimeReporterTest, MutedPaused) {}

TEST_P(MutedWatchTimeReporterTest, MutedSeeked) {}

TEST_P(MutedWatchTimeReporterTest, MutedPower) {}

TEST_P(MutedWatchTimeReporterTest, MutedControls) {}

TEST_P(MutedWatchTimeReporterTest, MutedDisplayType) {}

INSTANTIATE_TEST_SUITE_P();

// Separate test set since display tests only work with video.
INSTANTIATE_TEST_SUITE_P();

// Separate test set since muted tests only work with audio+video.
INSTANTIATE_TEST_SUITE_P();

}  // namespace blink