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

Side by Side Diff: chrome/test/pyautolib/pyauto.py

Issue 6685099: Removing command_execution_timeout_ms in favor of action_max_timeout_ms. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 9 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
OLDNEW
1 #!/usr/bin/python 1 #!/usr/bin/python
2 2
3 # Copyright (c) 2011 The Chromium Authors. All rights reserved. 3 # Copyright (c) 2011 The Chromium Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be 4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file. 5 # found in the LICENSE file.
6 6
7 """PyAuto: Python Interface to Chromium's Automation Proxy. 7 """PyAuto: Python Interface to Chromium's Automation Proxy.
8 8
9 PyAuto uses swig to expose Automation Proxy interfaces to Python. 9 PyAuto uses swig to expose Automation Proxy interfaces to Python.
10 For complete documentation on the functionality available, 10 For complete documentation on the functionality available,
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after
415 while timeout is None or time.time() - begin <= timeout: 415 while timeout is None or time.time() - begin <= timeout:
416 retval = function(*args) 416 retval = function(*args)
417 if (expect_retval is None and retval) or expect_retval == retval: 417 if (expect_retval is None and retval) or expect_retval == retval:
418 return True 418 return True
419 logging.debug('WaitUntil(%s) still waiting. ' 419 logging.debug('WaitUntil(%s) still waiting. '
420 'Expecting %s. Last returned %s.' % ( 420 'Expecting %s. Last returned %s.' % (
421 function, expect_retval, retval)) 421 function, expect_retval, retval))
422 time.sleep(retry_sleep) 422 time.sleep(retry_sleep)
423 return False 423 return False
424 424
425 class CmdExecutionTimeoutChanger(object):
426 """Facilitate temporary changes to command_execution_timeout_ms.
427
428 Automatically resets to original timeout when object is destroyed.
429 """
430 _saved_timeout = -1 # Saved value for command_execution_timeout_ms
431
432 def __init__(self, ui_test, new_timeout):
433 """Initialize.
434
435 Args:
436 ui_test: a PyUITest object
437 new_timeout: new timeout to use (in milli secs)
438 """
439 self._saved_timeout = ui_test.command_execution_timeout_ms()
440 if new_timeout != self._saved_timeout:
441 ui_test.set_command_execution_timeout_ms(new_timeout)
442 self._ui_test = ui_test
443
444 def __del__(self):
445 """Reset command_execution_timeout_ms to original value."""
446 if self._ui_test.command_execution_timeout_ms() != self._saved_timeout:
447 self._ui_test.set_command_execution_timeout_ms(self._saved_timeout)
448
449 425
450 def _GetResultFromJSONRequest(self, cmd_dict, windex=0): 426 def _GetResultFromJSONRequest(self, cmd_dict, windex=0):
451 """Issue call over the JSON automation channel and fetch output. 427 """Issue call over the JSON automation channel and fetch output.
452 428
453 This method packages the given dictionary into a json string, sends it 429 This method packages the given dictionary into a json string, sends it
430 over the JSON automation channel, loads the json output string returned,
431 and returns it back as a dictionary.
432
433 Args:
434 cmd_dict: the command dictionary. It must have a 'command' key
435 Sample:
436 {
437 'command': 'SetOmniboxText',
438 'text': text,
439 }
440 windex: 0-based window index on which to work. Default: 0 (first window)
441 Use -ve windex if the automation command does not apply to a
442 browser window. example: chromeos login
443
444 Returns:
445 a dictionary for the output returned by the automation channel.
446
447 Raises:
448 pyauto_errors.JSONInterfaceError if the automation call returns an error.
449 """
450 return self._GetResultFromJSONRequest(
451 cmd_dict, windex, timeout=self.action_max_timeout_ms())
452
453
454 def _GetResultFromJSONRequest(self, cmd_dict, windex=0, timeout=-1):
455 """Issue call over the JSON automation channel and fetch output.
456
457 This method packages the given dictionary into a json string, sends it
454 over the JSON automation channel, loads the json output string returned, 458 over the JSON automation channel, loads the json output string returned,
455 and returns it back as a dictionary. 459 and returns it back as a dictionary.
456 460
457 Args: 461 Args:
458 cmd_dict: the command dictionary. It must have a 'command' key 462 cmd_dict: the command dictionary. It must have a 'command' key
459 Sample: 463 Sample:
460 { 464 {
461 'command': 'SetOmniboxText', 465 'command': 'SetOmniboxText',
462 'text': text, 466 'text': text,
463 } 467 }
464 windex: 0-based window index on which to work. Default: 0 (first window) 468 windex: 0-based window index on which to work. Default: 0 (first window)
465 Use -ve windex if the automation command does not apply to a 469 Use -ve windex if the automation command does not apply to a
466 browser window. example: chromeos login 470 browser window. example: chromeos login
467 471
472 timeout: request timeout
473
468 Returns: 474 Returns:
469 a dictionary for the output returned by the automation channel. 475 a dictionary for the output returned by the automation channel.
470 476
471 Raises: 477 Raises:
472 pyauto_errors.JSONInterfaceError if the automation call returns an error. 478 pyauto_errors.JSONInterfaceError if the automation call returns an error.
473 """ 479 """
474 ret_dict = json.loads(self._SendJSONRequest(windex, json.dumps(cmd_dict))) 480 if timeout == -1: # Default
481 timeout = self.action_max_timeout_ms()
Paweł Hajdan Jr. 2011/03/26 10:55:12 Similarly to action_max_timeout, you can add acces
482 ret_dict = json.loads(self._SendJSONRequest(
483 windex, json.dumps(cmd_dict), timeout))
475 if ret_dict.has_key('error'): 484 if ret_dict.has_key('error'):
476 raise JSONInterfaceError(ret_dict['error']) 485 raise JSONInterfaceError(ret_dict['error'])
477 return ret_dict 486 return ret_dict
478 487
479 def GetBookmarkModel(self): 488 def GetBookmarkModel(self):
480 """Return the bookmark model as a BookmarkModel object. 489 """Return the bookmark model as a BookmarkModel object.
481 490
482 This is a snapshot of the bookmark model; it is not a proxy and 491 This is a snapshot of the bookmark model; it is not a proxy and
483 does not get updated as the bookmark model changes. 492 does not get updated as the bookmark model changes.
484 """ 493 """
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
748 what type is expected for a particular preference path. 757 what type is expected for a particular preference path.
749 """ 758 """
750 cmd_dict = { 759 cmd_dict = {
751 'command': 'SetPrefs', 760 'command': 'SetPrefs',
752 'path': path, 761 'path': path,
753 'value': value, 762 'value': value,
754 } 763 }
755 self._GetResultFromJSONRequest(cmd_dict) 764 self._GetResultFromJSONRequest(cmd_dict)
756 765
757 def WaitForAllDownloadsToComplete(self, windex=0): 766 def WaitForAllDownloadsToComplete(self, windex=0):
767 self.WaitForAllDownloads(
768 self, windex=0, timeout=self.action_max_timeout_ms())
769
770 def WaitForAllDownloadsToComplete(self, windex=0, timeout=-1):
758 """Wait for all downloads to complete. 771 """Wait for all downloads to complete.
759 772
760 Note: This method does not work for dangerous downloads. Use 773 Note: This method does not work for dangerous downloads. Use
761 WaitForGivenDownloadsToComplete (below) instead. 774 WaitForGivenDownloadsToComplete (below) instead.
762 """ 775 """
776 if timeout == -1: # Default
777 timeout = self.action_max_timeout_ms()
763 cmd_dict = {'command': 'WaitForAllDownloadsToComplete'} 778 cmd_dict = {'command': 'WaitForAllDownloadsToComplete'}
764 self._GetResultFromJSONRequest(cmd_dict, windex=windex) 779 self._GetResultFromJSONRequest(cmd_dict, windex=windex, timeout=timeout)
765 780
766 def WaitForDownloadToComplete(self, download_path, timeout=-1): 781 def WaitForDownloadToComplete(self, download_path, timeout=-1):
767 """Wait for the given downloads to complete. 782 """Wait for the given downloads to complete.
768 783
769 This method works for dangerous downloads as well as regular downloads. 784 This method works for dangerous downloads as well as regular downloads.
770 785
771 Args: 786 Args:
772 download_path: The path to the final download. This is only necessary for 787 download_path: The path to the final download. This is only necessary for
773 the workaround described in the comments below and should 788 the workaround described in the comments below and should
774 be removed when downloads are re-implemented. 789 be removed when downloads are re-implemented.
(...skipping 2009 matching lines...) Expand 10 before | Expand all | Expand 10 after
2784 if self._options.verbose: 2799 if self._options.verbose:
2785 verbosity = 2 2800 verbosity = 2
2786 result = PyAutoTextTestRuner(verbosity=verbosity).run(pyauto_suite) 2801 result = PyAutoTextTestRuner(verbosity=verbosity).run(pyauto_suite)
2787 del loaded_tests # Need to destroy test cases before the suite 2802 del loaded_tests # Need to destroy test cases before the suite
2788 del pyauto_suite 2803 del pyauto_suite
2789 sys.exit(not result.wasSuccessful()) 2804 sys.exit(not result.wasSuccessful())
2790 2805
2791 2806
2792 if __name__ == '__main__': 2807 if __name__ == '__main__':
2793 Main() 2808 Main()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698