Home | History | Annotate | Download | only in fullscreen
      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 url::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(IsWindowFullscreenForTabOrPending(), 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(url::kAboutBlankURL), PAGE_TRANSITION_TYPED);
    185 
    186   ASSERT_NO_FATAL_FAILURE(ToggleTabFullscreen(true));
    187 
    188   {
    189     FullscreenNotificationObserver fullscreen_observer;
    190     AddTabAtIndex(1, GURL(url::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(url::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(url::kAboutBlankURL), PAGE_TRANSITION_TYPED);
    216   AddTabAtIndex(1, GURL(url::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(url::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(url::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(IsWindowFullscreenForTabOrPending());
    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(IsWindowFullscreenForTabOrPending());
    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(url::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(IsWindowFullscreenForTabOrPending());
    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(IsWindowFullscreenForTabOrPending());
    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(IsWindowFullscreenForTabOrPending());
    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(IsWindowFullscreenForTabOrPending());
    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(IsWindowFullscreenForTabOrPending());
    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(IsWindowFullscreenForTabOrPending());
    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(IsWindowFullscreenForTabOrPending());
    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(IsWindowFullscreenForTabOrPending());
    620 
    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());
    626 }
    627 
    628 // Tests mouse lock and fullscreen for the privileged fullscreen case (e.g.,
    629 // embedded flash fullscreen, since the Flash plugin handles user permissions
    630 // requests itself).
    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));
    637 
    638   ASSERT_FALSE(IsFullscreenBubbleDisplayed());
    639 
    640   SetPrivilegedFullscreen(true);
    641 
    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();
    649 
    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());
    656 }
    657 
    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
    662 #else
    663 #define MAYBE_MouseLockSilentAfterTargetUnlock MouseLockSilentAfterTargetUnlock
    664 #endif
    665 
    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));
    673 
    674   ASSERT_FALSE(IsFullscreenBubbleDisplayed());
    675 
    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());
    684 
    685   // Accept mouse lock.
    686   AcceptCurrentFullscreenOrMouseLockRequest();
    687   ASSERT_TRUE(IsMouseLocked());
    688   ASSERT_TRUE(IsFullscreenBubbleDisplayed());
    689 
    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());
    697 
    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());
    705 
    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());
    712 
    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());
    720 
    721   // Unlock by escape.
    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());
    727 
    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());
    735 }
    736 
    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
    747 #else
    748 #define MAYBE_TestTabExitsMouseLockOnNavigation \
    749     TestTabExitsMouseLockOnNavigation
    750 #define MAYBE_TestTabExitsMouseLockOnGoBack \
    751     TestTabExitsMouseLockOnGoBack
    752 #endif
    753 
    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));
    760 
    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());
    769 
    770   // Accept mouse lock.
    771   AcceptCurrentFullscreenOrMouseLockRequest();
    772   ASSERT_TRUE(IsMouseLocked());
    773 
    774   ui_test_utils::NavigateToURL(browser(), GURL("chrome://newtab"));
    775 
    776   ASSERT_FALSE(IsMouseLocked());
    777 }
    778 
    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());
    783 
    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));
    788 
    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());
    797 
    798   // Accept mouse lock.
    799   AcceptCurrentFullscreenOrMouseLockRequest();
    800   ASSERT_TRUE(IsMouseLocked());
    801 
    802   GoBack();
    803 
    804   ASSERT_FALSE(IsMouseLocked());
    805 }
    806 
    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
    810 #else
    811 #define MAYBE_TestTabDoesntExitMouseLockOnSubFrameNavigation TestTabDoesntExitMouseLockOnSubFrameNavigation
    812 #endif
    813 
    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());
    818 
    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");
    822 
    823   // Navigate to test page.
    824   ui_test_utils::NavigateToURL(browser(), url);
    825 
    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());
    834 
    835   // Accept mouse lock.
    836   AcceptCurrentFullscreenOrMouseLockRequest();
    837   ASSERT_TRUE(IsMouseLocked());
    838 
    839   // Navigate to url with fragment. Mouse lock should persist.
    840   ui_test_utils::NavigateToURL(browser(), url_with_fragment);
    841   ASSERT_TRUE(IsMouseLocked());
    842 }
    843 
    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));
    852 
    853   ASSERT_FALSE(IsMouseLockPermissionRequested());
    854 
    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());
    861 
    862   // Reload. Mouse lock request should be cleared.
    863   {
    864     MouseLockNotificationObserver mouselock_observer;
    865     Reload();
    866     mouselock_observer.Wait();
    867     ASSERT_FALSE(IsMouseLockPermissionRequested());
    868   }
    869 
    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());
    876 
    877   // Accept mouse lock.
    878   AcceptCurrentFullscreenOrMouseLockRequest();
    879   ASSERT_TRUE(IsMouseLocked());
    880   ASSERT_TRUE(IsFullscreenBubbleDisplayed());
    881 
    882   // Reload. Mouse should be unlocked.
    883   {
    884     MouseLockNotificationObserver mouselock_observer;
    885     Reload();
    886     mouselock_observer.Wait();
    887     ASSERT_FALSE(IsMouseLocked());
    888   }
    889 
    890   // Request to lock the mouse and enter fullscreen.
    891   {
    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();
    898   }
    899 
    900   // We are fullscreen.
    901   ASSERT_TRUE(IsWindowFullscreenForTabOrPending());
    902 
    903   // Reload. Mouse should be unlocked and fullscreen exited.
    904   {
    905     FullscreenNotificationObserver fullscreen_observer;
    906     Reload();
    907     fullscreen_observer.Wait();
    908     ASSERT_FALSE(IsMouseLocked());
    909     ASSERT_FALSE(IsWindowFullscreenForTabOrPending());
    910   }
    911 }
    912 
    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
    924 
    925   GURL url = test_server()->GetURL("simple.html");
    926   AddTabAtIndex(0, url, PAGE_TRANSITION_TYPED);
    927 
    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));
    933 }
    934