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