OLD | NEW |
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 error_type_(TranslateErrors::NONE), | 22 error_type_(translate::TranslateErrors::NONE), |
23 original_language_index_(0), | 23 original_language_index_(0), |
24 target_language_index_(1), | 24 target_language_index_(1), |
25 never_translate_language_(false), | 25 never_translate_language_(false), |
26 never_translate_site_(false), | 26 never_translate_site_(false), |
27 should_always_translate_(false), | 27 should_always_translate_(false), |
28 set_always_translate_called_count_(0), | 28 set_always_translate_called_count_(0), |
29 translate_called_(false), | 29 translate_called_(false), |
30 revert_translation_called_(false), | 30 revert_translation_called_(false), |
31 translation_declined_called_(false), | 31 translation_declined_called_(false), |
32 original_language_index_on_translation_(-1), | 32 original_language_index_on_translation_(-1), |
33 target_language_index_on_translation_(-1) { | 33 target_language_index_on_translation_(-1) {} |
34 } | |
35 | 34 |
36 virtual TranslateBubbleModel::ViewState GetViewState() const OVERRIDE { | 35 virtual TranslateBubbleModel::ViewState GetViewState() const OVERRIDE { |
37 return view_state_transition_.view_state(); | 36 return view_state_transition_.view_state(); |
38 } | 37 } |
39 | 38 |
40 virtual void SetViewState(TranslateBubbleModel::ViewState view_state) | 39 virtual void SetViewState(TranslateBubbleModel::ViewState view_state) |
41 OVERRIDE { | 40 OVERRIDE { |
42 view_state_transition_.SetViewState(view_state); | 41 view_state_transition_.SetViewState(view_state); |
43 } | 42 } |
44 | 43 |
45 virtual void ShowError(TranslateErrors::Type error_type) OVERRIDE { | 44 virtual void ShowError(translate::TranslateErrors::Type error_type) OVERRIDE { |
46 error_type_ = error_type; | 45 error_type_ = error_type; |
47 } | 46 } |
48 | 47 |
49 virtual void GoBackFromAdvanced() OVERRIDE { | 48 virtual void GoBackFromAdvanced() OVERRIDE { |
50 view_state_transition_.GoBackFromAdvanced(); | 49 view_state_transition_.GoBackFromAdvanced(); |
51 } | 50 } |
52 | 51 |
53 virtual int GetNumberOfLanguages() const OVERRIDE { | 52 virtual int GetNumberOfLanguages() const OVERRIDE { |
54 return 1000; | 53 return 1000; |
55 } | 54 } |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 translation_declined_called_ = true; | 104 translation_declined_called_ = true; |
106 } | 105 } |
107 | 106 |
108 virtual bool IsPageTranslatedInCurrentLanguages() const OVERRIDE { | 107 virtual bool IsPageTranslatedInCurrentLanguages() const OVERRIDE { |
109 return original_language_index_on_translation_ == | 108 return original_language_index_on_translation_ == |
110 original_language_index_ && | 109 original_language_index_ && |
111 target_language_index_on_translation_ == target_language_index_; | 110 target_language_index_on_translation_ == target_language_index_; |
112 } | 111 } |
113 | 112 |
114 TranslateBubbleViewStateTransition view_state_transition_; | 113 TranslateBubbleViewStateTransition view_state_transition_; |
115 TranslateErrors::Type error_type_; | 114 translate::TranslateErrors::Type error_type_; |
116 int original_language_index_; | 115 int original_language_index_; |
117 int target_language_index_; | 116 int target_language_index_; |
118 bool never_translate_language_; | 117 bool never_translate_language_; |
119 bool never_translate_site_; | 118 bool never_translate_site_; |
120 bool should_always_translate_; | 119 bool should_always_translate_; |
121 int set_always_translate_called_count_; | 120 int set_always_translate_called_count_; |
122 bool translate_called_; | 121 bool translate_called_; |
123 bool revert_translation_called_; | 122 bool revert_translation_called_; |
124 bool translation_declined_called_; | 123 bool translation_declined_called_; |
125 int original_language_index_on_translation_; | 124 int original_language_index_on_translation_; |
(...skipping 18 matching lines...) Expand all Loading... |
144 | 143 |
145 anchor_widget_.reset(new views::Widget()); | 144 anchor_widget_.reset(new views::Widget()); |
146 anchor_widget_->Init(params); | 145 anchor_widget_->Init(params); |
147 anchor_widget_->Show(); | 146 anchor_widget_->Show(); |
148 | 147 |
149 mock_model_ = new MockTranslateBubbleModel( | 148 mock_model_ = new MockTranslateBubbleModel( |
150 TranslateBubbleModel::VIEW_STATE_BEFORE_TRANSLATE); | 149 TranslateBubbleModel::VIEW_STATE_BEFORE_TRANSLATE); |
151 scoped_ptr<TranslateBubbleModel> model(mock_model_); | 150 scoped_ptr<TranslateBubbleModel> model(mock_model_); |
152 bubble_ = new TranslateBubbleView(anchor_widget_->GetContentsView(), | 151 bubble_ = new TranslateBubbleView(anchor_widget_->GetContentsView(), |
153 model.Pass(), | 152 model.Pass(), |
154 TranslateErrors::NONE, | 153 translate::TranslateErrors::NONE, |
155 NULL); | 154 NULL); |
156 views::BubbleDelegateView::CreateBubble(bubble_)->Show(); | 155 views::BubbleDelegateView::CreateBubble(bubble_)->Show(); |
157 } | 156 } |
158 | 157 |
159 virtual void TearDown() OVERRIDE { | 158 virtual void TearDown() OVERRIDE { |
160 bubble_->GetWidget()->CloseNow(); | 159 bubble_->GetWidget()->CloseNow(); |
161 anchor_widget_.reset(); | 160 anchor_widget_.reset(); |
162 | 161 |
163 views::ViewsTestBase::TearDown(); | 162 views::ViewsTestBase::TearDown(); |
164 } | 163 } |
(...skipping 23 matching lines...) Expand all Loading... |
188 TEST_F(TranslateBubbleViewTest, ShowOriginalButton) { | 187 TEST_F(TranslateBubbleViewTest, ShowOriginalButton) { |
189 bubble_->SwitchView(TranslateBubbleModel::VIEW_STATE_AFTER_TRANSLATE); | 188 bubble_->SwitchView(TranslateBubbleModel::VIEW_STATE_AFTER_TRANSLATE); |
190 | 189 |
191 // Click the "Show original" button to revert translation. | 190 // Click the "Show original" button to revert translation. |
192 EXPECT_FALSE(mock_model_->revert_translation_called_); | 191 EXPECT_FALSE(mock_model_->revert_translation_called_); |
193 bubble_->HandleButtonPressed(TranslateBubbleView::BUTTON_ID_SHOW_ORIGINAL); | 192 bubble_->HandleButtonPressed(TranslateBubbleView::BUTTON_ID_SHOW_ORIGINAL); |
194 EXPECT_TRUE(mock_model_->revert_translation_called_); | 193 EXPECT_TRUE(mock_model_->revert_translation_called_); |
195 } | 194 } |
196 | 195 |
197 TEST_F(TranslateBubbleViewTest, TryAgainButton) { | 196 TEST_F(TranslateBubbleViewTest, TryAgainButton) { |
198 bubble_->SwitchToErrorView(TranslateErrors::NETWORK); | 197 bubble_->SwitchToErrorView(translate::TranslateErrors::NETWORK); |
199 | 198 |
200 EXPECT_EQ(TranslateErrors::NETWORK, mock_model_->error_type_); | 199 EXPECT_EQ(translate::TranslateErrors::NETWORK, mock_model_->error_type_); |
201 | 200 |
202 // Click the "Try again" button to translate. | 201 // Click the "Try again" button to translate. |
203 EXPECT_FALSE(mock_model_->translate_called_); | 202 EXPECT_FALSE(mock_model_->translate_called_); |
204 bubble_->HandleButtonPressed(TranslateBubbleView::BUTTON_ID_TRY_AGAIN); | 203 bubble_->HandleButtonPressed(TranslateBubbleView::BUTTON_ID_TRY_AGAIN); |
205 EXPECT_TRUE(mock_model_->translate_called_); | 204 EXPECT_TRUE(mock_model_->translate_called_); |
206 } | 205 } |
207 | 206 |
208 TEST_F(TranslateBubbleViewTest, AlwaysTranslateCheckboxAndCancelButton) { | 207 TEST_F(TranslateBubbleViewTest, AlwaysTranslateCheckboxAndCancelButton) { |
209 bubble_->SwitchView(TranslateBubbleModel::VIEW_STATE_ADVANCED); | 208 bubble_->SwitchView(TranslateBubbleModel::VIEW_STATE_ADVANCED); |
210 | 209 |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
320 | 319 |
321 TEST_F(TranslateBubbleViewTest, CancelButtonReturningError) { | 320 TEST_F(TranslateBubbleViewTest, CancelButtonReturningError) { |
322 bubble_->SwitchView(TranslateBubbleModel::VIEW_STATE_ERROR); | 321 bubble_->SwitchView(TranslateBubbleModel::VIEW_STATE_ERROR); |
323 bubble_->SwitchView(TranslateBubbleModel::VIEW_STATE_ADVANCED); | 322 bubble_->SwitchView(TranslateBubbleModel::VIEW_STATE_ADVANCED); |
324 | 323 |
325 // Click the "Cancel" button to go back. | 324 // Click the "Cancel" button to go back. |
326 EXPECT_EQ(TranslateBubbleModel::VIEW_STATE_ADVANCED, bubble_->GetViewState()); | 325 EXPECT_EQ(TranslateBubbleModel::VIEW_STATE_ADVANCED, bubble_->GetViewState()); |
327 bubble_->HandleButtonPressed(TranslateBubbleView::BUTTON_ID_CANCEL); | 326 bubble_->HandleButtonPressed(TranslateBubbleView::BUTTON_ID_CANCEL); |
328 EXPECT_EQ(TranslateBubbleModel::VIEW_STATE_ERROR, bubble_->GetViewState()); | 327 EXPECT_EQ(TranslateBubbleModel::VIEW_STATE_ERROR, bubble_->GetViewState()); |
329 } | 328 } |
OLD | NEW |