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

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

Powered by Google App Engine
This is Rietveld 408576698