| 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/UserGestureIndicator.h" | 9 #include "core/dom/UserGestureIndicator.h" |
| 10 #include "core/frame/FrameView.h" | 10 #include "core/frame/FrameView.h" |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 namespace { | 37 namespace { |
| 38 | 38 |
| 39 // WebLockOrientationCallback implementation that will not react to a success | 39 // WebLockOrientationCallback implementation that will not react to a success |
| 40 // nor a failure. | 40 // nor a failure. |
| 41 class DummyScreenOrientationCallback final : public WebLockOrientationCallback { | 41 class DummyScreenOrientationCallback final : public WebLockOrientationCallback { |
| 42 public: | 42 public: |
| 43 void OnSuccess() override {} | 43 void OnSuccess() override {} |
| 44 void OnError(WebLockOrientationError) override {} | 44 void OnError(WebLockOrientationError) override {} |
| 45 }; | 45 }; |
| 46 | 46 |
| 47 class MockVideoWebMediaPlayer final : public EmptyWebMediaPlayer { | 47 class MockWebMediaPlayerForOrientationLockDelegate final |
| 48 : public EmptyWebMediaPlayer { |
| 48 public: | 49 public: |
| 49 bool HasVideo() const override { return true; } | 50 bool HasVideo() const override { return true; } |
| 50 | 51 |
| 51 MOCK_CONST_METHOD0(NaturalSize, WebSize()); | 52 MOCK_CONST_METHOD0(NaturalSize, WebSize()); |
| 52 }; | 53 }; |
| 53 | 54 |
| 54 class MockWebScreenOrientationClient final : public WebScreenOrientationClient { | 55 class MockWebScreenOrientationClient final : public WebScreenOrientationClient { |
| 55 public: | 56 public: |
| 56 // WebScreenOrientationClient overrides: | 57 // WebScreenOrientationClient overrides: |
| 57 void LockOrientation(WebScreenOrientationLockType type, | 58 void LockOrientation(WebScreenOrientationLockType type, |
| (...skipping 10 matching lines...) Expand all Loading... |
| 68 Fullscreen::From(*document).DidEnterFullscreen(); | 69 Fullscreen::From(*document).DidEnterFullscreen(); |
| 69 document->ServiceScriptedAnimations(WTF::MonotonicallyIncreasingTime()); | 70 document->ServiceScriptedAnimations(WTF::MonotonicallyIncreasingTime()); |
| 70 } | 71 } |
| 71 | 72 |
| 72 void DidExitFullscreen(Document* document) { | 73 void DidExitFullscreen(Document* document) { |
| 73 DCHECK(document); | 74 DCHECK(document); |
| 74 Fullscreen::From(*document).DidExitFullscreen(); | 75 Fullscreen::From(*document).DidExitFullscreen(); |
| 75 document->ServiceScriptedAnimations(WTF::MonotonicallyIncreasingTime()); | 76 document->ServiceScriptedAnimations(WTF::MonotonicallyIncreasingTime()); |
| 76 } | 77 } |
| 77 | 78 |
| 78 class MockChromeClient final : public EmptyChromeClient { | 79 class MockChromeClientForOrientationLockDelegate final |
| 80 : public EmptyChromeClient { |
| 79 public: | 81 public: |
| 80 // ChromeClient overrides: | 82 // ChromeClient overrides: |
| 81 void InstallSupplements(LocalFrame& frame) override { | 83 void InstallSupplements(LocalFrame& frame) override { |
| 82 EmptyChromeClient::InstallSupplements(frame); | 84 EmptyChromeClient::InstallSupplements(frame); |
| 83 ScreenOrientationControllerImpl::ProvideTo(frame, | 85 ScreenOrientationControllerImpl::ProvideTo(frame, |
| 84 &web_screen_orientation_client_); | 86 &web_screen_orientation_client_); |
| 85 } | 87 } |
| 86 // The real ChromeClient::EnterFullscreen/ExitFullscreen implementation is | 88 // The real ChromeClient::EnterFullscreen/ExitFullscreen implementation is |
| 87 // async due to IPC, emulate that by posting tasks: | 89 // async due to IPC, emulate that by posting tasks: |
| 88 void EnterFullscreen(LocalFrame& frame) override { | 90 void EnterFullscreen(LocalFrame& frame) override { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 99 MOCK_CONST_METHOD0(GetScreenInfo, WebScreenInfo()); | 101 MOCK_CONST_METHOD0(GetScreenInfo, WebScreenInfo()); |
| 100 | 102 |
| 101 MockWebScreenOrientationClient& WebScreenOrientationClient() { | 103 MockWebScreenOrientationClient& WebScreenOrientationClient() { |
| 102 return web_screen_orientation_client_; | 104 return web_screen_orientation_client_; |
| 103 } | 105 } |
| 104 | 106 |
| 105 private: | 107 private: |
| 106 MockWebScreenOrientationClient web_screen_orientation_client_; | 108 MockWebScreenOrientationClient web_screen_orientation_client_; |
| 107 }; | 109 }; |
| 108 | 110 |
| 109 class StubLocalFrameClient final : public EmptyLocalFrameClient { | 111 class StubLocalFrameClientForOrientationLockDelegate final |
| 112 : public EmptyLocalFrameClient { |
| 110 public: | 113 public: |
| 111 static StubLocalFrameClient* Create() { return new StubLocalFrameClient; } | 114 static StubLocalFrameClientForOrientationLockDelegate* Create() { |
| 115 return new StubLocalFrameClientForOrientationLockDelegate; |
| 116 } |
| 112 | 117 |
| 113 std::unique_ptr<WebMediaPlayer> CreateWebMediaPlayer( | 118 std::unique_ptr<WebMediaPlayer> CreateWebMediaPlayer( |
| 114 HTMLMediaElement&, | 119 HTMLMediaElement&, |
| 115 const WebMediaPlayerSource&, | 120 const WebMediaPlayerSource&, |
| 116 WebMediaPlayerClient*) override { | 121 WebMediaPlayerClient*) override { |
| 117 return WTF::MakeUnique<MockVideoWebMediaPlayer>(); | 122 return WTF::MakeUnique<MockWebMediaPlayerForOrientationLockDelegate>(); |
| 118 } | 123 } |
| 119 }; | 124 }; |
| 120 | 125 |
| 121 } // anonymous namespace | 126 } // anonymous namespace |
| 122 | 127 |
| 123 class MediaControlsOrientationLockDelegateTest : public ::testing::Test { | 128 class MediaControlsOrientationLockDelegateTest : public ::testing::Test { |
| 124 protected: | 129 protected: |
| 125 using DeviceOrientationType = | 130 using DeviceOrientationType = |
| 126 MediaControlsOrientationLockDelegate::DeviceOrientationType; | 131 MediaControlsOrientationLockDelegate::DeviceOrientationType; |
| 127 | 132 |
| 128 static constexpr TimeDelta GetUnlockDelay() { | 133 static constexpr TimeDelta GetUnlockDelay() { |
| 129 return MediaControlsOrientationLockDelegate::kUnlockDelay; | 134 return MediaControlsOrientationLockDelegate::kUnlockDelay; |
| 130 } | 135 } |
| 131 | 136 |
| 132 void SetUp() override { | 137 void SetUp() override { |
| 133 chrome_client_ = new MockChromeClient(); | 138 chrome_client_ = new MockChromeClientForOrientationLockDelegate(); |
| 134 | 139 |
| 135 Page::PageClients clients; | 140 Page::PageClients clients; |
| 136 FillWithEmptyClients(clients); | 141 FillWithEmptyClients(clients); |
| 137 clients.chrome_client = chrome_client_.Get(); | 142 clients.chrome_client = chrome_client_.Get(); |
| 138 | 143 |
| 139 page_holder_ = DummyPageHolder::Create(IntSize(800, 600), &clients, | 144 page_holder_ = DummyPageHolder::Create( |
| 140 StubLocalFrameClient::Create()); | 145 IntSize(800, 600), &clients, |
| 146 StubLocalFrameClientForOrientationLockDelegate::Create()); |
| 141 | 147 |
| 142 previous_orientation_event_value_ = | 148 previous_orientation_event_value_ = |
| 143 RuntimeEnabledFeatures::OrientationEventEnabled(); | 149 RuntimeEnabledFeatures::OrientationEventEnabled(); |
| 144 previous_video_fullscreen_orientation_lock_value_ = | 150 previous_video_fullscreen_orientation_lock_value_ = |
| 145 RuntimeEnabledFeatures::VideoFullscreenOrientationLockEnabled(); | 151 RuntimeEnabledFeatures::VideoFullscreenOrientationLockEnabled(); |
| 146 previous_video_rotate_to_fullscreen_value_ = | 152 previous_video_rotate_to_fullscreen_value_ = |
| 147 RuntimeEnabledFeatures::VideoRotateToFullscreenEnabled(); | 153 RuntimeEnabledFeatures::VideoRotateToFullscreenEnabled(); |
| 148 RuntimeEnabledFeatures::SetVideoFullscreenOrientationLockEnabled(true); | 154 RuntimeEnabledFeatures::SetVideoFullscreenOrientationLockEnabled(true); |
| 149 // Turn off rotate-to-fullscreen. Tests covering the intersection of the two | 155 // Turn off rotate-to-fullscreen. Tests covering the intersection of the two |
| 150 // can use the MediaControlsOrientationLockAndRotateToFullscreenDelegateTest | 156 // can use the MediaControlsOrientationLockAndRotateToFullscreenDelegateTest |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 | 231 |
| 226 WebScreenOrientationLockType DelegateOrientationLock() const { | 232 WebScreenOrientationLockType DelegateOrientationLock() const { |
| 227 return MediaControls()->orientation_lock_delegate_->locked_orientation_; | 233 return MediaControls()->orientation_lock_delegate_->locked_orientation_; |
| 228 } | 234 } |
| 229 | 235 |
| 230 WebScreenOrientationLockType ComputeOrientationLock() const { | 236 WebScreenOrientationLockType ComputeOrientationLock() const { |
| 231 return MediaControls() | 237 return MediaControls() |
| 232 ->orientation_lock_delegate_->ComputeOrientationLock(); | 238 ->orientation_lock_delegate_->ComputeOrientationLock(); |
| 233 } | 239 } |
| 234 | 240 |
| 235 MockChromeClient& ChromeClient() const { return *chrome_client_; } | 241 MockChromeClientForOrientationLockDelegate& ChromeClient() const { |
| 242 return *chrome_client_; |
| 243 } |
| 236 | 244 |
| 237 HTMLVideoElement& Video() const { return *video_; } | 245 HTMLVideoElement& Video() const { return *video_; } |
| 238 Document& GetDocument() const { return page_holder_->GetDocument(); } | 246 Document& GetDocument() const { return page_holder_->GetDocument(); } |
| 239 MockWebScreenOrientationClient& ScreenOrientationClient() const { | 247 MockWebScreenOrientationClient& ScreenOrientationClient() const { |
| 240 return ChromeClient().WebScreenOrientationClient(); | 248 return ChromeClient().WebScreenOrientationClient(); |
| 241 } | 249 } |
| 242 MockVideoWebMediaPlayer& MockWebMediaPlayer() const { | 250 MockWebMediaPlayerForOrientationLockDelegate& MockWebMediaPlayer() const { |
| 243 return *static_cast<MockVideoWebMediaPlayer*>(Video().GetWebMediaPlayer()); | 251 return *static_cast<MockWebMediaPlayerForOrientationLockDelegate*>( |
| 252 Video().GetWebMediaPlayer()); |
| 244 } | 253 } |
| 245 | 254 |
| 246 private: | 255 private: |
| 247 friend class MediaControlsOrientationLockAndRotateToFullscreenDelegateTest; | 256 friend class MediaControlsOrientationLockAndRotateToFullscreenDelegateTest; |
| 248 | 257 |
| 249 bool previous_orientation_event_value_; | 258 bool previous_orientation_event_value_; |
| 250 bool previous_video_fullscreen_orientation_lock_value_; | 259 bool previous_video_fullscreen_orientation_lock_value_; |
| 251 bool previous_video_rotate_to_fullscreen_value_; | 260 bool previous_video_rotate_to_fullscreen_value_; |
| 252 std::unique_ptr<DummyPageHolder> page_holder_; | 261 std::unique_ptr<DummyPageHolder> page_holder_; |
| 253 Persistent<HTMLVideoElement> video_; | 262 Persistent<HTMLVideoElement> video_; |
| 254 Persistent<MockChromeClient> chrome_client_; | 263 Persistent<MockChromeClientForOrientationLockDelegate> chrome_client_; |
| 255 }; | 264 }; |
| 256 | 265 |
| 257 class MediaControlsOrientationLockAndRotateToFullscreenDelegateTest | 266 class MediaControlsOrientationLockAndRotateToFullscreenDelegateTest |
| 258 : public MediaControlsOrientationLockDelegateTest { | 267 : public MediaControlsOrientationLockDelegateTest { |
| 259 protected: | 268 protected: |
| 260 enum DeviceNaturalOrientation { kNaturalIsPortrait, kNaturalIsLandscape }; | 269 enum DeviceNaturalOrientation { kNaturalIsPortrait, kNaturalIsLandscape }; |
| 261 | 270 |
| 262 void SetUp() override { | 271 void SetUp() override { |
| 263 // Unset this to fix ScreenOrientationControllerImpl::ComputeOrientation. | 272 // Unset this to fix ScreenOrientationControllerImpl::ComputeOrientation. |
| 264 // TODO(mlamouri): Refactor to avoid this (crbug.com/726817). | 273 // TODO(mlamouri): Refactor to avoid this (crbug.com/726817). |
| (...skipping 1122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1387 | 1396 |
| 1388 // Wait for the rest of the unlock delay. | 1397 // Wait for the rest of the unlock delay. |
| 1389 testing::RunDelayedTasks(GetUnlockDelay() - kMinUnlockDelay); | 1398 testing::RunDelayedTasks(GetUnlockDelay() - kMinUnlockDelay); |
| 1390 | 1399 |
| 1391 // MediaControlsOrientationLockDelegate should now have unlocked. | 1400 // MediaControlsOrientationLockDelegate should now have unlocked. |
| 1392 CheckStatePendingFullscreen(); | 1401 CheckStatePendingFullscreen(); |
| 1393 EXPECT_FALSE(DelegateWillUnlockFullscreen()); | 1402 EXPECT_FALSE(DelegateWillUnlockFullscreen()); |
| 1394 } | 1403 } |
| 1395 | 1404 |
| 1396 } // namespace blink | 1405 } // namespace blink |
| OLD | NEW |