chromium/chrome/browser/media/media_engagement_contents_observer_unittest.cc

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

#include "chrome/browser/media/media_engagement_contents_observer.h"

#include <memory>
#include <optional>
#include <string>
#include <utility>
#include <vector>

#include "base/memory/ptr_util.h"
#include "base/memory/raw_ptr.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/simple_test_clock.h"
#include "base/test/test_mock_time_task_runner.h"
#include "base/timer/mock_timer.h"
#include "build/build_config.h"
#include "chrome/browser/media/media_engagement_score.h"
#include "chrome/browser/media/media_engagement_service.h"
#include "chrome/browser/media/media_engagement_service_factory.h"
#include "chrome/browser/media/media_engagement_session.h"
#include "chrome/browser/ui/recently_audible_helper.h"
#include "chrome/test/base/chrome_render_view_host_test_harness.h"
#include "chrome/test/base/testing_profile.h"
#include "components/ukm/test_ukm_recorder.h"
#include "content/public/browser/global_routing_id.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/web_contents.h"
#include "content/public/test/mock_navigation_handle.h"
#include "content/public/test/navigation_simulator.h"
#include "content/public/test/prerender_test_util.h"
#include "content/public/test/web_contents_tester.h"
#include "media/base/media_switches.h"
#include "services/metrics/public/cpp/ukm_builders.h"
#include "services/metrics/public/cpp/ukm_source.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/common/features.h"

// TODO(crbug.com/40099090) All these tests crash on Android
#if !BUILDFLAG(IS_ANDROID)
class MediaEngagementContentsObserverTest
    : public ChromeRenderViewHostTestHarness {};

// TODO(mlamouri): test that visits are not recorded multiple times when a
// same-origin navigation happens.

TEST_F(MediaEngagementContentsObserverTest, SignificantActivePlayerCount) {}

TEST_F(MediaEngagementContentsObserverTest, AreConditionsMet) {}

TEST_F(MediaEngagementContentsObserverTest, AreConditionsMet_AudioOnly) {}

TEST_F(MediaEngagementContentsObserverTest,
       EnsureCleanupAfterNavigation_AudioContext) {}

TEST_F(MediaEngagementContentsObserverTest,
       EnsureCleanupAfterNavigation_Media) {}

TEST_F(MediaEngagementContentsObserverTest, TimerRunsDependingOnConditions) {}

TEST_F(MediaEngagementContentsObserverTest,
       TimerRunsDependingOnConditions_AudioContext) {}

TEST_F(MediaEngagementContentsObserverTest,
       TimerRunsDependingOnConditions_AudioOnly) {}

TEST_F(MediaEngagementContentsObserverTest,
       TimerDoesNotRunIfEntryRecorded_AudioContext) {}

TEST_F(MediaEngagementContentsObserverTest,
       TimerDoesNotRunIfEntryRecorded_Media) {}

TEST_F(MediaEngagementContentsObserverTest,
       SignificantPlaybackRecordedWhenTimerFires_AudioContext) {}

TEST_F(MediaEngagementContentsObserverTest,
       SignificantPlaybackRecordedWhenTimerFires_Media) {}

TEST_F(MediaEngagementContentsObserverTest, InteractionsRecorded) {}

TEST_F(MediaEngagementContentsObserverTest,
       SignificantPlaybackNotRecordedIfAudioSilent) {}

TEST_F(MediaEngagementContentsObserverTest, DoNotRecordAudiolessTrack) {}

TEST_F(MediaEngagementContentsObserverTest,
       ResetStateOnNavigationWithPlayingPlayers_AudioContext) {}

TEST_F(MediaEngagementContentsObserverTest,
       ResetStateOnNavigationWithPlayingPlayers_Media) {}

TEST_F(MediaEngagementContentsObserverTest,
       VisibilityNotRequired_AudioContext) {}

TEST_F(MediaEngagementContentsObserverTest, VisibilityNotRequired_Media) {}

TEST_F(MediaEngagementContentsObserverTest, RecordUkmMetricsOnDestroy) {}

TEST_F(MediaEngagementContentsObserverTest,
       RecordUkmMetricsOnDestroy_AudioContextOnly) {}

TEST_F(MediaEngagementContentsObserverTest,
       RecordUkmMetricsOnDestroy_NoPlaybacks) {}

TEST_F(MediaEngagementContentsObserverTest, RecordUkmMetricsOnNavigate) {}

TEST_F(MediaEngagementContentsObserverTest,
       RecordUkmMetricsOnNavigate_AudioContextOnly) {}

TEST_F(MediaEngagementContentsObserverTest,
       RecordUkmMetricsOnNavigate_NoPlaybacks) {}

TEST_F(MediaEngagementContentsObserverTest,
       RecordUkmMetrics_MultiplePlaybackTime) {}

TEST_F(MediaEngagementContentsObserverTest, DoNotCreateSessionOnInternalUrl) {}

TEST_F(MediaEngagementContentsObserverTest, RecordAudiblePlayers_OnDestroy) {}

TEST_F(MediaEngagementContentsObserverTest, RecordAudiblePlayers_OnNavigate) {}

TEST_F(MediaEngagementContentsObserverTest, TimerSpecificToPlayer) {}

TEST_F(MediaEngagementContentsObserverTest, PagePlayerTimersDifferent) {}

TEST_F(MediaEngagementContentsObserverTest, SignificantAudibleTabMuted_On) {}

TEST_F(MediaEngagementContentsObserverTest, SignificantAudibleTabMuted_Off) {}

TEST_F(MediaEngagementContentsObserverTest, RecordPlaybackTime) {}

TEST_F(MediaEngagementContentsObserverTest, ShortMediaIgnored) {}

TEST_F(MediaEngagementContentsObserverTest, TotalTimeUsedInShortCalculation) {}

TEST_F(MediaEngagementContentsObserverTest, OnlyIgnoreFinishedMedia) {}

TEST_F(MediaEngagementContentsObserverTest, GetOrCreateSession_SpecialURLs) {}

TEST_F(MediaEngagementContentsObserverTest, GetOrCreateSession_NoOpener) {}

TEST_F(MediaEngagementContentsObserverTest, GetOrCreateSession_WithOpener) {}

TEST_F(MediaEngagementContentsObserverTest, IgnoreAudioContextIfDisabled) {}

TEST_F(MediaEngagementContentsObserverTest, PlayerStateIsCleanedUp) {}

class MediaEngagementContentsObserverPrerenderTest
    : public MediaEngagementContentsObserverTest {};

TEST_F(MediaEngagementContentsObserverPrerenderTest,
       EnsureDoNotCleanupAfterNavigation_AudioContextInPrerendering) {}

class MediaEngagementContentsObserverFencedFrameTest
    : public MediaEngagementContentsObserverTest {};

TEST_F(MediaEngagementContentsObserverFencedFrameTest,
       EnsureDoNotCleanupAfterNavigation_AudioContextOnFencedFrame) {}

#endif  // !BUILDFLAG(IS_ANDROID)