Commit a6658bf1 authored by Michael Sun's avatar Michael Sun Committed by Commit Bot

[Media Keys] Add handling for Media Stop

To support the "stop" event generated by the Bluetooth devices with
AVRCP (Audio/Video Remote Control Profile), add handling for the stop
key.

BUG=b/147367020

Change-Id: I4bc9efa74173d8ffeab0affb4d685bc587f07616
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2063809Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Reviewed-by: default avatarBecca Hughes <beccahughes@chromium.org>
Commit-Queue: Michael Sun <michaelfsun@google.com>
Cr-Commit-Position: refs/heads/master@{#743143}
parent 9bf4c080
......@@ -177,6 +177,31 @@ void MediaControllerImpl::HandleMediaPause() {
client_->HandleMediaPause();
}
void MediaControllerImpl::HandleMediaStop() {
if (Shell::Get()->session_controller()->IsScreenLocked() &&
!AreLockScreenMediaKeysEnabled()) {
return;
}
ui::RecordMediaHardwareKeyAction(ui::MediaHardwareKeyAction::kStop);
// If the |client_| is force handling the keys then we should forward them.
if (client_ && force_media_client_key_handling_) {
client_->HandleMediaStop();
return;
}
// If media session media key handling is enabled. Fire stop using the media
// session service.
if (ShouldUseMediaSession()) {
GetMediaSessionController()->Stop();
return;
}
if (client_)
client_->HandleMediaStop();
}
void MediaControllerImpl::HandleMediaNextTrack() {
if (Shell::Get()->session_controller()->IsScreenLocked() &&
!AreLockScreenMediaKeysEnabled()) {
......
......@@ -62,6 +62,7 @@ class ASH_EXPORT MediaControllerImpl
void HandleMediaPlayPause();
void HandleMediaPlay();
void HandleMediaPause();
void HandleMediaStop();
void HandleMediaNextTrack();
void HandleMediaPrevTrack();
......
......@@ -76,6 +76,8 @@ class MediaControllerTest : public AshTestBase {
Flush();
Shell::Get()->media_controller()->HandleMediaPause();
Flush();
Shell::Get()->media_controller()->HandleMediaStop();
Flush();
Shell::Get()->media_controller()->HandleMediaPrevTrack();
Flush();
Shell::Get()->media_controller()->HandleMediaNextTrack();
......@@ -91,6 +93,7 @@ class MediaControllerTest : public AshTestBase {
TEST_F(MediaControllerTest, EnableMediaKeysWhenUnlocked) {
EXPECT_EQ(0, controller()->suspend_count());
EXPECT_EQ(0, controller()->resume_count());
EXPECT_EQ(0, controller()->stop_count());
EXPECT_EQ(0, controller()->previous_track_count());
EXPECT_EQ(0, controller()->next_track_count());
......@@ -98,6 +101,7 @@ TEST_F(MediaControllerTest, EnableMediaKeysWhenUnlocked) {
EXPECT_EQ(2, controller()->suspend_count());
EXPECT_EQ(1, controller()->resume_count());
EXPECT_EQ(1, controller()->stop_count());
EXPECT_EQ(1, controller()->previous_track_count());
EXPECT_EQ(1, controller()->next_track_count());
}
......@@ -153,6 +157,7 @@ TEST_F(MediaControllerTest, EnableMediaKeysWhenLockedAndControlsEnabled) {
EXPECT_EQ(0, controller()->suspend_count());
EXPECT_EQ(0, controller()->resume_count());
EXPECT_EQ(0, controller()->stop_count());
EXPECT_EQ(0, controller()->previous_track_count());
EXPECT_EQ(0, controller()->next_track_count());
......@@ -162,6 +167,7 @@ TEST_F(MediaControllerTest, EnableMediaKeysWhenLockedAndControlsEnabled) {
EXPECT_EQ(2, controller()->suspend_count());
EXPECT_EQ(1, controller()->resume_count());
EXPECT_EQ(1, controller()->stop_count());
EXPECT_EQ(1, controller()->previous_track_count());
EXPECT_EQ(1, controller()->next_track_count());
}
......@@ -173,6 +179,7 @@ TEST_F(MediaControllerTest, DisableMediaKeysWhenLockedAndControlsDisabled) {
EXPECT_EQ(0, controller()->suspend_count());
EXPECT_EQ(0, controller()->resume_count());
EXPECT_EQ(0, controller()->stop_count());
EXPECT_EQ(0, controller()->previous_track_count());
EXPECT_EQ(0, controller()->next_track_count());
......@@ -182,6 +189,7 @@ TEST_F(MediaControllerTest, DisableMediaKeysWhenLockedAndControlsDisabled) {
EXPECT_EQ(0, controller()->suspend_count());
EXPECT_EQ(0, controller()->resume_count());
EXPECT_EQ(0, controller()->stop_count());
EXPECT_EQ(0, controller()->previous_track_count());
EXPECT_EQ(0, controller()->next_track_count());
}
......
......@@ -24,6 +24,9 @@ class ASH_PUBLIC_EXPORT MediaClient {
// Handles the Pause Media shortcut key.
virtual void HandleMediaPause() = 0;
// Handles the Stop Media shortcut key.
virtual void HandleMediaStop() = 0;
// Handles the Previous Track Media shortcut key.
virtual void HandleMediaPrevTrack() = 0;
......
......@@ -25,6 +25,10 @@ void TestMediaClient::HandleMediaPause() {
++handle_media_pause_count_;
}
void TestMediaClient::HandleMediaStop() {
++handle_media_stop_count_;
}
void TestMediaClient::HandleMediaPrevTrack() {
++handle_media_prev_track_count_;
}
......
......@@ -22,6 +22,7 @@ class TestMediaClient : public MediaClient {
void HandleMediaPlayPause() override;
void HandleMediaPlay() override;
void HandleMediaPause() override;
void HandleMediaStop() override;
void HandleMediaPrevTrack() override;
void RequestCaptureState() override;
void SuspendMediaSessions() override;
......@@ -34,6 +35,7 @@ class TestMediaClient : public MediaClient {
}
int handle_media_play_count() const { return handle_media_play_count_; }
int handle_media_pause_count() const { return handle_media_pause_count_; }
int handle_media_stop_count() const { return handle_media_pause_count_; }
int handle_media_prev_track_count() const {
return handle_media_prev_track_count_;
}
......@@ -44,6 +46,7 @@ class TestMediaClient : public MediaClient {
int handle_media_play_pause_count_ = 0;
int handle_media_play_count_ = 0;
int handle_media_pause_count_ = 0;
int handle_media_stop_count_ = 0;
int handle_media_prev_track_count_ = 0;
bool media_sessions_suspended_ = false;
......
......@@ -189,6 +189,10 @@ void MediaClientImpl::HandleMediaPause() {
HandleMediaAction(ui::VKEY_MEDIA_PAUSE);
}
void MediaClientImpl::HandleMediaStop() {
HandleMediaAction(ui::VKEY_MEDIA_STOP);
}
void MediaClientImpl::HandleMediaPrevTrack() {
HandleMediaAction(ui::VKEY_MEDIA_PREV_TRACK);
}
......@@ -303,10 +307,11 @@ void MediaClientImpl::HandleMediaAction(ui::KeyboardCode keycode) {
case ui::VKEY_MEDIA_PLAY_PAUSE:
router->NotifyTogglePlayState();
break;
// TODO(https://crbug.com/1053777): Handle media action for VKEY_MEDIA_PLAY
// and VKEY_MEDIA_PAUSE.
// TODO(https://crbug.com/1053777): Handle media action for VKEY_MEDIA_PLAY,
// VKEY_MEDIA_PAUSE, and VKEY_MEDIA_STOP.
case ui::VKEY_MEDIA_PLAY:
case ui::VKEY_MEDIA_PAUSE:
case ui::VKEY_MEDIA_STOP:
break;
default:
break;
......
......@@ -39,6 +39,7 @@ class MediaClientImpl : public ash::MediaClient,
void HandleMediaPlayPause() override;
void HandleMediaPlay() override;
void HandleMediaPause() override;
void HandleMediaStop() override;
void HandleMediaPrevTrack() override;
void RequestCaptureState() override;
void SuspendMediaSessions() override;
......
......@@ -243,6 +243,44 @@ TEST_F(MediaClientTest, HandleMediaPause) {
EXPECT_EQ(base::nullopt, delegate()->ConsumeLastMediaKey());
}
TEST_F(MediaClientTest, HandleMediaStop) {
const ui::Accelerator test_accelerator(ui::VKEY_MEDIA_STOP, ui::EF_NONE);
// Enable custom media key handling for the current browser. Ensure that the
// client set the override on the controller.
client()->EnableCustomMediaKeyHandler(profile(), delegate());
EXPECT_TRUE(controller()->force_media_client_key_handling());
// Simulate the media key and check that the delegate received it.
client()->HandleMediaStop();
EXPECT_EQ(test_accelerator, delegate()->ConsumeLastMediaKey());
// Change the active browser and ensure the override was disabled.
BrowserList::SetLastActive(alt_browser());
EXPECT_FALSE(controller()->force_media_client_key_handling());
// Simulate the media key and check that the delegate did not receive it.
client()->HandleMediaStop();
EXPECT_EQ(base::nullopt, delegate()->ConsumeLastMediaKey());
// Change the active browser back and ensure the override was enabled.
BrowserList::SetLastActive(browser());
EXPECT_TRUE(controller()->force_media_client_key_handling());
// Simulate the media key and check the delegate received it.
client()->HandleMediaStop();
EXPECT_EQ(test_accelerator, delegate()->ConsumeLastMediaKey());
// Disable custom media key handling for the current browser and ensure the
// override was disabled.
client()->DisableCustomMediaKeyHandler(profile(), delegate());
EXPECT_FALSE(controller()->force_media_client_key_handling());
// Simulate the media key and check the delegate did not receive it.
client()->HandleMediaStop();
EXPECT_EQ(base::nullopt, delegate()->ConsumeLastMediaKey());
}
TEST_F(MediaClientTest, HandleMediaNextTrack) {
const ui::Accelerator test_accelerator(ui::VKEY_MEDIA_NEXT_TRACK,
ui::EF_NONE);
......
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