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

Side by Side 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/views/translate/translate_bubble_view.h" 5 #include "chrome/browser/ui/views/translate/translate_bubble_view.h"
6 6
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "chrome/browser/ui/translate/translate_bubble_model.h" 8 #include "chrome/browser/ui/translate/translate_bubble_model.h"
9 #include "chrome/browser/ui/translate/translate_bubble_view_state_transition.h" 9 #include "chrome/browser/ui/translate/translate_bubble_view_state_transition.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
11 #include "ui/views/controls/button/checkbox.h" 11 #include "ui/views/controls/button/checkbox.h"
12 #include "ui/views/controls/combobox/combobox.h" 12 #include "ui/views/controls/combobox/combobox.h"
13 #include "ui/views/test/views_test_base.h" 13 #include "ui/views/test/views_test_base.h"
14 #include "ui/views/widget/widget.h" 14 #include "ui/views/widget/widget.h"
15 15
16 namespace { 16 namespace {
17 17
18 class MockTranslateBubbleModel : public TranslateBubbleModel { 18 class MockTranslateBubbleModel : public TranslateBubbleModel {
19 public: 19 public:
20 explicit MockTranslateBubbleModel(TranslateBubbleModel::ViewState view_state) 20 explicit MockTranslateBubbleModel(TranslateBubbleModel::ViewState view_state)
21 : view_state_transition_(view_state), 21 : view_state_transition_(view_state),
22 original_language_index_(0), 22 original_language_index_(0),
23 target_language_index_(1), 23 target_language_index_(1),
24 never_translate_language_(false), 24 never_translate_language_(false),
25 never_translate_site_(false), 25 never_translate_site_(false),
26 should_always_translate_(false), 26 should_always_translate_(false),
27 set_always_translate_called_count_(0), 27 set_always_translate_called_count_(0),
28 translate_called_(false), 28 translate_called_(false),
29 revert_translation_called_(false), 29 revert_translation_called_(false),
30 translation_declined_called_(false) { 30 translation_declined_called_(false),
31 original_language_index_on_translation_(-1),
32 target_language_index_on_translation_(-1) {
31 } 33 }
32 34
33 virtual TranslateBubbleModel::ViewState GetViewState() const OVERRIDE { 35 virtual TranslateBubbleModel::ViewState GetViewState() const OVERRIDE {
34 return view_state_transition_.view_state(); 36 return view_state_transition_.view_state();
35 } 37 }
36 38
37 virtual void SetViewState(TranslateBubbleModel::ViewState view_state) 39 virtual void SetViewState(TranslateBubbleModel::ViewState view_state)
38 OVERRIDE { 40 OVERRIDE {
39 view_state_transition_.SetViewState(view_state); 41 view_state_transition_.SetViewState(view_state);
40 } 42 }
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 return should_always_translate_; 81 return should_always_translate_;
80 } 82 }
81 83
82 virtual void SetAlwaysTranslate(bool value) OVERRIDE { 84 virtual void SetAlwaysTranslate(bool value) OVERRIDE {
83 should_always_translate_ = value; 85 should_always_translate_ = value;
84 set_always_translate_called_count_++; 86 set_always_translate_called_count_++;
85 } 87 }
86 88
87 virtual void Translate() OVERRIDE { 89 virtual void Translate() OVERRIDE {
88 translate_called_ = true; 90 translate_called_ = true;
91 original_language_index_on_translation_ = original_language_index_;
92 target_language_index_on_translation_ = target_language_index_;
89 } 93 }
90 94
91 virtual void RevertTranslation() OVERRIDE { 95 virtual void RevertTranslation() OVERRIDE {
92 revert_translation_called_ = true; 96 revert_translation_called_ = true;
93 } 97 }
94 98
95 virtual void TranslationDeclined() OVERRIDE { 99 virtual void TranslationDeclined() OVERRIDE {
96 translation_declined_called_ = true; 100 translation_declined_called_ = true;
97 } 101 }
98 102
103 virtual bool IsPageTranslatedInCurrentLanguages() const OVERRIDE {
104 return original_language_index_on_translation_ ==
105 original_language_index_ &&
106 target_language_index_on_translation_ == target_language_index_;
107 }
108
99 TranslateBubbleViewStateTransition view_state_transition_; 109 TranslateBubbleViewStateTransition view_state_transition_;
100 int original_language_index_; 110 int original_language_index_;
101 int target_language_index_; 111 int target_language_index_;
102 bool never_translate_language_; 112 bool never_translate_language_;
103 bool never_translate_site_; 113 bool never_translate_site_;
104 bool should_always_translate_; 114 bool should_always_translate_;
105 int set_always_translate_called_count_; 115 int set_always_translate_called_count_;
106 bool translate_called_; 116 bool translate_called_;
107 bool revert_translation_called_; 117 bool revert_translation_called_;
108 bool translation_declined_called_; 118 bool translation_declined_called_;
119 int original_language_index_on_translation_;
120 int target_language_index_on_translation_;
109 }; 121 };
110 122
111 } // namespace 123 } // namespace
112 124
113 class TranslateBubbleViewTest : public views::ViewsTestBase { 125 class TranslateBubbleViewTest : public views::ViewsTestBase {
114 public: 126 public:
115 TranslateBubbleViewTest() { 127 TranslateBubbleViewTest() {
116 } 128 }
117 129
118 protected: 130 protected:
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 bubble_->HandleButtonPressed(TranslateBubbleView::BUTTON_ID_ALWAYS_TRANSLATE); 236 bubble_->HandleButtonPressed(TranslateBubbleView::BUTTON_ID_ALWAYS_TRANSLATE);
225 EXPECT_FALSE(mock_model_->should_always_translate_); 237 EXPECT_FALSE(mock_model_->should_always_translate_);
226 EXPECT_EQ(0, mock_model_->set_always_translate_called_count_); 238 EXPECT_EQ(0, mock_model_->set_always_translate_called_count_);
227 239
228 // Click the done button. The state is saved. 240 // Click the done button. The state is saved.
229 bubble_->HandleButtonPressed(TranslateBubbleView::BUTTON_ID_DONE); 241 bubble_->HandleButtonPressed(TranslateBubbleView::BUTTON_ID_DONE);
230 EXPECT_TRUE(mock_model_->should_always_translate_); 242 EXPECT_TRUE(mock_model_->should_always_translate_);
231 EXPECT_EQ(1, mock_model_->set_always_translate_called_count_); 243 EXPECT_EQ(1, mock_model_->set_always_translate_called_count_);
232 } 244 }
233 245
234
235 TEST_F(TranslateBubbleViewTest, DoneButton) { 246 TEST_F(TranslateBubbleViewTest, DoneButton) {
236 bubble_->SwitchView(TranslateBubbleModel::VIEW_STATE_ADVANCED); 247 bubble_->SwitchView(TranslateBubbleModel::VIEW_STATE_ADVANCED);
237 248
238 // Click the "Done" button to translate. The selected languages by the user 249 // Click the "Done" button to translate. The selected languages by the user
239 // are applied. 250 // are applied.
240 EXPECT_FALSE(mock_model_->translate_called_); 251 EXPECT_FALSE(mock_model_->translate_called_);
241 bubble_->source_language_combobox_->SetSelectedIndex(10); 252 bubble_->source_language_combobox_->SetSelectedIndex(10);
242 bubble_->HandleComboboxSelectedIndexChanged( 253 bubble_->HandleComboboxSelectedIndexChanged(
243 TranslateBubbleView::COMBOBOX_ID_SOURCE_LANGUAGE); 254 TranslateBubbleView::COMBOBOX_ID_SOURCE_LANGUAGE);
244 bubble_->target_language_combobox_->SetSelectedIndex(20); 255 bubble_->target_language_combobox_->SetSelectedIndex(20);
245 bubble_->HandleComboboxSelectedIndexChanged( 256 bubble_->HandleComboboxSelectedIndexChanged(
246 TranslateBubbleView::COMBOBOX_ID_TARGET_LANGUAGE); 257 TranslateBubbleView::COMBOBOX_ID_TARGET_LANGUAGE);
247 bubble_->HandleButtonPressed(TranslateBubbleView::BUTTON_ID_DONE); 258 bubble_->HandleButtonPressed(TranslateBubbleView::BUTTON_ID_DONE);
248 EXPECT_TRUE(mock_model_->translate_called_); 259 EXPECT_TRUE(mock_model_->translate_called_);
249 EXPECT_EQ(10, mock_model_->original_language_index_); 260 EXPECT_EQ(10, mock_model_->original_language_index_);
250 EXPECT_EQ(20, mock_model_->target_language_index_); 261 EXPECT_EQ(20, mock_model_->target_language_index_);
251 } 262 }
252 263
264 TEST_F(TranslateBubbleViewTest, DoneButtonWithoutTranslating) {
265 EXPECT_EQ(TranslateBubbleModel::VIEW_STATE_BEFORE_TRANSLATE,
266 bubble_->GetViewState());
267
268 // Translate the page once.
269 mock_model_->Translate();
270 EXPECT_TRUE(mock_model_->translate_called_);
271
272 // Go back to the initial view.
273 EXPECT_EQ(TranslateBubbleModel::VIEW_STATE_BEFORE_TRANSLATE,
274 bubble_->GetViewState());
275 mock_model_->translate_called_ = false;
276
277 EXPECT_EQ(TranslateBubbleModel::VIEW_STATE_BEFORE_TRANSLATE,
278 bubble_->GetViewState());
279 bubble_->SwitchView(TranslateBubbleModel::VIEW_STATE_ADVANCED);
280
281 // Click the "Done" button with the current language pair. This time,
282 // translation is not performed and the view state will be back to the
283 // previous view.
284 bubble_->HandleButtonPressed(TranslateBubbleView::BUTTON_ID_DONE);
285 EXPECT_FALSE(mock_model_->translate_called_);
286
287 EXPECT_EQ(TranslateBubbleModel::VIEW_STATE_BEFORE_TRANSLATE,
288 bubble_->GetViewState());
289 }
290
253 TEST_F(TranslateBubbleViewTest, CancelButtonReturningBeforeTranslate) { 291 TEST_F(TranslateBubbleViewTest, CancelButtonReturningBeforeTranslate) {
254 bubble_->SwitchView(TranslateBubbleModel::VIEW_STATE_BEFORE_TRANSLATE); 292 bubble_->SwitchView(TranslateBubbleModel::VIEW_STATE_BEFORE_TRANSLATE);
255 bubble_->SwitchView(TranslateBubbleModel::VIEW_STATE_ADVANCED); 293 bubble_->SwitchView(TranslateBubbleModel::VIEW_STATE_ADVANCED);
256 294
257 // Click the "Cancel" button to go back. 295 // Click the "Cancel" button to go back.
258 EXPECT_EQ(TranslateBubbleModel::VIEW_STATE_ADVANCED, bubble_->GetViewState()); 296 EXPECT_EQ(TranslateBubbleModel::VIEW_STATE_ADVANCED, bubble_->GetViewState());
259 bubble_->HandleButtonPressed(TranslateBubbleView::BUTTON_ID_CANCEL); 297 bubble_->HandleButtonPressed(TranslateBubbleView::BUTTON_ID_CANCEL);
260 EXPECT_EQ(TranslateBubbleModel::VIEW_STATE_BEFORE_TRANSLATE, 298 EXPECT_EQ(TranslateBubbleModel::VIEW_STATE_BEFORE_TRANSLATE,
261 bubble_->GetViewState()); 299 bubble_->GetViewState());
262 } 300 }
(...skipping 11 matching lines...) Expand all
274 312
275 TEST_F(TranslateBubbleViewTest, CancelButtonReturningError) { 313 TEST_F(TranslateBubbleViewTest, CancelButtonReturningError) {
276 bubble_->SwitchView(TranslateBubbleModel::VIEW_STATE_ERROR); 314 bubble_->SwitchView(TranslateBubbleModel::VIEW_STATE_ERROR);
277 bubble_->SwitchView(TranslateBubbleModel::VIEW_STATE_ADVANCED); 315 bubble_->SwitchView(TranslateBubbleModel::VIEW_STATE_ADVANCED);
278 316
279 // Click the "Cancel" button to go back. 317 // Click the "Cancel" button to go back.
280 EXPECT_EQ(TranslateBubbleModel::VIEW_STATE_ADVANCED, bubble_->GetViewState()); 318 EXPECT_EQ(TranslateBubbleModel::VIEW_STATE_ADVANCED, bubble_->GetViewState());
281 bubble_->HandleButtonPressed(TranslateBubbleView::BUTTON_ID_CANCEL); 319 bubble_->HandleButtonPressed(TranslateBubbleView::BUTTON_ID_CANCEL);
282 EXPECT_EQ(TranslateBubbleModel::VIEW_STATE_ERROR, bubble_->GetViewState()); 320 EXPECT_EQ(TranslateBubbleModel::VIEW_STATE_ERROR, bubble_->GetViewState());
283 } 321 }
OLDNEW
« 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