#include "base/command_line.h"
#include "base/functional/bind.h"
#include "base/memory/raw_ptr.h"
#include "base/run_loop.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/gmock_callback_support.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/time/time.h"
#include "base/timer/timer.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/component_updater/mei_preload_component_installer.h"
#include "chrome/browser/media/media_engagement_contents_observer.h"
#include "chrome/browser/media/media_engagement_preloaded_list.h"
#include "chrome/browser/media/media_engagement_service.h"
#include "chrome/browser/prefs/session_startup_pref.h"
#include "chrome/browser/preloading/prefetch/no_state_prefetch/no_state_prefetch_manager_factory.h"
#include "chrome/browser/preloading/prefetch/no_state_prefetch/no_state_prefetch_test_utils.h"
#include "chrome/browser/profiles/keep_alive/profile_keep_alive_types.h"
#include "chrome/browser/profiles/keep_alive/scoped_profile_keep_alive.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/sessions/session_restore.h"
#include "chrome/browser/sessions/session_restore_test_helper.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/browser_navigator.h"
#include "chrome/browser/ui/recently_audible_helper.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/ui_test_utils.h"
#include "components/component_updater/component_updater_service.h"
#include "components/content_settings/core/common/features.h"
#include "components/keep_alive_registry/keep_alive_types.h"
#include "components/keep_alive_registry/scoped_keep_alive.h"
#include "components/no_state_prefetch/browser/no_state_prefetch_handle.h"
#include "components/no_state_prefetch/browser/no_state_prefetch_manager.h"
#include "components/no_state_prefetch/common/no_state_prefetch_final_status.h"
#include "content/public/browser/web_contents_observer.h"
#include "content/public/common/content_features.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/fenced_frame_test_util.h"
#include "content/public/test/prerender_test_util.h"
#include "media/base/media_switches.h"
#include "net/dns/mock_host_resolver.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "third_party/blink/public/common/associated_interfaces/associated_interface_provider.h"
#include "third_party/blink/public/mojom/autoplay/autoplay.mojom-test-utils.h"
#include "third_party/blink/public/mojom/autoplay/autoplay.mojom.h"
#if BUILDFLAG(IS_CHROMEOS_ASH)
#include "chrome/browser/sessions/session_service_factory.h"
#include "chrome/browser/sessions/session_service_test_helper.h"
#endif
namespace {
const char* kMediaEngagementTestDataPath = …;
const std::u16string kReadyTitle = …;
class WasRecentlyAudibleWatcher { … };
}
class MediaEngagementBrowserTest : public InProcessBrowserTest { … };
class MediaEngagementPreloadBrowserTest : public InProcessBrowserTest { … };
IN_PROC_BROWSER_TEST_F(MediaEngagementBrowserTest, RecordEngagement) { … }
#if BUILDFLAG(IS_CHROMEOS_ASH)
#define MAYBE_RecordEngagement_AudioOnly …
#else
#define MAYBE_RecordEngagement_AudioOnly …
#endif
IN_PROC_BROWSER_TEST_F(MediaEngagementBrowserTest,
MAYBE_RecordEngagement_AudioOnly) { … }
IN_PROC_BROWSER_TEST_F(MediaEngagementBrowserTest,
DoNotRecordEngagement_NotTime) { … }
#if BUILDFLAG(IS_CHROMEOS_ASH)
#define MAYBE_DoNotRecordEngagement_NotTime_AudioOnly …
#else
#define MAYBE_DoNotRecordEngagement_NotTime_AudioOnly …
#endif
IN_PROC_BROWSER_TEST_F(MediaEngagementBrowserTest,
MAYBE_DoNotRecordEngagement_NotTime_AudioOnly) { … }
IN_PROC_BROWSER_TEST_F(MediaEngagementBrowserTest,
DoNotRecordEngagement_TabMuted) { … }
#if BUILDFLAG(IS_CHROMEOS_ASH)
#define MAYBE_DoNotRecordEngagement_TabMuted_AudioOnly …
#else
#define MAYBE_DoNotRecordEngagement_TabMuted_AudioOnly …
#endif
IN_PROC_BROWSER_TEST_F(MediaEngagementBrowserTest,
MAYBE_DoNotRecordEngagement_TabMuted_AudioOnly) { … }
IN_PROC_BROWSER_TEST_F(MediaEngagementBrowserTest,
DoNotRecordEngagement_PlayerMuted) { … }
IN_PROC_BROWSER_TEST_F(MediaEngagementBrowserTest,
DoNotRecordEngagement_PlayerMuted_AudioOnly) { … }
IN_PROC_BROWSER_TEST_F(MediaEngagementBrowserTest,
DISABLED_DoNotRecordEngagement_PlaybackStopped) { … }
#if BUILDFLAG(IS_CHROMEOS_ASH)
#define MAYBE_DoNotRecordEngagement_PlaybackStopped_AudioOnly …
#else
#define MAYBE_DoNotRecordEngagement_PlaybackStopped_AudioOnly …
#endif
IN_PROC_BROWSER_TEST_F(MediaEngagementBrowserTest,
MAYBE_DoNotRecordEngagement_PlaybackStopped_AudioOnly) { … }
IN_PROC_BROWSER_TEST_F(MediaEngagementBrowserTest,
RecordEngagement_NotVisible) { … }
#if BUILDFLAG(IS_CHROMEOS_ASH)
#define MAYBE_RecordEngagement_NotVisible_AudioOnly …
#else
#define MAYBE_RecordEngagement_NotVisible_AudioOnly …
#endif
IN_PROC_BROWSER_TEST_F(MediaEngagementBrowserTest,
MAYBE_RecordEngagement_NotVisible_AudioOnly) { … }
IN_PROC_BROWSER_TEST_F(MediaEngagementBrowserTest,
DoNotRecordEngagement_FrameSize) { … }
IN_PROC_BROWSER_TEST_F(MediaEngagementBrowserTest,
DoNotRecordEngagement_NoAudioTrack) { … }
IN_PROC_BROWSER_TEST_F(MediaEngagementBrowserTest,
DoNotRecordEngagement_SilentAudioTrack) { … }
IN_PROC_BROWSER_TEST_F(MediaEngagementBrowserTest, RecordVisitOnBrowserClose) { … }
#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || \
BUILDFLAG(IS_MAC)
#define MAYBE_RecordSingleVisitOnSameOrigin …
#else
#define MAYBE_RecordSingleVisitOnSameOrigin …
#endif
IN_PROC_BROWSER_TEST_F(MediaEngagementBrowserTest,
MAYBE_RecordSingleVisitOnSameOrigin) { … }
#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
#define MAYBE_RecordVisitOnNewOrigin …
#else
#define MAYBE_RecordVisitOnNewOrigin …
#endif
IN_PROC_BROWSER_TEST_F(MediaEngagementBrowserTest,
MAYBE_RecordVisitOnNewOrigin) { … }
#if BUILDFLAG(IS_CHROMEOS_ASH)
#define MAYBE_DoNotRecordEngagement_SilentAudioTrack_AudioOnly …
#else
#define MAYBE_DoNotRecordEngagement_SilentAudioTrack_AudioOnly …
#endif
IN_PROC_BROWSER_TEST_F(MediaEngagementBrowserTest,
MAYBE_DoNotRecordEngagement_SilentAudioTrack_AudioOnly) { … }
IN_PROC_BROWSER_TEST_F(MediaEngagementBrowserTest, IFrameDelegation) { … }
IN_PROC_BROWSER_TEST_F(MediaEngagementBrowserTest, IFrameDelegation_AudioOnly) { … }
IN_PROC_BROWSER_TEST_F(MediaEngagementBrowserTest,
ClearBrowsingHistoryBeforePlayback) { … }
#if BUILDFLAG(IS_CHROMEOS_ASH)
#define MAYBE_MultipleElements …
#else
#define MAYBE_MultipleElements …
#endif
IN_PROC_BROWSER_TEST_F(MediaEngagementBrowserTest, MAYBE_MultipleElements) { … }
IN_PROC_BROWSER_TEST_F(MediaEngagementBrowserTest,
RecordAudibleBasedOnShortTime) { … }
#if BUILDFLAG(IS_MAC)
#define MAYBE_SessionNewTabNavigateSameURL …
#else
#define MAYBE_SessionNewTabNavigateSameURL …
#endif
IN_PROC_BROWSER_TEST_F(MediaEngagementBrowserTest,
MAYBE_SessionNewTabNavigateSameURL) { … }
#if BUILDFLAG(IS_MAC)
#define MAYBE_SessionNewTabSameURL …
#else
#define MAYBE_SessionNewTabSameURL …
#endif
IN_PROC_BROWSER_TEST_F(MediaEngagementBrowserTest, MAYBE_SessionNewTabSameURL) { … }
#if BUILDFLAG(IS_MAC)
#define MAYBE_SessionNewTabSameOrigin …
#else
#define MAYBE_SessionNewTabSameOrigin …
#endif
IN_PROC_BROWSER_TEST_F(MediaEngagementBrowserTest,
MAYBE_SessionNewTabSameOrigin) { … }
IN_PROC_BROWSER_TEST_F(MediaEngagementBrowserTest, SessionNewTabCrossOrigin) { … }
#if BUILDFLAG(IS_MAC)
#define MAYBE_SessionMultipleTabsClosingParent …
#else
#define MAYBE_SessionMultipleTabsClosingParent …
#endif
IN_PROC_BROWSER_TEST_F(MediaEngagementBrowserTest,
MAYBE_SessionMultipleTabsClosingParent) { … }
IN_PROC_BROWSER_TEST_F(MediaEngagementPreloadBrowserTest,
EnsureSingletonListIsLoaded) { … }
#if BUILDFLAG(IS_MAC)
#define MAYBE_SessionNewTabNavigateSameURLWithOpener_Typed …
#else
#define MAYBE_SessionNewTabNavigateSameURLWithOpener_Typed …
#endif
IN_PROC_BROWSER_TEST_F(MediaEngagementBrowserTest,
MAYBE_SessionNewTabNavigateSameURLWithOpener_Typed) { … }
class MediaEngagementPreThirdPartyCookieDeprecationBrowserTest
: public MediaEngagementBrowserTest { … };
#if BUILDFLAG(IS_WIN)
#define MAYBE_Ignored …
#else
#define MAYBE_Ignored …
#endif
IN_PROC_BROWSER_TEST_F(MediaEngagementPreThirdPartyCookieDeprecationBrowserTest,
MAYBE_Ignored) { … }
class MediaEngagementSessionRestoreBrowserTest
: public MediaEngagementBrowserTest { … };
IN_PROC_BROWSER_TEST_F(MediaEngagementSessionRestoreBrowserTest,
RestoredSession_NoPlayback_NoMEI) { … }
IN_PROC_BROWSER_TEST_F(MediaEngagementSessionRestoreBrowserTest,
RestoredSession_Playback_MEI) { … }
class MockAutoplayConfigurationClient
: public blink::mojom::AutoplayConfigurationClientInterceptorForTesting { … };
class MediaEngagementContentsObserverMPArchBrowserTest
: public MediaEngagementBrowserTest { … };
class MediaEngagementContentsObserverPrerenderBrowserTest
: public MediaEngagementContentsObserverMPArchBrowserTest { … };
#if BUILDFLAG(IS_LINUX)
#define MAYBE_DoNotSendEngagementLevelToRenderFrameInPrerendering …
#else
#define MAYBE_DoNotSendEngagementLevelToRenderFrameInPrerendering …
#endif
IN_PROC_BROWSER_TEST_F(
MediaEngagementContentsObserverPrerenderBrowserTest,
MAYBE_DoNotSendEngagementLevelToRenderFrameInPrerendering) { … }
class MediaEngagementContentsObserverFencedFrameBrowserTest
: public MediaEngagementContentsObserverMPArchBrowserTest { … };
#if BUILDFLAG(IS_LINUX)
#define MAYBE_SendEngagementLevelToRenderFrameOnFencedFrame …
#else
#define MAYBE_SendEngagementLevelToRenderFrameOnFencedFrame …
#endif
IN_PROC_BROWSER_TEST_F(MediaEngagementContentsObserverFencedFrameBrowserTest,
MAYBE_SendEngagementLevelToRenderFrameOnFencedFrame) { … }