Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(240)

Unified Diff: chrome/browser/ui/views/location_bar/icon_label_bubble_view_unittest.cc

Issue 2720183002: [Views] Update ink drop for omnibox icons (Closed)
Patch Set: Nits Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..bf7e232bad5385d325fa27db7f9491cf71f0f120 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,9 @@
#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/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"
@@ -17,6 +20,9 @@
namespace {
+using views::test::InkDropHostViewTestApi;
+using views::test::TestInkDrop;
+
const int kStayOpenTimeMS = 100;
const int kOpenTimeMS = 100;
const int kAnimationDurationMS = (kOpenTimeMS * 2) + kStayOpenTimeMS;
@@ -43,6 +49,10 @@ class TestIconLabelBubbleView : public IconLabelBubbleView {
SizeToPreferredSize();
}
+ void SetInkDrop(std::unique_ptr<views::InkDrop> ink_drop) {
+ InkDropHostViewTestApi(this).SetInkDrop(std::move(ink_drop));
+ }
+
int width() const { return bounds().width(); }
bool IsLabelVisible() const { return label()->visible(); }
void SetLabelVisible(bool visible) { label()->SetVisible(visible); }
@@ -59,6 +69,10 @@ class TestIconLabelBubbleView : public IconLabelBubbleView {
return STEADY;
}
+ void OnWidgetVisibilityChanged(views::Widget* widget, bool visible) override {
bruthig 2017/03/24 20:48:03 Is this needed?
spqchan 2017/03/27 23:41:51 Removed
+ IconLabelBubbleView::OnWidgetVisibilityChanged(widget, visible);
+ };
+
protected:
// IconLabelBubbleView:
SkColor GetTextColor() const override { return kTestColor; }
@@ -99,6 +113,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 +128,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 +155,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 +255,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 +279,15 @@ TEST_F(IconLabelBubbleViewTest, AnimateLayout) {
VerifyWithAnimationStep(25);
}
+TEST_F(IconLabelBubbleViewTest, InkDropState) {
+ AttachInkDrop();
+ generator()->ClickLeftButton();
+ EXPECT_EQ(views::InkDropState::ACTION_PENDING,
+ ink_drop()->GetTargetInkDropState());
+ view()->OnWidgetVisibilityChanged(nullptr, false);
+ EXPECT_EQ(views::InkDropState::HIDDEN, ink_drop()->GetTargetInkDropState());
+}
+
#if defined(USE_ASH)
// Verifies IconLabelBubbleView::GetPreferredSize() doesn't crash when there is
// a widget but no compositor.

Powered by Google App Engine
This is Rietveld 408576698