| Index: ui/views/controls/button/custom_button_unittest.cc
|
| diff --git a/ui/views/controls/button/custom_button_unittest.cc b/ui/views/controls/button/custom_button_unittest.cc
|
| index ef26e199f7852eaf196e58b10ccce18e0b583b4a..686f4d7c63d8458810b6e279175e762d0a7a7fbc 100644
|
| --- a/ui/views/controls/button/custom_button_unittest.cc
|
| +++ b/ui/views/controls/button/custom_button_unittest.cc
|
| @@ -9,7 +9,10 @@
|
| #include "testing/gtest/include/gtest/gtest.h"
|
| #include "ui/base/layout.h"
|
| #include "ui/events/event_utils.h"
|
| +#include "ui/events/test/event_generator.h"
|
| #include "ui/gfx/screen.h"
|
| +#include "ui/views/animation/ink_drop_delegate.h"
|
| +#include "ui/views/animation/ink_drop_host.h"
|
| #include "ui/views/controls/button/checkbox.h"
|
| #include "ui/views/controls/button/image_button.h"
|
| #include "ui/views/controls/button/label_button.h"
|
| @@ -84,6 +87,73 @@ class TestWidget : public Widget {
|
| DISALLOW_COPY_AND_ASSIGN(TestWidget);
|
| };
|
|
|
| +// An InkDropDelegate that keeps track of ink drop visibility.
|
| +class TestInkDropDelegate : public InkDropDelegate {
|
| + public:
|
| + TestInkDropDelegate(InkDropHost* ink_drop_host,
|
| + bool* ink_shown,
|
| + bool* ink_hidden)
|
| + : ink_drop_host_(ink_drop_host),
|
| + ink_shown_(ink_shown),
|
| + ink_hidden_(ink_hidden) {
|
| + ink_drop_host_->AddInkDropLayer(nullptr);
|
| + }
|
| + ~TestInkDropDelegate() override {}
|
| +
|
| + // InkDropDelegate:
|
| + void SetInkDropSize(int large_size,
|
| + int large_corner_radius,
|
| + int small_size,
|
| + int small_corner_radius) override {}
|
| + void OnLayout() override {}
|
| + void OnAction(InkDropState state) override {
|
| + switch (state) {
|
| + case InkDropState::ACTION_PENDING:
|
| + case InkDropState::SLOW_ACTION_PENDING:
|
| + case InkDropState::ACTIVATED:
|
| + *ink_shown_ = true;
|
| + break;
|
| + case InkDropState::HIDDEN:
|
| + *ink_hidden_ = true;
|
| + break;
|
| + case InkDropState::QUICK_ACTION:
|
| + case InkDropState::SLOW_ACTION:
|
| + case InkDropState::DEACTIVATED:
|
| + break;
|
| + }
|
| + }
|
| +
|
| + private:
|
| + InkDropHost* ink_drop_host_;
|
| + bool* ink_shown_;
|
| + bool* ink_hidden_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(TestInkDropDelegate);
|
| +};
|
| +
|
| +// A test Button class that owns a TestInkDropDelegate.
|
| +class TestButtonWithInkDrop : public TestCustomButton,
|
| + public views::InkDropHost {
|
| + public:
|
| + TestButtonWithInkDrop(bool* ink_shown, bool* ink_hidden)
|
| + : TestCustomButton(),
|
| + ink_drop_delegate_(
|
| + new TestInkDropDelegate(this, ink_shown, ink_hidden)) {
|
| + set_ink_drop_delegate(ink_drop_delegate_.get());
|
| + }
|
| + ~TestButtonWithInkDrop() override {}
|
| +
|
| + // views::InkDropHost:
|
| + void AddInkDropLayer(ui::Layer* ink_drop_layer) override {}
|
| + void RemoveInkDropLayer(ui::Layer* ink_drop_layer) override {}
|
| + gfx::Point CalculateInkDropCenter() const override { return gfx::Point(); }
|
| +
|
| + private:
|
| + scoped_ptr<views::InkDropDelegate> ink_drop_delegate_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(TestButtonWithInkDrop);
|
| +};
|
| +
|
| class CustomButtonTest : public ViewsTestBase {
|
| public:
|
| CustomButtonTest() {}
|
| @@ -101,13 +171,6 @@ class CustomButtonTest : public ViewsTestBase {
|
| widget_->Init(params);
|
| widget_->Show();
|
|
|
| - // Position the widget in a way so that it is under the cursor.
|
| - gfx::Point cursor = gfx::Screen::GetScreenFor(
|
| - widget_->GetNativeView())->GetCursorScreenPoint();
|
| - gfx::Rect widget_bounds = widget_->GetWindowBoundsInScreen();
|
| - widget_bounds.set_origin(cursor);
|
| - widget_->SetBounds(widget_bounds);
|
| -
|
| button_ = new TestCustomButton();
|
| widget_->SetContentsView(button_);
|
| }
|
| @@ -117,12 +180,25 @@ class CustomButtonTest : public ViewsTestBase {
|
| ViewsTestBase::TearDown();
|
| }
|
|
|
| + void CreateButtonWithInkDrop() {
|
| + delete button_;
|
| + ink_shown_ = false;
|
| + ink_hidden_ = false;
|
| + button_ = new TestButtonWithInkDrop(&ink_shown_, &ink_hidden_);
|
| + widget_->SetContentsView(button_);
|
| + }
|
| +
|
| + protected:
|
| TestWidget* widget() { return widget_.get(); }
|
| TestCustomButton* button() { return button_; }
|
| + bool ink_shown() const { return ink_shown_; }
|
| + bool ink_hidden() const { return ink_hidden_; }
|
|
|
| private:
|
| scoped_ptr<TestWidget> widget_;
|
| TestCustomButton* button_;
|
| + bool ink_shown_ = false;
|
| + bool ink_hidden_ = false;
|
|
|
| DISALLOW_COPY_AND_ASSIGN(CustomButtonTest);
|
| };
|
| @@ -361,4 +437,40 @@ TEST_F(CustomButtonTest, AsCustomButton) {
|
| EXPECT_FALSE(CustomButton::AsCustomButton(&textfield));
|
| }
|
|
|
| +// Tests that pressing a button shows the ink drop and releasing the button
|
| +// does not hide the ink drop.
|
| +// Note: Ink drop is not hidden upon release because CustomButton descendants
|
| +// may enter a different ink drop state.
|
| +TEST_F(CustomButtonTest, ButtonClickTogglesInkDrop) {
|
| + gfx::Point old_cursor = gfx::Screen::GetScreenFor(
|
| + widget()->GetNativeView())->GetCursorScreenPoint();
|
| + CreateButtonWithInkDrop();
|
| +
|
| + ui::test::EventGenerator generator(GetContext(), widget()->GetNativeWindow());
|
| + generator.set_current_location(gfx::Point(50, 50));
|
| + generator.PressLeftButton();
|
| + EXPECT_TRUE(ink_shown());
|
| + EXPECT_FALSE(ink_hidden());
|
| +
|
| + generator.ReleaseLeftButton();
|
| + EXPECT_FALSE(ink_hidden());
|
| +}
|
| +
|
| +// Tests that pressing a button shows and releasing capture hides ink drop.
|
| +TEST_F(CustomButtonTest, CaptureLossHidesInkDrop) {
|
| + gfx::Point old_cursor = gfx::Screen::GetScreenFor(
|
| + widget()->GetNativeView())->GetCursorScreenPoint();
|
| + CreateButtonWithInkDrop();
|
| +
|
| + ui::test::EventGenerator generator(GetContext(), widget()->GetNativeWindow());
|
| + generator.set_current_location(gfx::Point(50, 50));
|
| + generator.PressLeftButton();
|
| + EXPECT_TRUE(ink_shown());
|
| + EXPECT_FALSE(ink_hidden());
|
| +
|
| + widget()->SetCapture(button());
|
| + widget()->ReleaseCapture();
|
| + EXPECT_TRUE(ink_hidden());
|
| +}
|
| +
|
| } // namespace views
|
|
|