Chromium Code Reviews| Index: media/base/android/media_source_player_unittest.cc |
| diff --git a/media/base/android/media_source_player_unittest.cc b/media/base/android/media_source_player_unittest.cc |
| index 5da992be13e2c4db39b1efd95c3b75445b4803a9..43bc69081c90242778fe138218c76351b14b99f7 100644 |
| --- a/media/base/android/media_source_player_unittest.cc |
| +++ b/media/base/android/media_source_player_unittest.cc |
| @@ -46,7 +46,9 @@ class MockMediaPlayerManager : public MediaPlayerManager { |
| playback_completed_(false), |
| num_resources_requested_(0), |
| num_metadata_changes_(0), |
| - timestamp_updated_(false) {} |
| + timestamp_updated_(false), |
| + is_audible_(false), |
| + is_audible_idle_timeout_expired_(false) {} |
| ~MockMediaPlayerManager() override {} |
| // MediaPlayerManager implementation. |
| @@ -75,7 +77,6 @@ class MockMediaPlayerManager : public MediaPlayerManager { |
| const base::TimeDelta& current_time) override {} |
| void OnError(int player_id, int error) override {} |
| void OnVideoSizeChanged(int player_id, int width, int height) override {} |
| - void OnAudibleStateChanged(int player_id, bool is_audible_now) override {} |
| void OnWaitingForDecryptionKey(int player_id) override {} |
| MediaPlayerAndroid* GetFullscreenPlayer() override { return NULL; } |
| MediaPlayerAndroid* GetPlayer(int player_id) override { return NULL; } |
| @@ -86,6 +87,10 @@ class MockMediaPlayerManager : public MediaPlayerManager { |
| } |
| #endif // defined(VIDEO_HOLE) |
| + void OnAudibleStateChanged(int player_id, bool is_audible_now) override { |
| + is_audible_ = is_audible_now; |
| + } |
| + |
| bool playback_completed() const { |
| return playback_completed_; |
| } |
| @@ -110,6 +115,18 @@ class MockMediaPlayerManager : public MediaPlayerManager { |
| timestamp_updated_ = false; |
| } |
| + bool is_audible() const { |
| + return is_audible_; |
| + } |
| + |
| + bool is_audible_idle_timeout_expired() const { |
| + return is_audible_idle_timeout_expired_; |
| + } |
| + |
| + void SetAudibleIdleTimeoutExpired(bool value) { |
| + is_audible_idle_timeout_expired_ = value; |
| + } |
| + |
| private: |
| base::MessageLoop* message_loop_; |
| bool playback_completed_; |
| @@ -119,6 +136,11 @@ class MockMediaPlayerManager : public MediaPlayerManager { |
| int num_metadata_changes_; |
| // Playback timestamp was updated. |
| bool timestamp_updated_; |
| + // Audible state of the pipeline |
| + bool is_audible_; |
| + // Helper flag to ensure delay before we check |
| + // the audible state |
| + bool is_audible_idle_timeout_expired_; |
| DISALLOW_COPY_AND_ASSIGN(MockMediaPlayerManager); |
| }; |
| @@ -176,6 +198,7 @@ class MediaSourcePlayerTest : public testing::Test { |
| GURL()), |
| decoder_callback_hook_executed_(false), |
| surface_texture_a_is_next_(true) {} |
| + |
| ~MediaSourcePlayerTest() override {} |
| protected: |
| @@ -842,6 +865,7 @@ class MediaSourcePlayerTest : public testing::Test { |
| return GetMediaDecoderJob(is_audio)->drain_decoder_; |
| } |
| + protected: |
| base::MessageLoop message_loop_; |
| MockMediaPlayerManager manager_; |
| MockDemuxerAndroid* demuxer_; // Owned by |player_|. |
| @@ -862,6 +886,8 @@ class MediaSourcePlayerTest : public testing::Test { |
| bool surface_texture_a_is_next_; |
| int next_texture_id_; |
| + bool verify_not_audible_is_called_; |
| + |
| DISALLOW_COPY_AND_ASSIGN(MediaSourcePlayerTest); |
| }; |
| @@ -893,6 +919,63 @@ TEST_F(MediaSourcePlayerTest, StartAudioDecoderWithInvalidConfig) { |
| EXPECT_FALSE(GetMediaCodecBridge(true)); |
| } |
| +// timav |
| +TEST_F(MediaSourcePlayerTest, AudioDecoderSetsAudibleState) { |
| + SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); |
| + |
| + // No data arrived yet |
| + EXPECT_FALSE(manager_.is_audible()); |
| + |
| + StartAudioDecoderJob(); |
| + player_.SetVolume(1.0); |
| + |
| + // The first decoded frame should report the audio state |
| + // to the manager |
| + DecodeAudioDataUntilOutputBecomesAvailable(); |
| + EXPECT_TRUE(manager_.is_audible()); |
| + |
| + // The player release should report a non-audible state. |
| + ReleasePlayer(); |
| + EXPECT_FALSE(manager_.is_audible()); |
| +} |
| + |
| +TEST_F(MediaSourcePlayerTest, AudioDecoderRemovesAudibleStateWhenIdle) { |
| + SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); |
| + |
| + // No data arrived yet |
| + EXPECT_FALSE(manager_.is_audible()); |
| + |
| + StartAudioDecoderJob(); |
| + player_.SetVolume(1.0); |
| + |
| + // Shorten the idle period for the test to 300 ms |
| + const int kDelay = 300; // milliseconds |
| + player_.SetAudibleStateIdlePeriod(base::TimeDelta::FromMilliseconds(kDelay)); |
| + |
| + // The first decoded frame should report the audio state |
| + // to the manager |
| + DecodeAudioDataUntilOutputBecomesAvailable(); |
| + EXPECT_TRUE(manager_.is_audible()); |
| + |
| + // Wait till more than 300 ms pass (we wait 400 ms in this case) |
| + manager_.SetAudibleIdleTimeoutExpired(false); |
| + message_loop_.PostDelayedTask( |
|
Tima Vaisburd
2015/03/18 01:35:02
I wanted to guarantee that this delayed task arriv
|
| + FROM_HERE, |
| + base::Bind(&MockMediaPlayerManager::SetAudibleIdleTimeoutExpired, |
| + base::Unretained(&manager_), |
| + true), |
| + base::TimeDelta::FromMilliseconds(kDelay + 100)); |
| + |
| + while (!manager_.is_audible_idle_timeout_expired()) |
| + message_loop_.RunUntilIdle(); |
| + |
| + // The player should have reported that there is no audio |
| + // by this time. |
| + EXPECT_FALSE(manager_.is_audible()); |
| + |
| + ReleasePlayer(); |
| +} |
| + |
| TEST_F(MediaSourcePlayerTest, StartVideoCodecWithValidSurface) { |
| SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); |