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 |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 'fullscreen_mouselock', 'fullscreen_mouselock.html')) | 136 'fullscreen_mouselock', 'fullscreen_mouselock.html')) |
137 # Should not be in fullscreen mode during initial launch. | 137 # Should not be in fullscreen mode during initial launch. |
138 self.assertFalse(self.IsFullscreenForBrowser()) | 138 self.assertFalse(self.IsFullscreenForBrowser()) |
139 self.assertFalse(self.IsFullscreenForTab()) | 139 self.assertFalse(self.IsFullscreenForTab()) |
140 # Initiate browser fullscreen. | 140 # Initiate browser fullscreen. |
141 self.ApplyAccelerator(pyauto.IDC_FULLSCREEN) | 141 self.ApplyAccelerator(pyauto.IDC_FULLSCREEN) |
142 self.assertTrue(self.WaitUntil(self.IsFullscreenForBrowser)) | 142 self.assertTrue(self.WaitUntil(self.IsFullscreenForBrowser)) |
143 self.assertTrue(self.WaitUntil(lambda: not self.IsFullscreenForTab())) | 143 self.assertTrue(self.WaitUntil(lambda: not self.IsFullscreenForTab())) |
144 self.assertTrue(self.WaitUntil(lambda: not self.IsMouseLocked())) | 144 self.assertTrue(self.WaitUntil(lambda: not self.IsMouseLocked())) |
145 | 145 |
| 146 def _InitiateTabFullscreen(self): |
| 147 """Helper function that initiates tab fullscreen.""" |
| 148 self.NavigateToURL(self.GetHttpURLForDataPath( |
| 149 'fullscreen_mouselock', 'fullscreen_mouselock.html')) |
| 150 # Initiate tab fullscreen. |
| 151 self._driver.find_element_by_id('enterFullscreen').click() |
| 152 self.assertTrue(self.WaitUntil(self.IsFullscreenForTab)) |
| 153 |
146 def _AcceptFullscreenOrMouseLockRequest(self): | 154 def _AcceptFullscreenOrMouseLockRequest(self): |
147 """Helper function to accept fullscreen or mouse lock request.""" | 155 """Helper function to accept fullscreen or mouse lock request.""" |
148 self.AcceptCurrentFullscreenOrMouseLockRequest() | 156 self.AcceptCurrentFullscreenOrMouseLockRequest() |
149 self.assertTrue(self.WaitUntil( | 157 self.assertTrue(self.WaitUntil( |
150 lambda: not self.IsFullscreenBubbleDisplayingButtons())) | 158 lambda: not self.IsFullscreenBubbleDisplayingButtons())) |
151 | 159 |
152 def _EnableFullscreenAndMouseLockMode(self): | 160 def _EnableFullscreenAndMouseLockMode(self): |
153 """Helper function to enable fullscreen and mouse lock mode.""" | 161 """Helper function to enable fullscreen and mouse lock mode.""" |
154 self._LaunchFSAndExpectPrompt(button_action='enterFullscreenAndLockMouse1') | 162 self._LaunchFSAndExpectPrompt(button_action='enterFullscreenAndLockMouse1') |
155 # Allow fullscreen. | 163 # Allow fullscreen. |
(...skipping 10 matching lines...) Expand all Loading... |
166 | 174 |
167 Args: | 175 Args: |
168 button_action: The button id to click to initiate an action. Default is to | 176 button_action: The button id to click to initiate an action. Default is to |
169 click lockMouse1. | 177 click lockMouse1. |
170 """ | 178 """ |
171 self._driver.find_element_by_id(button_action).click() | 179 self._driver.find_element_by_id(button_action).click() |
172 self.assertTrue(self.WaitUntil(self.IsMouseLockPermissionRequested)) | 180 self.assertTrue(self.WaitUntil(self.IsMouseLockPermissionRequested)) |
173 self.AcceptCurrentFullscreenOrMouseLockRequest() | 181 self.AcceptCurrentFullscreenOrMouseLockRequest() |
174 self.assertTrue(self.IsMouseLocked()) | 182 self.assertTrue(self.IsMouseLocked()) |
175 | 183 |
| 184 def _EnableAndReturnLockMouseResult(self): |
| 185 """Helper function to enable and return mouse lock result.""" |
| 186 self.NavigateToURL(self.GetHttpURLForDataPath( |
| 187 'fullscreen_mouselock', 'fullscreen_mouselock.html')) |
| 188 self._driver.find_element_by_id('lockMouse2').click() |
| 189 self.assertTrue( |
| 190 self.WaitUntil(self.IsMouseLockPermissionRequested)) |
| 191 self.AcceptCurrentFullscreenOrMouseLockRequest() |
| 192 # Waits until lock_result gets 'success' or 'failure'. |
| 193 return self._driver.execute_script('return lock_result') |
| 194 |
176 def testPrefsForFullscreenAllowed(self): | 195 def testPrefsForFullscreenAllowed(self): |
177 """Verify prefs when fullscreen is allowed.""" | 196 """Verify prefs when fullscreen is allowed.""" |
178 self._LaunchFSAndExpectPrompt() | 197 self._LaunchFSAndExpectPrompt() |
179 self._AcceptFullscreenOrMouseLockRequest() | 198 self._AcceptFullscreenOrMouseLockRequest() |
180 content_settings = ( | 199 content_settings = ( |
181 self.GetPrefsInfo().Prefs()['profile']['content_settings']) | 200 self.GetPrefsInfo().Prefs()['profile']['content_settings']) |
182 self.assertEqual( | 201 self.assertEqual( |
183 {self._hostname_pattern + ',*': {'fullscreen': 1}}, # Allow hostname. | 202 {self._hostname_pattern + ',*': {'fullscreen': 1}}, # Allow hostname. |
184 content_settings['pattern_pairs'], | 203 content_settings['pattern_pairs'], |
185 msg='Saved hostname pattern does not match expected pattern.') | 204 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.""" | 387 """Verify mouse lock bubble goes away when tab loses focus.""" |
369 self.NavigateToURL(self.GetHttpURLForDataPath( | 388 self.NavigateToURL(self.GetHttpURLForDataPath( |
370 'fullscreen_mouselock', 'fullscreen_mouselock.html')) | 389 'fullscreen_mouselock', 'fullscreen_mouselock.html')) |
371 self._driver.find_element_by_id('lockMouse1').click() | 390 self._driver.find_element_by_id('lockMouse1').click() |
372 self.assertTrue(self.WaitUntil(self.IsMouseLockPermissionRequested)) | 391 self.assertTrue(self.WaitUntil(self.IsMouseLockPermissionRequested)) |
373 self.AppendTab(pyauto.GURL('chrome://newtab')) | 392 self.AppendTab(pyauto.GURL('chrome://newtab')) |
374 self.assertTrue(self.WaitUntil( | 393 self.assertTrue(self.WaitUntil( |
375 lambda: not self.IsFullscreenBubbleDisplayingButtons()), | 394 lambda: not self.IsFullscreenBubbleDisplayingButtons()), |
376 msg='Mouse lock bubble did not clear when tab lost focus.') | 395 msg='Mouse lock bubble did not clear when tab lost focus.') |
377 | 396 |
| 397 def testTabFSExitWhenNavBackToPrevPage(self): |
| 398 """Verify tab fullscreen exit when navigating back to previous page. |
| 399 |
| 400 This test navigates to a new page while in tab fullscreen mode by using |
| 401 GoBack() to navigate to the previous google.html page. |
| 402 """ |
| 403 self.NavigateToURL(self.GetHttpURLForDataPath('google', 'google.html')) |
| 404 self._InitiateTabFullscreen() |
| 405 self.GetBrowserWindow().GetTab().GoBack() |
| 406 self.assertFalse( |
| 407 self.IsFullscreenForTab(), |
| 408 msg='Tab fullscreen did not exit when navigating to a new page.') |
| 409 |
| 410 def testTabFSExitWhenNavToNewPage(self): |
| 411 """Verify tab fullscreen exit when navigating to a new website. |
| 412 |
| 413 This test navigates to a new website while in tab fullscreen. |
| 414 """ |
| 415 self._InitiateTabFullscreen() |
| 416 self.NavigateToURL(self.GetHttpURLForDataPath('google', 'google.html')) |
| 417 self.assertFalse( |
| 418 self.IsFullscreenForTab(), |
| 419 msg='Tab fullscreen did not exit when navigating to a new website.') |
| 420 |
| 421 def testTabFSDoesNotExitForAnchorLinks(self): |
| 422 """Verify tab fullscreen does not exit for anchor links. |
| 423 |
| 424 Tab fullscreen should not exit when following a link to the same page such |
| 425 as example.html#anchor. |
| 426 """ |
| 427 self._InitiateTabFullscreen() |
| 428 self._driver.find_element_by_id('anchor').click() |
| 429 self.assertTrue( |
| 430 self.WaitUntil(self.IsFullscreenForTab), |
| 431 msg='Tab fullscreen should not exit when clicking on an anchor link.') |
| 432 |
| 433 def testMLExitWhenNavBackToPrevPage(self): |
| 434 """Verify mouse lock exit when navigating back to previous page. |
| 435 |
| 436 This test navigates to a new page while mouse lock is activated by using |
| 437 GoBack() to navigate to the previous google.html page. |
| 438 """ |
| 439 self.NavigateToURL(self.GetHttpURLForDataPath('google', 'google.html')) |
| 440 lock_result = self._EnableAndReturnLockMouseResult() |
| 441 self.assertEqual( |
| 442 lock_result, 'success', msg='Mouse is not locked.') |
| 443 self.GetBrowserWindow().GetTab().GoBack() |
| 444 self.assertFalse( |
| 445 self.IsMouseLocked(), |
| 446 msg='Mouse lock did not exit when navigating to the prev page.') |
| 447 |
| 448 def testMLExitWhenNavToNewPage(self): |
| 449 """Verify mouse lock exit when navigating to a new website.""" |
| 450 lock_result = self._EnableAndReturnLockMouseResult() |
| 451 self.assertEqual( |
| 452 lock_result, 'success', msg='Mouse is not locked.') |
| 453 self.NavigateToURL(self.GetHttpURLForDataPath('google', 'google.html')) |
| 454 self.assertFalse( |
| 455 self.IsMouseLocked(), |
| 456 msg='Mouse lock did not exit when navigating to a new website.') |
| 457 |
| 458 def testMLDoesNotExitForAnchorLinks(self): |
| 459 """Verify mouse lock does not exit for anchor links. |
| 460 |
| 461 Mouse lock should not exist when following a link to the same page such as |
| 462 example.html#anchor. |
| 463 """ |
| 464 lock_result = self._EnableAndReturnLockMouseResult() |
| 465 self.assertEqual( |
| 466 lock_result, 'success', msg='Mouse is not locked.') |
| 467 self._driver.execute_script('document.getElementById("anchor").click()') |
| 468 self.assertTrue(self.WaitUntil(self.IsMouseLocked), |
| 469 msg='Mouse lock broke when clicking on an anchor link.') |
| 470 |
378 def ExitTabFSToBrowserFS(self): | 471 def ExitTabFSToBrowserFS(self): |
379 """Verify exiting tab fullscreen leaves browser in browser fullscreen. | 472 """Verify exiting tab fullscreen leaves browser in browser fullscreen. |
380 | 473 |
381 This test is semi-automated. | 474 This test is semi-automated. |
382 | 475 |
383 The browser initiates browser fullscreen, then initiates tab fullscreen. The | 476 The browser initiates browser fullscreen, then initiates tab fullscreen. The |
384 test verifies that existing tab fullscreen by simulating ESC key press or | 477 test verifies that existing tab fullscreen by simulating ESC key press or |
385 clicking the js function to exitFullscreen() will exit the tab fullscreen | 478 clicking the js function to exitFullscreen() will exit the tab fullscreen |
386 leaving browser fullscreen intact. | 479 leaving browser fullscreen intact. |
387 """ | 480 """ |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
476 self.NavigateToURL(url2, 0, 1) | 569 self.NavigateToURL(url2, 0, 1) |
477 self._driver.switch_to_window(tab2) | 570 self._driver.switch_to_window(tab2) |
478 self._EnableMouseLockMode() # Lock mouse in tab 2. | 571 self._EnableMouseLockMode() # Lock mouse in tab 2. |
479 raw_input('Manually move the mouse cursor on the page in tab 2. Shift+Tab \ | 572 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 \ | 573 into tab 1, click on lockMouse1() button, and move the mouse \ |
481 cursor on the page in tab 1. Verify mouse movement is smooth.') | 574 cursor on the page in tab 1. Verify mouse movement is smooth.') |
482 | 575 |
483 | 576 |
484 if __name__ == '__main__': | 577 if __name__ == '__main__': |
485 pyauto_functional.Main() | 578 pyauto_functional.Main() |
OLD | NEW |