Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(313)

Side by Side Diff: chrome/test/functional/fullscreen_mouselock.py

Issue 10082033: Add tests for fullscreen mode and mouse lock mode. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/test/functional/PYAUTO_TESTS ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 shutil 9 import shutil
10 import time
9 11
10 import pyauto_functional # Must be imported before pyauto 12 import pyauto_functional # Must be imported before pyauto
11 import pyauto 13 import pyauto
12 import test_utils 14 import test_utils
13 from selenium.webdriver.common.keys import Keys 15 from selenium.webdriver.common.keys import Keys
16 from webdriver_pages import settings
14 17
15 18
16 class FullscreenMouselockTest(pyauto.PyUITest): 19 class FullscreenMouselockTest(pyauto.PyUITest):
17 """TestCase for Fullscreen and Mouse Lock.""" 20 """TestCase for Fullscreen and Mouse Lock."""
18 21
22 def setUp(self):
23 pyauto.PyUITest.setUp(self)
24 self._driver = self.NewWebDriver()
25 # Get the hostname pattern (e.g. http://127.0.0.1:57622).
26 self._hostname_pattern = (
27 re.sub('/files/$', '', self.GetHttpURLForDataPath('')))
28
29 def Debug(self):
30 """Test method for experimentation.
31
32 This method will not run automatically.
33 """
34 page = settings.ContentSettingsPage.FromNavigation(self._driver)
35 import pdb
36 pdb.set_trace()
37
19 def ExtraChromeFlags(self): 38 def ExtraChromeFlags(self):
20 """Ensures Chrome is launched with custom flags. 39 """Ensures Chrome is launched with custom flags.
21 40
22 Returns: 41 Returns:
23 A list of extra flags to pass to Chrome when it is launched. 42 A list of extra flags to pass to Chrome when it is launched.
24 """ 43 """
25 # Extra flag needed by scroll performance tests. 44 # Extra flag needed by scroll performance tests.
26 return super(FullscreenMouselockTest, 45 return super(FullscreenMouselockTest,
27 self).ExtraChromeFlags() + ['--enable-pointer-lock'] 46 self).ExtraChromeFlags() + ['--enable-pointer-lock']
28 47
29 def testFullScreenMouseLockHooks(self): 48 def testFullScreenMouseLockHooks(self):
30 """Verify fullscreen and mouse lock automation hooks work.""" 49 """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( 50 self.NavigateToURL(self.GetHttpURLForDataPath(
36 'fullscreen_mouselock', 'fullscreen_mouselock.html')) 51 'fullscreen_mouselock', 'fullscreen_mouselock.html'))
37 52
38 # Starting off we shouldn't be fullscreen 53 # Starting off we shouldn't be fullscreen
39 self.assertFalse(self.IsFullscreenForBrowser()) 54 self.assertFalse(self.IsFullscreenForBrowser())
40 self.assertFalse(self.IsFullscreenForTab()) 55 self.assertFalse(self.IsFullscreenForTab())
41 56
42 # Go fullscreen 57 # Go fullscreen
43 driver.find_element_by_id('enterFullscreen').click() 58 self._driver.find_element_by_id('enterFullscreen').click()
44 self.assertTrue(self.WaitUntil(self.IsFullscreenForTab)) 59 self.assertTrue(self.WaitUntil(self.IsFullscreenForTab))
45 60
46 # Bubble should be up prompting to allow fullscreen 61 # Bubble should be up prompting to allow fullscreen
47 self.assertTrue(self.IsFullscreenBubbleDisplayed()) 62 self.assertTrue(self.IsFullscreenBubbleDisplayed())
48 self.assertTrue(self.IsFullscreenBubbleDisplayingButtons()) 63 self.assertTrue(self.IsFullscreenBubbleDisplayingButtons())
49 self.assertTrue(self.IsFullscreenPermissionRequested()) 64 self.assertTrue(self.IsFullscreenPermissionRequested())
50 65
51 # Accept bubble, it should go away. 66 # Accept bubble, it should go away.
52 self.AcceptCurrentFullscreenOrMouseLockRequest() 67 self.AcceptCurrentFullscreenOrMouseLockRequest()
53 self.assertTrue(self.WaitUntil( 68 self.assertTrue(self.WaitUntil(
54 lambda: not self.IsFullscreenBubbleDisplayingButtons())) 69 lambda: not self.IsFullscreenBubbleDisplayingButtons()))
55 70
56 # Try to lock mouse, it won't lock yet but permision will be requested. 71 # Try to lock mouse, it won't lock yet but permision will be requested.
57 self.assertFalse(self.IsMouseLocked()) 72 self.assertFalse(self.IsMouseLocked())
58 driver.find_element_by_id('lockMouse1').click() 73 self._driver.find_element_by_id('lockMouse1').click()
59 self.assertTrue(self.WaitUntil(self.IsMouseLockPermissionRequested)) 74 self.assertTrue(self.WaitUntil(self.IsMouseLockPermissionRequested))
60 self.assertFalse(self.IsMouseLocked()) 75 self.assertFalse(self.IsMouseLocked())
61 76
62 # Deny mouse lock. 77 # Deny mouse lock.
63 self.DenyCurrentFullscreenOrMouseLockRequest() 78 self.DenyCurrentFullscreenOrMouseLockRequest()
64 self.assertTrue(self.WaitUntil( 79 self.assertTrue(self.WaitUntil(
65 lambda: not self.IsFullscreenBubbleDisplayingButtons())) 80 lambda: not self.IsFullscreenBubbleDisplayingButtons()))
66 self.assertFalse(self.IsMouseLocked()) 81 self.assertFalse(self.IsMouseLocked())
67 82
68 # Try mouse lock again, and accept it. 83 # Try mouse lock again, and accept it.
69 driver.find_element_by_id('lockMouse1').click() 84 self._driver.find_element_by_id('lockMouse1').click()
70 self.assertTrue(self.WaitUntil(self.IsMouseLockPermissionRequested)) 85 self.assertTrue(self.WaitUntil(self.IsMouseLockPermissionRequested))
71 self.AcceptCurrentFullscreenOrMouseLockRequest() 86 self.AcceptCurrentFullscreenOrMouseLockRequest()
72 self.assertTrue(self.WaitUntil(self.IsMouseLocked)) 87 self.assertTrue(self.WaitUntil(self.IsMouseLocked))
73 88
74 # The following doesn't work - as sending the key to the input field isn't 89 # 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. 90 # picked up by the browser. :( Need an alternative way.
76 # 91 #
77 # # Ideally we wouldn't target a specific element, we'd just send keys to 92 # # Ideally we wouldn't target a specific element, we'd just send keys to
78 # # whatever the current keyboard focus was. 93 # # whatever the current keyboard focus was.
79 # keys_target = driver.find_element_by_id('sendKeysTarget') 94 # keys_target = driver.find_element_by_id('sendKeysTarget')
80 # 95 #
81 # # ESC key should exit fullscreen and mouse lock. 96 # # ESC key should exit fullscreen and mouse lock.
82 # 97 #
83 # print "# ESC key should exit fullscreen and mouse lock." 98 # print "# ESC key should exit fullscreen and mouse lock."
84 # keys_target.send_keys(Keys.ESCAPE) 99 # keys_target.send_keys(Keys.ESCAPE)
85 # self.assertTrue(self.WaitUntil(lambda: not self.IsFullscreenForBrowser())) 100 # self.assertTrue(self.WaitUntil(lambda: not self.IsFullscreenForBrowser()))
86 # self.assertTrue(self.WaitUntil(lambda: not self.IsFullscreenForTab())) 101 # self.assertTrue(self.WaitUntil(lambda: not self.IsFullscreenForTab()))
87 # self.assertTrue(self.WaitUntil(lambda: not self.IsMouseLocked())) 102 # self.assertTrue(self.WaitUntil(lambda: not self.IsMouseLocked()))
88 # 103 #
89 # # Check we can go browser fullscreen 104 # # Check we can go browser fullscreen
90 # print "# Check we can go browser fullscreen" 105 # print "# Check we can go browser fullscreen"
91 # keys_target.send_keys(Keys.F11) 106 # keys_target.send_keys(Keys.F11)
92 # self.assertTrue(self.WaitUntil(self.IsFullscreenForBrowser)) 107 # self.assertTrue(self.WaitUntil(self.IsFullscreenForBrowser))
93 108
109 def _LaunchFSAndExpectPrompt(self, button_action='enterFullscreen'):
110 """Helper function to launch fullscreen and expect a prompt.
111
112 Fullscreen is initiated and a bubble prompt appears asking to allow or
113 cancel from fullscreen mode. The actual fullscreen mode doesn't take place
114 until after approving the prompt.
115
116 If the helper is not successful then the test will fail.
117
118 Args:
119 button_action: The button id to click to initiate an action. Default is to
120 click enterFullscreen.
121 """
122 self.NavigateToURL(self.GetHttpURLForDataPath(
123 'fullscreen_mouselock', 'fullscreen_mouselock.html'))
124 # Should not be in fullscreen mode during initial launch.
125 self.assertFalse(self.IsFullscreenForBrowser())
126 self.assertFalse(self.IsFullscreenForTab())
127 # Go into fullscreen mode.
128 self._driver.find_element_by_id(button_action).click()
129 self.assertTrue(self.WaitUntil(self.IsFullscreenForTab))
130 # Bubble should display prompting to allow fullscreen.
131 self.assertTrue(self.IsFullscreenPermissionRequested())
132
133 def _InitiateBrowserFullscreen(self):
134 """Helper function that initiates browser fullscreen."""
135 self.NavigateToURL(self.GetHttpURLForDataPath(
136 'fullscreen_mouselock', 'fullscreen_mouselock.html'))
137 # Should not be in fullscreen mode during initial launch.
138 self.assertFalse(self.IsFullscreenForBrowser())
139 self.assertFalse(self.IsFullscreenForTab())
140 # Initiate browser fullscreen.
141 self.ApplyAccelerator(pyauto.IDC_FULLSCREEN)
142 self.assertTrue(self.WaitUntil(self.IsFullscreenForBrowser))
143 self.assertTrue(self.WaitUntil(lambda: not self.IsFullscreenForTab()))
144 self.assertTrue(self.WaitUntil(lambda: not self.IsMouseLocked()))
145
146 def _AcceptFullscreenOrMouseLockRequest(self):
147 """Helper function to accept fullscreen or mouse lock request."""
148 self.AcceptCurrentFullscreenOrMouseLockRequest()
149 self.assertTrue(self.WaitUntil(
150 lambda: not self.IsFullscreenBubbleDisplayingButtons()))
151
152 def _EnableFullscreenAndMouseLockMode(self):
153 """Helper function to enable fullscreen and mouse lock mode."""
154 self._LaunchFSAndExpectPrompt(button_action='enterFullscreenAndLockMouse1')
155 # Allow fullscreen.
156 self.AcceptCurrentFullscreenOrMouseLockRequest()
157 # The wait is needed due to crbug.com/123396. Should be able to click the
158 # fullscreen and mouselock button and be both accepted in a single action.
159 self.assertTrue(self.WaitUntil(self.IsMouseLockPermissionRequested))
160 # Allow mouse lock.
161 self.AcceptCurrentFullscreenOrMouseLockRequest()
162 self.assertTrue(self.WaitUntil(self.IsMouseLocked))
163
164 def _EnableMouseLockMode(self, button_action='lockMouse1'):
165 """Helper function to enable mouse lock mode.
166
167 For now, to lock the mouse, the browser needs to be in fullscreen mode.
168
169 Args:
170 button_action: The button id to click to initiate an action. Default is to
171 click lockMouse1.
172 """
173 self._driver.find_element_by_id(button_action).click()
174 self.assertTrue(self.IsMouseLockPermissionRequested())
175 self.AcceptCurrentFullscreenOrMouseLockRequest()
176 self.assertTrue(self.IsMouseLocked())
177
178 def testPrefsForFullscreenAllowed(self):
179 """Verify prefs when fullscreen is allowed."""
180 self._LaunchFSAndExpectPrompt()
181 self._AcceptFullscreenOrMouseLockRequest()
182 content_settings = (
183 self.GetPrefsInfo().Prefs()['profile']['content_settings'])
184 self.assertEqual(
185 {self._hostname_pattern + ',*': {'fullscreen': 1}}, # Allow hostname.
186 content_settings['pattern_pairs'],
187 msg='Saved hostname pattern does not match expected pattern.')
188
189 def testPrefsForFullscreenExit(self):
190 """Verify prefs is empty when exit fullscreen mode before allowing."""
191 self._LaunchFSAndExpectPrompt()
192 self._driver.find_element_by_id('exitFullscreen').click()
193 # Verify exit from fullscreen mode.
194 self.assertTrue(self.WaitUntil(lambda: not self.IsFullscreenForTab()))
195 content_settings = (
196 self.GetPrefsInfo().Prefs()['profile']['content_settings'])
197 self.assertEqual(
198 {}, content_settings['pattern_pairs'],
199 msg='Patterns saved when there should be none.')
200
201 def testPatternsForFSAndML(self):
202 """Verify hostname pattern and behavior for allowed mouse cursor lock.
203
204 To lock the mouse, the browser needs to be in fullscreen mode.
205 """
206 self._EnableFullscreenAndMouseLockMode()
207 self._EnableMouseLockMode()
208 expected_pattern = (
209 {self._hostname_pattern + ',*': {'fullscreen': 1, 'mouselock': 1}})
210 content_settings = (
211 self.GetPrefsInfo().Prefs()['profile']['content_settings'])
212 self.assertEqual(
213 expected_pattern, content_settings['pattern_pairs'],
214 msg='Saved hostname and behavior patterns do not match expected.')
215
216 def testPatternsForAllowMouseLock(self):
217 """Verify hostname pattern and behavior for allowed mouse cursor lock.
218
219 Enable fullscreen mode and enable mouse lock separately.
220 """
221 self._LaunchFSAndExpectPrompt()
222 self.AcceptCurrentFullscreenOrMouseLockRequest()
223 self._EnableMouseLockMode()
224 expected_pattern = (
225 {self._hostname_pattern + ',*': {'fullscreen': 1, 'mouselock': 1}})
226 content_settings = (
227 self.GetPrefsInfo().Prefs()['profile']['content_settings'])
228 self.assertEqual(
229 expected_pattern, content_settings['pattern_pairs'],
230 msg='Saved hostname and behavior patterns do not match expected.')
231
232 def testNoMouseLockRequest(self):
233 """Verify mouse lock request does not appear.
234
235 When allowing all sites to disable the mouse cursor, the mouse lock request
236 bubble should not show. The mouse cursor should be automatically disabled
237 when clicking on a disable mouse button.
238 """
239 # Allow all sites to disable mouse cursor.
240 self.SetPrefs(pyauto.kDefaultContentSettings, {u'mouselock': 1})
241 self._LaunchFSAndExpectPrompt()
242 # Allow for fullscreen mode.
243 self._AcceptFullscreenOrMouseLockRequest()
244 self._driver.set_script_timeout(2)
245 # Receive callback status (success or failure) from javascript that the
246 # click has registered and the mouse lock status has changed.
247 lock_result = self._driver.execute_async_script(
248 'lockMouse1(arguments[arguments.length - 1])')
249 self.assertEqual(lock_result, 'success', msg='Mouse lock unsuccessful.')
250 self.assertTrue(self.WaitUntil(
251 lambda: not self.IsMouseLockPermissionRequested()))
252 self.assertTrue(self.IsMouseLocked())
253
254 def testUnableToLockMouse(self):
255 """Verify mouse lock is disabled.
256
257 When not allowing any site to disable the mouse cursor, the mouse lock
258 request bubble should not show and the mouse cursor should not be disabled.
259 """
260 # Do not allow any site to disable mouse cursor.
261 self.SetPrefs(pyauto.kDefaultContentSettings, {u'mouselock': 2})
262 self._LaunchFSAndExpectPrompt()
263 # Allow for fullscreen mode.
264 self._AcceptFullscreenOrMouseLockRequest()
265 self._driver.set_script_timeout(2)
266 # Receive callback status (success or failure) from javascript that the
267 # click has registered and the mouse lock status has changed.
268 lock_result = self._driver.execute_async_script(
269 'lockMouse1(arguments[arguments.length - 1])')
270 self.assertEqual(lock_result, 'failure', msg='Mouse locked unexpectedly.')
271 self.assertTrue(self.WaitUntil(
272 lambda: not self.IsMouseLockPermissionRequested()))
273 self.assertTrue(self.WaitUntil(lambda: not self.IsMouseLocked()))
274
275 def testEnterTabFSWhileInBrowserFS(self):
276 """Verify able to enter into tab fullscreen while in browser fullscreen."""
277 self._InitiateBrowserFullscreen()
278 # Initiate tab fullscreen.
279 self._driver.find_element_by_id('enterFullscreen').click()
280 self.assertTrue(self.WaitUntil(lambda: self.IsFullscreenForTab()))
281 self.assertTrue(self.WaitUntil(lambda: not self.IsMouseLocked()))
282
283 def testNoMouseLockInBrowserFS(self):
284 """Verify mouse lock can't be activated in browser fullscreen.
285
286 Later on when windowed-mode mouse lock is allowed, this test will adjust to
287 verify that mouse lock in browser fullscreen requires an allow prompt, even
288 when there is a content setting for Allow.
289 """
290 self._InitiateBrowserFullscreen()
291 self._driver.find_element_by_id('lockMouse1').click()
292 self._driver.set_script_timeout(2)
293 # Receive callback status (success or failure) from javascript that the
294 # click has registered and the mouse lock status had changed.
295 lock_result = self._driver.execute_async_script(
296 'lockMouse1(arguments[arguments.length - 1])')
dennis_jeffrey 2012/04/23 23:25:18 should we add a semicolon after the javascript sta
dyu1 2012/04/24 00:11:00 Done.
297 self.assertEqual(
298 lock_result, 'failure', msg='Mouse locked in browser fullscreen.')
299 self.assertTrue(self.WaitUntil(lambda: not self.IsMouseLocked()),
300 msg='Mouse is locked in browser fullscreen.')
301
302 def testMouseLockExitWhenBrowserLoseFocus(self):
303 """Verify mouse lock breaks when browser loses focus.
304
305 Mouse lock breaks when the focus is placed on another new window.
306 """
307 self.NavigateToURL(self.GetHttpURLForDataPath(
308 'fullscreen_mouselock', 'fullscreen_mouselock.html'))
309 self._driver.find_element_by_id('enterFullscreen').click()
310 self._driver.find_element_by_id('lockMouse1').click()
311 self.AcceptCurrentFullscreenOrMouseLockRequest()
312 self.WaitUntil(lambda: self.IsFullscreenForTab())
313 self.WaitUntil(lambda: self.IsMouseLocked())
314 # Open a new window to shift focus away.
315 self.OpenNewBrowserWindow(True)
316 self.assertTrue(self.WaitUntil(lambda: self.IsFullscreenForTab()))
317 self.assertTrue(self.WaitUntil(lambda: not self.IsMouseLocked()),
318 msg='Alert dialog did not break mouse lock.')
319
320 def ExitTabFSToBrowserFS(self):
321 """Verify exiting tab fullscreen leaves browser in browser fullscreen.
322
323 The browser initiates browser fullscreen, then initiates tab fullscreen. The
324 test verifies that existing tab fullscreen by simulating ESC key press or
325 clicking the js function to exitFullscreen() will exit the tab fullscreen
326 leaving browser fullscreen intact.
327 """
328 self._InitiateBrowserFullscreen()
329 # Initiate tab fullscreen.
330 self._driver.find_element_by_id('enterFullscreen').click()
331 self.assertTrue(self.WaitUntil(lambda: self.IsFullscreenForTab()))
332 # Require manual intervention to send ESC key due to crbug.com/123930.
333 # TODO(dyu): Update to a full test once associated bug is fixed.
334 print "Press ESC key to exit tab fullscreen."
335 time.sleep(5)
336 self.assertTrue(self.WaitUntil(lambda: not self.IsFullscreenForTab()))
337 self.assertTrue(self.WaitUntil(lambda: self.IsFullscreenForBrowser()),
338 msg='Not in browser fullscreen mode.')
339
340 self._driver.find_element_by_id('enterFullscreen').click()
341 self.assertTrue(self.WaitUntil(lambda: self.IsFullscreenForTab()))
342 # Exit tab fullscreen by clicking button exitFullscreen().
343 self._driver.find_element_by_id('exitFullscreen').click()
344 self.assertTrue(self.WaitUntil(lambda: not self.IsFullscreenForTab()))
345 self.assertTrue(self.WaitUntil(lambda: self.IsFullscreenForBrowser()),
346 msg='Not in browser fullscreen mode.')
347
348 def F11KeyExitsTabAndBrowserFS(self):
349 """Verify existing tab fullscreen exits all fullscreen modes.
350
351 The browser initiates browser fullscreen, then initiates tab fullscreen. The
352 test verifies that existing tab fullscreen by simulating F11 key press or
353 CMD + SHIFT + F keys on the Mac will exit the tab fullscreen and the
354 browser fullscreen.
355 """
356 self._InitiateBrowserFullscreen()
357 # Initiate tab fullscreen.
358 self._driver.find_element_by_id('enterFullscreen').click()
359 self.assertTrue(self.WaitUntil(lambda: self.IsFullscreenForTab()))
360 # Require manual intervention to send F11 key due to crbug.com/123930.
361 # TODO(dyu): Update to a full test once associated bug is fixed.
362 print "Press F11 key to exit tab fullscreen."
363 time.sleep(5)
364 self.assertTrue(self.WaitUntil(lambda: not self.IsFullscreenForTab()))
365 self.assertTrue(self.WaitUntil(lambda: not self.IsFullscreenForBrowser()),
366 msg='Browser is in fullscreen mode.')
367
368 def SearchForTextOutsideOfContainer(self):
369 """Verify text outside of container is not visible when fullscreen.
370
371 Verify this test manually until there is a way to find text on screen
372 without using FindInPage().
373
374 The text that is outside of the fullscreen container should only be visible
375 when fullscreen is off. The text should not be visible while in fullscreen
376 mode.
377 """
378 self.NavigateToURL(self.GetHttpURLForDataPath(
379 'fullscreen_mouselock', 'fullscreen_mouselock.html'))
380 # Should not be in fullscreen mode during initial launch.
381 self.assertFalse(self.IsFullscreenForBrowser())
382 self.assertFalse(self.IsFullscreenForTab())
383 self.assertTrue(
384 self.WaitUntil(lambda: self.FindInPage(
385 'This text is outside of the container')['match_count'],
386 expect_retval=1))
387 # Go into fullscreen mode.
388 self._driver.find_element_by_id('enterFullscreen').click()
389 self.assertTrue(self.WaitUntil(self.IsFullscreenForTab))
390 # TODO(dyu): find a way to verify on screen text instead of using
391 # FindInPage() which searches for text in the HTML.
392
94 393
95 if __name__ == '__main__': 394 if __name__ == '__main__':
96 pyauto_functional.Main() 395 pyauto_functional.Main()
OLDNEW
« no previous file with comments | « chrome/test/functional/PYAUTO_TESTS ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698