Chromium Code Reviews| 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/dom/Document.h" | 8 #include "core/dom/Document.h" |
| 8 #include "core/dom/DocumentUserGestureToken.h" | 9 #include "core/dom/DocumentUserGestureToken.h" |
| 9 #include "core/dom/Fullscreen.h" | 10 #include "core/dom/Fullscreen.h" |
| 11 #include "core/frame/FrameView.h" | |
| 10 #include "core/frame/ScreenOrientationController.h" | 12 #include "core/frame/ScreenOrientationController.h" |
| 11 #include "core/html/HTMLAudioElement.h" | 13 #include "core/html/HTMLAudioElement.h" |
| 12 #include "core/html/HTMLVideoElement.h" | 14 #include "core/html/HTMLVideoElement.h" |
| 13 #include "core/loader/EmptyClients.h" | 15 #include "core/loader/EmptyClients.h" |
| 14 #include "core/testing/DummyPageHolder.h" | 16 #include "core/testing/DummyPageHolder.h" |
| 17 #include "modules/device_orientation/DeviceOrientationController.h" | |
| 18 #include "modules/device_orientation/DeviceOrientationData.h" | |
| 15 #include "modules/media_controls/MediaControlsImpl.h" | 19 #include "modules/media_controls/MediaControlsImpl.h" |
| 20 #include "modules/screen_orientation/ScreenOrientationControllerImpl.h" | |
| 21 #include "platform/LayoutTestSupport.h" | |
| 16 #include "platform/UserGestureIndicator.h" | 22 #include "platform/UserGestureIndicator.h" |
| 23 #include "platform/geometry/IntRect.h" | |
| 17 #include "platform/testing/EmptyWebMediaPlayer.h" | 24 #include "platform/testing/EmptyWebMediaPlayer.h" |
| 18 #include "platform/testing/UnitTestHelpers.h" | 25 #include "platform/testing/UnitTestHelpers.h" |
| 19 #include "public/platform/WebSize.h" | 26 #include "public/platform/WebSize.h" |
| 20 #include "public/platform/modules/screen_orientation/WebLockOrientationCallback. h" | 27 #include "public/platform/modules/screen_orientation/WebLockOrientationCallback. h" |
| 28 #include "public/platform/modules/screen_orientation/WebScreenOrientationClient. h" | |
| 21 #include "testing/gmock/include/gmock/gmock.h" | 29 #include "testing/gmock/include/gmock/gmock.h" |
| 22 #include "testing/gtest/include/gtest/gtest.h" | 30 #include "testing/gtest/include/gtest/gtest.h" |
| 23 | 31 |
| 24 using ::testing::_; | 32 using ::testing::_; |
| 33 using ::testing::AtLeast; | |
| 25 using ::testing::Return; | 34 using ::testing::Return; |
| 26 | 35 |
| 27 namespace blink { | 36 namespace blink { |
| 28 | 37 |
| 29 namespace { | 38 namespace { |
| 30 | 39 |
| 31 // WebLockOrientationCallback implementation that will not react to a success | 40 // WebLockOrientationCallback implementation that will not react to a success |
| 32 // nor a failure. | 41 // nor a failure. |
| 33 class DummyScreenOrientationCallback : public WebLockOrientationCallback { | 42 class DummyScreenOrientationCallback : public WebLockOrientationCallback { |
| 34 public: | 43 public: |
| 35 void OnSuccess() override {} | 44 void OnSuccess() override {} |
| 36 void OnError(WebLockOrientationError) override {} | 45 void OnError(WebLockOrientationError) override {} |
| 37 }; | 46 }; |
| 38 | 47 |
| 39 class MockVideoWebMediaPlayer : public EmptyWebMediaPlayer { | 48 class MockVideoWebMediaPlayer : public EmptyWebMediaPlayer { |
| 40 public: | 49 public: |
| 41 bool HasVideo() const override { return true; } | 50 bool HasVideo() const override { return true; } |
| 42 | 51 |
| 43 MOCK_CONST_METHOD0(NaturalSize, WebSize()); | 52 MOCK_CONST_METHOD0(NaturalSize, WebSize()); |
| 44 }; | 53 }; |
| 45 | 54 |
| 55 class MockWebScreenOrientationClient : public WebScreenOrientationClient { | |
|
mlamouri (slow - plz ping)
2017/05/26 20:02:47
nit: final?
johnme
2017/05/30 12:40:54
Done (though I'm not sure who's going to try and s
| |
| 56 public: | |
| 57 // WebScreenOrientationClient overrides: | |
| 58 void LockOrientation(WebScreenOrientationLockType type, | |
| 59 std::unique_ptr<WebLockOrientationCallback>) override { | |
| 60 LockOrientation(type); | |
| 61 } | |
| 62 MOCK_METHOD0(UnlockOrientation, void()); | |
|
mlamouri (slow - plz ping)
2017/05/26 20:02:47
style: keep MOCK_METHODS in the same block?
johnme
2017/05/30 12:40:54
I'd rather keep the overrides together? The mocked
| |
| 63 | |
| 64 MOCK_METHOD1(LockOrientation, void(WebScreenOrientationLockType)); | |
| 65 }; | |
| 66 | |
| 46 class MockChromeClient : public EmptyChromeClient { | 67 class MockChromeClient : public EmptyChromeClient { |
|
mlamouri (slow - plz ping)
2017/05/26 20:02:47
nit: could be final too?
johnme
2017/05/30 12:40:54
Done (ditto).
| |
| 47 public: | 68 public: |
| 69 // ChromeClient overrides: | |
| 70 void InstallSupplements(LocalFrame& frame) override { | |
| 71 EmptyChromeClient::InstallSupplements(frame); | |
| 72 ScreenOrientationControllerImpl::ProvideTo(frame, | |
| 73 &web_screen_orientation_client_); | |
| 74 } | |
| 75 void EnterFullscreen(LocalFrame& frame) override { | |
| 76 Fullscreen::From(*frame.GetDocument()).DidEnterFullscreen(); | |
| 77 } | |
| 78 void ExitFullscreen(LocalFrame& frame) override { | |
| 79 Fullscreen::From(*frame.GetDocument()).DidExitFullscreen(); | |
| 80 } | |
| 81 | |
| 48 MOCK_CONST_METHOD0(GetScreenInfo, WebScreenInfo()); | 82 MOCK_CONST_METHOD0(GetScreenInfo, WebScreenInfo()); |
| 83 | |
| 84 MockWebScreenOrientationClient& WebScreenOrientationClient() { | |
| 85 return web_screen_orientation_client_; | |
| 86 } | |
| 87 | |
| 88 private: | |
| 89 MockWebScreenOrientationClient web_screen_orientation_client_; | |
| 49 }; | 90 }; |
| 50 | 91 |
| 51 class StubLocalFrameClient : public EmptyLocalFrameClient { | 92 class StubLocalFrameClient : public EmptyLocalFrameClient { |
| 52 public: | 93 public: |
| 53 static StubLocalFrameClient* Create() { return new StubLocalFrameClient; } | 94 static StubLocalFrameClient* Create() { return new StubLocalFrameClient; } |
| 54 | 95 |
| 55 std::unique_ptr<WebMediaPlayer> CreateWebMediaPlayer( | 96 std::unique_ptr<WebMediaPlayer> CreateWebMediaPlayer( |
| 56 HTMLMediaElement&, | 97 HTMLMediaElement&, |
| 57 const WebMediaPlayerSource&, | 98 const WebMediaPlayerSource&, |
| 58 WebMediaPlayerClient*) override { | 99 WebMediaPlayerClient*) override { |
| 59 return WTF::MakeUnique<MockVideoWebMediaPlayer>(); | 100 return WTF::MakeUnique<MockVideoWebMediaPlayer>(); |
| 60 } | 101 } |
| 61 }; | 102 }; |
| 62 | 103 |
| 63 class MockScreenOrientationController final | |
| 64 : public ScreenOrientationController { | |
| 65 WTF_MAKE_NONCOPYABLE(MockScreenOrientationController); | |
| 66 | |
| 67 public: | |
| 68 static MockScreenOrientationController* ProvideTo(LocalFrame& frame) { | |
| 69 MockScreenOrientationController* controller = | |
| 70 new MockScreenOrientationController(frame); | |
| 71 ScreenOrientationController::ProvideTo(frame, controller); | |
| 72 return controller; | |
| 73 } | |
| 74 | |
| 75 MOCK_METHOD1(lock, void(WebScreenOrientationLockType)); | |
| 76 MOCK_METHOD0(MockUnlock, void()); | |
| 77 | |
| 78 DEFINE_INLINE_VIRTUAL_TRACE() { ScreenOrientationController::Trace(visitor); } | |
| 79 | |
| 80 private: | |
| 81 explicit MockScreenOrientationController(LocalFrame& frame) | |
| 82 : ScreenOrientationController(frame) {} | |
| 83 | |
| 84 void lock(WebScreenOrientationLockType type, | |
| 85 std::unique_ptr<WebLockOrientationCallback>) override { | |
| 86 locked_ = true; | |
| 87 lock(type); | |
| 88 } | |
| 89 | |
| 90 void unlock() override { | |
| 91 locked_ = false; | |
| 92 MockUnlock(); | |
| 93 } | |
| 94 | |
| 95 void NotifyOrientationChanged() override {} | |
| 96 | |
| 97 bool MaybeHasActiveLock() const override { return locked_; } | |
| 98 | |
| 99 bool locked_ = false; | |
| 100 }; | |
| 101 | |
| 102 } // anonymous namespace | 104 } // anonymous namespace |
| 103 | 105 |
| 104 class MediaControlsOrientationLockDelegateTest : public ::testing::Test { | 106 class MediaControlsOrientationLockDelegateTest : public ::testing::Test { |
| 105 protected: | 107 protected: |
| 108 using DeviceOrientation = | |
| 109 MediaControlsOrientationLockDelegate::DeviceOrientation; | |
| 110 | |
| 106 void SetUp() override { | 111 void SetUp() override { |
| 107 previous_video_fullscreen_orientation_lock_value_ = | |
| 108 RuntimeEnabledFeatures::videoFullscreenOrientationLockEnabled(); | |
| 109 RuntimeEnabledFeatures::setVideoFullscreenOrientationLockEnabled(true); | |
| 110 | |
| 111 chrome_client_ = new MockChromeClient(); | 112 chrome_client_ = new MockChromeClient(); |
| 112 | 113 |
| 113 Page::PageClients clients; | 114 Page::PageClients clients; |
| 114 FillWithEmptyClients(clients); | 115 FillWithEmptyClients(clients); |
| 115 clients.chrome_client = chrome_client_.Get(); | 116 clients.chrome_client = chrome_client_.Get(); |
| 116 | 117 |
| 117 page_holder_ = DummyPageHolder::Create(IntSize(800, 600), &clients, | 118 page_holder_ = DummyPageHolder::Create(IntSize(800, 600), &clients, |
| 118 StubLocalFrameClient::Create()); | 119 StubLocalFrameClient::Create()); |
| 119 | 120 |
| 121 previous_orientation_event_value_ = | |
| 122 RuntimeEnabledFeatures::orientationEventEnabled(); | |
| 123 previous_video_fullscreen_orientation_lock_value_ = | |
| 124 RuntimeEnabledFeatures::videoFullscreenOrientationLockEnabled(); | |
| 125 previous_video_rotate_to_fullscreen_value_ = | |
| 126 RuntimeEnabledFeatures::videoRotateToFullscreenEnabled(); | |
| 127 RuntimeEnabledFeatures::setVideoFullscreenOrientationLockEnabled(true); | |
| 128 // Turn off rotate-to-fullscreen. Tests covering the intersection of the two | |
| 129 // can use the MediaControlsOrientationLockAndRotateToFullscreenDelegateTest | |
| 130 // subclass. | |
| 131 RuntimeEnabledFeatures::setVideoRotateToFullscreenEnabled(false); | |
| 132 | |
| 120 GetDocument().write("<body><video></body>"); | 133 GetDocument().write("<body><video></body>"); |
| 121 video_ = toHTMLVideoElement(*GetDocument().QuerySelector("video")); | 134 video_ = toHTMLVideoElement(*GetDocument().QuerySelector("video")); |
| 122 | |
| 123 screen_orientation_controller_ = | |
| 124 MockScreenOrientationController::ProvideTo(page_holder_->GetFrame()); | |
| 125 } | 135 } |
| 126 | 136 |
| 127 void TearDown() override { | 137 void TearDown() override { |
| 128 ::testing::Mock::VerifyAndClear(&GetScreenOrientationController()); | 138 ::testing::Mock::VerifyAndClear(&ScreenOrientationClient()); |
| 129 | 139 |
| 140 RuntimeEnabledFeatures::setOrientationEventEnabled( | |
| 141 previous_orientation_event_value_); | |
| 130 RuntimeEnabledFeatures::setVideoFullscreenOrientationLockEnabled( | 142 RuntimeEnabledFeatures::setVideoFullscreenOrientationLockEnabled( |
| 131 previous_video_fullscreen_orientation_lock_value_); | 143 previous_video_fullscreen_orientation_lock_value_); |
| 144 RuntimeEnabledFeatures::setVideoRotateToFullscreenEnabled( | |
| 145 previous_video_rotate_to_fullscreen_value_); | |
| 132 } | 146 } |
| 133 | 147 |
| 134 static bool HasDelegate(const MediaControls& media_controls) { | 148 static bool HasDelegate(const MediaControls& media_controls) { |
| 135 return !!static_cast<const MediaControlsImpl*>(&media_controls) | 149 return !!static_cast<const MediaControlsImpl*>(&media_controls) |
| 136 ->orientation_lock_delegate_; | 150 ->orientation_lock_delegate_; |
| 137 } | 151 } |
| 138 | 152 |
| 139 void SimulateEnterFullscreen() { | 153 void SimulateEnterFullscreen() { |
| 140 UserGestureIndicator gesture( | 154 UserGestureIndicator gesture( |
| 141 DocumentUserGestureToken::Create(&GetDocument())); | 155 DocumentUserGestureToken::Create(&GetDocument())); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 181 MediaControls()->orientation_lock_delegate_->state_); | 195 MediaControls()->orientation_lock_delegate_->state_); |
| 182 } | 196 } |
| 183 | 197 |
| 184 void CheckStateMaybeLockedFullscreen() const { | 198 void CheckStateMaybeLockedFullscreen() const { |
| 185 EXPECT_EQ( | 199 EXPECT_EQ( |
| 186 MediaControlsOrientationLockDelegate::State::kMaybeLockedFullscreen, | 200 MediaControlsOrientationLockDelegate::State::kMaybeLockedFullscreen, |
| 187 MediaControls()->orientation_lock_delegate_->state_); | 201 MediaControls()->orientation_lock_delegate_->state_); |
| 188 } | 202 } |
| 189 | 203 |
| 190 bool DelegateWillUnlockFullscreen() const { | 204 bool DelegateWillUnlockFullscreen() const { |
| 191 return MediaControls()->orientation_lock_delegate_->locked_orientation_ != | 205 return DelegateOrientationLock() != |
| 192 kWebScreenOrientationLockDefault /* unlocked */; | 206 kWebScreenOrientationLockDefault /* unlocked */; |
| 193 } | 207 } |
| 194 | 208 |
| 209 WebScreenOrientationLockType DelegateOrientationLock() const { | |
| 210 return MediaControls()->orientation_lock_delegate_->locked_orientation_; | |
| 211 } | |
| 212 | |
| 195 WebScreenOrientationLockType ComputeOrientationLock() const { | 213 WebScreenOrientationLockType ComputeOrientationLock() const { |
| 196 return MediaControls() | 214 return MediaControls() |
| 197 ->orientation_lock_delegate_->ComputeOrientationLock(); | 215 ->orientation_lock_delegate_->ComputeOrientationLock(); |
| 198 } | 216 } |
| 199 | 217 |
| 200 MockChromeClient& ChromeClient() const { return *chrome_client_; } | 218 MockChromeClient& ChromeClient() const { return *chrome_client_; } |
| 201 | 219 |
| 202 HTMLVideoElement& Video() const { return *video_; } | 220 HTMLVideoElement& Video() const { return *video_; } |
| 203 Document& GetDocument() const { return page_holder_->GetDocument(); } | 221 Document& GetDocument() const { return page_holder_->GetDocument(); } |
| 204 MockScreenOrientationController& GetScreenOrientationController() const { | 222 MockWebScreenOrientationClient& ScreenOrientationClient() const { |
| 205 return *screen_orientation_controller_; | 223 return ChromeClient().WebScreenOrientationClient(); |
| 206 } | 224 } |
| 207 MockVideoWebMediaPlayer& MockWebMediaPlayer() const { | 225 MockVideoWebMediaPlayer& MockWebMediaPlayer() const { |
| 208 return *static_cast<MockVideoWebMediaPlayer*>(Video().GetWebMediaPlayer()); | 226 return *static_cast<MockVideoWebMediaPlayer*>(Video().GetWebMediaPlayer()); |
| 209 } | 227 } |
| 210 | 228 |
| 211 private: | 229 private: |
| 230 friend class MediaControlsOrientationLockAndRotateToFullscreenDelegateTest; | |
| 231 | |
| 232 bool previous_orientation_event_value_; | |
| 212 bool previous_video_fullscreen_orientation_lock_value_; | 233 bool previous_video_fullscreen_orientation_lock_value_; |
| 234 bool previous_video_rotate_to_fullscreen_value_; | |
| 213 std::unique_ptr<DummyPageHolder> page_holder_; | 235 std::unique_ptr<DummyPageHolder> page_holder_; |
| 214 Persistent<HTMLVideoElement> video_; | 236 Persistent<HTMLVideoElement> video_; |
| 215 Persistent<MockScreenOrientationController> screen_orientation_controller_; | |
| 216 Persistent<MockChromeClient> chrome_client_; | 237 Persistent<MockChromeClient> chrome_client_; |
| 217 }; | 238 }; |
| 218 | 239 |
| 240 class MediaControlsOrientationLockAndRotateToFullscreenDelegateTest | |
| 241 : public MediaControlsOrientationLockDelegateTest { | |
| 242 protected: | |
| 243 enum DeviceNaturalOrientation { kNaturalIsPortrait, kNaturalIsLandscape }; | |
| 244 | |
| 245 void SetUp() override { | |
| 246 // Unset this to fix ScreenOrientationControllerImpl::ComputeOrientation. | |
|
mlamouri (slow - plz ping)
2017/05/26 20:02:47
Can you make this a TODO and assign it to me? I've
johnme
2017/05/30 12:40:54
Done.
| |
| 247 was_running_layout_test_ = LayoutTestSupport::IsRunningLayoutTest(); | |
| 248 LayoutTestSupport::SetIsRunningLayoutTest(false); | |
| 249 | |
| 250 MediaControlsOrientationLockDelegateTest::SetUp(); | |
| 251 | |
| 252 RuntimeEnabledFeatures::setOrientationEventEnabled(true); | |
| 253 RuntimeEnabledFeatures::setVideoRotateToFullscreenEnabled(true); | |
| 254 | |
| 255 // Reset the <video> element now we've enabled the runtime feature. | |
| 256 video_->parentElement()->RemoveChild(video_); | |
| 257 video_ = HTMLVideoElement::Create(GetDocument()); | |
| 258 video_->setAttribute(HTMLNames::controlsAttr, g_empty_atom); | |
| 259 // Most tests should call GetDocument().body()->AppendChild(&Video()); | |
| 260 // This is not done automatically, so that tests control timing of `Attach`, | |
| 261 // which is important for MediaControlsRotateToFullscreenDelegate since | |
| 262 // that's when it reads the initial screen orientation. | |
| 263 } | |
| 264 | |
| 265 void TearDown() override { | |
| 266 MediaControlsOrientationLockDelegateTest::TearDown(); | |
| 267 LayoutTestSupport::SetIsRunningLayoutTest(was_running_layout_test_); | |
| 268 } | |
| 269 | |
| 270 void SetIsAutoRotateEnabledByUser(bool enabled) { | |
| 271 MediaControls() | |
| 272 ->orientation_lock_delegate_ | |
| 273 ->is_auto_rotate_enabled_by_user_for_testing_ = | |
| 274 static_cast<int>(enabled); | |
| 275 } | |
| 276 | |
| 277 WebRect ScreenRectFromAngle(uint16_t screen_orientation_angle) { | |
| 278 uint16_t portrait_angle_mod_180 = natural_orientation_is_portrait_ ? 0 : 90; | |
| 279 bool screen_rect_is_portrait = | |
| 280 screen_orientation_angle % 180 == portrait_angle_mod_180; | |
| 281 return screen_rect_is_portrait ? IntRect(0, 0, 1080, 1920) | |
| 282 : IntRect(0, 0, 1920, 1080); | |
| 283 } | |
| 284 | |
| 285 void RotateDeviceTo(uint16_t new_device_orientation_angle) { | |
| 286 // Pick one of the many (beta,gamma) pairs that should map to each angle. | |
| 287 switch (new_device_orientation_angle) { | |
| 288 case 0: | |
| 289 RotateDeviceTo(90, 0); | |
| 290 break; | |
| 291 case 90: | |
| 292 RotateDeviceTo(0, -90); | |
| 293 break; | |
| 294 case 180: | |
| 295 RotateDeviceTo(-90, 0); | |
| 296 break; | |
| 297 case 270: | |
| 298 RotateDeviceTo(0, 90); | |
| 299 break; | |
| 300 default: | |
| 301 NOTREACHED(); | |
| 302 break; | |
| 303 } | |
| 304 } | |
| 305 void RotateDeviceTo(double beta, double gamma) { | |
| 306 DeviceOrientationController::From(GetDocument()) | |
| 307 .SetOverride(DeviceOrientationData::Create(0.0 /* alpha */, beta, gamma, | |
| 308 false /* absolute */)); | |
| 309 testing::RunPendingTasks(); | |
| 310 } | |
| 311 | |
| 312 // Calls must be wrapped in ASSERT_NO_FATAL_FAILURE. | |
| 313 void RotateScreenTo(WebScreenOrientationType screen_orientation_type, | |
| 314 uint16_t screen_orientation_angle) { | |
| 315 WebScreenInfo screen_info; | |
| 316 screen_info.orientation_type = screen_orientation_type; | |
| 317 screen_info.orientation_angle = screen_orientation_angle; | |
| 318 screen_info.rect = ScreenRectFromAngle(screen_orientation_angle); | |
| 319 ASSERT_TRUE(screen_info.orientation_type == | |
| 320 ScreenOrientationControllerImpl::ComputeOrientation( | |
| 321 screen_info.rect, screen_info.orientation_angle)); | |
| 322 | |
| 323 ::testing::Mock::VerifyAndClearExpectations(&ChromeClient()); | |
| 324 EXPECT_CALL(ChromeClient(), GetScreenInfo()) | |
| 325 .Times(AtLeast(1)) | |
| 326 .WillRepeatedly(Return(screen_info)); | |
| 327 | |
| 328 // Screen Orientation API | |
| 329 ScreenOrientationController::From(*GetDocument().GetFrame()) | |
| 330 ->NotifyOrientationChanged(); | |
| 331 | |
| 332 // Legacy window.orientation API | |
| 333 GetDocument().domWindow()->SendOrientationChangeEvent(); | |
| 334 | |
| 335 testing::RunPendingTasks(); | |
| 336 } | |
| 337 | |
| 338 void InitVideo(int video_width, int video_height) { | |
| 339 // Set up the WebMediaPlayer instance. | |
| 340 GetDocument().body()->AppendChild(&Video()); | |
| 341 Video().SetSrc("https://example.com"); | |
| 342 testing::RunPendingTasks(); | |
| 343 SimulateVideoReadyState(HTMLMediaElement::kHaveMetadata); | |
| 344 | |
| 345 // Set video size. | |
| 346 EXPECT_CALL(MockWebMediaPlayer(), NaturalSize()) | |
| 347 .WillRepeatedly(Return(WebSize(video_width, video_height))); | |
| 348 } | |
| 349 | |
| 350 void PlayVideo() { | |
| 351 { | |
| 352 UserGestureIndicator gesture( | |
| 353 DocumentUserGestureToken::Create(&GetDocument())); | |
| 354 Video().Play(); | |
| 355 } | |
| 356 testing::RunPendingTasks(); | |
| 357 } | |
| 358 | |
| 359 void UpdateVisibilityObserver() { | |
| 360 // Let IntersectionObserver update. | |
| 361 GetDocument().View()->UpdateAllLifecyclePhases(); | |
| 362 testing::RunPendingTasks(); | |
| 363 } | |
| 364 | |
| 365 DeviceOrientation ComputeDeviceOrientation( | |
| 366 DeviceOrientationData* data) const { | |
| 367 return MediaControls() | |
| 368 ->orientation_lock_delegate_->ComputeDeviceOrientation(data); | |
| 369 } | |
| 370 | |
| 371 bool was_running_layout_test_ = false; | |
| 372 bool natural_orientation_is_portrait_ = true; | |
| 373 }; | |
| 374 | |
| 219 TEST_F(MediaControlsOrientationLockDelegateTest, DelegateRequiresFlag) { | 375 TEST_F(MediaControlsOrientationLockDelegateTest, DelegateRequiresFlag) { |
| 220 // Flag on by default. | 376 // Flag on by default. |
| 221 EXPECT_TRUE(HasDelegate(*Video().GetMediaControls())); | 377 EXPECT_TRUE(HasDelegate(*Video().GetMediaControls())); |
| 222 | 378 |
| 223 // Same with flag off. | 379 // Same with flag off. |
| 224 RuntimeEnabledFeatures::setVideoFullscreenOrientationLockEnabled(false); | 380 RuntimeEnabledFeatures::setVideoFullscreenOrientationLockEnabled(false); |
| 225 HTMLVideoElement* video = HTMLVideoElement::Create(GetDocument()); | 381 HTMLVideoElement* video = HTMLVideoElement::Create(GetDocument()); |
| 226 GetDocument().body()->AppendChild(video); | 382 GetDocument().body()->AppendChild(video); |
| 227 EXPECT_FALSE(HasDelegate(*video->GetMediaControls())); | 383 EXPECT_FALSE(HasDelegate(*video->GetMediaControls())); |
| 228 } | 384 } |
| 229 | 385 |
| 230 TEST_F(MediaControlsOrientationLockDelegateTest, DelegateRequiresVideo) { | 386 TEST_F(MediaControlsOrientationLockDelegateTest, DelegateRequiresVideo) { |
| 231 HTMLAudioElement* audio = HTMLAudioElement::Create(GetDocument()); | 387 HTMLAudioElement* audio = HTMLAudioElement::Create(GetDocument()); |
| 232 GetDocument().body()->AppendChild(audio); | 388 GetDocument().body()->AppendChild(audio); |
| 233 EXPECT_FALSE(HasDelegate(*audio->GetMediaControls())); | 389 EXPECT_FALSE(HasDelegate(*audio->GetMediaControls())); |
| 234 } | 390 } |
| 235 | 391 |
| 236 TEST_F(MediaControlsOrientationLockDelegateTest, InitialState) { | 392 TEST_F(MediaControlsOrientationLockDelegateTest, InitialState) { |
| 237 CheckStatePendingFullscreen(); | 393 CheckStatePendingFullscreen(); |
| 238 } | 394 } |
| 239 | 395 |
| 240 TEST_F(MediaControlsOrientationLockDelegateTest, EnterFullscreenNoMetadata) { | 396 TEST_F(MediaControlsOrientationLockDelegateTest, EnterFullscreenNoMetadata) { |
| 241 EXPECT_CALL(GetScreenOrientationController(), lock(_)).Times(0); | 397 EXPECT_CALL(ScreenOrientationClient(), LockOrientation(_)).Times(0); |
| 242 | 398 |
| 243 SimulateEnterFullscreen(); | 399 SimulateEnterFullscreen(); |
| 244 | 400 |
| 245 CheckStatePendingMetadata(); | 401 CheckStatePendingMetadata(); |
| 246 } | 402 } |
| 247 | 403 |
| 248 TEST_F(MediaControlsOrientationLockDelegateTest, LeaveFullscreenNoMetadata) { | 404 TEST_F(MediaControlsOrientationLockDelegateTest, LeaveFullscreenNoMetadata) { |
| 249 EXPECT_CALL(GetScreenOrientationController(), lock(_)).Times(0); | 405 EXPECT_CALL(ScreenOrientationClient(), LockOrientation(_)).Times(0); |
| 250 EXPECT_CALL(GetScreenOrientationController(), MockUnlock()).Times(0); | 406 EXPECT_CALL(ScreenOrientationClient(), UnlockOrientation()).Times(0); |
| 251 | 407 |
| 252 SimulateEnterFullscreen(); | 408 SimulateEnterFullscreen(); |
| 253 // State set to PendingMetadata. | 409 // State set to PendingMetadata. |
| 254 SimulateExitFullscreen(); | 410 SimulateExitFullscreen(); |
| 255 | 411 |
| 256 CheckStatePendingFullscreen(); | 412 CheckStatePendingFullscreen(); |
| 257 } | 413 } |
| 258 | 414 |
| 259 TEST_F(MediaControlsOrientationLockDelegateTest, EnterFullscreenWithMetadata) { | 415 TEST_F(MediaControlsOrientationLockDelegateTest, EnterFullscreenWithMetadata) { |
| 260 SimulateVideoReadyState(HTMLMediaElement::kHaveMetadata); | 416 SimulateVideoReadyState(HTMLMediaElement::kHaveMetadata); |
| 261 | 417 |
| 262 EXPECT_CALL(GetScreenOrientationController(), lock(_)).Times(1); | 418 EXPECT_CALL(ScreenOrientationClient(), LockOrientation(_)).Times(1); |
| 263 EXPECT_FALSE(DelegateWillUnlockFullscreen()); | 419 EXPECT_FALSE(DelegateWillUnlockFullscreen()); |
| 264 | 420 |
| 265 SimulateEnterFullscreen(); | 421 SimulateEnterFullscreen(); |
| 266 | 422 |
| 267 EXPECT_TRUE(DelegateWillUnlockFullscreen()); | 423 EXPECT_TRUE(DelegateWillUnlockFullscreen()); |
| 268 CheckStateMaybeLockedFullscreen(); | 424 CheckStateMaybeLockedFullscreen(); |
| 269 } | 425 } |
| 270 | 426 |
| 271 TEST_F(MediaControlsOrientationLockDelegateTest, LeaveFullscreenWithMetadata) { | 427 TEST_F(MediaControlsOrientationLockDelegateTest, LeaveFullscreenWithMetadata) { |
| 272 SimulateVideoReadyState(HTMLMediaElement::kHaveMetadata); | 428 SimulateVideoReadyState(HTMLMediaElement::kHaveMetadata); |
| 273 | 429 |
| 274 EXPECT_CALL(GetScreenOrientationController(), lock(_)).Times(1); | 430 EXPECT_CALL(ScreenOrientationClient(), LockOrientation(_)).Times(1); |
| 275 EXPECT_CALL(GetScreenOrientationController(), MockUnlock()).Times(1); | 431 EXPECT_CALL(ScreenOrientationClient(), UnlockOrientation()).Times(1); |
| 276 | 432 |
| 277 SimulateEnterFullscreen(); | 433 SimulateEnterFullscreen(); |
| 278 // State set to MaybeLockedFullscreen. | 434 // State set to MaybeLockedFullscreen. |
| 279 SimulateExitFullscreen(); | 435 SimulateExitFullscreen(); |
| 280 | 436 |
| 281 EXPECT_FALSE(DelegateWillUnlockFullscreen()); | 437 EXPECT_FALSE(DelegateWillUnlockFullscreen()); |
| 282 CheckStatePendingFullscreen(); | 438 CheckStatePendingFullscreen(); |
| 283 } | 439 } |
| 284 | 440 |
| 285 TEST_F(MediaControlsOrientationLockDelegateTest, EnterFullscreenAfterPageLock) { | 441 TEST_F(MediaControlsOrientationLockDelegateTest, EnterFullscreenAfterPageLock) { |
| 286 SimulateVideoReadyState(HTMLMediaElement::kHaveMetadata); | 442 SimulateVideoReadyState(HTMLMediaElement::kHaveMetadata); |
| 287 SimulateOrientationLock(); | 443 SimulateOrientationLock(); |
| 288 | 444 |
| 289 EXPECT_FALSE(DelegateWillUnlockFullscreen()); | 445 EXPECT_FALSE(DelegateWillUnlockFullscreen()); |
| 290 EXPECT_CALL(GetScreenOrientationController(), lock(_)).Times(0); | 446 EXPECT_CALL(ScreenOrientationClient(), LockOrientation(_)).Times(0); |
| 291 | 447 |
| 292 SimulateEnterFullscreen(); | 448 SimulateEnterFullscreen(); |
| 293 | 449 |
| 294 EXPECT_FALSE(DelegateWillUnlockFullscreen()); | 450 EXPECT_FALSE(DelegateWillUnlockFullscreen()); |
| 295 CheckStateMaybeLockedFullscreen(); | 451 CheckStateMaybeLockedFullscreen(); |
| 296 } | 452 } |
| 297 | 453 |
| 298 TEST_F(MediaControlsOrientationLockDelegateTest, LeaveFullscreenAfterPageLock) { | 454 TEST_F(MediaControlsOrientationLockDelegateTest, LeaveFullscreenAfterPageLock) { |
| 299 SimulateVideoReadyState(HTMLMediaElement::kHaveMetadata); | 455 SimulateVideoReadyState(HTMLMediaElement::kHaveMetadata); |
| 300 SimulateOrientationLock(); | 456 SimulateOrientationLock(); |
| 301 | 457 |
| 302 EXPECT_CALL(GetScreenOrientationController(), lock(_)).Times(0); | 458 EXPECT_CALL(ScreenOrientationClient(), LockOrientation(_)).Times(0); |
| 303 EXPECT_CALL(GetScreenOrientationController(), MockUnlock()).Times(0); | 459 EXPECT_CALL(ScreenOrientationClient(), UnlockOrientation()).Times(0); |
| 304 | 460 |
| 305 SimulateEnterFullscreen(); | 461 SimulateEnterFullscreen(); |
| 306 // State set to MaybeLockedFullscreen. | 462 // State set to MaybeLockedFullscreen. |
| 307 SimulateExitFullscreen(); | 463 SimulateExitFullscreen(); |
| 308 | 464 |
| 309 EXPECT_FALSE(DelegateWillUnlockFullscreen()); | 465 EXPECT_FALSE(DelegateWillUnlockFullscreen()); |
| 310 CheckStatePendingFullscreen(); | 466 CheckStatePendingFullscreen(); |
| 311 } | 467 } |
| 312 | 468 |
| 313 TEST_F(MediaControlsOrientationLockDelegateTest, | 469 TEST_F(MediaControlsOrientationLockDelegateTest, |
| 314 ReceivedMetadataAfterExitingFullscreen) { | 470 ReceivedMetadataAfterExitingFullscreen) { |
| 315 EXPECT_CALL(GetScreenOrientationController(), lock(_)).Times(1); | 471 EXPECT_CALL(ScreenOrientationClient(), LockOrientation(_)).Times(1); |
| 316 | 472 |
| 317 SimulateEnterFullscreen(); | 473 SimulateEnterFullscreen(); |
| 318 // State set to PendingMetadata. | 474 // State set to PendingMetadata. |
| 319 | 475 |
| 320 // Set up the WebMediaPlayer instance. | 476 // Set up the WebMediaPlayer instance. |
| 321 Video().SetSrc("http://example.com"); | 477 Video().SetSrc("http://example.com"); |
| 322 testing::RunPendingTasks(); | 478 testing::RunPendingTasks(); |
| 323 | 479 |
| 324 SimulateVideoNetworkState(HTMLMediaElement::kNetworkIdle); | 480 SimulateVideoNetworkState(HTMLMediaElement::kNetworkIdle); |
| 325 SimulateVideoReadyState(HTMLMediaElement::kHaveMetadata); | 481 SimulateVideoReadyState(HTMLMediaElement::kHaveMetadata); |
| 326 testing::RunPendingTasks(); | 482 testing::RunPendingTasks(); |
| 327 | 483 |
| 328 CheckStateMaybeLockedFullscreen(); | 484 CheckStateMaybeLockedFullscreen(); |
| 329 } | 485 } |
| 330 | 486 |
| 331 TEST_F(MediaControlsOrientationLockDelegateTest, ReceivedMetadataLater) { | 487 TEST_F(MediaControlsOrientationLockDelegateTest, ReceivedMetadataLater) { |
| 332 EXPECT_CALL(GetScreenOrientationController(), lock(_)).Times(0); | 488 EXPECT_CALL(ScreenOrientationClient(), LockOrientation(_)).Times(0); |
| 333 EXPECT_CALL(GetScreenOrientationController(), MockUnlock()).Times(0); | 489 EXPECT_CALL(ScreenOrientationClient(), UnlockOrientation()).Times(0); |
| 334 | 490 |
| 335 SimulateEnterFullscreen(); | 491 SimulateEnterFullscreen(); |
| 336 // State set to PendingMetadata. | 492 // State set to PendingMetadata. |
| 337 SimulateExitFullscreen(); | 493 SimulateExitFullscreen(); |
| 338 | 494 |
| 339 // Set up the WebMediaPlayer instance. | 495 // Set up the WebMediaPlayer instance. |
| 340 Video().SetSrc("http://example.com"); | 496 Video().SetSrc("http://example.com"); |
| 341 testing::RunPendingTasks(); | 497 testing::RunPendingTasks(); |
| 342 | 498 |
| 343 SimulateVideoNetworkState(HTMLMediaElement::kNetworkIdle); | 499 SimulateVideoNetworkState(HTMLMediaElement::kNetworkIdle); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 395 .WillOnce(Return(screen_info)); | 551 .WillOnce(Return(screen_info)); |
| 396 EXPECT_EQ(kWebScreenOrientationLockLandscape, ComputeOrientationLock()); | 552 EXPECT_EQ(kWebScreenOrientationLockLandscape, ComputeOrientationLock()); |
| 397 | 553 |
| 398 screen_info.orientation_type = kWebScreenOrientationLandscapeSecondary; | 554 screen_info.orientation_type = kWebScreenOrientationLandscapeSecondary; |
| 399 EXPECT_CALL(ChromeClient(), GetScreenInfo()) | 555 EXPECT_CALL(ChromeClient(), GetScreenInfo()) |
| 400 .Times(1) | 556 .Times(1) |
| 401 .WillOnce(Return(screen_info)); | 557 .WillOnce(Return(screen_info)); |
| 402 EXPECT_EQ(kWebScreenOrientationLockLandscape, ComputeOrientationLock()); | 558 EXPECT_EQ(kWebScreenOrientationLockLandscape, ComputeOrientationLock()); |
| 403 } | 559 } |
| 404 | 560 |
| 561 TEST_F(MediaControlsOrientationLockAndRotateToFullscreenDelegateTest, | |
| 562 ComputeDeviceOrientation) { | |
| 563 InitVideo(400, 400); | |
| 564 | |
| 565 for (int n_o_i_p = false; n_o_i_p <= true; n_o_i_p++) { | |
|
mlamouri (slow - plz ping)
2017/05/26 20:02:47
This looks weird at first glance. Maybe add a comm
johnme
2017/05/30 12:40:54
Done.
| |
| 566 natural_orientation_is_portrait_ = static_cast<bool>(n_o_i_p); | |
| 567 SCOPED_TRACE(::testing::Message() << "natural_orientation_is_portrait_=" | |
| 568 << natural_orientation_is_portrait_); | |
| 569 | |
| 570 DeviceOrientation natural_orientation = natural_orientation_is_portrait_ | |
| 571 ? DeviceOrientation::kPortrait | |
| 572 : DeviceOrientation::kLandscape; | |
| 573 DeviceOrientation perpendicular_to_natural_orientation = | |
| 574 natural_orientation_is_portrait_ ? DeviceOrientation::kLandscape | |
| 575 : DeviceOrientation::kPortrait; | |
| 576 | |
| 577 // There are four valid combinations of orientation type and orientation | |
| 578 // angle for a naturally portrait device, and they should all calculate the | |
| 579 // same device orientation (since this doesn't depend on the screen | |
| 580 // orientation, it only depends on whether the device is naturally portrait | |
| 581 // or naturally landscape). Similarly for a naturally landscape device. | |
| 582 for (int screen_angle = 0; screen_angle < 360; screen_angle += 90) { | |
| 583 SCOPED_TRACE(::testing::Message() << "screen_angle=" << screen_angle); | |
| 584 WebScreenOrientationType screen_type = kWebScreenOrientationUndefined; | |
| 585 switch (screen_angle) { | |
| 586 case 0: | |
| 587 screen_type = natural_orientation_is_portrait_ | |
| 588 ? kWebScreenOrientationPortraitPrimary | |
| 589 : kWebScreenOrientationLandscapePrimary; | |
| 590 break; | |
| 591 case 90: | |
| 592 screen_type = natural_orientation_is_portrait_ | |
| 593 ? kWebScreenOrientationLandscapePrimary | |
| 594 : kWebScreenOrientationPortraitSecondary; | |
| 595 break; | |
| 596 case 180: | |
| 597 screen_type = natural_orientation_is_portrait_ | |
| 598 ? kWebScreenOrientationPortraitSecondary | |
| 599 : kWebScreenOrientationLandscapeSecondary; | |
| 600 break; | |
| 601 case 270: | |
| 602 screen_type = natural_orientation_is_portrait_ | |
| 603 ? kWebScreenOrientationLandscapeSecondary | |
| 604 : kWebScreenOrientationPortraitPrimary; | |
| 605 break; | |
| 606 } | |
| 607 ASSERT_NO_FATAL_FAILURE(RotateScreenTo(screen_type, screen_angle)); | |
| 608 | |
| 609 // Compass heading is irrelevant to this calculation. | |
| 610 double alpha = 0.0; | |
| 611 bool absolute = false; | |
| 612 | |
| 613 // These beta and gamma values should all map to r < sin(24 degrees), so | |
| 614 // orientation == kFlat, irrespective of their device_orientation_angle. | |
| 615 EXPECT_EQ(DeviceOrientation::kFlat, // face up | |
| 616 ComputeDeviceOrientation(DeviceOrientationData::Create( | |
| 617 alpha, 0. /* beta */, 0. /* gamma */, absolute))); | |
| 618 EXPECT_EQ(DeviceOrientation::kFlat, // face down | |
| 619 ComputeDeviceOrientation(DeviceOrientationData::Create( | |
| 620 alpha, 180. /* beta */, 0. /* gamma */, absolute))); | |
| 621 EXPECT_EQ(DeviceOrientation::kFlat, // face down | |
| 622 ComputeDeviceOrientation(DeviceOrientationData::Create( | |
| 623 alpha, -180. /* beta */, 0. /* gamma */, absolute))); | |
| 624 EXPECT_EQ(DeviceOrientation::kFlat, // face up, angle=0 | |
| 625 ComputeDeviceOrientation(DeviceOrientationData::Create( | |
| 626 alpha, 20. /* beta */, 0. /* gamma */, absolute))); | |
| 627 EXPECT_EQ(DeviceOrientation::kFlat, // face up, angle=90 | |
| 628 ComputeDeviceOrientation(DeviceOrientationData::Create( | |
| 629 alpha, 0. /* beta */, -20. /* gamma */, absolute))); | |
| 630 EXPECT_EQ(DeviceOrientation::kFlat, // face up, angle=180 | |
| 631 ComputeDeviceOrientation(DeviceOrientationData::Create( | |
| 632 alpha, -20. /* beta */, 0. /* gamma */, absolute))); | |
| 633 EXPECT_EQ(DeviceOrientation::kFlat, // face up, angle=270 | |
| 634 ComputeDeviceOrientation(DeviceOrientationData::Create( | |
| 635 alpha, 0. /* beta */, 20. /* gamma */, absolute))); | |
| 636 | |
| 637 // These beta and gamma values should all map to r ~= 1 and | |
| 638 // device_orientation_angle % 90 ~= 45, hence orientation == kDiagonal. | |
| 639 EXPECT_EQ(DeviceOrientation::kDiagonal, // angle=45 | |
| 640 ComputeDeviceOrientation(DeviceOrientationData::Create( | |
| 641 alpha, 135. /* beta */, 90. /* gamma */, absolute))); | |
| 642 EXPECT_EQ(DeviceOrientation::kDiagonal, // angle=45 | |
| 643 ComputeDeviceOrientation(DeviceOrientationData::Create( | |
| 644 alpha, 45. /* beta */, -90. /* gamma */, absolute))); | |
| 645 EXPECT_EQ(DeviceOrientation::kDiagonal, // angle=135 | |
| 646 ComputeDeviceOrientation(DeviceOrientationData::Create( | |
| 647 alpha, -135. /* beta */, 90. /* gamma */, absolute))); | |
| 648 EXPECT_EQ(DeviceOrientation::kDiagonal, // angle=135 | |
| 649 ComputeDeviceOrientation(DeviceOrientationData::Create( | |
| 650 alpha, -45. /* beta */, -90. /* gamma */, absolute))); | |
| 651 EXPECT_EQ(DeviceOrientation::kDiagonal, // angle=225 | |
| 652 ComputeDeviceOrientation(DeviceOrientationData::Create( | |
| 653 alpha, -45. /* beta */, 90. /* gamma */, absolute))); | |
| 654 EXPECT_EQ(DeviceOrientation::kDiagonal, // angle=225 | |
| 655 ComputeDeviceOrientation(DeviceOrientationData::Create( | |
| 656 alpha, -135. /* beta */, -90. /* gamma */, absolute))); | |
| 657 EXPECT_EQ(DeviceOrientation::kDiagonal, // angle=315 | |
| 658 ComputeDeviceOrientation(DeviceOrientationData::Create( | |
| 659 alpha, 45. /* beta */, 90. /* gamma */, absolute))); | |
| 660 EXPECT_EQ(DeviceOrientation::kDiagonal, // angle=315 | |
| 661 ComputeDeviceOrientation(DeviceOrientationData::Create( | |
| 662 alpha, 135. /* beta */, -90. /* gamma */, absolute))); | |
| 663 | |
| 664 // These beta and gamma values should all map to r ~= 1 and | |
| 665 // device_orientation_angle ~= 0, hence orientation == kPortrait. | |
| 666 EXPECT_EQ(natural_orientation, | |
| 667 ComputeDeviceOrientation(DeviceOrientationData::Create( | |
| 668 alpha, 90. /* beta */, 0. /* gamma */, absolute))); | |
| 669 EXPECT_EQ(natural_orientation, | |
| 670 ComputeDeviceOrientation(DeviceOrientationData::Create( | |
| 671 alpha, 90. /* beta */, 90. /* gamma */, absolute))); | |
| 672 EXPECT_EQ(natural_orientation, | |
| 673 ComputeDeviceOrientation(DeviceOrientationData::Create( | |
| 674 alpha, 90. /* beta */, -90. /* gamma */, absolute))); | |
| 675 EXPECT_EQ(natural_orientation, | |
| 676 ComputeDeviceOrientation(DeviceOrientationData::Create( | |
| 677 alpha, 85. /* beta */, 90. /* gamma */, absolute))); | |
| 678 EXPECT_EQ(natural_orientation, | |
| 679 ComputeDeviceOrientation(DeviceOrientationData::Create( | |
| 680 alpha, 85. /* beta */, -90. /* gamma */, absolute))); | |
| 681 EXPECT_EQ(natural_orientation, | |
| 682 ComputeDeviceOrientation(DeviceOrientationData::Create( | |
| 683 alpha, 95. /* beta */, 90. /* gamma */, absolute))); | |
| 684 EXPECT_EQ(natural_orientation, | |
| 685 ComputeDeviceOrientation(DeviceOrientationData::Create( | |
| 686 alpha, 95. /* beta */, -90. /* gamma */, absolute))); | |
| 687 | |
| 688 // These beta and gamma values should all map to r == 1 and | |
| 689 // device_orientation_angle == 90, hence orientation == kLandscape. | |
| 690 EXPECT_EQ(perpendicular_to_natural_orientation, | |
| 691 ComputeDeviceOrientation(DeviceOrientationData::Create( | |
| 692 alpha, 0. /* beta */, -90. /* gamma */, absolute))); | |
| 693 EXPECT_EQ(perpendicular_to_natural_orientation, | |
| 694 ComputeDeviceOrientation(DeviceOrientationData::Create( | |
| 695 alpha, 180. /* beta */, 90. /* gamma */, absolute))); | |
| 696 EXPECT_EQ(perpendicular_to_natural_orientation, | |
| 697 ComputeDeviceOrientation(DeviceOrientationData::Create( | |
| 698 alpha, -180. /* beta */, 90. /* gamma */, absolute))); | |
| 699 | |
| 700 // These beta and gamma values should all map to r ~= 1 and | |
| 701 // device_orientation_angle ~= 180, hence orientation == kPortrait. | |
| 702 EXPECT_EQ(natural_orientation, | |
| 703 ComputeDeviceOrientation(DeviceOrientationData::Create( | |
| 704 alpha, -90. /* beta */, 0. /* gamma */, absolute))); | |
| 705 EXPECT_EQ(natural_orientation, | |
| 706 ComputeDeviceOrientation(DeviceOrientationData::Create( | |
| 707 alpha, -90. /* beta */, 90. /* gamma */, absolute))); | |
| 708 EXPECT_EQ(natural_orientation, | |
| 709 ComputeDeviceOrientation(DeviceOrientationData::Create( | |
| 710 alpha, -90. /* beta */, -90. /* gamma */, absolute))); | |
| 711 EXPECT_EQ(natural_orientation, | |
| 712 ComputeDeviceOrientation(DeviceOrientationData::Create( | |
| 713 alpha, -85. /* beta */, 90. /* gamma */, absolute))); | |
| 714 EXPECT_EQ(natural_orientation, | |
| 715 ComputeDeviceOrientation(DeviceOrientationData::Create( | |
| 716 alpha, -85. /* beta */, -90. /* gamma */, absolute))); | |
| 717 EXPECT_EQ(natural_orientation, | |
| 718 ComputeDeviceOrientation(DeviceOrientationData::Create( | |
| 719 alpha, -95. /* beta */, 90. /* gamma */, absolute))); | |
| 720 EXPECT_EQ(natural_orientation, | |
| 721 ComputeDeviceOrientation(DeviceOrientationData::Create( | |
| 722 alpha, -95. /* beta */, -90. /* gamma */, absolute))); | |
| 723 | |
| 724 // These beta and gamma values should all map to r == 1 and | |
| 725 // device_orientation_angle == 270, hence orientation == kLandscape. | |
| 726 EXPECT_EQ(perpendicular_to_natural_orientation, | |
| 727 ComputeDeviceOrientation(DeviceOrientationData::Create( | |
| 728 alpha, 0. /* beta */, 90. /* gamma */, absolute))); | |
| 729 EXPECT_EQ(perpendicular_to_natural_orientation, | |
| 730 ComputeDeviceOrientation(DeviceOrientationData::Create( | |
| 731 alpha, 180. /* beta */, -90. /* gamma */, absolute))); | |
| 732 EXPECT_EQ(perpendicular_to_natural_orientation, | |
| 733 ComputeDeviceOrientation(DeviceOrientationData::Create( | |
| 734 alpha, -180. /* beta */, -90. /* gamma */, absolute))); | |
| 735 } | |
| 736 } | |
| 737 } | |
| 738 | |
| 739 TEST_F(MediaControlsOrientationLockAndRotateToFullscreenDelegateTest, | |
| 740 PortraitInlineRotateToLandscapeFullscreen) { | |
| 741 // Naturally portrait device, initially portrait, with landscape video. | |
| 742 natural_orientation_is_portrait_ = true; | |
| 743 ASSERT_NO_FATAL_FAILURE( | |
| 744 RotateScreenTo(kWebScreenOrientationPortraitPrimary, 0)); | |
| 745 InitVideo(640, 480); | |
| 746 SetIsAutoRotateEnabledByUser(true); | |
| 747 PlayVideo(); | |
| 748 UpdateVisibilityObserver(); | |
| 749 | |
| 750 // Initially inline, unlocked orientation. | |
| 751 ASSERT_FALSE(Video().IsFullscreen()); | |
| 752 CheckStatePendingFullscreen(); | |
| 753 ASSERT_FALSE(DelegateWillUnlockFullscreen()); | |
| 754 | |
| 755 // Simulate user rotating their device to landscape triggering a screen | |
| 756 // orientation change. | |
| 757 ASSERT_NO_FATAL_FAILURE( | |
| 758 RotateScreenTo(kWebScreenOrientationLandscapePrimary, 90)); | |
| 759 | |
| 760 // MediaControlsRotateToFullscreenDelegate should enter fullscreen, so | |
| 761 // MediaControlsOrientationLockDelegate should lock orientation to landscape | |
| 762 // (even though the screen is already landscape). | |
| 763 EXPECT_TRUE(Video().IsFullscreen()); | |
| 764 CheckStateMaybeLockedFullscreen(); | |
| 765 EXPECT_EQ(kWebScreenOrientationLockLandscape, DelegateOrientationLock()); | |
| 766 | |
| 767 // Device orientation events received by MediaControlsOrientationLockDelegate | |
| 768 // will confirm that the device is already landscape. | |
| 769 RotateDeviceTo(90 /* landscape primary */); | |
| 770 | |
| 771 // MediaControlsOrientationLockDelegate should unlock orientation. | |
| 772 CheckStatePendingFullscreen(); | |
| 773 EXPECT_FALSE(DelegateWillUnlockFullscreen()); | |
| 774 } | |
| 775 | |
| 776 TEST_F(MediaControlsOrientationLockAndRotateToFullscreenDelegateTest, | |
| 777 PortraitInlineButtonToPortraitLockedLandscapeFullscreen) { | |
| 778 // Naturally portrait device, initially portrait, with landscape video. | |
| 779 natural_orientation_is_portrait_ = true; | |
| 780 ASSERT_NO_FATAL_FAILURE( | |
| 781 RotateScreenTo(kWebScreenOrientationPortraitPrimary, 0)); | |
| 782 InitVideo(640, 480); | |
| 783 SetIsAutoRotateEnabledByUser(true); | |
| 784 | |
| 785 // Initially inline, unlocked orientation. | |
| 786 ASSERT_FALSE(Video().IsFullscreen()); | |
| 787 CheckStatePendingFullscreen(); | |
| 788 ASSERT_FALSE(DelegateWillUnlockFullscreen()); | |
| 789 | |
| 790 // Simulate user clicking on media controls fullscreen button. | |
| 791 SimulateEnterFullscreen(); | |
| 792 EXPECT_TRUE(Video().IsFullscreen()); | |
| 793 | |
| 794 // MediaControlsOrientationLockDelegate should lock to landscape. | |
| 795 CheckStateMaybeLockedFullscreen(); | |
| 796 EXPECT_EQ(kWebScreenOrientationLockLandscape, DelegateOrientationLock()); | |
| 797 | |
| 798 // This will trigger a screen orientation change to landscape. | |
| 799 ASSERT_NO_FATAL_FAILURE( | |
| 800 RotateScreenTo(kWebScreenOrientationLandscapePrimary, 90)); | |
| 801 | |
| 802 // Even though the device is still held in portrait. | |
| 803 RotateDeviceTo(0 /* portrait primary */); | |
| 804 | |
| 805 // MediaControlsOrientationLockDelegate should remain locked to landscape. | |
| 806 CheckStateMaybeLockedFullscreen(); | |
| 807 EXPECT_EQ(kWebScreenOrientationLockLandscape, DelegateOrientationLock()); | |
| 808 } | |
| 809 | |
| 810 TEST_F(MediaControlsOrientationLockAndRotateToFullscreenDelegateTest, | |
| 811 PortraitLockedLandscapeFullscreenRotateToLandscapeFullscreen) { | |
| 812 // Naturally portrait device, initially portrait device orientation but locked | |
| 813 // to landscape screen orientation, with landscape video. | |
| 814 natural_orientation_is_portrait_ = true; | |
| 815 ASSERT_NO_FATAL_FAILURE( | |
| 816 RotateScreenTo(kWebScreenOrientationLandscapePrimary, 90)); | |
| 817 InitVideo(640, 480); | |
| 818 SetIsAutoRotateEnabledByUser(true); | |
| 819 | |
| 820 // Initially fullscreen, locked orientation. | |
| 821 SimulateEnterFullscreen(); | |
| 822 ASSERT_TRUE(Video().IsFullscreen()); | |
| 823 CheckStateMaybeLockedFullscreen(); | |
| 824 EXPECT_EQ(kWebScreenOrientationLockLandscape, DelegateOrientationLock()); | |
| 825 | |
| 826 // Simulate user rotating their device to landscape (matching the screen | |
| 827 // orientation lock). | |
| 828 RotateDeviceTo(90 /* landscape primary */); | |
| 829 | |
| 830 // MediaControlsOrientationLockDelegate should unlock orientation. | |
| 831 CheckStatePendingFullscreen(); | |
| 832 EXPECT_FALSE(DelegateWillUnlockFullscreen()); | |
| 833 EXPECT_TRUE(Video().IsFullscreen()); | |
| 834 } | |
| 835 | |
| 836 TEST_F(MediaControlsOrientationLockAndRotateToFullscreenDelegateTest, | |
| 837 PortraitLockedLandscapeFullscreenBackToPortraitInline) { | |
| 838 // Naturally portrait device, initially portrait device orientation but locked | |
| 839 // to landscape screen orientation, with landscape video. | |
| 840 natural_orientation_is_portrait_ = true; | |
| 841 ASSERT_NO_FATAL_FAILURE( | |
| 842 RotateScreenTo(kWebScreenOrientationLandscapePrimary, 90)); | |
| 843 InitVideo(640, 480); | |
| 844 SetIsAutoRotateEnabledByUser(true); | |
| 845 | |
| 846 // Initially fullscreen, locked orientation. | |
| 847 SimulateEnterFullscreen(); | |
| 848 ASSERT_TRUE(Video().IsFullscreen()); | |
| 849 CheckStateMaybeLockedFullscreen(); | |
| 850 EXPECT_EQ(kWebScreenOrientationLockLandscape, DelegateOrientationLock()); | |
| 851 | |
| 852 // Simulate user clicking on media controls exit fullscreen button. | |
| 853 // orientation lock). | |
| 854 SimulateExitFullscreen(); | |
| 855 EXPECT_FALSE(Video().IsFullscreen()); | |
| 856 | |
| 857 // MediaControlsOrientationLockDelegate should unlock orientation. | |
| 858 CheckStatePendingFullscreen(); | |
| 859 EXPECT_FALSE(DelegateWillUnlockFullscreen()); | |
| 860 | |
| 861 // Play the video and make it visible, just to make sure | |
| 862 // MediaControlsRotateToFullscreenDelegate doesn't react to the | |
| 863 // orientationchange event. | |
| 864 PlayVideo(); | |
| 865 UpdateVisibilityObserver(); | |
| 866 | |
| 867 // Unlocking the orientation earlier will trigger a screen orientation change | |
| 868 // to portrait (since the device orientation was already portrait, even though | |
| 869 // the screen was locked to landscape). | |
| 870 ASSERT_NO_FATAL_FAILURE( | |
| 871 RotateScreenTo(kWebScreenOrientationPortraitPrimary, 0)); | |
| 872 | |
| 873 // Video should remain inline, unlocked. | |
| 874 CheckStatePendingFullscreen(); | |
| 875 EXPECT_FALSE(DelegateWillUnlockFullscreen()); | |
| 876 EXPECT_FALSE(Video().IsFullscreen()); | |
| 877 } | |
| 878 | |
| 879 TEST_F(MediaControlsOrientationLockAndRotateToFullscreenDelegateTest, | |
| 880 LandscapeInlineRotateToPortraitInline) { | |
| 881 // Naturally portrait device, initially landscape, with landscape video. | |
| 882 natural_orientation_is_portrait_ = true; | |
| 883 ASSERT_NO_FATAL_FAILURE( | |
| 884 RotateScreenTo(kWebScreenOrientationLandscapePrimary, 90)); | |
| 885 InitVideo(640, 480); | |
| 886 SetIsAutoRotateEnabledByUser(true); | |
| 887 PlayVideo(); | |
| 888 UpdateVisibilityObserver(); | |
| 889 | |
| 890 // Initially inline, unlocked orientation. | |
| 891 ASSERT_FALSE(Video().IsFullscreen()); | |
| 892 CheckStatePendingFullscreen(); | |
| 893 ASSERT_FALSE(DelegateWillUnlockFullscreen()); | |
| 894 | |
| 895 // Simulate user rotating their device to portrait triggering a screen | |
| 896 // orientation change. | |
| 897 ASSERT_NO_FATAL_FAILURE( | |
| 898 RotateScreenTo(kWebScreenOrientationPortraitPrimary, 0)); | |
| 899 | |
| 900 // Video should remain inline, unlocked. | |
| 901 CheckStatePendingFullscreen(); | |
| 902 EXPECT_FALSE(DelegateWillUnlockFullscreen()); | |
| 903 EXPECT_FALSE(Video().IsFullscreen()); | |
| 904 } | |
| 905 | |
| 906 TEST_F(MediaControlsOrientationLockAndRotateToFullscreenDelegateTest, | |
| 907 LandscapeInlineButtonToLandscapeFullscreen) { | |
| 908 // Naturally portrait device, initially landscape, with landscape video. | |
| 909 natural_orientation_is_portrait_ = true; | |
| 910 ASSERT_NO_FATAL_FAILURE( | |
| 911 RotateScreenTo(kWebScreenOrientationLandscapePrimary, 90)); | |
| 912 InitVideo(640, 480); | |
| 913 SetIsAutoRotateEnabledByUser(true); | |
| 914 | |
| 915 // Initially inline, unlocked orientation. | |
| 916 ASSERT_FALSE(Video().IsFullscreen()); | |
| 917 CheckStatePendingFullscreen(); | |
| 918 ASSERT_FALSE(DelegateWillUnlockFullscreen()); | |
| 919 | |
| 920 // Simulate user clicking on media controls fullscreen button. | |
| 921 SimulateEnterFullscreen(); | |
| 922 EXPECT_TRUE(Video().IsFullscreen()); | |
| 923 | |
| 924 // MediaControlsOrientationLockDelegate should lock to landscape (even though | |
| 925 // the screen is already landscape). | |
| 926 CheckStateMaybeLockedFullscreen(); | |
| 927 EXPECT_EQ(kWebScreenOrientationLockLandscape, DelegateOrientationLock()); | |
| 928 | |
| 929 // Device orientation events received by MediaControlsOrientationLockDelegate | |
| 930 // will confirm that the device is already landscape. | |
| 931 RotateDeviceTo(90 /* landscape primary */); | |
| 932 | |
| 933 // MediaControlsOrientationLockDelegate should unlock orientation. | |
| 934 CheckStatePendingFullscreen(); | |
| 935 EXPECT_FALSE(DelegateWillUnlockFullscreen()); | |
| 936 } | |
| 937 | |
| 938 TEST_F(MediaControlsOrientationLockAndRotateToFullscreenDelegateTest, | |
| 939 LandscapeFullscreenRotateToPortraitInline) { | |
| 940 // Naturally portrait device, initially landscape, with landscape video. | |
| 941 natural_orientation_is_portrait_ = true; | |
| 942 ASSERT_NO_FATAL_FAILURE( | |
| 943 RotateScreenTo(kWebScreenOrientationLandscapePrimary, 90)); | |
| 944 InitVideo(640, 480); | |
| 945 SetIsAutoRotateEnabledByUser(true); | |
| 946 | |
| 947 // Initially fullscreen, unlocked orientation. | |
| 948 SimulateEnterFullscreen(); | |
| 949 RotateDeviceTo(90 /* landscape primary */); | |
| 950 ASSERT_TRUE(Video().IsFullscreen()); | |
| 951 CheckStatePendingFullscreen(); | |
| 952 EXPECT_FALSE(DelegateWillUnlockFullscreen()); | |
| 953 | |
| 954 // Simulate user rotating their device to portrait triggering a screen | |
| 955 // orientation change. | |
| 956 ASSERT_NO_FATAL_FAILURE( | |
| 957 RotateScreenTo(kWebScreenOrientationPortraitPrimary, 0)); | |
| 958 | |
| 959 // MediaControlsRotateToFullscreenDelegate should exit fullscreen. | |
| 960 EXPECT_FALSE(Video().IsFullscreen()); | |
| 961 | |
| 962 // MediaControlsOrientationLockDelegate should remain unlocked. | |
| 963 CheckStatePendingFullscreen(); | |
| 964 EXPECT_FALSE(DelegateWillUnlockFullscreen()); | |
| 965 } | |
| 966 | |
| 967 TEST_F(MediaControlsOrientationLockAndRotateToFullscreenDelegateTest, | |
| 968 LandscapeFullscreenBackToLandscapeInline) { | |
| 969 // Naturally portrait device, initially landscape, with landscape video. | |
| 970 natural_orientation_is_portrait_ = true; | |
| 971 ASSERT_NO_FATAL_FAILURE( | |
| 972 RotateScreenTo(kWebScreenOrientationLandscapePrimary, 90)); | |
| 973 InitVideo(640, 480); | |
| 974 SetIsAutoRotateEnabledByUser(true); | |
| 975 | |
| 976 // Initially fullscreen, unlocked orientation. | |
| 977 SimulateEnterFullscreen(); | |
| 978 RotateDeviceTo(90 /* landscape primary */); | |
| 979 ASSERT_TRUE(Video().IsFullscreen()); | |
| 980 CheckStatePendingFullscreen(); | |
| 981 EXPECT_FALSE(DelegateWillUnlockFullscreen()); | |
| 982 | |
| 983 // Simulate user clicking on media controls exit fullscreen button. | |
| 984 // orientation lock). | |
| 985 SimulateExitFullscreen(); | |
| 986 EXPECT_FALSE(Video().IsFullscreen()); | |
| 987 | |
| 988 // MediaControlsOrientationLockDelegate should remain unlocked. | |
| 989 CheckStatePendingFullscreen(); | |
| 990 EXPECT_FALSE(DelegateWillUnlockFullscreen()); | |
| 991 } | |
| 992 | |
| 993 TEST_F( | |
| 994 MediaControlsOrientationLockAndRotateToFullscreenDelegateTest, | |
| 995 AutoRotateDisabledPortraitInlineButtonToPortraitLockedLandscapeFullscreen) { | |
| 996 // Naturally portrait device, initially portrait, with landscape video. | |
| 997 natural_orientation_is_portrait_ = true; | |
| 998 ASSERT_NO_FATAL_FAILURE( | |
| 999 RotateScreenTo(kWebScreenOrientationPortraitPrimary, 0)); | |
| 1000 InitVideo(640, 480); | |
| 1001 // But this time the user has disabled auto rotate, e.g. locked to portrait. | |
| 1002 SetIsAutoRotateEnabledByUser(false); | |
| 1003 | |
| 1004 // Initially inline, unlocked orientation. | |
| 1005 ASSERT_FALSE(Video().IsFullscreen()); | |
| 1006 CheckStatePendingFullscreen(); | |
| 1007 ASSERT_FALSE(DelegateWillUnlockFullscreen()); | |
| 1008 | |
| 1009 // Simulate user clicking on media controls fullscreen button. | |
| 1010 SimulateEnterFullscreen(); | |
| 1011 EXPECT_TRUE(Video().IsFullscreen()); | |
| 1012 | |
| 1013 // MediaControlsOrientationLockDelegate should lock to landscape. | |
| 1014 CheckStateMaybeLockedFullscreen(); | |
| 1015 EXPECT_EQ(kWebScreenOrientationLockLandscape, DelegateOrientationLock()); | |
| 1016 | |
| 1017 // This will trigger a screen orientation change to landscape, since the app's | |
| 1018 // lock overrides the user's orientation lock (at least on Android). | |
| 1019 ASSERT_NO_FATAL_FAILURE( | |
| 1020 RotateScreenTo(kWebScreenOrientationLandscapePrimary, 90)); | |
| 1021 | |
| 1022 // Even though the device is still held in portrait. | |
| 1023 RotateDeviceTo(0 /* portrait primary */); | |
| 1024 | |
| 1025 // MediaControlsOrientationLockDelegate should remain locked to landscape. | |
| 1026 CheckStateMaybeLockedFullscreen(); | |
| 1027 EXPECT_EQ(kWebScreenOrientationLockLandscape, DelegateOrientationLock()); | |
| 1028 } | |
| 1029 | |
| 1030 TEST_F( | |
| 1031 MediaControlsOrientationLockAndRotateToFullscreenDelegateTest, | |
| 1032 AutoRotateDisabledPortraitLockedLandscapeFullscreenRotateToLandscapeLockedLa ndscapeFullscreen) { | |
| 1033 // Naturally portrait device, initially portrait device orientation but locked | |
| 1034 // to landscape screen orientation, with landscape video. | |
| 1035 natural_orientation_is_portrait_ = true; | |
| 1036 ASSERT_NO_FATAL_FAILURE( | |
| 1037 RotateScreenTo(kWebScreenOrientationLandscapePrimary, 90)); | |
| 1038 InitVideo(640, 480); | |
| 1039 // But this time the user has disabled auto rotate, e.g. locked to portrait | |
| 1040 // (even though the app's landscape screen orientation lock overrides it). | |
| 1041 SetIsAutoRotateEnabledByUser(false); | |
| 1042 | |
| 1043 // Initially fullscreen, locked orientation. | |
| 1044 SimulateEnterFullscreen(); | |
| 1045 ASSERT_TRUE(Video().IsFullscreen()); | |
| 1046 CheckStateMaybeLockedFullscreen(); | |
| 1047 EXPECT_EQ(kWebScreenOrientationLockLandscape, DelegateOrientationLock()); | |
| 1048 | |
| 1049 // Simulate user rotating their device to landscape (matching the screen | |
| 1050 // orientation lock). | |
| 1051 RotateDeviceTo(90 /* landscape primary */); | |
| 1052 | |
| 1053 // MediaControlsOrientationLockDelegate should remain locked to landscape even | |
| 1054 // though the screen orientation is now landscape, since the user has disabled | |
| 1055 // auto rotate, so unlocking now would cause the device to return to the | |
| 1056 // portrait orientation. | |
| 1057 CheckStateMaybeLockedFullscreen(); | |
| 1058 EXPECT_EQ(kWebScreenOrientationLockLandscape, DelegateOrientationLock()); | |
| 1059 EXPECT_TRUE(Video().IsFullscreen()); | |
| 1060 } | |
| 1061 | |
| 1062 TEST_F( | |
| 1063 MediaControlsOrientationLockAndRotateToFullscreenDelegateTest, | |
| 1064 AutoRotateDisabledPortraitLockedLandscapeFullscreenBackToPortraitInline) { | |
| 1065 // Naturally portrait device, initially portrait device orientation but locked | |
| 1066 // to landscape screen orientation, with landscape video. | |
| 1067 natural_orientation_is_portrait_ = true; | |
| 1068 ASSERT_NO_FATAL_FAILURE( | |
| 1069 RotateScreenTo(kWebScreenOrientationLandscapePrimary, 90)); | |
| 1070 InitVideo(640, 480); | |
| 1071 // But this time the user has disabled auto rotate, e.g. locked to portrait | |
| 1072 // (even though the app's landscape screen orientation lock overrides it). | |
| 1073 SetIsAutoRotateEnabledByUser(false); | |
| 1074 | |
| 1075 // Initially fullscreen, locked orientation. | |
| 1076 SimulateEnterFullscreen(); | |
| 1077 ASSERT_TRUE(Video().IsFullscreen()); | |
| 1078 CheckStateMaybeLockedFullscreen(); | |
| 1079 EXPECT_EQ(kWebScreenOrientationLockLandscape, DelegateOrientationLock()); | |
| 1080 | |
| 1081 // Simulate user clicking on media controls exit fullscreen button. | |
| 1082 // orientation lock). | |
| 1083 SimulateExitFullscreen(); | |
| 1084 EXPECT_FALSE(Video().IsFullscreen()); | |
| 1085 | |
| 1086 // MediaControlsOrientationLockDelegate should unlock orientation. | |
| 1087 CheckStatePendingFullscreen(); | |
| 1088 EXPECT_FALSE(DelegateWillUnlockFullscreen()); | |
| 1089 | |
| 1090 // Play the video and make it visible, just to make sure | |
| 1091 // MediaControlsRotateToFullscreenDelegate doesn't react to the | |
| 1092 // orientationchange event. | |
| 1093 PlayVideo(); | |
| 1094 UpdateVisibilityObserver(); | |
| 1095 | |
| 1096 // Unlocking the orientation earlier will trigger a screen orientation change | |
| 1097 // to portrait, since the user had locked the screen orientation to portrait, | |
| 1098 // (which happens to also match the device orientation) and | |
| 1099 // MediaControlsOrientationLockDelegate is no longer overriding that lock. | |
| 1100 ASSERT_NO_FATAL_FAILURE( | |
| 1101 RotateScreenTo(kWebScreenOrientationPortraitPrimary, 0)); | |
| 1102 | |
| 1103 // Video should remain inline, unlocked. | |
| 1104 CheckStatePendingFullscreen(); | |
| 1105 EXPECT_FALSE(DelegateWillUnlockFullscreen()); | |
| 1106 EXPECT_FALSE(Video().IsFullscreen()); | |
| 1107 } | |
| 1108 | |
| 1109 TEST_F( | |
| 1110 MediaControlsOrientationLockAndRotateToFullscreenDelegateTest, | |
| 1111 AutoRotateDisabledLandscapeLockedLandscapeFullscreenRotateToPortraitLockedLa ndscapeFullscreen) { | |
| 1112 // Naturally portrait device, initially landscape device orientation yet also | |
| 1113 // locked to landscape screen orientation since the user had disabled auto | |
| 1114 // rotate, with landscape video. | |
| 1115 natural_orientation_is_portrait_ = true; | |
| 1116 ASSERT_NO_FATAL_FAILURE( | |
| 1117 RotateScreenTo(kWebScreenOrientationLandscapePrimary, 90)); | |
| 1118 InitVideo(640, 480); | |
| 1119 // The user has disabled auto rotate, e.g. locked to portrait (even though the | |
| 1120 // app's landscape screen orientation lock overrides it). | |
| 1121 SetIsAutoRotateEnabledByUser(false); | |
| 1122 | |
| 1123 // Initially fullscreen, locked orientation. | |
| 1124 SimulateEnterFullscreen(); | |
| 1125 ASSERT_TRUE(Video().IsFullscreen()); | |
| 1126 CheckStateMaybeLockedFullscreen(); | |
| 1127 EXPECT_EQ(kWebScreenOrientationLockLandscape, DelegateOrientationLock()); | |
| 1128 | |
| 1129 // Simulate user rotating their device to portrait (matching the user's | |
| 1130 // rotation lock, but perpendicular to MediaControlsOrientationLockDelegate's | |
| 1131 // screen orientation lock which overrides it). | |
| 1132 RotateDeviceTo(0 /* portrait primary */); | |
| 1133 | |
| 1134 // Video should remain locked and fullscreen. This may disappoint users who | |
| 1135 // expect MediaControlsRotateToFullscreenDelegate to let them always leave | |
| 1136 // fullscreen by rotating perpendicular to the video's orientation (i.e. | |
| 1137 // rotating to portrait for a landscape video), however in this specific case, | |
| 1138 // since the user disabled auto rotate at the OS level, it's likely that they | |
| 1139 // wish to be able to use their phone whilst their head is lying sideways on a | |
| 1140 // pillow (or similar), in which case it's essential to keep the fullscreen | |
| 1141 // orientation lock. | |
| 1142 CheckStateMaybeLockedFullscreen(); | |
| 1143 EXPECT_EQ(kWebScreenOrientationLockLandscape, DelegateOrientationLock()); | |
| 1144 EXPECT_TRUE(Video().IsFullscreen()); | |
| 1145 } | |
| 1146 | |
| 1147 TEST_F( | |
| 1148 MediaControlsOrientationLockAndRotateToFullscreenDelegateTest, | |
| 1149 AutoRotateDisabledLandscapeLockedLandscapeFullscreenBackToPortraitInline) { | |
| 1150 // Naturally portrait device, initially landscape device orientation yet also | |
| 1151 // locked to landscape screen orientation since the user had disabled auto | |
| 1152 // rotate, with landscape video. | |
| 1153 natural_orientation_is_portrait_ = true; | |
| 1154 ASSERT_NO_FATAL_FAILURE( | |
| 1155 RotateScreenTo(kWebScreenOrientationLandscapePrimary, 90)); | |
| 1156 InitVideo(640, 480); | |
| 1157 // The user has disabled auto rotate, e.g. locked to portrait (even though the | |
| 1158 // app's landscape screen orientation lock overrides it). | |
| 1159 SetIsAutoRotateEnabledByUser(false); | |
| 1160 | |
| 1161 // Initially fullscreen, locked orientation. | |
| 1162 SimulateEnterFullscreen(); | |
| 1163 ASSERT_TRUE(Video().IsFullscreen()); | |
| 1164 CheckStateMaybeLockedFullscreen(); | |
| 1165 EXPECT_EQ(kWebScreenOrientationLockLandscape, DelegateOrientationLock()); | |
| 1166 | |
| 1167 // Simulate user clicking on media controls exit fullscreen button. | |
| 1168 // orientation lock). | |
| 1169 SimulateExitFullscreen(); | |
| 1170 EXPECT_FALSE(Video().IsFullscreen()); | |
| 1171 | |
| 1172 // MediaControlsOrientationLockDelegate should unlock orientation. | |
| 1173 CheckStatePendingFullscreen(); | |
| 1174 EXPECT_FALSE(DelegateWillUnlockFullscreen()); | |
| 1175 | |
| 1176 // Play the video and make it visible, just to make sure | |
| 1177 // MediaControlsRotateToFullscreenDelegate doesn't react to the | |
| 1178 // orientationchange event. | |
| 1179 PlayVideo(); | |
| 1180 UpdateVisibilityObserver(); | |
| 1181 | |
| 1182 // Unlocking the orientation earlier will trigger a screen orientation change | |
| 1183 // to portrait even though the device orientation is landscape, since the user | |
| 1184 // had locked the screen orientation to portrait, and | |
| 1185 // MediaControlsOrientationLockDelegate is no longer overriding that. | |
| 1186 ASSERT_NO_FATAL_FAILURE( | |
| 1187 RotateScreenTo(kWebScreenOrientationPortraitPrimary, 0)); | |
| 1188 | |
| 1189 // Video should remain inline, unlocked. | |
| 1190 CheckStatePendingFullscreen(); | |
| 1191 EXPECT_FALSE(DelegateWillUnlockFullscreen()); | |
| 1192 EXPECT_FALSE(Video().IsFullscreen()); | |
| 1193 } | |
| 1194 | |
| 1195 TEST_F(MediaControlsOrientationLockAndRotateToFullscreenDelegateTest, | |
| 1196 PortraitVideoRotateEnterExit) { | |
| 1197 // Naturally portrait device, initially landscape, with *portrait* video. | |
| 1198 natural_orientation_is_portrait_ = true; | |
| 1199 ASSERT_NO_FATAL_FAILURE( | |
| 1200 RotateScreenTo(kWebScreenOrientationLandscapePrimary, 90)); | |
| 1201 InitVideo(480, 640); | |
| 1202 SetIsAutoRotateEnabledByUser(true); | |
| 1203 PlayVideo(); | |
| 1204 UpdateVisibilityObserver(); | |
| 1205 | |
| 1206 // Initially inline, unlocked orientation. | |
| 1207 ASSERT_FALSE(Video().IsFullscreen()); | |
| 1208 CheckStatePendingFullscreen(); | |
| 1209 ASSERT_FALSE(DelegateWillUnlockFullscreen()); | |
| 1210 | |
| 1211 // Simulate user rotating their device to portrait triggering a screen | |
| 1212 // orientation change. | |
| 1213 ASSERT_NO_FATAL_FAILURE( | |
| 1214 RotateScreenTo(kWebScreenOrientationPortraitPrimary, 0)); | |
| 1215 | |
| 1216 // MediaControlsRotateToFullscreenDelegate should enter fullscreen, so | |
| 1217 // MediaControlsOrientationLockDelegate should lock orientation to portrait | |
| 1218 // (even though the screen is already portrait). | |
| 1219 EXPECT_TRUE(Video().IsFullscreen()); | |
| 1220 CheckStateMaybeLockedFullscreen(); | |
| 1221 EXPECT_EQ(kWebScreenOrientationLockPortrait, DelegateOrientationLock()); | |
| 1222 | |
| 1223 // Device orientation events received by MediaControlsOrientationLockDelegate | |
| 1224 // will confirm that the device is already portrait. | |
| 1225 RotateDeviceTo(0 /* portrait primary */); | |
| 1226 | |
| 1227 // MediaControlsOrientationLockDelegate should unlock orientation. | |
| 1228 CheckStatePendingFullscreen(); | |
| 1229 EXPECT_FALSE(DelegateWillUnlockFullscreen()); | |
| 1230 EXPECT_TRUE(Video().IsFullscreen()); | |
| 1231 | |
| 1232 // Simulate user rotating their device to landscape triggering a screen | |
| 1233 // orientation change. | |
| 1234 ASSERT_NO_FATAL_FAILURE( | |
| 1235 RotateScreenTo(kWebScreenOrientationLandscapePrimary, 90)); | |
| 1236 | |
| 1237 // MediaControlsRotateToFullscreenDelegate should exit fullscreen. | |
| 1238 EXPECT_FALSE(Video().IsFullscreen()); | |
| 1239 | |
| 1240 // MediaControlsOrientationLockDelegate should remain unlocked. | |
| 1241 CheckStatePendingFullscreen(); | |
| 1242 EXPECT_FALSE(DelegateWillUnlockFullscreen()); | |
| 1243 } | |
| 1244 | |
| 1245 TEST_F(MediaControlsOrientationLockAndRotateToFullscreenDelegateTest, | |
| 1246 LandscapeDeviceRotateEnterExit) { | |
| 1247 // Naturally *landscape* device, initially portrait, with landscape video. | |
| 1248 natural_orientation_is_portrait_ = false; | |
| 1249 ASSERT_NO_FATAL_FAILURE( | |
| 1250 RotateScreenTo(kWebScreenOrientationPortraitPrimary, 270)); | |
| 1251 InitVideo(640, 480); | |
| 1252 SetIsAutoRotateEnabledByUser(true); | |
| 1253 PlayVideo(); | |
| 1254 UpdateVisibilityObserver(); | |
| 1255 | |
| 1256 // Initially inline, unlocked orientation. | |
| 1257 ASSERT_FALSE(Video().IsFullscreen()); | |
| 1258 CheckStatePendingFullscreen(); | |
| 1259 ASSERT_FALSE(DelegateWillUnlockFullscreen()); | |
| 1260 | |
| 1261 // Simulate user rotating their device to landscape triggering a screen | |
| 1262 // orientation change. | |
| 1263 ASSERT_NO_FATAL_FAILURE( | |
| 1264 RotateScreenTo(kWebScreenOrientationLandscapePrimary, 0)); | |
| 1265 | |
| 1266 // MediaControlsRotateToFullscreenDelegate should enter fullscreen, so | |
| 1267 // MediaControlsOrientationLockDelegate should lock orientation to landscape | |
| 1268 // (even though the screen is already landscape). | |
| 1269 EXPECT_TRUE(Video().IsFullscreen()); | |
| 1270 CheckStateMaybeLockedFullscreen(); | |
| 1271 EXPECT_EQ(kWebScreenOrientationLockLandscape, DelegateOrientationLock()); | |
| 1272 | |
| 1273 // Device orientation events received by MediaControlsOrientationLockDelegate | |
| 1274 // will confirm that the device is already landscape. | |
| 1275 RotateDeviceTo(0 /* landscape primary */); | |
| 1276 | |
| 1277 // MediaControlsOrientationLockDelegate should unlock orientation. | |
| 1278 CheckStatePendingFullscreen(); | |
| 1279 EXPECT_FALSE(DelegateWillUnlockFullscreen()); | |
| 1280 EXPECT_TRUE(Video().IsFullscreen()); | |
| 1281 | |
| 1282 // Simulate user rotating their device to portrait triggering a screen | |
| 1283 // orientation change. | |
| 1284 ASSERT_NO_FATAL_FAILURE( | |
| 1285 RotateScreenTo(kWebScreenOrientationPortraitPrimary, 270)); | |
| 1286 | |
| 1287 // MediaControlsRotateToFullscreenDelegate should exit fullscreen. | |
| 1288 EXPECT_FALSE(Video().IsFullscreen()); | |
| 1289 | |
| 1290 // MediaControlsOrientationLockDelegate should remain unlocked. | |
| 1291 CheckStatePendingFullscreen(); | |
| 1292 EXPECT_FALSE(DelegateWillUnlockFullscreen()); | |
| 1293 } | |
| 1294 | |
| 405 } // namespace blink | 1295 } // namespace blink |
| OLD | NEW |