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 shutil | 9 import shutil |
9 | 10 |
10 import pyauto_functional # Must be imported before pyauto | 11 import pyauto_functional # Must be imported before pyauto |
11 import pyauto | 12 import pyauto |
12 import test_utils | 13 import test_utils |
13 from selenium.webdriver.common.keys import Keys | 14 from selenium.webdriver.common.keys import Keys |
15 from webdriver_pages import settings | |
14 | 16 |
15 | 17 |
16 class FullscreenMouselockTest(pyauto.PyUITest): | 18 class FullscreenMouselockTest(pyauto.PyUITest): |
17 """TestCase for Fullscreen and Mouse Lock.""" | 19 """TestCase for Fullscreen and Mouse Lock.""" |
18 | 20 |
21 def setUp(self): | |
22 pyauto.PyUITest.setUp(self) | |
23 self._driver = self.NewWebDriver() | |
24 # Get the hostname pattern (e.g. http://127.0.0.1:57622). | |
25 self._hostname_pattern = ( | |
26 re.sub('/files/$', '', self.GetHttpURLForDataPath(''))) | |
27 | |
28 def Debug(self): | |
29 """Test method for experimentation. | |
30 | |
31 This method will not run automatically. | |
32 """ | |
33 self._driver = self.NewWebDriver() | |
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, 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.
| |
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. | |
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.
| |
115 | |
116 Args: | |
117 buttonAction: The button id to click to initiate an action. Default is to | |
118 click enterFullscreen. | |
dennis_jeffrey
2012/04/17 17:57:14
indent by 4 more spaces
dyu1
2012/04/23 18:50:26
Done.
| |
119 """ | |
120 self.NavigateToURL(self.GetHttpURLForDataPath( | |
121 'fullscreen_mouselock', 'fullscreen_mouselock.html')) | |
122 # Should not be in fullscreen mode during initial launch. | |
123 self.assertFalse(self.IsFullscreenForBrowser()) | |
124 self.assertFalse(self.IsFullscreenForTab()) | |
125 # Go into fullscreen mode. | |
126 self._driver.find_element_by_id(buttonAction).click() | |
127 self.assertTrue(self.WaitUntil(self.IsFullscreenForTab)) | |
128 # Bubble should display prompting to allow fullscreen. | |
129 self.assertTrue(self.IsFullscreenPermissionRequested()) | |
130 | |
131 def _AcceptFullscreenOrMouseLockRequest(self): | |
132 """Helper function to accept Fullscreen or Mouse Lock request.""" | |
133 self.AcceptCurrentFullscreenOrMouseLockRequest() | |
134 self.assertTrue(self.WaitUntil( | |
135 lambda: not self.IsFullscreenBubbleDisplayingButtons())) | |
136 | |
137 def EnableFullscreenAndMouseLockMode(self): | |
138 """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.
| |
139 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
| |
140 # Allow fullscreen. | |
141 self.AcceptCurrentFullscreenOrMouseLockRequest() | |
142 # The wait is needed due to crbug.com/123396. Should be able to click the | |
143 # fullscreen and mouselock button and be both accepted in a single action. | |
144 self.assertTrue(self.WaitUntil(self.IsMouseLockPermissionRequested)) | |
145 # Allow mouse lock. | |
146 self.AcceptCurrentFullscreenOrMouseLockRequest() | |
147 self.assertTrue(self.WaitUntil(self.IsMouseLocked)) | |
148 | |
149 def EnableMouseLockMode(self, buttonAction='lockMouse1'): | |
150 """Helper function to enable mouse lock mode. | |
151 | |
152 For now, to lock the mouse, the browser needs to be in fullscreen mode. | |
153 | |
154 Args: | |
155 buttonAction: The button id to click to initiate an action. Default is to | |
156 click lockMouse1. | |
157 """ | |
158 self._driver.find_element_by_id(buttonAction).click() | |
159 self.assertTrue(self.IsMouseLockPermissionRequested()) | |
160 self.AcceptCurrentFullscreenOrMouseLockRequest() | |
161 self.assertTrue(self.IsMouseLocked()) | |
162 | |
163 def testPrefsLineEntryForFullscreenAllowed(self): | |
164 """Verify line entry when fullscreen is allowed.""" | |
165 self.LaunchFSAndExpectPrompt() | |
166 self._AcceptFullscreenOrMouseLockRequest() | |
167 content_settings = ( | |
168 self.GetPrefsInfo().Prefs()['profile']['content_settings']) | |
169 self.assertEqual( | |
170 {self._hostname_pattern + ',*': {'fullscreen': 1}}, # Allow hostname. | |
171 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
| |
172 | |
173 def testPrefsLineEntryForFullscreenExit(self): | |
174 """Verify line entry is empty when exit fullscreen mode before allowing.""" | |
175 self.LaunchFSAndExpectPrompt() | |
176 self._driver.find_element_by_id('exitFullscreen').click() | |
177 # Verify exit from fullscreen mode. | |
178 self.assertTrue(self.WaitUntil(lambda: not self.IsFullscreenForTab())) | |
179 content_settings = ( | |
180 self.GetPrefsInfo().Prefs()['profile']['content_settings']) | |
181 self.assertEqual({}, content_settings['pattern_pairs']) | |
182 | |
183 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
| |
184 """Verify hostname pattern and behavior for allowed mouse cursor lock. | |
185 | |
186 To lock the mouse, the browser needs to be in fullscreen mode. | |
187 """ | |
188 self.EnableFullscreenAndMouseLockMode() | |
189 self.EnableMouseLockMode() | |
190 expected_pattern = ( | |
191 {self._hostname_pattern + ',*': {'fullscreen': 1, 'mouselock': 1}}) | |
192 content_settings = ( | |
193 self.GetPrefsInfo().Prefs()['profile']['content_settings']) | |
194 self.assertEqual(expected_pattern, content_settings['pattern_pairs']) | |
195 | |
196 def testPatternsForAllowMouseLock(self): | |
197 """Verify hostname pattern and behavior for allowed mouse cursor lock. | |
198 | |
199 Enable fullscreen mode and enable mouse lock separately. | |
200 """ | |
201 self.LaunchFSAndExpectPrompt() | |
202 self.AcceptCurrentFullscreenOrMouseLockRequest() | |
203 self.EnableMouseLockMode() | |
204 expected_pattern = ( | |
205 {self._hostname_pattern + ',*': {'fullscreen': 1, 'mouselock': 1}}) | |
206 content_settings = ( | |
207 self.GetPrefsInfo().Prefs()['profile']['content_settings']) | |
208 self.assertEqual(expected_pattern, content_settings['pattern_pairs']) | |
209 | |
210 def testNoMouseLockRequest(self): | |
211 """Verify mouse lock request does not appear. | |
212 | |
213 When allowing all sites to disable the mouse cursor, the mouse lock request | |
214 bubble should not show. The mouse cursor should be automatically disabled | |
215 when clicking on a disable mouse button. | |
216 """ | |
217 # Allow all sites to disable mouse cursor. | |
218 self.SetPrefs(pyauto.kDefaultContentSettings, {u'mouselock': 1}) | |
219 self.LaunchFSAndExpectPrompt() | |
220 # Allow for fullscreen mode. | |
221 self._AcceptFullscreenOrMouseLockRequest() | |
222 self._driver.find_element_by_id('lockMouse1').click() | |
223 self.assertTrue(self.WaitUntil( | |
224 lambda: not self.IsMouseLockPermissionRequested())) | |
225 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
| |
226 | |
227 def testUnableToLockMouse(self): | |
228 """Verify mouse lock is disabled. | |
229 | |
230 When not allowing any site to disable the mouse cursor, the mouse lock | |
231 request bubble should not show and the mouse cursor should not be disabled. | |
232 """ | |
233 # Do not allow any site to disable mouse cursor. | |
234 self.SetPrefs(pyauto.kDefaultContentSettings, {u'mouselock': 2}) | |
235 self.LaunchFSAndExpectPrompt() | |
236 # Allow for fullscreen mode. | |
237 self._AcceptFullscreenOrMouseLockRequest() | |
238 self._driver.find_element_by_id('lockMouse1').click() | |
239 self.assertTrue(self.WaitUntil( | |
240 lambda: not self.IsMouseLockPermissionRequested())) | |
241 self.assertTrue(self.WaitUntil(lambda: not self.IsMouseLocked())) | |
242 | |
243 def SearchForTextOutsideOfContainer(self): | |
244 """Verify text outside of container is not visible when fullscreen. | |
245 | |
246 Verify this test manually until there is a way to find text on screen | |
247 without using FindInPage(). | |
248 | |
249 The text that is outside of the fullscreen container should only be visible | |
250 when fullscreen is off. The text should not be visible while in fullscreen | |
251 mode. | |
252 """ | |
253 self.NavigateToURL(self.GetHttpURLForDataPath( | |
254 'fullscreen_mouselock', 'fullscreen_mouselock.html')) | |
255 # Should not be in fullscreen mode during initial launch. | |
256 self.assertFalse(self.IsFullscreenForBrowser()) | |
257 self.assertFalse(self.IsFullscreenForTab()) | |
258 self.assertTrue( | |
259 self.WaitUntil(lambda: self.FindInPage( | |
260 'This text is outside of the container')['match_count'], | |
261 expect_retval=1)) | |
262 # Go into fullscreen mode. | |
263 self._driver.find_element_by_id('enterFullscreen').click() | |
264 self.assertTrue(self.WaitUntil(self.IsFullscreenForTab)) | |
265 # TODO(dyu): find a way to verify on screen text instead of using | |
266 # FindInPage() which searches for text in the HTML. | |
267 | |
94 | 268 |
95 if __name__ == '__main__': | 269 if __name__ == '__main__': |
96 pyauto_functional.Main() | 270 pyauto_functional.Main() |
OLD | NEW |