Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(354)

Side by Side Diff: media/blink/webmediaplayer_impl_unittest.cc

Issue 2696423003: Don't pause suspended videos with no audio. (Closed)
Patch Set: Added WMPI tests Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « media/blink/webmediaplayer_impl.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "media/blink/webmediaplayer_impl.h" 5 #include "media/blink/webmediaplayer_impl.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <memory> 9 #include <memory>
10 10
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 void ForegroundPlayer() { 312 void ForegroundPlayer() {
313 delegate_.SetFrameHiddenForTesting(false); 313 delegate_.SetFrameHiddenForTesting(false);
314 delegate_.SetFrameClosedForTesting(false); 314 delegate_.SetFrameClosedForTesting(false);
315 wmpi_->OnFrameShown(); 315 wmpi_->OnFrameShown();
316 } 316 }
317 317
318 void Play() { wmpi_->play(); } 318 void Play() { wmpi_->play(); }
319 319
320 void Pause() { wmpi_->pause(); } 320 void Pause() { wmpi_->pause(); }
321 321
322 void ScheduleIdlePauseTimer() { wmpi_->ScheduleIdlePauseTimer(); }
323
324 bool IsIdlePauseTimerRunning() {
325 return wmpi_->background_pause_timer_.IsRunning();
326 }
327
328 void SetSuspendState(bool is_suspended) {
329 wmpi_->SetSuspendState(is_suspended);
330 }
331
322 // "Renderer" thread. 332 // "Renderer" thread.
323 base::MessageLoop message_loop_; 333 base::MessageLoop message_loop_;
324 334
325 // "Media" thread. This is necessary because WMPI destruction waits on a 335 // "Media" thread. This is necessary because WMPI destruction waits on a
326 // WaitableEvent. 336 // WaitableEvent.
327 base::Thread media_thread_; 337 base::Thread media_thread_;
328 338
329 // Blink state. 339 // Blink state.
330 blink::WebFrameClient web_frame_client_; 340 blink::WebFrameClient web_frame_client_;
331 blink::WebView* web_view_; 341 blink::WebView* web_view_;
(...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after
739 blink::WebScopedUserGesture user_gesture(nullptr); 749 blink::WebScopedUserGesture user_gesture(nullptr);
740 Pause(); 750 Pause();
741 EXPECT_TRUE(IsVideoLockedWhenPausedWhenHidden()); 751 EXPECT_TRUE(IsVideoLockedWhenPausedWhenHidden());
742 } 752 }
743 753
744 // Foregrounding the player unsets the lock. 754 // Foregrounding the player unsets the lock.
745 ForegroundPlayer(); 755 ForegroundPlayer();
746 EXPECT_FALSE(IsVideoLockedWhenPausedWhenHidden()); 756 EXPECT_FALSE(IsVideoLockedWhenPausedWhenHidden());
747 } 757 }
748 758
759 TEST_F(WebMediaPlayerImplTest, BackgroundIdlePauseTimerDependsOnAudio) {
760 InitializeWebMediaPlayerImpl(true);
761 SetSuspendState(true);
762 SetPaused(false);
763
764 ASSERT_TRUE(IsSuspended());
765
766 // Video-only players are not paused when suspended.
767 SetMetadata(false, true);
768 ScheduleIdlePauseTimer();
769 EXPECT_FALSE(IsIdlePauseTimerRunning());
770
771 SetMetadata(true, true);
772 ScheduleIdlePauseTimer();
773 EXPECT_TRUE(IsIdlePauseTimerRunning());
774 }
775
749 class WebMediaPlayerImplBackgroundBehaviorTest 776 class WebMediaPlayerImplBackgroundBehaviorTest
750 : public WebMediaPlayerImplTest, 777 : public WebMediaPlayerImplTest,
751 public ::testing::WithParamInterface< 778 public ::testing::WithParamInterface<
752 std::tuple<bool, bool, int, int, bool>> { 779 std::tuple<bool, bool, int, int, bool>> {
753 public: 780 public:
754 // Indices of the tuple parameters. 781 // Indices of the tuple parameters.
755 static const int kIsMediaSuspendEnabled = 0; 782 static const int kIsMediaSuspendEnabled = 0;
756 static const int kIsBackgroundOptimizationEnabled = 1; 783 static const int kIsBackgroundOptimizationEnabled = 1;
757 static const int kDurationSec = 2; 784 static const int kDurationSec = 2;
758 static const int kAverageKeyframeDistanceSec = 3; 785 static const int kAverageKeyframeDistanceSec = 3;
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
891 918
892 INSTANTIATE_TEST_CASE_P(BackgroundBehaviorTestInstances, 919 INSTANTIATE_TEST_CASE_P(BackgroundBehaviorTestInstances,
893 WebMediaPlayerImplBackgroundBehaviorTest, 920 WebMediaPlayerImplBackgroundBehaviorTest,
894 ::testing::Combine(::testing::Bool(), 921 ::testing::Combine(::testing::Bool(),
895 ::testing::Bool(), 922 ::testing::Bool(),
896 ::testing::Values(5, 300), 923 ::testing::Values(5, 300),
897 ::testing::Values(5, 100), 924 ::testing::Values(5, 100),
898 ::testing::Bool())); 925 ::testing::Bool()));
899 926
900 } // namespace media 927 } // namespace media
OLDNEW
« no previous file with comments | « media/blink/webmediaplayer_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698