#include "content/browser/media/session/media_session_impl.h"
#include <memory>
#include "base/command_line.h"
#include "base/memory/ptr_util.h"
#include "base/test/scoped_feature_list.h"
#include "build/build_config.h"
#include "content/browser/media/session/media_session_player_observer.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/public/browser/browser_context.h"
#include "content/public/browser/media_session_service.h"
#include "content/public/browser/web_contents_delegate.h"
#include "content/public/test/test_browser_context.h"
#include "content/public/test/test_media_session_client.h"
#include "content/public/test/test_renderer_host.h"
#include "content/test/test_web_contents.h"
#include "media/base/media_content_type.h"
#include "media/base/media_switches.h"
#include "services/media_session/public/cpp/features.h"
#include "services/media_session/public/cpp/test/audio_focus_test_util.h"
#include "services/media_session/public/cpp/test/mock_media_session.h"
#include "services/media_session/public/mojom/audio_focus.mojom.h"
#include "services/media_session/public/mojom/media_session.mojom.h"
#include "third_party/blink/public/common/features.h"
_;
namespace content {
AudioFocusType;
MediaPlaybackState;
MediaSessionAction;
MediaSessionInfo;
MediaSessionInfoPtr;
MockMediaSessionMojoObserver;
TestAudioFocusObserver;
namespace {
class MockAudioFocusDelegate : public AudioFocusDelegate { … };
class MockWebContentsDelegate : public content::WebContentsDelegate { … };
}
class MediaSessionImplTest : public RenderViewHostTestHarness { … };
TEST_F(MediaSessionImplTest, SessionInfoState) { … }
TEST_F(MediaSessionImplTest, NotifyDelegateOnStateChange) { … }
TEST_F(MediaSessionImplTest, PepperForcesDuckAndRequestsFocus) { … }
TEST_F(MediaSessionImplTest, RegisterObserver) { … }
TEST_F(MediaSessionImplTest, SessionInfo_PlaybackState) { … }
TEST_F(MediaSessionImplTest, SuspendUI) { … }
TEST_F(MediaSessionImplTest, SuspendContent_WithAction) { … }
TEST_F(MediaSessionImplTest, SuspendSystem_WithAction) { … }
TEST_F(MediaSessionImplTest, SuspendUI_WithAction) { … }
TEST_F(MediaSessionImplTest, ResumeUI) { … }
TEST_F(MediaSessionImplTest, ResumeContent_WithAction) { … }
TEST_F(MediaSessionImplTest, ResumeSystem_WithAction) { … }
TEST_F(MediaSessionImplTest, ResumeUI_WithAction) { … }
#if !BUILDFLAG(IS_ANDROID)
TEST_F(MediaSessionImplTest, WebContentsDestroyed_ReleasesFocus) { … }
TEST_F(MediaSessionImplTest, WebContentsDestroyed_ReleasesTransients) { … }
TEST_F(MediaSessionImplTest, WebContentsDestroyed_StopsDucking) { … }
#if BUILDFLAG(IS_MAC)
TEST_F(MediaSessionImplTest, TabFocusDoesNotCauseAudioFocus) {
MockAudioFocusDelegate* delegate = new MockAudioFocusDelegate();
SetDelegateForTests(GetMediaSession(), delegate);
{
MockMediaSessionMojoObserver observer(*GetMediaSession());
RequestAudioFocus(GetMediaSession(), AudioFocusType::kGain);
FlushForTesting(GetMediaSession());
observer.WaitForState(MediaSessionInfo::SessionState::kActive);
}
EXPECT_EQ(1, delegate->request_audio_focus_count());
GetMediaSession()->OnWebContentsFocused(nullptr);
EXPECT_EQ(1, delegate->request_audio_focus_count());
}
#else
TEST_F(MediaSessionImplTest, RequestAudioFocus_OnFocus_Active) { … }
TEST_F(MediaSessionImplTest, RequestAudioFocus_OnFocus_Inactive) { … }
TEST_F(MediaSessionImplTest, RequestAudioFocus_OnFocus_Suspended) { … }
#endif
#endif
TEST_F(MediaSessionImplTest, SourceId_SameBrowserContext) { … }
TEST_F(MediaSessionImplTest, SourceId_DifferentBrowserContext) { … }
TEST_F(MediaSessionImplTest, SessionInfoPictureInPicture) { … }
TEST_F(MediaSessionImplTest, SessionInfoAudioSink) { … }
TEST_F(MediaSessionImplTest, SessionInfoPresentation) { … }
TEST_F(MediaSessionImplTest, SessionInfoRemotePlaybackMetadata) { … }
TEST_F(MediaSessionImplTest, RaiseActivatesWebContents) { … }
TEST_F(MediaSessionImplTest,
RegisteredEnterPictureInPictureExposesAutoPictureInPicture) { … }
TEST_F(MediaSessionImplTest, WebContentsHasPictureInPictureVideo) { … }
TEST_F(MediaSessionImplTest, WebContentsHasPictureInPictureDocument) { … }
TEST_F(MediaSessionImplTest, SufficientlyVisibleVideo_NoPlayer) { … }
TEST_F(MediaSessionImplTest, SufficientlyVisibleVideo_MultiplePlayers) { … }
TEST_F(MediaSessionImplTest, SessionInfoDontHideMetadataByDefault) { … }
TEST_F(MediaSessionImplTest, PausedPlayersDoNotRequestFocus) { … }
TEST_F(MediaSessionImplTest, SeekingAndScrubbingNotAllowedWithMaxDuration) { … }
class MediaSessionImplWithMediaSessionClientTest : public MediaSessionImplTest { … };
TEST_F(MediaSessionImplWithMediaSessionClientTest,
SessionInfoDontHideMetadata) { … }
TEST_F(MediaSessionImplWithMediaSessionClientTest, SessionInfoHideMetadata) { … }
class MediaSessionImplIsSensitive : public MediaSessionImplTest,
public ::testing::WithParamInterface<bool> { … };
INSTANTIATE_TEST_SUITE_P(…);
TEST_P(MediaSessionImplIsSensitive, SessionInfo_IsSensitive_NormalSession) { … }
TEST_P(MediaSessionImplIsSensitive, SessionInfo_IsSensitive_OffTheRecord) { … }
class MediaSessionImplDurationThrottleTest : public MediaSessionImplTest { … };
TEST_F(MediaSessionImplDurationThrottleTest, ThrottleDurationUpdate) { … }
TEST_F(MediaSessionImplDurationThrottleTest, ThrottleResetOnPlayerChange) { … }
}