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

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

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

Powered by Google App Engine
This is Rietveld 408576698