Chromium Code Reviews| Index: chrome/browser/ui/views/location_bar/icon_label_bubble_view_unittest.cc |
| diff --git a/chrome/browser/ui/views/location_bar/icon_label_bubble_view_unittest.cc b/chrome/browser/ui/views/location_bar/icon_label_bubble_view_unittest.cc |
| index b2fc2bbf066c7aef5f0e4636f19b5e7f089d59b6..07c25faeb0f70f88cf63f7c53ffd0a81b3f420d6 100644 |
| --- a/chrome/browser/ui/views/location_bar/icon_label_bubble_view_unittest.cc |
| +++ b/chrome/browser/ui/views/location_bar/icon_label_bubble_view_unittest.cc |
| @@ -8,6 +8,11 @@ |
| #include "chrome/browser/ui/layout_constants.h" |
| #include "chrome/browser/ui/views/location_bar/location_bar_view.h" |
| #include "testing/gtest/include/gtest/gtest.h" |
| +#include "ui/events/base_event_utils.h" |
| +#include "ui/events/gesture_detection/gesture_configuration.h" |
| +#include "ui/events/test/event_generator.h" |
| +#include "ui/views/animation/test/ink_drop_host_view_test_api.h" |
| +#include "ui/views/animation/test/test_ink_drop.h" |
| #include "ui/views/controls/image_view.h" |
| #include "ui/views/test/views_test_base.h" |
| @@ -15,6 +20,9 @@ |
| #include "ui/aura/window.h" |
| #endif |
| +using views::test::InkDropHostViewTestApi; |
| +using views::test::TestInkDrop; |
| + |
| namespace { |
| const int kStayOpenTimeMS = 100; |
| @@ -33,7 +41,9 @@ class TestIconLabelBubbleView : public IconLabelBubbleView { |
| }; |
| explicit TestIconLabelBubbleView(const gfx::FontList& font_list) |
| - : IconLabelBubbleView(font_list, false), value_(0) { |
| + : IconLabelBubbleView(font_list, false), |
| + value_(0), |
| + is_bubble_shown_(false) { |
| GetImageView()->SetImageSize(gfx::Size(kImageSize, kImageSize)); |
| SetLabel(base::ASCIIToUTF16("Label")); |
| } |
| @@ -59,6 +69,12 @@ class TestIconLabelBubbleView : public IconLabelBubbleView { |
| return STEADY; |
| } |
| + void HideBubble() { OnWidgetVisibilityChanged(nullptr, false); } |
| + |
| + void set_is_bubble_shown(bool is_bubble_shown) { |
| + is_bubble_shown_ = is_bubble_shown; |
| + } |
| + |
| protected: |
| // IconLabelBubbleView: |
| SkColor GetTextColor() const override { return kTestColor; } |
| @@ -88,8 +104,15 @@ class TestIconLabelBubbleView : public IconLabelBubbleView { |
| bool IsShrinking() const override { return state() == SHRINKING; } |
| + bool IsBubbleShown() const override { return is_bubble_shown_; } |
| + |
| + bool ShowBubble(const ui::Event& event) override { |
| + return !is_bubble_shown_; |
| + }; |
|
sky
2017/05/12 13:11:48
no ;
spqchan
2017/05/18 01:13:05
Done.
|
| + |
| private: |
| int value_; |
| + bool is_bubble_shown_; |
| DISALLOW_COPY_AND_ASSIGN(TestIconLabelBubbleView); |
| }; |
| @@ -99,6 +122,9 @@ class IconLabelBubbleViewTest : public views::ViewsTestBase { |
| public: |
| IconLabelBubbleViewTest() |
| : views::ViewsTestBase(), |
| + widget_(nullptr), |
| + view_(nullptr), |
| + ink_drop_(nullptr), |
| steady_reached_(false), |
| shrinking_reached_(false), |
| minimum_size_reached_(false), |
| @@ -111,7 +137,22 @@ class IconLabelBubbleViewTest : public views::ViewsTestBase { |
| void SetUp() override { |
| views::ViewsTestBase::SetUp(); |
| gfx::FontList font_list; |
| - view_.reset(new TestIconLabelBubbleView(font_list)); |
| + |
| + CreateWidget(); |
| + generator_.reset(new ui::test::EventGenerator(widget_->GetNativeWindow())); |
| + view_ = new TestIconLabelBubbleView(font_list); |
| + view_->SetBoundsRect(gfx::Rect(0, 0, 24, 24)); |
| + widget_->SetContentsView(view_); |
| + |
| + widget_->Show(); |
| + } |
| + |
| + void TearDown() override { |
| + generator_.reset(); |
| + if (widget_ && !widget_->IsClosed()) |
| + widget_->Close(); |
| + |
| + ViewsTestBase::TearDown(); |
| } |
| void VerifyWithAnimationStep(int step) { |
| @@ -123,7 +164,28 @@ class IconLabelBubbleViewTest : public views::ViewsTestBase { |
| view_->SetLabelVisible(false); |
| } |
| + TestInkDrop* ink_drop() { return ink_drop_; } |
| + |
| + TestIconLabelBubbleView* view() { return view_; } |
| + |
| + ui::test::EventGenerator* generator() { return generator_.get(); } |
| + |
| + void AttachInkDrop() { |
| + ink_drop_ = new TestInkDrop(); |
| + InkDropHostViewTestApi(view_).SetInkDrop(base::WrapUnique(ink_drop_)); |
| + } |
| + |
| private: |
| + void CreateWidget() { |
| + DCHECK(!widget_); |
| + |
| + widget_ = new views::Widget; |
| + views::Widget::InitParams params = |
| + CreateParams(views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); |
| + params.bounds = gfx::Rect(0, 0, 200, 200); |
| + widget_->Init(params); |
| + } |
| + |
| void Reset() { |
| view_->SetLabelVisible(true); |
| SetValue(0); |
| @@ -202,7 +264,10 @@ class IconLabelBubbleViewTest : public views::ViewsTestBase { |
| return view_->GetImageView()->bounds(); |
| } |
| - std::unique_ptr<TestIconLabelBubbleView> view_; |
| + views::Widget* widget_; |
| + TestIconLabelBubbleView* view_; |
| + TestInkDrop* ink_drop_; |
| + std::unique_ptr<ui::test::EventGenerator> generator_; |
| bool steady_reached_; |
| bool shrinking_reached_; |
| @@ -223,6 +288,52 @@ TEST_F(IconLabelBubbleViewTest, AnimateLayout) { |
| VerifyWithAnimationStep(25); |
| } |
| +TEST_F(IconLabelBubbleViewTest, MouseInkDropState) { |
| + AttachInkDrop(); |
| + generator()->PressLeftButton(); |
| + EXPECT_EQ(views::InkDropState::ACTION_PENDING, |
| + ink_drop()->GetTargetInkDropState()); |
| + generator()->ReleaseLeftButton(); |
| + EXPECT_EQ(views::InkDropState::ACTIVATED, |
| + ink_drop()->GetTargetInkDropState()); |
| + view()->HideBubble(); |
| + EXPECT_EQ(views::InkDropState::HIDDEN, ink_drop()->GetTargetInkDropState()); |
| + |
| + // If the bubble is shown, the InkDropState should not change to |
| + // ACTION_PENDING. |
| + generator()->PressLeftButton(); |
| + EXPECT_EQ(views::InkDropState::ACTION_PENDING, |
| + ink_drop()->GetTargetInkDropState()); |
| + generator()->ReleaseLeftButton(); |
| + EXPECT_EQ(views::InkDropState::ACTIVATED, |
| + ink_drop()->GetTargetInkDropState()); |
| + view()->set_is_bubble_shown(true); |
| + generator()->PressLeftButton(); |
| + EXPECT_NE(views::InkDropState::ACTION_PENDING, |
| + ink_drop()->GetTargetInkDropState()); |
| +} |
| + |
| +#if !defined(OS_MACOSX) |
| +TEST_F(IconLabelBubbleViewTest, GestureInkDropState) { |
| + AttachInkDrop(); |
| + view()->set_is_bubble_shown(false); |
| + generator()->GestureTapAt(gfx::Point()); |
| + EXPECT_EQ(views::InkDropState::ACTIVATED, |
| + ink_drop()->GetTargetInkDropState()); |
| + view()->HideBubble(); |
| + EXPECT_EQ(views::InkDropState::HIDDEN, ink_drop()->GetTargetInkDropState()); |
| + |
| + // If the bubble is shown, the InkDropState should not change to |
| + // ACTIVATED. |
| + generator()->GestureTapAt(gfx::Point()); |
| + EXPECT_EQ(views::InkDropState::ACTIVATED, |
| + ink_drop()->GetTargetInkDropState()); |
| + view()->set_is_bubble_shown(true); |
| + generator()->GestureTapAt(gfx::Point()); |
| + EXPECT_EQ(views::InkDropState::HIDDEN, ink_drop()->GetTargetInkDropState()); |
| +} |
| +#endif |
| + |
| #if defined(USE_ASH) |
| // Verifies IconLabelBubbleView::GetPreferredSize() doesn't crash when there is |
| // a widget but no compositor. |