Chromium Code Reviews| Index: third_party/WebKit/Source/modules/media_controls/MediaControlsOrientationLockDelegateTest.cpp |
| diff --git a/third_party/WebKit/Source/modules/media_controls/MediaControlsOrientationLockDelegateTest.cpp b/third_party/WebKit/Source/modules/media_controls/MediaControlsOrientationLockDelegateTest.cpp |
| index 1a6760c8ecbba9c7ae4f854cb4ed5bd251518040..8012f2764f62c4cce644ac167c3c4b5474f09fb5 100644 |
| --- a/third_party/WebKit/Source/modules/media_controls/MediaControlsOrientationLockDelegateTest.cpp |
| +++ b/third_party/WebKit/Source/modules/media_controls/MediaControlsOrientationLockDelegateTest.cpp |
| @@ -107,6 +107,8 @@ class MediaControlsOrientationLockDelegateTest : public ::testing::Test { |
| protected: |
| using DeviceOrientation = |
| MediaControlsOrientationLockDelegate::DeviceOrientation; |
| + static constexpr int kUnlockDelayMs = |
| + MediaControlsOrientationLockDelegate::kUnlockDelayMs; |
| void SetUp() override { |
| chrome_client_ = new MockChromeClient(); |
| @@ -769,6 +771,7 @@ TEST_F(MediaControlsOrientationLockAndRotateToFullscreenDelegateTest, |
| // Device orientation events received by MediaControlsOrientationLockDelegate |
| // will confirm that the device is already landscape. |
| RotateDeviceTo(90 /* landscape primary */); |
| + testing::RunDelayedTasks(kUnlockDelayMs); |
| // MediaControlsOrientationLockDelegate should unlock orientation. |
| CheckStatePendingFullscreen(); |
| @@ -803,6 +806,7 @@ TEST_F(MediaControlsOrientationLockAndRotateToFullscreenDelegateTest, |
| // Even though the device is still held in portrait. |
| RotateDeviceTo(0 /* portrait primary */); |
| + testing::RunDelayedTasks(kUnlockDelayMs); |
| // MediaControlsOrientationLockDelegate should remain locked to landscape. |
| CheckStateMaybeLockedFullscreen(); |
| @@ -828,6 +832,7 @@ TEST_F(MediaControlsOrientationLockAndRotateToFullscreenDelegateTest, |
| // Simulate user rotating their device to landscape (matching the screen |
| // orientation lock). |
| RotateDeviceTo(90 /* landscape primary */); |
| + testing::RunDelayedTasks(kUnlockDelayMs); |
| // MediaControlsOrientationLockDelegate should unlock orientation. |
| CheckStatePendingFullscreen(); |
| @@ -898,6 +903,7 @@ TEST_F(MediaControlsOrientationLockAndRotateToFullscreenDelegateTest, |
| // orientation change. |
| ASSERT_NO_FATAL_FAILURE( |
| RotateScreenTo(kWebScreenOrientationPortraitPrimary, 0)); |
| + testing::RunDelayedTasks(kUnlockDelayMs); |
| // Video should remain inline, unlocked. |
| CheckStatePendingFullscreen(); |
| @@ -931,6 +937,7 @@ TEST_F(MediaControlsOrientationLockAndRotateToFullscreenDelegateTest, |
| // Device orientation events received by MediaControlsOrientationLockDelegate |
| // will confirm that the device is already landscape. |
| RotateDeviceTo(90 /* landscape primary */); |
| + testing::RunDelayedTasks(kUnlockDelayMs); |
| // MediaControlsOrientationLockDelegate should unlock orientation. |
| CheckStatePendingFullscreen(); |
| @@ -949,6 +956,7 @@ TEST_F(MediaControlsOrientationLockAndRotateToFullscreenDelegateTest, |
| // Initially fullscreen, unlocked orientation. |
| SimulateEnterFullscreen(); |
| RotateDeviceTo(90 /* landscape primary */); |
| + testing::RunDelayedTasks(kUnlockDelayMs); |
| ASSERT_TRUE(Video().IsFullscreen()); |
| CheckStatePendingFullscreen(); |
| EXPECT_FALSE(DelegateWillUnlockFullscreen()); |
| @@ -957,6 +965,7 @@ TEST_F(MediaControlsOrientationLockAndRotateToFullscreenDelegateTest, |
| // orientation change. |
| ASSERT_NO_FATAL_FAILURE( |
| RotateScreenTo(kWebScreenOrientationPortraitPrimary, 0)); |
| + testing::RunDelayedTasks(kUnlockDelayMs); |
| // MediaControlsRotateToFullscreenDelegate should exit fullscreen. |
| EXPECT_FALSE(Video().IsFullscreen()); |
| @@ -978,6 +987,7 @@ TEST_F(MediaControlsOrientationLockAndRotateToFullscreenDelegateTest, |
| // Initially fullscreen, unlocked orientation. |
| SimulateEnterFullscreen(); |
| RotateDeviceTo(90 /* landscape primary */); |
| + testing::RunDelayedTasks(kUnlockDelayMs); |
| ASSERT_TRUE(Video().IsFullscreen()); |
| CheckStatePendingFullscreen(); |
| EXPECT_FALSE(DelegateWillUnlockFullscreen()); |
| @@ -1023,6 +1033,7 @@ TEST_F( |
| // Even though the device is still held in portrait. |
| RotateDeviceTo(0 /* portrait primary */); |
| + testing::RunDelayedTasks(kUnlockDelayMs); |
| // MediaControlsOrientationLockDelegate should remain locked to landscape. |
| CheckStateMaybeLockedFullscreen(); |
| @@ -1051,6 +1062,7 @@ TEST_F( |
| // Simulate user rotating their device to landscape (matching the screen |
| // orientation lock). |
| RotateDeviceTo(90 /* landscape primary */); |
| + testing::RunDelayedTasks(kUnlockDelayMs); |
| // MediaControlsOrientationLockDelegate should remain locked to landscape even |
| // though the screen orientation is now landscape, since the user has disabled |
| @@ -1132,6 +1144,7 @@ TEST_F( |
| // rotation lock, but perpendicular to MediaControlsOrientationLockDelegate's |
| // screen orientation lock which overrides it). |
| RotateDeviceTo(0 /* portrait primary */); |
| + testing::RunDelayedTasks(kUnlockDelayMs); |
| // Video should remain locked and fullscreen. This may disappoint users who |
| // expect MediaControlsRotateToFullscreenDelegate to let them always leave |
| @@ -1225,6 +1238,7 @@ TEST_F(MediaControlsOrientationLockAndRotateToFullscreenDelegateTest, |
| // Device orientation events received by MediaControlsOrientationLockDelegate |
| // will confirm that the device is already portrait. |
| RotateDeviceTo(0 /* portrait primary */); |
| + testing::RunDelayedTasks(kUnlockDelayMs); |
| // MediaControlsOrientationLockDelegate should unlock orientation. |
| CheckStatePendingFullscreen(); |
| @@ -1275,6 +1289,7 @@ TEST_F(MediaControlsOrientationLockAndRotateToFullscreenDelegateTest, |
| // Device orientation events received by MediaControlsOrientationLockDelegate |
| // will confirm that the device is already landscape. |
| RotateDeviceTo(0 /* landscape primary */); |
| + testing::RunDelayedTasks(kUnlockDelayMs); |
| // MediaControlsOrientationLockDelegate should unlock orientation. |
| CheckStatePendingFullscreen(); |
| @@ -1294,4 +1309,66 @@ TEST_F(MediaControlsOrientationLockAndRotateToFullscreenDelegateTest, |
| EXPECT_FALSE(DelegateWillUnlockFullscreen()); |
| } |
| +TEST_F(MediaControlsOrientationLockAndRotateToFullscreenDelegateTest, |
| + ScreenOrientationRace) { |
| + // Naturally portrait device, initially portrait, with landscape video. |
| + natural_orientation_is_portrait_ = true; |
| + ASSERT_NO_FATAL_FAILURE( |
| + RotateScreenTo(kWebScreenOrientationPortraitPrimary, 0)); |
| + InitVideo(640, 480); |
| + SetIsAutoRotateEnabledByUser(true); |
| + |
| + // Initially inline, unlocked orientation. |
| + ASSERT_FALSE(Video().IsFullscreen()); |
| + CheckStatePendingFullscreen(); |
| + ASSERT_FALSE(DelegateWillUnlockFullscreen()); |
| + |
| + // Simulate user clicking on media controls fullscreen button. |
| + SimulateEnterFullscreen(); |
| + EXPECT_TRUE(Video().IsFullscreen()); |
| + |
| + // MediaControlsOrientationLockDelegate should lock to landscape. |
| + CheckStateMaybeLockedFullscreen(); |
| + EXPECT_EQ(kWebScreenOrientationLockLandscape, DelegateOrientationLock()); |
| + |
| + // This will trigger a screen orientation change to landscape. |
| + ASSERT_NO_FATAL_FAILURE( |
| + RotateScreenTo(kWebScreenOrientationLandscapePrimary, 90)); |
| + |
| + // Even though the device is still held in portrait. |
| + RotateDeviceTo(0 /* portrait primary */); |
| + |
| + // MediaControlsOrientationLockDelegate should remain locked to landscape |
| + // indefinitely. |
| + testing::RunDelayedTasks(kUnlockDelayMs); |
| + CheckStateMaybeLockedFullscreen(); |
| + EXPECT_EQ(kWebScreenOrientationLockLandscape, DelegateOrientationLock()); |
| + |
| + // Now suppose the user actually rotates from portrait-primary to landscape- |
| + // secondary, despite the screen currently being landscape-primary. |
| + RotateDeviceTo(270 /* landscape secondary */); |
| + |
| + // MediaControlsOrientationLockDelegate should remain locked to landscape for |
| + // a few hundred milliseconds... |
| + testing::RunDelayedTasks(249); |
| + CheckStateMaybeLockedFullscreen(); |
| + EXPECT_EQ(kWebScreenOrientationLockLandscape, DelegateOrientationLock()); |
| + |
| + // ...because it might take that long for Android to update the screen |
| + // orientation due to low pass filtering. |
| + ASSERT_NO_FATAL_FAILURE( |
| + RotateScreenTo(kWebScreenOrientationLandscapeSecondary, 270)); |
| + |
| + // MediaControlsOrientationLockDelegate should remain locked to landscape. |
| + CheckStateMaybeLockedFullscreen(); |
| + EXPECT_EQ(kWebScreenOrientationLockLandscape, DelegateOrientationLock()); |
| + |
| + // Wait for the rest of the unlock delay. |
| + 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
|
| + |
| + // MediaControlsOrientationLockDelegate should now have unlocked. |
| + CheckStatePendingFullscreen(); |
| + EXPECT_FALSE(DelegateWillUnlockFullscreen()); |
| +} |
| + |
| } // namespace blink |