OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 import logging | 6 import logging |
7 import os | 7 import os |
8 import re | 8 import re |
9 import shutil | 9 import shutil |
10 import time | 10 import time |
11 | 11 |
12 import pyauto_functional # Must be imported before pyauto | 12 import pyauto_functional # Must be imported before pyauto |
13 import pyauto | 13 import pyauto |
14 import test_utils | 14 import test_utils |
| 15 from selenium.webdriver.common.action_chains import ActionChains |
| 16 from selenium.common.exceptions import WebDriverException |
15 from selenium.webdriver.common.keys import Keys | 17 from selenium.webdriver.common.keys import Keys |
16 from webdriver_pages import settings | 18 from webdriver_pages import settings |
17 | 19 |
18 | 20 |
19 class FullscreenMouselockTest(pyauto.PyUITest): | 21 class FullscreenMouselockTest(pyauto.PyUITest): |
20 """TestCase for Fullscreen and Mouse Lock.""" | 22 """TestCase for Fullscreen and Mouse Lock.""" |
21 | 23 |
22 def setUp(self): | 24 def setUp(self): |
23 pyauto.PyUITest.setUp(self) | 25 pyauto.PyUITest.setUp(self) |
24 self._driver = self.NewWebDriver() | 26 self._driver = self.NewWebDriver() |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 'fullscreen_mouselock', 'fullscreen_mouselock.html')) | 138 'fullscreen_mouselock', 'fullscreen_mouselock.html')) |
137 # Should not be in fullscreen mode during initial launch. | 139 # Should not be in fullscreen mode during initial launch. |
138 self.assertFalse(self.IsFullscreenForBrowser()) | 140 self.assertFalse(self.IsFullscreenForBrowser()) |
139 self.assertFalse(self.IsFullscreenForTab()) | 141 self.assertFalse(self.IsFullscreenForTab()) |
140 # Initiate browser fullscreen. | 142 # Initiate browser fullscreen. |
141 self.ApplyAccelerator(pyauto.IDC_FULLSCREEN) | 143 self.ApplyAccelerator(pyauto.IDC_FULLSCREEN) |
142 self.assertTrue(self.WaitUntil(self.IsFullscreenForBrowser)) | 144 self.assertTrue(self.WaitUntil(self.IsFullscreenForBrowser)) |
143 self.assertTrue(self.WaitUntil(lambda: not self.IsFullscreenForTab())) | 145 self.assertTrue(self.WaitUntil(lambda: not self.IsFullscreenForTab())) |
144 self.assertTrue(self.WaitUntil(lambda: not self.IsMouseLocked())) | 146 self.assertTrue(self.WaitUntil(lambda: not self.IsMouseLocked())) |
145 | 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 |
146 def _AcceptFullscreenOrMouseLockRequest(self): | 156 def _AcceptFullscreenOrMouseLockRequest(self): |
147 """Helper function to accept fullscreen or mouse lock request.""" | 157 """Helper function to accept fullscreen or mouse lock request.""" |
148 self.AcceptCurrentFullscreenOrMouseLockRequest() | 158 self.AcceptCurrentFullscreenOrMouseLockRequest() |
149 self.assertTrue(self.WaitUntil( | 159 self.assertTrue(self.WaitUntil( |
150 lambda: not self.IsFullscreenBubbleDisplayingButtons())) | 160 lambda: not self.IsFullscreenBubbleDisplayingButtons())) |
151 | 161 |
152 def _EnableFullscreenAndMouseLockMode(self): | 162 def _EnableFullscreenAndMouseLockMode(self): |
153 """Helper function to enable fullscreen and mouse lock mode.""" | 163 """Helper function to enable fullscreen and mouse lock mode.""" |
154 self._LaunchFSAndExpectPrompt(button_action='enterFullscreenAndLockMouse1') | 164 self._LaunchFSAndExpectPrompt(button_action='enterFullscreenAndLockMouse1') |
155 # Allow fullscreen. | 165 # Allow fullscreen. |
(...skipping 10 matching lines...) Expand all Loading... |
166 | 176 |
167 Args: | 177 Args: |
168 button_action: The button id to click to initiate an action. Default is to | 178 button_action: The button id to click to initiate an action. Default is to |
169 click lockMouse1. | 179 click lockMouse1. |
170 """ | 180 """ |
171 self._driver.find_element_by_id(button_action).click() | 181 self._driver.find_element_by_id(button_action).click() |
172 self.assertTrue(self.WaitUntil(self.IsMouseLockPermissionRequested)) | 182 self.assertTrue(self.WaitUntil(self.IsMouseLockPermissionRequested)) |
173 self.AcceptCurrentFullscreenOrMouseLockRequest() | 183 self.AcceptCurrentFullscreenOrMouseLockRequest() |
174 self.assertTrue(self.IsMouseLocked()) | 184 self.assertTrue(self.IsMouseLocked()) |
175 | 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 |
176 def testPrefsForFullscreenAllowed(self): | 212 def testPrefsForFullscreenAllowed(self): |
177 """Verify prefs when fullscreen is allowed.""" | 213 """Verify prefs when fullscreen is allowed.""" |
178 self._LaunchFSAndExpectPrompt() | 214 self._LaunchFSAndExpectPrompt() |
179 self._AcceptFullscreenOrMouseLockRequest() | 215 self._AcceptFullscreenOrMouseLockRequest() |
180 content_settings = ( | 216 content_settings = ( |
181 self.GetPrefsInfo().Prefs()['profile']['content_settings']) | 217 self.GetPrefsInfo().Prefs()['profile']['content_settings']) |
182 self.assertEqual( | 218 self.assertEqual( |
183 {self._hostname_pattern + ',*': {'fullscreen': 1}}, # Allow hostname. | 219 {self._hostname_pattern + ',*': {'fullscreen': 1}}, # Allow hostname. |
184 content_settings['pattern_pairs'], | 220 content_settings['pattern_pairs'], |
185 msg='Saved hostname pattern does not match expected pattern.') | 221 msg='Saved hostname pattern does not match expected pattern.') |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
368 """Verify mouse lock bubble goes away when tab loses focus.""" | 404 """Verify mouse lock bubble goes away when tab loses focus.""" |
369 self.NavigateToURL(self.GetHttpURLForDataPath( | 405 self.NavigateToURL(self.GetHttpURLForDataPath( |
370 'fullscreen_mouselock', 'fullscreen_mouselock.html')) | 406 'fullscreen_mouselock', 'fullscreen_mouselock.html')) |
371 self._driver.find_element_by_id('lockMouse1').click() | 407 self._driver.find_element_by_id('lockMouse1').click() |
372 self.assertTrue(self.WaitUntil(self.IsMouseLockPermissionRequested)) | 408 self.assertTrue(self.WaitUntil(self.IsMouseLockPermissionRequested)) |
373 self.AppendTab(pyauto.GURL('chrome://newtab')) | 409 self.AppendTab(pyauto.GURL('chrome://newtab')) |
374 self.assertTrue(self.WaitUntil( | 410 self.assertTrue(self.WaitUntil( |
375 lambda: not self.IsFullscreenBubbleDisplayingButtons()), | 411 lambda: not self.IsFullscreenBubbleDisplayingButtons()), |
376 msg='Mouse lock bubble did not clear when tab lost focus.') | 412 msg='Mouse lock bubble did not clear when tab lost focus.') |
377 | 413 |
| 414 def testTabFSExitWhenNavBackToPrevPage(self): |
| 415 """Verify tab fullscreen exit when navigating back to previous page. |
| 416 |
| 417 This test navigates to a new page while in tab fullscreen mode by using |
| 418 GoBack() to navigate to the previous google.html page. |
| 419 """ |
| 420 self.NavigateToURL(self.GetHttpURLForDataPath('google', 'google.html')) |
| 421 self._InitiateTabFullscreen() |
| 422 self.GetBrowserWindow().GetTab().GoBack() |
| 423 self.assertFalse( |
| 424 self.IsFullscreenForTab(), |
| 425 msg='Tab fullscreen did not exit when navigating to a new page.') |
| 426 |
| 427 def testTabFSExitWhenNavToNewPage(self): |
| 428 """Verify tab fullscreen exit when navigating to a new website. |
| 429 |
| 430 This test navigates to a new website while in tab fullscreen. |
| 431 """ |
| 432 self._InitiateTabFullscreen() |
| 433 self.NavigateToURL(self.GetHttpURLForDataPath('google', 'google.html')) |
| 434 self.assertFalse( |
| 435 self.IsFullscreenForTab(), |
| 436 msg='Tab fullscreen did not exit when navigating to a new website.') |
| 437 |
| 438 def testTabFSDoesNotExitForAnchorLinks(self): |
| 439 """Verify tab fullscreen does not exit for anchor links. |
| 440 |
| 441 Tab fullscreen should not exit when following a link to the same page such |
| 442 as example.html#anchor. |
| 443 """ |
| 444 self._InitiateTabFullscreen() |
| 445 self.assertTrue(self.WaitUntil(self._ClickAnchorLink)) |
| 446 self.assertTrue( |
| 447 self.WaitUntil(self.IsFullscreenForTab), |
| 448 msg='Tab fullscreen should not exit when clicking on an anchor link.') |
| 449 |
| 450 def testMLExitWhenNavBackToPrevPage(self): |
| 451 """Verify mouse lock exit when navigating back to previous page. |
| 452 |
| 453 This test navigates to a new page while mouse lock is activated by using |
| 454 GoBack() to navigate to the previous google.html page. |
| 455 """ |
| 456 self.NavigateToURL(self.GetHttpURLForDataPath('google', 'google.html')) |
| 457 lock_result = self._EnableAndReturnLockMouseResult() |
| 458 self.assertEqual( |
| 459 lock_result, 'success', msg='Mouse is not locked.') |
| 460 self.GetBrowserWindow().GetTab().GoBack() |
| 461 self.assertFalse( |
| 462 self.IsMouseLocked(), |
| 463 msg='Mouse lock did not exit when navigating to the prev page.') |
| 464 |
| 465 def testMLExitWhenNavToNewPage(self): |
| 466 """Verify mouse lock exit when navigating to a new website.""" |
| 467 lock_result = self._EnableAndReturnLockMouseResult() |
| 468 self.assertEqual( |
| 469 lock_result, 'success', msg='Mouse is not locked.') |
| 470 self.NavigateToURL(self.GetHttpURLForDataPath('google', 'google.html')) |
| 471 self.assertFalse( |
| 472 self.IsMouseLocked(), |
| 473 msg='Mouse lock did not exit when navigating to a new website.') |
| 474 |
| 475 def testMLDoesNotExitForAnchorLinks(self): |
| 476 """Verify mouse lock does not exit for anchor links. |
| 477 |
| 478 Mouse lock should not exist when following a link to the same page such as |
| 479 example.html#anchor. |
| 480 """ |
| 481 lock_result = self._EnableAndReturnLockMouseResult() |
| 482 self.assertEqual( |
| 483 lock_result, 'success', msg='Mouse is not locked.') |
| 484 ActionChains(self._driver).move_to_element( |
| 485 self._driver.find_element_by_id('anchor')).click().perform() |
| 486 self.assertTrue(self.WaitUntil(self.IsMouseLocked), |
| 487 msg='Mouse lock broke when clicking on an anchor link.') |
| 488 |
378 def ExitTabFSToBrowserFS(self): | 489 def ExitTabFSToBrowserFS(self): |
379 """Verify exiting tab fullscreen leaves browser in browser fullscreen. | 490 """Verify exiting tab fullscreen leaves browser in browser fullscreen. |
380 | 491 |
381 This test is semi-automated. | 492 This test is semi-automated. |
382 | 493 |
383 The browser initiates browser fullscreen, then initiates tab fullscreen. The | 494 The browser initiates browser fullscreen, then initiates tab fullscreen. The |
384 test verifies that existing tab fullscreen by simulating ESC key press or | 495 test verifies that existing tab fullscreen by simulating ESC key press or |
385 clicking the js function to exitFullscreen() will exit the tab fullscreen | 496 clicking the js function to exitFullscreen() will exit the tab fullscreen |
386 leaving browser fullscreen intact. | 497 leaving browser fullscreen intact. |
387 """ | 498 """ |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
476 self.NavigateToURL(url2, 0, 1) | 587 self.NavigateToURL(url2, 0, 1) |
477 self._driver.switch_to_window(tab2) | 588 self._driver.switch_to_window(tab2) |
478 self._EnableMouseLockMode() # Lock mouse in tab 2. | 589 self._EnableMouseLockMode() # Lock mouse in tab 2. |
479 raw_input('Manually move the mouse cursor on the page in tab 2. Shift+Tab \ | 590 raw_input('Manually move the mouse cursor on the page in tab 2. Shift+Tab \ |
480 into tab 1, click on lockMouse1() button, and move the mouse \ | 591 into tab 1, click on lockMouse1() button, and move the mouse \ |
481 cursor on the page in tab 1. Verify mouse movement is smooth.') | 592 cursor on the page in tab 1. Verify mouse movement is smooth.') |
482 | 593 |
483 | 594 |
484 if __name__ == '__main__': | 595 if __name__ == '__main__': |
485 pyauto_functional.Main() | 596 pyauto_functional.Main() |
OLD | NEW |