Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1658)

Unified Diff: chrome/browser/ui/views/translate/translate_bubble_view_unittest.cc

Issue 98643003: Translate new UX: Fix the visual and behavior of 'Done' button (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: sky's review Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/ui/views/translate/translate_bubble_view.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/views/translate/translate_bubble_view_unittest.cc
diff --git a/chrome/browser/ui/views/translate/translate_bubble_view_unittest.cc b/chrome/browser/ui/views/translate/translate_bubble_view_unittest.cc
index 0b84c1bc4c10d5ab10ea88d7ace74fa5ba0d66a8..14a5e14d2217bcd66eadd422cd25fbadcb7ee06e 100644
--- a/chrome/browser/ui/views/translate/translate_bubble_view_unittest.cc
+++ b/chrome/browser/ui/views/translate/translate_bubble_view_unittest.cc
@@ -27,7 +27,9 @@ class MockTranslateBubbleModel : public TranslateBubbleModel {
set_always_translate_called_count_(0),
translate_called_(false),
revert_translation_called_(false),
- translation_declined_called_(false) {
+ translation_declined_called_(false),
+ original_language_index_on_translation_(-1),
+ target_language_index_on_translation_(-1) {
}
virtual TranslateBubbleModel::ViewState GetViewState() const OVERRIDE {
@@ -86,6 +88,8 @@ class MockTranslateBubbleModel : public TranslateBubbleModel {
virtual void Translate() OVERRIDE {
translate_called_ = true;
+ original_language_index_on_translation_ = original_language_index_;
+ target_language_index_on_translation_ = target_language_index_;
}
virtual void RevertTranslation() OVERRIDE {
@@ -96,6 +100,12 @@ class MockTranslateBubbleModel : public TranslateBubbleModel {
translation_declined_called_ = true;
}
+ virtual bool IsPageTranslatedInCurrentLanguages() const OVERRIDE {
+ return original_language_index_on_translation_ ==
+ original_language_index_ &&
+ target_language_index_on_translation_ == target_language_index_;
+ }
+
TranslateBubbleViewStateTransition view_state_transition_;
int original_language_index_;
int target_language_index_;
@@ -106,6 +116,8 @@ class MockTranslateBubbleModel : public TranslateBubbleModel {
bool translate_called_;
bool revert_translation_called_;
bool translation_declined_called_;
+ int original_language_index_on_translation_;
+ int target_language_index_on_translation_;
};
} // namespace
@@ -231,7 +243,6 @@ TEST_F(TranslateBubbleViewTest, AlwaysTranslateCheckboxAndDoneButton) {
EXPECT_EQ(1, mock_model_->set_always_translate_called_count_);
}
-
TEST_F(TranslateBubbleViewTest, DoneButton) {
bubble_->SwitchView(TranslateBubbleModel::VIEW_STATE_ADVANCED);
@@ -250,6 +261,33 @@ TEST_F(TranslateBubbleViewTest, DoneButton) {
EXPECT_EQ(20, mock_model_->target_language_index_);
}
+TEST_F(TranslateBubbleViewTest, DoneButtonWithoutTranslating) {
+ EXPECT_EQ(TranslateBubbleModel::VIEW_STATE_BEFORE_TRANSLATE,
+ bubble_->GetViewState());
+
+ // Translate the page once.
+ mock_model_->Translate();
+ EXPECT_TRUE(mock_model_->translate_called_);
+
+ // Go back to the initial view.
+ EXPECT_EQ(TranslateBubbleModel::VIEW_STATE_BEFORE_TRANSLATE,
+ bubble_->GetViewState());
+ mock_model_->translate_called_ = false;
+
+ EXPECT_EQ(TranslateBubbleModel::VIEW_STATE_BEFORE_TRANSLATE,
+ bubble_->GetViewState());
+ bubble_->SwitchView(TranslateBubbleModel::VIEW_STATE_ADVANCED);
+
+ // Click the "Done" button with the current language pair. This time,
+ // translation is not performed and the view state will be back to the
+ // previous view.
+ bubble_->HandleButtonPressed(TranslateBubbleView::BUTTON_ID_DONE);
+ EXPECT_FALSE(mock_model_->translate_called_);
+
+ EXPECT_EQ(TranslateBubbleModel::VIEW_STATE_BEFORE_TRANSLATE,
+ bubble_->GetViewState());
+}
+
TEST_F(TranslateBubbleViewTest, CancelButtonReturningBeforeTranslate) {
bubble_->SwitchView(TranslateBubbleModel::VIEW_STATE_BEFORE_TRANSLATE);
bubble_->SwitchView(TranslateBubbleModel::VIEW_STATE_ADVANCED);
« no previous file with comments | « chrome/browser/ui/views/translate/translate_bubble_view.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698