| 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..d54579364622d3b26326060320662e6e7e88ba65 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_showing_(false) {
|
| GetImageView()->SetImageSize(gfx::Size(kImageSize, kImageSize));
|
| SetLabel(base::ASCIIToUTF16("Label"));
|
| }
|
| @@ -59,6 +69,13 @@ class TestIconLabelBubbleView : public IconLabelBubbleView {
|
| return STEADY;
|
| }
|
|
|
| + void HideBubble() {
|
| + OnWidgetVisibilityChanged(nullptr, false);
|
| + is_bubble_showing_ = false;
|
| + }
|
| +
|
| + bool IsBubbleShowing() const override { return is_bubble_showing_; }
|
| +
|
| protected:
|
| // IconLabelBubbleView:
|
| SkColor GetTextColor() const override { return kTestColor; }
|
| @@ -88,8 +105,14 @@ class TestIconLabelBubbleView : public IconLabelBubbleView {
|
|
|
| bool IsShrinking() const override { return state() == SHRINKING; }
|
|
|
| + bool ShowBubble(const ui::Event& event) override {
|
| + is_bubble_showing_ = true;
|
| + return true;
|
| + }
|
| +
|
| private:
|
| int value_;
|
| + bool is_bubble_showing_;
|
| 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,65 @@ TEST_F(IconLabelBubbleViewTest, AnimateLayout) {
|
| VerifyWithAnimationStep(25);
|
| }
|
|
|
| +// Verify that clicking the view a second time hides its bubble.
|
| +TEST_F(IconLabelBubbleViewTest, SecondClick) {
|
| + generator()->PressLeftButton();
|
| + EXPECT_FALSE(view()->IsBubbleShowing());
|
| + generator()->ReleaseLeftButton();
|
| + EXPECT_TRUE(view()->IsBubbleShowing());
|
| +
|
| + // Hide the bubble manually. In the browser this would normally happen during
|
| + // the event processing.
|
| + generator()->PressLeftButton();
|
| + view()->HideBubble();
|
| + EXPECT_FALSE(view()->IsBubbleShowing());
|
| + generator()->ReleaseLeftButton();
|
| +}
|
| +
|
| +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());
|
| + generator()->PressLeftButton();
|
| + EXPECT_NE(views::InkDropState::ACTION_PENDING,
|
| + ink_drop()->GetTargetInkDropState());
|
| +}
|
| +
|
| +#if !defined(OS_MACOSX)
|
| +TEST_F(IconLabelBubbleViewTest, GestureInkDropState) {
|
| + AttachInkDrop();
|
| + 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());
|
| + generator()->GestureTapAt(gfx::Point());
|
| + view()->HideBubble();
|
| + 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.
|
|
|