summaryrefslogtreecommitdiffstats
path: root/chrome/test
diff options
context:
space:
mode:
authorvandebo@chromium.org <vandebo@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-11 22:41:43 +0000
committervandebo@chromium.org <vandebo@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-11 22:41:43 +0000
commitf6ff0dfd962666d79e4919e23c0078283fed2922 (patch)
tree88a7462b11dc1463ef7cc728ccabaf7012cb188d /chrome/test
parentb3839a6adf2c4ec9572852577b2c270b9266820a (diff)
downloadchromium_src-f6ff0dfd962666d79e4919e23c0078283fed2922.zip
chromium_src-f6ff0dfd962666d79e4919e23c0078283fed2922.tar.gz
chromium_src-f6ff0dfd962666d79e4919e23c0078283fed2922.tar.bz2
Revert 52054: causing startup tests to fail on Vista and XP perf dbg
Revert 52054 - Refactor json automation interface for pyauto hooks. Reduces the number of lines you need to add per new automation hook. Shaves off several lines of code. Refactor pyauto.py to obviate raising exception in case the json interfaces produces an error string. Review URL: http://codereview.chromium.org/2898001 TBR=nirnimesh@chromium.org Review URL: http://codereview.chromium.org/2977001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@52067 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/test')
-rw-r--r--chrome/test/pyautolib/pyauto.py90
1 files changed, 49 insertions, 41 deletions
diff --git a/chrome/test/pyautolib/pyauto.py b/chrome/test/pyautolib/pyauto.py
index 5a82c5f..4b94b3d 100644
--- a/chrome/test/pyautolib/pyauto.py
+++ b/chrome/test/pyautolib/pyauto.py
@@ -260,33 +260,6 @@ class PyUITest(pyautolib.PyUITestBase, unittest.TestCase):
time.sleep(retry_sleep)
return False
- def _GetResultFromJSONRequest(self, cmd_dict, windex=0):
- """Issue call over the JSON automation channel and fetch output.
-
- This method packages the given dictionary into a json string, sends it
- over the JSON automation channel, loads the json output string returned,
- and returns it back as a dictionary.
-
- Args:
- cmd_dict: the command dictionary. It must have a 'command' key
- Sample:
- {
- 'command': 'SetOmniboxText',
- 'text': text,
- }
- windex: 0-based window index on which to work. Default: 0 (first window)
-
- Returns:
- a dictionary for the output returned by the automation channel.
-
- Raises:
- pyauto_errors.JSONInterfaceError if the automation call returns an error.
- """
- ret_dict = json.loads(self._SendJSONRequest(windex, json.dumps(cmd_dict)))
- if ret_dict.has_key('error'):
- raise JSONInterfaceError(ret_dict['error'])
- return ret_dict
-
def GetBookmarkModel(self):
"""Return the bookmark model as a BookmarkModel object.
@@ -375,7 +348,9 @@ class PyUITest(pyautolib.PyUITestBase, unittest.TestCase):
'command': 'OmniboxMovePopupSelection',
'count': count,
}
- self._GetResultFromJSONRequest(cmd_dict, windex=windex)
+ ret_dict = json.loads(self._SendJSONRequest(windex, json.dumps(cmd_dict)))
+ if ret_dict.has_key('error'):
+ raise JSONInterfaceError(ret_dict['error'])
def OmniboxAcceptInput(self, windex=0):
"""Accepts the current string of text in the omnibox.
@@ -390,7 +365,9 @@ class PyUITest(pyautolib.PyUITestBase, unittest.TestCase):
cmd_dict = {
'command': 'OmniboxAcceptInput',
}
- self._GetResultFromJSONRequest(cmd_dict, windex=windex)
+ ret_dict = json.loads(self._SendJSONRequest(windex, json.dumps(cmd_dict)))
+ if ret_dict.has_key('error'):
+ raise JSONInterfaceError(ret_dict['error'])
def GetPrefsInfo(self):
"""Return info about preferences.
@@ -432,13 +409,16 @@ class PyUITest(pyautolib.PyUITestBase, unittest.TestCase):
'path': path,
'value': value,
}
- self._GetResultFromJSONRequest(cmd_dict)
+ ret_dict = json.loads(self._SendJSONRequest(0, json.dumps(cmd_dict)))
+ if ret_dict.has_key('error'):
+ raise JSONInterfaceError(ret_dict['error'])
def WaitForAllDownloadsToComplete(self):
"""Wait for all downloads to complete."""
# Implementation detail: uses the generic "JSON command" model
# (experimental)
- self._GetResultFromJSONRequest({'command': 'WaitForAllDownloadsToComplete'})
+ self._SendJSONRequest(0, json.dumps({'command':
+ 'WaitForAllDownloadsToComplete'}))
def DownloadAndWaitForStart(self, file_url):
"""Trigger download for the given url and wait for downloads to start.
@@ -481,7 +461,10 @@ class PyUITest(pyautolib.PyUITestBase, unittest.TestCase):
cmd_dict['width'] = width
if height:
cmd_dict['height'] = height
- self._GetResultFromJSONRequest(cmd_dict, windex=windex)
+ ret_dict = json.loads(self._SendJSONRequest(0, json.dumps(cmd_dict)))
+ if ret_dict.has_key('error'):
+ raise JSONInterfaceError(ret_dict['error'])
+ return ret_dict
def GetBrowserInfo(self):
"""Return info about the browser.
@@ -541,7 +524,10 @@ class PyUITest(pyautolib.PyUITestBase, unittest.TestCase):
cmd_dict = { # Prepare command for the json interface
'command': 'GetBrowserInfo',
}
- return self._GetResultFromJSONRequest(cmd_dict)
+ ret_dict = json.loads(self._SendJSONRequest(0, json.dumps(cmd_dict)))
+ if ret_dict.has_key('error'):
+ raise JSONInterfaceError(ret_dict['error'])
+ return ret_dict
def GetHistoryInfo(self, search_text=''):
"""Return info about browsing history.
@@ -640,7 +626,10 @@ class PyUITest(pyautolib.PyUITestBase, unittest.TestCase):
for credit_card in credit_cards:
if not 'label' in credit_card:
raise JSONInterfaceError('must specify label for all credit cards')
- self._GetResultFromJSONRequest(cmd_dict)
+ ret_dict = json.loads(self._SendJSONRequest(window_index,
+ json.dumps(cmd_dict)))
+ if ret_dict.has_key('error'):
+ raise JSONInterfaceError(ret_dict['error'])
def GetAutoFillProfile(self, tab_index=0, window_index=0):
"""Return the profile including all profiles and credit cards currently
@@ -662,7 +651,11 @@ class PyUITest(pyautolib.PyUITestBase, unittest.TestCase):
'command': 'GetAutoFillProfile',
'tab_index': tab_index
}
- return self._GetResultFromJSONRequest(cmd_dict)
+ ret_dict = json.loads(self._SendJSONRequest(window_index,
+ json.dumps(cmd_dict)))
+ if ret_dict.has_key('error'):
+ raise JSONInterfaceError(ret_dict['error'])
+ return ret_dict
def AddHistoryItem(self, item):
"""Forge a history item for Chrome.
@@ -686,7 +679,9 @@ class PyUITest(pyautolib.PyUITestBase, unittest.TestCase):
}
if not 'url' in item:
raise JSONInterfaceError('must specify url')
- self._GetResultFromJSONRequest(cmd_dict)
+ ret_dict = json.loads(self._SendJSONRequest(0, json.dumps(cmd_dict)))
+ if ret_dict.has_key('error'):
+ raise JSONInterfaceError(ret_dict['error'])
def GetPluginsInfo(self):
"""Return info about plugins.
@@ -711,7 +706,9 @@ class PyUITest(pyautolib.PyUITestBase, unittest.TestCase):
'command': 'EnablePlugin',
'path': path,
}
- self._GetResultFromJSONRequest(cmd_dict)
+ ret_dict = json.loads(self._SendJSONRequest(0, json.dumps(cmd_dict)))
+ if ret_dict.has_key('error'):
+ raise JSONInterfaceError(ret_dict['error'])
def DisablePlugin(self, path):
"""Disable the plugin at the given path.
@@ -725,7 +722,9 @@ class PyUITest(pyautolib.PyUITestBase, unittest.TestCase):
'command': 'DisablePlugin',
'path': path,
}
- self._GetResultFromJSONRequest(cmd_dict)
+ ret_dict = json.loads(self._SendJSONRequest(0, json.dumps(cmd_dict)))
+ if ret_dict.has_key('error'):
+ raise JSONInterfaceError(ret_dict['error'])
def GetTabContents(self, tab_index=0, window_index=0):
"""Get the html contents of a tab (a la "view source").
@@ -746,7 +745,10 @@ class PyUITest(pyautolib.PyUITestBase, unittest.TestCase):
'tab_index': tab_index,
'filename': filename
}
- ret_dict = self._GetResultFromJSONRequest(cmd_dict, windex=window_index)
+ ret_dict = json.loads(self._SendJSONRequest(window_index,
+ json.dumps(cmd_dict)))
+ if ret_dict.has_key('error'):
+ raise JSONInterfaceError(ret_dict['error'])
try:
f = open(filename)
all_data = f.read()
@@ -781,7 +783,10 @@ class PyUITest(pyautolib.PyUITestBase, unittest.TestCase):
cmd_dict = {
'command': 'ClearTheme',
}
- self._GetResultFromJSONRequest(cmd_dict)
+ ret_dict = json.loads(self._SendJSONRequest(0, json.dumps(cmd_dict)))
+ if ret_dict.has_key('error'):
+ raise JSONInterfaceError(ret_dict['error'])
+ return ret_dict
def GetThemeInfo(self):
"""Get info about theme.
@@ -809,7 +814,10 @@ class PyUITest(pyautolib.PyUITestBase, unittest.TestCase):
cmd_dict = {
'command': 'GetThemeInfo',
}
- return self._GetResultFromJSONRequest(cmd_dict)
+ ret_dict = json.loads(self._SendJSONRequest(0, json.dumps(cmd_dict)))
+ if ret_dict.has_key('error'):
+ raise JSONInterfaceError(ret_dict['error'])
+ return ret_dict
class PyUITestSuite(pyautolib.PyUITestSuiteBase, unittest.TestSuite):