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

Unified Diff: ui/views/animation/ink_drop_delegate_unittest.cc

Issue 1517003002: Fixes stale hover or ink ripple visuals when dragging over extension buttons (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixes stale hover or ink ripple visuals when dragging over extension buttons (adds test) Created 4 years, 12 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
« no previous file with comments | « no previous file | ui/views/controls/button/custom_button.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/views/animation/ink_drop_delegate_unittest.cc
diff --git a/ui/views/animation/ink_drop_delegate_unittest.cc b/ui/views/animation/ink_drop_delegate_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..6a69155be007ae4728b9b070e9177f9a9838dce6
--- /dev/null
+++ b/ui/views/animation/ink_drop_delegate_unittest.cc
@@ -0,0 +1,161 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ui/views/animation/ink_drop_delegate.h"
+
+#include "ui/events/test/event_generator.h"
+#include "ui/views/animation/ink_drop_host.h"
+#include "ui/views/controls/button/custom_button.h"
+#include "ui/views/test/views_test_base.h"
+
+namespace views {
+
+namespace {
+
+// An InkDropDelegate that keeps track of order of deletions.
+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::QUICK_ACTION:
+ case InkDropState::SLOW_ACTION_PENDING:
+ case InkDropState::SLOW_ACTION:
+ case InkDropState::ACTIVATED:
+ *ink_shown_ = true;
+ break;
+ case InkDropState::HIDDEN:
+ case InkDropState::DEACTIVATED:
+ *ink_hidden_ = true;
+ 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 TestButton : public views::CustomButton, public views::InkDropHost {
+ public:
+ TestButton(bool* ink_shown, bool* ink_hidden)
+ : CustomButton(nullptr),
+ ink_drop_delegate_(
+ new TestInkDropDelegate(this, ink_shown, ink_hidden)) {
+ set_ink_drop_delegate(ink_drop_delegate_.get());
+ }
+ ~TestButton() 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(TestButton);
+};
+
+} // namespace
+
+class InkDropDelegateTest : public ViewsTestBase {
+ public:
+ InkDropDelegateTest() {}
+ ~InkDropDelegateTest() override {}
+
+ void TearDown() override {
+ if (widget_ && !widget_->IsClosed())
+ widget_->Close();
+ ViewsTestBase::TearDown();
+ }
+
+ Widget* widget() { return widget_; }
+ TestButton* button() { return button_; }
+
+ protected:
+ // Creates a MenuButton with no button listener.
+ void CreateTestButtons() { CreateButtons(); }
+
+ bool ink_shown() const { return ink_shown_; }
+ bool ink_hidden() const { return ink_hidden_; }
+
+ private:
+ void CreateButtons() {
+ CreateWidget();
+ button_ = new TestButton(&ink_shown_, &ink_hidden_);
bruthig 2016/01/06 22:46:00 It might be worth having a DCHECK(!button_) after
varkha 2016/01/07 01:37:36 Acknowledged (the code has been reworked so that C
+ button_->SetBounds(0, 0, 100, 100);
+ widget_->SetContentsView(button_);
+ widget_->Show();
+ }
+
+ void CreateWidget() {
+ DCHECK(!widget_);
+
+ widget_ = new Widget;
+ Widget::InitParams params =
+ CreateParams(Widget::InitParams::TYPE_WINDOW_FRAMELESS);
+ params.bounds = gfx::Rect(0, 0, 100, 100);
+ widget_->Init(params);
+ }
+
+ Widget* widget_ = nullptr;
+ TestButton* button_ = nullptr;
+ bool ink_shown_ = false;
+ bool ink_hidden_ = false;
+};
+
+// 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(InkDropDelegateTest, ButtonClickTogglesInkDrop) {
+ CreateTestButtons();
+
+ 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(InkDropDelegateTest, CaptureLossHidesInkDrop) {
+ CreateTestButtons();
+
+ 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
« no previous file with comments | « no previous file | ui/views/controls/button/custom_button.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698