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 <memory> |
7 #include <utility> | 8 #include <utility> |
8 | 9 |
9 #include "base/memory/scoped_ptr.h" | |
10 #include "chrome/browser/ui/translate/translate_bubble_model.h" | 10 #include "chrome/browser/ui/translate/translate_bubble_model.h" |
11 #include "chrome/browser/ui/translate/translate_bubble_view_state_transition.h" | 11 #include "chrome/browser/ui/translate/translate_bubble_view_state_transition.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
13 #include "ui/views/controls/button/checkbox.h" | 13 #include "ui/views/controls/button/checkbox.h" |
14 #include "ui/views/controls/combobox/combobox.h" | 14 #include "ui/views/controls/combobox/combobox.h" |
15 #include "ui/views/test/combobox_test_api.h" | 15 #include "ui/views/test/combobox_test_api.h" |
16 #include "ui/views/test/views_test_base.h" | 16 #include "ui/views/test/views_test_base.h" |
17 #include "ui/views/widget/widget.h" | 17 #include "ui/views/widget/widget.h" |
18 | 18 |
19 namespace { | 19 namespace { |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 views::Widget::InitParams params = | 136 views::Widget::InitParams params = |
137 CreateParams(views::Widget::InitParams::TYPE_WINDOW); | 137 CreateParams(views::Widget::InitParams::TYPE_WINDOW); |
138 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 138 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
139 | 139 |
140 anchor_widget_.reset(new views::Widget()); | 140 anchor_widget_.reset(new views::Widget()); |
141 anchor_widget_->Init(params); | 141 anchor_widget_->Init(params); |
142 anchor_widget_->Show(); | 142 anchor_widget_->Show(); |
143 | 143 |
144 mock_model_ = new MockTranslateBubbleModel( | 144 mock_model_ = new MockTranslateBubbleModel( |
145 TranslateBubbleModel::VIEW_STATE_BEFORE_TRANSLATE); | 145 TranslateBubbleModel::VIEW_STATE_BEFORE_TRANSLATE); |
146 scoped_ptr<TranslateBubbleModel> model(mock_model_); | 146 std::unique_ptr<TranslateBubbleModel> model(mock_model_); |
147 bubble_ = new TranslateBubbleView(anchor_widget_->GetContentsView(), | 147 bubble_ = new TranslateBubbleView(anchor_widget_->GetContentsView(), |
148 std::move(model), | 148 std::move(model), |
149 translate::TranslateErrors::NONE, NULL); | 149 translate::TranslateErrors::NONE, NULL); |
150 views::BubbleDialogDelegateView::CreateBubble(bubble_)->Show(); | 150 views::BubbleDialogDelegateView::CreateBubble(bubble_)->Show(); |
151 } | 151 } |
152 | 152 |
153 void TearDown() override { | 153 void TearDown() override { |
154 bubble_->GetWidget()->CloseNow(); | 154 bubble_->GetWidget()->CloseNow(); |
155 anchor_widget_.reset(); | 155 anchor_widget_.reset(); |
156 | 156 |
157 views::ViewsTestBase::TearDown(); | 157 views::ViewsTestBase::TearDown(); |
158 } | 158 } |
159 | 159 |
160 views::Combobox* denial_combobox() { return bubble_->denial_combobox_; } | 160 views::Combobox* denial_combobox() { return bubble_->denial_combobox_; } |
161 bool denial_button_clicked() { return mock_model_->translation_declined_; } | 161 bool denial_button_clicked() { return mock_model_->translation_declined_; } |
162 | 162 |
163 scoped_ptr<views::Widget> anchor_widget_; | 163 std::unique_ptr<views::Widget> anchor_widget_; |
164 MockTranslateBubbleModel* mock_model_; | 164 MockTranslateBubbleModel* mock_model_; |
165 TranslateBubbleView* bubble_; | 165 TranslateBubbleView* bubble_; |
166 }; | 166 }; |
167 | 167 |
168 TEST_F(TranslateBubbleViewTest, TranslateButton) { | 168 TEST_F(TranslateBubbleViewTest, TranslateButton) { |
169 EXPECT_FALSE(mock_model_->translate_called_); | 169 EXPECT_FALSE(mock_model_->translate_called_); |
170 | 170 |
171 // Press the "Translate" button. | 171 // Press the "Translate" button. |
172 bubble_->HandleButtonPressed(TranslateBubbleView::BUTTON_ID_TRANSLATE); | 172 bubble_->HandleButtonPressed(TranslateBubbleView::BUTTON_ID_TRANSLATE); |
173 EXPECT_TRUE(mock_model_->translate_called_); | 173 EXPECT_TRUE(mock_model_->translate_called_); |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
354 | 354 |
355 TEST_F(TranslateBubbleViewTest, CancelButtonReturningError) { | 355 TEST_F(TranslateBubbleViewTest, CancelButtonReturningError) { |
356 bubble_->SwitchView(TranslateBubbleModel::VIEW_STATE_ERROR); | 356 bubble_->SwitchView(TranslateBubbleModel::VIEW_STATE_ERROR); |
357 bubble_->SwitchView(TranslateBubbleModel::VIEW_STATE_ADVANCED); | 357 bubble_->SwitchView(TranslateBubbleModel::VIEW_STATE_ADVANCED); |
358 | 358 |
359 // Click the "Cancel" button to go back. | 359 // Click the "Cancel" button to go back. |
360 EXPECT_EQ(TranslateBubbleModel::VIEW_STATE_ADVANCED, bubble_->GetViewState()); | 360 EXPECT_EQ(TranslateBubbleModel::VIEW_STATE_ADVANCED, bubble_->GetViewState()); |
361 bubble_->HandleButtonPressed(TranslateBubbleView::BUTTON_ID_CANCEL); | 361 bubble_->HandleButtonPressed(TranslateBubbleView::BUTTON_ID_CANCEL); |
362 EXPECT_EQ(TranslateBubbleModel::VIEW_STATE_ERROR, bubble_->GetViewState()); | 362 EXPECT_EQ(TranslateBubbleModel::VIEW_STATE_ERROR, bubble_->GetViewState()); |
363 } | 363 } |
OLD | NEW |