| OLD | NEW |
| (Empty) |
| 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 "base/compiler_specific.h" | |
| 6 #include "base/utf_string_conversions.h" | |
| 7 #include "chrome/browser/content_settings/host_content_settings_map.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_controller_test.h" | |
| 13 #include "chrome/test/base/ui_test_utils.h" | |
| 14 #include "content/public/browser/render_view_host.h" | |
| 15 #include "content/public/browser/web_contents.h" | |
| 16 #include "content/public/common/url_constants.h" | |
| 17 #include "content/public/test/test_navigation_observer.h" | |
| 18 #if defined(OS_MACOSX) | |
| 19 #include "base/mac/mac_util.h" | |
| 20 #endif | |
| 21 | |
| 22 using content::WebContents; | |
| 23 | |
| 24 namespace { | |
| 25 | |
| 26 const FilePath::CharType* kSimpleFile = FILE_PATH_LITERAL("simple.html"); | |
| 27 | |
| 28 } // namespace | |
| 29 | |
| 30 class FullscreenControllerBrowserTest: public FullscreenControllerTest { | |
| 31 protected: | |
| 32 void TestFullscreenMouseLockContentSettings(); | |
| 33 }; | |
| 34 | |
| 35 #if defined(OS_MACOSX) | |
| 36 // http://crbug.com/104265 | |
| 37 #define MAYBE_TestNewTabExitsFullscreen DISABLED_TestNewTabExitsFullscreen | |
| 38 #else | |
| 39 #define MAYBE_TestNewTabExitsFullscreen TestNewTabExitsFullscreen | |
| 40 #endif | |
| 41 | |
| 42 // Tests that while in fullscreen creating a new tab will exit fullscreen. | |
| 43 IN_PROC_BROWSER_TEST_F(FullscreenControllerTest, | |
| 44 MAYBE_TestNewTabExitsFullscreen) { | |
| 45 ASSERT_TRUE(test_server()->Start()); | |
| 46 | |
| 47 AddTabAtIndexAndWait( | |
| 48 0, GURL(chrome::kAboutBlankURL), content::PAGE_TRANSITION_TYPED); | |
| 49 | |
| 50 ASSERT_NO_FATAL_FAILURE(ToggleTabFullscreen(true)); | |
| 51 | |
| 52 { | |
| 53 FullscreenNotificationObserver fullscreen_observer; | |
| 54 AddTabAtIndexAndWait( | |
| 55 1, GURL(chrome::kAboutBlankURL), content::PAGE_TRANSITION_TYPED); | |
| 56 fullscreen_observer.Wait(); | |
| 57 ASSERT_FALSE(browser()->window()->IsFullscreen()); | |
| 58 } | |
| 59 } | |
| 60 | |
| 61 #if defined(OS_MACOSX) | |
| 62 // http://crbug.com/100467 | |
| 63 #define MAYBE_TestTabExitsItselfFromFullscreen \ | |
| 64 FAILS_TestTabExitsItselfFromFullscreen | |
| 65 #else | |
| 66 #define MAYBE_TestTabExitsItselfFromFullscreen TestTabExitsItselfFromFullscreen | |
| 67 #endif | |
| 68 | |
| 69 // Tests a tab exiting fullscreen will bring the browser out of fullscreen. | |
| 70 IN_PROC_BROWSER_TEST_F(FullscreenControllerTest, | |
| 71 MAYBE_TestTabExitsItselfFromFullscreen) { | |
| 72 ASSERT_TRUE(test_server()->Start()); | |
| 73 | |
| 74 AddTabAtIndexAndWait( | |
| 75 0, GURL(chrome::kAboutBlankURL), content::PAGE_TRANSITION_TYPED); | |
| 76 | |
| 77 ASSERT_NO_FATAL_FAILURE(ToggleTabFullscreen(true)); | |
| 78 ASSERT_NO_FATAL_FAILURE(ToggleTabFullscreen(false)); | |
| 79 } | |
| 80 | |
| 81 // Tests entering fullscreen and then requesting mouse lock results in | |
| 82 // buttons for the user, and that after confirming the buttons are dismissed. | |
| 83 IN_PROC_BROWSER_TEST_F(FullscreenControllerTest, | |
| 84 TestFullscreenBubbleMouseLockState) { | |
| 85 ASSERT_TRUE(test_server()->Start()); | |
| 86 | |
| 87 AddTabAtIndexAndWait(0, GURL(chrome::kAboutBlankURL), | |
| 88 content::PAGE_TRANSITION_TYPED); | |
| 89 AddTabAtIndexAndWait(1, GURL(chrome::kAboutBlankURL), | |
| 90 content::PAGE_TRANSITION_TYPED); | |
| 91 | |
| 92 ASSERT_NO_FATAL_FAILURE(ToggleTabFullscreen(true)); | |
| 93 | |
| 94 // Request mouse lock and verify the bubble is waiting for user confirmation. | |
| 95 RequestToLockMouse(true, false); | |
| 96 ASSERT_TRUE(IsMouseLockPermissionRequested()); | |
| 97 | |
| 98 // Accept mouse lock and verify bubble no longer shows confirmation buttons. | |
| 99 AcceptCurrentFullscreenOrMouseLockRequest(); | |
| 100 ASSERT_FALSE(IsFullscreenBubbleDisplayingButtons()); | |
| 101 } | |
| 102 | |
| 103 // Helper method to be called by multiple tests. | |
| 104 // Tests Fullscreen and Mouse Lock with varying content settings ALLOW & BLOCK. | |
| 105 void FullscreenControllerBrowserTest::TestFullscreenMouseLockContentSettings() { | |
| 106 GURL url = test_server()->GetURL("simple.html"); | |
| 107 AddTabAtIndexAndWait(0, url, content::PAGE_TRANSITION_TYPED); | |
| 108 | |
| 109 // Validate that going fullscreen for a URL defaults to asking permision. | |
| 110 ASSERT_FALSE(IsFullscreenPermissionRequested()); | |
| 111 ASSERT_NO_FATAL_FAILURE(ToggleTabFullscreen(true)); | |
| 112 ASSERT_TRUE(IsFullscreenPermissionRequested()); | |
| 113 ASSERT_NO_FATAL_FAILURE(ToggleTabFullscreen(false)); | |
| 114 | |
| 115 // Add content setting to ALLOW fullscreen. | |
| 116 HostContentSettingsMap* settings_map = | |
| 117 browser()->profile()->GetHostContentSettingsMap(); | |
| 118 ContentSettingsPattern pattern = | |
| 119 ContentSettingsPattern::FromURL(url); | |
| 120 settings_map->SetContentSetting( | |
| 121 pattern, ContentSettingsPattern::Wildcard(), | |
| 122 CONTENT_SETTINGS_TYPE_FULLSCREEN, std::string(), | |
| 123 CONTENT_SETTING_ALLOW); | |
| 124 | |
| 125 // Now, fullscreen should not prompt for permission. | |
| 126 ASSERT_FALSE(IsFullscreenPermissionRequested()); | |
| 127 ASSERT_NO_FATAL_FAILURE(ToggleTabFullscreen(true)); | |
| 128 ASSERT_FALSE(IsFullscreenPermissionRequested()); | |
| 129 | |
| 130 // Leaving tab in fullscreen, now test mouse lock ALLOW: | |
| 131 | |
| 132 // Validate that mouse lock defaults to asking permision. | |
| 133 ASSERT_FALSE(IsMouseLockPermissionRequested()); | |
| 134 RequestToLockMouse(true, false); | |
| 135 ASSERT_TRUE(IsMouseLockPermissionRequested()); | |
| 136 LostMouseLock(); | |
| 137 | |
| 138 // Add content setting to ALLOW mouse lock. | |
| 139 settings_map->SetContentSetting( | |
| 140 pattern, ContentSettingsPattern::Wildcard(), | |
| 141 CONTENT_SETTINGS_TYPE_MOUSELOCK, std::string(), | |
| 142 CONTENT_SETTING_ALLOW); | |
| 143 | |
| 144 // Now, mouse lock should not prompt for permission. | |
| 145 ASSERT_FALSE(IsMouseLockPermissionRequested()); | |
| 146 RequestToLockMouse(true, false); | |
| 147 ASSERT_FALSE(IsMouseLockPermissionRequested()); | |
| 148 LostMouseLock(); | |
| 149 | |
| 150 // Leaving tab in fullscreen, now test mouse lock BLOCK: | |
| 151 | |
| 152 // Add content setting to BLOCK mouse lock. | |
| 153 settings_map->SetContentSetting( | |
| 154 pattern, ContentSettingsPattern::Wildcard(), | |
| 155 CONTENT_SETTINGS_TYPE_MOUSELOCK, std::string(), | |
| 156 CONTENT_SETTING_BLOCK); | |
| 157 | |
| 158 // Now, mouse lock should not be pending. | |
| 159 ASSERT_FALSE(IsMouseLockPermissionRequested()); | |
| 160 RequestToLockMouse(true, false); | |
| 161 ASSERT_FALSE(IsMouseLockPermissionRequested()); | |
| 162 } | |
| 163 | |
| 164 #if defined(OS_MACOSX) || defined(OS_LINUX) | |
| 165 // http://crbug.com/133831 | |
| 166 #define MAYBE_FullscreenMouseLockContentSettings \ | |
| 167 FLAKY_FullscreenMouseLockContentSettings | |
| 168 #else | |
| 169 #define MAYBE_FullscreenMouseLockContentSettings \ | |
| 170 FullscreenMouseLockContentSettings | |
| 171 #endif | |
| 172 | |
| 173 // Tests fullscreen and Mouse Lock with varying content settings ALLOW & BLOCK. | |
| 174 IN_PROC_BROWSER_TEST_F(FullscreenControllerBrowserTest, | |
| 175 MAYBE_FullscreenMouseLockContentSettings) { | |
| 176 TestFullscreenMouseLockContentSettings(); | |
| 177 } | |
| 178 | |
| 179 // Tests fullscreen and Mouse Lock with varying content settings ALLOW & BLOCK, | |
| 180 // but with the browser initiated in fullscreen mode first. | |
| 181 IN_PROC_BROWSER_TEST_F(FullscreenControllerBrowserTest, | |
| 182 BrowserFullscreenMouseLockContentSettings) { | |
| 183 // Enter browser fullscreen first. | |
| 184 ASSERT_NO_FATAL_FAILURE(ToggleBrowserFullscreen(true)); | |
| 185 TestFullscreenMouseLockContentSettings(); | |
| 186 ASSERT_NO_FATAL_FAILURE(ToggleBrowserFullscreen(false)); | |
| 187 } | |
| 188 | |
| 189 // Tests Fullscreen entered in Browser, then Tab mode, then exited via Browser. | |
| 190 IN_PROC_BROWSER_TEST_F(FullscreenControllerTest, BrowserFullscreenExit) { | |
| 191 // Enter browser fullscreen. | |
| 192 ASSERT_NO_FATAL_FAILURE(ToggleBrowserFullscreen(true)); | |
| 193 | |
| 194 // Enter tab fullscreen. | |
| 195 AddTabAtIndexAndWait(0, GURL(chrome::kAboutBlankURL), | |
| 196 content::PAGE_TRANSITION_TYPED); | |
| 197 ASSERT_NO_FATAL_FAILURE(ToggleTabFullscreen(true)); | |
| 198 | |
| 199 // Exit browser fullscreen. | |
| 200 ASSERT_NO_FATAL_FAILURE(ToggleBrowserFullscreen(false)); | |
| 201 ASSERT_FALSE(browser()->window()->IsFullscreen()); | |
| 202 } | |
| 203 | |
| 204 // Tests Browser Fullscreen remains active after Tab mode entered and exited. | |
| 205 IN_PROC_BROWSER_TEST_F(FullscreenControllerTest, | |
| 206 BrowserFullscreenAfterTabFSExit) { | |
| 207 // Enter browser fullscreen. | |
| 208 ASSERT_NO_FATAL_FAILURE(ToggleBrowserFullscreen(true)); | |
| 209 | |
| 210 // Enter and then exit tab fullscreen. | |
| 211 AddTabAtIndexAndWait(0, GURL(chrome::kAboutBlankURL), | |
| 212 content::PAGE_TRANSITION_TYPED); | |
| 213 ASSERT_NO_FATAL_FAILURE(ToggleTabFullscreen(true)); | |
| 214 ASSERT_NO_FATAL_FAILURE(ToggleTabFullscreen(false)); | |
| 215 | |
| 216 // Verify browser fullscreen still active. | |
| 217 ASSERT_TRUE(IsFullscreenForBrowser()); | |
| 218 } | |
| 219 | |
| 220 // Tests fullscreen entered without permision prompt for file:// urls. | |
| 221 IN_PROC_BROWSER_TEST_F(FullscreenControllerTest, FullscreenFileURL) { | |
| 222 ui_test_utils::NavigateToURL(browser(), | |
| 223 ui_test_utils::GetTestUrl(FilePath(FilePath::kCurrentDirectory), | |
| 224 FilePath(kSimpleFile))); | |
| 225 | |
| 226 // Validate that going fullscreen for a file does not ask permision. | |
| 227 ASSERT_FALSE(IsFullscreenPermissionRequested()); | |
| 228 ASSERT_NO_FATAL_FAILURE(ToggleTabFullscreen(true)); | |
| 229 ASSERT_FALSE(IsFullscreenPermissionRequested()); | |
| 230 ASSERT_NO_FATAL_FAILURE(ToggleTabFullscreen(false)); | |
| 231 } | |
| 232 | |
| 233 // Tests fullscreen is exited on page navigation. | |
| 234 // (Similar to mouse lock version in FullscreenControllerInteractiveTest) | |
| 235 IN_PROC_BROWSER_TEST_F(FullscreenControllerTest, | |
| 236 TestTabExitsFullscreenOnNavigation) { | |
| 237 ASSERT_TRUE(test_server()->Start()); | |
| 238 | |
| 239 ui_test_utils::NavigateToURL(browser(), GURL("about:blank")); | |
| 240 ASSERT_NO_FATAL_FAILURE(ToggleTabFullscreen(true)); | |
| 241 ui_test_utils::NavigateToURL(browser(), GURL("chrome://newtab")); | |
| 242 | |
| 243 ASSERT_FALSE(browser()->window()->IsFullscreen()); | |
| 244 } | |
| 245 | |
| 246 // Tests fullscreen is exited when navigating back. | |
| 247 // (Similar to mouse lock version in FullscreenControllerInteractiveTest) | |
| 248 IN_PROC_BROWSER_TEST_F(FullscreenControllerTest, | |
| 249 TestTabExitsFullscreenOnGoBack) { | |
| 250 ASSERT_TRUE(test_server()->Start()); | |
| 251 | |
| 252 ui_test_utils::NavigateToURL(browser(), GURL("about:blank")); | |
| 253 ui_test_utils::NavigateToURL(browser(), GURL("chrome://newtab")); | |
| 254 | |
| 255 ASSERT_NO_FATAL_FAILURE(ToggleTabFullscreen(true)); | |
| 256 | |
| 257 GoBack(); | |
| 258 | |
| 259 ASSERT_FALSE(browser()->window()->IsFullscreen()); | |
| 260 } | |
| 261 | |
| 262 // Tests fullscreen is not exited on sub frame navigation. | |
| 263 // (Similar to mouse lock version in FullscreenControllerInteractiveTest) | |
| 264 IN_PROC_BROWSER_TEST_F(FullscreenControllerTest, | |
| 265 TestTabDoesntExitFullscreenOnSubFrameNavigation) { | |
| 266 ASSERT_TRUE(test_server()->Start()); | |
| 267 | |
| 268 GURL url(ui_test_utils::GetTestUrl(FilePath(FilePath::kCurrentDirectory), | |
| 269 FilePath(kSimpleFile))); | |
| 270 GURL url_with_fragment(url.spec() + "#fragment"); | |
| 271 | |
| 272 ui_test_utils::NavigateToURL(browser(), url); | |
| 273 ASSERT_NO_FATAL_FAILURE(ToggleTabFullscreen(true)); | |
| 274 ui_test_utils::NavigateToURL(browser(), url_with_fragment); | |
| 275 ASSERT_TRUE(IsFullscreenForTabOrPending()); | |
| 276 } | |
| 277 | |
| 278 // Tests tab fullscreen exits, but browser fullscreen remains, on navigation. | |
| 279 IN_PROC_BROWSER_TEST_F(FullscreenControllerTest, | |
| 280 TestFullscreenFromTabWhenAlreadyInBrowserFullscreenWorks)
{ | |
| 281 ASSERT_TRUE(test_server()->Start()); | |
| 282 | |
| 283 ui_test_utils::NavigateToURL(browser(), GURL("about:blank")); | |
| 284 ui_test_utils::NavigateToURL(browser(), GURL("chrome://newtab")); | |
| 285 | |
| 286 ASSERT_NO_FATAL_FAILURE(ToggleBrowserFullscreen(true)); | |
| 287 ASSERT_NO_FATAL_FAILURE(ToggleTabFullscreen(true)); | |
| 288 | |
| 289 GoBack(); | |
| 290 | |
| 291 ASSERT_TRUE(IsFullscreenForBrowser()); | |
| 292 ASSERT_FALSE(IsFullscreenForTabOrPending()); | |
| 293 } | |
| 294 | |
| 295 #if defined(OS_MACOSX) | |
| 296 // http://crbug.com/100467 | |
| 297 IN_PROC_BROWSER_TEST_F( | |
| 298 FullscreenControllerTest, FAILS_TabEntersPresentationModeFromWindowed) { | |
| 299 ASSERT_TRUE(test_server()->Start()); | |
| 300 | |
| 301 AddTabAtIndexAndWait( | |
| 302 0, GURL(chrome::kAboutBlankURL), content::PAGE_TRANSITION_TYPED); | |
| 303 | |
| 304 WebContents* tab = browser()->GetActiveWebContents(); | |
| 305 | |
| 306 { | |
| 307 FullscreenNotificationObserver fullscreen_observer; | |
| 308 EXPECT_FALSE(browser()->window()->IsFullscreen()); | |
| 309 EXPECT_FALSE(browser()->window()->InPresentationMode()); | |
| 310 browser()->ToggleFullscreenModeForTab(tab, true); | |
| 311 fullscreen_observer.Wait(); | |
| 312 ASSERT_TRUE(browser()->window()->IsFullscreen()); | |
| 313 ASSERT_TRUE(browser()->window()->InPresentationMode()); | |
| 314 } | |
| 315 | |
| 316 { | |
| 317 FullscreenNotificationObserver fullscreen_observer; | |
| 318 browser()->TogglePresentationMode(); | |
| 319 fullscreen_observer.Wait(); | |
| 320 ASSERT_FALSE(browser()->window()->IsFullscreen()); | |
| 321 ASSERT_FALSE(browser()->window()->InPresentationMode()); | |
| 322 } | |
| 323 | |
| 324 if (base::mac::IsOSLionOrLater()) { | |
| 325 // Test that tab fullscreen mode doesn't make presentation mode the default | |
| 326 // on Lion. | |
| 327 FullscreenNotificationObserver fullscreen_observer; | |
| 328 browser()->ToggleFullscreenMode(); | |
| 329 fullscreen_observer.Wait(); | |
| 330 ASSERT_TRUE(browser()->window()->IsFullscreen()); | |
| 331 ASSERT_FALSE(browser()->window()->InPresentationMode()); | |
| 332 } | |
| 333 } | |
| 334 #endif | |
| 335 | |
| 336 IN_PROC_BROWSER_TEST_F(FullscreenControllerTest, | |
| 337 PendingMouseLockExitsOnTabSwitch) { | |
| 338 AddTabAtIndexAndWait(0, GURL(chrome::kAboutBlankURL), | |
| 339 content::PAGE_TRANSITION_TYPED); | |
| 340 AddTabAtIndexAndWait(0, GURL(chrome::kAboutBlankURL), | |
| 341 content::PAGE_TRANSITION_TYPED); | |
| 342 WebContents* tab1 = browser()->GetActiveWebContents(); | |
| 343 | |
| 344 // Request mouse lock. Bubble is displayed. | |
| 345 RequestToLockMouse(true, false); | |
| 346 ASSERT_TRUE(IsFullscreenBubbleDisplayed()); | |
| 347 | |
| 348 // Activate current tab. Mouse lock bubble remains. | |
| 349 browser()->ActivateTabAt(0, true); | |
| 350 ASSERT_TRUE(IsFullscreenBubbleDisplayed()); | |
| 351 | |
| 352 // Activate second tab. Mouse lock bubble clears. | |
| 353 { | |
| 354 MouseLockNotificationObserver mouse_lock_observer; | |
| 355 browser()->ActivateTabAt(1, true); | |
| 356 mouse_lock_observer.Wait(); | |
| 357 } | |
| 358 ASSERT_FALSE(IsFullscreenBubbleDisplayed()); | |
| 359 | |
| 360 // Now, test that closing an unrelated tab does not disturb a request. | |
| 361 | |
| 362 // Request mouse lock. Bubble is displayed. | |
| 363 RequestToLockMouse(true, false); | |
| 364 ASSERT_TRUE(IsFullscreenBubbleDisplayed()); | |
| 365 | |
| 366 // Close first tab while second active. Mouse lock bubble remains. | |
| 367 browser()->CloseTabContents(tab1); | |
| 368 ASSERT_TRUE(IsFullscreenBubbleDisplayed()); | |
| 369 } | |
| 370 | |
| 371 IN_PROC_BROWSER_TEST_F(FullscreenControllerTest, | |
| 372 PendingMouseLockExitsOnTabClose) { | |
| 373 // Add more tabs. | |
| 374 AddTabAtIndexAndWait(0, GURL(chrome::kAboutBlankURL), | |
| 375 content::PAGE_TRANSITION_TYPED); | |
| 376 AddTabAtIndexAndWait(0, GURL(chrome::kAboutBlankURL), | |
| 377 content::PAGE_TRANSITION_TYPED); | |
| 378 | |
| 379 // Request mouse lock. Bubble is displayed. | |
| 380 RequestToLockMouse(true, false); | |
| 381 ASSERT_TRUE(IsFullscreenBubbleDisplayed()); | |
| 382 | |
| 383 // Close tab. Bubble is cleared. | |
| 384 { | |
| 385 MouseLockNotificationObserver mouse_lock_observer; | |
| 386 chrome::CloseTab(browser()); | |
| 387 mouse_lock_observer.Wait(); | |
| 388 } | |
| 389 ASSERT_FALSE(IsFullscreenBubbleDisplayed()); | |
| 390 } | |
| OLD | NEW |