| 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 original_language_index_(0), | 23 original_language_index_(0), |
| 23 target_language_index_(1), | 24 target_language_index_(1), |
| 24 never_translate_language_(false), | 25 never_translate_language_(false), |
| 25 never_translate_site_(false), | 26 never_translate_site_(false), |
| 26 should_always_translate_(false), | 27 should_always_translate_(false), |
| 27 set_always_translate_called_count_(0), | 28 set_always_translate_called_count_(0), |
| 28 translate_called_(false), | 29 translate_called_(false), |
| 29 revert_translation_called_(false), | 30 revert_translation_called_(false), |
| 30 translation_declined_called_(false) { | 31 translation_declined_called_(false) { |
| 31 } | 32 } |
| 32 | 33 |
| 33 virtual TranslateBubbleModel::ViewState GetViewState() const OVERRIDE { | 34 virtual TranslateBubbleModel::ViewState GetViewState() const OVERRIDE { |
| 34 return view_state_transition_.view_state(); | 35 return view_state_transition_.view_state(); |
| 35 } | 36 } |
| 36 | 37 |
| 37 virtual void SetViewState(TranslateBubbleModel::ViewState view_state) | 38 virtual void SetViewState(TranslateBubbleModel::ViewState view_state) |
| 38 OVERRIDE { | 39 OVERRIDE { |
| 39 view_state_transition_.SetViewState(view_state); | 40 view_state_transition_.SetViewState(view_state); |
| 40 } | 41 } |
| 41 | 42 |
| 43 virtual TranslateErrors::Type GetErrorType() const OVERRIDE { |
| 44 return error_type_; |
| 45 } |
| 46 |
| 47 virtual void SetErrorType(TranslateErrors::Type error_type) OVERRIDE { |
| 48 error_type_ = error_type; |
| 49 } |
| 50 |
| 42 virtual void GoBackFromAdvanced() OVERRIDE { | 51 virtual void GoBackFromAdvanced() OVERRIDE { |
| 43 view_state_transition_.GoBackFromAdvanced(); | 52 view_state_transition_.GoBackFromAdvanced(); |
| 44 } | 53 } |
| 45 | 54 |
| 46 virtual int GetNumberOfLanguages() const OVERRIDE { | 55 virtual int GetNumberOfLanguages() const OVERRIDE { |
| 47 return 1000; | 56 return 1000; |
| 48 } | 57 } |
| 49 | 58 |
| 50 virtual string16 GetLanguageNameAt(int index) const OVERRIDE { | 59 virtual string16 GetLanguageNameAt(int index) const OVERRIDE { |
| 51 return string16(); | 60 return string16(); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 | 99 |
| 91 virtual void RevertTranslation() OVERRIDE { | 100 virtual void RevertTranslation() OVERRIDE { |
| 92 revert_translation_called_ = true; | 101 revert_translation_called_ = true; |
| 93 } | 102 } |
| 94 | 103 |
| 95 virtual void TranslationDeclined() OVERRIDE { | 104 virtual void TranslationDeclined() OVERRIDE { |
| 96 translation_declined_called_ = true; | 105 translation_declined_called_ = true; |
| 97 } | 106 } |
| 98 | 107 |
| 99 TranslateBubbleViewStateTransition view_state_transition_; | 108 TranslateBubbleViewStateTransition view_state_transition_; |
| 109 TranslateErrors::Type error_type_; |
| 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_; |
| 109 }; | 119 }; |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 bubble_->SwitchView(TranslateBubbleModel::VIEW_STATE_AFTER_TRANSLATE); | 181 bubble_->SwitchView(TranslateBubbleModel::VIEW_STATE_AFTER_TRANSLATE); |
| 172 | 182 |
| 173 // Click the "Show original" button to revert translation. | 183 // Click the "Show original" button to revert translation. |
| 174 EXPECT_FALSE(mock_model_->revert_translation_called_); | 184 EXPECT_FALSE(mock_model_->revert_translation_called_); |
| 175 bubble_->HandleButtonPressed(TranslateBubbleView::BUTTON_ID_SHOW_ORIGINAL); | 185 bubble_->HandleButtonPressed(TranslateBubbleView::BUTTON_ID_SHOW_ORIGINAL); |
| 176 EXPECT_TRUE(mock_model_->revert_translation_called_); | 186 EXPECT_TRUE(mock_model_->revert_translation_called_); |
| 177 } | 187 } |
| 178 | 188 |
| 179 TEST_F(TranslateBubbleViewTest, TryAgainButton) { | 189 TEST_F(TranslateBubbleViewTest, TryAgainButton) { |
| 180 bubble_->SwitchView(TranslateBubbleModel::VIEW_STATE_ERROR); | 190 bubble_->SwitchView(TranslateBubbleModel::VIEW_STATE_ERROR); |
| 191 bubble_->model()->SetErrorType(TranslateErrors::NETWORK); |
| 192 |
| 193 EXPECT_EQ(TranslateErrors::NETWORK, bubble_->model()->GetErrorType()); |
| 181 | 194 |
| 182 // Click the "Try again" button to translate. | 195 // Click the "Try again" button to translate. |
| 183 EXPECT_FALSE(mock_model_->translate_called_); | 196 EXPECT_FALSE(mock_model_->translate_called_); |
| 184 bubble_->HandleButtonPressed(TranslateBubbleView::BUTTON_ID_TRY_AGAIN); | 197 bubble_->HandleButtonPressed(TranslateBubbleView::BUTTON_ID_TRY_AGAIN); |
| 185 EXPECT_TRUE(mock_model_->translate_called_); | 198 EXPECT_TRUE(mock_model_->translate_called_); |
| 186 } | 199 } |
| 187 | 200 |
| 188 TEST_F(TranslateBubbleViewTest, AlwaysTranslateCheckboxAndCancelButton) { | 201 TEST_F(TranslateBubbleViewTest, AlwaysTranslateCheckboxAndCancelButton) { |
| 189 bubble_->SwitchView(TranslateBubbleModel::VIEW_STATE_ADVANCED); | 202 bubble_->SwitchView(TranslateBubbleModel::VIEW_STATE_ADVANCED); |
| 190 | 203 |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 | 287 |
| 275 TEST_F(TranslateBubbleViewTest, CancelButtonReturningError) { | 288 TEST_F(TranslateBubbleViewTest, CancelButtonReturningError) { |
| 276 bubble_->SwitchView(TranslateBubbleModel::VIEW_STATE_ERROR); | 289 bubble_->SwitchView(TranslateBubbleModel::VIEW_STATE_ERROR); |
| 277 bubble_->SwitchView(TranslateBubbleModel::VIEW_STATE_ADVANCED); | 290 bubble_->SwitchView(TranslateBubbleModel::VIEW_STATE_ADVANCED); |
| 278 | 291 |
| 279 // Click the "Cancel" button to go back. | 292 // Click the "Cancel" button to go back. |
| 280 EXPECT_EQ(TranslateBubbleModel::VIEW_STATE_ADVANCED, bubble_->GetViewState()); | 293 EXPECT_EQ(TranslateBubbleModel::VIEW_STATE_ADVANCED, bubble_->GetViewState()); |
| 281 bubble_->HandleButtonPressed(TranslateBubbleView::BUTTON_ID_CANCEL); | 294 bubble_->HandleButtonPressed(TranslateBubbleView::BUTTON_ID_CANCEL); |
| 282 EXPECT_EQ(TranslateBubbleModel::VIEW_STATE_ERROR, bubble_->GetViewState()); | 295 EXPECT_EQ(TranslateBubbleModel::VIEW_STATE_ERROR, bubble_->GetViewState()); |
| 283 } | 296 } |
| OLD | NEW |