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. 4 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" 20 21 #if defined(OS_MACOSX) 22 #include "base/mac/mac_util.h" 23 #endif 24 25 using content::kAboutBlankURL; 26 using content::WebContents; 27 using content::PAGE_TRANSITION_TYPED; 28 29 namespace { 30 31 const base::FilePath::CharType* kSimpleFile = FILE_PATH_LITERAL("simple.html"); 32 33 } // namespace 34 35 class FullscreenControllerInteractiveTest 36 : public FullscreenControllerTest { 37 protected: 38 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); 44 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(); 57 } 58 59 void TestFullscreenMouseLockContentSettings(); 60 61 private: 62 void ToggleTabFullscreen_Internal(bool enter_fullscreen, 63 bool retry_until_success); 64 }; 65 66 void FullscreenControllerInteractiveTest::ToggleTabFullscreen( 67 bool enter_fullscreen) { 68 ToggleTabFullscreen_Internal(enter_fullscreen, true); 69 } 70 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); 82 } 83 84 void FullscreenControllerInteractiveTest::ToggleBrowserFullscreen( 85 bool enter_fullscreen) { 86 ASSERT_EQ(browser()->window()->IsFullscreen(), !enter_fullscreen); 87 FullscreenNotificationObserver fullscreen_observer; 88 89 chrome::ToggleFullscreenMode(browser()); 90 91 fullscreen_observer.Wait(); 92 ASSERT_EQ(browser()->window()->IsFullscreen(), enter_fullscreen); 93 ASSERT_EQ(IsFullscreenForBrowser(), enter_fullscreen); 94 } 95 96 // Helper method to be called by multiple tests. 97 // Tests Fullscreen and Mouse Lock with varying content settings ALLOW & BLOCK. 98 void 99 FullscreenControllerInteractiveTest::TestFullscreenMouseLockContentSettings() { 100 GURL url = test_server()->GetURL("simple.html"); 101 AddTabAtIndex(0, url, PAGE_TRANSITION_TYPED); 102 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)); 108 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); 118 119 // Now, fullscreen should not prompt for permission. 120 ASSERT_FALSE(IsFullscreenPermissionRequested()); 121 ASSERT_NO_FATAL_FAILURE(ToggleTabFullscreen(true)); 122 ASSERT_FALSE(IsFullscreenPermissionRequested()); 123 124 // Leaving tab in fullscreen, now test mouse lock ALLOW: 125 126 // Validate that mouse lock defaults to asking permision. 127 ASSERT_FALSE(IsMouseLockPermissionRequested()); 128 RequestToLockMouse(true, false); 129 ASSERT_TRUE(IsMouseLockPermissionRequested()); 130 LostMouseLock(); 131 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); 137 138 // Now, mouse lock should not prompt for permission. 139 ASSERT_FALSE(IsMouseLockPermissionRequested()); 140 RequestToLockMouse(true, false); 141 ASSERT_FALSE(IsMouseLockPermissionRequested()); 142 LostMouseLock(); 143 144 // Leaving tab in fullscreen, now test mouse lock BLOCK: 145 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); 151 152 // Now, mouse lock should not be pending. 153 ASSERT_FALSE(IsMouseLockPermissionRequested()); 154 RequestToLockMouse(true, false); 155 ASSERT_FALSE(IsMouseLockPermissionRequested()); 156 } 157 158 void FullscreenControllerInteractiveTest::ToggleTabFullscreen_Internal( 159 bool enter_fullscreen, bool retry_until_success) { 160 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents(); 161 do { 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); 174 } 175 176 // Tests /////////////////////////////////////////////////////////////////////// 177 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()); 183 184 AddTabAtIndex(0, GURL(kAboutBlankURL), PAGE_TRANSITION_TYPED); 185 186 ASSERT_NO_FATAL_FAILURE(ToggleTabFullscreen(true)); 187 188 { 189 FullscreenNotificationObserver fullscreen_observer; 190 AddTabAtIndex(1, GURL(kAboutBlankURL), PAGE_TRANSITION_TYPED); 191 fullscreen_observer.Wait(); 192 ASSERT_FALSE(browser()->window()->IsFullscreen()); 193 } 194 } 195 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()); 201 202 AddTabAtIndex(0, GURL(kAboutBlankURL), PAGE_TRANSITION_TYPED); 203 204 ASSERT_NO_FATAL_FAILURE(ToggleTabFullscreen(true)); 205 ASSERT_NO_FATAL_FAILURE(ToggleTabFullscreen(false)); 206 } 207 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()); 214 215 AddTabAtIndex(0, GURL(kAboutBlankURL), PAGE_TRANSITION_TYPED); 216 AddTabAtIndex(1, GURL(kAboutBlankURL), PAGE_TRANSITION_TYPED); 217 218 ASSERT_NO_FATAL_FAILURE(ToggleTabFullscreen(true)); 219 220 // Request mouse lock and verify the bubble is waiting for user confirmation. 221 RequestToLockMouse(true, false); 222 ASSERT_TRUE(IsMouseLockPermissionRequested()); 223 224 // Accept mouse lock and verify bubble no longer shows confirmation buttons. 225 AcceptCurrentFullscreenOrMouseLockRequest(); 226 ASSERT_FALSE(IsFullscreenBubbleDisplayingButtons()); 227 } 228 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(); 234 } 235 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)); 245 } 246 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)); 253 254 // Enter tab fullscreen. 255 AddTabAtIndex(0, GURL(kAboutBlankURL), PAGE_TRANSITION_TYPED); 256 ASSERT_NO_FATAL_FAILURE(ToggleTabFullscreen(true)); 257 258 // Exit browser fullscreen. 259 ASSERT_NO_FATAL_FAILURE(ToggleBrowserFullscreen(false)); 260 ASSERT_FALSE(browser()->window()->IsFullscreen()); 261 } 262 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)); 269 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)); 274 275 // Verify browser fullscreen still active. 276 ASSERT_TRUE(IsFullscreenForBrowser()); 277 } 278 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))); 287 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)); 293 } 294 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()); 300 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")); 304 305 ASSERT_FALSE(browser()->window()->IsFullscreen()); 306 } 307 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()); 313 314 ui_test_utils::NavigateToURL(browser(), GURL("about:blank")); 315 ui_test_utils::NavigateToURL(browser(), GURL("chrome://newtab")); 316 317 ASSERT_NO_FATAL_FAILURE(ToggleTabFullscreen(true)); 318 319 GoBack(); 320 321 ASSERT_FALSE(browser()->window()->IsFullscreen()); 322 } 323 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()); 330 331 GURL url(ui_test_utils::GetTestUrl(base::FilePath( 332 base::FilePath::kCurrentDirectory), base::FilePath(kSimpleFile))); 333 GURL url_with_fragment(url.spec() + "#fragment"); 334 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()); 339 } 340 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()); 347 348 ui_test_utils::NavigateToURL(browser(), GURL("about:blank")); 349 ui_test_utils::NavigateToURL(browser(), GURL("chrome://newtab")); 350 351 ASSERT_NO_FATAL_FAILURE(ToggleBrowserFullscreen(true)); 352 ASSERT_NO_FATAL_FAILURE(ToggleTabFullscreen(true)); 353 354 GoBack(); 355 356 ASSERT_TRUE(IsFullscreenForBrowser()); 357 ASSERT_FALSE(IsFullscreenForTabOrPending()); 358 } 359 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()); 365 366 AddTabAtIndex(0, GURL(kAboutBlankURL), PAGE_TRANSITION_TYPED); 367 368 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents(); 369 370 { 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()); 380 } 381 382 { 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()); 389 } 390 391 if (chrome::mac::SupportsSystemFullscreen()) { 392 // Test that tab fullscreen mode doesn't make presentation mode the default 393 // on Lion. 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()); 400 } 401 } 402 #endif 403 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)); 409 410 ASSERT_FALSE(IsFullscreenBubbleDisplayed()); 411 412 // Request to lock the mouse. 413 { 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())); 418 } 419 ASSERT_FALSE(IsFullscreenPermissionRequested()); 420 ASSERT_TRUE(IsMouseLockPermissionRequested()); 421 422 // Escape, no prompts should remain. 423 SendEscapeToFullscreenController(); 424 ASSERT_FALSE(IsFullscreenPermissionRequested()); 425 ASSERT_FALSE(IsMouseLockPermissionRequested()); 426 427 // Request to lock the mouse. 428 { 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())); 433 } 434 ASSERT_FALSE(IsFullscreenPermissionRequested()); 435 ASSERT_TRUE(IsMouseLockPermissionRequested()); 436 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()); 443 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()); 450 } 451 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)); 459 460 ASSERT_FALSE(IsFullscreenBubbleDisplayed()); 461 462 // Request to lock the mouse and enter fullscreen. 463 { 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(); 470 } 471 ASSERT_TRUE(IsFullscreenPermissionRequested()); 472 ASSERT_TRUE(IsMouseLockPermissionRequested()); 473 474 // Escape, no prompts should remain. 475 { 476 FullscreenNotificationObserver fullscreen_observer; 477 SendEscapeToFullscreenController(); 478 fullscreen_observer.Wait(); 479 } 480 ASSERT_FALSE(IsFullscreenPermissionRequested()); 481 ASSERT_FALSE(IsMouseLockPermissionRequested()); 482 483 // Request to lock the mouse and enter fullscreen. 484 { 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(); 491 } 492 ASSERT_TRUE(IsFullscreenPermissionRequested()); 493 ASSERT_TRUE(IsMouseLockPermissionRequested()); 494 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()); 501 502 // Escape, confirm we are out of mouse lock and fullscreen with no prompts. 503 { 504 FullscreenNotificationObserver fullscreen_observer; 505 SendEscapeToFullscreenController(); 506 fullscreen_observer.Wait(); 507 } 508 ASSERT_FALSE(IsMouseLocked()); 509 ASSERT_FALSE(IsFullscreenForTabOrPending()); 510 ASSERT_FALSE(IsFullscreenPermissionRequested()); 511 ASSERT_FALSE(IsMouseLockPermissionRequested()); 512 } 513 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)); 521 522 ASSERT_FALSE(IsFullscreenBubbleDisplayed()); 523 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()); 531 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()); 541 542 // Accept mouse lock. 543 AcceptCurrentFullscreenOrMouseLockRequest(); 544 ASSERT_TRUE(IsMouseLocked()); 545 ASSERT_FALSE(IsFullscreenBubbleDisplayingButtons()); 546 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()); 552 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()); 561 562 // Accept fullscreen and mouse lock. 563 AcceptCurrentFullscreenOrMouseLockRequest(); 564 ASSERT_TRUE(IsMouseLocked()); 565 ASSERT_TRUE(IsFullscreenForTabOrPending()); 566 ASSERT_FALSE(IsFullscreenBubbleDisplayingButtons()); 567 } 568 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)); 578 579 ASSERT_FALSE(IsFullscreenBubbleDisplayed()); 580 581 // Request to lock the mouse and enter fullscreen. 582 { 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(); 589 } 590 ASSERT_TRUE(IsFullscreenBubbleDisplayed()); 591 ASSERT_TRUE(IsFullscreenPermissionRequested()); 592 ASSERT_TRUE(IsMouseLockPermissionRequested()); 593 ASSERT_FALSE(IsMouseLocked()); 594 ASSERT_TRUE(IsFullscreenForTabOrPending()); 595 596 // Deny both first, to make sure we can. 597 { 598 FullscreenNotificationObserver fullscreen_observer; 599 DenyCurrentFullscreenOrMouseLockRequest(); 600 fullscreen_observer.Wait(); 601 } 602 ASSERT_FALSE(IsMouseLocked()); 603 ASSERT_FALSE(IsFullscreenForTabOrPending()); 604 ASSERT_FALSE(IsFullscreenPermissionRequested()); 605 606 // Request to lock the mouse and enter fullscreen. 607 { 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(); 614 } 615 ASSERT_TRUE(IsFullscreenBubbleDisplayed()); 616 ASSERT_TRUE(IsFullscreenPermissionRequested()); 617 ASSERT_TRUE(IsMouseLockPermissionRequested()); 618 ASSERT_FALSE(IsMouseLocked()); 619 ASSERT_TRUE(IsFullscreenForTabOrPending()); 620 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()); 626 } 627 628 // Tests mouse lock can be exited and re-entered by an application silently 629 // with no UI distraction for users. 630 IN_PROC_BROWSER_TEST_F(FullscreenControllerInteractiveTest, 631 MouseLockSilentAfterTargetUnlock) { 632 ASSERT_TRUE(test_server()->Start()); 633 ui_test_utils::NavigateToURL(browser(), 634 test_server()->GetURL(kFullscreenMouseLockHTML)); 635 636 ASSERT_FALSE(IsFullscreenBubbleDisplayed()); 637 638 // Lock the mouse with a user gesture. 639 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait( 640 browser(), ui::VKEY_1, false, false, false, false, 641 chrome::NOTIFICATION_MOUSE_LOCK_CHANGED, 642 content::NotificationService::AllSources())); 643 ASSERT_TRUE(IsFullscreenBubbleDisplayed()); 644 ASSERT_TRUE(IsMouseLockPermissionRequested()); 645 ASSERT_FALSE(IsMouseLocked()); 646 647 // Accept mouse lock. 648 AcceptCurrentFullscreenOrMouseLockRequest(); 649 ASSERT_TRUE(IsMouseLocked()); 650 ASSERT_TRUE(IsFullscreenBubbleDisplayed()); 651 652 // Unlock the mouse from target, make sure it's unlocked. 653 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait( 654 browser(), ui::VKEY_U, false, false, false, false, 655 chrome::NOTIFICATION_MOUSE_LOCK_CHANGED, 656 content::NotificationService::AllSources())); 657 ASSERT_FALSE(IsMouseLocked()); 658 ASSERT_FALSE(IsFullscreenBubbleDisplayed()); 659 660 // Lock mouse again, make sure it works with no bubble. 661 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait( 662 browser(), ui::VKEY_1, false, false, false, false, 663 chrome::NOTIFICATION_MOUSE_LOCK_CHANGED, 664 content::NotificationService::AllSources())); 665 ASSERT_TRUE(IsMouseLocked()); 666 ASSERT_FALSE(IsFullscreenBubbleDisplayed()); 667 668 // Unlock the mouse again by target. 669 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait( 670 browser(), ui::VKEY_U, false, false, false, false, 671 chrome::NOTIFICATION_MOUSE_LOCK_CHANGED, 672 content::NotificationService::AllSources())); 673 ASSERT_FALSE(IsMouseLocked()); 674 675 // Lock from target, not user gesture, make sure it works. 676 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait( 677 browser(), ui::VKEY_D, false, false, false, false, 678 chrome::NOTIFICATION_MOUSE_LOCK_CHANGED, 679 content::NotificationService::AllSources())); 680 ASSERT_TRUE(IsMouseLocked()); 681 ASSERT_FALSE(IsFullscreenBubbleDisplayed()); 682 683 // Unlock by escape. 684 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait( 685 browser(), ui::VKEY_ESCAPE, false, false, false, false, 686 chrome::NOTIFICATION_MOUSE_LOCK_CHANGED, 687 content::NotificationService::AllSources())); 688 ASSERT_FALSE(IsMouseLocked()); 689 690 // Lock the mouse with a user gesture, make sure we see bubble again. 691 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait( 692 browser(), ui::VKEY_1, false, false, false, false, 693 chrome::NOTIFICATION_MOUSE_LOCK_CHANGED, 694 content::NotificationService::AllSources())); 695 ASSERT_TRUE(IsFullscreenBubbleDisplayed()); 696 ASSERT_TRUE(IsMouseLocked()); 697 } 698 699 #if defined(OS_WIN) 700 // These tests are very flaky on Vista. 701 // http://crbug.com/158762 702 #define MAYBE_TestTabExitsMouseLockOnNavigation \ 703 DISABLED_TestTabExitsMouseLockOnNavigation 704 #define MAYBE_TestTabExitsMouseLockOnGoBack \ 705 DISABLED_TestTabExitsMouseLockOnGoBack 706 #else 707 #define MAYBE_TestTabExitsMouseLockOnNavigation \ 708 TestTabExitsMouseLockOnNavigation 709 #define MAYBE_TestTabExitsMouseLockOnGoBack \ 710 TestTabExitsMouseLockOnGoBack 711 #endif 712 713 // Tests mouse lock is exited on page navigation. 714 IN_PROC_BROWSER_TEST_F(FullscreenControllerInteractiveTest, 715 MAYBE_TestTabExitsMouseLockOnNavigation) { 716 ASSERT_TRUE(test_server()->Start()); 717 ui_test_utils::NavigateToURL(browser(), 718 test_server()->GetURL(kFullscreenMouseLockHTML)); 719 720 // Lock the mouse with a user gesture. 721 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait( 722 browser(), ui::VKEY_1, false, false, false, false, 723 chrome::NOTIFICATION_MOUSE_LOCK_CHANGED, 724 content::NotificationService::AllSources())); 725 ASSERT_TRUE(IsFullscreenBubbleDisplayed()); 726 ASSERT_TRUE(IsMouseLockPermissionRequested()); 727 ASSERT_FALSE(IsMouseLocked()); 728 729 // Accept mouse lock. 730 AcceptCurrentFullscreenOrMouseLockRequest(); 731 ASSERT_TRUE(IsMouseLocked()); 732 733 ui_test_utils::NavigateToURL(browser(), GURL("chrome://newtab")); 734 735 ASSERT_FALSE(IsMouseLocked()); 736 } 737 738 // Tests mouse lock is exited when navigating back. 739 IN_PROC_BROWSER_TEST_F(FullscreenControllerInteractiveTest, 740 MAYBE_TestTabExitsMouseLockOnGoBack) { 741 ASSERT_TRUE(test_server()->Start()); 742 743 // Navigate twice to provide a place to go back to. 744 ui_test_utils::NavigateToURL(browser(), GURL("about:blank")); 745 ui_test_utils::NavigateToURL(browser(), 746 test_server()->GetURL(kFullscreenMouseLockHTML)); 747 748 // Lock the mouse with a user gesture. 749 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait( 750 browser(), ui::VKEY_1, false, false, false, false, 751 chrome::NOTIFICATION_MOUSE_LOCK_CHANGED, 752 content::NotificationService::AllSources())); 753 ASSERT_TRUE(IsFullscreenBubbleDisplayed()); 754 ASSERT_TRUE(IsMouseLockPermissionRequested()); 755 ASSERT_FALSE(IsMouseLocked()); 756 757 // Accept mouse lock. 758 AcceptCurrentFullscreenOrMouseLockRequest(); 759 ASSERT_TRUE(IsMouseLocked()); 760 761 GoBack(); 762 763 ASSERT_FALSE(IsMouseLocked()); 764 } 765 766 // Tests mouse lock is not exited on sub frame navigation. 767 IN_PROC_BROWSER_TEST_F(FullscreenControllerInteractiveTest, 768 TestTabDoesntExitMouseLockOnSubFrameNavigation) { 769 ASSERT_TRUE(test_server()->Start()); 770 771 // Create URLs for test page and test page with #fragment. 772 GURL url(test_server()->GetURL(kFullscreenMouseLockHTML)); 773 GURL url_with_fragment(url.spec() + "#fragment"); 774 775 // Navigate to test page. 776 ui_test_utils::NavigateToURL(browser(), url); 777 778 // Lock the mouse with a user gesture. 779 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait( 780 browser(), ui::VKEY_1, false, false, false, false, 781 chrome::NOTIFICATION_MOUSE_LOCK_CHANGED, 782 content::NotificationService::AllSources())); 783 ASSERT_TRUE(IsFullscreenBubbleDisplayed()); 784 ASSERT_TRUE(IsMouseLockPermissionRequested()); 785 ASSERT_FALSE(IsMouseLocked()); 786 787 // Accept mouse lock. 788 AcceptCurrentFullscreenOrMouseLockRequest(); 789 ASSERT_TRUE(IsMouseLocked()); 790 791 // Navigate to url with fragment. Mouse lock should persist. 792 ui_test_utils::NavigateToURL(browser(), url_with_fragment); 793 ASSERT_TRUE(IsMouseLocked()); 794 } 795 796 // Tests Mouse Lock and Fullscreen are exited upon reload. 797 // http://crbug.com/137486 798 // mac: http://crbug.com/103912 799 IN_PROC_BROWSER_TEST_F(FullscreenControllerInteractiveTest, 800 DISABLED_ReloadExitsMouseLockAndFullscreen) { 801 ASSERT_TRUE(test_server()->Start()); 802 ui_test_utils::NavigateToURL(browser(), 803 test_server()->GetURL(kFullscreenMouseLockHTML)); 804 805 ASSERT_FALSE(IsMouseLockPermissionRequested()); 806 807 // Request mouse lock. 808 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait( 809 browser(), ui::VKEY_1, false, false, false, false, 810 chrome::NOTIFICATION_MOUSE_LOCK_CHANGED, 811 content::NotificationService::AllSources())); 812 ASSERT_TRUE(IsMouseLockPermissionRequested()); 813 814 // Reload. Mouse lock request should be cleared. 815 { 816 MouseLockNotificationObserver mouselock_observer; 817 Reload(); 818 mouselock_observer.Wait(); 819 ASSERT_FALSE(IsMouseLockPermissionRequested()); 820 } 821 822 // Request mouse lock. 823 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait( 824 browser(), ui::VKEY_1, false, false, false, false, 825 chrome::NOTIFICATION_MOUSE_LOCK_CHANGED, 826 content::NotificationService::AllSources())); 827 ASSERT_TRUE(IsMouseLockPermissionRequested()); 828 829 // Accept mouse lock. 830 AcceptCurrentFullscreenOrMouseLockRequest(); 831 ASSERT_TRUE(IsMouseLocked()); 832 ASSERT_TRUE(IsFullscreenBubbleDisplayed()); 833 834 // Reload. Mouse should be unlocked. 835 { 836 MouseLockNotificationObserver mouselock_observer; 837 Reload(); 838 mouselock_observer.Wait(); 839 ASSERT_FALSE(IsMouseLocked()); 840 } 841 842 // Request to lock the mouse and enter fullscreen. 843 { 844 FullscreenNotificationObserver fullscreen_observer; 845 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait( 846 browser(), ui::VKEY_B, false, true, false, false, 847 chrome::NOTIFICATION_MOUSE_LOCK_CHANGED, 848 content::NotificationService::AllSources())); 849 fullscreen_observer.Wait(); 850 } 851 852 // We are fullscreen. 853 ASSERT_TRUE(IsFullscreenForTabOrPending()); 854 855 // Reload. Mouse should be unlocked and fullscreen exited. 856 { 857 FullscreenNotificationObserver fullscreen_observer; 858 Reload(); 859 fullscreen_observer.Wait(); 860 ASSERT_FALSE(IsMouseLocked()); 861 ASSERT_FALSE(IsFullscreenForTabOrPending()); 862 } 863 } 864 865 // Tests ToggleFullscreenModeForTab always causes window to change. 866 // Test is flaky: http://crbug.com/146006 867 IN_PROC_BROWSER_TEST_F(FullscreenControllerInteractiveTest, 868 DISABLED_ToggleFullscreenModeForTab) { 869 // Most fullscreen tests run sharded in fullscreen_controller_browsertest.cc 870 // but flakiness required a while loop in 871 // FullscreenControllerTest::ToggleTabFullscreen. This test verifies that 872 // when running serially there is no flakiness. 873 // This test reproduces the same flow as 874 // TestFullscreenMouseLockContentSettings. 875 // http://crbug.com/133831 876 877 GURL url = test_server()->GetURL("simple.html"); 878 AddTabAtIndex(0, url, PAGE_TRANSITION_TYPED); 879 880 // Validate that going fullscreen for a URL defaults to asking permision. 881 ASSERT_FALSE(IsFullscreenPermissionRequested()); 882 ASSERT_NO_FATAL_FAILURE(ToggleTabFullscreenNoRetries(true)); 883 ASSERT_TRUE(IsFullscreenPermissionRequested()); 884 ASSERT_NO_FATAL_FAILURE(ToggleTabFullscreenNoRetries(false)); 885 } 886