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

Side by Side Diff: ash/shelf/shelf_tooltip_manager_unittest.cc

Issue 2070143003: Add MD ink drop ripple to app list button (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@b612539_shelf_button_ripple
Patch Set: Rebased Created 4 years, 5 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 | « ash/shelf/shelf_button.cc ('k') | ash/shelf/shelf_view.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ash/shelf/shelf_tooltip_manager.h" 5 #include "ash/shelf/shelf_tooltip_manager.h"
6 6
7 #include "ash/common/shelf/shelf_item_delegate_manager.h" 7 #include "ash/common/shelf/shelf_item_delegate_manager.h"
8 #include "ash/common/shelf/shelf_model.h" 8 #include "ash/common/shelf/shelf_model.h"
9 #include "ash/shelf/app_list_button.h"
9 #include "ash/shelf/shelf_layout_manager.h" 10 #include "ash/shelf/shelf_layout_manager.h"
10 #include "ash/shelf/shelf_view.h" 11 #include "ash/shelf/shelf_view.h"
11 #include "ash/shelf/shelf_widget.h" 12 #include "ash/shelf/shelf_widget.h"
12 #include "ash/shell.h" 13 #include "ash/shell.h"
13 #include "ash/test/ash_test_base.h" 14 #include "ash/test/ash_test_base.h"
14 #include "ash/test/shelf_test_api.h" 15 #include "ash/test/shelf_test_api.h"
15 #include "ash/test/shelf_view_test_api.h" 16 #include "ash/test/shelf_view_test_api.h"
16 #include "ash/test/test_shelf_item_delegate.h" 17 #include "ash/test/test_shelf_item_delegate.h"
17 #include "base/memory/ptr_util.h" 18 #include "base/memory/ptr_util.h"
18 #include "ui/events/event_constants.h" 19 #include "ui/events/event_constants.h"
(...skipping 23 matching lines...) Expand all
42 protected: 43 protected:
43 Shelf* shelf_; 44 Shelf* shelf_;
44 ShelfView* shelf_view_; 45 ShelfView* shelf_view_;
45 ShelfTooltipManager* tooltip_manager_; 46 ShelfTooltipManager* tooltip_manager_;
46 47
47 private: 48 private:
48 DISALLOW_COPY_AND_ASSIGN(ShelfTooltipManagerTest); 49 DISALLOW_COPY_AND_ASSIGN(ShelfTooltipManagerTest);
49 }; 50 };
50 51
51 TEST_F(ShelfTooltipManagerTest, ShowTooltip) { 52 TEST_F(ShelfTooltipManagerTest, ShowTooltip) {
52 tooltip_manager_->ShowTooltip(shelf_->GetAppListButtonView()); 53 tooltip_manager_->ShowTooltip(shelf_->GetAppListButton());
53 EXPECT_TRUE(tooltip_manager_->IsVisible()); 54 EXPECT_TRUE(tooltip_manager_->IsVisible());
54 EXPECT_FALSE(IsTimerRunning()); 55 EXPECT_FALSE(IsTimerRunning());
55 } 56 }
56 57
57 TEST_F(ShelfTooltipManagerTest, ShowTooltipWithDelay) { 58 TEST_F(ShelfTooltipManagerTest, ShowTooltipWithDelay) {
58 // ShowTooltipWithDelay should start the timer instead of showing immediately. 59 // ShowTooltipWithDelay should start the timer instead of showing immediately.
59 tooltip_manager_->ShowTooltipWithDelay(shelf_->GetAppListButtonView()); 60 tooltip_manager_->ShowTooltipWithDelay(shelf_->GetAppListButton());
60 EXPECT_FALSE(tooltip_manager_->IsVisible()); 61 EXPECT_FALSE(tooltip_manager_->IsVisible());
61 EXPECT_TRUE(IsTimerRunning()); 62 EXPECT_TRUE(IsTimerRunning());
62 RunAllPendingInMessageLoop(); 63 RunAllPendingInMessageLoop();
63 #if !defined(OS_WIN) 64 #if !defined(OS_WIN)
64 // This check fails on Windows. 65 // This check fails on Windows.
65 EXPECT_TRUE(tooltip_manager_->IsVisible()); 66 EXPECT_TRUE(tooltip_manager_->IsVisible());
66 #endif // !OS_WIN 67 #endif // !OS_WIN
67 EXPECT_FALSE(IsTimerRunning()); 68 EXPECT_FALSE(IsTimerRunning());
68 } 69 }
69 70
(...skipping 26 matching lines...) Expand all
96 97
97 // Removing the view won't stop the timer, but the tooltip shouldn't be shown. 98 // Removing the view won't stop the timer, but the tooltip shouldn't be shown.
98 model->RemoveItemAt(index); 99 model->RemoveItemAt(index);
99 EXPECT_TRUE(IsTimerRunning()); 100 EXPECT_TRUE(IsTimerRunning());
100 RunAllPendingInMessageLoop(); 101 RunAllPendingInMessageLoop();
101 EXPECT_FALSE(IsTimerRunning()); 102 EXPECT_FALSE(IsTimerRunning());
102 EXPECT_FALSE(tooltip_manager_->IsVisible()); 103 EXPECT_FALSE(tooltip_manager_->IsVisible());
103 } 104 }
104 105
105 TEST_F(ShelfTooltipManagerTest, HideWhenShelfIsHidden) { 106 TEST_F(ShelfTooltipManagerTest, HideWhenShelfIsHidden) {
106 tooltip_manager_->ShowTooltip(shelf_->GetAppListButtonView()); 107 tooltip_manager_->ShowTooltip(shelf_->GetAppListButton());
107 ASSERT_TRUE(tooltip_manager_->IsVisible()); 108 ASSERT_TRUE(tooltip_manager_->IsVisible());
108 109
109 // Create a full-screen window to hide the shelf. 110 // Create a full-screen window to hide the shelf.
110 std::unique_ptr<views::Widget> widget(new views::Widget); 111 std::unique_ptr<views::Widget> widget(new views::Widget);
111 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); 112 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW);
112 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; 113 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
113 params.context = CurrentContext(); 114 params.context = CurrentContext();
114 widget->Init(params); 115 widget->Init(params);
115 widget->SetFullscreen(true); 116 widget->SetFullscreen(true);
116 widget->Show(); 117 widget->Show();
117 118
118 // Once the shelf is hidden, the tooltip should be invisible. 119 // Once the shelf is hidden, the tooltip should be invisible.
119 ASSERT_EQ(SHELF_HIDDEN, shelf_->shelf_layout_manager()->visibility_state()); 120 ASSERT_EQ(SHELF_HIDDEN, shelf_->shelf_layout_manager()->visibility_state());
120 EXPECT_FALSE(tooltip_manager_->IsVisible()); 121 EXPECT_FALSE(tooltip_manager_->IsVisible());
121 122
122 // Do not show the view if the shelf is hidden. 123 // Do not show the view if the shelf is hidden.
123 tooltip_manager_->ShowTooltip(shelf_->GetAppListButtonView()); 124 tooltip_manager_->ShowTooltip(shelf_->GetAppListButton());
124 EXPECT_FALSE(tooltip_manager_->IsVisible()); 125 EXPECT_FALSE(tooltip_manager_->IsVisible());
125 126
126 // ShowTooltipWithDelay doesn't even start the timer for the hidden shelf. 127 // ShowTooltipWithDelay doesn't even start the timer for the hidden shelf.
127 tooltip_manager_->ShowTooltipWithDelay(shelf_->GetAppListButtonView()); 128 tooltip_manager_->ShowTooltipWithDelay(shelf_->GetAppListButton());
128 EXPECT_FALSE(IsTimerRunning()); 129 EXPECT_FALSE(IsTimerRunning());
129 } 130 }
130 131
131 TEST_F(ShelfTooltipManagerTest, HideWhenShelfIsAutoHide) { 132 TEST_F(ShelfTooltipManagerTest, HideWhenShelfIsAutoHide) {
132 // Create a visible window so auto-hide behavior is enforced. 133 // Create a visible window so auto-hide behavior is enforced.
133 views::Widget* dummy = new views::Widget; 134 views::Widget* dummy = new views::Widget;
134 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); 135 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW);
135 params.bounds = gfx::Rect(0, 0, 200, 200); 136 params.bounds = gfx::Rect(0, 0, 200, 200);
136 params.context = CurrentContext(); 137 params.context = CurrentContext();
137 dummy->Init(params); 138 dummy->Init(params);
138 dummy->Show(); 139 dummy->Show();
139 140
140 tooltip_manager_->ShowTooltip(shelf_->GetAppListButtonView()); 141 tooltip_manager_->ShowTooltip(shelf_->GetAppListButton());
141 ASSERT_TRUE(tooltip_manager_->IsVisible()); 142 ASSERT_TRUE(tooltip_manager_->IsVisible());
142 143
143 shelf_->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); 144 shelf_->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
144 shelf_->shelf_layout_manager()->UpdateAutoHideState(); 145 shelf_->shelf_layout_manager()->UpdateAutoHideState();
145 ASSERT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf_->GetAutoHideState()); 146 ASSERT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf_->GetAutoHideState());
146 147
147 // Tooltip visibility change for auto hide may take time. 148 // Tooltip visibility change for auto hide may take time.
148 EXPECT_TRUE(tooltip_manager_->IsVisible()); 149 EXPECT_TRUE(tooltip_manager_->IsVisible());
149 RunAllPendingInMessageLoop(); 150 RunAllPendingInMessageLoop();
150 EXPECT_FALSE(tooltip_manager_->IsVisible()); 151 EXPECT_FALSE(tooltip_manager_->IsVisible());
151 152
152 // Do not show the view if the shelf is hidden. 153 // Do not show the view if the shelf is hidden.
153 tooltip_manager_->ShowTooltip(shelf_->GetAppListButtonView()); 154 tooltip_manager_->ShowTooltip(shelf_->GetAppListButton());
154 EXPECT_FALSE(tooltip_manager_->IsVisible()); 155 EXPECT_FALSE(tooltip_manager_->IsVisible());
155 156
156 // ShowTooltipWithDelay doesn't even run the timer for the hidden shelf. 157 // ShowTooltipWithDelay doesn't even run the timer for the hidden shelf.
157 tooltip_manager_->ShowTooltipWithDelay(shelf_->GetAppListButtonView()); 158 tooltip_manager_->ShowTooltipWithDelay(shelf_->GetAppListButton());
158 EXPECT_FALSE(IsTimerRunning()); 159 EXPECT_FALSE(IsTimerRunning());
159 } 160 }
160 161
161 TEST_F(ShelfTooltipManagerTest, HideForEvents) { 162 TEST_F(ShelfTooltipManagerTest, HideForEvents) {
162 ui::test::EventGenerator& generator = GetEventGenerator(); 163 ui::test::EventGenerator& generator = GetEventGenerator();
163 gfx::Rect shelf_bounds = shelf_->shelf_widget()->GetNativeWindow()->bounds(); 164 gfx::Rect shelf_bounds = shelf_->shelf_widget()->GetNativeWindow()->bounds();
164 165
165 // Should hide if the mouse exits the shelf area. 166 // Should hide if the mouse exits the shelf area.
166 tooltip_manager_->ShowTooltip(shelf_->GetAppListButtonView()); 167 tooltip_manager_->ShowTooltip(shelf_->GetAppListButton());
167 ASSERT_TRUE(tooltip_manager_->IsVisible()); 168 ASSERT_TRUE(tooltip_manager_->IsVisible());
168 generator.MoveMouseTo(shelf_bounds.CenterPoint()); 169 generator.MoveMouseTo(shelf_bounds.CenterPoint());
169 generator.SendMouseExit(); 170 generator.SendMouseExit();
170 EXPECT_FALSE(tooltip_manager_->IsVisible()); 171 EXPECT_FALSE(tooltip_manager_->IsVisible());
171 172
172 // Should hide if the mouse is pressed in the shelf area. 173 // Should hide if the mouse is pressed in the shelf area.
173 tooltip_manager_->ShowTooltip(shelf_->GetAppListButtonView()); 174 tooltip_manager_->ShowTooltip(shelf_->GetAppListButton());
174 ASSERT_TRUE(tooltip_manager_->IsVisible()); 175 ASSERT_TRUE(tooltip_manager_->IsVisible());
175 generator.MoveMouseTo(shelf_bounds.CenterPoint()); 176 generator.MoveMouseTo(shelf_bounds.CenterPoint());
176 generator.PressLeftButton(); 177 generator.PressLeftButton();
177 EXPECT_FALSE(tooltip_manager_->IsVisible()); 178 EXPECT_FALSE(tooltip_manager_->IsVisible());
178 179
179 // Should hide for touch events in the shelf. 180 // Should hide for touch events in the shelf.
180 tooltip_manager_->ShowTooltip(shelf_->GetAppListButtonView()); 181 tooltip_manager_->ShowTooltip(shelf_->GetAppListButton());
181 ASSERT_TRUE(tooltip_manager_->IsVisible()); 182 ASSERT_TRUE(tooltip_manager_->IsVisible());
182 generator.set_current_location(shelf_bounds.CenterPoint()); 183 generator.set_current_location(shelf_bounds.CenterPoint());
183 generator.PressTouch(); 184 generator.PressTouch();
184 EXPECT_FALSE(tooltip_manager_->IsVisible()); 185 EXPECT_FALSE(tooltip_manager_->IsVisible());
185 186
186 // Should hide for gesture events in the shelf. 187 // Should hide for gesture events in the shelf.
187 tooltip_manager_->ShowTooltip(shelf_->GetAppListButtonView()); 188 tooltip_manager_->ShowTooltip(shelf_->GetAppListButton());
188 ASSERT_TRUE(tooltip_manager_->IsVisible()); 189 ASSERT_TRUE(tooltip_manager_->IsVisible());
189 generator.GestureTapDownAndUp(shelf_bounds.CenterPoint()); 190 generator.GestureTapDownAndUp(shelf_bounds.CenterPoint());
190 EXPECT_FALSE(tooltip_manager_->IsVisible()); 191 EXPECT_FALSE(tooltip_manager_->IsVisible());
191 } 192 }
192 193
193 TEST_F(ShelfTooltipManagerTest, HideForExternalEvents) { 194 TEST_F(ShelfTooltipManagerTest, HideForExternalEvents) {
194 ui::test::EventGenerator& generator = GetEventGenerator(); 195 ui::test::EventGenerator& generator = GetEventGenerator();
195 // TODO(msw): Observe events outside the shelf in mash, to close tooltips. 196 // TODO(msw): Observe events outside the shelf in mash, to close tooltips.
196 aura::Window* shelf_window = shelf_->shelf_widget()->GetNativeWindow(); 197 aura::Window* shelf_window = shelf_->shelf_widget()->GetNativeWindow();
197 bool closes = shelf_window->GetRootWindow() == Shell::GetPrimaryRootWindow(); 198 bool closes = shelf_window->GetRootWindow() == Shell::GetPrimaryRootWindow();
198 199
199 // Should hide for touches outside the shelf. 200 // Should hide for touches outside the shelf.
200 tooltip_manager_->ShowTooltip(shelf_->GetAppListButtonView()); 201 tooltip_manager_->ShowTooltip(shelf_->GetAppListButton());
201 ASSERT_TRUE(tooltip_manager_->IsVisible()); 202 ASSERT_TRUE(tooltip_manager_->IsVisible());
202 generator.set_current_location(gfx::Point()); 203 generator.set_current_location(gfx::Point());
203 generator.PressTouch(); 204 generator.PressTouch();
204 EXPECT_EQ(tooltip_manager_->IsVisible(), !closes); 205 EXPECT_EQ(tooltip_manager_->IsVisible(), !closes);
205 generator.ReleaseTouch(); 206 generator.ReleaseTouch();
206 207
207 // Should hide for touch events on the tooltip. 208 // Should hide for touch events on the tooltip.
208 tooltip_manager_->ShowTooltip(shelf_->GetAppListButtonView()); 209 tooltip_manager_->ShowTooltip(shelf_->GetAppListButton());
209 ASSERT_TRUE(tooltip_manager_->IsVisible()); 210 ASSERT_TRUE(tooltip_manager_->IsVisible());
210 generator.set_current_location( 211 generator.set_current_location(
211 GetTooltip()->GetWindowBoundsInScreen().CenterPoint()); 212 GetTooltip()->GetWindowBoundsInScreen().CenterPoint());
212 generator.PressTouch(); 213 generator.PressTouch();
213 EXPECT_EQ(tooltip_manager_->IsVisible(), !closes); 214 EXPECT_EQ(tooltip_manager_->IsVisible(), !closes);
214 generator.ReleaseTouch(); 215 generator.ReleaseTouch();
215 216
216 // Should hide for gestures outside the shelf. 217 // Should hide for gestures outside the shelf.
217 tooltip_manager_->ShowTooltip(shelf_->GetAppListButtonView()); 218 tooltip_manager_->ShowTooltip(shelf_->GetAppListButton());
218 ASSERT_TRUE(tooltip_manager_->IsVisible()); 219 ASSERT_TRUE(tooltip_manager_->IsVisible());
219 generator.GestureTapDownAndUp(gfx::Point()); 220 generator.GestureTapDownAndUp(gfx::Point());
220 EXPECT_EQ(tooltip_manager_->IsVisible(), !closes); 221 EXPECT_EQ(tooltip_manager_->IsVisible(), !closes);
221 } 222 }
222 223
223 TEST_F(ShelfTooltipManagerTest, DoNotHideForKeyEvents) { 224 TEST_F(ShelfTooltipManagerTest, DoNotHideForKeyEvents) {
224 ui::test::EventGenerator& generator = GetEventGenerator(); 225 ui::test::EventGenerator& generator = GetEventGenerator();
225 226
226 // Should not hide for key events. 227 // Should not hide for key events.
227 tooltip_manager_->ShowTooltip(shelf_->GetAppListButtonView()); 228 tooltip_manager_->ShowTooltip(shelf_->GetAppListButton());
228 ASSERT_TRUE(tooltip_manager_->IsVisible()); 229 ASSERT_TRUE(tooltip_manager_->IsVisible());
229 generator.PressKey(ui::VKEY_A, ui::EF_NONE); 230 generator.PressKey(ui::VKEY_A, ui::EF_NONE);
230 EXPECT_TRUE(tooltip_manager_->IsVisible()); 231 EXPECT_TRUE(tooltip_manager_->IsVisible());
231 } 232 }
232 233
233 } // namespace test 234 } // namespace test
234 } // namespace ash 235 } // namespace ash
OLDNEW
« no previous file with comments | « ash/shelf/shelf_button.cc ('k') | ash/shelf/shelf_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698