summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/cocoa/translate/translate_infobar_base.mm8
-rw-r--r--chrome/browser/cocoa/translate/translate_infobar_unittest.mm18
-rw-r--r--chrome/browser/cocoa/translate/translate_message_infobar_controller.mm6
-rw-r--r--chrome/browser/gtk/translate/translate_infobar_base_gtk.cc14
-rw-r--r--chrome/browser/translate/translate_infobar_delegate.cc36
-rw-r--r--chrome/browser/translate/translate_infobar_delegate.h14
-rw-r--r--chrome/browser/translate/translate_manager.cc15
-rw-r--r--chrome/browser/translate/translate_manager.h11
-rw-r--r--chrome/browser/translate/translate_manager_unittest.cc73
-rw-r--r--chrome/browser/views/infobars/translate_infobar_base.cc14
10 files changed, 137 insertions, 72 deletions
diff --git a/chrome/browser/cocoa/translate/translate_infobar_base.mm b/chrome/browser/cocoa/translate/translate_infobar_base.mm
index 108ce74..fb7dd5a 100644
--- a/chrome/browser/cocoa/translate/translate_infobar_base.mm
+++ b/chrome/browser/cocoa/translate/translate_infobar_base.mm
@@ -471,7 +471,7 @@ InfoBar* TranslateInfoBarDelegate::CreateInfoBar() {
[self rebuildOptionsMenu:NO];
[[optionsPopUp_ cell] setArrowPosition:NSPopUpArrowAtBottom];
[optionsPopUp_ sizeToFit];
-
+
MoveControl(closeButton_, optionsPopUp_, spaceBetweenControls_, false);
if (!VerifyControlOrderAndSpacing(lastView, optionsPopUp_)) {
[self rebuildOptionsMenu:YES];
@@ -490,8 +490,8 @@ InfoBar* TranslateInfoBarDelegate::CreateInfoBar() {
- (IBAction)ok:(id)sender {
TranslateInfoBarDelegate* delegate = [self delegate];
TranslateInfoBarDelegate::Type state = delegate->type();
- DCHECK(state == TranslateInfoBarDelegate::kBeforeTranslate ||
- state == TranslateInfoBarDelegate::kTranslationError);
+ DCHECK(state == TranslateInfoBarDelegate::BEFORE_TRANSLATE ||
+ state == TranslateInfoBarDelegate::TRANSLATION_ERROR);
delegate->Translate();
UMA_HISTOGRAM_COUNTS("Translate.Translate", 1);
}
@@ -499,7 +499,7 @@ InfoBar* TranslateInfoBarDelegate::CreateInfoBar() {
// Called when someone clicks on the "Nope" button.
- (IBAction)cancel:(id)sender {
DCHECK(
- [self delegate]->type() == TranslateInfoBarDelegate::kBeforeTranslate);
+ [self delegate]->type() == TranslateInfoBarDelegate::BEFORE_TRANSLATE);
[self delegate]->TranslationDeclined();
UMA_HISTOGRAM_COUNTS("Translate.DeclineTranslate", 1);
[super dismiss:nil];
diff --git a/chrome/browser/cocoa/translate/translate_infobar_unittest.mm b/chrome/browser/cocoa/translate/translate_infobar_unittest.mm
index 8e3d257..668d8bf 100644
--- a/chrome/browser/cocoa/translate/translate_infobar_unittest.mm
+++ b/chrome/browser/cocoa/translate/translate_infobar_unittest.mm
@@ -23,10 +23,10 @@ namespace {
// All states the translate toolbar can assume.
TranslateInfoBarDelegate::Type kTranslateToolbarStates[] = {
- TranslateInfoBarDelegate::kBeforeTranslate,
- TranslateInfoBarDelegate::kAfterTranslate,
- TranslateInfoBarDelegate::kTranslating,
- TranslateInfoBarDelegate::kTranslationError
+ TranslateInfoBarDelegate::BEFORE_TRANSLATE,
+ TranslateInfoBarDelegate::AFTER_TRANSLATE,
+ TranslateInfoBarDelegate::TRANSLATING,
+ TranslateInfoBarDelegate::TRANSLATION_ERROR
};
class MockTranslateInfoBarDelegate : public TranslateInfoBarDelegate {
@@ -79,7 +79,7 @@ class TranslationInfoBarTest : public CocoaTest {
}
void CreateInfoBar() {
- CreateInfoBar(TranslateInfoBarDelegate::kBeforeTranslate);
+ CreateInfoBar(TranslateInfoBarDelegate::BEFORE_TRANSLATE);
}
void CreateInfoBar(TranslateInfoBarDelegate::Type type) {
@@ -91,7 +91,7 @@ class TranslationInfoBarTest : public CocoaTest {
MSG_ROUTING_NONE,
NULL));
TranslateErrors::Type error = TranslateErrors::NONE;
- if (type == TranslateInfoBarDelegate::kTranslationError)
+ if (type == TranslateInfoBarDelegate::TRANSLATION_ERROR)
error = TranslateErrors::NETWORK;
infobar_delegate.reset(
new MockTranslateInfoBarDelegate(type, error, tab_contents.get()));
@@ -125,7 +125,7 @@ TEST_F(TranslationInfoBarTest, TranslateCalledOnButtonPress) {
// Check that clicking the "Retry" button calls Translate() when we're
// in the error mode - http://crbug.com/41315 .
TEST_F(TranslationInfoBarTest, TranslateCalledInErrorMode) {
- CreateInfoBar(TranslateInfoBarDelegate::kTranslationError);
+ CreateInfoBar(TranslateInfoBarDelegate::TRANSLATION_ERROR);
EXPECT_CALL(*infobar_delegate, Translate()).Times(1);
@@ -227,7 +227,7 @@ TEST_F(TranslationInfoBarTest, TriggerShowAlwaysTranslateButton) {
for (int i = 0; i < 4; ++i) {
translate_prefs.IncrementTranslationAcceptedCount("en");
}
- CreateInfoBar(TranslateInfoBarDelegate::kBeforeTranslate);
+ CreateInfoBar(TranslateInfoBarDelegate::BEFORE_TRANSLATE);
BeforeTranslateInfobarController* controller =
(BeforeTranslateInfobarController*)infobar_controller.get();
EXPECT_TRUE([[controller alwaysTranslateButton] superview] != nil);
@@ -242,7 +242,7 @@ TEST_F(TranslationInfoBarTest, TriggerShowNeverTranslateButton) {
for (int i = 0; i < 4; ++i) {
translate_prefs.IncrementTranslationDeniedCount("en");
}
- CreateInfoBar(TranslateInfoBarDelegate::kBeforeTranslate);
+ CreateInfoBar(TranslateInfoBarDelegate::BEFORE_TRANSLATE);
BeforeTranslateInfobarController* controller =
(BeforeTranslateInfobarController*)infobar_controller.get();
EXPECT_TRUE([[controller alwaysTranslateButton] superview] == nil);
diff --git a/chrome/browser/cocoa/translate/translate_message_infobar_controller.mm b/chrome/browser/cocoa/translate/translate_message_infobar_controller.mm
index db2f46f..5b4fcaf 100644
--- a/chrome/browser/cocoa/translate/translate_message_infobar_controller.mm
+++ b/chrome/browser/cocoa/translate/translate_message_infobar_controller.mm
@@ -14,9 +14,9 @@ using TranslateInfoBarUtilities::MoveControl;
if ((self = [super initWithDelegate:delegate])) {
TranslateInfoBarDelegate* delegate = [self delegate];
if (delegate->IsError())
- state_ = TranslateInfoBarDelegate::kTranslationError;
+ state_ = TranslateInfoBarDelegate::TRANSLATION_ERROR;
else
- state_ = TranslateInfoBarDelegate::kTranslating;
+ state_ = TranslateInfoBarDelegate::TRANSLATING;
}
return self;
}
@@ -37,7 +37,7 @@ using TranslateInfoBarUtilities::MoveControl;
- (NSArray*)visibleControls {
NSMutableArray* visibleControls =
[NSMutableArray arrayWithObjects:label1_.get(), nil];
- if (state_ == TranslateInfoBarDelegate::kTranslationError)
+ if (state_ == TranslateInfoBarDelegate::TRANSLATION_ERROR)
[visibleControls addObject:tryAgainButton_];
return visibleControls;
}
diff --git a/chrome/browser/gtk/translate/translate_infobar_base_gtk.cc b/chrome/browser/gtk/translate/translate_infobar_base_gtk.cc
index c0998d6..bb55831 100644
--- a/chrome/browser/gtk/translate/translate_infobar_base_gtk.cc
+++ b/chrome/browser/gtk/translate/translate_infobar_base_gtk.cc
@@ -36,14 +36,14 @@ TranslateInfoBarBase::TranslateInfoBarBase(TranslateInfoBarDelegate* delegate)
: InfoBar(delegate) {
TranslateInfoBarDelegate::BackgroundAnimationType animation =
delegate->background_animation_type();
- if (animation != TranslateInfoBarDelegate::kNone) {
+ if (animation != TranslateInfoBarDelegate::NONE) {
background_color_animation_.reset(new SlideAnimation(this));
background_color_animation_->SetTweenType(Tween::LINEAR);
background_color_animation_->SetSlideDuration(500);
- if (animation == TranslateInfoBarDelegate::kNormalToError) {
+ if (animation == TranslateInfoBarDelegate::NORMAL_TO_ERROR) {
background_color_animation_->Show();
} else {
- DCHECK_EQ(TranslateInfoBarDelegate::kErrorToNormal, animation);
+ DCHECK_EQ(TranslateInfoBarDelegate::ERROR_TO_NORMAL, animation);
// Hide() runs the animation in reverse.
background_color_animation_->Reset(1.0);
background_color_animation_->Hide();
@@ -218,14 +218,14 @@ void TranslateInfoBarBase::OnOptionsClicked(GtkWidget* sender) {
InfoBar* TranslateInfoBarDelegate::CreateInfoBar() {
TranslateInfoBarBase* infobar = NULL;
switch (type_) {
- case kBeforeTranslate:
+ case BEFORE_TRANSLATE:
infobar = new BeforeTranslateInfoBar(this);
break;
- case kAfterTranslate:
+ case AFTER_TRANSLATE:
infobar = new AfterTranslateInfoBar(this);
break;
- case kTranslating:
- case kTranslationError:
+ case TRANSLATING:
+ case TRANSLATION_ERROR:
infobar = new TranslateMessageInfoBar(this);
break;
default:
diff --git a/chrome/browser/translate/translate_infobar_delegate.cc b/chrome/browser/translate/translate_infobar_delegate.cc
index 2233991..e1a801b 100644
--- a/chrome/browser/translate/translate_infobar_delegate.cc
+++ b/chrome/browser/translate/translate_infobar_delegate.cc
@@ -23,7 +23,7 @@ TranslateInfoBarDelegate* TranslateInfoBarDelegate::CreateDelegate(
TabContents* tab_contents,
const std::string& original_language,
const std::string& target_language) {
- DCHECK(type != kTranslationError);
+ DCHECK(type != TRANSLATION_ERROR);
if (!TranslateManager::IsSupportedLanguage(original_language) ||
!TranslateManager::IsSupportedLanguage(target_language)) {
return NULL;
@@ -42,7 +42,7 @@ TranslateInfoBarDelegate* TranslateInfoBarDelegate::CreateErrorDelegate(
TabContents* tab_contents,
const std::string& original_language,
const std::string& target_language) {
- return new TranslateInfoBarDelegate(kTranslationError, error, tab_contents,
+ return new TranslateInfoBarDelegate(TRANSLATION_ERROR, error, tab_contents,
original_language, target_language);
}
@@ -54,7 +54,7 @@ TranslateInfoBarDelegate::TranslateInfoBarDelegate(
const std::string& target_language)
: InfoBarDelegate(tab_contents),
type_(type),
- background_animation_(kNone),
+ background_animation_(NONE),
tab_contents_(tab_contents),
original_language_index_(-1),
initial_original_language_index_(-1),
@@ -62,8 +62,8 @@ TranslateInfoBarDelegate::TranslateInfoBarDelegate(
error_(error),
infobar_view_(NULL),
prefs_(tab_contents_->profile()->GetPrefs()) {
- DCHECK((type_ != kTranslationError && error == TranslateErrors::NONE) ||
- (type_ == kTranslationError && error != TranslateErrors::NONE));
+ DCHECK((type_ != TRANSLATION_ERROR && error == TranslateErrors::NONE) ||
+ (type_ == TRANSLATION_ERROR && error != TranslateErrors::NONE));
std::vector<std::string> language_codes;
TranslateManager::GetSupportedLanguages(&language_codes);
@@ -123,7 +123,7 @@ void TranslateInfoBarDelegate::SetOriginalLanguage(int language_index) {
original_language_index_ = language_index;
if (infobar_view_)
infobar_view_->OriginalLanguageChanged();
- if (type_ == kAfterTranslate)
+ if (type_ == AFTER_TRANSLATE)
Translate();
}
@@ -132,12 +132,12 @@ void TranslateInfoBarDelegate::SetTargetLanguage(int language_index) {
target_language_index_ = language_index;
if (infobar_view_)
infobar_view_->TargetLanguageChanged();
- if (type_ == kAfterTranslate)
+ if (type_ == AFTER_TRANSLATE)
Translate();
}
bool TranslateInfoBarDelegate::IsError() {
- return type_ == kTranslationError;
+ return type_ == TRANSLATION_ERROR;
}
void TranslateInfoBarDelegate::Translate() {
@@ -175,7 +175,7 @@ void TranslateInfoBarDelegate::TranslationDeclined() {
}
void TranslateInfoBarDelegate::InfoBarDismissed() {
- if (type_ != kBeforeTranslate)
+ if (type_ != BEFORE_TRANSLATE)
return;
// The user closed the infobar without clicking the translate button.
@@ -259,11 +259,11 @@ void TranslateInfoBarDelegate::NeverTranslatePageLanguage() {
string16 TranslateInfoBarDelegate::GetMessageInfoBarText() {
switch (type_) {
- case kTranslating:
+ case TRANSLATING:
return l10n_util::GetStringFUTF16(
IDS_TRANSLATE_INFOBAR_TRANSLATING_TO,
GetLanguageDisplayableNameAt(target_language_index_));
- case kTranslationError:
+ case TRANSLATION_ERROR:
switch (error_) {
case TranslateErrors::NETWORK:
return l10n_util::GetStringUTF16(
@@ -295,9 +295,9 @@ string16 TranslateInfoBarDelegate::GetMessageInfoBarText() {
string16 TranslateInfoBarDelegate::GetMessageInfoBarButtonText() {
switch (type_) {
- case kTranslating:
+ case TRANSLATING:
return string16();
- case kTranslationError:
+ case TRANSLATION_ERROR:
if (error_ == TranslateErrors::IDENTICAL_LANGUAGES ||
error_ == TranslateErrors::UNKNOWN_LANGUAGE) {
// No retry button, we would fail again with the same error.
@@ -313,7 +313,7 @@ string16 TranslateInfoBarDelegate::GetMessageInfoBarButtonText() {
}
void TranslateInfoBarDelegate::MessageInfoBarButtonPressed() {
- DCHECK(type_ == kTranslationError);
+ DCHECK(type_ == TRANSLATION_ERROR);
if (error_ == TranslateErrors::UNSUPPORTED_LANGUAGE) {
RevertTranslation();
return;
@@ -324,22 +324,22 @@ void TranslateInfoBarDelegate::MessageInfoBarButtonPressed() {
}
bool TranslateInfoBarDelegate::ShouldShowNeverTranslateButton() {
- DCHECK(type_ == kBeforeTranslate);
+ DCHECK(type_ == BEFORE_TRANSLATE);
return prefs_.GetTranslationDeniedCount(GetOriginalLanguageCode()) >= 3;
}
bool TranslateInfoBarDelegate::ShouldShowAlwaysTranslateButton() {
- DCHECK(type_ == kBeforeTranslate);
+ DCHECK(type_ == BEFORE_TRANSLATE);
return prefs_.GetTranslationAcceptedCount(GetOriginalLanguageCode()) >= 3;
}
void TranslateInfoBarDelegate::UpdateBackgroundAnimation(
TranslateInfoBarDelegate* previous_infobar) {
if (!previous_infobar || previous_infobar->IsError() == IsError()) {
- background_animation_ = kNone;
+ background_animation_ = NONE;
return;
}
- background_animation_ = IsError() ? kNormalToError: kErrorToNormal;
+ background_animation_ = IsError() ? NORMAL_TO_ERROR: ERROR_TO_NORMAL;
}
std::string TranslateInfoBarDelegate::GetPageHost() {
diff --git a/chrome/browser/translate/translate_infobar_delegate.h b/chrome/browser/translate/translate_infobar_delegate.h
index c82cde7..4b1b1e9 100644
--- a/chrome/browser/translate/translate_infobar_delegate.h
+++ b/chrome/browser/translate/translate_infobar_delegate.h
@@ -19,17 +19,17 @@ class TranslateInfoBarDelegate : public InfoBarDelegate {
public:
// The different types of infobars that can be shown for translation.
enum Type {
- kBeforeTranslate,
- kTranslating,
- kAfterTranslate,
- kTranslationError
+ BEFORE_TRANSLATE,
+ TRANSLATING,
+ AFTER_TRANSLATE,
+ TRANSLATION_ERROR
};
// The types of background color animations.
enum BackgroundAnimationType {
- kNone,
- kNormalToError,
- kErrorToNormal
+ NONE,
+ NORMAL_TO_ERROR,
+ ERROR_TO_NORMAL
};
// Factory method to create a non-error translate infobar.
diff --git a/chrome/browser/translate/translate_manager.cc b/chrome/browser/translate/translate_manager.cc
index 8a8e645..48b3079 100644
--- a/chrome/browser/translate/translate_manager.cc
+++ b/chrome/browser/translate/translate_manager.cc
@@ -129,6 +129,8 @@ const char* const kTranslateScriptHeader =
const char* const kReportLanguageDetectionErrorURL =
"http://translate.google.com/translate_error";
+const int kTranslateScriptExpirationDelayMS = 24 * 60 * 60 * 1000; // 1 day.
+
} // namespace
// static
@@ -268,6 +270,12 @@ void TranslateManager::OnURLFetchComplete(const URLFetcher* source,
DCHECK(translate_script_.empty());
str.CopyToString(&translate_script_);
translate_script_ += "\n" + data;
+ // We'll expire the cached script after some time, to make sure long running
+ // browsers still get fixes that might get pushed with newer scripts.
+ MessageLoop::current()->PostDelayedTask(FROM_HERE,
+ method_factory_.NewRunnableMethod(
+ &TranslateManager::ClearTranslateScript),
+ translate_script_expiration_delay_);
}
// Process any pending requests.
@@ -307,6 +315,7 @@ bool TranslateManager::IsShowingTranslateInfobar(TabContents* tab) {
TranslateManager::TranslateManager()
: ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)),
+ translate_script_expiration_delay_(kTranslateScriptExpirationDelayMS),
translate_script_request_pending_(false) {
notification_registrar_.Add(this, NotificationType::NAV_ENTRY_COMMITTED,
NotificationService::AllSources());
@@ -371,7 +380,7 @@ void TranslateManager::InitiateTranslation(TabContents* tab,
// Prompts the user if he/she wants the page translated.
tab->AddInfoBar(TranslateInfoBarDelegate::CreateDelegate(
- TranslateInfoBarDelegate::kBeforeTranslate, tab,
+ TranslateInfoBarDelegate::BEFORE_TRANSLATE, tab,
page_lang, target_lang));
}
@@ -400,7 +409,7 @@ void TranslateManager::TranslatePage(TabContents* tab_contents,
// showing (that is the case when the translation was triggered by the
// "always translate" for example).
infobar = TranslateInfoBarDelegate::CreateDelegate(
- TranslateInfoBarDelegate::kTranslating, tab_contents,
+ TranslateInfoBarDelegate::TRANSLATING, tab_contents,
source_lang, target_lang);
ShowInfoBar(tab_contents, infobar);
}
@@ -489,7 +498,7 @@ void TranslateManager::PageTranslated(TabContents* tab,
details->source_language, details->target_language);
} else {
infobar = TranslateInfoBarDelegate::CreateDelegate(
- TranslateInfoBarDelegate::kAfterTranslate, tab,
+ TranslateInfoBarDelegate::AFTER_TRANSLATE, tab,
details->source_language, details->target_language);
}
ShowInfoBar(tab, infobar);
diff --git a/chrome/browser/translate/translate_manager.h b/chrome/browser/translate/translate_manager.h
index 260f345..54debf4 100644
--- a/chrome/browser/translate/translate_manager.h
+++ b/chrome/browser/translate/translate_manager.h
@@ -51,7 +51,6 @@ class TranslateManager : public NotificationObserver,
void ReportLanguageDetectionError(TabContents* tab_contents);
// Clears the translate script, so it will be fetched next time we translate.
- // Currently used by unit-tests.
void ClearTranslateScript() { translate_script_.clear(); }
// NotificationObserver implementation:
@@ -67,6 +66,12 @@ class TranslateManager : public NotificationObserver,
const ResponseCookies& cookies,
const std::string& data);
+ // Used by unit-tests to override the default delay after which the translate
+ // script is fetched again from the translation server.
+ void set_translate_script_expiration_delay(int delay_ms) {
+ translate_script_expiration_delay_ = delay_ms;
+ }
+
// Convenience method to know if a tab is showing a translate infobar.
static bool IsShowingTranslateInfobar(TabContents* tab);
@@ -158,6 +163,10 @@ class TranslateManager : public NotificationObserver,
// The JS injected in the page to do the translation.
std::string translate_script_;
+ // Delay in milli-seconds after which the translate script is fetched again
+ // from the translate server.
+ int translate_script_expiration_delay_;
+
// Whether the translate JS is currently being retrieved.
bool translate_script_request_pending_;
diff --git a/chrome/browser/translate/translate_manager_unittest.cc b/chrome/browser/translate/translate_manager_unittest.cc
index 41d8c3d..1b1598d 100644
--- a/chrome/browser/translate/translate_manager_unittest.cc
+++ b/chrome/browser/translate/translate_manager_unittest.cc
@@ -113,6 +113,11 @@ class TranslateManagerTest : public RenderViewHostTestHarness,
removed_infobars_.clear();
}
+ void ExpireTranslateScriptImmediately() {
+ Singleton<TranslateManager>::get()->
+ set_translate_script_expiration_delay(0);
+ }
+
// If there is 1 infobar and it is a translate infobar, deny translation and
// returns true. Returns false otherwise.
bool DenyTranslation() {
@@ -140,8 +145,12 @@ class TranslateManagerTest : public RenderViewHostTestHarness,
// the TranslateManager is created before the TabContents. This matters as
// they both register for similar events and we want the notifications to
// happen in the same sequence (TranslateManager first, TabContents second).
- // Also clears the translate script so it is fetched everytime.
+ // Also clears the translate script so it is fetched everytime and sets the
+ // expiration delay to a large value by default (in case it was zeroed in
+ // a previous test).
Singleton<TranslateManager>::get()->ClearTranslateScript();
+ Singleton<TranslateManager>::get()->
+ set_translate_script_expiration_delay(60 * 60 * 1000);
RenderViewHostTestHarness::SetUp();
@@ -272,7 +281,7 @@ TEST_F(TranslateManagerTest, NormalTranslate) {
// We should have an infobar.
TranslateInfoBarDelegate* infobar = GetTranslateInfoBar();
ASSERT_TRUE(infobar != NULL);
- EXPECT_EQ(TranslateInfoBarDelegate::kBeforeTranslate, infobar->type());
+ EXPECT_EQ(TranslateInfoBarDelegate::BEFORE_TRANSLATE, infobar->type());
// Simulate clicking translate.
process()->sink().ClearMessages();
@@ -281,7 +290,7 @@ TEST_F(TranslateManagerTest, NormalTranslate) {
// The "Translating..." infobar should be showing.
infobar = GetTranslateInfoBar();
ASSERT_TRUE(infobar != NULL);
- EXPECT_EQ(TranslateInfoBarDelegate::kTranslating, infobar->type());
+ EXPECT_EQ(TranslateInfoBarDelegate::TRANSLATING, infobar->type());
// Simulate the translate script being retrieved (it only needs to be done
// once in the test as it is cached).
@@ -302,7 +311,7 @@ TEST_F(TranslateManagerTest, NormalTranslate) {
// The after translate infobar should be showing.
infobar = GetTranslateInfoBar();
ASSERT_TRUE(infobar != NULL);
- EXPECT_EQ(TranslateInfoBarDelegate::kAfterTranslate, infobar->type());
+ EXPECT_EQ(TranslateInfoBarDelegate::AFTER_TRANSLATE, infobar->type());
// Simulate changing the original language, this should trigger a translation.
process()->sink().ClearMessages();
@@ -343,7 +352,7 @@ TEST_F(TranslateManagerTest, TranslateScriptNotAvailable) {
// We should have an infobar.
TranslateInfoBarDelegate* infobar = GetTranslateInfoBar();
ASSERT_TRUE(infobar != NULL);
- EXPECT_EQ(TranslateInfoBarDelegate::kBeforeTranslate, infobar->type());
+ EXPECT_EQ(TranslateInfoBarDelegate::BEFORE_TRANSLATE, infobar->type());
// Simulate clicking translate.
process()->sink().ClearMessages();
@@ -357,7 +366,7 @@ TEST_F(TranslateManagerTest, TranslateScriptNotAvailable) {
// And we should have an error infobar showing.
infobar = GetTranslateInfoBar();
ASSERT_TRUE(infobar != NULL);
- EXPECT_EQ(TranslateInfoBarDelegate::kTranslationError, infobar->type());
+ EXPECT_EQ(TranslateInfoBarDelegate::TRANSLATION_ERROR, infobar->type());
}
// Ensures we deal correctly with pages for which the browser does not recognize
@@ -375,7 +384,7 @@ TEST_F(TranslateManagerTest, TranslateUnknownLanguage) {
TestRenderViewContextMenu::CreateContextMenu(contents()));
menu->Init();
menu->ExecuteCommand(IDC_CONTENT_CONTEXT_TRANSLATE);
- SimulateURLFetch(true); // Simulare receiving the translate script.
+ SimulateURLFetch(true); // Simulate receiving the translate script.
// Simulate the render notifying the translation has been done, the server
// having detected the page was in a known and supported language.
@@ -385,7 +394,7 @@ TEST_F(TranslateManagerTest, TranslateUnknownLanguage) {
// The after translate infobar should be showing.
TranslateInfoBarDelegate* infobar = GetTranslateInfoBar();
ASSERT_TRUE(infobar != NULL);
- EXPECT_EQ(TranslateInfoBarDelegate::kAfterTranslate, infobar->type());
+ EXPECT_EQ(TranslateInfoBarDelegate::AFTER_TRANSLATE, infobar->type());
EXPECT_EQ("fr", infobar->GetOriginalLanguageCode());
EXPECT_EQ("en", infobar->GetTargetLanguageCode());
@@ -400,7 +409,7 @@ TEST_F(TranslateManagerTest, TranslateUnknownLanguage) {
TranslateErrors::IDENTICAL_LANGUAGES));
infobar = GetTranslateInfoBar();
ASSERT_TRUE(infobar != NULL);
- EXPECT_EQ(TranslateInfoBarDelegate::kTranslationError, infobar->type());
+ EXPECT_EQ(TranslateInfoBarDelegate::TRANSLATION_ERROR, infobar->type());
EXPECT_EQ(TranslateErrors::IDENTICAL_LANGUAGES, infobar->error());
// Let's run the same steps again but this time the server fails to detect the
@@ -414,7 +423,7 @@ TEST_F(TranslateManagerTest, TranslateUnknownLanguage) {
TranslateErrors::UNKNOWN_LANGUAGE));
infobar = GetTranslateInfoBar();
ASSERT_TRUE(infobar != NULL);
- EXPECT_EQ(TranslateInfoBarDelegate::kTranslationError, infobar->type());
+ EXPECT_EQ(TranslateInfoBarDelegate::TRANSLATION_ERROR, infobar->type());
EXPECT_EQ(TranslateErrors::UNKNOWN_LANGUAGE, infobar->error());
}
@@ -734,7 +743,7 @@ TEST_F(TranslateManagerTest, ServerReportsUnsupportedLanguage) {
// language.
infobar = GetTranslateInfoBar();
ASSERT_TRUE(infobar != NULL);
- EXPECT_EQ(TranslateInfoBarDelegate::kTranslationError, infobar->type());
+ EXPECT_EQ(TranslateInfoBarDelegate::TRANSLATION_ERROR, infobar->type());
// This infobar should have a button (so the string should not be empty).
ASSERT_FALSE(infobar->GetMessageInfoBarButtonText().empty());
@@ -1056,7 +1065,7 @@ TEST_F(TranslateManagerTest, BeforeTranslateExtraButtons) {
true);
infobar = GetTranslateInfoBar();
ASSERT_TRUE(infobar != NULL);
- EXPECT_EQ(TranslateInfoBarDelegate::kBeforeTranslate, infobar->type());
+ EXPECT_EQ(TranslateInfoBarDelegate::BEFORE_TRANSLATE, infobar->type());
if (i < 3) {
EXPECT_FALSE(infobar->ShouldShowAlwaysTranslateButton());
infobar->Translate();
@@ -1084,7 +1093,7 @@ TEST_F(TranslateManagerTest, BeforeTranslateExtraButtons) {
true);
infobar = GetTranslateInfoBar();
ASSERT_TRUE(infobar != NULL);
- EXPECT_EQ(TranslateInfoBarDelegate::kBeforeTranslate, infobar->type());
+ EXPECT_EQ(TranslateInfoBarDelegate::BEFORE_TRANSLATE, infobar->type());
if (i < 3) {
EXPECT_FALSE(infobar->ShouldShowNeverTranslateButton());
infobar->TranslationDeclined();
@@ -1119,3 +1128,41 @@ TEST_F(TranslateManagerTest, NonTranslatablePage) {
EXPECT_FALSE(menu->IsCommandIdEnabled(IDC_CONTENT_CONTEXT_TRANSLATE));
}
+// Tests that the script is expired and refetched as expected.
+TEST_F(TranslateManagerTest, ScriptExpires) {
+ ExpireTranslateScriptImmediately();
+
+ // Simulate navigating to a page and translating it.
+ SimulateNavigation(GURL("http://www.google.fr"), 0, "Le Google", "fr", true);
+ TranslateInfoBarDelegate* infobar = GetTranslateInfoBar();
+ ASSERT_TRUE(infobar != NULL);
+ process()->sink().ClearMessages();
+ infobar->Translate();
+ SimulateURLFetch(true);
+ rvh()->TestOnMessageReceived(ViewHostMsg_PageTranslated(0, 0, "fr", "en",
+ TranslateErrors::NONE));
+
+ // A task should have been posted to clear the script, run it.
+ MessageLoop::current()->RunAllPending();
+
+ // Do another navigation and translation.
+ SimulateNavigation(GURL("http://www.google.es"), 1, "El Google", "es", true);
+ infobar = GetTranslateInfoBar();
+ ASSERT_TRUE(infobar != NULL);
+ process()->sink().ClearMessages();
+ infobar->Translate();
+ // If we don't simulate the URL fetch, the TranslateManager should be waiting
+ // for the script and no message should have been sent to the renderer.
+ EXPECT_TRUE(
+ process()->sink().GetFirstMessageMatching(ViewMsg_TranslatePage::ID) ==
+ NULL);
+ // Now simulate the URL fetch.
+ SimulateURLFetch(true);
+ // Now the message should have been sent.
+ int page_id = 0;
+ std::string original_lang, target_lang;
+ EXPECT_TRUE(GetTranslateMessage(&page_id, &original_lang, &target_lang));
+ EXPECT_EQ(1, page_id);
+ EXPECT_EQ("es", original_lang);
+ EXPECT_EQ("en", target_lang);
+}
diff --git a/chrome/browser/views/infobars/translate_infobar_base.cc b/chrome/browser/views/infobars/translate_infobar_base.cc
index 1527c0b..50c7120 100644
--- a/chrome/browser/views/infobars/translate_infobar_base.cc
+++ b/chrome/browser/views/infobars/translate_infobar_base.cc
@@ -30,14 +30,14 @@ TranslateInfoBarBase::TranslateInfoBarBase(
TranslateInfoBarDelegate::BackgroundAnimationType animation =
delegate->background_animation_type();
- if (animation != TranslateInfoBarDelegate::kNone) {
+ if (animation != TranslateInfoBarDelegate::NONE) {
background_color_animation_.reset(new SlideAnimation(this));
background_color_animation_->SetTweenType(Tween::LINEAR);
background_color_animation_->SetSlideDuration(500);
- if (animation == TranslateInfoBarDelegate::kNormalToError) {
+ if (animation == TranslateInfoBarDelegate::NORMAL_TO_ERROR) {
background_color_animation_->Show();
} else {
- DCHECK_EQ(TranslateInfoBarDelegate::kErrorToNormal, animation);
+ DCHECK_EQ(TranslateInfoBarDelegate::ERROR_TO_NORMAL, animation);
// Hide() runs the animation in reverse.
background_color_animation_->Reset(1.0);
background_color_animation_->Hide();
@@ -158,14 +158,14 @@ void TranslateInfoBarBase::FadeBackground(gfx::Canvas* canvas,
InfoBar* TranslateInfoBarDelegate::CreateInfoBar() {
TranslateInfoBarBase* infobar = NULL;
switch (type_) {
- case kBeforeTranslate:
+ case BEFORE_TRANSLATE:
infobar = new BeforeTranslateInfoBar(this);
break;
- case kAfterTranslate:
+ case AFTER_TRANSLATE:
infobar = new AfterTranslateInfoBar(this);
break;
- case kTranslating:
- case kTranslationError:
+ case TRANSLATING:
+ case TRANSLATION_ERROR:
infobar = new TranslateMessageInfoBar(this);
break;
default: