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 content::kAboutBlankURL
;
26 using content::WebContents
;
27 using content::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(IsFullscreenForTabOrPending(), 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(kAboutBlankURL
), PAGE_TRANSITION_TYPED
);
186 ASSERT_NO_FATAL_FAILURE(ToggleTabFullscreen(true));
189 FullscreenNotificationObserver fullscreen_observer
;
190 AddTabAtIndex(1, GURL(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(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(kAboutBlankURL
), PAGE_TRANSITION_TYPED
);
216 AddTabAtIndex(1, GURL(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(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(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(IsFullscreenForTabOrPending());
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(IsFullscreenForTabOrPending());
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(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(IsFullscreenForTabOrPending());
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(IsFullscreenForTabOrPending());
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(IsFullscreenForTabOrPending());
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(IsFullscreenForTabOrPending());
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(IsFullscreenForTabOrPending());
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(IsFullscreenForTabOrPending());
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(IsFullscreenForTabOrPending());
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(IsFullscreenForTabOrPending());
621 // Accept both, confirm they are enabled and there is no prompt.
622 AcceptCurrentFullscreenOrMouseLockRequest();
623 ASSERT_TRUE(IsMouseLocked());
624 ASSERT_TRUE(IsFullscreenForTabOrPending());
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_TRUE(IsFullscreenBubbleDisplayed());
652 ASSERT_FALSE(IsFullscreenPermissionRequested());
653 ASSERT_FALSE(IsMouseLockPermissionRequested());
654 ASSERT_TRUE(IsMouseLocked());
655 ASSERT_TRUE(IsFullscreenForTabOrPending());
658 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(USE_AURA)
659 // TODO(erg): linux_aura bringup: http://crbug.com/163931
660 #define MAYBE_MouseLockSilentAfterTargetUnlock \
661 DISABLED_MouseLockSilentAfterTargetUnlock
663 #define MAYBE_MouseLockSilentAfterTargetUnlock MouseLockSilentAfterTargetUnlock
666 // Tests mouse lock can be exited and re-entered by an application silently
667 // with no UI distraction for users.
668 IN_PROC_BROWSER_TEST_F(FullscreenControllerInteractiveTest
,
669 MAYBE_MouseLockSilentAfterTargetUnlock
) {
670 ASSERT_TRUE(test_server()->Start());
671 ui_test_utils::NavigateToURL(browser(),
672 test_server()->GetURL(kFullscreenMouseLockHTML
));
674 ASSERT_FALSE(IsFullscreenBubbleDisplayed());
676 // Lock the mouse with a user gesture.
677 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait(
678 browser(), ui::VKEY_1
, false, false, false, false,
679 chrome::NOTIFICATION_MOUSE_LOCK_CHANGED
,
680 content::NotificationService::AllSources()));
681 ASSERT_TRUE(IsFullscreenBubbleDisplayed());
682 ASSERT_TRUE(IsMouseLockPermissionRequested());
683 ASSERT_FALSE(IsMouseLocked());
685 // Accept mouse lock.
686 AcceptCurrentFullscreenOrMouseLockRequest();
687 ASSERT_TRUE(IsMouseLocked());
688 ASSERT_TRUE(IsFullscreenBubbleDisplayed());
690 // Unlock the mouse from target, make sure it's unlocked.
691 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait(
692 browser(), ui::VKEY_U
, false, false, false, false,
693 chrome::NOTIFICATION_MOUSE_LOCK_CHANGED
,
694 content::NotificationService::AllSources()));
695 ASSERT_FALSE(IsMouseLocked());
696 ASSERT_FALSE(IsFullscreenBubbleDisplayed());
698 // Lock mouse again, make sure it works with no bubble.
699 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait(
700 browser(), ui::VKEY_1
, false, false, false, false,
701 chrome::NOTIFICATION_MOUSE_LOCK_CHANGED
,
702 content::NotificationService::AllSources()));
703 ASSERT_TRUE(IsMouseLocked());
704 ASSERT_FALSE(IsFullscreenBubbleDisplayed());
706 // Unlock the mouse again by target.
707 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait(
708 browser(), ui::VKEY_U
, false, false, false, false,
709 chrome::NOTIFICATION_MOUSE_LOCK_CHANGED
,
710 content::NotificationService::AllSources()));
711 ASSERT_FALSE(IsMouseLocked());
713 // Lock from target, not user gesture, make sure it works.
714 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait(
715 browser(), ui::VKEY_D
, false, false, false, false,
716 chrome::NOTIFICATION_MOUSE_LOCK_CHANGED
,
717 content::NotificationService::AllSources()));
718 ASSERT_TRUE(IsMouseLocked());
719 ASSERT_FALSE(IsFullscreenBubbleDisplayed());
722 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait(
723 browser(), ui::VKEY_ESCAPE
, false, false, false, false,
724 chrome::NOTIFICATION_MOUSE_LOCK_CHANGED
,
725 content::NotificationService::AllSources()));
726 ASSERT_FALSE(IsMouseLocked());
728 // Lock the mouse with a user gesture, make sure we see bubble again.
729 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait(
730 browser(), ui::VKEY_1
, false, false, false, false,
731 chrome::NOTIFICATION_MOUSE_LOCK_CHANGED
,
732 content::NotificationService::AllSources()));
733 ASSERT_TRUE(IsFullscreenBubbleDisplayed());
734 ASSERT_TRUE(IsMouseLocked());
737 #if defined(OS_WIN) || \
738 (defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(USE_AURA))
739 // These tests are very flaky on Vista.
740 // http://crbug.com/158762
741 // These are flaky on linux_aura.
742 // http://crbug.com/163931
743 #define MAYBE_TestTabExitsMouseLockOnNavigation \
744 DISABLED_TestTabExitsMouseLockOnNavigation
745 #define MAYBE_TestTabExitsMouseLockOnGoBack \
746 DISABLED_TestTabExitsMouseLockOnGoBack
748 #define MAYBE_TestTabExitsMouseLockOnNavigation \
749 TestTabExitsMouseLockOnNavigation
750 #define MAYBE_TestTabExitsMouseLockOnGoBack \
751 TestTabExitsMouseLockOnGoBack
754 // Tests mouse lock is exited on page navigation.
755 IN_PROC_BROWSER_TEST_F(FullscreenControllerInteractiveTest
,
756 MAYBE_TestTabExitsMouseLockOnNavigation
) {
757 ASSERT_TRUE(test_server()->Start());
758 ui_test_utils::NavigateToURL(browser(),
759 test_server()->GetURL(kFullscreenMouseLockHTML
));
761 // Lock the mouse with a user gesture.
762 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait(
763 browser(), ui::VKEY_1
, false, false, false, false,
764 chrome::NOTIFICATION_MOUSE_LOCK_CHANGED
,
765 content::NotificationService::AllSources()));
766 ASSERT_TRUE(IsFullscreenBubbleDisplayed());
767 ASSERT_TRUE(IsMouseLockPermissionRequested());
768 ASSERT_FALSE(IsMouseLocked());
770 // Accept mouse lock.
771 AcceptCurrentFullscreenOrMouseLockRequest();
772 ASSERT_TRUE(IsMouseLocked());
774 ui_test_utils::NavigateToURL(browser(), GURL("chrome://newtab"));
776 ASSERT_FALSE(IsMouseLocked());
779 // Tests mouse lock is exited when navigating back.
780 IN_PROC_BROWSER_TEST_F(FullscreenControllerInteractiveTest
,
781 MAYBE_TestTabExitsMouseLockOnGoBack
) {
782 ASSERT_TRUE(test_server()->Start());
784 // Navigate twice to provide a place to go back to.
785 ui_test_utils::NavigateToURL(browser(), GURL("about:blank"));
786 ui_test_utils::NavigateToURL(browser(),
787 test_server()->GetURL(kFullscreenMouseLockHTML
));
789 // Lock the mouse with a user gesture.
790 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait(
791 browser(), ui::VKEY_1
, false, false, false, false,
792 chrome::NOTIFICATION_MOUSE_LOCK_CHANGED
,
793 content::NotificationService::AllSources()));
794 ASSERT_TRUE(IsFullscreenBubbleDisplayed());
795 ASSERT_TRUE(IsMouseLockPermissionRequested());
796 ASSERT_FALSE(IsMouseLocked());
798 // Accept mouse lock.
799 AcceptCurrentFullscreenOrMouseLockRequest();
800 ASSERT_TRUE(IsMouseLocked());
804 ASSERT_FALSE(IsMouseLocked());
807 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(USE_AURA)
808 // TODO(erg): linux_aura bringup: http://crbug.com/163931
809 #define MAYBE_TestTabDoesntExitMouseLockOnSubFrameNavigation DISABLED_TestTabDoesntExitMouseLockOnSubFrameNavigation
811 #define MAYBE_TestTabDoesntExitMouseLockOnSubFrameNavigation TestTabDoesntExitMouseLockOnSubFrameNavigation
814 // Tests mouse lock is not exited on sub frame navigation.
815 IN_PROC_BROWSER_TEST_F(FullscreenControllerInteractiveTest
,
816 MAYBE_TestTabDoesntExitMouseLockOnSubFrameNavigation
) {
817 ASSERT_TRUE(test_server()->Start());
819 // Create URLs for test page and test page with #fragment.
820 GURL
url(test_server()->GetURL(kFullscreenMouseLockHTML
));
821 GURL
url_with_fragment(url
.spec() + "#fragment");
823 // Navigate to test page.
824 ui_test_utils::NavigateToURL(browser(), url
);
826 // Lock the mouse with a user gesture.
827 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait(
828 browser(), ui::VKEY_1
, false, false, false, false,
829 chrome::NOTIFICATION_MOUSE_LOCK_CHANGED
,
830 content::NotificationService::AllSources()));
831 ASSERT_TRUE(IsFullscreenBubbleDisplayed());
832 ASSERT_TRUE(IsMouseLockPermissionRequested());
833 ASSERT_FALSE(IsMouseLocked());
835 // Accept mouse lock.
836 AcceptCurrentFullscreenOrMouseLockRequest();
837 ASSERT_TRUE(IsMouseLocked());
839 // Navigate to url with fragment. Mouse lock should persist.
840 ui_test_utils::NavigateToURL(browser(), url_with_fragment
);
841 ASSERT_TRUE(IsMouseLocked());
844 // Tests Mouse Lock and Fullscreen are exited upon reload.
845 // http://crbug.com/137486
846 // mac: http://crbug.com/103912
847 IN_PROC_BROWSER_TEST_F(FullscreenControllerInteractiveTest
,
848 DISABLED_ReloadExitsMouseLockAndFullscreen
) {
849 ASSERT_TRUE(test_server()->Start());
850 ui_test_utils::NavigateToURL(browser(),
851 test_server()->GetURL(kFullscreenMouseLockHTML
));
853 ASSERT_FALSE(IsMouseLockPermissionRequested());
855 // Request mouse lock.
856 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait(
857 browser(), ui::VKEY_1
, false, false, false, false,
858 chrome::NOTIFICATION_MOUSE_LOCK_CHANGED
,
859 content::NotificationService::AllSources()));
860 ASSERT_TRUE(IsMouseLockPermissionRequested());
862 // Reload. Mouse lock request should be cleared.
864 MouseLockNotificationObserver mouselock_observer
;
866 mouselock_observer
.Wait();
867 ASSERT_FALSE(IsMouseLockPermissionRequested());
870 // Request mouse lock.
871 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait(
872 browser(), ui::VKEY_1
, false, false, false, false,
873 chrome::NOTIFICATION_MOUSE_LOCK_CHANGED
,
874 content::NotificationService::AllSources()));
875 ASSERT_TRUE(IsMouseLockPermissionRequested());
877 // Accept mouse lock.
878 AcceptCurrentFullscreenOrMouseLockRequest();
879 ASSERT_TRUE(IsMouseLocked());
880 ASSERT_TRUE(IsFullscreenBubbleDisplayed());
882 // Reload. Mouse should be unlocked.
884 MouseLockNotificationObserver mouselock_observer
;
886 mouselock_observer
.Wait();
887 ASSERT_FALSE(IsMouseLocked());
890 // Request to lock the mouse and enter fullscreen.
892 FullscreenNotificationObserver fullscreen_observer
;
893 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait(
894 browser(), ui::VKEY_B
, false, true, false, false,
895 chrome::NOTIFICATION_MOUSE_LOCK_CHANGED
,
896 content::NotificationService::AllSources()));
897 fullscreen_observer
.Wait();
900 // We are fullscreen.
901 ASSERT_TRUE(IsFullscreenForTabOrPending());
903 // Reload. Mouse should be unlocked and fullscreen exited.
905 FullscreenNotificationObserver fullscreen_observer
;
907 fullscreen_observer
.Wait();
908 ASSERT_FALSE(IsMouseLocked());
909 ASSERT_FALSE(IsFullscreenForTabOrPending());
913 // Tests ToggleFullscreenModeForTab always causes window to change.
914 // Test is flaky: http://crbug.com/146006
915 IN_PROC_BROWSER_TEST_F(FullscreenControllerInteractiveTest
,
916 DISABLED_ToggleFullscreenModeForTab
) {
917 // Most fullscreen tests run sharded in fullscreen_controller_browsertest.cc
918 // but flakiness required a while loop in
919 // FullscreenControllerTest::ToggleTabFullscreen. This test verifies that
920 // when running serially there is no flakiness.
921 // This test reproduces the same flow as
922 // TestFullscreenMouseLockContentSettings.
923 // http://crbug.com/133831
925 GURL url
= test_server()->GetURL("simple.html");
926 AddTabAtIndex(0, url
, PAGE_TRANSITION_TYPED
);
928 // Validate that going fullscreen for a URL defaults to asking permision.
929 ASSERT_FALSE(IsFullscreenPermissionRequested());
930 ASSERT_NO_FATAL_FAILURE(ToggleTabFullscreenNoRetries(true));
931 ASSERT_TRUE(IsFullscreenPermissionRequested());
932 ASSERT_NO_FATAL_FAILURE(ToggleTabFullscreenNoRetries(false));