Index: third_party/WebKit/Source/modules/media_controls/MediaControlsRotateToFullscreenDelegateTest.cpp |
diff --git a/third_party/WebKit/Source/modules/media_controls/MediaControlsRotateToFullscreenDelegateTest.cpp b/third_party/WebKit/Source/modules/media_controls/MediaControlsRotateToFullscreenDelegateTest.cpp |
index 3e831ea97dae1ff90b2ef0580a3474f1a1abbeae..37d492f5a089d44fa53e3409f79d47203d52d5d3 100644 |
--- a/third_party/WebKit/Source/modules/media_controls/MediaControlsRotateToFullscreenDelegateTest.cpp |
+++ b/third_party/WebKit/Source/modules/media_controls/MediaControlsRotateToFullscreenDelegateTest.cpp |
@@ -17,15 +17,18 @@ |
#include "core/loader/EmptyClients.h" |
#include "core/testing/DummyPageHolder.h" |
#include "modules/media_controls/MediaControlsImpl.h" |
+#include "modules/screen_orientation/ScreenOrientationControllerImpl.h" |
#include "platform/UserGestureIndicator.h" |
#include "platform/testing/EmptyWebMediaPlayer.h" |
#include "platform/testing/UnitTestHelpers.h" |
#include "platform/wtf/text/AtomicString.h" |
#include "public/platform/WebSize.h" |
+#include "public/platform/modules/screen_orientation/WebScreenOrientationClient.h" |
#include "public/platform/modules/screen_orientation/WebScreenOrientationType.h" |
#include "testing/gmock/include/gmock/gmock.h" |
#include "testing/gtest/include/gtest/gtest.h" |
+using ::testing::AtLeast; |
using ::testing::Return; |
namespace blink { |
@@ -34,9 +37,17 @@ using namespace HTMLNames; |
namespace { |
+class FakeWebScreenOrientationClient : public WebScreenOrientationClient { |
+ public: |
+ // WebScreenOrientationClient overrides: |
+ void LockOrientation(WebScreenOrientationLockType, |
+ std::unique_ptr<WebLockOrientationCallback>) override {} |
+ void UnlockOrientation() override {} |
+}; |
+ |
class MockVideoWebMediaPlayer : public EmptyWebMediaPlayer { |
public: |
- // ChromeClient overrides: |
+ // EmptyWebMediaPlayer overrides: |
bool HasVideo() const override { return true; } |
MOCK_CONST_METHOD0(NaturalSize, WebSize()); |
@@ -45,6 +56,11 @@ class MockVideoWebMediaPlayer : public EmptyWebMediaPlayer { |
class MockChromeClient : public EmptyChromeClient { |
public: |
// ChromeClient overrides: |
+ void InstallSupplements(LocalFrame& frame) override { |
+ EmptyChromeClient::InstallSupplements(frame); |
+ ScreenOrientationControllerImpl::ProvideTo(frame, |
+ &web_screen_orientation_client_); |
+ } |
void EnterFullscreen(LocalFrame& frame) override { |
Fullscreen::From(*frame.GetDocument()).DidEnterFullscreen(); |
} |
@@ -53,6 +69,9 @@ class MockChromeClient : public EmptyChromeClient { |
} |
MOCK_CONST_METHOD0(GetScreenInfo, WebScreenInfo()); |
+ |
+ private: |
+ FakeWebScreenOrientationClient web_screen_orientation_client_; |
}; |
class StubLocalFrameClient : public EmptyLocalFrameClient { |
@@ -75,8 +94,11 @@ class MediaControlsRotateToFullscreenDelegateTest : public ::testing::Test { |
MediaControlsRotateToFullscreenDelegate::SimpleOrientation; |
void SetUp() override { |
+ previous_video_fullscreen_orientation_lock_value_ = |
+ RuntimeEnabledFeatures::videoFullscreenOrientationLockEnabled(); |
previous_video_rotate_to_fullscreen_value_ = |
RuntimeEnabledFeatures::videoRotateToFullscreenEnabled(); |
+ RuntimeEnabledFeatures::setVideoFullscreenOrientationLockEnabled(true); |
RuntimeEnabledFeatures::setVideoRotateToFullscreenEnabled(true); |
chrome_client_ = new MockChromeClient(); |
@@ -95,6 +117,8 @@ class MediaControlsRotateToFullscreenDelegateTest : public ::testing::Test { |
} |
void TearDown() override { |
+ RuntimeEnabledFeatures::setVideoFullscreenOrientationLockEnabled( |
+ previous_video_fullscreen_orientation_lock_value_); |
RuntimeEnabledFeatures::setVideoRotateToFullscreenEnabled( |
previous_video_rotate_to_fullscreen_value_); |
} |
@@ -104,11 +128,6 @@ class MediaControlsRotateToFullscreenDelegateTest : public ::testing::Test { |
->rotate_to_fullscreen_delegate_; |
} |
- static bool HasOrientationLockDelegate(const MediaControls& media_controls) { |
- return !!static_cast<const MediaControlsImpl*>(&media_controls) |
- ->orientation_lock_delegate_; |
- } |
- |
void SimulateVideoReadyState(HTMLMediaElement::ReadyState state) { |
GetVideo().SetReadyState(state); |
} |
@@ -169,6 +188,7 @@ class MediaControlsRotateToFullscreenDelegateTest : public ::testing::Test { |
} |
private: |
+ bool previous_video_fullscreen_orientation_lock_value_; |
bool previous_video_rotate_to_fullscreen_value_; |
Persistent<MockChromeClient> chrome_client_; |
std::unique_ptr<DummyPageHolder> page_holder_; |
@@ -209,9 +229,10 @@ void MediaControlsRotateToFullscreenDelegateTest::RotateTo( |
WebScreenOrientationType new_screen_orientation) { |
WebScreenInfo screen_info; |
screen_info.orientation_type = new_screen_orientation; |
+ ::testing::Mock::VerifyAndClearExpectations(&GetChromeClient()); |
EXPECT_CALL(GetChromeClient(), GetScreenInfo()) |
- .Times(1) |
- .WillOnce(Return(screen_info)); |
+ .Times(AtLeast(1)) |
+ .WillRepeatedly(Return(screen_info)); |
DispatchEvent(GetWindow(), EventTypeNames::orientationchange); |
testing::RunPendingTasks(); |
} |
@@ -234,18 +255,6 @@ TEST_F(MediaControlsRotateToFullscreenDelegateTest, DelegateRequiresVideo) { |
EXPECT_FALSE(HasDelegate(*audio->GetMediaControls())); |
} |
-TEST_F(MediaControlsRotateToFullscreenDelegateTest, |
- OrientationLockIsMutuallyExclusive) { |
- // Rotate to fullscreen and fullscreen orientation lock are currently |
- // incompatible, so if both are enabled only one should be active. |
- RuntimeEnabledFeatures::setVideoRotateToFullscreenEnabled(true); |
- RuntimeEnabledFeatures::setVideoFullscreenOrientationLockEnabled(true); |
- HTMLVideoElement* video = HTMLVideoElement::Create(GetDocument()); |
- GetDocument().body()->AppendChild(video); |
- EXPECT_TRUE(HasDelegate(*video->GetMediaControls())); |
- EXPECT_FALSE(HasOrientationLockDelegate(*video->GetMediaControls())); |
-} |
- |
TEST_F(MediaControlsRotateToFullscreenDelegateTest, ComputeVideoOrientation) { |
// Set up the WebMediaPlayer instance. |
GetDocument().body()->AppendChild(&GetVideo()); |
@@ -589,6 +598,9 @@ TEST_F(MediaControlsRotateToFullscreenDelegateTest, |
DocumentUserGestureToken::Create(&GetDocument())); |
GetMediaControls().EnterFullscreen(); |
} |
+ // n.b. omit to call Fullscreen::From(GetDocument()).DidEnterFullscreen() so |
+ // that MediaControlsOrientationLockDelegate doesn't trigger, which avoids |
+ // having to create deviceorientation events here to unlock it again. |
testing::RunPendingTasks(); |
EXPECT_TRUE(GetVideo().IsFullscreen()); |
@@ -596,7 +608,8 @@ TEST_F(MediaControlsRotateToFullscreenDelegateTest, |
EXPECT_TRUE(GetVideo().paused()); |
EXPECT_FALSE(ObservedVisibility()); |
- // Rotate screen to portrait. |
+ // Rotate screen to portrait. This relies on the screen orientation no longer |
+ // being locked by MediaControlsOrientationLockDelegate. |
RotateTo(kWebScreenOrientationPortraitPrimary); |
// Should exit fullscreen. |
@@ -616,6 +629,9 @@ TEST_F(MediaControlsRotateToFullscreenDelegateTest, |
DocumentUserGestureToken::Create(&GetDocument())); |
GetMediaControls().EnterFullscreen(); |
} |
+ // n.b. omit to call Fullscreen::From(GetDocument()).DidEnterFullscreen() so |
+ // that MediaControlsOrientationLockDelegate doesn't trigger, which avoids |
+ // having to create deviceorientation events here to unlock it again. |
testing::RunPendingTasks(); |
EXPECT_TRUE(GetVideo().IsFullscreen()); |
@@ -623,7 +639,8 @@ TEST_F(MediaControlsRotateToFullscreenDelegateTest, |
EXPECT_TRUE(GetVideo().paused()); |
EXPECT_FALSE(ObservedVisibility()); |
- // Rotate screen to landscape. |
+ // Rotate screen to portrait. This relies on the screen orientation no longer |
+ // being locked by MediaControlsOrientationLockDelegate. |
RotateTo(kWebScreenOrientationLandscapePrimary); |
// Should exit fullscreen. |