OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/launcher/launcher_tooltip_manager.h" | 5 #include "ash/launcher/launcher_tooltip_manager.h" |
6 | 6 |
7 #include "ash/root_window_controller.h" | 7 #include "ash/root_window_controller.h" |
8 #include "ash/shelf/shelf_layout_manager.h" | 8 #include "ash/shelf/shelf_layout_manager.h" |
9 #include "ash/shelf/shelf_widget.h" | 9 #include "ash/shelf/shelf_widget.h" |
10 #include "ash/shell.h" | 10 #include "ash/shell.h" |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 ui::ET_GESTURE_BEGIN, 0, 0, ui::EF_NONE, | 210 ui::ET_GESTURE_BEGIN, 0, 0, ui::EF_NONE, |
211 base::TimeDelta::FromMilliseconds(base::Time::Now().ToDoubleT() * 1000), | 211 base::TimeDelta::FromMilliseconds(base::Time::Now().ToDoubleT() * 1000), |
212 ui::GestureEventDetails(ui::ET_GESTURE_BEGIN, 0.0f, 0.0f), 0); | 212 ui::GestureEventDetails(ui::ET_GESTURE_BEGIN, 0.0f, 0.0f), 0); |
213 SetEventTarget(tooltip_widget->GetNativeWindow(), &gesture_event); | 213 SetEventTarget(tooltip_widget->GetNativeWindow(), &gesture_event); |
214 event_handler->OnGestureEvent(&gesture_event); | 214 event_handler->OnGestureEvent(&gesture_event); |
215 EXPECT_FALSE(gesture_event.handled()); | 215 EXPECT_FALSE(gesture_event.handled()); |
216 RunAllPendingInMessageLoop(); | 216 RunAllPendingInMessageLoop(); |
217 EXPECT_FALSE(TooltipIsVisible()); | 217 EXPECT_FALSE(TooltipIsVisible()); |
218 } | 218 } |
219 | 219 |
220 TEST_F(LauncherTooltipManagerTest, HideForMouseEvent) { | 220 TEST_F(LauncherTooltipManagerTest, HideForMouseMoveEvent) { |
221 ShowImmediately(); | 221 ShowImmediately(); |
222 ASSERT_TRUE(TooltipIsVisible()); | 222 ASSERT_TRUE(TooltipIsVisible()); |
223 | 223 |
224 aura::RootWindow* root_window = Shell::GetInstance()->GetPrimaryRootWindow(); | 224 aura::RootWindow* root_window = Shell::GetInstance()->GetPrimaryRootWindow(); |
225 ui::EventHandler* event_handler = GetEventHandler(); | 225 ui::EventHandler* event_handler = GetEventHandler(); |
226 | 226 |
227 gfx::Rect tooltip_rect = GetTooltipWidget()->GetNativeWindow()->bounds(); | 227 gfx::Rect tooltip_rect = GetTooltipWidget()->GetNativeWindow()->bounds(); |
228 ASSERT_FALSE(tooltip_rect.IsEmpty()); | 228 ASSERT_FALSE(tooltip_rect.IsEmpty()); |
229 | 229 |
230 // Shouldn't hide if the mouse is in the tooltip. | 230 // Shouldn't hide if the mouse is in the tooltip. |
231 ui::MouseEvent mouse_event(ui::ET_MOUSE_MOVED, tooltip_rect.CenterPoint(), | 231 ui::MouseEvent mouse_event(ui::ET_MOUSE_MOVED, tooltip_rect.CenterPoint(), |
232 tooltip_rect.CenterPoint(), ui::EF_NONE); | 232 tooltip_rect.CenterPoint(), ui::EF_NONE); |
233 ui::LocatedEvent::TestApi test_api(&mouse_event); | 233 ui::LocatedEvent::TestApi test_api(&mouse_event); |
234 | 234 |
235 SetEventTarget(root_window, &mouse_event); | 235 SetEventTarget(root_window, &mouse_event); |
236 event_handler->OnMouseEvent(&mouse_event); | 236 event_handler->OnMouseEvent(&mouse_event); |
237 EXPECT_FALSE(mouse_event.handled()); | 237 EXPECT_FALSE(mouse_event.handled()); |
238 EXPECT_TRUE(TooltipIsVisible()); | 238 EXPECT_TRUE(TooltipIsVisible()); |
239 | 239 |
240 // Should hide if the mouse is out of the tooltip. | 240 // Should hide if the mouse is out of the tooltip. |
241 test_api.set_location(tooltip_rect.origin() + gfx::Vector2d(-1, -1)); | 241 test_api.set_location(tooltip_rect.origin() + gfx::Vector2d(-1, -1)); |
242 event_handler->OnMouseEvent(&mouse_event); | 242 event_handler->OnMouseEvent(&mouse_event); |
243 EXPECT_FALSE(mouse_event.handled()); | 243 EXPECT_FALSE(mouse_event.handled()); |
244 RunAllPendingInMessageLoop(); | 244 RunAllPendingInMessageLoop(); |
245 EXPECT_FALSE(TooltipIsVisible()); | 245 EXPECT_FALSE(TooltipIsVisible()); |
246 } | 246 } |
247 | 247 |
| 248 //Checks that tooltip is hidden when mouse is pressed in anywhere. |
| 249 TEST_F(LauncherTooltipManagerTest, HideForMouseClickEvent) { |
| 250 ShowImmediately(); |
| 251 ASSERT_TRUE(TooltipIsVisible()); |
| 252 |
| 253 aura::RootWindow* root_window = Shell::GetInstance()->GetPrimaryRootWindow(); |
| 254 ui::EventHandler* event_handler = GetEventHandler(); |
| 255 |
| 256 gfx::Rect tooltip_rect = GetTooltipWidget()->GetNativeWindow()->bounds(); |
| 257 ASSERT_FALSE(tooltip_rect.IsEmpty()); |
| 258 |
| 259 // Should hide if the mouse is pressed in the tooltip. |
| 260 ui::MouseEvent mouse_event(ui::ET_MOUSE_PRESSED, tooltip_rect.CenterPoint(), |
| 261 tooltip_rect.CenterPoint(), ui::EF_NONE); |
| 262 |
| 263 SetEventTarget(root_window, &mouse_event); |
| 264 event_handler->OnMouseEvent(&mouse_event); |
| 265 EXPECT_FALSE(mouse_event.handled()); |
| 266 RunAllPendingInMessageLoop(); |
| 267 EXPECT_FALSE(TooltipIsVisible()); |
| 268 |
| 269 // Should hide if the mouse is pressed outside of the tooltip. |
| 270 ShowImmediately(); |
| 271 ASSERT_TRUE(TooltipIsVisible()); |
| 272 |
| 273 ui::LocatedEvent::TestApi test_api(&mouse_event); |
| 274 test_api.set_location(tooltip_rect.origin() + gfx::Vector2d(-1, -1)); |
| 275 |
| 276 SetEventTarget(root_window, &mouse_event); |
| 277 event_handler->OnMouseEvent(&mouse_event); |
| 278 EXPECT_FALSE(mouse_event.handled()); |
| 279 RunAllPendingInMessageLoop(); |
| 280 EXPECT_FALSE(TooltipIsVisible()); |
| 281 } |
| 282 |
248 } // namespace test | 283 } // namespace test |
249 } // namespace ash | 284 } // namespace ash |
OLD | NEW |