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

Side by Side 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, 11 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 unified diff | Download patch
« no previous file with comments | « no previous file | ui/views/controls/button/custom_button.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "ui/views/animation/ink_drop_delegate.h"
6
7 #include "ui/events/test/event_generator.h"
8 #include "ui/views/animation/ink_drop_host.h"
9 #include "ui/views/controls/button/custom_button.h"
10 #include "ui/views/test/views_test_base.h"
11
12 namespace views {
13
14 namespace {
15
16 // An InkDropDelegate that keeps track of order of deletions.
17 class TestInkDropDelegate : public InkDropDelegate {
18 public:
19 TestInkDropDelegate(InkDropHost* ink_drop_host,
20 bool* ink_shown,
21 bool* ink_hidden)
22 : ink_drop_host_(ink_drop_host),
23 ink_shown_(ink_shown),
24 ink_hidden_(ink_hidden) {
25 ink_drop_host_->AddInkDropLayer(nullptr);
26 }
27 ~TestInkDropDelegate() override {}
28
29 // InkDropDelegate:
30 void SetInkDropSize(int large_size,
31 int large_corner_radius,
32 int small_size,
33 int small_corner_radius) override {}
34 void OnLayout() override {}
35 void OnAction(InkDropState state) override {
36 switch (state) {
37 case InkDropState::ACTION_PENDING:
38 case InkDropState::QUICK_ACTION:
39 case InkDropState::SLOW_ACTION_PENDING:
40 case InkDropState::SLOW_ACTION:
41 case InkDropState::ACTIVATED:
42 *ink_shown_ = true;
43 break;
44 case InkDropState::HIDDEN:
45 case InkDropState::DEACTIVATED:
46 *ink_hidden_ = true;
47 break;
48 }
49 }
50
51 private:
52 InkDropHost* ink_drop_host_;
53 bool* ink_shown_;
54 bool* ink_hidden_;
55
56 DISALLOW_COPY_AND_ASSIGN(TestInkDropDelegate);
57 };
58
59 // A test Button class that owns a TestInkDropDelegate.
60 class TestButton : public views::CustomButton, public views::InkDropHost {
61 public:
62 TestButton(bool* ink_shown, bool* ink_hidden)
63 : CustomButton(nullptr),
64 ink_drop_delegate_(
65 new TestInkDropDelegate(this, ink_shown, ink_hidden)) {
66 set_ink_drop_delegate(ink_drop_delegate_.get());
67 }
68 ~TestButton() override {}
69
70 // views::InkDropHost:
71 void AddInkDropLayer(ui::Layer* ink_drop_layer) override {}
72 void RemoveInkDropLayer(ui::Layer* ink_drop_layer) override {}
73 gfx::Point CalculateInkDropCenter() const override { return gfx::Point(); }
74
75 private:
76 scoped_ptr<views::InkDropDelegate> ink_drop_delegate_;
77
78 DISALLOW_COPY_AND_ASSIGN(TestButton);
79 };
80
81 } // namespace
82
83 class InkDropDelegateTest : public ViewsTestBase {
84 public:
85 InkDropDelegateTest() {}
86 ~InkDropDelegateTest() override {}
87
88 void TearDown() override {
89 if (widget_ && !widget_->IsClosed())
90 widget_->Close();
91 ViewsTestBase::TearDown();
92 }
93
94 Widget* widget() { return widget_; }
95 TestButton* button() { return button_; }
96
97 protected:
98 // Creates a MenuButton with no button listener.
99 void CreateTestButtons() { CreateButtons(); }
100
101 bool ink_shown() const { return ink_shown_; }
102 bool ink_hidden() const { return ink_hidden_; }
103
104 private:
105 void CreateButtons() {
106 CreateWidget();
107 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
108 button_->SetBounds(0, 0, 100, 100);
109 widget_->SetContentsView(button_);
110 widget_->Show();
111 }
112
113 void CreateWidget() {
114 DCHECK(!widget_);
115
116 widget_ = new Widget;
117 Widget::InitParams params =
118 CreateParams(Widget::InitParams::TYPE_WINDOW_FRAMELESS);
119 params.bounds = gfx::Rect(0, 0, 100, 100);
120 widget_->Init(params);
121 }
122
123 Widget* widget_ = nullptr;
124 TestButton* button_ = nullptr;
125 bool ink_shown_ = false;
126 bool ink_hidden_ = false;
127 };
128
129 // Tests that pressing a button shows the ink drop and releasing the button
130 // does not hide the ink drop.
131 // Note: Ink drop is not hidden upon release because CustomButton descendants
132 // may enter a different ink drop state.
133 TEST_F(InkDropDelegateTest, ButtonClickTogglesInkDrop) {
134 CreateTestButtons();
135
136 ui::test::EventGenerator generator(GetContext(), widget()->GetNativeWindow());
137 generator.set_current_location(gfx::Point(50, 50));
138 generator.PressLeftButton();
139 EXPECT_TRUE(ink_shown());
140 EXPECT_FALSE(ink_hidden());
141
142 generator.ReleaseLeftButton();
143 EXPECT_FALSE(ink_hidden());
144 }
145
146 // Tests that pressing a button shows and releasing capture hides ink drop.
147 TEST_F(InkDropDelegateTest, CaptureLossHidesInkDrop) {
148 CreateTestButtons();
149
150 ui::test::EventGenerator generator(GetContext(), widget()->GetNativeWindow());
151 generator.set_current_location(gfx::Point(50, 50));
152 generator.PressLeftButton();
153 EXPECT_TRUE(ink_shown());
154 EXPECT_FALSE(ink_hidden());
155
156 widget()->SetCapture(button());
157 widget()->ReleaseCapture();
158 EXPECT_TRUE(ink_hidden());
159 }
160
161 } // namespace views
OLDNEW
« 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