summaryrefslogtreecommitdiffstats
path: root/chrome/browser/translate
diff options
context:
space:
mode:
authorjeremy@chromium.org <jeremy@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-15 12:16:30 +0000
committerjeremy@chromium.org <jeremy@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-15 12:16:30 +0000
commit6a6ce8b3a868dd1f94f8731ebd05abd39da46fec (patch)
tree1d13b28d170d29bd1ef503ba167eae1500afb705 /chrome/browser/translate
parent4757aecb7691429748791c315b17b7f402869197 (diff)
downloadchromium_src-6a6ce8b3a868dd1f94f8731ebd05abd39da46fec.zip
chromium_src-6a6ce8b3a868dd1f94f8731ebd05abd39da46fec.tar.gz
chromium_src-6a6ce8b3a868dd1f94f8731ebd05abd39da46fec.tar.bz2
Reland translate toolbar unit tests (originally landed as r41274, rolled back at r41284).
BUG=None TEST=New unit tests, tree should stay green after this checkin. Revert "Reland translate toolbar unit tests (originally landed as r41274, rolled back at r41284)." Revert r41569 - 10.6 unit tests not passing. Review URL: http://codereview.chromium.org/962001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@41579 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/translate')
-rw-r--r--chrome/browser/translate/languages_menu_model.cc2
-rw-r--r--chrome/browser/translate/options_menu_model.cc4
-rw-r--r--chrome/browser/translate/translate_infobars_delegates.cc32
-rw-r--r--chrome/browser/translate/translate_infobars_delegates.h32
4 files changed, 41 insertions, 29 deletions
diff --git a/chrome/browser/translate/languages_menu_model.cc b/chrome/browser/translate/languages_menu_model.cc
index ba749df..5231ce0 100644
--- a/chrome/browser/translate/languages_menu_model.cc
+++ b/chrome/browser/translate/languages_menu_model.cc
@@ -24,7 +24,7 @@ LanguagesMenuModel::LanguagesMenuModel(
}
std::vector<std::string>::const_iterator iter = languages.begin();
for (int i = base_command_id; iter != languages.end(); ++i, ++iter) {
- AddItem(i, TranslateInfoBarDelegate::GetDisplayNameForLocale(*iter));
+ AddItem(i, translate_delegate->GetDisplayNameForLocale(*iter));
}
}
diff --git a/chrome/browser/translate/options_menu_model.cc b/chrome/browser/translate/options_menu_model.cc
index 376e2cb..4364e07 100644
--- a/chrome/browser/translate/options_menu_model.cc
+++ b/chrome/browser/translate/options_menu_model.cc
@@ -13,7 +13,7 @@ OptionsMenuModel::OptionsMenuModel(menus::SimpleMenuModel::Delegate* delegate,
TranslateInfoBarDelegate* translate_delegate)
: menus::SimpleMenuModel(delegate) {
string16 original_language =
- TranslateInfoBarDelegate::GetDisplayNameForLocale(
+ translate_delegate->GetDisplayNameForLocale(
translate_delegate->original_lang_code());
TranslateInfoBarDelegate::TranslateState state = translate_delegate->state();
if (state == TranslateInfoBarDelegate::kBeforeTranslate) {
@@ -26,7 +26,7 @@ OptionsMenuModel::OptionsMenuModel(menus::SimpleMenuModel::Delegate* delegate,
IDS_TRANSLATE_INFOBAR_OPTIONS_NEVER_TRANSLATE_SITE));
} else if (state == TranslateInfoBarDelegate::kAfterTranslate) {
string16 target_language =
- TranslateInfoBarDelegate::GetDisplayNameForLocale(
+ translate_delegate->GetDisplayNameForLocale(
translate_delegate->target_lang_code());
AddCheckItem(IDC_TRANSLATE_OPTIONS_ALWAYS,
l10n_util::GetStringFUTF16(IDS_TRANSLATE_INFOBAR_OPTIONS_ALWAYS,
diff --git a/chrome/browser/translate/translate_infobars_delegates.cc b/chrome/browser/translate/translate_infobars_delegates.cc
index 948e337..062eba8 100644
--- a/chrome/browser/translate/translate_infobars_delegates.cc
+++ b/chrome/browser/translate/translate_infobars_delegates.cc
@@ -41,6 +41,12 @@ void TranslateInfoBarDelegate::InfoBarClosed() {
// TranslateInfoBarDelegate: public: -------------------------------------------
+string16 TranslateInfoBarDelegate::GetDisplayNameForLocale(
+ const std::string& language_code) {
+ return l10n_util::GetDisplayNameForLocale(
+ language_code, g_browser_process->GetApplicationLocale(), true);
+}
+
void TranslateInfoBarDelegate::UpdateState(TranslateState new_state) {
if (state_ != new_state)
state_ = new_state;
@@ -84,7 +90,7 @@ void TranslateInfoBarDelegate::TranslationDeclined() {
bool TranslateInfoBarDelegate::IsLanguageBlacklisted() {
if (state_ == kBeforeTranslate) {
never_translate_language_ =
- prefs_.IsLanguageBlacklisted(original_lang_code());
+ prefs_->IsLanguageBlacklisted(original_lang_code());
return never_translate_language_;
}
NOTREACHED() << "Invalid mehod called for translate state";
@@ -93,7 +99,7 @@ bool TranslateInfoBarDelegate::IsLanguageBlacklisted() {
bool TranslateInfoBarDelegate::IsSiteBlacklisted() {
if (state_ == kBeforeTranslate) {
- never_translate_site_ = prefs_.IsSiteBlacklisted(site_);
+ never_translate_site_ = prefs_->IsSiteBlacklisted(site_);
return never_translate_site_;
}
NOTREACHED() << "Invalid mehod called for translate state";
@@ -102,7 +108,7 @@ bool TranslateInfoBarDelegate::IsSiteBlacklisted() {
bool TranslateInfoBarDelegate::ShouldAlwaysTranslate() {
if (state_ == kAfterTranslate) {
- always_translate_ = prefs_.IsLanguagePairWhitelisted(original_lang_code(),
+ always_translate_ = prefs_->IsLanguagePairWhitelisted(original_lang_code(),
target_lang_code());
return always_translate_;
}
@@ -114,9 +120,9 @@ void TranslateInfoBarDelegate::ToggleLanguageBlacklist() {
if (state_ == kBeforeTranslate) {
never_translate_language_ = !never_translate_language_;
if (never_translate_language_)
- prefs_.BlacklistLanguage(original_lang_code());
+ prefs_->BlacklistLanguage(original_lang_code());
else
- prefs_.RemoveLanguageFromBlacklist(original_lang_code());
+ prefs_->RemoveLanguageFromBlacklist(original_lang_code());
} else {
NOTREACHED() << "Invalid method called for translate state";
}
@@ -126,9 +132,9 @@ void TranslateInfoBarDelegate::ToggleSiteBlacklist() {
if (state_ == kBeforeTranslate) {
never_translate_site_ = !never_translate_site_;
if (never_translate_site_)
- prefs_.BlacklistSite(site_);
+ prefs_->BlacklistSite(site_);
else
- prefs_.RemoveSiteFromBlacklist(site_);
+ prefs_->RemoveSiteFromBlacklist(site_);
} else {
NOTREACHED() << "Invalid mehod called for translate state";
}
@@ -138,9 +144,9 @@ void TranslateInfoBarDelegate::ToggleAlwaysTranslate() {
if (state_ == kAfterTranslate) {
always_translate_ = !always_translate_;
if (always_translate_)
- prefs_.WhitelistLanguagePair(original_lang_code(), target_lang_code());
+ prefs_->WhitelistLanguagePair(original_lang_code(), target_lang_code());
else
- prefs_.RemoveLanguagePairFromWhitelist(original_lang_code(),
+ prefs_->RemoveLanguagePairFromWhitelist(original_lang_code(),
target_lang_code());
} else {
NOTREACHED() << "Invalid mehod called for translate state";
@@ -209,12 +215,6 @@ TranslateInfoBarDelegate* TranslateInfoBarDelegate::Create(
original_lang_index, target_lang_index);
}
-string16 TranslateInfoBarDelegate::GetDisplayNameForLocale(
- const std::string& language_code) {
- return l10n_util::GetDisplayNameForLocale(
- language_code, g_browser_process->GetApplicationLocale(), true);
-}
-
// TranslateInfoBarDelegate: private: ------------------------------------------
TranslateInfoBarDelegate::TranslateInfoBarDelegate(TabContents* tab_contents,
@@ -222,7 +222,7 @@ TranslateInfoBarDelegate::TranslateInfoBarDelegate(TabContents* tab_contents,
int original_lang_index, int target_lang_index)
: InfoBarDelegate(tab_contents),
tab_contents_(tab_contents),
- prefs_(user_prefs),
+ prefs_(new TranslatePrefs(user_prefs)),
state_(state),
site_(url.HostNoBrackets()),
original_lang_index_(original_lang_index),
diff --git a/chrome/browser/translate/translate_infobars_delegates.h b/chrome/browser/translate/translate_infobars_delegates.h
index ce8cede..74753a8 100644
--- a/chrome/browser/translate/translate_infobars_delegates.h
+++ b/chrome/browser/translate/translate_infobars_delegates.h
@@ -35,14 +35,14 @@ class TranslateInfoBarDelegate : public InfoBarDelegate {
void GetAvailableTargetLanguages(std::vector<std::string>* languages);
void ModifyOriginalLanguage(int lang_index);
void ModifyTargetLanguage(int lang_index);
- void Translate();
- void TranslationDeclined();
- bool IsLanguageBlacklisted();
- void ToggleLanguageBlacklist();
- bool IsSiteBlacklisted();
- void ToggleSiteBlacklist();
- bool ShouldAlwaysTranslate();
- void ToggleAlwaysTranslate();
+ virtual void Translate();
+ virtual void TranslationDeclined();
+ virtual bool IsLanguageBlacklisted();
+ virtual void ToggleLanguageBlacklist();
+ virtual bool IsSiteBlacklisted();
+ virtual void ToggleSiteBlacklist();
+ virtual bool ShouldAlwaysTranslate();
+ virtual void ToggleAlwaysTranslate();
int original_lang_index() const {
return original_lang_index_;
@@ -94,11 +94,23 @@ class TranslateInfoBarDelegate : public InfoBarDelegate {
virtual void InfoBarClosed();
// Returns the printable version of the language code |language_code|.
- static string16 GetDisplayNameForLocale(const std::string& language_code);
+ virtual string16 GetDisplayNameForLocale(const std::string& language_code);
// Overridden from InfoBarDelegate:
virtual InfoBar* CreateInfoBar();
+ protected:
+ // For testing.
+ TranslateInfoBarDelegate() :
+ InfoBarDelegate(NULL),
+ tab_contents_(NULL),
+ state_(kBeforeTranslate),
+ original_lang_index_(0),
+ target_lang_index_(0),
+ never_translate_language_(false),
+ never_translate_site_(false),
+ always_translate_(false) {}
+
private:
TranslateInfoBarDelegate(TabContents* contents,
PrefService* user_prefs,
@@ -108,7 +120,7 @@ class TranslateInfoBarDelegate : public InfoBarDelegate {
int target_language_index);
TabContents* tab_contents_; // Weak.
- TranslatePrefs prefs_;
+ scoped_ptr<TranslatePrefs> prefs_;
TranslateState state_;
std::string site_;
int original_lang_index_;