| OLD | NEW |
| 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/Fullscreen.h" | 9 #include "core/dom/Fullscreen.h" |
| 10 #include "core/dom/UserGestureIndicator.h" | 10 #include "core/dom/UserGestureIndicator.h" |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 return WTF::MakeUnique<MockVideoWebMediaPlayer>(); | 99 return WTF::MakeUnique<MockVideoWebMediaPlayer>(); |
| 100 } | 100 } |
| 101 }; | 101 }; |
| 102 | 102 |
| 103 } // anonymous namespace | 103 } // anonymous namespace |
| 104 | 104 |
| 105 class MediaControlsOrientationLockDelegateTest : public ::testing::Test { | 105 class MediaControlsOrientationLockDelegateTest : public ::testing::Test { |
| 106 protected: | 106 protected: |
| 107 using DeviceOrientationType = | 107 using DeviceOrientationType = |
| 108 MediaControlsOrientationLockDelegate::DeviceOrientationType; | 108 MediaControlsOrientationLockDelegate::DeviceOrientationType; |
| 109 static constexpr int kUnlockDelayMs = |
| 110 MediaControlsOrientationLockDelegate::kUnlockDelayMs; |
| 109 | 111 |
| 110 void SetUp() override { | 112 void SetUp() override { |
| 111 chrome_client_ = new MockChromeClient(); | 113 chrome_client_ = new MockChromeClient(); |
| 112 | 114 |
| 113 Page::PageClients clients; | 115 Page::PageClients clients; |
| 114 FillWithEmptyClients(clients); | 116 FillWithEmptyClients(clients); |
| 115 clients.chrome_client = chrome_client_.Get(); | 117 clients.chrome_client = chrome_client_.Get(); |
| 116 | 118 |
| 117 page_holder_ = DummyPageHolder::Create(IntSize(800, 600), &clients, | 119 page_holder_ = DummyPageHolder::Create(IntSize(800, 600), &clients, |
| 118 StubLocalFrameClient::Create()); | 120 StubLocalFrameClient::Create()); |
| (...skipping 639 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 758 // MediaControlsRotateToFullscreenDelegate should enter fullscreen, so | 760 // MediaControlsRotateToFullscreenDelegate should enter fullscreen, so |
| 759 // MediaControlsOrientationLockDelegate should lock orientation to landscape | 761 // MediaControlsOrientationLockDelegate should lock orientation to landscape |
| 760 // (even though the screen is already landscape). | 762 // (even though the screen is already landscape). |
| 761 EXPECT_TRUE(Video().IsFullscreen()); | 763 EXPECT_TRUE(Video().IsFullscreen()); |
| 762 CheckStateMaybeLockedFullscreen(); | 764 CheckStateMaybeLockedFullscreen(); |
| 763 EXPECT_EQ(kWebScreenOrientationLockLandscape, DelegateOrientationLock()); | 765 EXPECT_EQ(kWebScreenOrientationLockLandscape, DelegateOrientationLock()); |
| 764 | 766 |
| 765 // Device orientation events received by MediaControlsOrientationLockDelegate | 767 // Device orientation events received by MediaControlsOrientationLockDelegate |
| 766 // will confirm that the device is already landscape. | 768 // will confirm that the device is already landscape. |
| 767 RotateDeviceTo(90 /* landscape primary */); | 769 RotateDeviceTo(90 /* landscape primary */); |
| 770 testing::RunDelayedTasks(kUnlockDelayMs); |
| 768 | 771 |
| 769 // MediaControlsOrientationLockDelegate should unlock orientation. | 772 // MediaControlsOrientationLockDelegate should unlock orientation. |
| 770 CheckStatePendingFullscreen(); | 773 CheckStatePendingFullscreen(); |
| 771 EXPECT_FALSE(DelegateWillUnlockFullscreen()); | 774 EXPECT_FALSE(DelegateWillUnlockFullscreen()); |
| 772 } | 775 } |
| 773 | 776 |
| 774 TEST_F(MediaControlsOrientationLockAndRotateToFullscreenDelegateTest, | 777 TEST_F(MediaControlsOrientationLockAndRotateToFullscreenDelegateTest, |
| 775 PortraitInlineButtonToPortraitLockedLandscapeFullscreen) { | 778 PortraitInlineButtonToPortraitLockedLandscapeFullscreen) { |
| 776 // Naturally portrait device, initially portrait, with landscape video. | 779 // Naturally portrait device, initially portrait, with landscape video. |
| 777 natural_orientation_is_portrait_ = true; | 780 natural_orientation_is_portrait_ = true; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 792 // MediaControlsOrientationLockDelegate should lock to landscape. | 795 // MediaControlsOrientationLockDelegate should lock to landscape. |
| 793 CheckStateMaybeLockedFullscreen(); | 796 CheckStateMaybeLockedFullscreen(); |
| 794 EXPECT_EQ(kWebScreenOrientationLockLandscape, DelegateOrientationLock()); | 797 EXPECT_EQ(kWebScreenOrientationLockLandscape, DelegateOrientationLock()); |
| 795 | 798 |
| 796 // This will trigger a screen orientation change to landscape. | 799 // This will trigger a screen orientation change to landscape. |
| 797 ASSERT_NO_FATAL_FAILURE( | 800 ASSERT_NO_FATAL_FAILURE( |
| 798 RotateScreenTo(kWebScreenOrientationLandscapePrimary, 90)); | 801 RotateScreenTo(kWebScreenOrientationLandscapePrimary, 90)); |
| 799 | 802 |
| 800 // Even though the device is still held in portrait. | 803 // Even though the device is still held in portrait. |
| 801 RotateDeviceTo(0 /* portrait primary */); | 804 RotateDeviceTo(0 /* portrait primary */); |
| 805 testing::RunDelayedTasks(kUnlockDelayMs); |
| 802 | 806 |
| 803 // MediaControlsOrientationLockDelegate should remain locked to landscape. | 807 // MediaControlsOrientationLockDelegate should remain locked to landscape. |
| 804 CheckStateMaybeLockedFullscreen(); | 808 CheckStateMaybeLockedFullscreen(); |
| 805 EXPECT_EQ(kWebScreenOrientationLockLandscape, DelegateOrientationLock()); | 809 EXPECT_EQ(kWebScreenOrientationLockLandscape, DelegateOrientationLock()); |
| 806 } | 810 } |
| 807 | 811 |
| 808 TEST_F(MediaControlsOrientationLockAndRotateToFullscreenDelegateTest, | 812 TEST_F(MediaControlsOrientationLockAndRotateToFullscreenDelegateTest, |
| 809 PortraitLockedLandscapeFullscreenRotateToLandscapeFullscreen) { | 813 PortraitLockedLandscapeFullscreenRotateToLandscapeFullscreen) { |
| 810 // Naturally portrait device, initially portrait device orientation but locked | 814 // Naturally portrait device, initially portrait device orientation but locked |
| 811 // to landscape screen orientation, with landscape video. | 815 // to landscape screen orientation, with landscape video. |
| 812 natural_orientation_is_portrait_ = true; | 816 natural_orientation_is_portrait_ = true; |
| 813 ASSERT_NO_FATAL_FAILURE( | 817 ASSERT_NO_FATAL_FAILURE( |
| 814 RotateScreenTo(kWebScreenOrientationLandscapePrimary, 90)); | 818 RotateScreenTo(kWebScreenOrientationLandscapePrimary, 90)); |
| 815 InitVideo(640, 480); | 819 InitVideo(640, 480); |
| 816 SetIsAutoRotateEnabledByUser(true); | 820 SetIsAutoRotateEnabledByUser(true); |
| 817 | 821 |
| 818 // Initially fullscreen, locked orientation. | 822 // Initially fullscreen, locked orientation. |
| 819 SimulateEnterFullscreen(); | 823 SimulateEnterFullscreen(); |
| 820 ASSERT_TRUE(Video().IsFullscreen()); | 824 ASSERT_TRUE(Video().IsFullscreen()); |
| 821 CheckStateMaybeLockedFullscreen(); | 825 CheckStateMaybeLockedFullscreen(); |
| 822 EXPECT_EQ(kWebScreenOrientationLockLandscape, DelegateOrientationLock()); | 826 EXPECT_EQ(kWebScreenOrientationLockLandscape, DelegateOrientationLock()); |
| 823 | 827 |
| 824 // Simulate user rotating their device to landscape (matching the screen | 828 // Simulate user rotating their device to landscape (matching the screen |
| 825 // orientation lock). | 829 // orientation lock). |
| 826 RotateDeviceTo(90 /* landscape primary */); | 830 RotateDeviceTo(90 /* landscape primary */); |
| 831 testing::RunDelayedTasks(kUnlockDelayMs); |
| 827 | 832 |
| 828 // MediaControlsOrientationLockDelegate should unlock orientation. | 833 // MediaControlsOrientationLockDelegate should unlock orientation. |
| 829 CheckStatePendingFullscreen(); | 834 CheckStatePendingFullscreen(); |
| 830 EXPECT_FALSE(DelegateWillUnlockFullscreen()); | 835 EXPECT_FALSE(DelegateWillUnlockFullscreen()); |
| 831 EXPECT_TRUE(Video().IsFullscreen()); | 836 EXPECT_TRUE(Video().IsFullscreen()); |
| 832 } | 837 } |
| 833 | 838 |
| 834 TEST_F(MediaControlsOrientationLockAndRotateToFullscreenDelegateTest, | 839 TEST_F(MediaControlsOrientationLockAndRotateToFullscreenDelegateTest, |
| 835 PortraitLockedLandscapeFullscreenBackToPortraitInline) { | 840 PortraitLockedLandscapeFullscreenBackToPortraitInline) { |
| 836 // Naturally portrait device, initially portrait device orientation but locked | 841 // Naturally portrait device, initially portrait device orientation but locked |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 886 | 891 |
| 887 // Initially inline, unlocked orientation. | 892 // Initially inline, unlocked orientation. |
| 888 ASSERT_FALSE(Video().IsFullscreen()); | 893 ASSERT_FALSE(Video().IsFullscreen()); |
| 889 CheckStatePendingFullscreen(); | 894 CheckStatePendingFullscreen(); |
| 890 ASSERT_FALSE(DelegateWillUnlockFullscreen()); | 895 ASSERT_FALSE(DelegateWillUnlockFullscreen()); |
| 891 | 896 |
| 892 // Simulate user rotating their device to portrait triggering a screen | 897 // Simulate user rotating their device to portrait triggering a screen |
| 893 // orientation change. | 898 // orientation change. |
| 894 ASSERT_NO_FATAL_FAILURE( | 899 ASSERT_NO_FATAL_FAILURE( |
| 895 RotateScreenTo(kWebScreenOrientationPortraitPrimary, 0)); | 900 RotateScreenTo(kWebScreenOrientationPortraitPrimary, 0)); |
| 901 testing::RunDelayedTasks(kUnlockDelayMs); |
| 896 | 902 |
| 897 // Video should remain inline, unlocked. | 903 // Video should remain inline, unlocked. |
| 898 CheckStatePendingFullscreen(); | 904 CheckStatePendingFullscreen(); |
| 899 EXPECT_FALSE(DelegateWillUnlockFullscreen()); | 905 EXPECT_FALSE(DelegateWillUnlockFullscreen()); |
| 900 EXPECT_FALSE(Video().IsFullscreen()); | 906 EXPECT_FALSE(Video().IsFullscreen()); |
| 901 } | 907 } |
| 902 | 908 |
| 903 TEST_F(MediaControlsOrientationLockAndRotateToFullscreenDelegateTest, | 909 TEST_F(MediaControlsOrientationLockAndRotateToFullscreenDelegateTest, |
| 904 LandscapeInlineButtonToLandscapeFullscreen) { | 910 LandscapeInlineButtonToLandscapeFullscreen) { |
| 905 // Naturally portrait device, initially landscape, with landscape video. | 911 // Naturally portrait device, initially landscape, with landscape video. |
| (...skipping 13 matching lines...) Expand all Loading... |
| 919 EXPECT_TRUE(Video().IsFullscreen()); | 925 EXPECT_TRUE(Video().IsFullscreen()); |
| 920 | 926 |
| 921 // MediaControlsOrientationLockDelegate should lock to landscape (even though | 927 // MediaControlsOrientationLockDelegate should lock to landscape (even though |
| 922 // the screen is already landscape). | 928 // the screen is already landscape). |
| 923 CheckStateMaybeLockedFullscreen(); | 929 CheckStateMaybeLockedFullscreen(); |
| 924 EXPECT_EQ(kWebScreenOrientationLockLandscape, DelegateOrientationLock()); | 930 EXPECT_EQ(kWebScreenOrientationLockLandscape, DelegateOrientationLock()); |
| 925 | 931 |
| 926 // Device orientation events received by MediaControlsOrientationLockDelegate | 932 // Device orientation events received by MediaControlsOrientationLockDelegate |
| 927 // will confirm that the device is already landscape. | 933 // will confirm that the device is already landscape. |
| 928 RotateDeviceTo(90 /* landscape primary */); | 934 RotateDeviceTo(90 /* landscape primary */); |
| 935 testing::RunDelayedTasks(kUnlockDelayMs); |
| 929 | 936 |
| 930 // MediaControlsOrientationLockDelegate should unlock orientation. | 937 // MediaControlsOrientationLockDelegate should unlock orientation. |
| 931 CheckStatePendingFullscreen(); | 938 CheckStatePendingFullscreen(); |
| 932 EXPECT_FALSE(DelegateWillUnlockFullscreen()); | 939 EXPECT_FALSE(DelegateWillUnlockFullscreen()); |
| 933 } | 940 } |
| 934 | 941 |
| 935 TEST_F(MediaControlsOrientationLockAndRotateToFullscreenDelegateTest, | 942 TEST_F(MediaControlsOrientationLockAndRotateToFullscreenDelegateTest, |
| 936 LandscapeFullscreenRotateToPortraitInline) { | 943 LandscapeFullscreenRotateToPortraitInline) { |
| 937 // Naturally portrait device, initially landscape, with landscape video. | 944 // Naturally portrait device, initially landscape, with landscape video. |
| 938 natural_orientation_is_portrait_ = true; | 945 natural_orientation_is_portrait_ = true; |
| 939 ASSERT_NO_FATAL_FAILURE( | 946 ASSERT_NO_FATAL_FAILURE( |
| 940 RotateScreenTo(kWebScreenOrientationLandscapePrimary, 90)); | 947 RotateScreenTo(kWebScreenOrientationLandscapePrimary, 90)); |
| 941 InitVideo(640, 480); | 948 InitVideo(640, 480); |
| 942 SetIsAutoRotateEnabledByUser(true); | 949 SetIsAutoRotateEnabledByUser(true); |
| 943 | 950 |
| 944 // Initially fullscreen, unlocked orientation. | 951 // Initially fullscreen, unlocked orientation. |
| 945 SimulateEnterFullscreen(); | 952 SimulateEnterFullscreen(); |
| 946 RotateDeviceTo(90 /* landscape primary */); | 953 RotateDeviceTo(90 /* landscape primary */); |
| 954 testing::RunDelayedTasks(kUnlockDelayMs); |
| 947 ASSERT_TRUE(Video().IsFullscreen()); | 955 ASSERT_TRUE(Video().IsFullscreen()); |
| 948 CheckStatePendingFullscreen(); | 956 CheckStatePendingFullscreen(); |
| 949 EXPECT_FALSE(DelegateWillUnlockFullscreen()); | 957 EXPECT_FALSE(DelegateWillUnlockFullscreen()); |
| 950 | 958 |
| 951 // Simulate user rotating their device to portrait triggering a screen | 959 // Simulate user rotating their device to portrait triggering a screen |
| 952 // orientation change. | 960 // orientation change. |
| 953 ASSERT_NO_FATAL_FAILURE( | 961 ASSERT_NO_FATAL_FAILURE( |
| 954 RotateScreenTo(kWebScreenOrientationPortraitPrimary, 0)); | 962 RotateScreenTo(kWebScreenOrientationPortraitPrimary, 0)); |
| 963 testing::RunDelayedTasks(kUnlockDelayMs); |
| 955 | 964 |
| 956 // MediaControlsRotateToFullscreenDelegate should exit fullscreen. | 965 // MediaControlsRotateToFullscreenDelegate should exit fullscreen. |
| 957 EXPECT_FALSE(Video().IsFullscreen()); | 966 EXPECT_FALSE(Video().IsFullscreen()); |
| 958 | 967 |
| 959 // MediaControlsOrientationLockDelegate should remain unlocked. | 968 // MediaControlsOrientationLockDelegate should remain unlocked. |
| 960 CheckStatePendingFullscreen(); | 969 CheckStatePendingFullscreen(); |
| 961 EXPECT_FALSE(DelegateWillUnlockFullscreen()); | 970 EXPECT_FALSE(DelegateWillUnlockFullscreen()); |
| 962 } | 971 } |
| 963 | 972 |
| 964 TEST_F(MediaControlsOrientationLockAndRotateToFullscreenDelegateTest, | 973 TEST_F(MediaControlsOrientationLockAndRotateToFullscreenDelegateTest, |
| 965 LandscapeFullscreenBackToLandscapeInline) { | 974 LandscapeFullscreenBackToLandscapeInline) { |
| 966 // Naturally portrait device, initially landscape, with landscape video. | 975 // Naturally portrait device, initially landscape, with landscape video. |
| 967 natural_orientation_is_portrait_ = true; | 976 natural_orientation_is_portrait_ = true; |
| 968 ASSERT_NO_FATAL_FAILURE( | 977 ASSERT_NO_FATAL_FAILURE( |
| 969 RotateScreenTo(kWebScreenOrientationLandscapePrimary, 90)); | 978 RotateScreenTo(kWebScreenOrientationLandscapePrimary, 90)); |
| 970 InitVideo(640, 480); | 979 InitVideo(640, 480); |
| 971 SetIsAutoRotateEnabledByUser(true); | 980 SetIsAutoRotateEnabledByUser(true); |
| 972 | 981 |
| 973 // Initially fullscreen, unlocked orientation. | 982 // Initially fullscreen, unlocked orientation. |
| 974 SimulateEnterFullscreen(); | 983 SimulateEnterFullscreen(); |
| 975 RotateDeviceTo(90 /* landscape primary */); | 984 RotateDeviceTo(90 /* landscape primary */); |
| 985 testing::RunDelayedTasks(kUnlockDelayMs); |
| 976 ASSERT_TRUE(Video().IsFullscreen()); | 986 ASSERT_TRUE(Video().IsFullscreen()); |
| 977 CheckStatePendingFullscreen(); | 987 CheckStatePendingFullscreen(); |
| 978 EXPECT_FALSE(DelegateWillUnlockFullscreen()); | 988 EXPECT_FALSE(DelegateWillUnlockFullscreen()); |
| 979 | 989 |
| 980 // Simulate user clicking on media controls exit fullscreen button. | 990 // Simulate user clicking on media controls exit fullscreen button. |
| 981 SimulateExitFullscreen(); | 991 SimulateExitFullscreen(); |
| 982 EXPECT_FALSE(Video().IsFullscreen()); | 992 EXPECT_FALSE(Video().IsFullscreen()); |
| 983 | 993 |
| 984 // MediaControlsOrientationLockDelegate should remain unlocked. | 994 // MediaControlsOrientationLockDelegate should remain unlocked. |
| 985 CheckStatePendingFullscreen(); | 995 CheckStatePendingFullscreen(); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 1010 CheckStateMaybeLockedFullscreen(); | 1020 CheckStateMaybeLockedFullscreen(); |
| 1011 EXPECT_EQ(kWebScreenOrientationLockLandscape, DelegateOrientationLock()); | 1021 EXPECT_EQ(kWebScreenOrientationLockLandscape, DelegateOrientationLock()); |
| 1012 | 1022 |
| 1013 // This will trigger a screen orientation change to landscape, since the app's | 1023 // This will trigger a screen orientation change to landscape, since the app's |
| 1014 // lock overrides the user's orientation lock (at least on Android). | 1024 // lock overrides the user's orientation lock (at least on Android). |
| 1015 ASSERT_NO_FATAL_FAILURE( | 1025 ASSERT_NO_FATAL_FAILURE( |
| 1016 RotateScreenTo(kWebScreenOrientationLandscapePrimary, 90)); | 1026 RotateScreenTo(kWebScreenOrientationLandscapePrimary, 90)); |
| 1017 | 1027 |
| 1018 // Even though the device is still held in portrait. | 1028 // Even though the device is still held in portrait. |
| 1019 RotateDeviceTo(0 /* portrait primary */); | 1029 RotateDeviceTo(0 /* portrait primary */); |
| 1030 testing::RunDelayedTasks(kUnlockDelayMs); |
| 1020 | 1031 |
| 1021 // MediaControlsOrientationLockDelegate should remain locked to landscape. | 1032 // MediaControlsOrientationLockDelegate should remain locked to landscape. |
| 1022 CheckStateMaybeLockedFullscreen(); | 1033 CheckStateMaybeLockedFullscreen(); |
| 1023 EXPECT_EQ(kWebScreenOrientationLockLandscape, DelegateOrientationLock()); | 1034 EXPECT_EQ(kWebScreenOrientationLockLandscape, DelegateOrientationLock()); |
| 1024 } | 1035 } |
| 1025 | 1036 |
| 1026 TEST_F( | 1037 TEST_F( |
| 1027 MediaControlsOrientationLockAndRotateToFullscreenDelegateTest, | 1038 MediaControlsOrientationLockAndRotateToFullscreenDelegateTest, |
| 1028 AutoRotateDisabledPortraitLockedLandscapeFullscreenRotateToLandscapeLockedLa
ndscapeFullscreen) { | 1039 AutoRotateDisabledPortraitLockedLandscapeFullscreenRotateToLandscapeLockedLa
ndscapeFullscreen) { |
| 1029 // Naturally portrait device, initially portrait device orientation but locked | 1040 // Naturally portrait device, initially portrait device orientation but locked |
| 1030 // to landscape screen orientation, with landscape video. | 1041 // to landscape screen orientation, with landscape video. |
| 1031 natural_orientation_is_portrait_ = true; | 1042 natural_orientation_is_portrait_ = true; |
| 1032 ASSERT_NO_FATAL_FAILURE( | 1043 ASSERT_NO_FATAL_FAILURE( |
| 1033 RotateScreenTo(kWebScreenOrientationLandscapePrimary, 90)); | 1044 RotateScreenTo(kWebScreenOrientationLandscapePrimary, 90)); |
| 1034 InitVideo(640, 480); | 1045 InitVideo(640, 480); |
| 1035 // But this time the user has disabled auto rotate, e.g. locked to portrait | 1046 // But this time the user has disabled auto rotate, e.g. locked to portrait |
| 1036 // (even though the app's landscape screen orientation lock overrides it). | 1047 // (even though the app's landscape screen orientation lock overrides it). |
| 1037 SetIsAutoRotateEnabledByUser(false); | 1048 SetIsAutoRotateEnabledByUser(false); |
| 1038 | 1049 |
| 1039 // Initially fullscreen, locked orientation. | 1050 // Initially fullscreen, locked orientation. |
| 1040 SimulateEnterFullscreen(); | 1051 SimulateEnterFullscreen(); |
| 1041 ASSERT_TRUE(Video().IsFullscreen()); | 1052 ASSERT_TRUE(Video().IsFullscreen()); |
| 1042 CheckStateMaybeLockedFullscreen(); | 1053 CheckStateMaybeLockedFullscreen(); |
| 1043 EXPECT_EQ(kWebScreenOrientationLockLandscape, DelegateOrientationLock()); | 1054 EXPECT_EQ(kWebScreenOrientationLockLandscape, DelegateOrientationLock()); |
| 1044 | 1055 |
| 1045 // Simulate user rotating their device to landscape (matching the screen | 1056 // Simulate user rotating their device to landscape (matching the screen |
| 1046 // orientation lock). | 1057 // orientation lock). |
| 1047 RotateDeviceTo(90 /* landscape primary */); | 1058 RotateDeviceTo(90 /* landscape primary */); |
| 1059 testing::RunDelayedTasks(kUnlockDelayMs); |
| 1048 | 1060 |
| 1049 // MediaControlsOrientationLockDelegate should remain locked to landscape even | 1061 // MediaControlsOrientationLockDelegate should remain locked to landscape even |
| 1050 // though the screen orientation is now landscape, since the user has disabled | 1062 // though the screen orientation is now landscape, since the user has disabled |
| 1051 // auto rotate, so unlocking now would cause the device to return to the | 1063 // auto rotate, so unlocking now would cause the device to return to the |
| 1052 // portrait orientation. | 1064 // portrait orientation. |
| 1053 CheckStateMaybeLockedFullscreen(); | 1065 CheckStateMaybeLockedFullscreen(); |
| 1054 EXPECT_EQ(kWebScreenOrientationLockLandscape, DelegateOrientationLock()); | 1066 EXPECT_EQ(kWebScreenOrientationLockLandscape, DelegateOrientationLock()); |
| 1055 EXPECT_TRUE(Video().IsFullscreen()); | 1067 EXPECT_TRUE(Video().IsFullscreen()); |
| 1056 } | 1068 } |
| 1057 | 1069 |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1118 // Initially fullscreen, locked orientation. | 1130 // Initially fullscreen, locked orientation. |
| 1119 SimulateEnterFullscreen(); | 1131 SimulateEnterFullscreen(); |
| 1120 ASSERT_TRUE(Video().IsFullscreen()); | 1132 ASSERT_TRUE(Video().IsFullscreen()); |
| 1121 CheckStateMaybeLockedFullscreen(); | 1133 CheckStateMaybeLockedFullscreen(); |
| 1122 EXPECT_EQ(kWebScreenOrientationLockLandscape, DelegateOrientationLock()); | 1134 EXPECT_EQ(kWebScreenOrientationLockLandscape, DelegateOrientationLock()); |
| 1123 | 1135 |
| 1124 // Simulate user rotating their device to portrait (matching the user's | 1136 // Simulate user rotating their device to portrait (matching the user's |
| 1125 // rotation lock, but perpendicular to MediaControlsOrientationLockDelegate's | 1137 // rotation lock, but perpendicular to MediaControlsOrientationLockDelegate's |
| 1126 // screen orientation lock which overrides it). | 1138 // screen orientation lock which overrides it). |
| 1127 RotateDeviceTo(0 /* portrait primary */); | 1139 RotateDeviceTo(0 /* portrait primary */); |
| 1140 testing::RunDelayedTasks(kUnlockDelayMs); |
| 1128 | 1141 |
| 1129 // Video should remain locked and fullscreen. This may disappoint users who | 1142 // Video should remain locked and fullscreen. This may disappoint users who |
| 1130 // expect MediaControlsRotateToFullscreenDelegate to let them always leave | 1143 // expect MediaControlsRotateToFullscreenDelegate to let them always leave |
| 1131 // fullscreen by rotating perpendicular to the video's orientation (i.e. | 1144 // fullscreen by rotating perpendicular to the video's orientation (i.e. |
| 1132 // rotating to portrait for a landscape video), however in this specific case, | 1145 // rotating to portrait for a landscape video), however in this specific case, |
| 1133 // since the user disabled auto rotate at the OS level, it's likely that they | 1146 // since the user disabled auto rotate at the OS level, it's likely that they |
| 1134 // wish to be able to use their phone whilst their head is lying sideways on a | 1147 // wish to be able to use their phone whilst their head is lying sideways on a |
| 1135 // pillow (or similar), in which case it's essential to keep the fullscreen | 1148 // pillow (or similar), in which case it's essential to keep the fullscreen |
| 1136 // orientation lock. | 1149 // orientation lock. |
| 1137 CheckStateMaybeLockedFullscreen(); | 1150 CheckStateMaybeLockedFullscreen(); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1210 // MediaControlsRotateToFullscreenDelegate should enter fullscreen, so | 1223 // MediaControlsRotateToFullscreenDelegate should enter fullscreen, so |
| 1211 // MediaControlsOrientationLockDelegate should lock orientation to portrait | 1224 // MediaControlsOrientationLockDelegate should lock orientation to portrait |
| 1212 // (even though the screen is already portrait). | 1225 // (even though the screen is already portrait). |
| 1213 EXPECT_TRUE(Video().IsFullscreen()); | 1226 EXPECT_TRUE(Video().IsFullscreen()); |
| 1214 CheckStateMaybeLockedFullscreen(); | 1227 CheckStateMaybeLockedFullscreen(); |
| 1215 EXPECT_EQ(kWebScreenOrientationLockPortrait, DelegateOrientationLock()); | 1228 EXPECT_EQ(kWebScreenOrientationLockPortrait, DelegateOrientationLock()); |
| 1216 | 1229 |
| 1217 // Device orientation events received by MediaControlsOrientationLockDelegate | 1230 // Device orientation events received by MediaControlsOrientationLockDelegate |
| 1218 // will confirm that the device is already portrait. | 1231 // will confirm that the device is already portrait. |
| 1219 RotateDeviceTo(0 /* portrait primary */); | 1232 RotateDeviceTo(0 /* portrait primary */); |
| 1233 testing::RunDelayedTasks(kUnlockDelayMs); |
| 1220 | 1234 |
| 1221 // MediaControlsOrientationLockDelegate should unlock orientation. | 1235 // MediaControlsOrientationLockDelegate should unlock orientation. |
| 1222 CheckStatePendingFullscreen(); | 1236 CheckStatePendingFullscreen(); |
| 1223 EXPECT_FALSE(DelegateWillUnlockFullscreen()); | 1237 EXPECT_FALSE(DelegateWillUnlockFullscreen()); |
| 1224 EXPECT_TRUE(Video().IsFullscreen()); | 1238 EXPECT_TRUE(Video().IsFullscreen()); |
| 1225 | 1239 |
| 1226 // Simulate user rotating their device to landscape triggering a screen | 1240 // Simulate user rotating their device to landscape triggering a screen |
| 1227 // orientation change. | 1241 // orientation change. |
| 1228 ASSERT_NO_FATAL_FAILURE( | 1242 ASSERT_NO_FATAL_FAILURE( |
| 1229 RotateScreenTo(kWebScreenOrientationLandscapePrimary, 90)); | 1243 RotateScreenTo(kWebScreenOrientationLandscapePrimary, 90)); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 1260 // MediaControlsRotateToFullscreenDelegate should enter fullscreen, so | 1274 // MediaControlsRotateToFullscreenDelegate should enter fullscreen, so |
| 1261 // MediaControlsOrientationLockDelegate should lock orientation to landscape | 1275 // MediaControlsOrientationLockDelegate should lock orientation to landscape |
| 1262 // (even though the screen is already landscape). | 1276 // (even though the screen is already landscape). |
| 1263 EXPECT_TRUE(Video().IsFullscreen()); | 1277 EXPECT_TRUE(Video().IsFullscreen()); |
| 1264 CheckStateMaybeLockedFullscreen(); | 1278 CheckStateMaybeLockedFullscreen(); |
| 1265 EXPECT_EQ(kWebScreenOrientationLockLandscape, DelegateOrientationLock()); | 1279 EXPECT_EQ(kWebScreenOrientationLockLandscape, DelegateOrientationLock()); |
| 1266 | 1280 |
| 1267 // Device orientation events received by MediaControlsOrientationLockDelegate | 1281 // Device orientation events received by MediaControlsOrientationLockDelegate |
| 1268 // will confirm that the device is already landscape. | 1282 // will confirm that the device is already landscape. |
| 1269 RotateDeviceTo(0 /* landscape primary */); | 1283 RotateDeviceTo(0 /* landscape primary */); |
| 1284 testing::RunDelayedTasks(kUnlockDelayMs); |
| 1270 | 1285 |
| 1271 // MediaControlsOrientationLockDelegate should unlock orientation. | 1286 // MediaControlsOrientationLockDelegate should unlock orientation. |
| 1272 CheckStatePendingFullscreen(); | 1287 CheckStatePendingFullscreen(); |
| 1273 EXPECT_FALSE(DelegateWillUnlockFullscreen()); | 1288 EXPECT_FALSE(DelegateWillUnlockFullscreen()); |
| 1274 EXPECT_TRUE(Video().IsFullscreen()); | 1289 EXPECT_TRUE(Video().IsFullscreen()); |
| 1275 | 1290 |
| 1276 // Simulate user rotating their device to portrait triggering a screen | 1291 // Simulate user rotating their device to portrait triggering a screen |
| 1277 // orientation change. | 1292 // orientation change. |
| 1278 ASSERT_NO_FATAL_FAILURE( | 1293 ASSERT_NO_FATAL_FAILURE( |
| 1279 RotateScreenTo(kWebScreenOrientationPortraitPrimary, 270)); | 1294 RotateScreenTo(kWebScreenOrientationPortraitPrimary, 270)); |
| 1280 | 1295 |
| 1281 // MediaControlsRotateToFullscreenDelegate should exit fullscreen. | 1296 // MediaControlsRotateToFullscreenDelegate should exit fullscreen. |
| 1282 EXPECT_FALSE(Video().IsFullscreen()); | 1297 EXPECT_FALSE(Video().IsFullscreen()); |
| 1283 | 1298 |
| 1284 // MediaControlsOrientationLockDelegate should remain unlocked. | 1299 // MediaControlsOrientationLockDelegate should remain unlocked. |
| 1285 CheckStatePendingFullscreen(); | 1300 CheckStatePendingFullscreen(); |
| 1286 EXPECT_FALSE(DelegateWillUnlockFullscreen()); | 1301 EXPECT_FALSE(DelegateWillUnlockFullscreen()); |
| 1287 } | 1302 } |
| 1288 | 1303 |
| 1304 TEST_F(MediaControlsOrientationLockAndRotateToFullscreenDelegateTest, |
| 1305 ScreenOrientationRaceCondition) { |
| 1306 // Naturally portrait device, initially portrait, with landscape video. |
| 1307 natural_orientation_is_portrait_ = true; |
| 1308 ASSERT_NO_FATAL_FAILURE( |
| 1309 RotateScreenTo(kWebScreenOrientationPortraitPrimary, 0)); |
| 1310 InitVideo(640, 480); |
| 1311 SetIsAutoRotateEnabledByUser(true); |
| 1312 |
| 1313 // Initially inline, unlocked orientation. |
| 1314 ASSERT_FALSE(Video().IsFullscreen()); |
| 1315 CheckStatePendingFullscreen(); |
| 1316 ASSERT_FALSE(DelegateWillUnlockFullscreen()); |
| 1317 |
| 1318 // Simulate user clicking on media controls fullscreen button. |
| 1319 SimulateEnterFullscreen(); |
| 1320 EXPECT_TRUE(Video().IsFullscreen()); |
| 1321 |
| 1322 // MediaControlsOrientationLockDelegate should lock to landscape. |
| 1323 CheckStateMaybeLockedFullscreen(); |
| 1324 EXPECT_EQ(kWebScreenOrientationLockLandscape, DelegateOrientationLock()); |
| 1325 |
| 1326 // This will trigger a screen orientation change to landscape. |
| 1327 ASSERT_NO_FATAL_FAILURE( |
| 1328 RotateScreenTo(kWebScreenOrientationLandscapePrimary, 90)); |
| 1329 |
| 1330 // Even though the device is still held in portrait. |
| 1331 RotateDeviceTo(0 /* portrait primary */); |
| 1332 |
| 1333 // MediaControlsOrientationLockDelegate should remain locked to landscape |
| 1334 // indefinitely. |
| 1335 testing::RunDelayedTasks(kUnlockDelayMs); |
| 1336 CheckStateMaybeLockedFullscreen(); |
| 1337 EXPECT_EQ(kWebScreenOrientationLockLandscape, DelegateOrientationLock()); |
| 1338 |
| 1339 // Now suppose the user actually rotates from portrait-primary to landscape- |
| 1340 // secondary, despite the screen currently being landscape-primary. |
| 1341 RotateDeviceTo(270 /* landscape secondary */); |
| 1342 |
| 1343 // There can be a significant delay, between the device orientation changing |
| 1344 // and the OS updating the screen orientation to match the new device |
| 1345 // orientation. Manual testing showed that it could take longer than 200ms, |
| 1346 // but less than 250ms, on common Android devices. Partly this is because OSes |
| 1347 // often low-pass filter the device orientation to ignore high frequency |
| 1348 // noise. |
| 1349 // |
| 1350 // During this period, MediaControlsOrientationLockDelegate should |
| 1351 // remain locked to landscape. This prevents a race condition where the |
| 1352 // delegate unlocks the screen orientation, so Android changes the screen |
| 1353 // orientation back to portrait because it hasn't yet processed the device |
| 1354 // orientation change to landscape. |
| 1355 constexpr int kMinUnlockDelayMs = 249; |
| 1356 static_assert(kUnlockDelayMs > kMinUnlockDelayMs, |
| 1357 "kUnlockDelayMs should significantly exceed kMinUnlockDelayMs"); |
| 1358 testing::RunDelayedTasks(kMinUnlockDelayMs); |
| 1359 CheckStateMaybeLockedFullscreen(); |
| 1360 EXPECT_EQ(kWebScreenOrientationLockLandscape, DelegateOrientationLock()); |
| 1361 |
| 1362 // Simulate the OS processing the device orientation change after a delay of |
| 1363 // `kMinUnlockDelayMs` and hence changing the screen orientation. |
| 1364 ASSERT_NO_FATAL_FAILURE( |
| 1365 RotateScreenTo(kWebScreenOrientationLandscapeSecondary, 270)); |
| 1366 |
| 1367 // MediaControlsOrientationLockDelegate should remain locked to landscape. |
| 1368 CheckStateMaybeLockedFullscreen(); |
| 1369 EXPECT_EQ(kWebScreenOrientationLockLandscape, DelegateOrientationLock()); |
| 1370 |
| 1371 // Wait for the rest of the unlock delay. |
| 1372 testing::RunDelayedTasks(kUnlockDelayMs - kMinUnlockDelayMs); |
| 1373 |
| 1374 // MediaControlsOrientationLockDelegate should now have unlocked. |
| 1375 CheckStatePendingFullscreen(); |
| 1376 EXPECT_FALSE(DelegateWillUnlockFullscreen()); |
| 1377 } |
| 1378 |
| 1289 } // namespace blink | 1379 } // namespace blink |
| OLD | NEW |