1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "build/build_config.h"
6 #include "chrome/browser/content_settings/host_content_settings_map.h"
7 #include "chrome/browser/fullscreen.h"
8 #include "chrome/browser/profiles/profile.h"
9 #include "chrome/browser/ui/browser.h"
10 #include "chrome/browser/ui/browser_commands.h"
11 #include "chrome/browser/ui/browser_window.h"
12 #include "chrome/browser/ui/fullscreen/fullscreen_controller_test.h"
13 #include "chrome/browser/ui/tabs/tab_strip_model.h"
14 #include "chrome/test/base/interactive_test_utils.h"
15 #include "chrome/test/base/ui_test_utils.h"
16 #include "content/public/browser/render_view_host.h"
17 #include "content/public/browser/render_widget_host_view.h"
18 #include "content/public/browser/web_contents.h"
19 #include "content/public/common/url_constants.h"
21 #if defined(OS_MACOSX)
22 #include "base/mac/mac_util.h"
25 using url::kAboutBlankURL
;
26 using content::WebContents
;
27 using ui::PAGE_TRANSITION_TYPED
;
31 const base::FilePath::CharType
* kSimpleFile
= FILE_PATH_LITERAL("simple.html");
35 class FullscreenControllerInteractiveTest
36 : public FullscreenControllerTest
{
39 // Tests that actually make the browser fullscreen have been flaky when
40 // run sharded, and so are restricted here to interactive ui tests.
41 void ToggleTabFullscreen(bool enter_fullscreen
);
42 void ToggleTabFullscreenNoRetries(bool enter_fullscreen
);
43 void ToggleBrowserFullscreen(bool enter_fullscreen
);
45 // IsMouseLocked verifies that the FullscreenController state believes
46 // the mouse is locked. This is possible only for tests that initiate
47 // mouse lock from a renderer process, and uses logic that tests that the
48 // browser has focus. Thus, this can only be used in interactive ui tests
49 // and not on sharded tests.
50 bool IsMouseLocked() {
51 // Verify that IsMouseLocked is consistent between the
52 // Fullscreen Controller and the Render View Host View.
53 EXPECT_TRUE(browser()->IsMouseLocked() ==
54 browser()->tab_strip_model()->GetActiveWebContents()->
55 GetRenderViewHost()->GetView()->IsMouseLocked());
56 return browser()->IsMouseLocked();
59 void TestFullscreenMouseLockContentSettings();
62 void ToggleTabFullscreen_Internal(bool enter_fullscreen
,
63 bool retry_until_success
);
66 void FullscreenControllerInteractiveTest::ToggleTabFullscreen(
67 bool enter_fullscreen
) {
68 ToggleTabFullscreen_Internal(enter_fullscreen
, true);
71 // |ToggleTabFullscreen| should not need to tolerate the transition failing.
72 // Most fullscreen tests run sharded in fullscreen_controller_browsertest.cc
73 // and some flakiness has occurred when calling |ToggleTabFullscreen|, so that
74 // method has been made robust by retrying if the transition fails.
75 // The root cause of that flakiness should still be tracked down, see
76 // http://crbug.com/133831. In the mean time, this method
77 // allows a fullscreen_controller_interactive_browsertest.cc test to verify
78 // that when running serially there is no flakiness in the transition.
79 void FullscreenControllerInteractiveTest::ToggleTabFullscreenNoRetries(
80 bool enter_fullscreen
) {
81 ToggleTabFullscreen_Internal(enter_fullscreen
, false);
84 void FullscreenControllerInteractiveTest::ToggleBrowserFullscreen(
85 bool enter_fullscreen
) {
86 ASSERT_EQ(browser()->window()->IsFullscreen(), !enter_fullscreen
);
87 FullscreenNotificationObserver fullscreen_observer
;
89 chrome::ToggleFullscreenMode(browser());
91 fullscreen_observer
.Wait();
92 ASSERT_EQ(browser()->window()->IsFullscreen(), enter_fullscreen
);
93 ASSERT_EQ(IsFullscreenForBrowser(), enter_fullscreen
);
96 // Helper method to be called by multiple tests.
97 // Tests Fullscreen and Mouse Lock with varying content settings ALLOW & BLOCK.
99 FullscreenControllerInteractiveTest::TestFullscreenMouseLockContentSettings() {
100 GURL url
= test_server()->GetURL("simple.html");
101 AddTabAtIndex(0, url
, PAGE_TRANSITION_TYPED
);
103 // Validate that going fullscreen for a URL defaults to asking permision.
104 ASSERT_FALSE(IsFullscreenPermissionRequested());
105 ASSERT_NO_FATAL_FAILURE(ToggleTabFullscreen(true));
106 ASSERT_TRUE(IsFullscreenPermissionRequested());
107 ASSERT_NO_FATAL_FAILURE(ToggleTabFullscreen(false));
109 // Add content setting to ALLOW fullscreen.
110 HostContentSettingsMap
* settings_map
=
111 browser()->profile()->GetHostContentSettingsMap();
112 ContentSettingsPattern pattern
=
113 ContentSettingsPattern::FromURL(url
);
114 settings_map
->SetContentSetting(
115 pattern
, ContentSettingsPattern::Wildcard(),
116 CONTENT_SETTINGS_TYPE_FULLSCREEN
, std::string(),
117 CONTENT_SETTING_ALLOW
);
119 // Now, fullscreen should not prompt for permission.
120 ASSERT_FALSE(IsFullscreenPermissionRequested());
121 ASSERT_NO_FATAL_FAILURE(ToggleTabFullscreen(true));
122 ASSERT_FALSE(IsFullscreenPermissionRequested());
124 // Leaving tab in fullscreen, now test mouse lock ALLOW:
126 // Validate that mouse lock defaults to asking permision.
127 ASSERT_FALSE(IsMouseLockPermissionRequested());
128 RequestToLockMouse(true, false);
129 ASSERT_TRUE(IsMouseLockPermissionRequested());
132 // Add content setting to ALLOW mouse lock.
133 settings_map
->SetContentSetting(
134 pattern
, ContentSettingsPattern::Wildcard(),
135 CONTENT_SETTINGS_TYPE_MOUSELOCK
, std::string(),
136 CONTENT_SETTING_ALLOW
);
138 // Now, mouse lock should not prompt for permission.
139 ASSERT_FALSE(IsMouseLockPermissionRequested());
140 RequestToLockMouse(true, false);
141 ASSERT_FALSE(IsMouseLockPermissionRequested());
144 // Leaving tab in fullscreen, now test mouse lock BLOCK:
146 // Add content setting to BLOCK mouse lock.
147 settings_map
->SetContentSetting(
148 pattern
, ContentSettingsPattern::Wildcard(),
149 CONTENT_SETTINGS_TYPE_MOUSELOCK
, std::string(),
150 CONTENT_SETTING_BLOCK
);
152 // Now, mouse lock should not be pending.
153 ASSERT_FALSE(IsMouseLockPermissionRequested());
154 RequestToLockMouse(true, false);
155 ASSERT_FALSE(IsMouseLockPermissionRequested());
158 void FullscreenControllerInteractiveTest::ToggleTabFullscreen_Internal(
159 bool enter_fullscreen
, bool retry_until_success
) {
160 WebContents
* tab
= browser()->tab_strip_model()->GetActiveWebContents();
162 FullscreenNotificationObserver fullscreen_observer
;
163 browser()->ToggleFullscreenModeForTab(tab
, enter_fullscreen
);
164 fullscreen_observer
.Wait();
165 // Repeat ToggleFullscreenModeForTab until the correct state is entered.
166 // This addresses flakiness on test bots running many fullscreen
167 // tests in parallel.
168 } while (retry_until_success
&&
169 !IsFullscreenForBrowser() &&
170 browser()->window()->IsFullscreen() != enter_fullscreen
);
171 ASSERT_EQ(IsWindowFullscreenForTabOrPending(), enter_fullscreen
);
172 if (!IsFullscreenForBrowser())
173 ASSERT_EQ(browser()->window()->IsFullscreen(), enter_fullscreen
);
176 // Tests ///////////////////////////////////////////////////////////////////////
178 // Tests that while in fullscreen creating a new tab will exit fullscreen.
179 // Test is flaky: http://crbug.com/146006
180 IN_PROC_BROWSER_TEST_F(FullscreenControllerInteractiveTest
,
181 DISABLED_TestNewTabExitsFullscreen
) {
182 ASSERT_TRUE(test_server()->Start());
184 AddTabAtIndex(0, GURL(url::kAboutBlankURL
), PAGE_TRANSITION_TYPED
);
186 ASSERT_NO_FATAL_FAILURE(ToggleTabFullscreen(true));
189 FullscreenNotificationObserver fullscreen_observer
;
190 AddTabAtIndex(1, GURL(url::kAboutBlankURL
), PAGE_TRANSITION_TYPED
);
191 fullscreen_observer
.Wait();
192 ASSERT_FALSE(browser()->window()->IsFullscreen());
196 // Tests a tab exiting fullscreen will bring the browser out of fullscreen.
197 // Test is flaky: http://crbug.com/146006
198 IN_PROC_BROWSER_TEST_F(FullscreenControllerInteractiveTest
,
199 DISABLED_TestTabExitsItselfFromFullscreen
) {
200 ASSERT_TRUE(test_server()->Start());
202 AddTabAtIndex(0, GURL(url::kAboutBlankURL
), PAGE_TRANSITION_TYPED
);
204 ASSERT_NO_FATAL_FAILURE(ToggleTabFullscreen(true));
205 ASSERT_NO_FATAL_FAILURE(ToggleTabFullscreen(false));
208 // Tests entering fullscreen and then requesting mouse lock results in
209 // buttons for the user, and that after confirming the buttons are dismissed.
210 // Test is flaky: http://crbug.com/146006
211 IN_PROC_BROWSER_TEST_F(FullscreenControllerInteractiveTest
,
212 DISABLED_TestFullscreenBubbleMouseLockState
) {
213 ASSERT_TRUE(test_server()->Start());
215 AddTabAtIndex(0, GURL(url::kAboutBlankURL
), PAGE_TRANSITION_TYPED
);
216 AddTabAtIndex(1, GURL(url::kAboutBlankURL
), PAGE_TRANSITION_TYPED
);
218 ASSERT_NO_FATAL_FAILURE(ToggleTabFullscreen(true));
220 // Request mouse lock and verify the bubble is waiting for user confirmation.
221 RequestToLockMouse(true, false);
222 ASSERT_TRUE(IsMouseLockPermissionRequested());
224 // Accept mouse lock and verify bubble no longer shows confirmation buttons.
225 AcceptCurrentFullscreenOrMouseLockRequest();
226 ASSERT_FALSE(IsFullscreenBubbleDisplayingButtons());
229 // Tests fullscreen and Mouse Lock with varying content settings ALLOW & BLOCK.
230 // http://crbug.com/146006
231 IN_PROC_BROWSER_TEST_F(FullscreenControllerInteractiveTest
,
232 DISABLED_FullscreenMouseLockContentSettings
) {
233 TestFullscreenMouseLockContentSettings();
236 // Tests fullscreen and Mouse Lock with varying content settings ALLOW & BLOCK,
237 // but with the browser initiated in fullscreen mode first.
238 // Test is flaky: http://crbug.com/103912, http://crbug.com/146006
239 IN_PROC_BROWSER_TEST_F(FullscreenControllerInteractiveTest
,
240 DISABLED_BrowserFullscreenMouseLockContentSettings
) {
241 // Enter browser fullscreen first.
242 ASSERT_NO_FATAL_FAILURE(ToggleBrowserFullscreen(true));
243 TestFullscreenMouseLockContentSettings();
244 ASSERT_NO_FATAL_FAILURE(ToggleBrowserFullscreen(false));
247 // Tests Fullscreen entered in Browser, then Tab mode, then exited via Browser.
248 // Test is flaky: http://crbug.com/146006
249 IN_PROC_BROWSER_TEST_F(FullscreenControllerInteractiveTest
,
250 DISABLED_BrowserFullscreenExit
) {
251 // Enter browser fullscreen.
252 ASSERT_NO_FATAL_FAILURE(ToggleBrowserFullscreen(true));
254 // Enter tab fullscreen.
255 AddTabAtIndex(0, GURL(url::kAboutBlankURL
), PAGE_TRANSITION_TYPED
);
256 ASSERT_NO_FATAL_FAILURE(ToggleTabFullscreen(true));
258 // Exit browser fullscreen.
259 ASSERT_NO_FATAL_FAILURE(ToggleBrowserFullscreen(false));
260 ASSERT_FALSE(browser()->window()->IsFullscreen());
263 // Tests Browser Fullscreen remains active after Tab mode entered and exited.
264 // Test is flaky: http://crbug.com/146006
265 IN_PROC_BROWSER_TEST_F(FullscreenControllerInteractiveTest
,
266 DISABLED_BrowserFullscreenAfterTabFSExit
) {
267 // Enter browser fullscreen.
268 ASSERT_NO_FATAL_FAILURE(ToggleBrowserFullscreen(true));
270 // Enter and then exit tab fullscreen.
271 AddTabAtIndex(0, GURL(url::kAboutBlankURL
), PAGE_TRANSITION_TYPED
);
272 ASSERT_NO_FATAL_FAILURE(ToggleTabFullscreen(true));
273 ASSERT_NO_FATAL_FAILURE(ToggleTabFullscreen(false));
275 // Verify browser fullscreen still active.
276 ASSERT_TRUE(IsFullscreenForBrowser());
279 // Tests fullscreen entered without permision prompt for file:// urls.
280 // Test is flaky: http://crbug.com/146006
281 IN_PROC_BROWSER_TEST_F(FullscreenControllerInteractiveTest
,
282 DISABLED_FullscreenFileURL
) {
283 ui_test_utils::NavigateToURL(
284 browser(), ui_test_utils::GetTestUrl(
285 base::FilePath(base::FilePath::kCurrentDirectory
),
286 base::FilePath(kSimpleFile
)));
288 // Validate that going fullscreen for a file does not ask permision.
289 ASSERT_FALSE(IsFullscreenPermissionRequested());
290 ASSERT_NO_FATAL_FAILURE(ToggleTabFullscreen(true));
291 ASSERT_FALSE(IsFullscreenPermissionRequested());
292 ASSERT_NO_FATAL_FAILURE(ToggleTabFullscreen(false));
295 // Tests fullscreen is exited on page navigation.
296 // Test is flaky: http://crbug.com/146006
297 IN_PROC_BROWSER_TEST_F(FullscreenControllerInteractiveTest
,
298 DISABLED_TestTabExitsFullscreenOnNavigation
) {
299 ASSERT_TRUE(test_server()->Start());
301 ui_test_utils::NavigateToURL(browser(), GURL("about:blank"));
302 ASSERT_NO_FATAL_FAILURE(ToggleTabFullscreen(true));
303 ui_test_utils::NavigateToURL(browser(), GURL("chrome://newtab"));
305 ASSERT_FALSE(browser()->window()->IsFullscreen());
308 // Tests fullscreen is exited when navigating back.
309 // Test is flaky: http://crbug.com/146006
310 IN_PROC_BROWSER_TEST_F(FullscreenControllerInteractiveTest
,
311 DISABLED_TestTabExitsFullscreenOnGoBack
) {
312 ASSERT_TRUE(test_server()->Start());
314 ui_test_utils::NavigateToURL(browser(), GURL("about:blank"));
315 ui_test_utils::NavigateToURL(browser(), GURL("chrome://newtab"));
317 ASSERT_NO_FATAL_FAILURE(ToggleTabFullscreen(true));
321 ASSERT_FALSE(browser()->window()->IsFullscreen());
324 // Tests fullscreen is not exited on sub frame navigation.
325 // Test is flaky: http://crbug.com/146006
326 IN_PROC_BROWSER_TEST_F(
327 FullscreenControllerInteractiveTest
,
328 DISABLED_TestTabDoesntExitFullscreenOnSubFrameNavigation
) {
329 ASSERT_TRUE(test_server()->Start());
331 GURL
url(ui_test_utils::GetTestUrl(base::FilePath(
332 base::FilePath::kCurrentDirectory
), base::FilePath(kSimpleFile
)));
333 GURL
url_with_fragment(url
.spec() + "#fragment");
335 ui_test_utils::NavigateToURL(browser(), url
);
336 ASSERT_NO_FATAL_FAILURE(ToggleTabFullscreen(true));
337 ui_test_utils::NavigateToURL(browser(), url_with_fragment
);
338 ASSERT_TRUE(IsWindowFullscreenForTabOrPending());
341 // Tests tab fullscreen exits, but browser fullscreen remains, on navigation.
342 // Test is flaky: http://crbug.com/146006
343 IN_PROC_BROWSER_TEST_F(
344 FullscreenControllerInteractiveTest
,
345 DISABLED_TestFullscreenFromTabWhenAlreadyInBrowserFullscreenWorks
) {
346 ASSERT_TRUE(test_server()->Start());
348 ui_test_utils::NavigateToURL(browser(), GURL("about:blank"));
349 ui_test_utils::NavigateToURL(browser(), GURL("chrome://newtab"));
351 ASSERT_NO_FATAL_FAILURE(ToggleBrowserFullscreen(true));
352 ASSERT_NO_FATAL_FAILURE(ToggleTabFullscreen(true));
356 ASSERT_TRUE(IsFullscreenForBrowser());
357 ASSERT_FALSE(IsWindowFullscreenForTabOrPending());
360 #if defined(OS_MACOSX)
361 // http://crbug.com/100467
362 IN_PROC_BROWSER_TEST_F(
363 FullscreenControllerTest
, DISABLED_TabEntersPresentationModeFromWindowed
) {
364 ASSERT_TRUE(test_server()->Start());
366 AddTabAtIndex(0, GURL(url::kAboutBlankURL
), PAGE_TRANSITION_TYPED
);
368 WebContents
* tab
= browser()->tab_strip_model()->GetActiveWebContents();
371 FullscreenNotificationObserver fullscreen_observer
;
372 EXPECT_FALSE(browser()->window()->IsFullscreen());
373 EXPECT_FALSE(browser()->window()->IsFullscreenWithChrome());
374 EXPECT_FALSE(browser()->window()->IsFullscreenWithoutChrome());
375 browser()->ToggleFullscreenModeForTab(tab
, true);
376 fullscreen_observer
.Wait();
377 EXPECT_TRUE(browser()->window()->IsFullscreen());
378 EXPECT_FALSE(browser()->window()->IsFullscreenWithChrome());
379 EXPECT_TRUE(browser()->window()->IsFullscreenWithoutChrome());
383 FullscreenNotificationObserver fullscreen_observer
;
384 chrome::ToggleFullscreenMode(browser());
385 fullscreen_observer
.Wait();
386 EXPECT_FALSE(browser()->window()->IsFullscreen());
387 EXPECT_FALSE(browser()->window()->IsFullscreenWithChrome());
388 EXPECT_FALSE(browser()->window()->IsFullscreenWithoutChrome());
391 if (chrome::mac::SupportsSystemFullscreen()) {
392 // Test that tab fullscreen mode doesn't make presentation mode the default
394 FullscreenNotificationObserver fullscreen_observer
;
395 chrome::ToggleFullscreenMode(browser());
396 fullscreen_observer
.Wait();
397 EXPECT_TRUE(browser()->window()->IsFullscreen());
398 EXPECT_TRUE(browser()->window()->IsFullscreenWithChrome());
399 EXPECT_FALSE(browser()->window()->IsFullscreenWithoutChrome());
404 // Tests mouse lock can be escaped with ESC key.
405 IN_PROC_BROWSER_TEST_F(FullscreenControllerInteractiveTest
, EscapingMouseLock
) {
406 ASSERT_TRUE(test_server()->Start());
407 ui_test_utils::NavigateToURL(browser(),
408 test_server()->GetURL(kFullscreenMouseLockHTML
));
410 ASSERT_FALSE(IsFullscreenBubbleDisplayed());
412 // Request to lock the mouse.
414 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait(
415 browser(), ui::VKEY_1
, false, false, false, false,
416 chrome::NOTIFICATION_MOUSE_LOCK_CHANGED
,
417 content::NotificationService::AllSources()));
419 ASSERT_FALSE(IsFullscreenPermissionRequested());
420 ASSERT_TRUE(IsMouseLockPermissionRequested());
422 // Escape, no prompts should remain.
423 SendEscapeToFullscreenController();
424 ASSERT_FALSE(IsFullscreenPermissionRequested());
425 ASSERT_FALSE(IsMouseLockPermissionRequested());
427 // Request to lock the mouse.
429 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait(
430 browser(), ui::VKEY_1
, false, false, false, false,
431 chrome::NOTIFICATION_MOUSE_LOCK_CHANGED
,
432 content::NotificationService::AllSources()));
434 ASSERT_FALSE(IsFullscreenPermissionRequested());
435 ASSERT_TRUE(IsMouseLockPermissionRequested());
437 // Accept mouse lock, confirm it and that there is no prompt.
438 AcceptCurrentFullscreenOrMouseLockRequest();
439 ASSERT_TRUE(IsMouseLocked());
440 ASSERT_FALSE(IsWindowFullscreenForTabOrPending());
441 ASSERT_FALSE(IsFullscreenPermissionRequested());
442 ASSERT_FALSE(IsMouseLockPermissionRequested());
444 // Escape, confirm we are out of mouse lock with no prompts.
445 SendEscapeToFullscreenController();
446 ASSERT_FALSE(IsMouseLocked());
447 ASSERT_FALSE(IsWindowFullscreenForTabOrPending());
448 ASSERT_FALSE(IsFullscreenPermissionRequested());
449 ASSERT_FALSE(IsMouseLockPermissionRequested());
452 // Tests mouse lock and fullscreen modes can be escaped with ESC key.
453 // Test is flaky: http://crbug.com/146006
454 IN_PROC_BROWSER_TEST_F(FullscreenControllerInteractiveTest
,
455 DISABLED_EscapingMouseLockAndFullscreen
) {
456 ASSERT_TRUE(test_server()->Start());
457 ui_test_utils::NavigateToURL(browser(),
458 test_server()->GetURL(kFullscreenMouseLockHTML
));
460 ASSERT_FALSE(IsFullscreenBubbleDisplayed());
462 // Request to lock the mouse and enter fullscreen.
464 FullscreenNotificationObserver fullscreen_observer
;
465 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait(
466 browser(), ui::VKEY_B
, false, true, false, false,
467 chrome::NOTIFICATION_MOUSE_LOCK_CHANGED
,
468 content::NotificationService::AllSources()));
469 fullscreen_observer
.Wait();
471 ASSERT_TRUE(IsFullscreenPermissionRequested());
472 ASSERT_TRUE(IsMouseLockPermissionRequested());
474 // Escape, no prompts should remain.
476 FullscreenNotificationObserver fullscreen_observer
;
477 SendEscapeToFullscreenController();
478 fullscreen_observer
.Wait();
480 ASSERT_FALSE(IsFullscreenPermissionRequested());
481 ASSERT_FALSE(IsMouseLockPermissionRequested());
483 // Request to lock the mouse and enter fullscreen.
485 FullscreenNotificationObserver fullscreen_observer
;
486 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait(
487 browser(), ui::VKEY_B
, false, true, false, false,
488 chrome::NOTIFICATION_MOUSE_LOCK_CHANGED
,
489 content::NotificationService::AllSources()));
490 fullscreen_observer
.Wait();
492 ASSERT_TRUE(IsFullscreenPermissionRequested());
493 ASSERT_TRUE(IsMouseLockPermissionRequested());
495 // Accept both, confirm mouse lock and fullscreen and no prompts.
496 AcceptCurrentFullscreenOrMouseLockRequest();
497 ASSERT_TRUE(IsMouseLocked());
498 ASSERT_TRUE(IsWindowFullscreenForTabOrPending());
499 ASSERT_FALSE(IsFullscreenPermissionRequested());
500 ASSERT_FALSE(IsMouseLockPermissionRequested());
502 // Escape, confirm we are out of mouse lock and fullscreen with no prompts.
504 FullscreenNotificationObserver fullscreen_observer
;
505 SendEscapeToFullscreenController();
506 fullscreen_observer
.Wait();
508 ASSERT_FALSE(IsMouseLocked());
509 ASSERT_FALSE(IsWindowFullscreenForTabOrPending());
510 ASSERT_FALSE(IsFullscreenPermissionRequested());
511 ASSERT_FALSE(IsMouseLockPermissionRequested());
514 // Tests mouse lock then fullscreen.
515 // Test is flaky: http://crbug.com/146006
516 IN_PROC_BROWSER_TEST_F(FullscreenControllerInteractiveTest
,
517 DISABLED_MouseLockThenFullscreen
) {
518 ASSERT_TRUE(test_server()->Start());
519 ui_test_utils::NavigateToURL(browser(),
520 test_server()->GetURL(kFullscreenMouseLockHTML
));
522 ASSERT_FALSE(IsFullscreenBubbleDisplayed());
524 // Lock the mouse without a user gesture, expect no response.
525 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait(
526 browser(), ui::VKEY_D
, false, false, false, false,
527 chrome::NOTIFICATION_MOUSE_LOCK_CHANGED
,
528 content::NotificationService::AllSources()));
529 ASSERT_FALSE(IsFullscreenBubbleDisplayed());
530 ASSERT_FALSE(IsMouseLocked());
532 // Lock the mouse with a user gesture.
533 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait(
534 browser(), ui::VKEY_1
, false, false, false, false,
535 chrome::NOTIFICATION_MOUSE_LOCK_CHANGED
,
536 content::NotificationService::AllSources()));
537 ASSERT_TRUE(IsFullscreenBubbleDisplayed());
538 ASSERT_FALSE(IsFullscreenPermissionRequested());
539 ASSERT_TRUE(IsMouseLockPermissionRequested());
540 ASSERT_FALSE(IsMouseLocked());
542 // Accept mouse lock.
543 AcceptCurrentFullscreenOrMouseLockRequest();
544 ASSERT_TRUE(IsMouseLocked());
545 ASSERT_FALSE(IsFullscreenBubbleDisplayingButtons());
547 // Enter fullscreen mode, mouse lock should be dropped to present buttons.
548 ASSERT_NO_FATAL_FAILURE(ToggleTabFullscreen(true));
549 ASSERT_TRUE(IsFullscreenPermissionRequested());
550 ASSERT_FALSE(IsMouseLockPermissionRequested());
551 ASSERT_FALSE(IsMouseLocked());
553 // Request mouse lock also, expect fullscreen and mouse lock buttons.
554 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait(
555 browser(), ui::VKEY_1
, false, false, false, false,
556 chrome::NOTIFICATION_MOUSE_LOCK_CHANGED
,
557 content::NotificationService::AllSources()));
558 ASSERT_TRUE(IsFullscreenPermissionRequested());
559 ASSERT_TRUE(IsMouseLockPermissionRequested());
560 ASSERT_FALSE(IsMouseLocked());
562 // Accept fullscreen and mouse lock.
563 AcceptCurrentFullscreenOrMouseLockRequest();
564 ASSERT_TRUE(IsMouseLocked());
565 ASSERT_TRUE(IsWindowFullscreenForTabOrPending());
566 ASSERT_FALSE(IsFullscreenBubbleDisplayingButtons());
569 // Times out sometimes on Linux. http://crbug.com/135115
570 // Mac: http://crbug.com/103912
571 // Windows: Failing flakily on try jobs also.
572 // Tests mouse lock then fullscreen in same request.
573 IN_PROC_BROWSER_TEST_F(FullscreenControllerInteractiveTest
,
574 DISABLED_MouseLockAndFullscreen
) {
575 ASSERT_TRUE(test_server()->Start());
576 ui_test_utils::NavigateToURL(browser(),
577 test_server()->GetURL(kFullscreenMouseLockHTML
));
579 ASSERT_FALSE(IsFullscreenBubbleDisplayed());
581 // Request to lock the mouse and enter fullscreen.
583 FullscreenNotificationObserver fullscreen_observer
;
584 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait(
585 browser(), ui::VKEY_B
, false, true, false, false,
586 chrome::NOTIFICATION_MOUSE_LOCK_CHANGED
,
587 content::NotificationService::AllSources()));
588 fullscreen_observer
.Wait();
590 ASSERT_TRUE(IsFullscreenBubbleDisplayed());
591 ASSERT_TRUE(IsFullscreenPermissionRequested());
592 ASSERT_TRUE(IsMouseLockPermissionRequested());
593 ASSERT_FALSE(IsMouseLocked());
594 ASSERT_TRUE(IsWindowFullscreenForTabOrPending());
596 // Deny both first, to make sure we can.
598 FullscreenNotificationObserver fullscreen_observer
;
599 DenyCurrentFullscreenOrMouseLockRequest();
600 fullscreen_observer
.Wait();
602 ASSERT_FALSE(IsMouseLocked());
603 ASSERT_FALSE(IsWindowFullscreenForTabOrPending());
604 ASSERT_FALSE(IsFullscreenPermissionRequested());
606 // Request to lock the mouse and enter fullscreen.
608 FullscreenNotificationObserver fullscreen_observer
;
609 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait(
610 browser(), ui::VKEY_B
, false, true, false, false,
611 chrome::NOTIFICATION_MOUSE_LOCK_CHANGED
,
612 content::NotificationService::AllSources()));
613 fullscreen_observer
.Wait();
615 ASSERT_TRUE(IsFullscreenBubbleDisplayed());
616 ASSERT_TRUE(IsFullscreenPermissionRequested());
617 ASSERT_TRUE(IsMouseLockPermissionRequested());
618 ASSERT_FALSE(IsMouseLocked());
619 ASSERT_TRUE(IsWindowFullscreenForTabOrPending());
621 // Accept both, confirm they are enabled and there is no prompt.
622 AcceptCurrentFullscreenOrMouseLockRequest();
623 ASSERT_TRUE(IsMouseLocked());
624 ASSERT_TRUE(IsWindowFullscreenForTabOrPending());
625 ASSERT_FALSE(IsFullscreenPermissionRequested());
628 // Tests mouse lock and fullscreen for the privileged fullscreen case (e.g.,
629 // embedded flash fullscreen, since the Flash plugin handles user permissions
631 // Test is flaky: http://crbug.com/146006
632 IN_PROC_BROWSER_TEST_F(FullscreenControllerInteractiveTest
,
633 DISABLED_PrivilegedMouseLockAndFullscreen
) {
634 ASSERT_TRUE(test_server()->Start());
635 ui_test_utils::NavigateToURL(browser(),
636 test_server()->GetURL(kFullscreenMouseLockHTML
));
638 ASSERT_FALSE(IsFullscreenBubbleDisplayed());
640 SetPrivilegedFullscreen(true);
642 // Request to lock the mouse and enter fullscreen.
643 FullscreenNotificationObserver fullscreen_observer
;
644 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait(
645 browser(), ui::VKEY_B
, false, true, false, false,
646 chrome::NOTIFICATION_MOUSE_LOCK_CHANGED
,
647 content::NotificationService::AllSources()));
648 fullscreen_observer
.Wait();
650 // Confirm they are enabled and there is no prompt.
651 ASSERT_FALSE(IsFullscreenBubbleDisplayed());
652 ASSERT_FALSE(IsFullscreenPermissionRequested());
653 ASSERT_FALSE(IsMouseLockPermissionRequested());
654 ASSERT_TRUE(IsMouseLocked());
655 ASSERT_TRUE(IsWindowFullscreenForTabOrPending());
658 // TODO(erg): linux_aura bringup: http://crbug.com/163931
659 // Flaky on Windows, Linux, CrOS: http://crbug.com/159000
660 #if defined(OS_WIN) || defined(OS_LINUX) || defined(OS_CHROMEOS)
661 #define MAYBE_MouseLockSilentAfterTargetUnlock \
662 DISABLED_MouseLockSilentAfterTargetUnlock
664 #define MAYBE_MouseLockSilentAfterTargetUnlock MouseLockSilentAfterTargetUnlock
667 // Tests mouse lock can be exited and re-entered by an application silently
668 // with no UI distraction for users.
669 IN_PROC_BROWSER_TEST_F(FullscreenControllerInteractiveTest
,
670 MAYBE_MouseLockSilentAfterTargetUnlock
) {
671 ASSERT_TRUE(test_server()->Start());
672 ui_test_utils::NavigateToURL(browser(),
673 test_server()->GetURL(kFullscreenMouseLockHTML
));
675 ASSERT_FALSE(IsFullscreenBubbleDisplayed());
677 // Lock the mouse with a user gesture.
678 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait(
679 browser(), ui::VKEY_1
, false, false, false, false,
680 chrome::NOTIFICATION_MOUSE_LOCK_CHANGED
,
681 content::NotificationService::AllSources()));
682 ASSERT_TRUE(IsFullscreenBubbleDisplayed());
683 ASSERT_TRUE(IsMouseLockPermissionRequested());
684 ASSERT_FALSE(IsMouseLocked());
686 // Accept mouse lock.
687 AcceptCurrentFullscreenOrMouseLockRequest();
688 ASSERT_TRUE(IsMouseLocked());
689 ASSERT_TRUE(IsFullscreenBubbleDisplayed());
691 // Unlock the mouse from target, make sure it's unlocked.
692 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait(
693 browser(), ui::VKEY_U
, false, false, false, false,
694 chrome::NOTIFICATION_MOUSE_LOCK_CHANGED
,
695 content::NotificationService::AllSources()));
696 ASSERT_FALSE(IsMouseLocked());
697 ASSERT_FALSE(IsFullscreenBubbleDisplayed());
699 // Lock mouse again, make sure it works with no bubble.
700 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait(
701 browser(), ui::VKEY_1
, false, false, false, false,
702 chrome::NOTIFICATION_MOUSE_LOCK_CHANGED
,
703 content::NotificationService::AllSources()));
704 ASSERT_TRUE(IsMouseLocked());
705 ASSERT_FALSE(IsFullscreenBubbleDisplayed());
707 // Unlock the mouse again by target.
708 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait(
709 browser(), ui::VKEY_U
, false, false, false, false,
710 chrome::NOTIFICATION_MOUSE_LOCK_CHANGED
,
711 content::NotificationService::AllSources()));
712 ASSERT_FALSE(IsMouseLocked());
714 // Lock from target, not user gesture, make sure it works.
715 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait(
716 browser(), ui::VKEY_D
, false, false, false, false,
717 chrome::NOTIFICATION_MOUSE_LOCK_CHANGED
,
718 content::NotificationService::AllSources()));
719 ASSERT_TRUE(IsMouseLocked());
720 ASSERT_FALSE(IsFullscreenBubbleDisplayed());
723 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait(
724 browser(), ui::VKEY_ESCAPE
, false, false, false, false,
725 chrome::NOTIFICATION_MOUSE_LOCK_CHANGED
,
726 content::NotificationService::AllSources()));
727 ASSERT_FALSE(IsMouseLocked());
729 // Lock the mouse with a user gesture, make sure we see bubble again.
730 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait(
731 browser(), ui::VKEY_1
, false, false, false, false,
732 chrome::NOTIFICATION_MOUSE_LOCK_CHANGED
,
733 content::NotificationService::AllSources()));
734 ASSERT_TRUE(IsFullscreenBubbleDisplayed());
735 ASSERT_TRUE(IsMouseLocked());
738 #if defined(OS_WIN) || \
739 (defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(USE_AURA))
740 // These tests are very flaky on Vista.
741 // http://crbug.com/158762
742 // These are flaky on linux_aura.
743 // http://crbug.com/163931
744 #define MAYBE_TestTabExitsMouseLockOnNavigation \
745 DISABLED_TestTabExitsMouseLockOnNavigation
746 #define MAYBE_TestTabExitsMouseLockOnGoBack \
747 DISABLED_TestTabExitsMouseLockOnGoBack
749 #define MAYBE_TestTabExitsMouseLockOnNavigation \
750 TestTabExitsMouseLockOnNavigation
751 #define MAYBE_TestTabExitsMouseLockOnGoBack \
752 TestTabExitsMouseLockOnGoBack
755 // Tests mouse lock is exited on page navigation.
756 IN_PROC_BROWSER_TEST_F(FullscreenControllerInteractiveTest
,
757 MAYBE_TestTabExitsMouseLockOnNavigation
) {
758 ASSERT_TRUE(test_server()->Start());
759 ui_test_utils::NavigateToURL(browser(),
760 test_server()->GetURL(kFullscreenMouseLockHTML
));
762 // Lock the mouse with a user gesture.
763 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait(
764 browser(), ui::VKEY_1
, false, false, false, false,
765 chrome::NOTIFICATION_MOUSE_LOCK_CHANGED
,
766 content::NotificationService::AllSources()));
767 ASSERT_TRUE(IsFullscreenBubbleDisplayed());
768 ASSERT_TRUE(IsMouseLockPermissionRequested());
769 ASSERT_FALSE(IsMouseLocked());
771 // Accept mouse lock.
772 AcceptCurrentFullscreenOrMouseLockRequest();
773 ASSERT_TRUE(IsMouseLocked());
775 ui_test_utils::NavigateToURL(browser(), GURL("chrome://newtab"));
777 ASSERT_FALSE(IsMouseLocked());
780 // Tests mouse lock is exited when navigating back.
781 IN_PROC_BROWSER_TEST_F(FullscreenControllerInteractiveTest
,
782 MAYBE_TestTabExitsMouseLockOnGoBack
) {
783 ASSERT_TRUE(test_server()->Start());
785 // Navigate twice to provide a place to go back to.
786 ui_test_utils::NavigateToURL(browser(), GURL("about:blank"));
787 ui_test_utils::NavigateToURL(browser(),
788 test_server()->GetURL(kFullscreenMouseLockHTML
));
790 // Lock the mouse with a user gesture.
791 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait(
792 browser(), ui::VKEY_1
, false, false, false, false,
793 chrome::NOTIFICATION_MOUSE_LOCK_CHANGED
,
794 content::NotificationService::AllSources()));
795 ASSERT_TRUE(IsFullscreenBubbleDisplayed());
796 ASSERT_TRUE(IsMouseLockPermissionRequested());
797 ASSERT_FALSE(IsMouseLocked());
799 // Accept mouse lock.
800 AcceptCurrentFullscreenOrMouseLockRequest();
801 ASSERT_TRUE(IsMouseLocked());
805 ASSERT_FALSE(IsMouseLocked());
808 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(USE_AURA)
809 // TODO(erg): linux_aura bringup: http://crbug.com/163931
810 #define MAYBE_TestTabDoesntExitMouseLockOnSubFrameNavigation DISABLED_TestTabDoesntExitMouseLockOnSubFrameNavigation
812 #define MAYBE_TestTabDoesntExitMouseLockOnSubFrameNavigation TestTabDoesntExitMouseLockOnSubFrameNavigation
815 // Tests mouse lock is not exited on sub frame navigation.
816 IN_PROC_BROWSER_TEST_F(FullscreenControllerInteractiveTest
,
817 MAYBE_TestTabDoesntExitMouseLockOnSubFrameNavigation
) {
818 ASSERT_TRUE(test_server()->Start());
820 // Create URLs for test page and test page with #fragment.
821 GURL
url(test_server()->GetURL(kFullscreenMouseLockHTML
));
822 GURL
url_with_fragment(url
.spec() + "#fragment");
824 // Navigate to test page.
825 ui_test_utils::NavigateToURL(browser(), url
);
827 // Lock the mouse with a user gesture.
828 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait(
829 browser(), ui::VKEY_1
, false, false, false, false,
830 chrome::NOTIFICATION_MOUSE_LOCK_CHANGED
,
831 content::NotificationService::AllSources()));
832 ASSERT_TRUE(IsFullscreenBubbleDisplayed());
833 ASSERT_TRUE(IsMouseLockPermissionRequested());
834 ASSERT_FALSE(IsMouseLocked());
836 // Accept mouse lock.
837 AcceptCurrentFullscreenOrMouseLockRequest();
838 ASSERT_TRUE(IsMouseLocked());
840 // Navigate to url with fragment. Mouse lock should persist.
841 ui_test_utils::NavigateToURL(browser(), url_with_fragment
);
842 ASSERT_TRUE(IsMouseLocked());
845 // Tests Mouse Lock and Fullscreen are exited upon reload.
846 // http://crbug.com/137486
847 // mac: http://crbug.com/103912
848 IN_PROC_BROWSER_TEST_F(FullscreenControllerInteractiveTest
,
849 DISABLED_ReloadExitsMouseLockAndFullscreen
) {
850 ASSERT_TRUE(test_server()->Start());
851 ui_test_utils::NavigateToURL(browser(),
852 test_server()->GetURL(kFullscreenMouseLockHTML
));
854 ASSERT_FALSE(IsMouseLockPermissionRequested());
856 // Request mouse lock.
857 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait(
858 browser(), ui::VKEY_1
, false, false, false, false,
859 chrome::NOTIFICATION_MOUSE_LOCK_CHANGED
,
860 content::NotificationService::AllSources()));
861 ASSERT_TRUE(IsMouseLockPermissionRequested());
863 // Reload. Mouse lock request should be cleared.
865 MouseLockNotificationObserver mouselock_observer
;
867 mouselock_observer
.Wait();
868 ASSERT_FALSE(IsMouseLockPermissionRequested());
871 // Request mouse lock.
872 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait(
873 browser(), ui::VKEY_1
, false, false, false, false,
874 chrome::NOTIFICATION_MOUSE_LOCK_CHANGED
,
875 content::NotificationService::AllSources()));
876 ASSERT_TRUE(IsMouseLockPermissionRequested());
878 // Accept mouse lock.
879 AcceptCurrentFullscreenOrMouseLockRequest();
880 ASSERT_TRUE(IsMouseLocked());
881 ASSERT_TRUE(IsFullscreenBubbleDisplayed());
883 // Reload. Mouse should be unlocked.
885 MouseLockNotificationObserver mouselock_observer
;
887 mouselock_observer
.Wait();
888 ASSERT_FALSE(IsMouseLocked());
891 // Request to lock the mouse and enter fullscreen.
893 FullscreenNotificationObserver fullscreen_observer
;
894 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait(
895 browser(), ui::VKEY_B
, false, true, false, false,
896 chrome::NOTIFICATION_MOUSE_LOCK_CHANGED
,
897 content::NotificationService::AllSources()));
898 fullscreen_observer
.Wait();
901 // We are fullscreen.
902 ASSERT_TRUE(IsWindowFullscreenForTabOrPending());
904 // Reload. Mouse should be unlocked and fullscreen exited.
906 FullscreenNotificationObserver fullscreen_observer
;
908 fullscreen_observer
.Wait();
909 ASSERT_FALSE(IsMouseLocked());
910 ASSERT_FALSE(IsWindowFullscreenForTabOrPending());
914 // Tests ToggleFullscreenModeForTab always causes window to change.
915 // Test is flaky: http://crbug.com/146006
916 IN_PROC_BROWSER_TEST_F(FullscreenControllerInteractiveTest
,
917 DISABLED_ToggleFullscreenModeForTab
) {
918 // Most fullscreen tests run sharded in fullscreen_controller_browsertest.cc
919 // but flakiness required a while loop in
920 // FullscreenControllerTest::ToggleTabFullscreen. This test verifies that
921 // when running serially there is no flakiness.
922 // This test reproduces the same flow as
923 // TestFullscreenMouseLockContentSettings.
924 // http://crbug.com/133831
926 GURL url
= test_server()->GetURL("simple.html");
927 AddTabAtIndex(0, url
, PAGE_TRANSITION_TYPED
);
929 // Validate that going fullscreen for a URL defaults to asking permision.
930 ASSERT_FALSE(IsFullscreenPermissionRequested());
931 ASSERT_NO_FATAL_FAILURE(ToggleTabFullscreenNoRetries(true));
932 ASSERT_TRUE(IsFullscreenPermissionRequested());
933 ASSERT_NO_FATAL_FAILURE(ToggleTabFullscreenNoRetries(false));