summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
authoralyssad@chromium.org <alyssad@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-08-04 23:50:15 +0000
committeralyssad@chromium.org <alyssad@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-08-04 23:50:15 +0000
commitda1913e62dbe0350e97abf73722a4394f22934f8 (patch)
tree9c30c71548b17d0edb602cc9cb01702ffa8d2b42 /chrome/browser
parent1741b97470b7d6af031ef9ebe37241faf2be3a91 (diff)
downloadchromium_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
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/automation/automation_provider.cc34
1 files changed, 34 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);