| 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 """PyAuto: Python Interface to Chromium's Automation Proxy. | 6 """PyAuto: Python Interface to Chromium's Automation Proxy. |
| 7 | 7 |
| 8 PyAuto uses swig to expose Automation Proxy interfaces to Python. | 8 PyAuto uses swig to expose Automation Proxy interfaces to Python. |
| 9 For complete documentation on the functionality available, | 9 For complete documentation on the functionality available, |
| 10 run pydoc on this file. | 10 run pydoc on this file. |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 from pyauto_errors import NTPThumbnailNotShownError | 89 from pyauto_errors import NTPThumbnailNotShownError |
| 90 import pyauto_utils | 90 import pyauto_utils |
| 91 import simplejson as json # found in third_party | 91 import simplejson as json # found in third_party |
| 92 | 92 |
| 93 _CHROME_DRIVER_FACTORY = None | 93 _CHROME_DRIVER_FACTORY = None |
| 94 _HTTP_SERVER = None | 94 _HTTP_SERVER = None |
| 95 _REMOTE_PROXY = None | 95 _REMOTE_PROXY = None |
| 96 _OPTIONS = None | 96 _OPTIONS = None |
| 97 _BROWSER_PID = None | 97 _BROWSER_PID = None |
| 98 | 98 |
| 99 # TODO(bartfab): Remove when crosbug.com/20709 is fixed. |
| 100 AUTO_CLEAR_LOCAL_STATE_MAGIC_FILE = '/root/.forget_usernames' |
| 101 |
| 99 | 102 |
| 100 class PyUITest(pyautolib.PyUITestBase, unittest.TestCase): | 103 class PyUITest(pyautolib.PyUITestBase, unittest.TestCase): |
| 101 """Base class for UI Test Cases in Python. | 104 """Base class for UI Test Cases in Python. |
| 102 | 105 |
| 103 A browser is created before executing each test, and is destroyed after | 106 A browser is created before executing each test, and is destroyed after |
| 104 each test irrespective of whether the test passed or failed. | 107 each test irrespective of whether the test passed or failed. |
| 105 | 108 |
| 106 You should derive from this class and create methods with 'test' prefix, | 109 You should derive from this class and create methods with 'test' prefix, |
| 107 and use methods inherited from PyUITestBase (the C++ side). | 110 and use methods inherited from PyUITestBase (the C++ side). |
| 108 | 111 |
| (...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 441 def CleanupFlimflamDirsOnChromeOS(): | 444 def CleanupFlimflamDirsOnChromeOS(): |
| 442 """Clean the contents of flimflam profiles and restart flimflam.""" | 445 """Clean the contents of flimflam profiles and restart flimflam.""" |
| 443 PyUITest.RunSuperuserActionOnChromeOS('CleanFlimflamDirs') | 446 PyUITest.RunSuperuserActionOnChromeOS('CleanFlimflamDirs') |
| 444 | 447 |
| 445 @staticmethod | 448 @staticmethod |
| 446 def RemoveAllCryptohomeVaultsOnChromeOS(): | 449 def RemoveAllCryptohomeVaultsOnChromeOS(): |
| 447 """Remove any existing cryptohome vaults.""" | 450 """Remove any existing cryptohome vaults.""" |
| 448 PyUITest.RunSuperuserActionOnChromeOS('RemoveAllCryptohomeVaults') | 451 PyUITest.RunSuperuserActionOnChromeOS('RemoveAllCryptohomeVaults') |
| 449 | 452 |
| 450 @staticmethod | 453 @staticmethod |
| 454 def TryToDisableLocalStateAutoClearingOnChromeOS(): |
| 455 """Disable clearing of the local state on session manager startup. |
| 456 |
| 457 TODO(bartfab): Remove this method when crosbug.com/20709 is fixed. |
| 458 """ |
| 459 PyUITest.RunSuperuserActionOnChromeOS('TryToDisableLocalStateAutoClearing') |
| 460 |
| 461 @staticmethod |
| 462 def TryToEnableLocalStateAutoClearingOnChromeOS(): |
| 463 """Enable clearing of the local state on session manager startup. |
| 464 |
| 465 TODO(bartfab): Remove this method when crosbug.com/20709 is fixed. |
| 466 """ |
| 467 PyUITest.RunSuperuserActionOnChromeOS('TryToEnableLocalStateAutoClearing') |
| 468 |
| 469 @staticmethod |
| 470 def IsLocalStateAutoClearingEnabledOnChromeOS(): |
| 471 """Check if the session manager is set to clear the local state on startup. |
| 472 |
| 473 TODO(bartfab): Remove this method when crosbug.com/20709 is fixed. |
| 474 """ |
| 475 return os.path.exists(AUTO_CLEAR_LOCAL_STATE_MAGIC_FILE) |
| 476 |
| 477 @staticmethod |
| 451 def _IsInodeNew(path, old_inode): | 478 def _IsInodeNew(path, old_inode): |
| 452 """Determine whether an inode has changed. POSIX only. | 479 """Determine whether an inode has changed. POSIX only. |
| 453 | 480 |
| 454 Args: | 481 Args: |
| 455 path: The file path to check for changes. | 482 path: The file path to check for changes. |
| 456 old_inode: The old inode number. | 483 old_inode: The old inode number. |
| 457 | 484 |
| 458 Returns: | 485 Returns: |
| 459 True if the path exists and its inode number is different from old_inode. | 486 True if the path exists and its inode number is different from old_inode. |
| 460 False otherwise. | 487 False otherwise. |
| (...skipping 824 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1285 """Return info about preferences. | 1312 """Return info about preferences. |
| 1286 | 1313 |
| 1287 This represents a snapshot of the local state preferences. If you expect | 1314 This represents a snapshot of the local state preferences. If you expect |
| 1288 local state preferences to have changed, you need to call this method again | 1315 local state preferences to have changed, you need to call this method again |
| 1289 to get a fresh snapshot. | 1316 to get a fresh snapshot. |
| 1290 | 1317 |
| 1291 Returns: | 1318 Returns: |
| 1292 an instance of prefs_info.PrefsInfo | 1319 an instance of prefs_info.PrefsInfo |
| 1293 """ | 1320 """ |
| 1294 return prefs_info.PrefsInfo( | 1321 return prefs_info.PrefsInfo( |
| 1295 self._SendJSONRequest(0, | 1322 self._SendJSONRequest(-1, |
| 1296 json.dumps({'command': 'GetLocalStatePrefsInfo'}), | 1323 json.dumps({'command': 'GetLocalStatePrefsInfo'}), |
| 1297 self.action_max_timeout_ms())) | 1324 self.action_max_timeout_ms())) |
| 1298 | 1325 |
| 1299 def SetLocalStatePrefs(self, path, value): | 1326 def SetLocalStatePrefs(self, path, value): |
| 1300 """Set local state preference for the given path. | 1327 """Set local state preference for the given path. |
| 1301 | 1328 |
| 1302 Preferences are stored by Chromium as a hierarchical dictionary. | 1329 Preferences are stored by Chromium as a hierarchical dictionary. |
| 1303 dot-separated paths can be used to refer to a particular preference. | 1330 dot-separated paths can be used to refer to a particular preference. |
| 1304 example: "session.restore_on_startup" | 1331 example: "session.restore_on_startup" |
| 1305 | 1332 |
| (...skipping 3982 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5288 successful = result.wasSuccessful() | 5315 successful = result.wasSuccessful() |
| 5289 if not successful: | 5316 if not successful: |
| 5290 pyauto_tests_file = os.path.join(self.TestsDir(), self._tests_filename) | 5317 pyauto_tests_file = os.path.join(self.TestsDir(), self._tests_filename) |
| 5291 print >>sys.stderr, 'Tests can be disabled by editing %s. ' \ | 5318 print >>sys.stderr, 'Tests can be disabled by editing %s. ' \ |
| 5292 'Ref: %s' % (pyauto_tests_file, _PYAUTO_DOC_URL) | 5319 'Ref: %s' % (pyauto_tests_file, _PYAUTO_DOC_URL) |
| 5293 sys.exit(not successful) | 5320 sys.exit(not successful) |
| 5294 | 5321 |
| 5295 | 5322 |
| 5296 if __name__ == '__main__': | 5323 if __name__ == '__main__': |
| 5297 Main() | 5324 Main() |
| OLD | NEW |