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

Side by Side Diff: third_party/WebKit/Source/modules/media_controls/MediaControlsOrientationLockDelegateTest.cpp

Issue 2919513002: [Media Controls] Prevent fullscreen orientation lock rotate glitch (Closed)
Patch Set: Created 3 years, 6 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 | « third_party/WebKit/Source/modules/media_controls/MediaControlsOrientationLockDelegate.cpp ('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 "modules/media_controls/MediaControlsOrientationLockDelegate.h" 5 #include "modules/media_controls/MediaControlsOrientationLockDelegate.h"
6 6
7 #include "core/HTMLNames.h" 7 #include "core/HTMLNames.h"
8 #include "core/dom/Document.h" 8 #include "core/dom/Document.h"
9 #include "core/dom/DocumentUserGestureToken.h" 9 #include "core/dom/DocumentUserGestureToken.h"
10 #include "core/dom/Fullscreen.h" 10 #include "core/dom/Fullscreen.h"
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 return WTF::MakeUnique<MockVideoWebMediaPlayer>(); 100 return WTF::MakeUnique<MockVideoWebMediaPlayer>();
101 } 101 }
102 }; 102 };
103 103
104 } // anonymous namespace 104 } // anonymous namespace
105 105
106 class MediaControlsOrientationLockDelegateTest : public ::testing::Test { 106 class MediaControlsOrientationLockDelegateTest : public ::testing::Test {
107 protected: 107 protected:
108 using DeviceOrientation = 108 using DeviceOrientation =
109 MediaControlsOrientationLockDelegate::DeviceOrientation; 109 MediaControlsOrientationLockDelegate::DeviceOrientation;
110 static constexpr int kUnlockDelayMs =
111 MediaControlsOrientationLockDelegate::kUnlockDelayMs;
110 112
111 void SetUp() override { 113 void SetUp() override {
112 chrome_client_ = new MockChromeClient(); 114 chrome_client_ = new MockChromeClient();
113 115
114 Page::PageClients clients; 116 Page::PageClients clients;
115 FillWithEmptyClients(clients); 117 FillWithEmptyClients(clients);
116 clients.chrome_client = chrome_client_.Get(); 118 clients.chrome_client = chrome_client_.Get();
117 119
118 page_holder_ = DummyPageHolder::Create(IntSize(800, 600), &clients, 120 page_holder_ = DummyPageHolder::Create(IntSize(800, 600), &clients,
119 StubLocalFrameClient::Create()); 121 StubLocalFrameClient::Create());
(...skipping 642 matching lines...) Expand 10 before | Expand all | Expand 10 after
762 // MediaControlsRotateToFullscreenDelegate should enter fullscreen, so 764 // MediaControlsRotateToFullscreenDelegate should enter fullscreen, so
763 // MediaControlsOrientationLockDelegate should lock orientation to landscape 765 // MediaControlsOrientationLockDelegate should lock orientation to landscape
764 // (even though the screen is already landscape). 766 // (even though the screen is already landscape).
765 EXPECT_TRUE(Video().IsFullscreen()); 767 EXPECT_TRUE(Video().IsFullscreen());
766 CheckStateMaybeLockedFullscreen(); 768 CheckStateMaybeLockedFullscreen();
767 EXPECT_EQ(kWebScreenOrientationLockLandscape, DelegateOrientationLock()); 769 EXPECT_EQ(kWebScreenOrientationLockLandscape, DelegateOrientationLock());
768 770
769 // Device orientation events received by MediaControlsOrientationLockDelegate 771 // Device orientation events received by MediaControlsOrientationLockDelegate
770 // will confirm that the device is already landscape. 772 // will confirm that the device is already landscape.
771 RotateDeviceTo(90 /* landscape primary */); 773 RotateDeviceTo(90 /* landscape primary */);
774 testing::RunDelayedTasks(kUnlockDelayMs);
772 775
773 // MediaControlsOrientationLockDelegate should unlock orientation. 776 // MediaControlsOrientationLockDelegate should unlock orientation.
774 CheckStatePendingFullscreen(); 777 CheckStatePendingFullscreen();
775 EXPECT_FALSE(DelegateWillUnlockFullscreen()); 778 EXPECT_FALSE(DelegateWillUnlockFullscreen());
776 } 779 }
777 780
778 TEST_F(MediaControlsOrientationLockAndRotateToFullscreenDelegateTest, 781 TEST_F(MediaControlsOrientationLockAndRotateToFullscreenDelegateTest,
779 PortraitInlineButtonToPortraitLockedLandscapeFullscreen) { 782 PortraitInlineButtonToPortraitLockedLandscapeFullscreen) {
780 // Naturally portrait device, initially portrait, with landscape video. 783 // Naturally portrait device, initially portrait, with landscape video.
781 natural_orientation_is_portrait_ = true; 784 natural_orientation_is_portrait_ = true;
(...skipping 14 matching lines...) Expand all
796 // MediaControlsOrientationLockDelegate should lock to landscape. 799 // MediaControlsOrientationLockDelegate should lock to landscape.
797 CheckStateMaybeLockedFullscreen(); 800 CheckStateMaybeLockedFullscreen();
798 EXPECT_EQ(kWebScreenOrientationLockLandscape, DelegateOrientationLock()); 801 EXPECT_EQ(kWebScreenOrientationLockLandscape, DelegateOrientationLock());
799 802
800 // This will trigger a screen orientation change to landscape. 803 // This will trigger a screen orientation change to landscape.
801 ASSERT_NO_FATAL_FAILURE( 804 ASSERT_NO_FATAL_FAILURE(
802 RotateScreenTo(kWebScreenOrientationLandscapePrimary, 90)); 805 RotateScreenTo(kWebScreenOrientationLandscapePrimary, 90));
803 806
804 // Even though the device is still held in portrait. 807 // Even though the device is still held in portrait.
805 RotateDeviceTo(0 /* portrait primary */); 808 RotateDeviceTo(0 /* portrait primary */);
809 testing::RunDelayedTasks(kUnlockDelayMs);
806 810
807 // MediaControlsOrientationLockDelegate should remain locked to landscape. 811 // MediaControlsOrientationLockDelegate should remain locked to landscape.
808 CheckStateMaybeLockedFullscreen(); 812 CheckStateMaybeLockedFullscreen();
809 EXPECT_EQ(kWebScreenOrientationLockLandscape, DelegateOrientationLock()); 813 EXPECT_EQ(kWebScreenOrientationLockLandscape, DelegateOrientationLock());
810 } 814 }
811 815
812 TEST_F(MediaControlsOrientationLockAndRotateToFullscreenDelegateTest, 816 TEST_F(MediaControlsOrientationLockAndRotateToFullscreenDelegateTest,
813 PortraitLockedLandscapeFullscreenRotateToLandscapeFullscreen) { 817 PortraitLockedLandscapeFullscreenRotateToLandscapeFullscreen) {
814 // Naturally portrait device, initially portrait device orientation but locked 818 // Naturally portrait device, initially portrait device orientation but locked
815 // to landscape screen orientation, with landscape video. 819 // to landscape screen orientation, with landscape video.
816 natural_orientation_is_portrait_ = true; 820 natural_orientation_is_portrait_ = true;
817 ASSERT_NO_FATAL_FAILURE( 821 ASSERT_NO_FATAL_FAILURE(
818 RotateScreenTo(kWebScreenOrientationLandscapePrimary, 90)); 822 RotateScreenTo(kWebScreenOrientationLandscapePrimary, 90));
819 InitVideo(640, 480); 823 InitVideo(640, 480);
820 SetIsAutoRotateEnabledByUser(true); 824 SetIsAutoRotateEnabledByUser(true);
821 825
822 // Initially fullscreen, locked orientation. 826 // Initially fullscreen, locked orientation.
823 SimulateEnterFullscreen(); 827 SimulateEnterFullscreen();
824 ASSERT_TRUE(Video().IsFullscreen()); 828 ASSERT_TRUE(Video().IsFullscreen());
825 CheckStateMaybeLockedFullscreen(); 829 CheckStateMaybeLockedFullscreen();
826 EXPECT_EQ(kWebScreenOrientationLockLandscape, DelegateOrientationLock()); 830 EXPECT_EQ(kWebScreenOrientationLockLandscape, DelegateOrientationLock());
827 831
828 // Simulate user rotating their device to landscape (matching the screen 832 // Simulate user rotating their device to landscape (matching the screen
829 // orientation lock). 833 // orientation lock).
830 RotateDeviceTo(90 /* landscape primary */); 834 RotateDeviceTo(90 /* landscape primary */);
835 testing::RunDelayedTasks(kUnlockDelayMs);
831 836
832 // MediaControlsOrientationLockDelegate should unlock orientation. 837 // MediaControlsOrientationLockDelegate should unlock orientation.
833 CheckStatePendingFullscreen(); 838 CheckStatePendingFullscreen();
834 EXPECT_FALSE(DelegateWillUnlockFullscreen()); 839 EXPECT_FALSE(DelegateWillUnlockFullscreen());
835 EXPECT_TRUE(Video().IsFullscreen()); 840 EXPECT_TRUE(Video().IsFullscreen());
836 } 841 }
837 842
838 TEST_F(MediaControlsOrientationLockAndRotateToFullscreenDelegateTest, 843 TEST_F(MediaControlsOrientationLockAndRotateToFullscreenDelegateTest,
839 PortraitLockedLandscapeFullscreenBackToPortraitInline) { 844 PortraitLockedLandscapeFullscreenBackToPortraitInline) {
840 // Naturally portrait device, initially portrait device orientation but locked 845 // Naturally portrait device, initially portrait device orientation but locked
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
891 896
892 // Initially inline, unlocked orientation. 897 // Initially inline, unlocked orientation.
893 ASSERT_FALSE(Video().IsFullscreen()); 898 ASSERT_FALSE(Video().IsFullscreen());
894 CheckStatePendingFullscreen(); 899 CheckStatePendingFullscreen();
895 ASSERT_FALSE(DelegateWillUnlockFullscreen()); 900 ASSERT_FALSE(DelegateWillUnlockFullscreen());
896 901
897 // Simulate user rotating their device to portrait triggering a screen 902 // Simulate user rotating their device to portrait triggering a screen
898 // orientation change. 903 // orientation change.
899 ASSERT_NO_FATAL_FAILURE( 904 ASSERT_NO_FATAL_FAILURE(
900 RotateScreenTo(kWebScreenOrientationPortraitPrimary, 0)); 905 RotateScreenTo(kWebScreenOrientationPortraitPrimary, 0));
906 testing::RunDelayedTasks(kUnlockDelayMs);
901 907
902 // Video should remain inline, unlocked. 908 // Video should remain inline, unlocked.
903 CheckStatePendingFullscreen(); 909 CheckStatePendingFullscreen();
904 EXPECT_FALSE(DelegateWillUnlockFullscreen()); 910 EXPECT_FALSE(DelegateWillUnlockFullscreen());
905 EXPECT_FALSE(Video().IsFullscreen()); 911 EXPECT_FALSE(Video().IsFullscreen());
906 } 912 }
907 913
908 TEST_F(MediaControlsOrientationLockAndRotateToFullscreenDelegateTest, 914 TEST_F(MediaControlsOrientationLockAndRotateToFullscreenDelegateTest,
909 LandscapeInlineButtonToLandscapeFullscreen) { 915 LandscapeInlineButtonToLandscapeFullscreen) {
910 // Naturally portrait device, initially landscape, with landscape video. 916 // Naturally portrait device, initially landscape, with landscape video.
(...skipping 13 matching lines...) Expand all
924 EXPECT_TRUE(Video().IsFullscreen()); 930 EXPECT_TRUE(Video().IsFullscreen());
925 931
926 // MediaControlsOrientationLockDelegate should lock to landscape (even though 932 // MediaControlsOrientationLockDelegate should lock to landscape (even though
927 // the screen is already landscape). 933 // the screen is already landscape).
928 CheckStateMaybeLockedFullscreen(); 934 CheckStateMaybeLockedFullscreen();
929 EXPECT_EQ(kWebScreenOrientationLockLandscape, DelegateOrientationLock()); 935 EXPECT_EQ(kWebScreenOrientationLockLandscape, DelegateOrientationLock());
930 936
931 // Device orientation events received by MediaControlsOrientationLockDelegate 937 // Device orientation events received by MediaControlsOrientationLockDelegate
932 // will confirm that the device is already landscape. 938 // will confirm that the device is already landscape.
933 RotateDeviceTo(90 /* landscape primary */); 939 RotateDeviceTo(90 /* landscape primary */);
940 testing::RunDelayedTasks(kUnlockDelayMs);
934 941
935 // MediaControlsOrientationLockDelegate should unlock orientation. 942 // MediaControlsOrientationLockDelegate should unlock orientation.
936 CheckStatePendingFullscreen(); 943 CheckStatePendingFullscreen();
937 EXPECT_FALSE(DelegateWillUnlockFullscreen()); 944 EXPECT_FALSE(DelegateWillUnlockFullscreen());
938 } 945 }
939 946
940 TEST_F(MediaControlsOrientationLockAndRotateToFullscreenDelegateTest, 947 TEST_F(MediaControlsOrientationLockAndRotateToFullscreenDelegateTest,
941 LandscapeFullscreenRotateToPortraitInline) { 948 LandscapeFullscreenRotateToPortraitInline) {
942 // Naturally portrait device, initially landscape, with landscape video. 949 // Naturally portrait device, initially landscape, with landscape video.
943 natural_orientation_is_portrait_ = true; 950 natural_orientation_is_portrait_ = true;
944 ASSERT_NO_FATAL_FAILURE( 951 ASSERT_NO_FATAL_FAILURE(
945 RotateScreenTo(kWebScreenOrientationLandscapePrimary, 90)); 952 RotateScreenTo(kWebScreenOrientationLandscapePrimary, 90));
946 InitVideo(640, 480); 953 InitVideo(640, 480);
947 SetIsAutoRotateEnabledByUser(true); 954 SetIsAutoRotateEnabledByUser(true);
948 955
949 // Initially fullscreen, unlocked orientation. 956 // Initially fullscreen, unlocked orientation.
950 SimulateEnterFullscreen(); 957 SimulateEnterFullscreen();
951 RotateDeviceTo(90 /* landscape primary */); 958 RotateDeviceTo(90 /* landscape primary */);
959 testing::RunDelayedTasks(kUnlockDelayMs);
952 ASSERT_TRUE(Video().IsFullscreen()); 960 ASSERT_TRUE(Video().IsFullscreen());
953 CheckStatePendingFullscreen(); 961 CheckStatePendingFullscreen();
954 EXPECT_FALSE(DelegateWillUnlockFullscreen()); 962 EXPECT_FALSE(DelegateWillUnlockFullscreen());
955 963
956 // Simulate user rotating their device to portrait triggering a screen 964 // Simulate user rotating their device to portrait triggering a screen
957 // orientation change. 965 // orientation change.
958 ASSERT_NO_FATAL_FAILURE( 966 ASSERT_NO_FATAL_FAILURE(
959 RotateScreenTo(kWebScreenOrientationPortraitPrimary, 0)); 967 RotateScreenTo(kWebScreenOrientationPortraitPrimary, 0));
968 testing::RunDelayedTasks(kUnlockDelayMs);
960 969
961 // MediaControlsRotateToFullscreenDelegate should exit fullscreen. 970 // MediaControlsRotateToFullscreenDelegate should exit fullscreen.
962 EXPECT_FALSE(Video().IsFullscreen()); 971 EXPECT_FALSE(Video().IsFullscreen());
963 972
964 // MediaControlsOrientationLockDelegate should remain unlocked. 973 // MediaControlsOrientationLockDelegate should remain unlocked.
965 CheckStatePendingFullscreen(); 974 CheckStatePendingFullscreen();
966 EXPECT_FALSE(DelegateWillUnlockFullscreen()); 975 EXPECT_FALSE(DelegateWillUnlockFullscreen());
967 } 976 }
968 977
969 TEST_F(MediaControlsOrientationLockAndRotateToFullscreenDelegateTest, 978 TEST_F(MediaControlsOrientationLockAndRotateToFullscreenDelegateTest,
970 LandscapeFullscreenBackToLandscapeInline) { 979 LandscapeFullscreenBackToLandscapeInline) {
971 // Naturally portrait device, initially landscape, with landscape video. 980 // Naturally portrait device, initially landscape, with landscape video.
972 natural_orientation_is_portrait_ = true; 981 natural_orientation_is_portrait_ = true;
973 ASSERT_NO_FATAL_FAILURE( 982 ASSERT_NO_FATAL_FAILURE(
974 RotateScreenTo(kWebScreenOrientationLandscapePrimary, 90)); 983 RotateScreenTo(kWebScreenOrientationLandscapePrimary, 90));
975 InitVideo(640, 480); 984 InitVideo(640, 480);
976 SetIsAutoRotateEnabledByUser(true); 985 SetIsAutoRotateEnabledByUser(true);
977 986
978 // Initially fullscreen, unlocked orientation. 987 // Initially fullscreen, unlocked orientation.
979 SimulateEnterFullscreen(); 988 SimulateEnterFullscreen();
980 RotateDeviceTo(90 /* landscape primary */); 989 RotateDeviceTo(90 /* landscape primary */);
990 testing::RunDelayedTasks(kUnlockDelayMs);
981 ASSERT_TRUE(Video().IsFullscreen()); 991 ASSERT_TRUE(Video().IsFullscreen());
982 CheckStatePendingFullscreen(); 992 CheckStatePendingFullscreen();
983 EXPECT_FALSE(DelegateWillUnlockFullscreen()); 993 EXPECT_FALSE(DelegateWillUnlockFullscreen());
984 994
985 // Simulate user clicking on media controls exit fullscreen button. 995 // Simulate user clicking on media controls exit fullscreen button.
986 // orientation lock). 996 // orientation lock).
987 SimulateExitFullscreen(); 997 SimulateExitFullscreen();
988 EXPECT_FALSE(Video().IsFullscreen()); 998 EXPECT_FALSE(Video().IsFullscreen());
989 999
990 // MediaControlsOrientationLockDelegate should remain unlocked. 1000 // MediaControlsOrientationLockDelegate should remain unlocked.
(...skipping 25 matching lines...) Expand all
1016 CheckStateMaybeLockedFullscreen(); 1026 CheckStateMaybeLockedFullscreen();
1017 EXPECT_EQ(kWebScreenOrientationLockLandscape, DelegateOrientationLock()); 1027 EXPECT_EQ(kWebScreenOrientationLockLandscape, DelegateOrientationLock());
1018 1028
1019 // This will trigger a screen orientation change to landscape, since the app's 1029 // This will trigger a screen orientation change to landscape, since the app's
1020 // lock overrides the user's orientation lock (at least on Android). 1030 // lock overrides the user's orientation lock (at least on Android).
1021 ASSERT_NO_FATAL_FAILURE( 1031 ASSERT_NO_FATAL_FAILURE(
1022 RotateScreenTo(kWebScreenOrientationLandscapePrimary, 90)); 1032 RotateScreenTo(kWebScreenOrientationLandscapePrimary, 90));
1023 1033
1024 // Even though the device is still held in portrait. 1034 // Even though the device is still held in portrait.
1025 RotateDeviceTo(0 /* portrait primary */); 1035 RotateDeviceTo(0 /* portrait primary */);
1036 testing::RunDelayedTasks(kUnlockDelayMs);
1026 1037
1027 // MediaControlsOrientationLockDelegate should remain locked to landscape. 1038 // MediaControlsOrientationLockDelegate should remain locked to landscape.
1028 CheckStateMaybeLockedFullscreen(); 1039 CheckStateMaybeLockedFullscreen();
1029 EXPECT_EQ(kWebScreenOrientationLockLandscape, DelegateOrientationLock()); 1040 EXPECT_EQ(kWebScreenOrientationLockLandscape, DelegateOrientationLock());
1030 } 1041 }
1031 1042
1032 TEST_F( 1043 TEST_F(
1033 MediaControlsOrientationLockAndRotateToFullscreenDelegateTest, 1044 MediaControlsOrientationLockAndRotateToFullscreenDelegateTest,
1034 AutoRotateDisabledPortraitLockedLandscapeFullscreenRotateToLandscapeLockedLa ndscapeFullscreen) { 1045 AutoRotateDisabledPortraitLockedLandscapeFullscreenRotateToLandscapeLockedLa ndscapeFullscreen) {
1035 // Naturally portrait device, initially portrait device orientation but locked 1046 // Naturally portrait device, initially portrait device orientation but locked
1036 // to landscape screen orientation, with landscape video. 1047 // to landscape screen orientation, with landscape video.
1037 natural_orientation_is_portrait_ = true; 1048 natural_orientation_is_portrait_ = true;
1038 ASSERT_NO_FATAL_FAILURE( 1049 ASSERT_NO_FATAL_FAILURE(
1039 RotateScreenTo(kWebScreenOrientationLandscapePrimary, 90)); 1050 RotateScreenTo(kWebScreenOrientationLandscapePrimary, 90));
1040 InitVideo(640, 480); 1051 InitVideo(640, 480);
1041 // But this time the user has disabled auto rotate, e.g. locked to portrait 1052 // But this time the user has disabled auto rotate, e.g. locked to portrait
1042 // (even though the app's landscape screen orientation lock overrides it). 1053 // (even though the app's landscape screen orientation lock overrides it).
1043 SetIsAutoRotateEnabledByUser(false); 1054 SetIsAutoRotateEnabledByUser(false);
1044 1055
1045 // Initially fullscreen, locked orientation. 1056 // Initially fullscreen, locked orientation.
1046 SimulateEnterFullscreen(); 1057 SimulateEnterFullscreen();
1047 ASSERT_TRUE(Video().IsFullscreen()); 1058 ASSERT_TRUE(Video().IsFullscreen());
1048 CheckStateMaybeLockedFullscreen(); 1059 CheckStateMaybeLockedFullscreen();
1049 EXPECT_EQ(kWebScreenOrientationLockLandscape, DelegateOrientationLock()); 1060 EXPECT_EQ(kWebScreenOrientationLockLandscape, DelegateOrientationLock());
1050 1061
1051 // Simulate user rotating their device to landscape (matching the screen 1062 // Simulate user rotating their device to landscape (matching the screen
1052 // orientation lock). 1063 // orientation lock).
1053 RotateDeviceTo(90 /* landscape primary */); 1064 RotateDeviceTo(90 /* landscape primary */);
1065 testing::RunDelayedTasks(kUnlockDelayMs);
1054 1066
1055 // MediaControlsOrientationLockDelegate should remain locked to landscape even 1067 // MediaControlsOrientationLockDelegate should remain locked to landscape even
1056 // though the screen orientation is now landscape, since the user has disabled 1068 // though the screen orientation is now landscape, since the user has disabled
1057 // auto rotate, so unlocking now would cause the device to return to the 1069 // auto rotate, so unlocking now would cause the device to return to the
1058 // portrait orientation. 1070 // portrait orientation.
1059 CheckStateMaybeLockedFullscreen(); 1071 CheckStateMaybeLockedFullscreen();
1060 EXPECT_EQ(kWebScreenOrientationLockLandscape, DelegateOrientationLock()); 1072 EXPECT_EQ(kWebScreenOrientationLockLandscape, DelegateOrientationLock());
1061 EXPECT_TRUE(Video().IsFullscreen()); 1073 EXPECT_TRUE(Video().IsFullscreen());
1062 } 1074 }
1063 1075
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
1125 // Initially fullscreen, locked orientation. 1137 // Initially fullscreen, locked orientation.
1126 SimulateEnterFullscreen(); 1138 SimulateEnterFullscreen();
1127 ASSERT_TRUE(Video().IsFullscreen()); 1139 ASSERT_TRUE(Video().IsFullscreen());
1128 CheckStateMaybeLockedFullscreen(); 1140 CheckStateMaybeLockedFullscreen();
1129 EXPECT_EQ(kWebScreenOrientationLockLandscape, DelegateOrientationLock()); 1141 EXPECT_EQ(kWebScreenOrientationLockLandscape, DelegateOrientationLock());
1130 1142
1131 // Simulate user rotating their device to portrait (matching the user's 1143 // Simulate user rotating their device to portrait (matching the user's
1132 // rotation lock, but perpendicular to MediaControlsOrientationLockDelegate's 1144 // rotation lock, but perpendicular to MediaControlsOrientationLockDelegate's
1133 // screen orientation lock which overrides it). 1145 // screen orientation lock which overrides it).
1134 RotateDeviceTo(0 /* portrait primary */); 1146 RotateDeviceTo(0 /* portrait primary */);
1147 testing::RunDelayedTasks(kUnlockDelayMs);
1135 1148
1136 // Video should remain locked and fullscreen. This may disappoint users who 1149 // Video should remain locked and fullscreen. This may disappoint users who
1137 // expect MediaControlsRotateToFullscreenDelegate to let them always leave 1150 // expect MediaControlsRotateToFullscreenDelegate to let them always leave
1138 // fullscreen by rotating perpendicular to the video's orientation (i.e. 1151 // fullscreen by rotating perpendicular to the video's orientation (i.e.
1139 // rotating to portrait for a landscape video), however in this specific case, 1152 // rotating to portrait for a landscape video), however in this specific case,
1140 // since the user disabled auto rotate at the OS level, it's likely that they 1153 // since the user disabled auto rotate at the OS level, it's likely that they
1141 // wish to be able to use their phone whilst their head is lying sideways on a 1154 // wish to be able to use their phone whilst their head is lying sideways on a
1142 // pillow (or similar), in which case it's essential to keep the fullscreen 1155 // pillow (or similar), in which case it's essential to keep the fullscreen
1143 // orientation lock. 1156 // orientation lock.
1144 CheckStateMaybeLockedFullscreen(); 1157 CheckStateMaybeLockedFullscreen();
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
1218 // MediaControlsRotateToFullscreenDelegate should enter fullscreen, so 1231 // MediaControlsRotateToFullscreenDelegate should enter fullscreen, so
1219 // MediaControlsOrientationLockDelegate should lock orientation to portrait 1232 // MediaControlsOrientationLockDelegate should lock orientation to portrait
1220 // (even though the screen is already portrait). 1233 // (even though the screen is already portrait).
1221 EXPECT_TRUE(Video().IsFullscreen()); 1234 EXPECT_TRUE(Video().IsFullscreen());
1222 CheckStateMaybeLockedFullscreen(); 1235 CheckStateMaybeLockedFullscreen();
1223 EXPECT_EQ(kWebScreenOrientationLockPortrait, DelegateOrientationLock()); 1236 EXPECT_EQ(kWebScreenOrientationLockPortrait, DelegateOrientationLock());
1224 1237
1225 // Device orientation events received by MediaControlsOrientationLockDelegate 1238 // Device orientation events received by MediaControlsOrientationLockDelegate
1226 // will confirm that the device is already portrait. 1239 // will confirm that the device is already portrait.
1227 RotateDeviceTo(0 /* portrait primary */); 1240 RotateDeviceTo(0 /* portrait primary */);
1241 testing::RunDelayedTasks(kUnlockDelayMs);
1228 1242
1229 // MediaControlsOrientationLockDelegate should unlock orientation. 1243 // MediaControlsOrientationLockDelegate should unlock orientation.
1230 CheckStatePendingFullscreen(); 1244 CheckStatePendingFullscreen();
1231 EXPECT_FALSE(DelegateWillUnlockFullscreen()); 1245 EXPECT_FALSE(DelegateWillUnlockFullscreen());
1232 EXPECT_TRUE(Video().IsFullscreen()); 1246 EXPECT_TRUE(Video().IsFullscreen());
1233 1247
1234 // Simulate user rotating their device to landscape triggering a screen 1248 // Simulate user rotating their device to landscape triggering a screen
1235 // orientation change. 1249 // orientation change.
1236 ASSERT_NO_FATAL_FAILURE( 1250 ASSERT_NO_FATAL_FAILURE(
1237 RotateScreenTo(kWebScreenOrientationLandscapePrimary, 90)); 1251 RotateScreenTo(kWebScreenOrientationLandscapePrimary, 90));
(...skipping 30 matching lines...) Expand all
1268 // MediaControlsRotateToFullscreenDelegate should enter fullscreen, so 1282 // MediaControlsRotateToFullscreenDelegate should enter fullscreen, so
1269 // MediaControlsOrientationLockDelegate should lock orientation to landscape 1283 // MediaControlsOrientationLockDelegate should lock orientation to landscape
1270 // (even though the screen is already landscape). 1284 // (even though the screen is already landscape).
1271 EXPECT_TRUE(Video().IsFullscreen()); 1285 EXPECT_TRUE(Video().IsFullscreen());
1272 CheckStateMaybeLockedFullscreen(); 1286 CheckStateMaybeLockedFullscreen();
1273 EXPECT_EQ(kWebScreenOrientationLockLandscape, DelegateOrientationLock()); 1287 EXPECT_EQ(kWebScreenOrientationLockLandscape, DelegateOrientationLock());
1274 1288
1275 // Device orientation events received by MediaControlsOrientationLockDelegate 1289 // Device orientation events received by MediaControlsOrientationLockDelegate
1276 // will confirm that the device is already landscape. 1290 // will confirm that the device is already landscape.
1277 RotateDeviceTo(0 /* landscape primary */); 1291 RotateDeviceTo(0 /* landscape primary */);
1292 testing::RunDelayedTasks(kUnlockDelayMs);
1278 1293
1279 // MediaControlsOrientationLockDelegate should unlock orientation. 1294 // MediaControlsOrientationLockDelegate should unlock orientation.
1280 CheckStatePendingFullscreen(); 1295 CheckStatePendingFullscreen();
1281 EXPECT_FALSE(DelegateWillUnlockFullscreen()); 1296 EXPECT_FALSE(DelegateWillUnlockFullscreen());
1282 EXPECT_TRUE(Video().IsFullscreen()); 1297 EXPECT_TRUE(Video().IsFullscreen());
1283 1298
1284 // Simulate user rotating their device to portrait triggering a screen 1299 // Simulate user rotating their device to portrait triggering a screen
1285 // orientation change. 1300 // orientation change.
1286 ASSERT_NO_FATAL_FAILURE( 1301 ASSERT_NO_FATAL_FAILURE(
1287 RotateScreenTo(kWebScreenOrientationPortraitPrimary, 270)); 1302 RotateScreenTo(kWebScreenOrientationPortraitPrimary, 270));
1288 1303
1289 // MediaControlsRotateToFullscreenDelegate should exit fullscreen. 1304 // MediaControlsRotateToFullscreenDelegate should exit fullscreen.
1290 EXPECT_FALSE(Video().IsFullscreen()); 1305 EXPECT_FALSE(Video().IsFullscreen());
1291 1306
1292 // MediaControlsOrientationLockDelegate should remain unlocked. 1307 // MediaControlsOrientationLockDelegate should remain unlocked.
1293 CheckStatePendingFullscreen(); 1308 CheckStatePendingFullscreen();
1294 EXPECT_FALSE(DelegateWillUnlockFullscreen()); 1309 EXPECT_FALSE(DelegateWillUnlockFullscreen());
1295 } 1310 }
1296 1311
1312 TEST_F(MediaControlsOrientationLockAndRotateToFullscreenDelegateTest,
1313 ScreenOrientationRace) {
1314 // Naturally portrait device, initially portrait, with landscape video.
1315 natural_orientation_is_portrait_ = true;
1316 ASSERT_NO_FATAL_FAILURE(
1317 RotateScreenTo(kWebScreenOrientationPortraitPrimary, 0));
1318 InitVideo(640, 480);
1319 SetIsAutoRotateEnabledByUser(true);
1320
1321 // Initially inline, unlocked orientation.
1322 ASSERT_FALSE(Video().IsFullscreen());
1323 CheckStatePendingFullscreen();
1324 ASSERT_FALSE(DelegateWillUnlockFullscreen());
1325
1326 // Simulate user clicking on media controls fullscreen button.
1327 SimulateEnterFullscreen();
1328 EXPECT_TRUE(Video().IsFullscreen());
1329
1330 // MediaControlsOrientationLockDelegate should lock to landscape.
1331 CheckStateMaybeLockedFullscreen();
1332 EXPECT_EQ(kWebScreenOrientationLockLandscape, DelegateOrientationLock());
1333
1334 // This will trigger a screen orientation change to landscape.
1335 ASSERT_NO_FATAL_FAILURE(
1336 RotateScreenTo(kWebScreenOrientationLandscapePrimary, 90));
1337
1338 // Even though the device is still held in portrait.
1339 RotateDeviceTo(0 /* portrait primary */);
1340
1341 // MediaControlsOrientationLockDelegate should remain locked to landscape
1342 // indefinitely.
1343 testing::RunDelayedTasks(kUnlockDelayMs);
1344 CheckStateMaybeLockedFullscreen();
1345 EXPECT_EQ(kWebScreenOrientationLockLandscape, DelegateOrientationLock());
1346
1347 // Now suppose the user actually rotates from portrait-primary to landscape-
1348 // secondary, despite the screen currently being landscape-primary.
1349 RotateDeviceTo(270 /* landscape secondary */);
1350
1351 // MediaControlsOrientationLockDelegate should remain locked to landscape for
1352 // a few hundred milliseconds...
1353 testing::RunDelayedTasks(249);
1354 CheckStateMaybeLockedFullscreen();
1355 EXPECT_EQ(kWebScreenOrientationLockLandscape, DelegateOrientationLock());
1356
1357 // ...because it might take that long for Android to update the screen
1358 // orientation due to low pass filtering.
1359 ASSERT_NO_FATAL_FAILURE(
1360 RotateScreenTo(kWebScreenOrientationLandscapeSecondary, 270));
1361
1362 // MediaControlsOrientationLockDelegate should remain locked to landscape.
1363 CheckStateMaybeLockedFullscreen();
1364 EXPECT_EQ(kWebScreenOrientationLockLandscape, DelegateOrientationLock());
1365
1366 // Wait for the rest of the unlock delay.
1367 testing::RunDelayedTasks(kUnlockDelayMs - 249);
mlamouri (slow - plz ping) 2017/05/31 20:18:37 Maybe you could harden this test by using `kUnlock
johnme 2017/06/01 17:21:56 If kUnlockDelayMs becomes lower than 250 (or at le
1368
1369 // MediaControlsOrientationLockDelegate should now have unlocked.
1370 CheckStatePendingFullscreen();
1371 EXPECT_FALSE(DelegateWillUnlockFullscreen());
1372 }
1373
1297 } // namespace blink 1374 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/modules/media_controls/MediaControlsOrientationLockDelegate.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698