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

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

Issue 2176813002: mash: Migrate ShelfTooltipManager to wm common types. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update comment. 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/shelf/shelf_tooltip_manager.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/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/shelf/shelf_layout_manager.h" 9 #include "ash/common/shelf/wm_shelf.h"
10 #include "ash/common/wm_shell.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/shell.h" 12 #include "ash/shell.h"
13 #include "ash/test/ash_test_base.h" 13 #include "ash/test/ash_test_base.h"
14 #include "ash/test/shelf_test_api.h" 14 #include "ash/test/shelf_test_api.h"
15 #include "ash/test/shelf_view_test_api.h" 15 #include "ash/test/shelf_view_test_api.h"
16 #include "ash/test/test_shelf_item_delegate.h" 16 #include "ash/test/test_shelf_item_delegate.h"
17 #include "base/memory/ptr_util.h" 17 #include "base/memory/ptr_util.h"
18 #include "ui/events/event_constants.h" 18 #include "ui/events/event_constants.h"
19 #include "ui/events/test/event_generator.h" 19 #include "ui/events/test/event_generator.h"
20 #include "ui/views/bubble/bubble_dialog_delegate.h" 20 #include "ui/views/bubble/bubble_dialog_delegate.h"
21 #include "ui/views/widget/widget.h" 21 #include "ui/views/widget/widget.h"
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 EXPECT_FALSE(IsTimerRunning()); 70 EXPECT_FALSE(IsTimerRunning());
71 71
72 // The manager should not show or start the timer for a non-shelf view. 72 // The manager should not show or start the timer for a non-shelf view.
73 views::View view; 73 views::View view;
74 tooltip_manager_->ShowTooltip(&view); 74 tooltip_manager_->ShowTooltip(&view);
75 EXPECT_FALSE(tooltip_manager_->IsVisible()); 75 EXPECT_FALSE(tooltip_manager_->IsVisible());
76 tooltip_manager_->ShowTooltipWithDelay(&view); 76 tooltip_manager_->ShowTooltipWithDelay(&view);
77 EXPECT_FALSE(IsTimerRunning()); 77 EXPECT_FALSE(IsTimerRunning());
78 78
79 // The manager should start the timer for a view on the shelf. 79 // The manager should start the timer for a view on the shelf.
80 ShelfModel* model = shelf_view_->model(); 80 ShelfModel* model = WmShell::Get()->shelf_model();
81 ShelfItem item; 81 ShelfItem item;
82 item.type = TYPE_APP_SHORTCUT; 82 item.type = TYPE_APP_SHORTCUT;
83 const int index = model->Add(item); 83 const int index = model->Add(item);
84 const ShelfID id = model->items()[index].id; 84 const ShelfID id = model->items()[index].id;
85 model->SetShelfItemDelegate( 85 model->SetShelfItemDelegate(
86 id, base::WrapUnique(new TestShelfItemDelegate(nullptr))); 86 id, base::WrapUnique(new TestShelfItemDelegate(nullptr)));
87 // Note: There's no easy way to correlate shelf a model index/id to its view. 87 // Note: There's no easy way to correlate shelf a model index/id to its view.
88 tooltip_manager_->ShowTooltipWithDelay( 88 tooltip_manager_->ShowTooltipWithDelay(
89 shelf_view_->child_at(shelf_view_->child_count() - 1)); 89 shelf_view_->child_at(shelf_view_->child_count() - 1));
90 EXPECT_TRUE(IsTimerRunning()); 90 EXPECT_TRUE(IsTimerRunning());
(...skipping 13 matching lines...) Expand all
104 // Create a full-screen window to hide the shelf. 104 // Create a full-screen window to hide the shelf.
105 std::unique_ptr<views::Widget> widget(new views::Widget); 105 std::unique_ptr<views::Widget> widget(new views::Widget);
106 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); 106 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW);
107 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; 107 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
108 params.context = CurrentContext(); 108 params.context = CurrentContext();
109 widget->Init(params); 109 widget->Init(params);
110 widget->SetFullscreen(true); 110 widget->SetFullscreen(true);
111 widget->Show(); 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, shelf_->shelf_layout_manager()->visibility_state()); 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_->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_->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 views::Widget* dummy = new views::Widget;
129 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); 129 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW);
130 params.bounds = gfx::Rect(0, 0, 200, 200); 130 params.bounds = gfx::Rect(0, 0, 200, 200);
131 params.context = CurrentContext(); 131 params.context = CurrentContext();
132 dummy->Init(params); 132 dummy->Init(params);
133 dummy->Show(); 133 dummy->Show();
134 134
135 tooltip_manager_->ShowTooltip(shelf_->GetAppListButton()); 135 tooltip_manager_->ShowTooltip(shelf_->GetAppListButton());
136 ASSERT_TRUE(tooltip_manager_->IsVisible()); 136 ASSERT_TRUE(tooltip_manager_->IsVisible());
137 137
138 shelf_->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); 138 GetPrimaryShelf()->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
139 shelf_->shelf_layout_manager()->UpdateAutoHideState(); 139 GetPrimaryShelf()->UpdateAutoHideState();
140 ASSERT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf_->GetAutoHideState()); 140 ASSERT_EQ(SHELF_AUTO_HIDE_HIDDEN, GetPrimaryShelf()->GetAutoHideState());
141 141
142 // Tooltip visibility change for auto hide may take time. 142 // Tooltip visibility change for auto hide may take time.
143 EXPECT_TRUE(tooltip_manager_->IsVisible()); 143 EXPECT_TRUE(tooltip_manager_->IsVisible());
144 RunAllPendingInMessageLoop(); 144 RunAllPendingInMessageLoop();
145 EXPECT_FALSE(tooltip_manager_->IsVisible()); 145 EXPECT_FALSE(tooltip_manager_->IsVisible());
146 146
147 // Do not show the view if the shelf is hidden. 147 // Do not show the view if the shelf is hidden.
148 tooltip_manager_->ShowTooltip(shelf_->GetAppListButton()); 148 tooltip_manager_->ShowTooltip(shelf_->GetAppListButton());
149 EXPECT_FALSE(tooltip_manager_->IsVisible()); 149 EXPECT_FALSE(tooltip_manager_->IsVisible());
150 150
151 // ShowTooltipWithDelay doesn't even run the timer for the hidden shelf. 151 // ShowTooltipWithDelay doesn't even run the timer for the hidden shelf.
152 tooltip_manager_->ShowTooltipWithDelay(shelf_->GetAppListButton()); 152 tooltip_manager_->ShowTooltipWithDelay(shelf_->GetAppListButton());
153 EXPECT_FALSE(IsTimerRunning()); 153 EXPECT_FALSE(IsTimerRunning());
154 } 154 }
155 155
156 TEST_F(ShelfTooltipManagerTest, HideForEvents) { 156 TEST_F(ShelfTooltipManagerTest, HideForEvents) {
157 ui::test::EventGenerator& generator = GetEventGenerator(); 157 ui::test::EventGenerator& generator = GetEventGenerator();
158 gfx::Rect shelf_bounds = shelf_->shelf_widget()->GetNativeWindow()->bounds(); 158 gfx::Rect shelf_bounds = shelf_view_->GetBoundsInScreen();
159 159
160 // Should hide if the mouse exits the shelf area. 160 // Should hide if the mouse exits the shelf area.
161 tooltip_manager_->ShowTooltip(shelf_->GetAppListButton()); 161 tooltip_manager_->ShowTooltip(shelf_->GetAppListButton());
162 ASSERT_TRUE(tooltip_manager_->IsVisible()); 162 ASSERT_TRUE(tooltip_manager_->IsVisible());
163 generator.MoveMouseTo(shelf_bounds.CenterPoint()); 163 generator.MoveMouseTo(shelf_bounds.CenterPoint());
164 generator.SendMouseExit(); 164 generator.SendMouseExit();
165 EXPECT_FALSE(tooltip_manager_->IsVisible()); 165 EXPECT_FALSE(tooltip_manager_->IsVisible());
166 166
167 // Should hide if the mouse is pressed in the shelf area. 167 // Should hide if the mouse is pressed in the shelf area.
168 tooltip_manager_->ShowTooltip(shelf_->GetAppListButton()); 168 tooltip_manager_->ShowTooltip(shelf_->GetAppListButton());
(...skipping 11 matching lines...) Expand all
180 180
181 // Should hide for gesture events in the shelf. 181 // Should hide for gesture events in the shelf.
182 tooltip_manager_->ShowTooltip(shelf_->GetAppListButton()); 182 tooltip_manager_->ShowTooltip(shelf_->GetAppListButton());
183 ASSERT_TRUE(tooltip_manager_->IsVisible()); 183 ASSERT_TRUE(tooltip_manager_->IsVisible());
184 generator.GestureTapDownAndUp(shelf_bounds.CenterPoint()); 184 generator.GestureTapDownAndUp(shelf_bounds.CenterPoint());
185 EXPECT_FALSE(tooltip_manager_->IsVisible()); 185 EXPECT_FALSE(tooltip_manager_->IsVisible());
186 } 186 }
187 187
188 TEST_F(ShelfTooltipManagerTest, HideForExternalEvents) { 188 TEST_F(ShelfTooltipManagerTest, HideForExternalEvents) {
189 ui::test::EventGenerator& generator = GetEventGenerator(); 189 ui::test::EventGenerator& generator = GetEventGenerator();
190 // TODO(msw): Observe events outside the shelf in mash, to close tooltips.
191 aura::Window* shelf_window = shelf_->shelf_widget()->GetNativeWindow();
192 bool closes = shelf_window->GetRootWindow() == Shell::GetPrimaryRootWindow();
193 190
194 // Should hide for touches outside the shelf. 191 // Should hide for touches outside the shelf.
195 tooltip_manager_->ShowTooltip(shelf_->GetAppListButton()); 192 tooltip_manager_->ShowTooltip(shelf_->GetAppListButton());
196 ASSERT_TRUE(tooltip_manager_->IsVisible()); 193 ASSERT_TRUE(tooltip_manager_->IsVisible());
197 generator.set_current_location(gfx::Point()); 194 generator.set_current_location(gfx::Point());
198 generator.PressTouch(); 195 generator.PressTouch();
199 EXPECT_EQ(tooltip_manager_->IsVisible(), !closes); 196 EXPECT_FALSE(tooltip_manager_->IsVisible());
200 generator.ReleaseTouch(); 197 generator.ReleaseTouch();
201 198
202 // Should hide for touch events on the tooltip. 199 // Should hide for touch events on the tooltip.
203 tooltip_manager_->ShowTooltip(shelf_->GetAppListButton()); 200 tooltip_manager_->ShowTooltip(shelf_->GetAppListButton());
204 ASSERT_TRUE(tooltip_manager_->IsVisible()); 201 ASSERT_TRUE(tooltip_manager_->IsVisible());
205 generator.set_current_location( 202 generator.set_current_location(
206 GetTooltip()->GetWindowBoundsInScreen().CenterPoint()); 203 GetTooltip()->GetWindowBoundsInScreen().CenterPoint());
207 generator.PressTouch(); 204 generator.PressTouch();
208 EXPECT_EQ(tooltip_manager_->IsVisible(), !closes); 205 EXPECT_FALSE(tooltip_manager_->IsVisible());
209 generator.ReleaseTouch(); 206 generator.ReleaseTouch();
210 207
211 // Should hide for gestures outside the shelf. 208 // Should hide for gestures outside the shelf.
212 tooltip_manager_->ShowTooltip(shelf_->GetAppListButton()); 209 tooltip_manager_->ShowTooltip(shelf_->GetAppListButton());
213 ASSERT_TRUE(tooltip_manager_->IsVisible()); 210 ASSERT_TRUE(tooltip_manager_->IsVisible());
214 generator.GestureTapDownAndUp(gfx::Point()); 211 generator.GestureTapDownAndUp(gfx::Point());
215 EXPECT_EQ(tooltip_manager_->IsVisible(), !closes); 212 EXPECT_FALSE(tooltip_manager_->IsVisible());
216 } 213 }
217 214
218 TEST_F(ShelfTooltipManagerTest, DoNotHideForKeyEvents) { 215 TEST_F(ShelfTooltipManagerTest, DoNotHideForKeyEvents) {
219 ui::test::EventGenerator& generator = GetEventGenerator(); 216 ui::test::EventGenerator& generator = GetEventGenerator();
220 217
221 // Should not hide for key events. 218 // Should not hide for key events.
222 tooltip_manager_->ShowTooltip(shelf_->GetAppListButton()); 219 tooltip_manager_->ShowTooltip(shelf_->GetAppListButton());
223 ASSERT_TRUE(tooltip_manager_->IsVisible()); 220 ASSERT_TRUE(tooltip_manager_->IsVisible());
224 generator.PressKey(ui::VKEY_A, ui::EF_NONE); 221 generator.PressKey(ui::VKEY_A, ui::EF_NONE);
225 EXPECT_TRUE(tooltip_manager_->IsVisible()); 222 EXPECT_TRUE(tooltip_manager_->IsVisible());
226 } 223 }
227 224
228 } // namespace test 225 } // namespace test
229 } // namespace ash 226 } // namespace ash
OLDNEW
« no previous file with comments | « ash/shelf/shelf_tooltip_manager.cc ('k') | ash/shelf/shelf_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698