Chromium Code Reviews| 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 shutil | 8 import shutil |
| 9 | 9 |
| 10 import pyauto_functional # Must be imported before pyauto | 10 import pyauto_functional # Must be imported before pyauto |
| 11 import pyauto | 11 import pyauto |
| 12 import test_utils | 12 import test_utils |
| 13 from selenium.webdriver.common.keys import Keys | 13 from selenium.webdriver.common.keys import Keys |
| 14 | 14 |
| 15 | 15 |
| 16 class FullscreenMouselockTest(pyauto.PyUITest): | 16 class FullscreenMouselockTest(pyauto.PyUITest): |
| 17 """TestCase for Fullscreen and Mouse Lock.""" | 17 """TestCase for Fullscreen and Mouse Lock.""" |
| 18 | 18 |
| 19 def setUp(self): | |
| 20 pyauto.PyUITest.setUp(self) | |
| 21 self._driver = self.NewWebDriver() | |
| 22 | |
| 23 def Debug(self): | |
| 24 """Test method for experimentation. | |
| 25 | |
| 26 This method will not run automatically. | |
| 27 """ | |
| 28 driver = self.NewWebDriver() | |
|
Nirnimesh
2012/04/16 19:42:12
why not use self._driver?
dyu1
2012/04/16 23:21:27
Done.
| |
| 29 page = settings.ContentSettingsPage.FromNavigation(driver) | |
| 30 import pdb | |
| 31 pdb.set_trace() | |
| 32 | |
| 19 def ExtraChromeFlags(self): | 33 def ExtraChromeFlags(self): |
| 20 """Ensures Chrome is launched with custom flags. | 34 """Ensures Chrome is launched with custom flags. |
| 21 | 35 |
| 22 Returns: | 36 Returns: |
| 23 A list of extra flags to pass to Chrome when it is launched. | 37 A list of extra flags to pass to Chrome when it is launched. |
| 24 """ | 38 """ |
| 25 # Extra flag needed by scroll performance tests. | 39 # Extra flag needed by scroll performance tests. |
| 26 return super(FullscreenMouselockTest, | 40 return super(FullscreenMouselockTest, |
| 27 self).ExtraChromeFlags() + ['--enable-pointer-lock'] | 41 self).ExtraChromeFlags() + ['--enable-pointer-lock'] |
| 28 | 42 |
| 29 def testFullScreenMouseLockHooks(self): | 43 def testFullScreenMouseLockHooks(self): |
| 30 """Verify fullscreen and mouse lock automation hooks work.""" | 44 """Verify fullscreen and mouse lock automation hooks work.""" |
| 31 | |
| 32 from webdriver_pages import settings | |
| 33 from webdriver_pages.settings import Behaviors, ContentTypes | |
| 34 driver = self.NewWebDriver() | |
| 35 self.NavigateToURL(self.GetHttpURLForDataPath( | 45 self.NavigateToURL(self.GetHttpURLForDataPath( |
| 36 'fullscreen_mouselock', 'fullscreen_mouselock.html')) | 46 'fullscreen_mouselock', 'fullscreen_mouselock.html')) |
| 37 | 47 |
| 38 # Starting off we shouldn't be fullscreen | 48 # Starting off we shouldn't be fullscreen |
| 39 self.assertFalse(self.IsFullscreenForBrowser()) | 49 self.assertFalse(self.IsFullscreenForBrowser()) |
| 40 self.assertFalse(self.IsFullscreenForTab()) | 50 self.assertFalse(self.IsFullscreenForTab()) |
| 41 | 51 |
| 42 # Go fullscreen | 52 # Go fullscreen |
| 43 driver.find_element_by_id('enterFullscreen').click() | 53 self._driver.find_element_by_id('enterFullscreen').click() |
| 44 self.assertTrue(self.WaitUntil(self.IsFullscreenForTab)) | 54 self.assertTrue(self.WaitUntil(self.IsFullscreenForTab)) |
| 45 | 55 |
| 46 # Bubble should be up prompting to allow fullscreen | 56 # Bubble should be up prompting to allow fullscreen |
| 47 self.assertTrue(self.IsFullscreenBubbleDisplayed()) | 57 self.assertTrue(self.IsFullscreenBubbleDisplayed()) |
| 48 self.assertTrue(self.IsFullscreenBubbleDisplayingButtons()) | 58 self.assertTrue(self.IsFullscreenBubbleDisplayingButtons()) |
| 49 self.assertTrue(self.IsFullscreenPermissionRequested()) | 59 self.assertTrue(self.IsFullscreenPermissionRequested()) |
| 50 | 60 |
| 51 # Accept bubble, it should go away. | 61 # Accept bubble, it should go away. |
| 52 self.AcceptCurrentFullscreenOrMouseLockRequest() | 62 self.AcceptCurrentFullscreenOrMouseLockRequest() |
| 53 self.assertTrue(self.WaitUntil( | 63 self.assertTrue(self.WaitUntil( |
| 54 lambda: not self.IsFullscreenBubbleDisplayingButtons())) | 64 lambda: not self.IsFullscreenBubbleDisplayingButtons())) |
| 55 | 65 |
| 56 # Try to lock mouse, it won't lock yet but permision will be requested. | 66 # Try to lock mouse, it won't lock yet but permision will be requested. |
| 57 self.assertFalse(self.IsMouseLocked()) | 67 self.assertFalse(self.IsMouseLocked()) |
| 58 driver.find_element_by_id('lockMouse1').click() | 68 self._driver.find_element_by_id('lockMouse1').click() |
| 59 self.assertTrue(self.WaitUntil(self.IsMouseLockPermissionRequested)) | 69 self.assertTrue(self.WaitUntil(self.IsMouseLockPermissionRequested)) |
| 60 self.assertFalse(self.IsMouseLocked()) | 70 self.assertFalse(self.IsMouseLocked()) |
| 61 | 71 |
| 62 # Deny mouse lock. | 72 # Deny mouse lock. |
| 63 self.DenyCurrentFullscreenOrMouseLockRequest() | 73 self.DenyCurrentFullscreenOrMouseLockRequest() |
| 64 self.assertTrue(self.WaitUntil( | 74 self.assertTrue(self.WaitUntil( |
| 65 lambda: not self.IsFullscreenBubbleDisplayingButtons())) | 75 lambda: not self.IsFullscreenBubbleDisplayingButtons())) |
| 66 self.assertFalse(self.IsMouseLocked()) | 76 self.assertFalse(self.IsMouseLocked()) |
| 67 | 77 |
| 68 # Try mouse lock again, and accept it. | 78 # Try mouse lock again, and accept it. |
| 69 driver.find_element_by_id('lockMouse1').click() | 79 self._driver.find_element_by_id('lockMouse1').click() |
| 70 self.assertTrue(self.WaitUntil(self.IsMouseLockPermissionRequested)) | 80 self.assertTrue(self.WaitUntil(self.IsMouseLockPermissionRequested)) |
| 71 self.AcceptCurrentFullscreenOrMouseLockRequest() | 81 self.AcceptCurrentFullscreenOrMouseLockRequest() |
| 72 self.assertTrue(self.WaitUntil(self.IsMouseLocked)) | 82 self.assertTrue(self.WaitUntil(self.IsMouseLocked)) |
| 73 | 83 |
| 74 # The following doesn't work - as sending the key to the input field isn't | 84 # The following doesn't work - as sending the key to the input field isn't |
| 75 # picked up by the browser. :( Need an alternative way. | 85 # picked up by the browser. :( Need an alternative way. |
| 76 # | 86 # |
| 77 # # Ideally we wouldn't target a specific element, we'd just send keys to | 87 # # Ideally we wouldn't target a specific element, we'd just send keys to |
| 78 # # whatever the current keyboard focus was. | 88 # # whatever the current keyboard focus was. |
| 79 # keys_target = driver.find_element_by_id('sendKeysTarget') | 89 # keys_target = driver.find_element_by_id('sendKeysTarget') |
| 80 # | 90 # |
| 81 # # ESC key should exit fullscreen and mouse lock. | 91 # # ESC key should exit fullscreen and mouse lock. |
| 82 # | 92 # |
| 83 # print "# ESC key should exit fullscreen and mouse lock." | 93 # print "# ESC key should exit fullscreen and mouse lock." |
| 84 # keys_target.send_keys(Keys.ESCAPE) | 94 # keys_target.send_keys(Keys.ESCAPE) |
| 85 # self.assertTrue(self.WaitUntil(lambda: not self.IsFullscreenForBrowser())) | 95 # self.assertTrue(self.WaitUntil(lambda: not self.IsFullscreenForBrowser())) |
| 86 # self.assertTrue(self.WaitUntil(lambda: not self.IsFullscreenForTab())) | 96 # self.assertTrue(self.WaitUntil(lambda: not self.IsFullscreenForTab())) |
| 87 # self.assertTrue(self.WaitUntil(lambda: not self.IsMouseLocked())) | 97 # self.assertTrue(self.WaitUntil(lambda: not self.IsMouseLocked())) |
| 88 # | 98 # |
| 89 # # Check we can go browser fullscreen | 99 # # Check we can go browser fullscreen |
| 90 # print "# Check we can go browser fullscreen" | 100 # print "# Check we can go browser fullscreen" |
| 91 # keys_target.send_keys(Keys.F11) | 101 # keys_target.send_keys(Keys.F11) |
| 92 # self.assertTrue(self.WaitUntil(self.IsFullscreenForBrowser)) | 102 # self.assertTrue(self.WaitUntil(self.IsFullscreenForBrowser)) |
| 93 | 103 |
| 104 def LaunchFullscreenMode(self): | |
|
scheib
2012/04/16 21:37:48
Consider naming this so it's clear that it doesn't
dyu1
2012/04/16 23:21:27
Done.
| |
| 105 """Helper function to launch into Fullscreen mode.""" | |
| 106 self.NavigateToURL(self.GetHttpURLForDataPath( | |
| 107 'fullscreen_mouselock', 'fullscreen_mouselock.html')) | |
| 108 # Should not be in fullscreen mode during initial launch. | |
| 109 self.assertFalse(self.IsFullscreenForBrowser()) | |
| 110 self.assertFalse(self.IsFullscreenForTab()) | |
| 111 # Go into fullscreen mode. | |
| 112 self._driver.find_element_by_id('enterFullscreen').click() | |
| 113 self.assertTrue(self.WaitUntil(self.IsFullscreenForTab)) | |
| 114 # Bubble should display prompting to allow fullscreen. | |
| 115 self.assertTrue(self.IsFullscreenBubbleDisplayed()) | |
|
scheib
2012/04/16 21:37:48
FYI: Above these lines are duplicated when testing
dyu1
2012/04/16 23:21:27
There could be a chance for additional duplicates
| |
| 116 self.assertTrue(self.IsFullscreenBubbleDisplayingButtons()) | |
| 117 self.assertTrue(self.IsFullscreenPermissionRequested()) | |
| 118 | |
| 119 def _AcceptFullscreenOrMouseLockRequest(self): | |
| 120 """Helper function to accept Fullscreen or Mouse Lock request.""" | |
| 121 self.AcceptCurrentFullscreenOrMouseLockRequest() | |
| 122 self.assertTrue(self.WaitUntil( | |
| 123 lambda: not self.IsFullscreenBubbleDisplayingButtons())) | |
| 124 | |
| 125 def EnableFullscreenAndMouseLockMode(self): | |
| 126 """Helper function to enable fullscreen and mouse lock mode.""" | |
| 127 self.NavigateToURL(self.GetHttpURLForDataPath( | |
| 128 'fullscreen_mouselock', 'fullscreen_mouselock.html')) | |
| 129 self._driver.find_element_by_id('enterFullscreenAndLockMouse1').click() | |
| 130 self.assertTrue(self.WaitUntil(self.IsFullscreenForTab)) | |
|
Nirnimesh
2012/04/16 19:42:12
why not call LaunchFullscreenMode() instead of 127
dyu1
2012/04/16 23:21:27
Done.
| |
| 131 # Allow fullscreen. | |
| 132 self.AcceptCurrentFullscreenOrMouseLockRequest() | |
| 133 self.assertTrue(self.WaitUntil(self.IsMouseLockPermissionRequested)) | |
|
scheib
2012/04/16 21:37:48
Please add a comment noting that this wait shouldn
dyu1
2012/04/16 23:21:27
Done.
| |
| 134 # Allow mouse lock. | |
| 135 self.AcceptCurrentFullscreenOrMouseLockRequest() | |
| 136 self.assertTrue(self.WaitUntil(self.IsMouseLocked)) | |
| 137 | |
| 138 def EnableMouseLockMode(self): | |
|
Nirnimesh
2012/04/16 19:42:12
_ prefix?
dyu1
2012/04/16 23:21:27
I didn't make this private since later on you'll b
| |
| 139 """Helper function to enable mouse lock mode.""" | |
|
Nirnimesh
2012/04/16 19:42:12
Declare the expectations. That the fullscreen_mous
dyu1
2012/04/16 23:21:27
Done.
| |
| 140 self._driver.find_element_by_id('lockMouse1').click() | |
| 141 self.assertTrue(self.IsMouseLockPermissionRequested()) | |
| 142 self.AcceptCurrentFullscreenOrMouseLockRequest() | |
| 143 self.assertTrue(self.IsMouseLocked()) | |
| 144 | |
| 145 def testPrefsLineEntryForFullscreenAllowed(self): | |
| 146 """Verify line entry when fullscreen is allowed.""" | |
| 147 self.LaunchFullscreenMode() | |
| 148 self._AcceptFullscreenOrMouseLockRequest() | |
| 149 # Get the hostname pattern (e.g. http://127.0.0.1:57622). | |
| 150 hostname_pattern = ( | |
| 151 '/'.join(self.GetHttpURLForDataPath('').split('/')[0:3]) + ',*') | |
|
Nirnimesh
2012/04/16 19:42:12
this is incomprehensible. Don't split. Just remove
dyu1
2012/04/16 23:21:27
Done and moved to setUp()
On 2012/04/16 19:42:12,
| |
| 152 content_settings = ( | |
| 153 self.GetPrefsInfo().Prefs()['profile']['content_settings']) | |
| 154 self.assertEqual( | |
| 155 {hostname_pattern: {'fullscreen': 1}}, # Allow the hostname. | |
| 156 content_settings['pattern_pairs']) | |
| 157 | |
| 158 def testPrefsLineEntryForFullscreenExit(self): | |
| 159 """Verify line entry is empty when exit fullscreen mode before allowing.""" | |
| 160 self.LaunchFullscreenMode() | |
| 161 self._driver.find_element_by_id('exitFullscreen').click() | |
| 162 # Verify exit from fullscreen mode. | |
| 163 self.assertTrue(self.WaitUntil(lambda: not self.IsFullscreenForTab())) | |
| 164 content_settings = ( | |
| 165 self.GetPrefsInfo().Prefs()['profile']['content_settings']) | |
| 166 self.assertEqual({}, content_settings['pattern_pairs']) | |
| 167 | |
| 168 def testPatternsForAllowFullscreenAndPointerLock(self): | |
|
Nirnimesh
2012/04/16 19:42:12
the test names are getting too big. Makes it diffi
dyu1
2012/04/16 23:21:27
Done.
| |
| 169 """Verify hostname pattern and behavior for allowed pointer lock. | |
| 170 | |
| 171 To lock the mouse, the browser needs to be in fullscreen mode. | |
| 172 """ | |
| 173 self.EnableFullscreenAndMouseLockMode() | |
| 174 self.EnableMouseLockMode() | |
| 175 hostname_pattern = ( | |
| 176 '/'.join(self.GetHttpURLForDataPath('').split('/')[0:3]) + ',*') | |
| 177 expected_pattern = ( | |
| 178 {hostname_pattern: {'fullscreen': 1, 'mouselock': 1}}) | |
| 179 content_settings = ( | |
| 180 self.GetPrefsInfo().Prefs()['profile']['content_settings']) | |
| 181 self.assertEqual(expected_pattern, content_settings['pattern_pairs']) | |
| 182 | |
| 183 def testPatternsForAllowMouseLock(self): | |
| 184 """Verify hostname pattern and behavior for allowed mouse lock. | |
| 185 | |
| 186 Enable fullscreen mode and enable mouse lock separately. | |
| 187 """ | |
| 188 self.LaunchFullscreenMode() | |
| 189 self.AcceptCurrentFullscreenOrMouseLockRequest() | |
| 190 self.EnableMouseLockMode() | |
| 191 hostname_pattern = ( | |
| 192 '/'.join(self.GetHttpURLForDataPath('').split('/')[0:3]) + ',*') | |
| 193 expected_pattern = ( | |
| 194 {hostname_pattern: {'fullscreen': 1, 'mouselock': 1}}) | |
| 195 content_settings = ( | |
| 196 self.GetPrefsInfo().Prefs()['profile']['content_settings']) | |
| 197 self.assertEqual(expected_pattern, content_settings['pattern_pairs']) | |
| 198 | |
| 199 def testNoMouseLockRequest(self): | |
| 200 """Verify mouse lock request does not appear. | |
| 201 | |
| 202 When allowing all sites to disable the mouse cursor, the mouse lock request | |
| 203 bubble should not show. The mouse cursor should be automatically disabled | |
| 204 when clicking on a disable mouse button. | |
| 205 """ | |
| 206 # Allow all sites to disable mouse cursor. | |
| 207 self.SetPrefs(pyauto.kDefaultContentSettings, {u'mouselock': 1}) | |
| 208 self.LaunchFullscreenMode() | |
| 209 # Allow for fullscreen mode. | |
| 210 self._AcceptFullscreenOrMouseLockRequest() | |
| 211 self._driver.find_element_by_id('lockMouse1').click() | |
| 212 self.assertTrue(self.WaitUntil( | |
| 213 lambda: not self.IsMouseLockPermissionRequested())) | |
| 214 self.assertTrue(self.IsMouseLocked()) | |
| 215 | |
| 216 def testUnableToLockMouse(self): | |
| 217 """Verify mouse lock is disabled. | |
| 218 | |
| 219 When not allowing any site to disable the mouse cursor, the mouse lock | |
| 220 request bubble should not show and the mouse cursor should not be disabled. | |
| 221 """ | |
| 222 # Do not allow any site to disable mouse cursor. | |
| 223 self.SetPrefs(pyauto.kDefaultContentSettings, {u'mouselock': 2}) | |
| 224 self.LaunchFullscreenMode() | |
| 225 # Allow for fullscreen mode. | |
| 226 self._AcceptFullscreenOrMouseLockRequest() | |
| 227 self._driver.find_element_by_id('lockMouse1').click() | |
| 228 self.assertTrue(self.WaitUntil( | |
| 229 lambda: not self.IsMouseLockPermissionRequested())) | |
|
scheib
2012/04/16 21:37:48
I'm concerned that there is a race condition here.
dyu1
2012/04/16 23:21:27
If the js callback is successful then check the tw
scheib
2012/04/16 23:55:42
If you can get your python test code to wait for s
dyu1
2012/04/23 18:50:26
Done.
| |
| 230 self.assertTrue(self.WaitUntil(lambda: not self.IsMouseLocked())) | |
| 231 | |
| 232 def SearchForTextOutsideOfContainer(self): | |
| 233 """Verify text outside of container is not visible when fullscreen. | |
| 234 | |
| 235 Verify this test manually until there is a way to find text on screen | |
| 236 without using FindInPage(). | |
| 237 | |
| 238 The text that is outside of the fullscreen container should only be visible | |
| 239 when fullscreen is off. The text should not be visible while in fullscreen | |
| 240 mode. | |
| 241 """ | |
| 242 self.NavigateToURL(self.GetHttpURLForDataPath( | |
| 243 'fullscreen_mouselock', 'fullscreen_mouselock.html')) | |
| 244 # Should not be in fullscreen mode during initial launch. | |
| 245 self.assertFalse(self.IsFullscreenForBrowser()) | |
| 246 self.assertFalse(self.IsFullscreenForTab()) | |
| 247 self.assertTrue( | |
| 248 self.WaitUntil(lambda: self.FindInPage( | |
| 249 'This text is outside of the container')['match_count'], | |
| 250 expect_retval=1)) | |
| 251 # Go into fullscreen mode. | |
| 252 self._driver.find_element_by_id('enterFullscreen').click() | |
| 253 self.assertTrue(self.WaitUntil(self.IsFullscreenForTab)) | |
| 254 # TODO(dyu): find a way to verify on screen text instead of using | |
| 255 # FindInPage() which searches for text in the HTML. | |
| 256 | |
| 94 | 257 |
| 95 if __name__ == '__main__': | 258 if __name__ == '__main__': |
| 96 pyauto_functional.Main() | 259 pyauto_functional.Main() |
| OLD | NEW |