Commit 02b79250 authored by Becca Hughes's avatar Becca Hughes Committed by Commit Bot

[Media Session] Make controllable if we have playback state

This changes MediaSession to be controllable if we
have set a playback state through the routed service.

This is to fix cases where a site may not be controllable
if the media is shorter than 7 seconds but we want it to be
controllable (e.g. if it is a media app).

BUG=902519

Change-Id: I86ef8ffca0fb6a3e6c11b2ca90e2a3c020cb9d70
Reviewed-on: https://chromium-review.googlesource.com/c/1393444
Commit-Queue: Becca Hughes <beccahughes@chromium.org>
Reviewed-by: default avatarMounir Lamouri <mlamouri@chromium.org>
Cr-Commit-Position: refs/heads/master@{#620102}
parent 82cbd968
......@@ -492,12 +492,19 @@ void MediaSessionImpl::Seek(base::TimeDelta seek_time) {
}
bool MediaSessionImpl::IsControllable() const {
// Only media session having focus Gain can be controllable unless it is
// inactive. Also, the session will be uncontrollable if it contains one-shot
// players.
return audio_focus_state_ != State::INACTIVE &&
desired_audio_focus_type_ == AudioFocusType::kGain &&
one_shot_players_.empty();
// If the session does not have audio focus or it has one shot players then it
// cannot be controllable.
if (audio_focus_state_ == State::INACTIVE || !one_shot_players_.empty())
return false;
#if !defined(OS_ANDROID)
if (routed_service_ && routed_service_->playback_state() !=
blink::mojom::MediaSessionPlaybackState::NONE) {
return true;
}
#endif
return desired_audio_focus_type_ == AudioFocusType::kGain;
}
bool MediaSessionImpl::IsActuallyPaused() const {
......
......@@ -756,6 +756,112 @@ IN_PROC_BROWSER_TEST_P(MediaSessionImplParamBrowserTest,
EXPECT_TRUE(IsActive());
}
// This behaviour is specific to desktop.
#if !defined(OS_ANDROID)
IN_PROC_BROWSER_TEST_P(MediaSessionImplParamBrowserTest,
ControlsNoShowForTransientAndRoutedService) {
EnsureMediaSessionService();
auto player_observer = std::make_unique<MockMediaSessionPlayerObserver>(
shell()->web_contents()->GetMainFrame());
EXPECT_CALL(*mock_media_session_observer(),
MediaSessionStateChanged(false, false));
// Starting a player with a transient type should not show the media controls.
StartNewPlayer(player_observer.get(), media::MediaContentType::Transient);
ResolveAudioFocusSuccess();
EXPECT_FALSE(IsControllable());
EXPECT_TRUE(IsActive());
}
IN_PROC_BROWSER_TEST_P(MediaSessionImplParamBrowserTest,
ControlsNoShowForTransientAndPlaybackStateNone) {
EnsureMediaSessionService();
auto player_observer = std::make_unique<MockMediaSessionPlayerObserver>(
shell()->web_contents()->GetMainFrame());
::testing::Sequence s;
EXPECT_CALL(*mock_media_session_observer(),
MediaSessionStateChanged(false, false))
.InSequence(s);
EXPECT_CALL(*mock_media_session_observer(),
MediaSessionStateChanged(false, _))
.InSequence(s);
// Starting a player with a transient type should not show the media controls.
StartNewPlayer(player_observer.get(), media::MediaContentType::Transient);
ResolveAudioFocusSuccess();
SetPlaybackState(blink::mojom::MediaSessionPlaybackState::NONE);
EXPECT_FALSE(IsControllable());
EXPECT_TRUE(IsActive());
// Verify before test exists. Otherwise the sequence will expire and cause
// weird problems.
::testing::Mock::VerifyAndClear(mock_media_session_observer());
}
IN_PROC_BROWSER_TEST_P(MediaSessionImplParamBrowserTest,
ControlsShowForTransientAndPlaybackStatePaused) {
EnsureMediaSessionService();
auto player_observer = std::make_unique<MockMediaSessionPlayerObserver>(
shell()->web_contents()->GetMainFrame());
::testing::Sequence s;
EXPECT_CALL(*mock_media_session_observer(),
MediaSessionStateChanged(false, false))
.InSequence(s);
EXPECT_CALL(*mock_media_session_observer(), MediaSessionStateChanged(true, _))
.InSequence(s);
// Starting a player with a transient type should show the media controls if
// we have a playback state from the service.
StartNewPlayer(player_observer.get(), media::MediaContentType::Transient);
ResolveAudioFocusSuccess();
SetPlaybackState(blink::mojom::MediaSessionPlaybackState::PAUSED);
EXPECT_TRUE(IsControllable());
EXPECT_TRUE(IsActive());
// Verify before test exists. Otherwise the sequence will expire and cause
// weird problems.
::testing::Mock::VerifyAndClear(mock_media_session_observer());
}
IN_PROC_BROWSER_TEST_P(MediaSessionImplParamBrowserTest,
ControlsShowForTransientAndPlaybackStatePlaying) {
EnsureMediaSessionService();
auto player_observer = std::make_unique<MockMediaSessionPlayerObserver>(
shell()->web_contents()->GetMainFrame());
::testing::Sequence s;
EXPECT_CALL(*mock_media_session_observer(),
MediaSessionStateChanged(false, false))
.InSequence(s);
EXPECT_CALL(*mock_media_session_observer(), MediaSessionStateChanged(true, _))
.InSequence(s);
// Starting a player with a transient type should show the media controls if
// we have a playback state from the service.
StartNewPlayer(player_observer.get(), media::MediaContentType::Transient);
ResolveAudioFocusSuccess();
SetPlaybackState(blink::mojom::MediaSessionPlaybackState::PLAYING);
EXPECT_TRUE(IsControllable());
EXPECT_TRUE(IsActive());
// Verify before test exists. Otherwise the sequence will expire and cause
// weird problems.
::testing::Mock::VerifyAndClear(mock_media_session_observer());
}
#endif // !defined(OS_ANDROID)
IN_PROC_BROWSER_TEST_P(MediaSessionImplParamBrowserTest,
ControlsHideWhenStopped) {
Expectation showControls = EXPECT_CALL(*mock_media_session_observer(),
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment