| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <string> | 5 #include <string> |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
| 9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
| 10 #if defined(OS_MACOSX) | 10 #if defined(OS_MACOSX) |
| (...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 ASSERT_EQ(browser()->window()->IsFullscreen(), !enter_fullscreen); | 257 ASSERT_EQ(browser()->window()->IsFullscreen(), !enter_fullscreen); |
| 258 FullscreenNotificationObserver fullscreen_observer; | 258 FullscreenNotificationObserver fullscreen_observer; |
| 259 | 259 |
| 260 browser()->ToggleFullscreenMode(); | 260 browser()->ToggleFullscreenMode(); |
| 261 | 261 |
| 262 fullscreen_observer.Wait(); | 262 fullscreen_observer.Wait(); |
| 263 ASSERT_EQ(browser()->window()->IsFullscreen(), enter_fullscreen); | 263 ASSERT_EQ(browser()->window()->IsFullscreen(), enter_fullscreen); |
| 264 ASSERT_EQ(IsFullscreenForBrowser(), enter_fullscreen); | 264 ASSERT_EQ(IsFullscreenForBrowser(), enter_fullscreen); |
| 265 } | 265 } |
| 266 | 266 |
| 267 void RequestToLockMouse(content::WebContents* tab, bool user_gesture) { | 267 void RequestToLockMouse(content::WebContents* tab, bool user_gesture, |
| 268 browser()->RequestToLockMouse(tab, user_gesture); | 268 bool after_target_unlock_request) { |
| 269 browser()->RequestToLockMouse(tab, user_gesture, |
| 270 after_target_unlock_request); |
| 269 } | 271 } |
| 270 | 272 |
| 271 void LostMouseLock() { | 273 void LostMouseLock() { |
| 272 browser()->LostMouseLock(); | 274 browser()->LostMouseLock(); |
| 273 } | 275 } |
| 274 | 276 |
| 275 bool SendEscapeToFullscreenController() { | 277 bool SendEscapeToFullscreenController() { |
| 276 return browser()->fullscreen_controller_->HandleUserPressedEscape(); | 278 return browser()->fullscreen_controller_->HandleUserPressedEscape(); |
| 277 } | 279 } |
| 278 | 280 |
| (...skipping 774 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1053 AddTabAtIndex(0, GURL(chrome::kAboutBlankURL), | 1055 AddTabAtIndex(0, GURL(chrome::kAboutBlankURL), |
| 1054 content::PAGE_TRANSITION_TYPED); | 1056 content::PAGE_TRANSITION_TYPED); |
| 1055 AddTabAtIndex(1, GURL(chrome::kAboutBlankURL), | 1057 AddTabAtIndex(1, GURL(chrome::kAboutBlankURL), |
| 1056 content::PAGE_TRANSITION_TYPED); | 1058 content::PAGE_TRANSITION_TYPED); |
| 1057 | 1059 |
| 1058 WebContents* fullscreen_tab = browser()->GetSelectedWebContents(); | 1060 WebContents* fullscreen_tab = browser()->GetSelectedWebContents(); |
| 1059 | 1061 |
| 1060 ASSERT_NO_FATAL_FAILURE(ToggleTabFullscreen(fullscreen_tab, true)); | 1062 ASSERT_NO_FATAL_FAILURE(ToggleTabFullscreen(fullscreen_tab, true)); |
| 1061 | 1063 |
| 1062 // Request mouse lock and verify the bubble is waiting for user confirmation. | 1064 // Request mouse lock and verify the bubble is waiting for user confirmation. |
| 1063 RequestToLockMouse(fullscreen_tab, true); | 1065 RequestToLockMouse(fullscreen_tab, true, false); |
| 1064 ASSERT_TRUE(IsMouseLockPermissionRequested()); | 1066 ASSERT_TRUE(IsMouseLockPermissionRequested()); |
| 1065 | 1067 |
| 1066 // Accept mouse lock and verify bubble no longer shows confirmation buttons. | 1068 // Accept mouse lock and verify bubble no longer shows confirmation buttons. |
| 1067 AcceptCurrentFullscreenOrMouseLockRequest(); | 1069 AcceptCurrentFullscreenOrMouseLockRequest(); |
| 1068 ASSERT_FALSE(IsFullscreenBubbleDisplayingButtons()); | 1070 ASSERT_FALSE(IsFullscreenBubbleDisplayingButtons()); |
| 1069 } | 1071 } |
| 1070 | 1072 |
| 1071 // Tests mouse lock then fullscreen. | 1073 // Tests mouse lock then fullscreen. |
| 1072 IN_PROC_BROWSER_TEST_F(BrowserTest, MouseLockThenFullscreen) { | 1074 IN_PROC_BROWSER_TEST_F(BrowserTest, MouseLockThenFullscreen) { |
| 1073 ASSERT_TRUE(test_server()->Start()); | 1075 ASSERT_TRUE(test_server()->Start()); |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1279 FullscreenNotificationObserver fullscreen_observer; | 1281 FullscreenNotificationObserver fullscreen_observer; |
| 1280 SendEscapeToFullscreenController(); | 1282 SendEscapeToFullscreenController(); |
| 1281 fullscreen_observer.Wait(); | 1283 fullscreen_observer.Wait(); |
| 1282 } | 1284 } |
| 1283 ASSERT_FALSE(IsMouseLocked()); | 1285 ASSERT_FALSE(IsMouseLocked()); |
| 1284 ASSERT_FALSE(IsFullscreenForTabOrPending()); | 1286 ASSERT_FALSE(IsFullscreenForTabOrPending()); |
| 1285 ASSERT_FALSE(IsFullscreenPermissionRequested()); | 1287 ASSERT_FALSE(IsFullscreenPermissionRequested()); |
| 1286 ASSERT_FALSE(IsMouseLockPermissionRequested()); | 1288 ASSERT_FALSE(IsMouseLockPermissionRequested()); |
| 1287 } | 1289 } |
| 1288 | 1290 |
| 1291 IN_PROC_BROWSER_TEST_F(BrowserTest, MouseLockSilentAfterTargetUnlock) { |
| 1292 ASSERT_TRUE(test_server()->Start()); |
| 1293 ui_test_utils::NavigateToURL(browser(), |
| 1294 test_server()->GetURL(kFullscreenMouseLockHTML)); |
| 1295 |
| 1296 ASSERT_FALSE(IsFullscreenBubbleDisplayed()); |
| 1297 |
| 1298 // Lock the mouse with a user gesture. |
| 1299 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait( |
| 1300 browser(), ui::VKEY_1, false, false, false, false, |
| 1301 chrome::NOTIFICATION_MOUSE_LOCK_CHANGED, |
| 1302 content::NotificationService::AllSources())); |
| 1303 ASSERT_TRUE(IsFullscreenBubbleDisplayed()); |
| 1304 ASSERT_TRUE(IsMouseLockPermissionRequested()); |
| 1305 ASSERT_FALSE(IsMouseLocked()); |
| 1306 |
| 1307 // Accept mouse lock. |
| 1308 AcceptCurrentFullscreenOrMouseLockRequest(); |
| 1309 ASSERT_TRUE(IsMouseLocked()); |
| 1310 ASSERT_TRUE(IsFullscreenBubbleDisplayed()); |
| 1311 |
| 1312 // Unlock the mouse from target, make sure it's unloacked |
| 1313 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait( |
| 1314 browser(), ui::VKEY_U, false, false, false, false, |
| 1315 chrome::NOTIFICATION_MOUSE_LOCK_CHANGED, |
| 1316 content::NotificationService::AllSources())); |
| 1317 ASSERT_FALSE(IsMouseLocked()); |
| 1318 ASSERT_FALSE(IsFullscreenBubbleDisplayed()); |
| 1319 |
| 1320 // Lock mouse again, make sure it works with no bubble |
| 1321 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait( |
| 1322 browser(), ui::VKEY_1, false, false, false, false, |
| 1323 chrome::NOTIFICATION_MOUSE_LOCK_CHANGED, |
| 1324 content::NotificationService::AllSources())); |
| 1325 ASSERT_TRUE(IsMouseLocked()); |
| 1326 ASSERT_FALSE(IsFullscreenBubbleDisplayed()); |
| 1327 |
| 1328 // Unlock the mouse again by target |
| 1329 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait( |
| 1330 browser(), ui::VKEY_U, false, false, false, false, |
| 1331 chrome::NOTIFICATION_MOUSE_LOCK_CHANGED, |
| 1332 content::NotificationService::AllSources())); |
| 1333 ASSERT_FALSE(IsMouseLocked()); |
| 1334 |
| 1335 // Lock from target, not user gesture, make sure it works |
| 1336 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait( |
| 1337 browser(), ui::VKEY_D, false, false, false, false, |
| 1338 chrome::NOTIFICATION_MOUSE_LOCK_CHANGED, |
| 1339 content::NotificationService::AllSources())); |
| 1340 ASSERT_TRUE(IsMouseLocked()); |
| 1341 ASSERT_FALSE(IsFullscreenBubbleDisplayed()); |
| 1342 |
| 1343 // Unlock by escape |
| 1344 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait( |
| 1345 browser(), ui::VKEY_ESCAPE, false, false, false, false, |
| 1346 chrome::NOTIFICATION_MOUSE_LOCK_CHANGED, |
| 1347 content::NotificationService::AllSources())); |
| 1348 ASSERT_FALSE(IsMouseLocked()); |
| 1349 |
| 1350 // Lock the mouse with a user gesture, make sure we see bubble again |
| 1351 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait( |
| 1352 browser(), ui::VKEY_1, false, false, false, false, |
| 1353 chrome::NOTIFICATION_MOUSE_LOCK_CHANGED, |
| 1354 content::NotificationService::AllSources())); |
| 1355 ASSERT_TRUE(IsFullscreenBubbleDisplayed()); |
| 1356 ASSERT_TRUE(IsMouseLocked()); |
| 1357 } |
| 1358 |
| 1289 // Helper method to be called by multiple tests. | 1359 // Helper method to be called by multiple tests. |
| 1290 // Tests Fullscreen and Mouse Lock with varying content settings ALLOW & BLOCK. | 1360 // Tests Fullscreen and Mouse Lock with varying content settings ALLOW & BLOCK. |
| 1291 void BrowserTest::TestFullscreenMouseLockContentSettings() { | 1361 void BrowserTest::TestFullscreenMouseLockContentSettings() { |
| 1292 GURL url = test_server()->GetURL("simple.html"); | 1362 GURL url = test_server()->GetURL("simple.html"); |
| 1293 AddTabAtIndex(0, url, content::PAGE_TRANSITION_TYPED); | 1363 AddTabAtIndex(0, url, content::PAGE_TRANSITION_TYPED); |
| 1294 WebContents* tab = browser()->GetSelectedWebContents(); | 1364 WebContents* tab = browser()->GetSelectedWebContents(); |
| 1295 | 1365 |
| 1296 // Validate that going fullscreen for a URL defaults to asking permision. | 1366 // Validate that going fullscreen for a URL defaults to asking permision. |
| 1297 ASSERT_FALSE(IsFullscreenPermissionRequested()); | 1367 ASSERT_FALSE(IsFullscreenPermissionRequested()); |
| 1298 ASSERT_NO_FATAL_FAILURE(ToggleTabFullscreen(tab, true)); | 1368 ASSERT_NO_FATAL_FAILURE(ToggleTabFullscreen(tab, true)); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1312 // Now, fullscreen should not prompt for permission. | 1382 // Now, fullscreen should not prompt for permission. |
| 1313 ASSERT_FALSE(IsFullscreenPermissionRequested()); | 1383 ASSERT_FALSE(IsFullscreenPermissionRequested()); |
| 1314 ASSERT_NO_FATAL_FAILURE(ToggleTabFullscreen(tab, true)); | 1384 ASSERT_NO_FATAL_FAILURE(ToggleTabFullscreen(tab, true)); |
| 1315 ASSERT_FALSE(IsFullscreenPermissionRequested()); | 1385 ASSERT_FALSE(IsFullscreenPermissionRequested()); |
| 1316 | 1386 |
| 1317 // Leaving tab in fullscreen, now test mouse lock ALLOW: | 1387 // Leaving tab in fullscreen, now test mouse lock ALLOW: |
| 1318 | 1388 |
| 1319 // Validate that mouse lock defaults to asking permision. | 1389 // Validate that mouse lock defaults to asking permision. |
| 1320 ASSERT_FALSE(IsMouseLockPermissionRequested()); | 1390 ASSERT_FALSE(IsMouseLockPermissionRequested()); |
| 1321 ASSERT_FALSE(IsMouseLocked()); | 1391 ASSERT_FALSE(IsMouseLocked()); |
| 1322 RequestToLockMouse(tab, true); | 1392 RequestToLockMouse(tab, true, false); |
| 1323 ASSERT_TRUE(IsMouseLockPermissionRequested()); | 1393 ASSERT_TRUE(IsMouseLockPermissionRequested()); |
| 1324 LostMouseLock(); | 1394 LostMouseLock(); |
| 1325 | 1395 |
| 1326 // Add content setting to ALLOW mouse lock. | 1396 // Add content setting to ALLOW mouse lock. |
| 1327 settings_map->SetContentSetting( | 1397 settings_map->SetContentSetting( |
| 1328 pattern, ContentSettingsPattern::Wildcard(), | 1398 pattern, ContentSettingsPattern::Wildcard(), |
| 1329 CONTENT_SETTINGS_TYPE_MOUSELOCK, std::string(), | 1399 CONTENT_SETTINGS_TYPE_MOUSELOCK, std::string(), |
| 1330 CONTENT_SETTING_ALLOW); | 1400 CONTENT_SETTING_ALLOW); |
| 1331 | 1401 |
| 1332 // Now, mouse lock should not prompt for permission. | 1402 // Now, mouse lock should not prompt for permission. |
| 1333 ASSERT_FALSE(IsMouseLockPermissionRequested()); | 1403 ASSERT_FALSE(IsMouseLockPermissionRequested()); |
| 1334 RequestToLockMouse(tab, true); | 1404 RequestToLockMouse(tab, true, false); |
| 1335 ASSERT_FALSE(IsMouseLockPermissionRequested()); | 1405 ASSERT_FALSE(IsMouseLockPermissionRequested()); |
| 1336 LostMouseLock(); | 1406 LostMouseLock(); |
| 1337 | 1407 |
| 1338 // Leaving tab in fullscreen, now test mouse lock BLOCK: | 1408 // Leaving tab in fullscreen, now test mouse lock BLOCK: |
| 1339 | 1409 |
| 1340 // Add content setting to BLOCK mouse lock. | 1410 // Add content setting to BLOCK mouse lock. |
| 1341 settings_map->SetContentSetting( | 1411 settings_map->SetContentSetting( |
| 1342 pattern, ContentSettingsPattern::Wildcard(), | 1412 pattern, ContentSettingsPattern::Wildcard(), |
| 1343 CONTENT_SETTINGS_TYPE_MOUSELOCK, std::string(), | 1413 CONTENT_SETTINGS_TYPE_MOUSELOCK, std::string(), |
| 1344 CONTENT_SETTING_BLOCK); | 1414 CONTENT_SETTING_BLOCK); |
| 1345 | 1415 |
| 1346 // Now, mouse lock should not be pending. | 1416 // Now, mouse lock should not be pending. |
| 1347 ASSERT_FALSE(IsMouseLockPermissionRequested()); | 1417 ASSERT_FALSE(IsMouseLockPermissionRequested()); |
| 1348 RequestToLockMouse(tab, true); | 1418 RequestToLockMouse(tab, true, false); |
| 1349 ASSERT_FALSE(IsMouseLockPermissionRequested()); | 1419 ASSERT_FALSE(IsMouseLockPermissionRequested()); |
| 1350 } | 1420 } |
| 1351 | 1421 |
| 1352 // Tests fullscreen and Mouse Lock with varying content settings ALLOW & BLOCK. | 1422 // Tests fullscreen and Mouse Lock with varying content settings ALLOW & BLOCK. |
| 1353 IN_PROC_BROWSER_TEST_F(BrowserTest, FullscreenMouseLockContentSettings) { | 1423 IN_PROC_BROWSER_TEST_F(BrowserTest, FullscreenMouseLockContentSettings) { |
| 1354 TestFullscreenMouseLockContentSettings(); | 1424 TestFullscreenMouseLockContentSettings(); |
| 1355 } | 1425 } |
| 1356 | 1426 |
| 1357 // Tests fullscreen and Mouse Lock with varying content settings ALLOW & BLOCK, | 1427 // Tests fullscreen and Mouse Lock with varying content settings ALLOW & BLOCK, |
| 1358 // but with the browser initiated in fullscreen mode first. | 1428 // but with the browser initiated in fullscreen mode first. |
| (...skipping 780 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2139 command_line->AppendSwitchASCII(switches::kApp, url.spec()); | 2209 command_line->AppendSwitchASCII(switches::kApp, url.spec()); |
| 2140 } | 2210 } |
| 2141 }; | 2211 }; |
| 2142 | 2212 |
| 2143 IN_PROC_BROWSER_TEST_F(AppModeTest, EnableAppModeTest) { | 2213 IN_PROC_BROWSER_TEST_F(AppModeTest, EnableAppModeTest) { |
| 2144 // Test that an application browser window loads correctly. | 2214 // Test that an application browser window loads correctly. |
| 2145 | 2215 |
| 2146 // Verify the browser is in application mode. | 2216 // Verify the browser is in application mode. |
| 2147 EXPECT_TRUE(browser()->IsApplication()); | 2217 EXPECT_TRUE(browser()->IsApplication()); |
| 2148 } | 2218 } |
| OLD | NEW |