diff options
author | alyssad@chromium.org <alyssad@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-04 23:50:15 +0000 |
---|---|---|
committer | alyssad@chromium.org <alyssad@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-04 23:50:15 +0000 |
commit | da1913e62dbe0350e97abf73722a4394f22934f8 (patch) | |
tree | 9c30c71548b17d0edb602cc9cb01702ffa8d2b42 | |
parent | 1741b97470b7d6af031ef9ebe37241faf2be3a91 (diff) | |
download | chromium_src-da1913e62dbe0350e97abf73722a4394f22934f8.zip chromium_src-da1913e62dbe0350e97abf73722a4394f22934f8.tar.gz chromium_src-da1913e62dbe0350e97abf73722a4394f22934f8.tar.bz2 |
New translate pyauto hook: select translate target language
This hook allows tests to select a different "to" language from the drop-down.
Review URL: http://codereview.chromium.org/3078026
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@55000 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/automation/automation_provider.cc | 34 | ||||
-rw-r--r-- | chrome/test/pyautolib/pyauto.py | 29 |
2 files changed, 63 insertions, 0 deletions
diff --git a/chrome/browser/automation/automation_provider.cc b/chrome/browser/automation/automation_provider.cc index 8f3e136..e59c07a 100644 --- a/chrome/browser/automation/automation_provider.cc +++ b/chrome/browser/automation/automation_provider.cc @@ -2830,6 +2830,40 @@ void AutomationProvider::SelectTranslateOption(Browser* browser, new PageTranslatedObserver(this, reply_message, tab_contents); translate_bar->Translate(); return; + } else if (option == "set_target_language") { + string16 target_language; + if (!args->GetString("target_language", &target_language)) { + AutomationJSONReply(this, reply_message). + SendError("Must include target_language string."); + return; + } + // Get the target language index based off of the language name. + int target_language_index = -1; + for (int i = 0; i < translate_bar->GetLanguageCount(); i++) { + if (translate_bar->GetLanguageDisplayableNameAt(i) == target_language) { + target_language_index = i; + break; + } + } + if (target_language_index == -1) { + AutomationJSONReply(this, reply_message) + .SendError("Invalid target language string."); + return; + } + // If the page has already been translated it will be translated again to + // the new language. The observer will wait until the page has been + // translated to reply. + if (translate_bar->type() == TranslateInfoBarDelegate::AFTER_TRANSLATE) { + new PageTranslatedObserver(this, reply_message, tab_contents); + translate_bar->SetTargetLanguage(target_language_index); + return; + } + // Otherwise just send the reply back immediately. + translate_bar->SetTargetLanguage(target_language_index); + scoped_ptr<DictionaryValue> return_value(new DictionaryValue); + return_value->SetBoolean("translation_success", true); + AutomationJSONReply(this, reply_message).SendSuccess(return_value.get()); + return; } AutomationJSONReply reply(this, reply_message); diff --git a/chrome/test/pyautolib/pyauto.py b/chrome/test/pyautolib/pyauto.py index 3c3f979..89b3c28 100644 --- a/chrome/test/pyautolib/pyauto.py +++ b/chrome/test/pyautolib/pyauto.py @@ -720,6 +720,35 @@ class PyUITest(pyautolib.PyUITestBase, unittest.TestCase): } self._GetResultFromJSONRequest(cmd_dict, windex=window_index) + def ChangeTranslateToLanguage(self, new_language, tab_index=0, + window_index=0): + """Set the target language to be a new language. + + This is equivalent to selecting a different language from the 'to' + drop-down menu on the translate bar. If the page was already translated + before calling this function, this will trigger a re-translate to the + new language. + + Args: + new_language: The new target language. The string should be equivalent + to the text seen in the translate bar options. + Example: 'English'. + tab_index: The tab index - default is 0. + window_index: The window index - default is 0. + + Returns: + False, if a new translation was triggered and the translation failed. + True on success. + """ + cmd_dict = { # Prepare command for the json interface + 'command': 'SelectTranslateOption', + 'tab_index': tab_index, + 'option': 'set_target_language', + 'target_language': new_language + } + return self._GetResultFromJSONRequest( + cmd_dict, windex=window_index)['translation_success'] + def GetExtensionsInfo(self): """Returns information about all installed extensions. |