| OLD | NEW |
| (Empty) |
| 1 #!/usr/bin/env python | |
| 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
| 3 # Use of this source code is governed by a BSD-style license that can be | |
| 4 # found in the LICENSE file. | |
| 5 | |
| 6 import logging | |
| 7 import os | |
| 8 import re | |
| 9 import shutil | |
| 10 import time | |
| 11 | |
| 12 import pyauto_functional # Must be imported before pyauto | |
| 13 import pyauto | |
| 14 import test_utils | |
| 15 from selenium.webdriver.common.action_chains import ActionChains | |
| 16 from selenium.common.exceptions import WebDriverException | |
| 17 from selenium.webdriver.common.keys import Keys | |
| 18 from webdriver_pages import settings | |
| 19 | |
| 20 | |
| 21 class FullscreenMouselockTest(pyauto.PyUITest): | |
| 22 """TestCase for Fullscreen and Mouse Lock.""" | |
| 23 | |
| 24 def setUp(self): | |
| 25 pyauto.PyUITest.setUp(self) | |
| 26 self._driver = self.NewWebDriver() | |
| 27 # Get the hostname pattern (e.g. http://127.0.0.1:57622). | |
| 28 self._hostname_pattern = ( | |
| 29 re.sub('/files/$', '', self.GetHttpURLForDataPath(''))) | |
| 30 | |
| 31 def Debug(self): | |
| 32 """Test method for experimentation. | |
| 33 | |
| 34 This method will not run automatically. | |
| 35 """ | |
| 36 page = settings.ContentSettingsPage.FromNavigation(self._driver) | |
| 37 import pdb | |
| 38 pdb.set_trace() | |
| 39 | |
| 40 def ExtraChromeFlags(self): | |
| 41 """Ensures Chrome is launched with custom flags. | |
| 42 | |
| 43 Returns: | |
| 44 A list of extra flags to pass to Chrome when it is launched. | |
| 45 """ | |
| 46 # Extra flag needed by scroll performance tests. | |
| 47 return super(FullscreenMouselockTest, | |
| 48 self).ExtraChromeFlags() + ['--enable-pointer-lock'] | |
| 49 | |
| 50 def testFullScreenMouseLockHooks(self): | |
| 51 """Verify fullscreen and mouse lock automation hooks work.""" | |
| 52 self.NavigateToURL(self.GetHttpURLForDataPath( | |
| 53 'fullscreen_mouselock', 'fullscreen_mouselock.html')) | |
| 54 | |
| 55 # Starting off we shouldn't be fullscreen | |
| 56 self.assertFalse(self.IsFullscreenForBrowser()) | |
| 57 self.assertFalse(self.IsFullscreenForTab()) | |
| 58 | |
| 59 # Go fullscreen | |
| 60 self._driver.find_element_by_id('enterFullscreen').click() | |
| 61 self.assertTrue(self.WaitUntil(self.IsFullscreenForTab)) | |
| 62 | |
| 63 # Bubble should be up prompting to allow fullscreen | |
| 64 self.assertTrue(self.IsFullscreenBubbleDisplayed()) | |
| 65 self.assertTrue(self.IsFullscreenBubbleDisplayingButtons()) | |
| 66 self.assertTrue(self.IsFullscreenPermissionRequested()) | |
| 67 | |
| 68 # Accept bubble, it should go away. | |
| 69 self.AcceptCurrentFullscreenOrMouseLockRequest() | |
| 70 self.assertTrue(self.WaitUntil( | |
| 71 lambda: not self.IsFullscreenBubbleDisplayingButtons())) | |
| 72 | |
| 73 # Try to lock mouse, it won't lock yet but permision will be requested. | |
| 74 self.assertFalse(self.IsMouseLocked()) | |
| 75 self._driver.find_element_by_id('lockMouse1').click() | |
| 76 self.assertTrue(self.WaitUntil(self.IsMouseLockPermissionRequested)) | |
| 77 self.assertFalse(self.IsMouseLocked()) | |
| 78 | |
| 79 # Deny mouse lock. | |
| 80 self.DenyCurrentFullscreenOrMouseLockRequest() | |
| 81 self.assertTrue(self.WaitUntil( | |
| 82 lambda: not self.IsFullscreenBubbleDisplayingButtons())) | |
| 83 self.assertFalse(self.IsMouseLocked()) | |
| 84 | |
| 85 # Try mouse lock again, and accept it. | |
| 86 self._driver.find_element_by_id('lockMouse1').click() | |
| 87 self.assertTrue(self.WaitUntil(self.IsMouseLockPermissionRequested)) | |
| 88 self.AcceptCurrentFullscreenOrMouseLockRequest() | |
| 89 self.assertTrue(self.WaitUntil(self.IsMouseLocked)) | |
| 90 | |
| 91 # The following doesn't work - as sending the key to the input field isn't | |
| 92 # picked up by the browser. :( Need an alternative way. | |
| 93 # | |
| 94 # # Ideally we wouldn't target a specific element, we'd just send keys to | |
| 95 # # whatever the current keyboard focus was. | |
| 96 # keys_target = driver.find_element_by_id('sendKeysTarget') | |
| 97 # | |
| 98 # # ESC key should exit fullscreen and mouse lock. | |
| 99 # | |
| 100 # print "# ESC key should exit fullscreen and mouse lock." | |
| 101 # keys_target.send_keys(Keys.ESCAPE) | |
| 102 # self.assertTrue(self.WaitUntil(lambda: not self.IsFullscreenForBrowser())) | |
| 103 # self.assertTrue(self.WaitUntil(lambda: not self.IsFullscreenForTab())) | |
| 104 # self.assertTrue(self.WaitUntil(lambda: not self.IsMouseLocked())) | |
| 105 # | |
| 106 # # Check we can go browser fullscreen | |
| 107 # print "# Check we can go browser fullscreen" | |
| 108 # keys_target.send_keys(Keys.F11) | |
| 109 # self.assertTrue(self.WaitUntil(self.IsFullscreenForBrowser)) | |
| 110 | |
| 111 def _LaunchFSAndExpectPrompt(self, button_action='enterFullscreen'): | |
| 112 """Helper function to launch fullscreen and expect a prompt. | |
| 113 | |
| 114 Fullscreen is initiated and a bubble prompt appears asking to allow or | |
| 115 cancel from fullscreen mode. The actual fullscreen mode doesn't take place | |
| 116 until after approving the prompt. | |
| 117 | |
| 118 If the helper is not successful then the test will fail. | |
| 119 | |
| 120 Args: | |
| 121 button_action: The button id to click to initiate an action. Default is to | |
| 122 click enterFullscreen. | |
| 123 """ | |
| 124 self.NavigateToURL(self.GetHttpURLForDataPath( | |
| 125 'fullscreen_mouselock', 'fullscreen_mouselock.html')) | |
| 126 # Should not be in fullscreen mode during initial launch. | |
| 127 self.assertFalse(self.IsFullscreenForBrowser()) | |
| 128 self.assertFalse(self.IsFullscreenForTab()) | |
| 129 # Go into fullscreen mode. | |
| 130 self._driver.find_element_by_id(button_action).click() | |
| 131 self.assertTrue(self.WaitUntil(self.IsFullscreenForTab)) | |
| 132 # Bubble should display prompting to allow fullscreen. | |
| 133 self.assertTrue(self.IsFullscreenPermissionRequested()) | |
| 134 | |
| 135 def _InitiateBrowserFullscreen(self): | |
| 136 """Helper function that initiates browser fullscreen.""" | |
| 137 self.NavigateToURL(self.GetHttpURLForDataPath( | |
| 138 'fullscreen_mouselock', 'fullscreen_mouselock.html')) | |
| 139 # Should not be in fullscreen mode during initial launch. | |
| 140 self.assertFalse(self.IsFullscreenForBrowser()) | |
| 141 self.assertFalse(self.IsFullscreenForTab()) | |
| 142 # Initiate browser fullscreen. | |
| 143 self.ApplyAccelerator(pyauto.IDC_FULLSCREEN) | |
| 144 self.assertTrue(self.WaitUntil(self.IsFullscreenForBrowser)) | |
| 145 self.assertTrue(self.WaitUntil(lambda: not self.IsFullscreenForTab())) | |
| 146 self.assertTrue(self.WaitUntil(lambda: not self.IsMouseLocked())) | |
| 147 | |
| 148 def _InitiateTabFullscreen(self): | |
| 149 """Helper function that initiates tab fullscreen.""" | |
| 150 self.NavigateToURL(self.GetHttpURLForDataPath( | |
| 151 'fullscreen_mouselock', 'fullscreen_mouselock.html')) | |
| 152 # Initiate tab fullscreen. | |
| 153 self._driver.find_element_by_id('enterFullscreen').click() | |
| 154 self.assertTrue(self.WaitUntil(self.IsFullscreenForTab)) | |
| 155 | |
| 156 def _AcceptFullscreenOrMouseLockRequest(self): | |
| 157 """Helper function to accept fullscreen or mouse lock request.""" | |
| 158 self.AcceptCurrentFullscreenOrMouseLockRequest() | |
| 159 self.assertTrue(self.WaitUntil( | |
| 160 lambda: not self.IsFullscreenBubbleDisplayingButtons())) | |
| 161 | |
| 162 def _EnableFullscreenAndMouseLockMode(self): | |
| 163 """Helper function to enable fullscreen and mouse lock mode.""" | |
| 164 self._LaunchFSAndExpectPrompt(button_action='enterFullscreenAndLockMouse1') | |
| 165 # Allow fullscreen. | |
| 166 self.AcceptCurrentFullscreenOrMouseLockRequest() | |
| 167 # The wait is needed due to crbug.com/123396. Should be able to click the | |
| 168 # fullscreen and mouselock button and be both accepted in a single action. | |
| 169 self.assertTrue(self.WaitUntil(self.IsMouseLockPermissionRequested)) | |
| 170 # Allow mouse lock. | |
| 171 self.AcceptCurrentFullscreenOrMouseLockRequest() | |
| 172 self.assertTrue(self.WaitUntil(self.IsMouseLocked)) | |
| 173 | |
| 174 def _EnableMouseLockMode(self, button_action='lockMouse1'): | |
| 175 """Helper function to enable mouse lock mode. | |
| 176 | |
| 177 Args: | |
| 178 button_action: The button id to click to initiate an action. Default is to | |
| 179 click lockMouse1. | |
| 180 """ | |
| 181 self._driver.find_element_by_id(button_action).click() | |
| 182 self.assertTrue(self.WaitUntil(self.IsMouseLockPermissionRequested)) | |
| 183 self.AcceptCurrentFullscreenOrMouseLockRequest() | |
| 184 self.assertTrue(self.IsMouseLocked()) | |
| 185 | |
| 186 def _EnableAndReturnLockMouseResult(self): | |
| 187 """Helper function to enable and return mouse lock result.""" | |
| 188 self.NavigateToURL(self.GetHttpURLForDataPath( | |
| 189 'fullscreen_mouselock', 'fullscreen_mouselock.html')) | |
| 190 self._driver.find_element_by_id('lockMouse2').click() | |
| 191 self.assertTrue( | |
| 192 self.WaitUntil(self.IsMouseLockPermissionRequested)) | |
| 193 self.AcceptCurrentFullscreenOrMouseLockRequest() | |
| 194 # Waits until lock_result gets 'success' or 'failure'. | |
| 195 return self._driver.execute_script('return lock_result') | |
| 196 | |
| 197 def _ClickAnchorLink(self): | |
| 198 """Clicks the anchor link until it's successfully clicked. | |
| 199 | |
| 200 Clicks on the anchor link and compares the js |clicked_elem_ID| variabled | |
| 201 with the anchor id. Returns True if the link is clicked. | |
| 202 """ | |
| 203 element_id = 'anchor' | |
| 204 # Catch WebDriverException: u'Element is not clickable at point (185.5, | |
| 205 # 669.5). Instead another element would receive the click. | |
| 206 try: | |
| 207 self._driver.find_element_by_id(element_id).click() | |
| 208 except WebDriverException: | |
| 209 return False | |
| 210 return self._driver.execute_script('return clicked_elem_ID') == element_id | |
| 211 | |
| 212 def testPrefsForFullscreenAllowed(self): | |
| 213 """Verify prefs when fullscreen is allowed.""" | |
| 214 self._LaunchFSAndExpectPrompt() | |
| 215 self._AcceptFullscreenOrMouseLockRequest() | |
| 216 content_settings = ( | |
| 217 self.GetPrefsInfo().Prefs()['profile']['content_settings']) | |
| 218 self.assertEqual( | |
| 219 {self._hostname_pattern + ',*': {'fullscreen': 1}}, # Allow hostname. | |
| 220 content_settings['pattern_pairs'], | |
| 221 msg='Saved hostname pattern does not match expected pattern.') | |
| 222 | |
| 223 def testPrefsForFullscreenExit(self): | |
| 224 """Verify prefs is empty when exit fullscreen mode before allowing.""" | |
| 225 self._LaunchFSAndExpectPrompt() | |
| 226 self._driver.find_element_by_id('exitFullscreen').click() | |
| 227 # Verify exit from fullscreen mode. | |
| 228 self.assertTrue(self.WaitUntil(lambda: not self.IsFullscreenForTab())) | |
| 229 content_settings = ( | |
| 230 self.GetPrefsInfo().Prefs()['profile']['content_settings']) | |
| 231 self.assertEqual( | |
| 232 {}, content_settings['pattern_pairs'], | |
| 233 msg='Patterns saved when there should be none.') | |
| 234 | |
| 235 def testPatternsForFSAndML(self): | |
| 236 """Verify hostname pattern and behavior for allowed mouse cursor lock. | |
| 237 | |
| 238 To lock the mouse, the browser needs to be in fullscreen mode. | |
| 239 """ | |
| 240 self._EnableFullscreenAndMouseLockMode() | |
| 241 self._EnableMouseLockMode() | |
| 242 expected_pattern = ( | |
| 243 {self._hostname_pattern + ',*': {'fullscreen': 1, 'mouselock': 1}}) | |
| 244 content_settings = ( | |
| 245 self.GetPrefsInfo().Prefs()['profile']['content_settings']) | |
| 246 self.assertEqual( | |
| 247 expected_pattern, content_settings['pattern_pairs'], | |
| 248 msg='Saved hostname and behavior patterns do not match expected.') | |
| 249 | |
| 250 def testPatternsForAllowMouseLock(self): | |
| 251 """Verify hostname pattern and behavior for allowed mouse cursor lock. | |
| 252 | |
| 253 Enable fullscreen mode and enable mouse lock separately. | |
| 254 """ | |
| 255 self._LaunchFSAndExpectPrompt() | |
| 256 self.AcceptCurrentFullscreenOrMouseLockRequest() | |
| 257 self._EnableMouseLockMode() | |
| 258 expected_pattern = ( | |
| 259 {self._hostname_pattern + ',*': {'fullscreen': 1, 'mouselock': 1}}) | |
| 260 content_settings = ( | |
| 261 self.GetPrefsInfo().Prefs()['profile']['content_settings']) | |
| 262 self.assertEqual( | |
| 263 expected_pattern, content_settings['pattern_pairs'], | |
| 264 msg='Saved hostname and behavior patterns do not match expected.') | |
| 265 | |
| 266 def testNoMouseLockRequest(self): | |
| 267 """Verify mouse lock request does not appear. | |
| 268 | |
| 269 When allowing all sites to disable the mouse cursor, the mouse lock request | |
| 270 bubble should not show. The mouse cursor should be automatically disabled | |
| 271 when clicking on a disable mouse button. | |
| 272 """ | |
| 273 # Allow all sites to disable mouse cursor. | |
| 274 self.SetPrefs(pyauto.kDefaultContentSettings, {u'mouselock': 1}) | |
| 275 self._LaunchFSAndExpectPrompt() | |
| 276 # Allow for fullscreen mode. | |
| 277 self._AcceptFullscreenOrMouseLockRequest() | |
| 278 self._driver.set_script_timeout(2) | |
| 279 # Receive callback status (success or failure) from javascript that the | |
| 280 # click has registered and the mouse lock status has changed. | |
| 281 lock_result = self._driver.execute_async_script( | |
| 282 'lockMouse1(arguments[arguments.length - 1])') | |
| 283 self.assertEqual(lock_result, 'success', msg='Mouse lock unsuccessful.') | |
| 284 self.assertTrue(self.WaitUntil( | |
| 285 lambda: not self.IsMouseLockPermissionRequested())) | |
| 286 self.assertTrue(self.IsMouseLocked()) | |
| 287 | |
| 288 def testUnableToLockMouse(self): | |
| 289 """Verify mouse lock is disabled. | |
| 290 | |
| 291 When not allowing any site to disable the mouse cursor, the mouse lock | |
| 292 request bubble should not show and the mouse cursor should not be disabled. | |
| 293 """ | |
| 294 # Do not allow any site to disable mouse cursor. | |
| 295 self.SetPrefs(pyauto.kDefaultContentSettings, {u'mouselock': 2}) | |
| 296 self._LaunchFSAndExpectPrompt() | |
| 297 # Allow for fullscreen mode. | |
| 298 self._AcceptFullscreenOrMouseLockRequest() | |
| 299 self._driver.set_script_timeout(2) | |
| 300 # Receive callback status (success or failure) from javascript that the | |
| 301 # click has registered and the mouse lock status has changed. | |
| 302 lock_result = self._driver.execute_async_script( | |
| 303 'lockMouse1(arguments[arguments.length - 1])') | |
| 304 self.assertEqual(lock_result, 'failure', msg='Mouse locked unexpectedly.') | |
| 305 self.assertTrue(self.WaitUntil( | |
| 306 lambda: not self.IsMouseLockPermissionRequested())) | |
| 307 self.assertTrue(self.WaitUntil(lambda: not self.IsMouseLocked())) | |
| 308 | |
| 309 def testEnterTabFSWhileInBrowserFS(self): | |
| 310 """Verify able to enter into tab fullscreen while in browser fullscreen.""" | |
| 311 self._InitiateBrowserFullscreen() | |
| 312 # Initiate tab fullscreen. | |
| 313 self._driver.find_element_by_id('enterFullscreen').click() | |
| 314 self.assertTrue(self.WaitUntil(lambda: self.IsFullscreenForTab())) | |
| 315 self.assertTrue(self.WaitUntil(lambda: not self.IsMouseLocked())) | |
| 316 | |
| 317 def testMouseLockInBrowserFS(self): | |
| 318 """Verify mouse lock in browser fullscreen requires allow prompt.""" | |
| 319 self._InitiateBrowserFullscreen() | |
| 320 self._driver.set_script_timeout(2) | |
| 321 self._driver.execute_script('lockMouse1AndSetLockResult()') | |
| 322 # Bubble should display prompting to allow mouselock. | |
| 323 self.assertTrue(self.WaitUntil(self.IsMouseLockPermissionRequested)) | |
| 324 self.AcceptCurrentFullscreenOrMouseLockRequest() | |
| 325 # Waits until lock_result gets 'success' or 'failure'. | |
| 326 lock_result = self._driver.execute_script('return lock_result') | |
| 327 self.assertEqual(lock_result, 'success', | |
| 328 msg='Mouse was not locked in browser fullscreen.') | |
| 329 | |
| 330 def testNoMouseLockWhenCancelFS(self): | |
| 331 """Verify mouse lock breaks when canceling tab fullscreen. | |
| 332 | |
| 333 This test uses javascript to initiate exit of tab fullscreen after mouse | |
| 334 lock success callback. | |
| 335 """ | |
| 336 self._LaunchFSAndExpectPrompt() | |
| 337 self._driver.set_script_timeout(2) | |
| 338 lock_result = self._driver.execute_script('lockMouse1AndSetLockResult()') | |
| 339 self.assertTrue( | |
| 340 self.WaitUntil(lambda: self.IsMouseLockPermissionRequested())) | |
| 341 self.AcceptCurrentFullscreenOrMouseLockRequest() | |
| 342 self.assertTrue(self.WaitUntil(self.IsMouseLocked)) | |
| 343 # Waits until lock_result gets 'success' or 'failure'. | |
| 344 lock_result = self._driver.execute_script('return lock_result') | |
| 345 self.assertEqual( | |
| 346 lock_result, 'success', msg='Mouse is not locked.') | |
| 347 self._driver.execute_script('document.webkitCancelFullScreen()') | |
| 348 self.assertTrue(self.WaitUntil(lambda: not self.IsFullscreenForTab()), | |
| 349 msg='Tab is still in fullscreen.') | |
| 350 self.assertTrue(self.WaitUntil(lambda: not self.IsMouseLocked()), | |
| 351 msg='Mouse is still locked after exiting fullscreen.') | |
| 352 | |
| 353 def testNoTabFSExitWhenJSExitMouseLock(self): | |
| 354 """Verify tab fullscreen does not exit when javascript init mouse lock exit. | |
| 355 | |
| 356 This test uses javascript to initiate exit of mouse lock after mouse | |
| 357 lock success callback. | |
| 358 """ | |
| 359 self._LaunchFSAndExpectPrompt() | |
| 360 self._EnableMouseLockMode() | |
| 361 self._driver.execute_script('navigator.webkitPointer.unlock()') | |
| 362 self.WaitUntil(lambda: not self.IsMouseLocked()) | |
| 363 self.assertTrue(self.IsFullscreenForTab(), msg='Tab fullscreen was lost.') | |
| 364 | |
| 365 def testMouseLockExitWhenAlertDialogShow(self): | |
| 366 """Verify mouse lock breaks when alert dialog appears.""" | |
| 367 self._LaunchFSAndExpectPrompt() | |
| 368 self._EnableMouseLockMode() | |
| 369 # Need to catch the exception here since the alert dialog raises | |
| 370 # a WebDriverException due to a modal dialog. | |
| 371 from selenium.common.exceptions import WebDriverException | |
| 372 try: | |
| 373 self._driver.execute_script('alert("A modal dialog")') | |
| 374 except WebDriverException: | |
| 375 pass | |
| 376 | |
| 377 self.assertTrue(self.WaitUntil(lambda: self.IsFullscreenForTab()), | |
| 378 msg='Tab fullscreen was lost.') | |
| 379 self.assertTrue(self.WaitUntil(lambda: not self.IsMouseLocked()), | |
| 380 msg='Mouse is still locked') | |
| 381 | |
| 382 def testMouseLockExitWhenBrowserLoseFocus(self): | |
| 383 """Verify mouse lock breaks when browser loses focus. | |
| 384 | |
| 385 Mouse lock breaks when the focus is placed on another new window. | |
| 386 """ | |
| 387 self._LaunchFSAndExpectPrompt() | |
| 388 self.AcceptCurrentFullscreenOrMouseLockRequest() | |
| 389 # Open a new window to shift focus away. | |
| 390 self.OpenNewBrowserWindow(True) | |
| 391 self.assertTrue(self.WaitUntil(lambda: self.IsFullscreenForTab())) | |
| 392 self.assertTrue(self.WaitUntil(lambda: not self.IsMouseLocked()), | |
| 393 msg='Mouse lock did not break when browser lost focus.') | |
| 394 | |
| 395 def testMouseLockLostOnReload(self): | |
| 396 """Verify mouse lock is lost on page reload.""" | |
| 397 self.NavigateToURL(self.GetHttpURLForDataPath( | |
| 398 'fullscreen_mouselock', 'fullscreen_mouselock.html')) | |
| 399 self._EnableMouseLockMode() | |
| 400 self.ReloadActiveTab() | |
| 401 self.assertTrue(self.WaitUntil(lambda: not self.IsMouseLocked()), | |
| 402 msg='Mouse lock did not break when page is reloaded.') | |
| 403 | |
| 404 def testNoMLBubbleWhenTabLoseFocus(self): | |
| 405 """Verify mouse lock bubble goes away when tab loses focus.""" | |
| 406 self.NavigateToURL(self.GetHttpURLForDataPath( | |
| 407 'fullscreen_mouselock', 'fullscreen_mouselock.html')) | |
| 408 self._driver.find_element_by_id('lockMouse1').click() | |
| 409 self.assertTrue(self.WaitUntil(self.IsMouseLockPermissionRequested)) | |
| 410 self.AppendTab(pyauto.GURL('chrome://newtab')) | |
| 411 self.assertTrue(self.WaitUntil( | |
| 412 lambda: not self.IsFullscreenBubbleDisplayingButtons()), | |
| 413 msg='Mouse lock bubble did not clear when tab lost focus.') | |
| 414 | |
| 415 def testTabFSExitWhenNavBackToPrevPage(self): | |
| 416 """Verify tab fullscreen exit when navigating back to previous page. | |
| 417 | |
| 418 This test navigates to a new page while in tab fullscreen mode by using | |
| 419 GoBack() to navigate to the previous google.html page. | |
| 420 """ | |
| 421 self.NavigateToURL(self.GetHttpURLForDataPath('google', 'google.html')) | |
| 422 self._InitiateTabFullscreen() | |
| 423 self.TabGoBack() | |
| 424 self.assertFalse( | |
| 425 self.IsFullscreenForTab(), | |
| 426 msg='Tab fullscreen did not exit when navigating to a new page.') | |
| 427 | |
| 428 def testTabFSExitWhenNavToNewPage(self): | |
| 429 """Verify tab fullscreen exit when navigating to a new website. | |
| 430 | |
| 431 This test navigates to a new website while in tab fullscreen. | |
| 432 """ | |
| 433 self._InitiateTabFullscreen() | |
| 434 self.NavigateToURL(self.GetHttpURLForDataPath('google', 'google.html')) | |
| 435 self.assertFalse( | |
| 436 self.IsFullscreenForTab(), | |
| 437 msg='Tab fullscreen did not exit when navigating to a new website.') | |
| 438 | |
| 439 def testTabFSDoesNotExitForAnchorLinks(self): | |
| 440 """Verify tab fullscreen does not exit for anchor links. | |
| 441 | |
| 442 Tab fullscreen should not exit when following a link to the same page such | |
| 443 as example.html#anchor. | |
| 444 """ | |
| 445 self._InitiateTabFullscreen() | |
| 446 self.assertTrue(self.WaitUntil(self._ClickAnchorLink)) | |
| 447 self.assertTrue( | |
| 448 self.WaitUntil(self.IsFullscreenForTab), | |
| 449 msg='Tab fullscreen should not exit when clicking on an anchor link.') | |
| 450 | |
| 451 def testMLExitWhenNavBackToPrevPage(self): | |
| 452 """Verify mouse lock exit when navigating back to previous page. | |
| 453 | |
| 454 This test navigates to a new page while mouse lock is activated by using | |
| 455 GoBack() to navigate to the previous google.html page. | |
| 456 """ | |
| 457 self.NavigateToURL(self.GetHttpURLForDataPath('google', 'google.html')) | |
| 458 lock_result = self._EnableAndReturnLockMouseResult() | |
| 459 self.assertEqual( | |
| 460 lock_result, 'success', msg='Mouse is not locked.') | |
| 461 self.TabGoBack() | |
| 462 self.assertFalse( | |
| 463 self.IsMouseLocked(), | |
| 464 msg='Mouse lock did not exit when navigating to the prev page.') | |
| 465 | |
| 466 def testMLExitWhenNavToNewPage(self): | |
| 467 """Verify mouse lock exit when navigating to a new website.""" | |
| 468 lock_result = self._EnableAndReturnLockMouseResult() | |
| 469 self.assertEqual( | |
| 470 lock_result, 'success', msg='Mouse is not locked.') | |
| 471 self.NavigateToURL(self.GetHttpURLForDataPath('google', 'google.html')) | |
| 472 self.assertFalse( | |
| 473 self.IsMouseLocked(), | |
| 474 msg='Mouse lock did not exit when navigating to a new website.') | |
| 475 | |
| 476 def testMLDoesNotExitForAnchorLinks(self): | |
| 477 """Verify mouse lock does not exit for anchor links. | |
| 478 | |
| 479 Mouse lock should not exist when following a link to the same page such as | |
| 480 example.html#anchor. | |
| 481 """ | |
| 482 lock_result = self._EnableAndReturnLockMouseResult() | |
| 483 self.assertEqual( | |
| 484 lock_result, 'success', msg='Mouse is not locked.') | |
| 485 ActionChains(self._driver).move_to_element( | |
| 486 self._driver.find_element_by_id('anchor')).click().perform() | |
| 487 self.assertTrue(self.WaitUntil(self.IsMouseLocked), | |
| 488 msg='Mouse lock broke when clicking on an anchor link.') | |
| 489 | |
| 490 def ExitTabFSToBrowserFS(self): | |
| 491 """Verify exiting tab fullscreen leaves browser in browser fullscreen. | |
| 492 | |
| 493 This test is semi-automated. | |
| 494 | |
| 495 The browser initiates browser fullscreen, then initiates tab fullscreen. The | |
| 496 test verifies that existing tab fullscreen by simulating ESC key press or | |
| 497 clicking the js function to exitFullscreen() will exit the tab fullscreen | |
| 498 leaving browser fullscreen intact. | |
| 499 """ | |
| 500 self._InitiateBrowserFullscreen() | |
| 501 # Initiate tab fullscreen. | |
| 502 self._driver.find_element_by_id('enterFullscreen').click() | |
| 503 self.assertTrue(self.WaitUntil(lambda: self.IsFullscreenForTab())) | |
| 504 # Require manual intervention to send ESC key due to crbug.com/123930. | |
| 505 # TODO(dyu): Update to a full test once associated bug is fixed. | |
| 506 logging.info('Press ESC key to exit tab fullscreen.') | |
| 507 time.sleep(5) | |
| 508 self.assertTrue(self.WaitUntil(lambda: not self.IsFullscreenForTab())) | |
| 509 self.assertTrue(self.WaitUntil(lambda: self.IsFullscreenForBrowser()), | |
| 510 msg='Not in browser fullscreen mode.') | |
| 511 | |
| 512 self._driver.find_element_by_id('enterFullscreen').click() | |
| 513 self.assertTrue(self.WaitUntil(lambda: self.IsFullscreenForTab())) | |
| 514 # Exit tab fullscreen by clicking button exitFullscreen(). | |
| 515 self._driver.find_element_by_id('exitFullscreen').click() | |
| 516 self.assertTrue(self.WaitUntil(lambda: not self.IsFullscreenForTab())) | |
| 517 self.assertTrue(self.WaitUntil(lambda: self.IsFullscreenForBrowser()), | |
| 518 msg='Not in browser fullscreen mode.') | |
| 519 | |
| 520 def F11KeyExitsTabAndBrowserFS(self): | |
| 521 """Verify existing tab fullscreen exits all fullscreen modes. | |
| 522 | |
| 523 This test is semi-automated. | |
| 524 | |
| 525 The browser initiates browser fullscreen, then initiates tab fullscreen. The | |
| 526 test verifies that existing tab fullscreen by simulating F11 key press or | |
| 527 CMD + SHIFT + F keys on the Mac will exit the tab fullscreen and the | |
| 528 browser fullscreen. | |
| 529 """ | |
| 530 self._InitiateBrowserFullscreen() | |
| 531 # Initiate tab fullscreen. | |
| 532 self._driver.find_element_by_id('enterFullscreen').click() | |
| 533 self.assertTrue(self.WaitUntil(lambda: self.IsFullscreenForTab())) | |
| 534 # Require manual intervention to send F11 key due to crbug.com/123930. | |
| 535 # TODO(dyu): Update to a full test once associated bug is fixed. | |
| 536 logging.info('Press F11 key to exit tab fullscreen.') | |
| 537 time.sleep(5) | |
| 538 self.assertTrue(self.WaitUntil(lambda: not self.IsFullscreenForTab())) | |
| 539 self.assertTrue(self.WaitUntil(lambda: not self.IsFullscreenForBrowser()), | |
| 540 msg='Browser is in fullscreen mode.') | |
| 541 | |
| 542 def SearchForTextOutsideOfContainer(self): | |
| 543 """Verify text outside of container is not visible when fullscreen. | |
| 544 | |
| 545 This test is semi-automated. | |
| 546 | |
| 547 Verify this test manually until there is a way to find text on screen | |
| 548 without using FindInPage(). | |
| 549 | |
| 550 The text that is outside of the fullscreen container should only be visible | |
| 551 when fullscreen is off. The text should not be visible while in fullscreen | |
| 552 mode. | |
| 553 """ | |
| 554 self.NavigateToURL(self.GetHttpURLForDataPath( | |
| 555 'fullscreen_mouselock', 'fullscreen_mouselock.html')) | |
| 556 # Should not be in fullscreen mode during initial launch. | |
| 557 self.assertFalse(self.IsFullscreenForBrowser()) | |
| 558 self.assertFalse(self.IsFullscreenForTab()) | |
| 559 self.assertTrue( | |
| 560 self.WaitUntil(lambda: self.FindInPage( | |
| 561 'This text is outside of the container')['match_count'], | |
| 562 expect_retval=1)) | |
| 563 # Go into fullscreen mode. | |
| 564 self._driver.find_element_by_id('enterFullscreen').click() | |
| 565 self.assertTrue(self.WaitUntil(self.IsFullscreenForTab)) | |
| 566 time.sleep(5) | |
| 567 # TODO(dyu): find a way to verify on screen text instead of using | |
| 568 # FindInPage() which searches for text in the HTML. | |
| 569 | |
| 570 def SameMouseLockMovement(self): | |
| 571 """Verify the correct feel of mouse movement data when mouse is locked. | |
| 572 | |
| 573 This test is semi-automated. | |
| 574 | |
| 575 This test loads the same web page in two different tabs while in mouse lock | |
| 576 mode. Each tab loads the web page from a different URL (e.g. by loading it | |
| 577 from a localhost server and a file url). The test verifies | |
| 578 that the mouse lock movements work the same in both | |
| 579 tabs. | |
| 580 """ | |
| 581 url1 = self.GetHttpURLForDataPath( | |
| 582 'fullscreen_mouselock', 'fullscreen_mouselock.html') | |
| 583 url2 = self.GetFileURLForDataPath( | |
| 584 'fullscreen_mouselock', 'fullscreen_mouselock.html') | |
| 585 tab2 = 'f1-4' | |
| 586 self.NavigateToURL(url1) | |
| 587 self.RunCommand(pyauto.IDC_NEW_TAB) # Open new tab. | |
| 588 self.NavigateToURL(url2, 0, 1) | |
| 589 self._driver.switch_to_window(tab2) | |
| 590 self._EnableMouseLockMode() # Lock mouse in tab 2. | |
| 591 raw_input('Manually move the mouse cursor on the page in tab 2. Shift+Tab \ | |
| 592 into tab 1, click on lockMouse1() button, and move the mouse \ | |
| 593 cursor on the page in tab 1. Verify mouse movement is smooth.') | |
| 594 | |
| 595 def MouseEventsIndependentOfExitBubble(self): | |
| 596 """Verify mouse events are independent of the exit FS exit bubble for ML. | |
| 597 | |
| 598 Mouse movement events should work immediately when mouse lock is activated. | |
| 599 The events should not be blocked waiting for the exit instruction bubble to | |
| 600 clear. | |
| 601 """ | |
| 602 self.NavigateToURL(self.GetHttpURLForDataPath( | |
| 603 'fullscreen_mouselock', 'fullscreen_mouselock.html')) | |
| 604 # Should not be in fullscreen mode during initial launch. | |
| 605 self.assertFalse(self.IsFullscreenForBrowser()) | |
| 606 self.assertFalse(self.IsFullscreenForTab()) | |
| 607 # Go into fullscreen mode. | |
| 608 self._driver.find_element_by_id('enterFullscreen').click() | |
| 609 self.assertTrue(self.WaitUntil(self.IsFullscreenForTab)) | |
| 610 self._EnableMouseLockMode() | |
| 611 raw_input( | |
| 612 '1. Move the mouse, see movement data being received by the page.\ | |
| 613 2. Press ESC key.\ | |
| 614 3. Lock the mouse without going fullscreen. Click lockMouse1() button.\ | |
| 615 Verify: The mouse movement events should work immediately.') | |
| 616 | |
| 617 if __name__ == '__main__': | |
| 618 pyauto_functional.Main() | |
| OLD | NEW |