#include "content/browser/media/system_media_controls_notifier.h"
#include <memory>
#include <utility>
#include "base/strings/utf_string_conversions.h"
#include "build/build_config.h"
#include "components/system_media_controls/mock_system_media_controls.h"
#include "content/public/test/browser_task_environment.h"
#include "content/public/test/test_media_session_client.h"
#include "services/media_session/public/mojom/media_session.mojom.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#if BUILDFLAG(IS_WIN)
#include "ui/base/idle/scoped_set_idle_state.h"
#endif
namespace {
std::u16string hidden_metadata_placeholder_title = …;
std::u16string hidden_metadata_placeholder_artist = …;
std::u16string hidden_metadata_placeholder_album = …;
int hidden_metadata_placeholder_thumbnail_size = …;
}
namespace content {
MediaPlaybackState;
MediaSessionInfo;
MediaSessionInfoPtr;
PlaybackStatus;
_;
Expectation;
WithArg;
class SystemMediaControlsNotifierTest : public testing::Test { … };
TEST_F(SystemMediaControlsNotifierTest, ProperlyUpdatesPlaybackState) { … }
TEST_F(SystemMediaControlsNotifierTest, ProperlyDebouncesPlaybackState) { … }
TEST_F(SystemMediaControlsNotifierTest, StopClearsPendingPlaybackState) { … }
TEST_F(SystemMediaControlsNotifierTest, ProperlyUpdatesMetadata) { … }
TEST_F(SystemMediaControlsNotifierTest, ProperlyUpdatesNullMetadata) { … }
TEST_F(SystemMediaControlsNotifierTest, ProperlyDebouncesMetadataUpdates) { … }
TEST_F(SystemMediaControlsNotifierTest, ProperlyUpdatesMetadaBetweenDebounces) { … }
TEST_F(SystemMediaControlsNotifierTest, EmptyMetadataClearsPendingMetadata) { … }
TEST_F(SystemMediaControlsNotifierTest, ProperlyUpdatesPosition) { … }
TEST_F(SystemMediaControlsNotifierTest, ProperlyHandlesNullPosition) { … }
TEST_F(SystemMediaControlsNotifierTest, ProperlyDebouncesPositionUpdates) { … }
TEST_F(SystemMediaControlsNotifierTest,
ProperlyUpdatesPositionBetweenDebounces) { … }
TEST_F(SystemMediaControlsNotifierTest, NullPositionClearsPendingPosition) { … }
TEST_F(SystemMediaControlsNotifierTest, ProperlyUpdatesImage) { … }
TEST_F(SystemMediaControlsNotifierTest, ProperlyDebouncesImage) { … }
TEST_F(SystemMediaControlsNotifierTest, ProperlyUpdatesIsSeekTooEnabled) { … }
TEST_F(SystemMediaControlsNotifierTest, ProperlyDebouncesIsSeekTooEnabled) { … }
TEST_F(SystemMediaControlsNotifierTest, ProperlyUpdatesID) { … }
TEST_F(SystemMediaControlsNotifierTest, DontHideMediaMetadataIfNotNeeded) { … }
TEST_F(SystemMediaControlsNotifierTest, HideMediaMetadataIfNeeded) { … }
TEST_F(SystemMediaControlsNotifierTest, HideMediaImageIfNeeded) { … }
#if BUILDFLAG(IS_WIN)
TEST_F(SystemMediaControlsNotifierTest, DisablesOnLockAndEnablesOnUnlock) {
EXPECT_CALL(mock_system_media_controls(), SetEnabled(false));
{
ui::ScopedSetIdleState locked(ui::IDLE_STATE_LOCKED);
EXPECT_TRUE(lock_polling_timer().IsRunning());
lock_polling_timer().user_task().Run();
}
testing::Mock::VerifyAndClearExpectations(&mock_system_media_controls());
EXPECT_CALL(mock_system_media_controls(), SetEnabled(true));
{
ui::ScopedSetIdleState unlocked(ui::IDLE_STATE_ACTIVE);
EXPECT_TRUE(lock_polling_timer().IsRunning());
lock_polling_timer().user_task().Run();
}
}
TEST_F(SystemMediaControlsNotifierTest, DoesNotDisableOnLockWhenPlaying) {
EXPECT_CALL(mock_system_media_controls(), SetEnabled(_)).Times(0);
SimulatePlaying();
ui::ScopedSetIdleState locked(ui::IDLE_STATE_LOCKED);
EXPECT_TRUE(lock_polling_timer().IsRunning());
lock_polling_timer().user_task().Run();
}
TEST_F(SystemMediaControlsNotifierTest, DisablesAfterPausingOnLockScreen) {
Expectation playing =
EXPECT_CALL(mock_system_media_controls(),
SetPlaybackStatus(PlaybackStatus::kPlaying));
Expectation paused = EXPECT_CALL(mock_system_media_controls(),
SetPlaybackStatus(PlaybackStatus::kPaused))
.After(playing);
EXPECT_CALL(mock_system_media_controls(), SetEnabled(false)).After(paused);
SimulatePlaying();
metadata_update_timer().FireNow();
ui::ScopedSetIdleState locked(ui::IDLE_STATE_LOCKED);
EXPECT_TRUE(lock_polling_timer().IsRunning());
lock_polling_timer().user_task().Run();
EXPECT_FALSE(hide_smtc_timer().IsRunning());
SimulatePaused();
metadata_update_timer().FireNow();
EXPECT_TRUE(hide_smtc_timer().IsRunning());
hide_smtc_timer().FireNow();
}
#endif
}