Chromium Code Reviews| 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 d9417ae413f6d4cb379f3ff0e1f39701853d3a64..fbc7df995d71124f557a58169cb647b7870a0b06 100644 |
| --- a/chrome/browser/ui/views/translate/translate_bubble_view_unittest.cc |
| +++ b/chrome/browser/ui/views/translate/translate_bubble_view_unittest.cc |
| @@ -7,11 +7,17 @@ |
| #include <memory> |
| #include <utility> |
| +#include "base/strings/utf_string_conversions.h" |
| #include "chrome/browser/ui/translate/translate_bubble_model.h" |
| #include "chrome/browser/ui/translate/translate_bubble_view_state_transition.h" |
| #include "testing/gtest/include/gtest/gtest.h" |
| +#include "ui/events/event_constants.h" |
| +#include "ui/events/event_utils.h" |
| +#include "ui/gfx/range/range.h" |
| +#include "ui/views/bubble/bubble_frame_view.h" |
| #include "ui/views/controls/button/checkbox.h" |
| #include "ui/views/controls/combobox/combobox.h" |
| +#include "ui/views/controls/styled_label.h" |
| #include "ui/views/test/combobox_test_api.h" |
| #include "ui/views/test/views_test_base.h" |
| #include "ui/views/widget/widget.h" |
| @@ -28,6 +34,7 @@ class MockTranslateBubbleModel : public TranslateBubbleModel { |
| never_translate_language_(false), |
| never_translate_site_(false), |
| should_always_translate_(false), |
| + always_translate_checked_(false), |
| set_always_translate_called_count_(0), |
| translate_called_(false), |
| revert_translation_called_(false), |
| @@ -54,7 +61,7 @@ class MockTranslateBubbleModel : public TranslateBubbleModel { |
| int GetNumberOfLanguages() const override { return 1000; } |
| base::string16 GetLanguageNameAt(int index) const override { |
| - return base::string16(); |
| + return base::ASCIIToUTF16("English"); |
| } |
| int GetOriginalLanguageIndex() const override { |
| @@ -81,6 +88,9 @@ class MockTranslateBubbleModel : public TranslateBubbleModel { |
| never_translate_site_ = value; |
| } |
| + bool GetAlwaysTranslateChecked() const override { |
| + return always_translate_checked_; |
| + } |
| bool ShouldAlwaysTranslate() const override { |
| return should_always_translate_; |
| } |
| @@ -113,6 +123,7 @@ class MockTranslateBubbleModel : public TranslateBubbleModel { |
| bool never_translate_language_; |
| bool never_translate_site_; |
| bool should_always_translate_; |
| + bool always_translate_checked_; |
| int set_always_translate_called_count_; |
| bool translate_called_; |
| bool revert_translation_called_; |
| @@ -143,6 +154,20 @@ class TranslateBubbleViewTest : public views::ViewsTestBase { |
| mock_model_ = new MockTranslateBubbleModel( |
| TranslateBubbleModel::VIEW_STATE_BEFORE_TRANSLATE); |
| + |
| + base::FeatureList::ClearInstanceForTesting(); |
| + base::FeatureList::SetInstance(base::WrapUnique(new base::FeatureList)); |
| + } |
| + |
| + void TurnOnTranslate2016Q2UIFlag() { |
| + base::FeatureList::ClearInstanceForTesting(); |
| + std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList); |
| + feature_list->InitializeFromCommandLine( |
| + translate::kTranslateUI2016Q2.name, ""); |
| + base::FeatureList::SetInstance(std::move(feature_list)); |
| + } |
| + |
| + void CreateAndShowBubble() { |
| std::unique_ptr<TranslateBubbleModel> model(mock_model_); |
| bubble_ = new TranslateBubbleView(anchor_widget_->GetContentsView(), |
| std::move(model), |
| @@ -150,6 +175,7 @@ class TranslateBubbleViewTest : public views::ViewsTestBase { |
| views::BubbleDialogDelegateView::CreateBubble(bubble_)->Show(); |
| } |
| + |
| void TearDown() override { |
| bubble_->GetWidget()->CloseNow(); |
| anchor_widget_.reset(); |
| @@ -166,6 +192,17 @@ class TranslateBubbleViewTest : public views::ViewsTestBase { |
| }; |
| TEST_F(TranslateBubbleViewTest, TranslateButton) { |
| + CreateAndShowBubble(); |
| + EXPECT_FALSE(mock_model_->translate_called_); |
| + |
| + // Press the "Translate" button. |
| + bubble_->HandleButtonPressed(TranslateBubbleView::BUTTON_ID_TRANSLATE); |
| + EXPECT_TRUE(mock_model_->translate_called_); |
| +} |
| + |
| +TEST_F(TranslateBubbleViewTest, TranslateButtonIn2016Q2UI) { |
| + TurnOnTranslate2016Q2UIFlag(); |
| + CreateAndShowBubble(); |
| EXPECT_FALSE(mock_model_->translate_called_); |
| // Press the "Translate" button. |
| @@ -173,7 +210,26 @@ TEST_F(TranslateBubbleViewTest, TranslateButton) { |
| EXPECT_TRUE(mock_model_->translate_called_); |
| } |
| +TEST_F(TranslateBubbleViewTest, CloseButtonIn2016Q2UI) { |
| + TurnOnTranslate2016Q2UIFlag(); |
| + CreateAndShowBubble(); |
| + EXPECT_FALSE(mock_model_->translate_called_); |
| + EXPECT_FALSE(mock_model_->translation_declined_); |
| + EXPECT_FALSE(bubble_->GetWidget()->IsClosed()); |
| + |
| + // Press the "Close" button. |
| + bubble_->GetBubbleFrameView()->ButtonPressed( |
| + bubble_->GetBubbleFrameView()->close_, |
| + ui::MouseEvent(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), |
| + ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE)); |
| + bubble_->WindowClosing(); |
|
Takashi Toyoshima
2016/04/28 05:01:22
ButtonPressed calls this internally, and causing t
|
| + EXPECT_FALSE(mock_model_->translate_called_); |
| + EXPECT_TRUE(mock_model_->translation_declined_); |
| + EXPECT_TRUE(bubble_->GetWidget()->IsClosed()); |
| +} |
| + |
| TEST_F(TranslateBubbleViewTest, ComboboxNope) { |
| + CreateAndShowBubble(); |
| views::test::ComboboxTestApi test_api(denial_combobox()); |
| EXPECT_FALSE(denial_button_clicked()); |
| EXPECT_FALSE(bubble_->GetWidget()->IsClosed()); |
| @@ -184,7 +240,38 @@ TEST_F(TranslateBubbleViewTest, ComboboxNope) { |
| EXPECT_TRUE(bubble_->GetWidget()->IsClosed()); |
| } |
| +TEST_F(TranslateBubbleViewTest, ComboboxNopeIn2016Q2UI) { |
| + TurnOnTranslate2016Q2UIFlag(); |
| + CreateAndShowBubble(); |
| + views::test::ComboboxTestApi test_api(denial_combobox()); |
| + EXPECT_FALSE(denial_button_clicked()); |
| + EXPECT_FALSE(bubble_->GetWidget()->IsClosed()); |
| + |
| + test_api.PerformActionAt(static_cast<int>( |
| + TranslateBubbleView::DenialComboboxIndex::DONT_TRANSLATE)); |
| + |
| + // In the 2016Q2 UI, we should not close nor take action. |
| + EXPECT_FALSE(denial_button_clicked()); |
| + EXPECT_FALSE(bubble_->GetWidget()->IsClosed()); |
| +} |
| + |
| TEST_F(TranslateBubbleViewTest, ComboboxNeverTranslateLanguage) { |
| + CreateAndShowBubble(); |
| + views::test::ComboboxTestApi test_api(denial_combobox()); |
| + EXPECT_FALSE(bubble_->GetWidget()->IsClosed()); |
| + EXPECT_FALSE(mock_model_->never_translate_language_); |
| + EXPECT_FALSE(denial_button_clicked()); |
| + |
| + test_api.PerformActionAt(static_cast<int>( |
| + TranslateBubbleView::DenialComboboxIndex::NEVER_TRANSLATE_LANGUAGE)); |
| + EXPECT_TRUE(denial_button_clicked()); |
| + EXPECT_TRUE(mock_model_->never_translate_language_); |
| + EXPECT_TRUE(bubble_->GetWidget()->IsClosed()); |
| +} |
| + |
| +TEST_F(TranslateBubbleViewTest, ComboboxNeverTranslateLanguageIn2016Q2UI) { |
| + TurnOnTranslate2016Q2UIFlag(); |
| + CreateAndShowBubble(); |
| views::test::ComboboxTestApi test_api(denial_combobox()); |
| EXPECT_FALSE(bubble_->GetWidget()->IsClosed()); |
| EXPECT_FALSE(mock_model_->never_translate_language_); |
| @@ -198,6 +285,22 @@ TEST_F(TranslateBubbleViewTest, ComboboxNeverTranslateLanguage) { |
| } |
| TEST_F(TranslateBubbleViewTest, ComboboxNeverTranslateSite) { |
| + CreateAndShowBubble(); |
| + views::test::ComboboxTestApi test_api(denial_combobox()); |
| + EXPECT_FALSE(mock_model_->never_translate_site_); |
| + EXPECT_FALSE(denial_button_clicked()); |
| + EXPECT_FALSE(bubble_->GetWidget()->IsClosed()); |
| + |
| + test_api.PerformActionAt(static_cast<int>( |
| + TranslateBubbleView::DenialComboboxIndex::NEVER_TRANSLATE_SITE)); |
| + EXPECT_TRUE(denial_button_clicked()); |
| + EXPECT_TRUE(mock_model_->never_translate_site_); |
| + EXPECT_TRUE(bubble_->GetWidget()->IsClosed()); |
| +} |
| + |
| +TEST_F(TranslateBubbleViewTest, ComboboxNeverTranslateSiteIn2016Q2UI) { |
| + TurnOnTranslate2016Q2UIFlag(); |
| + CreateAndShowBubble(); |
| views::test::ComboboxTestApi test_api(denial_combobox()); |
| EXPECT_FALSE(mock_model_->never_translate_site_); |
| EXPECT_FALSE(denial_button_clicked()); |
| @@ -211,6 +314,7 @@ TEST_F(TranslateBubbleViewTest, ComboboxNeverTranslateSite) { |
| } |
| TEST_F(TranslateBubbleViewTest, AdvancedLink) { |
| + CreateAndShowBubble(); |
| EXPECT_EQ(TranslateBubbleModel::VIEW_STATE_BEFORE_TRANSLATE, |
| bubble_->GetViewState()); |
| @@ -219,7 +323,20 @@ TEST_F(TranslateBubbleViewTest, AdvancedLink) { |
| EXPECT_EQ(TranslateBubbleModel::VIEW_STATE_ADVANCED, bubble_->GetViewState()); |
| } |
| +TEST_F(TranslateBubbleViewTest, AdvancedLinkIn2016Q2UI) { |
| + TurnOnTranslate2016Q2UIFlag(); |
| + CreateAndShowBubble(); |
| + EXPECT_EQ(TranslateBubbleModel::VIEW_STATE_BEFORE_TRANSLATE, |
| + bubble_->GetViewState()); |
| + |
| + // call the StyledLabelLinkClicked(); |
| + views::StyledLabel styled_label(base::ASCIIToUTF16("test"), nullptr); |
| + bubble_->StyledLabelLinkClicked(&styled_label, gfx::Range(), ui::EF_NONE); |
| + EXPECT_EQ(TranslateBubbleModel::VIEW_STATE_ADVANCED, bubble_->GetViewState()); |
| +} |
| + |
| TEST_F(TranslateBubbleViewTest, ShowOriginalButton) { |
| + CreateAndShowBubble(); |
| bubble_->SwitchView(TranslateBubbleModel::VIEW_STATE_AFTER_TRANSLATE); |
| // Click the "Show original" button to revert translation. |
| @@ -229,6 +346,7 @@ TEST_F(TranslateBubbleViewTest, ShowOriginalButton) { |
| } |
| TEST_F(TranslateBubbleViewTest, TryAgainButton) { |
| + CreateAndShowBubble(); |
| bubble_->SwitchToErrorView(translate::TranslateErrors::NETWORK); |
| EXPECT_EQ(translate::TranslateErrors::NETWORK, mock_model_->error_type_); |
| @@ -240,6 +358,7 @@ TEST_F(TranslateBubbleViewTest, TryAgainButton) { |
| } |
| TEST_F(TranslateBubbleViewTest, AlwaysTranslateCheckboxAndCancelButton) { |
| + CreateAndShowBubble(); |
| bubble_->SwitchView(TranslateBubbleModel::VIEW_STATE_ADVANCED); |
| // Click the "Always Translate" checkbox. Changing the state of this checkbox |
| @@ -263,6 +382,7 @@ TEST_F(TranslateBubbleViewTest, AlwaysTranslateCheckboxAndCancelButton) { |
| } |
| TEST_F(TranslateBubbleViewTest, AlwaysTranslateCheckboxAndDoneButton) { |
| + CreateAndShowBubble(); |
| bubble_->SwitchView(TranslateBubbleModel::VIEW_STATE_ADVANCED); |
| // Click the "Always Translate" checkbox. Changing the state of this checkbox |
| @@ -286,6 +406,7 @@ TEST_F(TranslateBubbleViewTest, AlwaysTranslateCheckboxAndDoneButton) { |
| } |
| TEST_F(TranslateBubbleViewTest, DoneButton) { |
| + CreateAndShowBubble(); |
| bubble_->SwitchView(TranslateBubbleModel::VIEW_STATE_ADVANCED); |
| // Click the "Done" button to translate. The selected languages by the user |
| @@ -304,6 +425,7 @@ TEST_F(TranslateBubbleViewTest, DoneButton) { |
| } |
| TEST_F(TranslateBubbleViewTest, DoneButtonWithoutTranslating) { |
| + CreateAndShowBubble(); |
| EXPECT_EQ(TranslateBubbleModel::VIEW_STATE_BEFORE_TRANSLATE, |
| bubble_->GetViewState()); |
| @@ -331,6 +453,7 @@ TEST_F(TranslateBubbleViewTest, DoneButtonWithoutTranslating) { |
| } |
| TEST_F(TranslateBubbleViewTest, CancelButtonReturningBeforeTranslate) { |
| + CreateAndShowBubble(); |
| bubble_->SwitchView(TranslateBubbleModel::VIEW_STATE_BEFORE_TRANSLATE); |
| bubble_->SwitchView(TranslateBubbleModel::VIEW_STATE_ADVANCED); |
| @@ -342,6 +465,7 @@ TEST_F(TranslateBubbleViewTest, CancelButtonReturningBeforeTranslate) { |
| } |
| TEST_F(TranslateBubbleViewTest, CancelButtonReturningAfterTranslate) { |
| + CreateAndShowBubble(); |
| bubble_->SwitchView(TranslateBubbleModel::VIEW_STATE_AFTER_TRANSLATE); |
| bubble_->SwitchView(TranslateBubbleModel::VIEW_STATE_ADVANCED); |
| @@ -353,6 +477,7 @@ TEST_F(TranslateBubbleViewTest, CancelButtonReturningAfterTranslate) { |
| } |
| TEST_F(TranslateBubbleViewTest, CancelButtonReturningError) { |
| + CreateAndShowBubble(); |
| bubble_->SwitchView(TranslateBubbleModel::VIEW_STATE_ERROR); |
| bubble_->SwitchView(TranslateBubbleModel::VIEW_STATE_ADVANCED); |