diff options
author | alyssad@chromium.org <alyssad@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-27 16:35:42 +0000 |
---|---|---|
committer | alyssad@chromium.org <alyssad@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-27 16:35:42 +0000 |
commit | 3dda5b0f1bb73a437ca6e6f2741580451030ac25 (patch) | |
tree | 4546385566b7b28211e416a4862fbe4699ea7b0d /chrome/test/pyautolib | |
parent | 0f86277de42193b543d0b33e4c82c750f0642141 (diff) | |
download | chromium_src-3dda5b0f1bb73a437ca6e6f2741580451030ac25.zip chromium_src-3dda5b0f1bb73a437ca6e6f2741580451030ac25.tar.gz chromium_src-3dda5b0f1bb73a437ca6e6f2741580451030ac25.tar.bz2 |
New pyauto hook for the translate feature.
Review URL: http://codereview.chromium.org/3026016
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@53791 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/test/pyautolib')
-rw-r--r-- | chrome/test/pyautolib/pyauto.py | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/chrome/test/pyautolib/pyauto.py b/chrome/test/pyautolib/pyauto.py index 28e39ed..4cd634f 100644 --- a/chrome/test/pyautolib/pyauto.py +++ b/chrome/test/pyautolib/pyauto.py @@ -646,6 +646,101 @@ class PyUITest(pyautolib.PyUITestBase, unittest.TestCase): return history_info.HistoryInfo( self._SendJSONRequest(0, json.dumps(cmd_dict))) + def GetTranslateInfo(self, tab_index=0, window_index=0): + """Returns info about translate for the given page. + + If the translate bar is showing, also returns information about the bar. + + Args: + tab_index: The tab index, default is 0. + window_index: The window index, default is 0. + + Returns: + A dictionary of information about translate for the page. Example: + { u'can_translate_page': True, + u'original_language': u'es', + u'page_translated': False, + # The below will only appear if the translate bar is showing. + u'translate_bar': { u'bar_state': u'BEFORE_TRANSLATE', + u'original_lang_code': u'es', + u'target_lang_code': u'en'}} + """ + cmd_dict = { # Prepare command for the json interface + 'command': 'GetTranslateInfo', + 'tab_index': tab_index + } + return self._GetResultFromJSONRequest(cmd_dict, windex=window_index) + + def ClickTranslateBarTranslate(self, tab_index=0, window_index=0): + """If the translate bar is showing, clicks the 'Translate' button on the + bar. This will show the 'this page has been translated...' infobar. + + Args: + tab_index: The index of the tab, default is 0. + window_index: The index of the window, default is 0. + + Returns: + True if the translation was successful or false if there was an error. + Note that an error shouldn't neccessarily mean a failed test - retry the + call on error. + + Raises: + pyauto_errors.JSONInterfaceError if the automation returns an error. + """ + cmd_dict = { # Prepare command for the json interface + 'command': 'SelectTranslateOption', + 'tab_index': tab_index, + 'option': 'translate_page' + } + return self._GetResultFromJSONRequest( + cmd_dict, windex=window_index)['translation_success'] + + def RevertPageTranslation(self, tab_index=0, window_index=0): + """Select the 'Show original' button on the 'this page has been + translated...' infobar. This will remove the infobar and revert the + page translation. + + Args: + tab_index: The index of the tab, default is 0. + window_index: The index of the window, default is 0. + """ + cmd_dict = { # Prepare command for the json interface + 'command': 'SelectTranslateOption', + 'tab_index': tab_index, + 'option': 'revert_translation' + } + self._GetResultFromJSONRequest(cmd_dict, windex=window_index) + + def SelectTranslateOption(self, option, tab_index=0, window_index=0): + """Selects one of the options in the drop-down menu for the translate bar. + + Args: + option: One of 'never_translate_language', 'never_translate_site', or + 'toggle_always_translate'. See notes on each below. + tab_index: The index of the tab, default is 0. + window_index: The index of the window, default is 0. + + *Notes* + never translate language: Selecting this means that no sites in this + language will be translated. This dismisses the infobar. + never translate site: Selecting this means that this site will never be + translated, regardless of the language. This dismisses the infobar. + toggle always translate: This does not dismiss the infobar or translate the + page. See ClickTranslateBarTranslate and PerformActioOnInfobar to do + those. If a language is selected to be always translated, then whenver + the user visits a page with that language, the infobar will show the + 'This page has been translated...' message. + + Raises: + pyauto_errors.JSONInterfaceError if the automation returns an error. + """ + cmd_dict = { # Prepare command for the json interface + 'command': 'SelectTranslateOption', + 'option': option, + 'tab_index': tab_index + } + self._GetResultFromJSONRequest(cmd_dict, windex=window_index) + def FillAutoFillProfile(self, profiles=None, credit_cards=None, tab_index=0, window_index=0): """Set the autofill profile to contain the given profiles and credit cards. |