#include "content/browser/media/session/media_session_impl.h"
#include <stddef.h>
#include <list>
#include <memory>
#include <vector>
#include "base/atomic_sequence_num.h"
#include "base/memory/ptr_util.h"
#include "base/memory/raw_ptr.h"
#include "base/metrics/histogram_samples.h"
#include "base/strings/strcat.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/bind.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/simple_test_tick_clock.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "content/browser/media/session/audio_focus_delegate.h"
#include "content/browser/media/session/mock_media_session_player_observer.h"
#include "content/browser/media/session/mock_media_session_service_impl.h"
#include "content/browser/renderer_host/back_forward_cache_impl.h"
#include "content/browser/renderer_host/render_frame_host_impl.h"
#include "content/browser/web_contents/web_contents_impl.h"
#include "content/public/browser/media_session.h"
#include "content/public/browser/web_contents.h"
#include "content/public/test/back_forward_cache_util.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/content_browser_test.h"
#include "content/public/test/content_browser_test_utils.h"
#include "content/public/test/prerender_test_util.h"
#include "content/shell/browser/shell.h"
#include "content/test/content_browser_test_utils_internal.h"
#include "media/base/media_content_type.h"
#include "net/base/filename_util.h"
#include "net/dns/mock_host_resolver.h"
#include "net/test/embedded_test_server/http_request.h"
#include "net/test/embedded_test_server/http_response.h"
#include "services/media_session/public/cpp/test/mock_media_session.h"
#include "services/media_session/public/mojom/audio_focus.mojom.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "third_party/blink/public/mojom/favicon/favicon_url.mojom.h"
AudioFocusType;
MediaPlaybackState;
MediaSessionInfo;
_;
Eq;
Expectation;
NiceMock;
namespace {
const double kDefaultVolumeMultiplier = …;
const double kDuckingVolumeMultiplier = …;
const double kDifferentDuckingVolumeMultiplier = …;
const std::u16string kExpectedSourceTitlePrefix = …;
constexpr gfx::Size kDefaultFaviconSize = …;
const std::string kExampleSinkId = …;
class MockAudioFocusDelegate : public content::AudioFocusDelegate { … };
class GetVisibilityWaiter { … };
}
namespace content {
class MediaSessionImplBrowserTest : public ContentBrowserTest { … };
class MediaSessionImplParamBrowserTest
: public MediaSessionImplBrowserTest,
public testing::WithParamInterface<bool> { … };
class MediaSessionImplSyncBrowserTest : public MediaSessionImplBrowserTest { … };
INSTANTIATE_TEST_SUITE_P(…);
IN_PROC_BROWSER_TEST_P(MediaSessionImplParamBrowserTest,
PlayersFromSameObserverDoNotStopEachOtherInSameSession) { … }
IN_PROC_BROWSER_TEST_P(MediaSessionImplParamBrowserTest,
PlayersFromManyObserverDoNotStopEachOtherInSameSession) { … }
IN_PROC_BROWSER_TEST_P(MediaSessionImplParamBrowserTest,
SuspendedMediaSessionStopsPlayers) { … }
IN_PROC_BROWSER_TEST_P(MediaSessionImplParamBrowserTest,
ResumedMediaSessionRestartsPlayers) { … }
IN_PROC_BROWSER_TEST_P(MediaSessionImplParamBrowserTest,
StartedPlayerOnSuspendedSessionPlaysAlone) { … }
IN_PROC_BROWSER_TEST_P(MediaSessionImplParamBrowserTest,
InitialVolumeMultiplier) { … }
IN_PROC_BROWSER_TEST_P(MediaSessionImplParamBrowserTest,
StartDuckingReducesVolumeMultiplier) { … }
IN_PROC_BROWSER_TEST_P(MediaSessionImplParamBrowserTest,
StopDuckingRecoversVolumeMultiplier) { … }
IN_PROC_BROWSER_TEST_P(MediaSessionImplParamBrowserTest,
DuckingUsesConfiguredMultiplier) { … }
IN_PROC_BROWSER_TEST_P(MediaSessionImplParamBrowserTest,
AudioFocusInitialState) { … }
IN_PROC_BROWSER_TEST_P(MediaSessionImplParamBrowserTest,
AddPlayerOnSuspendedFocusUnducksWhenPlaybackRestarts) { … }
IN_PROC_BROWSER_TEST_P(MediaSessionImplParamBrowserTest,
CanRequestFocusBeforePlayerCreation) { … }
IN_PROC_BROWSER_TEST_P(MediaSessionImplParamBrowserTest,
StartPlayerGivesFocus) { … }
IN_PROC_BROWSER_TEST_P(MediaSessionImplParamBrowserTest,
SuspendGivesAwayAudioFocus) { … }
IN_PROC_BROWSER_TEST_P(MediaSessionImplParamBrowserTest,
StopGivesAwayAudioFocus) { … }
IN_PROC_BROWSER_TEST_P(MediaSessionImplParamBrowserTest,
SystemResumeGivesBackAudioFocus) { … }
IN_PROC_BROWSER_TEST_P(MediaSessionImplParamBrowserTest,
UIResumeGivesBackAudioFocus) { … }
IN_PROC_BROWSER_TEST_P(MediaSessionImplParamBrowserTest,
RemovingLastPlayerDropsAudioFocus) { … }
IN_PROC_BROWSER_TEST_P(MediaSessionImplParamBrowserTest,
RemovingLastPlayerFromManyObserversDropsAudioFocus) { … }
IN_PROC_BROWSER_TEST_P(MediaSessionImplParamBrowserTest,
RemovingAllPlayersFromObserversDropsAudioFocus) { … }
IN_PROC_BROWSER_TEST_P(MediaSessionImplParamBrowserTest,
ResumePlayGivesAudioFocus) { … }
IN_PROC_BROWSER_TEST_P(MediaSessionImplParamBrowserTest,
ResumeSuspendSeekAreSentOnlyOncePerPlayers) { … }
IN_PROC_BROWSER_TEST_P(MediaSessionImplParamBrowserTest,
ResumeSuspendSeekAreSentOnlyOncePerPlayersAddedTwice) { … }
IN_PROC_BROWSER_TEST_P(MediaSessionImplParamBrowserTest,
RemovingTheSamePlayerTwiceIsANoop) { … }
IN_PROC_BROWSER_TEST_P(MediaSessionImplParamBrowserTest, AudioFocusType) { … }
IN_PROC_BROWSER_TEST_P(MediaSessionImplParamBrowserTest,
ControlsShowForContent) { … }
IN_PROC_BROWSER_TEST_P(MediaSessionImplParamBrowserTest,
ControlsNoShowForTransient) { … }
#if !BUILDFLAG(IS_ANDROID)
IN_PROC_BROWSER_TEST_P(MediaSessionImplParamBrowserTest,
ControlsNoShowForTransientAndRoutedService) { … }
IN_PROC_BROWSER_TEST_P(MediaSessionImplParamBrowserTest,
ControlsNoShowForTransientAndPlaybackStateNone) { … }
IN_PROC_BROWSER_TEST_P(MediaSessionImplParamBrowserTest,
ControlsShowForTransientAndPlaybackStatePaused) { … }
IN_PROC_BROWSER_TEST_P(MediaSessionImplParamBrowserTest,
ControlsShowForTransientAndPlaybackStatePlaying) { … }
#endif
IN_PROC_BROWSER_TEST_P(MediaSessionImplParamBrowserTest,
ControlsHideWhenStopped) { … }
IN_PROC_BROWSER_TEST_P(MediaSessionImplParamBrowserTest,
ControlsShownAcceptTransient) { … }
IN_PROC_BROWSER_TEST_P(MediaSessionImplParamBrowserTest,
ControlsShownAfterContentAdded) { … }
IN_PROC_BROWSER_TEST_P(MediaSessionImplParamBrowserTest,
ControlsStayIfOnlyOnePlayerHasBeenPaused) { … }
IN_PROC_BROWSER_TEST_P(MediaSessionImplParamBrowserTest,
ControlsHideWhenTheLastPlayerIsRemoved) { … }
IN_PROC_BROWSER_TEST_P(MediaSessionImplParamBrowserTest,
ControlsHideWhenAllThePlayersAreRemoved) { … }
IN_PROC_BROWSER_TEST_P(MediaSessionImplParamBrowserTest,
ControlsNotHideWhenTheLastPlayerIsPaused) { … }
IN_PROC_BROWSER_TEST_P(MediaSessionImplParamBrowserTest,
SuspendTemporaryUpdatesControls) { … }
IN_PROC_BROWSER_TEST_P(MediaSessionImplParamBrowserTest,
ControlsUpdatedWhenResumed) { … }
IN_PROC_BROWSER_TEST_P(MediaSessionImplParamBrowserTest,
ControlsHideWhenSessionSuspendedPermanently) { … }
IN_PROC_BROWSER_TEST_P(MediaSessionImplParamBrowserTest,
ControlsHideWhenSessionStops) { … }
IN_PROC_BROWSER_TEST_P(MediaSessionImplParamBrowserTest,
ControlsHideWhenSessionChangesFromContentToTransient) { … }
IN_PROC_BROWSER_TEST_P(MediaSessionImplParamBrowserTest,
ControlsUpdatedWhenNewPlayerResetsSession) { … }
IN_PROC_BROWSER_TEST_P(MediaSessionImplParamBrowserTest,
ControlsResumedWhenPlayerIsResumed) { … }
IN_PROC_BROWSER_TEST_P(MediaSessionImplParamBrowserTest,
ControlsUpdatedDueToResumeSessionAction) { … }
IN_PROC_BROWSER_TEST_P(MediaSessionImplParamBrowserTest,
ControlsUpdatedDueToSuspendSessionAction) { … }
IN_PROC_BROWSER_TEST_P(MediaSessionImplParamBrowserTest,
ControlsDontShowWhenOnlyOneShotIsPresent) { … }
IN_PROC_BROWSER_TEST_P(MediaSessionImplParamBrowserTest,
ControlsHiddenAfterRemoveOneShotWithoutOtherPlayers) { … }
IN_PROC_BROWSER_TEST_P(MediaSessionImplParamBrowserTest,
ControlsShowAfterRemoveOneShotWithPersistentPresent) { … }
IN_PROC_BROWSER_TEST_P(MediaSessionImplParamBrowserTest,
DontSuspendWhenOnlyOneShotIsPresent) { … }
IN_PROC_BROWSER_TEST_P(MediaSessionImplParamBrowserTest,
SuspendWhenOneShotAndNormalArePresent) { … }
IN_PROC_BROWSER_TEST_P(MediaSessionImplParamBrowserTest,
DontResumeBySystemUISuspendedSessions) { … }
IN_PROC_BROWSER_TEST_P(MediaSessionImplParamBrowserTest,
AllowUIResumeForSystemSuspend) { … }
IN_PROC_BROWSER_TEST_P(MediaSessionImplParamBrowserTest, ResumeSuspendFromUI) { … }
IN_PROC_BROWSER_TEST_P(MediaSessionImplParamBrowserTest,
ResumeSuspendFromSystem) { … }
IN_PROC_BROWSER_TEST_P(MediaSessionImplParamBrowserTest,
OneShotTakesGainFocus) { … }
IN_PROC_BROWSER_TEST_P(MediaSessionImplParamBrowserTest,
RemovingOneShotDropsFocus) { … }
IN_PROC_BROWSER_TEST_P(MediaSessionImplParamBrowserTest,
RemovingOneShotWhileStillHavingOtherPlayersKeepsFocus) { … }
IN_PROC_BROWSER_TEST_P(MediaSessionImplParamBrowserTest,
ActualPlaybackStateWhilePlayerPaused) { … }
IN_PROC_BROWSER_TEST_P(MediaSessionImplParamBrowserTest,
ActualPlaybackStateWhilePlayerPlaying) { … }
IN_PROC_BROWSER_TEST_P(MediaSessionImplParamBrowserTest,
ActualPlaybackStateWhilePlayerRemoved) { … }
IN_PROC_BROWSER_TEST_P(MediaSessionImplParamBrowserTest,
UMA_Suspended_SystemTransient) { … }
IN_PROC_BROWSER_TEST_P(MediaSessionImplParamBrowserTest,
UMA_Suspended_SystemPermantent) { … }
IN_PROC_BROWSER_TEST_P(MediaSessionImplParamBrowserTest, UMA_Suspended_UI) { … }
IN_PROC_BROWSER_TEST_P(MediaSessionImplParamBrowserTest,
UMA_Suspended_Multiple) { … }
IN_PROC_BROWSER_TEST_P(MediaSessionImplParamBrowserTest,
UMA_Suspended_Crossing) { … }
IN_PROC_BROWSER_TEST_P(MediaSessionImplParamBrowserTest, UMA_Suspended_Stop) { … }
IN_PROC_BROWSER_TEST_P(MediaSessionImplParamBrowserTest,
UMA_ActiveTime_NoActivation) { … }
IN_PROC_BROWSER_TEST_P(MediaSessionImplParamBrowserTest,
UMA_ActiveTime_SimpleActivation) { … }
IN_PROC_BROWSER_TEST_P(MediaSessionImplParamBrowserTest,
UMA_ActiveTime_ActivationWithUISuspension) { … }
IN_PROC_BROWSER_TEST_P(MediaSessionImplParamBrowserTest,
UMA_ActiveTime_ActivationWithSystemSuspension) { … }
IN_PROC_BROWSER_TEST_P(MediaSessionImplParamBrowserTest,
UMA_ActiveTime_ActivateSuspendedButNotStopped) { … }
IN_PROC_BROWSER_TEST_P(MediaSessionImplParamBrowserTest,
UMA_ActiveTime_ActivateSuspendStopTwice) { … }
IN_PROC_BROWSER_TEST_P(MediaSessionImplParamBrowserTest,
UMA_ActiveTime_MultipleActivations) { … }
IN_PROC_BROWSER_TEST_P(MediaSessionImplParamBrowserTest,
AddingObserverNotifiesCurrentInformation_EmptyInfo) { … }
IN_PROC_BROWSER_TEST_P(MediaSessionImplParamBrowserTest,
AddingMojoObserverNotifiesCurrentInformation_WithInfo) { … }
IN_PROC_BROWSER_TEST_F(MediaSessionImplSyncBrowserTest,
PepperPlayerNotAddedIfFocusFailed) { … }
IN_PROC_BROWSER_TEST_F(MediaSessionImplBrowserTest, Async_RequestFailure_Gain) { … }
IN_PROC_BROWSER_TEST_F(MediaSessionImplBrowserTest,
Async_RequestFailure_GainTransient) { … }
IN_PROC_BROWSER_TEST_F(MediaSessionImplBrowserTest, Async_GainThenTransient) { … }
IN_PROC_BROWSER_TEST_F(MediaSessionImplBrowserTest, Async_TransientThenGain) { … }
IN_PROC_BROWSER_TEST_F(MediaSessionImplBrowserTest,
Async_SuspendBeforeResolve) { … }
IN_PROC_BROWSER_TEST_F(MediaSessionImplBrowserTest, Async_ResumeBeforeResolve) { … }
IN_PROC_BROWSER_TEST_F(MediaSessionImplBrowserTest, Async_RemoveBeforeResolve) { … }
IN_PROC_BROWSER_TEST_F(MediaSessionImplBrowserTest, Async_StopBeforeResolve) { … }
IN_PROC_BROWSER_TEST_F(MediaSessionImplBrowserTest, Async_Unducking_Failure) { … }
IN_PROC_BROWSER_TEST_F(MediaSessionImplBrowserTest, Async_Unducking_Inactive) { … }
IN_PROC_BROWSER_TEST_F(MediaSessionImplBrowserTest, Async_Unducking_Success) { … }
IN_PROC_BROWSER_TEST_F(MediaSessionImplBrowserTest, Async_Unducking_Suspended) { … }
IN_PROC_BROWSER_TEST_F(MediaSessionImplBrowserTest, MetadataWhenFileUrlScheme) { … }
IN_PROC_BROWSER_TEST_F(MediaSessionImplBrowserTest, UpdateFaviconURL) { … }
IN_PROC_BROWSER_TEST_F(MediaSessionImplBrowserTest,
UpdateFaviconURL_ClearOnNavigate) { … }
IN_PROC_BROWSER_TEST_F(MediaSessionImplBrowserTest,
SinkIdChangeNotifiesObservers) { … }
class MediaSessionFaviconBrowserTest : public ContentBrowserTest { … };
class FaviconWaiter : public WebContentsObserver { … };
IN_PROC_BROWSER_TEST_F(MediaSessionFaviconBrowserTest, StartupInitalization) { … }
IN_PROC_BROWSER_TEST_F(MediaSessionImplBrowserTest,
PositionStateRouteWithTwoPlayers) { … }
IN_PROC_BROWSER_TEST_F(MediaSessionImplBrowserTest,
PositionStateWithOneShotPlayer) { … }
IN_PROC_BROWSER_TEST_F(MediaSessionImplBrowserTest,
PositionStateWithPepperPlayer) { … }
IN_PROC_BROWSER_TEST_F(MediaSessionImplBrowserTest,
PositionStateRouteWithTwoPlayers_OneShot) { … }
IN_PROC_BROWSER_TEST_F(MediaSessionImplBrowserTest,
PositionStateRouteWithTwoPlayers_Pepper) { … }
#if BUILDFLAG(IS_CHROMEOS_ASH) || BUILDFLAG(IS_ANDROID)
#define MAYBE_PositionStateRouteWithOnePlayer …
#else
#define MAYBE_PositionStateRouteWithOnePlayer …
#endif
IN_PROC_BROWSER_TEST_F(MediaSessionImplBrowserTest,
MAYBE_PositionStateRouteWithOnePlayer) { … }
IN_PROC_BROWSER_TEST_F(MediaSessionImplBrowserTest,
AudioDeviceSettingPersists) { … }
IN_PROC_BROWSER_TEST_F(MediaSessionImplBrowserTest, CacheFaviconImages) { … }
IN_PROC_BROWSER_TEST_F(MediaSessionImplBrowserTest,
GetVisibilityNotifiesObservers) { … }
IN_PROC_BROWSER_TEST_F(MediaSessionImplBrowserTest,
GetVisibilityMultiplePlayersMeetsVisibility) { … }
IN_PROC_BROWSER_TEST_F(MediaSessionImplBrowserTest,
GetVisibilityMultiplePlayersDoesNotMeetVisibility) { … }
IN_PROC_BROWSER_TEST_F(MediaSessionImplBrowserTest,
GetVisibilityMultiplePlayersEarlyCancelDoesNotCrash) { … }
IN_PROC_BROWSER_TEST_F(MediaSessionImplBrowserTest, GetVisibilityNoPlayers) { … }
IN_PROC_BROWSER_TEST_F(MediaSessionImplBrowserTest,
GetVisibilityPlayersPausedDoesNotMeetVisibility) { … }
class MediaSessionImplPrerenderingBrowserTest
: public MediaSessionImplBrowserTest { … };
IN_PROC_BROWSER_TEST_F(MediaSessionImplPrerenderingBrowserTest,
AudioDeviceSettingPersists) { … }
IN_PROC_BROWSER_TEST_F(MediaSessionImplPrerenderingBrowserTest,
DontClearFaviconCacheOnPrerenderNavigation) { … }
class MediaSessionImplWithBackForwardCacheBrowserTest
: public MediaSessionImplBrowserTest { … };
IN_PROC_BROWSER_TEST_F(MediaSessionImplWithBackForwardCacheBrowserTest,
PlayAndCache) { … }
IN_PROC_BROWSER_TEST_F(MediaSessionImplWithBackForwardCacheBrowserTest,
PauseAndCache) { … }
IN_PROC_BROWSER_TEST_F(MediaSessionImplWithBackForwardCacheBrowserTest,
CacheClearDoesntAffectCurrentPage) { … }
}