[pyauto] Fix ActionTimeoutChanger

Add a test for it.

BUG=139926
TEST=testActionTimeoutChanger

Review URL: https://chromiumcodereview.appspot.com/10828335

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@151806 0039d316-1c4b-4281-b951-d872f2087c98
parent 9702e844
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
# Use of this source code is governed by a BSD-style license that can be # Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file. # found in the LICENSE file.
import time
import unittest import unittest
import pyauto_functional # Must be imported before pyauto import pyauto_functional # Must be imported before pyauto
...@@ -50,6 +51,21 @@ class PyAutoTest(pyauto.PyUITest): ...@@ -50,6 +51,21 @@ class PyAutoTest(pyauto.PyUITest):
pyauto_errors.JSONInterfaceError, pyauto_errors.JSONInterfaceError,
lambda: self.GetNextEvent(timeout=2000)) # event queue is empty lambda: self.GetNextEvent(timeout=2000)) # event queue is empty
def testActionTimeoutChanger(self):
"""Verify that ActionTimeoutChanger works."""
new_timeout = 1000 # 1 sec
changer = pyauto.PyUITest.ActionTimeoutChanger(self, new_timeout)
self.assertEqual(self.action_timeout_ms(), new_timeout)
# Verify the amount of time taken for automation timeout
then = time.time()
self.assertRaises(
pyauto_errors.JSONInterfaceError,
lambda: self.ExecuteJavascript('invalid js should timeout'))
elapsed = time.time() - then
self.assertTrue(elapsed < new_timeout / 1000.0 + 2, # margin of 2 secs
msg='ActionTimeoutChanger did not work. '
'Automation timeout took %f secs' % elapsed)
if __name__ == '__main__': if __name__ == '__main__':
......
...@@ -1059,7 +1059,7 @@ class PyUITest(pyautolib.PyUITestBase, unittest.TestCase): ...@@ -1059,7 +1059,7 @@ class PyUITest(pyautolib.PyUITestBase, unittest.TestCase):
pyauto_errors.JSONInterfaceError if the automation call returns an error. pyauto_errors.JSONInterfaceError if the automation call returns an error.
""" """
if timeout == -1: # Default if timeout == -1: # Default
timeout = self.action_max_timeout_ms() timeout = self.action_timeout_ms()
if windex is None: # Do not target any window if windex is None: # Do not target any window
windex = -1 windex = -1
result = self._SendJSONRequest(windex, json.dumps(cmd_dict), timeout) result = self._SendJSONRequest(windex, json.dumps(cmd_dict), timeout)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment