Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(121)

Side by Side Diff: third_party/WebKit/Source/modules/media_controls/MediaControlsOrientationLockDelegateTest.cpp

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

Powered by Google App Engine
This is Rietveld 408576698