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