summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authoralyssad@chromium.org <alyssad@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-08-10 18:11:16 +0000
committeralyssad@chromium.org <alyssad@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-08-10 18:11:16 +0000
commit4a47d7612c2f80b6dd760fdea9ba48d9e3704057 (patch)
treeb83a011fb93df886d75559f12f2b18e1381146a5 /chrome
parent2c9e5769de902aacf1585f8273bf55dc3583e614 (diff)
downloadchromium_src-4a47d7612c2f80b6dd760fdea9ba48d9e3704057.zip
chromium_src-4a47d7612c2f80b6dd760fdea9ba48d9e3704057.tar.gz
chromium_src-4a47d7612c2f80b6dd760fdea9ba48d9e3704057.tar.bz2
New pyauto translate hooks: always and never translate button.
This hooks allows testers to test that always and never translate button that shows up after a user has accepted/declined translation several times. Review URL: http://codereview.chromium.org/3061054 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@55590 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/automation/automation_provider.cc23
-rw-r--r--chrome/browser/automation/automation_provider_observers.cc4
-rw-r--r--chrome/test/functional/translate.py31
-rw-r--r--chrome/test/pyautolib/pyauto.py19
4 files changed, 72 insertions, 5 deletions
diff --git a/chrome/browser/automation/automation_provider.cc b/chrome/browser/automation/automation_provider.cc
index 4ab8bc6..fdca465 100644
--- a/chrome/browser/automation/automation_provider.cc
+++ b/chrome/browser/automation/automation_provider.cc
@@ -2865,6 +2865,17 @@ void AutomationProvider::SelectTranslateOption(Browser* browser,
return_value->SetBoolean("translation_success", true);
AutomationJSONReply(this, reply_message).SendSuccess(return_value.get());
return;
+ } else if (option == "click_always_translate_lang_button") {
+ if (!translate_bar->ShouldShowAlwaysTranslateButton()) {
+ AutomationJSONReply(this, reply_message)
+ .SendError("Always translate button not showing.");
+ return;
+ }
+ // Clicking 'Always Translate' triggers a translation. The observer will
+ // wait until the translation is complete before sending the reply.
+ new PageTranslatedObserver(this, reply_message, tab_contents);
+ translate_bar->AlwaysTranslatePageLanguage();
+ return;
}
AutomationJSONReply reply(this, reply_message);
@@ -2888,6 +2899,18 @@ void AutomationProvider::SelectTranslateOption(Browser* browser,
} else if (option == "revert_translation") {
translate_bar->RevertTranslation();
reply.SendSuccess(NULL);
+ } else if (option == "click_never_translate_lang_button") {
+ if (!translate_bar->ShouldShowNeverTranslateButton()) {
+ reply.SendError("Always translate button not showing.");
+ return;
+ }
+ translate_bar->NeverTranslatePageLanguage();
+ reply.SendSuccess(NULL);
+ } else if (option == "decline_translation") {
+ // This is the function called when an infobar is dismissed or when the
+ // user clicks the 'Nope' translate button.
+ translate_bar->TranslationDeclined();
+ reply.SendSuccess(NULL);
} else {
reply.SendError("Invalid string found for option.");
}
diff --git a/chrome/browser/automation/automation_provider_observers.cc b/chrome/browser/automation/automation_provider_observers.cc
index fa45172..4938867 100644
--- a/chrome/browser/automation/automation_provider_observers.cc
+++ b/chrome/browser/automation/automation_provider_observers.cc
@@ -995,6 +995,10 @@ void TabLanguageDeterminedObserver::Observe(
type_to_string[TranslateInfoBarDelegate::TRANSLATION_ERROR] =
"TRANSLATION_ERROR";
+ bar_info->SetBoolean("always_translate_lang_button_showing",
+ translate_bar_->ShouldShowAlwaysTranslateButton());
+ bar_info->SetBoolean("never_translate_lang_button_showing",
+ translate_bar_->ShouldShowNeverTranslateButton());
bar_info->SetString("bar_state", type_to_string[translate_bar_->type()]);
bar_info->SetString("target_lang_code",
translate_bar_->GetTargetLanguageCode());
diff --git a/chrome/test/functional/translate.py b/chrome/test/functional/translate.py
index b271a5b..eb8f0f3 100644
--- a/chrome/test/functional/translate.py
+++ b/chrome/test/functional/translate.py
@@ -82,7 +82,7 @@ class TranslateTest(pyauto.PyUITest):
def testNoTranslate(self):
"""Tests that a page isn't translated if the user declines translate."""
self._NavigateAndWaitForBar(self._GetDefaultSpanishURL())
- self.PerformActionOnInfobar('dismiss', 0)
+ self.SelectTranslateOption('decline_translation')
translate_info = self.GetTranslateInfo()
self.assertEqual(self.spanish, translate_info['original_language'])
self.assertFalse(translate_info['page_translated'])
@@ -329,6 +329,35 @@ class TranslateTest(pyauto.PyUITest):
self.NavigateToURL(self._GetDefaultSpanishURL())
self.assertFalse('translate_bar' in self.GetTranslateInfo())
+ def testAlwaysTranslateLanguageButton(self):
+ """Test the always translate language button."""
+ spanish_url = self._GetDefaultSpanishURL()
+ self._NavigateAndWaitForBar(spanish_url)
+
+ # The 'Always Translate' button doesn't show up until the user has clicked
+ # 'Translate' for a language several times.
+ max_tries = 10
+ curr_try = 0
+ while (curr_try < max_tries and
+ not self.GetTranslateInfo()['translate_bar']\
+ ['always_translate_lang_button_showing']):
+ self._ClickTranslateUntilSuccess()
+ self._NavigateAndWaitForBar(spanish_url)
+ curr_try = curr_try + 1
+ if curr_try == max_tries:
+ self.fail('Clicked translate %d times and always translate button never '\
+ 'showed up.' % max_tries)
+
+ # Click the 'Always Translate' button.
+ self.SelectTranslateOption('click_always_translate_lang_button')
+ # Navigate to another Spanish page and verify it was translated.
+ self._NavigateAndWaitForBar('http://www.google.com/webhp?hl=es')
+ self.WaitUntilTranslateComplete()
+ # Assert that a translation was attempted. We don't care if it was error
+ # or success.
+ self.assertNotEqual(self.before_translate,
+ self.GetTranslateInfo()['translate_bar']['bar_state'])
+
def testSeveralLanguages(self):
"""Verify translation for several languages.
diff --git a/chrome/test/pyautolib/pyauto.py b/chrome/test/pyautolib/pyauto.py
index 7e0e766..577d117 100644
--- a/chrome/test/pyautolib/pyauto.py
+++ b/chrome/test/pyautolib/pyauto.py
@@ -691,7 +691,9 @@ class PyUITest(pyautolib.PyUITestBase, unittest.TestCase):
Returns:
A dictionary of information about translate for the page. Example:
- { u'can_translate_page': True,
+ { u'always_translate_lang_button_showing': False,
+ u'never_translate_lang_button_showing': False,
+ 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.
@@ -824,15 +826,24 @@ class PyUITest(pyautolib.PyUITestBase, unittest.TestCase):
window_index: The index of the window, default is 0.
*Notes*
- never translate language: Selecting this means that no sites in this
+ 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
+ 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
+ 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.
+ decline_translation: Equivalent to selecting 'Nope' on the translate bar.
+ click_never_translate_lang_button: This button appears when the user has
+ declined translation of this language several times. Selecting it causes
+ the language to never be translated. Look at GetTranslateInfo to
+ determine if the button is showing.
+ click_always_translate_lang_button: This button appears when the user has
+ accepted translation of this language several times. Selecting it causes
+ the language to always be translated. Look at GetTranslateInfo to
+ determine if the button is showing.
Raises:
pyauto_errors.JSONInterfaceError if the automation returns an error.