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 1276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1287 an instance of prefs_info.PrefsInfo | 1287 an instance of prefs_info.PrefsInfo |
1288 """ | 1288 """ |
1289 cmd_dict = { | 1289 cmd_dict = { |
1290 'command': 'GetPrefsInfo', | 1290 'command': 'GetPrefsInfo', |
1291 'windex': 0, | 1291 'windex': 0, |
1292 } | 1292 } |
1293 return prefs_info.PrefsInfo( | 1293 return prefs_info.PrefsInfo( |
1294 self._SendJSONRequest(-1, json.dumps(cmd_dict), | 1294 self._SendJSONRequest(-1, json.dumps(cmd_dict), |
1295 self.action_max_timeout_ms())) | 1295 self.action_max_timeout_ms())) |
1296 | 1296 |
1297 def SetPrefs(self, path, value): | 1297 def SetPrefs(self, path, value, windex=0): |
1298 """Set preference for the given path. | 1298 """Set preference for the given path. |
1299 | 1299 |
1300 Preferences are stored by Chromium as a hierarchical dictionary. | 1300 Preferences are stored by Chromium as a hierarchical dictionary. |
1301 dot-separated paths can be used to refer to a particular preference. | 1301 dot-separated paths can be used to refer to a particular preference. |
1302 example: "session.restore_on_startup" | 1302 example: "session.restore_on_startup" |
1303 | 1303 |
1304 Some preferences are managed, that is, they cannot be changed by the | 1304 Some preferences are managed, that is, they cannot be changed by the |
1305 user. It's up to the user to know which ones can be changed. Typically, | 1305 user. It's up to the user to know which ones can be changed. Typically, |
1306 the options available via Chromium preferences can be changed. | 1306 the options available via Chromium preferences can be changed. |
1307 | 1307 |
1308 Args: | 1308 Args: |
1309 path: the path the preference key that needs to be changed | 1309 path: the path the preference key that needs to be changed |
1310 example: "session.restore_on_startup" | 1310 example: "session.restore_on_startup" |
1311 One of the equivalent names in chrome/common/pref_names.h could | 1311 One of the equivalent names in chrome/common/pref_names.h could |
1312 also be used. | 1312 also be used. |
1313 value: the value to be set. It could be plain values like int, bool, | 1313 value: the value to be set. It could be plain values like int, bool, |
1314 string or complex ones like list. | 1314 string or complex ones like list. |
1315 The user has to ensure that the right value is specified for the | 1315 The user has to ensure that the right value is specified for the |
1316 right key. It's useful to dump the preferences first to determine | 1316 right key. It's useful to dump the preferences first to determine |
1317 what type is expected for a particular preference path. | 1317 what type is expected for a particular preference path. |
| 1318 windex: window index to work on. Defaults to 0 (first window). |
1318 """ | 1319 """ |
1319 cmd_dict = { | 1320 cmd_dict = { |
1320 'command': 'SetPrefs', | 1321 'command': 'SetPrefs', |
1321 'windex': 0, | 1322 'windex': windex, |
1322 'path': path, | 1323 'path': path, |
1323 'value': value, | 1324 'value': value, |
1324 } | 1325 } |
1325 self._GetResultFromJSONRequest(cmd_dict, windex=None) | 1326 self._GetResultFromJSONRequest(cmd_dict, windex=None) |
1326 | 1327 |
1327 def SendWebkitKeyEvent(self, key_type, key_code, tab_index=0, windex=0): | 1328 def SendWebkitKeyEvent(self, key_type, key_code, tab_index=0, windex=0): |
1328 """Send a webkit key event to the browser. | 1329 """Send a webkit key event to the browser. |
1329 | 1330 |
1330 Args: | 1331 Args: |
1331 key_type: the raw key type such as 0 for up and 3 for down. | 1332 key_type: the raw key type such as 0 for up and 3 for down. |
(...skipping 3698 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5030 test_names = pyauto_utils.Shard(test_names, shard_index, num_shards) | 5031 test_names = pyauto_utils.Shard(test_names, shard_index, num_shards) |
5031 | 5032 |
5032 test_names *= self._options.repeat | 5033 test_names *= self._options.repeat |
5033 logging.debug("Loading %d tests from %s", len(test_names), test_names) | 5034 logging.debug("Loading %d tests from %s", len(test_names), test_names) |
5034 if self._options.list_tests: # List tests and exit | 5035 if self._options.list_tests: # List tests and exit |
5035 for name in test_names: | 5036 for name in test_names: |
5036 print name | 5037 print name |
5037 sys.exit(0) | 5038 sys.exit(0) |
5038 pyauto_suite = PyUITestSuite(suite_args) | 5039 pyauto_suite = PyUITestSuite(suite_args) |
5039 loaded_tests = unittest.defaultTestLoader.loadTestsFromNames(test_names) | 5040 loaded_tests = unittest.defaultTestLoader.loadTestsFromNames(test_names) |
| 5041 pyauto_suite = PyUITestSuite(suite_args) |
5040 pyauto_suite.addTests(loaded_tests) | 5042 pyauto_suite.addTests(loaded_tests) |
5041 verbosity = 1 | 5043 verbosity = 1 |
5042 if self._options.verbose: | 5044 if self._options.verbose: |
5043 verbosity = 2 | 5045 verbosity = 2 |
5044 result = PyAutoTextTestRunner(verbosity=verbosity).run(pyauto_suite) | 5046 result = PyAutoTextTestRunner(verbosity=verbosity).run(pyauto_suite) |
5045 del loaded_tests # Need to destroy test cases before the suite | 5047 del loaded_tests # Need to destroy test cases before the suite |
5046 del pyauto_suite | 5048 del pyauto_suite |
5047 successful = result.wasSuccessful() | 5049 successful = result.wasSuccessful() |
5048 if not successful: | 5050 if not successful: |
5049 pyauto_tests_file = os.path.join(self.TestsDir(), self._tests_filename) | 5051 pyauto_tests_file = os.path.join(self.TestsDir(), self._tests_filename) |
5050 print >>sys.stderr, 'Tests can be disabled by editing %s. ' \ | 5052 print >>sys.stderr, 'Tests can be disabled by editing %s. ' \ |
5051 'Ref: %s' % (pyauto_tests_file, _PYAUTO_DOC_URL) | 5053 'Ref: %s' % (pyauto_tests_file, _PYAUTO_DOC_URL) |
5052 sys.exit(not successful) | 5054 sys.exit(not successful) |
5053 | 5055 |
5054 | 5056 |
5055 if __name__ == '__main__': | 5057 if __name__ == '__main__': |
5056 Main() | 5058 Main() |
OLD | NEW |