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

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

Issue 2818013002: [Media] Add a feature flag to pause bg video only players. (Closed)
Patch Set: Created 3 years, 8 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 791 matching lines...) Expand 10 before | Expand all | Expand 10 after
802 EXPECT_FALSE(IsIdlePauseTimerRunning()); 802 EXPECT_FALSE(IsIdlePauseTimerRunning());
803 803
804 SetMetadata(true, true); 804 SetMetadata(true, true);
805 ScheduleIdlePauseTimer(); 805 ScheduleIdlePauseTimer();
806 EXPECT_TRUE(IsIdlePauseTimerRunning()); 806 EXPECT_TRUE(IsIdlePauseTimerRunning());
807 } 807 }
808 808
809 class WebMediaPlayerImplBackgroundBehaviorTest 809 class WebMediaPlayerImplBackgroundBehaviorTest
810 : public WebMediaPlayerImplTest, 810 : public WebMediaPlayerImplTest,
811 public ::testing::WithParamInterface< 811 public ::testing::WithParamInterface<
812 std::tuple<bool, bool, int, int, bool, bool>> { 812 std::tuple<bool, bool, int, int, bool, bool, bool>> {
813 public: 813 public:
814 // Indices of the tuple parameters. 814 // Indices of the tuple parameters.
815 static const int kIsMediaSuspendEnabled = 0; 815 static const int kIsMediaSuspendEnabled = 0;
816 static const int kIsBackgroundOptimizationEnabled = 1; 816 static const int kIsBackgroundOptimizationEnabled = 1;
817 static const int kDurationSec = 2; 817 static const int kDurationSec = 2;
818 static const int kAverageKeyframeDistanceSec = 3; 818 static const int kAverageKeyframeDistanceSec = 3;
819 static const int kIsResumeBackgroundVideoEnabled = 4; 819 static const int kIsResumeBackgroundVideoEnabled = 4;
820 static const int kIsMediaSource = 5; 820 static const int kIsMediaSource = 5;
821 static const int kIsBackgroundPauseEnabled = 6;
821 822
822 void SetUp() override { 823 void SetUp() override {
823 WebMediaPlayerImplTest::SetUp(); 824 WebMediaPlayerImplTest::SetUp();
824 825
825 SetUpMediaSuspend(IsMediaSuspendOn()); 826 SetUpMediaSuspend(IsMediaSuspendOn());
826 827
827 std::string enabled_features; 828 std::string enabled_features;
828 std::string disabled_features; 829 std::string disabled_features;
829 if (IsBackgroundOptimizationOn()) { 830 if (IsBackgroundOptimizationOn()) {
830 enabled_features += kBackgroundVideoTrackOptimization.name; 831 enabled_features += kBackgroundVideoTrackOptimization.name;
831 } else { 832 } else {
832 disabled_features += kBackgroundVideoTrackOptimization.name; 833 disabled_features += kBackgroundVideoTrackOptimization.name;
833 } 834 }
834 835
836 if (IsBackgroundPauseOn()) {
837 if (!enabled_features.empty())
838 enabled_features += ",";
839 enabled_features += kBackgroundVideoPauseOptimization.name;
840 } else {
841 if (!disabled_features.empty())
842 disabled_features += ",";
843 disabled_features += kBackgroundVideoPauseOptimization.name;
844 }
845
835 if (IsResumeBackgroundVideoEnabled()) { 846 if (IsResumeBackgroundVideoEnabled()) {
836 if (!enabled_features.empty()) 847 if (!enabled_features.empty())
837 enabled_features += ","; 848 enabled_features += ",";
838 enabled_features += kResumeBackgroundVideo.name; 849 enabled_features += kResumeBackgroundVideo.name;
839 } else { 850 } else {
840 if (!disabled_features.empty()) 851 if (!disabled_features.empty())
841 disabled_features += ","; 852 disabled_features += ",";
842 disabled_features += kResumeBackgroundVideo.name; 853 disabled_features += kResumeBackgroundVideo.name;
843 } 854 }
844 855
(...skipping 24 matching lines...) Expand all
869 } 880 }
870 881
871 bool IsBackgroundOptimizationOn() { 882 bool IsBackgroundOptimizationOn() {
872 return std::get<kIsBackgroundOptimizationEnabled>(GetParam()); 883 return std::get<kIsBackgroundOptimizationEnabled>(GetParam());
873 } 884 }
874 885
875 bool IsResumeBackgroundVideoEnabled() { 886 bool IsResumeBackgroundVideoEnabled() {
876 return std::get<kIsResumeBackgroundVideoEnabled>(GetParam()); 887 return std::get<kIsResumeBackgroundVideoEnabled>(GetParam());
877 } 888 }
878 889
890 bool IsBackgroundPauseOn() {
891 return std::get<kIsBackgroundPauseEnabled>(GetParam());
892 }
893
879 int GetDurationSec() const { return std::get<kDurationSec>(GetParam()); } 894 int GetDurationSec() const { return std::get<kDurationSec>(GetParam()); }
880 895
881 int GetAverageKeyframeDistanceSec() const { 896 int GetAverageKeyframeDistanceSec() const {
882 return std::get<kAverageKeyframeDistanceSec>(GetParam()); 897 return std::get<kAverageKeyframeDistanceSec>(GetParam());
883 } 898 }
884 899
885 int GetMaxKeyframeDistanceSec() const { 900 int GetMaxKeyframeDistanceSec() const {
886 base::TimeDelta max_keyframe_distance = 901 base::TimeDelta max_keyframe_distance =
887 std::get<kIsMediaSource>(GetParam()) 902 std::get<kIsMediaSource>(GetParam())
888 ? kMaxKeyframeDistanceToDisableBackgroundVideoMSE 903 ? kMaxKeyframeDistanceToDisableBackgroundVideoMSE
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
931 946
932 // There's no optimization criteria for video only on Android. 947 // There's no optimization criteria for video only on Android.
933 bool matches_requirements = 948 bool matches_requirements =
934 IsAndroid() || 949 IsAndroid() ||
935 ((GetDurationSec() < GetMaxKeyframeDistanceSec()) || 950 ((GetDurationSec() < GetMaxKeyframeDistanceSec()) ||
936 (GetAverageKeyframeDistanceSec() < GetMaxKeyframeDistanceSec())); 951 (GetAverageKeyframeDistanceSec() < GetMaxKeyframeDistanceSec()));
937 EXPECT_EQ(matches_requirements, IsBackgroundOptimizationCandidate()); 952 EXPECT_EQ(matches_requirements, IsBackgroundOptimizationCandidate());
938 953
939 // Video is always paused when suspension is on and only if matches the 954 // Video is always paused when suspension is on and only if matches the
940 // optimization criteria if the optimization is on. 955 // optimization criteria if the optimization is on.
941 bool should_pause = IsMediaSuspendOn() || 956 bool should_pause =
942 (IsBackgroundOptimizationOn() && matches_requirements); 957 IsMediaSuspendOn() || (IsBackgroundPauseOn() && matches_requirements);
943 EXPECT_EQ(should_pause, ShouldPauseVideoWhenHidden()); 958 EXPECT_EQ(should_pause, ShouldPauseVideoWhenHidden());
944 } 959 }
945 960
946 TEST_P(WebMediaPlayerImplBackgroundBehaviorTest, AudioVideo) { 961 TEST_P(WebMediaPlayerImplBackgroundBehaviorTest, AudioVideo) {
947 SetMetadata(true, true); 962 SetMetadata(true, true);
948 963
949 // Optimization requirements are the same for all platforms. 964 // Optimization requirements are the same for all platforms.
950 bool matches_requirements = 965 bool matches_requirements =
951 (GetDurationSec() < GetMaxKeyframeDistanceSec()) || 966 (GetDurationSec() < GetMaxKeyframeDistanceSec()) ||
952 (GetAverageKeyframeDistanceSec() < GetMaxKeyframeDistanceSec()); 967 (GetAverageKeyframeDistanceSec() < GetMaxKeyframeDistanceSec());
953 968
954 EXPECT_EQ(matches_requirements, IsBackgroundOptimizationCandidate()); 969 EXPECT_EQ(matches_requirements, IsBackgroundOptimizationCandidate());
955 EXPECT_EQ(IsBackgroundOptimizationOn() && matches_requirements, 970 EXPECT_EQ(IsBackgroundOptimizationOn() && matches_requirements,
956 ShouldDisableVideoWhenHidden()); 971 ShouldDisableVideoWhenHidden());
957 972
958 // Only pause audible videos on Android if both media suspend and resume 973 // Only pause audible videos if both media suspend and resume background
959 // background videos is on. On Desktop 974 // videos is on. Both are on by default on Android and off on desktop.
960 EXPECT_EQ(IsMediaSuspendOn() && IsResumeBackgroundVideoEnabled(), 975 EXPECT_EQ(IsMediaSuspendOn() && IsResumeBackgroundVideoEnabled(),
961 ShouldPauseVideoWhenHidden()); 976 ShouldPauseVideoWhenHidden());
962 } 977 }
963 978
964 INSTANTIATE_TEST_CASE_P(BackgroundBehaviorTestInstances, 979 INSTANTIATE_TEST_CASE_P(BackgroundBehaviorTestInstances,
965 WebMediaPlayerImplBackgroundBehaviorTest, 980 WebMediaPlayerImplBackgroundBehaviorTest,
966 ::testing::Combine(::testing::Bool(), 981 ::testing::Combine(::testing::Bool(),
967 ::testing::Bool(), 982 ::testing::Bool(),
968 ::testing::Values(5, 300), 983 ::testing::Values(5, 300),
969 ::testing::Values(5, 100), 984 ::testing::Values(5, 100),
970 ::testing::Bool(), 985 ::testing::Bool(),
986 ::testing::Bool(),
971 ::testing::Bool())); 987 ::testing::Bool()));
972 988
973 } // namespace media 989 } // 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