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

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

Issue 2734653002: chromeos: Move files in //ash/common to //ash (Closed)
Patch Set: fix a11y tests, fix docs 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 unified diff | Download patch
« no previous file with comments | « ash/common/shelf/shelf_tooltip_manager.cc ('k') | ash/common/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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "ash/common/shelf/shelf_tooltip_manager.h"
6
7 #include "ash/common/shelf/app_list_button.h"
8 #include "ash/common/shelf/shelf_model.h"
9 #include "ash/common/shelf/shelf_view.h"
10 #include "ash/common/shelf/wm_shelf.h"
11 #include "ash/common/test/test_shelf_item_delegate.h"
12 #include "ash/common/wm_shell.h"
13 #include "ash/test/ash_test_base.h"
14 #include "ash/test/shelf_view_test_api.h"
15 #include "base/memory/ptr_util.h"
16 #include "ui/events/event_constants.h"
17 #include "ui/events/test/event_generator.h"
18 #include "ui/views/bubble/bubble_dialog_delegate.h"
19 #include "ui/views/widget/widget.h"
20
21 namespace ash {
22 namespace test {
23
24 class ShelfTooltipManagerTest : public AshTestBase {
25 public:
26 ShelfTooltipManagerTest() {}
27 ~ShelfTooltipManagerTest() override {}
28
29 void SetUp() override {
30 AshTestBase::SetUp();
31 shelf_view_ = GetPrimaryShelf()->GetShelfViewForTesting();
32 tooltip_manager_ = test::ShelfViewTestAPI(shelf_view_).tooltip_manager();
33 tooltip_manager_->set_timer_delay_for_test(0);
34 }
35
36 bool IsTimerRunning() { return tooltip_manager_->timer_.IsRunning(); }
37 views::Widget* GetTooltip() { return tooltip_manager_->bubble_->GetWidget(); }
38
39 std::unique_ptr<views::Widget> CreateTestWidget() {
40 std::unique_ptr<views::Widget> widget = base::MakeUnique<views::Widget>();
41 views::Widget::InitParams params;
42 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
43 params.context = CurrentContext();
44 widget->Init(params);
45 widget->Show();
46 return widget;
47 }
48
49 protected:
50 ShelfView* shelf_view_;
51 ShelfTooltipManager* tooltip_manager_;
52
53 private:
54 DISALLOW_COPY_AND_ASSIGN(ShelfTooltipManagerTest);
55 };
56
57 TEST_F(ShelfTooltipManagerTest, ShowTooltip) {
58 tooltip_manager_->ShowTooltip(shelf_view_->GetAppListButton());
59 EXPECT_TRUE(tooltip_manager_->IsVisible());
60 EXPECT_FALSE(IsTimerRunning());
61 }
62
63 TEST_F(ShelfTooltipManagerTest, ShowTooltipWithDelay) {
64 // ShowTooltipWithDelay should start the timer instead of showing immediately.
65 tooltip_manager_->ShowTooltipWithDelay(shelf_view_->GetAppListButton());
66 EXPECT_FALSE(tooltip_manager_->IsVisible());
67 EXPECT_TRUE(IsTimerRunning());
68 // TODO: Test that the delayed tooltip is shown, without flaky failures.
69 }
70
71 TEST_F(ShelfTooltipManagerTest, DoNotShowForInvalidView) {
72 // The manager should not show or start the timer for a null view.
73 tooltip_manager_->ShowTooltip(nullptr);
74 EXPECT_FALSE(tooltip_manager_->IsVisible());
75 tooltip_manager_->ShowTooltipWithDelay(nullptr);
76 EXPECT_FALSE(IsTimerRunning());
77
78 // The manager should not show or start the timer for a non-shelf view.
79 views::View view;
80 tooltip_manager_->ShowTooltip(&view);
81 EXPECT_FALSE(tooltip_manager_->IsVisible());
82 tooltip_manager_->ShowTooltipWithDelay(&view);
83 EXPECT_FALSE(IsTimerRunning());
84
85 // The manager should start the timer for a view on the shelf.
86 ShelfModel* model = shelf_view_->model();
87 ShelfItem item;
88 item.type = TYPE_APP_SHORTCUT;
89 const int index = model->Add(item);
90 const ShelfID id = model->items()[index].id;
91 model->SetShelfItemDelegate(id,
92 base::MakeUnique<TestShelfItemDelegate>(nullptr));
93 // Note: There's no easy way to correlate shelf a model index/id to its view.
94 tooltip_manager_->ShowTooltipWithDelay(
95 shelf_view_->child_at(shelf_view_->child_count() - 1));
96 EXPECT_TRUE(IsTimerRunning());
97
98 // Removing the view won't stop the timer, but the tooltip shouldn't be shown.
99 model->RemoveItemAt(index);
100 EXPECT_TRUE(IsTimerRunning());
101 RunAllPendingInMessageLoop();
102 EXPECT_FALSE(IsTimerRunning());
103 EXPECT_FALSE(tooltip_manager_->IsVisible());
104 }
105
106 TEST_F(ShelfTooltipManagerTest, HideWhenShelfIsHidden) {
107 tooltip_manager_->ShowTooltip(shelf_view_->GetAppListButton());
108 ASSERT_TRUE(tooltip_manager_->IsVisible());
109
110 // Create a full-screen window to hide the shelf.
111 std::unique_ptr<views::Widget> widget = CreateTestWidget();
112 widget->SetFullscreen(true);
113
114 // Once the shelf is hidden, the tooltip should be invisible.
115 ASSERT_EQ(SHELF_HIDDEN, GetPrimaryShelf()->GetVisibilityState());
116 EXPECT_FALSE(tooltip_manager_->IsVisible());
117
118 // Do not show the view if the shelf is hidden.
119 tooltip_manager_->ShowTooltip(shelf_view_->GetAppListButton());
120 EXPECT_FALSE(tooltip_manager_->IsVisible());
121
122 // ShowTooltipWithDelay doesn't even start the timer for the hidden shelf.
123 tooltip_manager_->ShowTooltipWithDelay(shelf_view_->GetAppListButton());
124 EXPECT_FALSE(IsTimerRunning());
125 }
126
127 TEST_F(ShelfTooltipManagerTest, HideWhenShelfIsAutoHideHidden) {
128 // Create a visible window so auto-hide behavior can actually hide the shelf.
129 std::unique_ptr<views::Widget> widget = CreateTestWidget();
130 tooltip_manager_->ShowTooltip(shelf_view_->GetAppListButton());
131 ASSERT_TRUE(tooltip_manager_->IsVisible());
132
133 GetPrimaryShelf()->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
134 GetPrimaryShelf()->UpdateAutoHideState();
135 ASSERT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS,
136 GetPrimaryShelf()->auto_hide_behavior());
137 ASSERT_EQ(SHELF_AUTO_HIDE_HIDDEN, GetPrimaryShelf()->GetAutoHideState());
138
139 // Tooltip visibility change for auto hide may take time.
140 EXPECT_TRUE(tooltip_manager_->IsVisible());
141 RunAllPendingInMessageLoop();
142 EXPECT_FALSE(tooltip_manager_->IsVisible());
143
144 // Do not show the view if the shelf is hidden.
145 tooltip_manager_->ShowTooltip(shelf_view_->GetAppListButton());
146 EXPECT_FALSE(tooltip_manager_->IsVisible());
147
148 // ShowTooltipWithDelay doesn't even run the timer for the hidden shelf.
149 tooltip_manager_->ShowTooltipWithDelay(shelf_view_->GetAppListButton());
150 EXPECT_FALSE(IsTimerRunning());
151
152 // Close the window to show the auto-hide shelf; tooltips should now show.
153 widget.reset();
154 GetPrimaryShelf()->UpdateAutoHideState();
155 ASSERT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS,
156 GetPrimaryShelf()->auto_hide_behavior());
157 ASSERT_EQ(SHELF_AUTO_HIDE_SHOWN, GetPrimaryShelf()->GetAutoHideState());
158
159 // The tooltip should show for an auto-hide-shown shelf.
160 tooltip_manager_->ShowTooltip(shelf_view_->GetAppListButton());
161 EXPECT_TRUE(tooltip_manager_->IsVisible());
162
163 // ShowTooltipWithDelay should run the timer for an auto-hide-shown shelf.
164 tooltip_manager_->ShowTooltipWithDelay(shelf_view_->GetAppListButton());
165 EXPECT_TRUE(IsTimerRunning());
166 }
167
168 TEST_F(ShelfTooltipManagerTest, HideForEvents) {
169 // TODO: investigate failure in mash. http://crbug.com/695563.
170 if (WmShell::Get()->IsRunningInMash())
171 return;
172
173 ui::test::EventGenerator& generator = GetEventGenerator();
174 gfx::Rect shelf_bounds = shelf_view_->GetBoundsInScreen();
175
176 // Should hide if the mouse exits the shelf area.
177 tooltip_manager_->ShowTooltip(shelf_view_->GetAppListButton());
178 ASSERT_TRUE(tooltip_manager_->IsVisible());
179 generator.MoveMouseTo(shelf_bounds.CenterPoint());
180 generator.SendMouseExit();
181 EXPECT_FALSE(tooltip_manager_->IsVisible());
182
183 // Should hide if the mouse is pressed in the shelf area.
184 tooltip_manager_->ShowTooltip(shelf_view_->GetAppListButton());
185 ASSERT_TRUE(tooltip_manager_->IsVisible());
186 generator.MoveMouseTo(shelf_bounds.CenterPoint());
187 generator.PressLeftButton();
188 EXPECT_FALSE(tooltip_manager_->IsVisible());
189
190 // Should hide for touch events in the shelf.
191 tooltip_manager_->ShowTooltip(shelf_view_->GetAppListButton());
192 ASSERT_TRUE(tooltip_manager_->IsVisible());
193 generator.set_current_location(shelf_bounds.CenterPoint());
194 generator.PressTouch();
195 EXPECT_FALSE(tooltip_manager_->IsVisible());
196
197 // Should hide for gesture events in the shelf.
198 tooltip_manager_->ShowTooltip(shelf_view_->GetAppListButton());
199 ASSERT_TRUE(tooltip_manager_->IsVisible());
200 generator.GestureTapDownAndUp(shelf_bounds.CenterPoint());
201 EXPECT_FALSE(tooltip_manager_->IsVisible());
202 }
203
204 TEST_F(ShelfTooltipManagerTest, HideForExternalEvents) {
205 // TODO: investigate failure in mash. http://crbug.com/695563.
206 if (WmShell::Get()->IsRunningInMash())
207 return;
208
209 ui::test::EventGenerator& generator = GetEventGenerator();
210
211 // Should hide for touches outside the shelf.
212 tooltip_manager_->ShowTooltip(shelf_view_->GetAppListButton());
213 ASSERT_TRUE(tooltip_manager_->IsVisible());
214 generator.set_current_location(gfx::Point());
215 generator.PressTouch();
216 EXPECT_FALSE(tooltip_manager_->IsVisible());
217 generator.ReleaseTouch();
218
219 // Should hide for touch events on the tooltip.
220 tooltip_manager_->ShowTooltip(shelf_view_->GetAppListButton());
221 ASSERT_TRUE(tooltip_manager_->IsVisible());
222 generator.set_current_location(
223 GetTooltip()->GetWindowBoundsInScreen().CenterPoint());
224 generator.PressTouch();
225 EXPECT_FALSE(tooltip_manager_->IsVisible());
226 generator.ReleaseTouch();
227
228 // Should hide for gestures outside the shelf.
229 tooltip_manager_->ShowTooltip(shelf_view_->GetAppListButton());
230 ASSERT_TRUE(tooltip_manager_->IsVisible());
231 generator.GestureTapDownAndUp(gfx::Point());
232 EXPECT_FALSE(tooltip_manager_->IsVisible());
233 }
234
235 TEST_F(ShelfTooltipManagerTest, DoNotHideForKeyEvents) {
236 ui::test::EventGenerator& generator = GetEventGenerator();
237
238 // Should not hide for key events.
239 tooltip_manager_->ShowTooltip(shelf_view_->GetAppListButton());
240 ASSERT_TRUE(tooltip_manager_->IsVisible());
241 generator.PressKey(ui::VKEY_A, ui::EF_NONE);
242 EXPECT_TRUE(tooltip_manager_->IsVisible());
243 }
244
245 } // namespace test
246 } // namespace ash
OLDNEW
« no previous file with comments | « ash/common/shelf/shelf_tooltip_manager.cc ('k') | ash/common/shelf/shelf_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698