Chromium Code Reviews| Index: chrome/test/functional/fullscreen_mouselock.py |
| =================================================================== |
| --- chrome/test/functional/fullscreen_mouselock.py (revision 132411) |
| +++ chrome/test/functional/fullscreen_mouselock.py (working copy) |
| @@ -5,17 +5,36 @@ |
| import logging |
| import os |
| +import re |
| import shutil |
| import pyauto_functional # Must be imported before pyauto |
| import pyauto |
| import test_utils |
| from selenium.webdriver.common.keys import Keys |
| +from webdriver_pages import settings |
| class FullscreenMouselockTest(pyauto.PyUITest): |
| """TestCase for Fullscreen and Mouse Lock.""" |
| + def setUp(self): |
| + pyauto.PyUITest.setUp(self) |
| + self._driver = self.NewWebDriver() |
| + # Get the hostname pattern (e.g. http://127.0.0.1:57622). |
| + self._hostname_pattern = ( |
| + re.sub('/files/$', '', self.GetHttpURLForDataPath(''))) |
| + |
| + def Debug(self): |
| + """Test method for experimentation. |
| + |
| + This method will not run automatically. |
| + """ |
| + self._driver = self.NewWebDriver() |
| + page = settings.ContentSettingsPage.FromNavigation(self._driver) |
| + import pdb |
| + pdb.set_trace() |
| + |
| def ExtraChromeFlags(self): |
| """Ensures Chrome is launched with custom flags. |
| @@ -28,10 +47,6 @@ |
| def testFullScreenMouseLockHooks(self): |
| """Verify fullscreen and mouse lock automation hooks work.""" |
| - |
| - from webdriver_pages import settings |
| - from webdriver_pages.settings import Behaviors, ContentTypes |
| - driver = self.NewWebDriver() |
| self.NavigateToURL(self.GetHttpURLForDataPath( |
| 'fullscreen_mouselock', 'fullscreen_mouselock.html')) |
| @@ -40,7 +55,7 @@ |
| self.assertFalse(self.IsFullscreenForTab()) |
| # Go fullscreen |
| - driver.find_element_by_id('enterFullscreen').click() |
| + self._driver.find_element_by_id('enterFullscreen').click() |
| self.assertTrue(self.WaitUntil(self.IsFullscreenForTab)) |
| # Bubble should be up prompting to allow fullscreen |
| @@ -55,7 +70,7 @@ |
| # Try to lock mouse, it won't lock yet but permision will be requested. |
| self.assertFalse(self.IsMouseLocked()) |
| - driver.find_element_by_id('lockMouse1').click() |
| + self._driver.find_element_by_id('lockMouse1').click() |
| self.assertTrue(self.WaitUntil(self.IsMouseLockPermissionRequested)) |
| self.assertFalse(self.IsMouseLocked()) |
| @@ -66,7 +81,7 @@ |
| self.assertFalse(self.IsMouseLocked()) |
| # Try mouse lock again, and accept it. |
| - driver.find_element_by_id('lockMouse1').click() |
| + self._driver.find_element_by_id('lockMouse1').click() |
| self.assertTrue(self.WaitUntil(self.IsMouseLockPermissionRequested)) |
| self.AcceptCurrentFullscreenOrMouseLockRequest() |
| self.assertTrue(self.WaitUntil(self.IsMouseLocked)) |
| @@ -91,6 +106,165 @@ |
| # keys_target.send_keys(Keys.F11) |
| # self.assertTrue(self.WaitUntil(self.IsFullscreenForBrowser)) |
| + def LaunchFSAndExpectPrompt(self, buttonAction='enterFullscreen'): |
|
dennis_jeffrey
2012/04/17 17:57:14
prefix function name with underscore if meant to b
dennis_jeffrey
2012/04/17 17:57:14
button_action, here and everywhere else in this fi
dyu1
2012/04/23 18:50:26
Done.
dyu1
2012/04/23 18:50:26
Done.
|
| + """Helper function to launch fullscreen and expect a prompt. |
| + Fullscreen is initiated and a bubble prompt appears asking to allow or |
| + cancel from fullscreen mode. The actual fullscreen mode doesn't take place |
| + until after approving the prompt. |
|
dennis_jeffrey
2012/04/17 17:57:14
(optional) maybe we should say that this helper wi
dyu1
2012/04/23 18:50:26
Done.
|
| + |
| + Args: |
| + buttonAction: The button id to click to initiate an action. Default is to |
| + click enterFullscreen. |
|
dennis_jeffrey
2012/04/17 17:57:14
indent by 4 more spaces
dyu1
2012/04/23 18:50:26
Done.
|
| + """ |
| + self.NavigateToURL(self.GetHttpURLForDataPath( |
| + 'fullscreen_mouselock', 'fullscreen_mouselock.html')) |
| + # Should not be in fullscreen mode during initial launch. |
| + self.assertFalse(self.IsFullscreenForBrowser()) |
| + self.assertFalse(self.IsFullscreenForTab()) |
| + # Go into fullscreen mode. |
| + self._driver.find_element_by_id(buttonAction).click() |
| + self.assertTrue(self.WaitUntil(self.IsFullscreenForTab)) |
| + # Bubble should display prompting to allow fullscreen. |
| + self.assertTrue(self.IsFullscreenPermissionRequested()) |
| + |
| + def _AcceptFullscreenOrMouseLockRequest(self): |
| + """Helper function to accept Fullscreen or Mouse Lock request.""" |
| + self.AcceptCurrentFullscreenOrMouseLockRequest() |
| + self.assertTrue(self.WaitUntil( |
| + lambda: not self.IsFullscreenBubbleDisplayingButtons())) |
| + |
| + def EnableFullscreenAndMouseLockMode(self): |
| + """Helper function to enable fullscreen and mouse lock mode.""" |
|
dennis_jeffrey
2012/04/17 17:57:14
nit: try to be consistent with capitalization of "
dyu1
2012/04/23 18:50:26
Done.
|
| + self.LaunchFSAndExpectPrompt('enterFullscreenAndLockMouse1') |
|
dennis_jeffrey
2012/04/17 17:57:14
button_action=
dyu1
2012/04/23 18:50:26
Done
On 2012/04/17 17:57:14, dennis_jeffrey wrote
|
| + # Allow fullscreen. |
| + self.AcceptCurrentFullscreenOrMouseLockRequest() |
| + # The wait is needed due to crbug.com/123396. Should be able to click the |
| + # fullscreen and mouselock button and be both accepted in a single action. |
| + self.assertTrue(self.WaitUntil(self.IsMouseLockPermissionRequested)) |
| + # Allow mouse lock. |
| + self.AcceptCurrentFullscreenOrMouseLockRequest() |
| + self.assertTrue(self.WaitUntil(self.IsMouseLocked)) |
| + |
| + def EnableMouseLockMode(self, buttonAction='lockMouse1'): |
| + """Helper function to enable mouse lock mode. |
| + |
| + For now, to lock the mouse, the browser needs to be in fullscreen mode. |
| + |
| + Args: |
| + buttonAction: The button id to click to initiate an action. Default is to |
| + click lockMouse1. |
| + """ |
| + self._driver.find_element_by_id(buttonAction).click() |
| + self.assertTrue(self.IsMouseLockPermissionRequested()) |
| + self.AcceptCurrentFullscreenOrMouseLockRequest() |
| + self.assertTrue(self.IsMouseLocked()) |
| + |
| + def testPrefsLineEntryForFullscreenAllowed(self): |
| + """Verify line entry when fullscreen is allowed.""" |
| + self.LaunchFSAndExpectPrompt() |
| + self._AcceptFullscreenOrMouseLockRequest() |
| + content_settings = ( |
| + self.GetPrefsInfo().Prefs()['profile']['content_settings']) |
| + self.assertEqual( |
| + {self._hostname_pattern + ',*': {'fullscreen': 1}}, # Allow hostname. |
| + content_settings['pattern_pairs']) |
|
dennis_jeffrey
2012/04/17 17:57:14
nit: should we have a msg='' argument to provide a
dyu1
2012/04/23 18:50:26
I added it although the assertion error shows that
|
| + |
| + def testPrefsLineEntryForFullscreenExit(self): |
| + """Verify line entry is empty when exit fullscreen mode before allowing.""" |
| + self.LaunchFSAndExpectPrompt() |
| + self._driver.find_element_by_id('exitFullscreen').click() |
| + # Verify exit from fullscreen mode. |
| + self.assertTrue(self.WaitUntil(lambda: not self.IsFullscreenForTab())) |
| + content_settings = ( |
| + self.GetPrefsInfo().Prefs()['profile']['content_settings']) |
| + self.assertEqual({}, content_settings['pattern_pairs']) |
| + |
| + def testPatternsForFSAndML(self): |
|
dennis_jeffrey
2012/04/17 17:57:14
there's some inconsistency in function names added
dyu1
2012/04/23 18:50:26
This test is disabled in PYAUTO_TESTS. The name is
|
| + """Verify hostname pattern and behavior for allowed mouse cursor lock. |
| + |
| + To lock the mouse, the browser needs to be in fullscreen mode. |
| + """ |
| + self.EnableFullscreenAndMouseLockMode() |
| + self.EnableMouseLockMode() |
| + expected_pattern = ( |
| + {self._hostname_pattern + ',*': {'fullscreen': 1, 'mouselock': 1}}) |
| + content_settings = ( |
| + self.GetPrefsInfo().Prefs()['profile']['content_settings']) |
| + self.assertEqual(expected_pattern, content_settings['pattern_pairs']) |
| + |
| + def testPatternsForAllowMouseLock(self): |
| + """Verify hostname pattern and behavior for allowed mouse cursor lock. |
| + |
| + Enable fullscreen mode and enable mouse lock separately. |
| + """ |
| + self.LaunchFSAndExpectPrompt() |
| + self.AcceptCurrentFullscreenOrMouseLockRequest() |
| + self.EnableMouseLockMode() |
| + expected_pattern = ( |
| + {self._hostname_pattern + ',*': {'fullscreen': 1, 'mouselock': 1}}) |
| + content_settings = ( |
| + self.GetPrefsInfo().Prefs()['profile']['content_settings']) |
| + self.assertEqual(expected_pattern, content_settings['pattern_pairs']) |
| + |
| + def testNoMouseLockRequest(self): |
| + """Verify mouse lock request does not appear. |
| + |
| + When allowing all sites to disable the mouse cursor, the mouse lock request |
| + bubble should not show. The mouse cursor should be automatically disabled |
| + when clicking on a disable mouse button. |
| + """ |
| + # Allow all sites to disable mouse cursor. |
| + self.SetPrefs(pyauto.kDefaultContentSettings, {u'mouselock': 1}) |
| + self.LaunchFSAndExpectPrompt() |
| + # Allow for fullscreen mode. |
| + self._AcceptFullscreenOrMouseLockRequest() |
| + self._driver.find_element_by_id('lockMouse1').click() |
| + self.assertTrue(self.WaitUntil( |
| + lambda: not self.IsMouseLockPermissionRequested())) |
| + self.assertTrue(self.IsMouseLocked()) |
|
dennis_jeffrey
2012/04/17 17:57:14
Perhaps the () are unnecessary, (e.g., see line 14
dennis_jeffrey
2012/04/17 19:12:07
Sorry, please ignore this comment. The parens are
|
| + |
| + def testUnableToLockMouse(self): |
| + """Verify mouse lock is disabled. |
| + |
| + When not allowing any site to disable the mouse cursor, the mouse lock |
| + request bubble should not show and the mouse cursor should not be disabled. |
| + """ |
| + # Do not allow any site to disable mouse cursor. |
| + self.SetPrefs(pyauto.kDefaultContentSettings, {u'mouselock': 2}) |
| + self.LaunchFSAndExpectPrompt() |
| + # Allow for fullscreen mode. |
| + self._AcceptFullscreenOrMouseLockRequest() |
| + self._driver.find_element_by_id('lockMouse1').click() |
| + self.assertTrue(self.WaitUntil( |
| + lambda: not self.IsMouseLockPermissionRequested())) |
| + self.assertTrue(self.WaitUntil(lambda: not self.IsMouseLocked())) |
| + |
| + def SearchForTextOutsideOfContainer(self): |
| + """Verify text outside of container is not visible when fullscreen. |
| + |
| + Verify this test manually until there is a way to find text on screen |
| + without using FindInPage(). |
| + |
| + The text that is outside of the fullscreen container should only be visible |
| + when fullscreen is off. The text should not be visible while in fullscreen |
| + mode. |
| + """ |
| + self.NavigateToURL(self.GetHttpURLForDataPath( |
| + 'fullscreen_mouselock', 'fullscreen_mouselock.html')) |
| + # Should not be in fullscreen mode during initial launch. |
| + self.assertFalse(self.IsFullscreenForBrowser()) |
| + self.assertFalse(self.IsFullscreenForTab()) |
| + self.assertTrue( |
| + self.WaitUntil(lambda: self.FindInPage( |
| + 'This text is outside of the container')['match_count'], |
| + expect_retval=1)) |
| + # Go into fullscreen mode. |
| + self._driver.find_element_by_id('enterFullscreen').click() |
| + self.assertTrue(self.WaitUntil(self.IsFullscreenForTab)) |
| + # TODO(dyu): find a way to verify on screen text instead of using |
| + # FindInPage() which searches for text in the HTML. |
| + |
| + |
| if __name__ == '__main__': |
| pyauto_functional.Main() |