Index: ash/launcher/launcher_tooltip_manager_unittest.cc |
diff --git a/ash/launcher/launcher_tooltip_manager_unittest.cc b/ash/launcher/launcher_tooltip_manager_unittest.cc |
index 0e428574d5034626c7c64e4b39a307308ad8b3dd..6d14c895e4f313c001ec2096e21c09b6fb2f1253 100644 |
--- a/ash/launcher/launcher_tooltip_manager_unittest.cc |
+++ b/ash/launcher/launcher_tooltip_manager_unittest.cc |
@@ -8,6 +8,12 @@ |
#include "ash/wm/shelf_layout_manager.h" |
#include "ash/wm/window_util.h" |
#include "base/string16.h" |
+#include "base/time.h" |
+#include "ui/aura/event.h" |
+#include "ui/aura/event_filter.h" |
+#include "ui/aura/root_window.h" |
+#include "ui/base/events.h" |
+#include "ui/base/keycodes/keyboard_codes.h" |
#include "ui/views/widget/widget.h" |
namespace ash { |
@@ -19,10 +25,17 @@ class LauncherTooltipManagerTest : public AshTestBase { |
virtual ~LauncherTooltipManagerTest() {} |
virtual void SetUp() OVERRIDE { |
- ash::test::AshTestBase::SetUp(); |
+ AshTestBase::SetUp(); |
tooltip_manager_.reset(new internal::LauncherTooltipManager( |
- SHELF_ALIGNMENT_BOTTOM, Shell::GetInstance()->shelf())); |
+ SHELF_ALIGNMENT_BOTTOM, |
+ Shell::GetInstance()->shelf(), |
+ Shell::GetInstance()->launcher()->GetLauncherViewForTest())); |
+ } |
+ |
+ virtual void TearDown() OVERRIDE { |
+ tooltip_manager_.reset(); |
+ AshTestBase::TearDown(); |
} |
void ShowDelayed() { |
@@ -43,6 +56,14 @@ class LauncherTooltipManagerTest : public AshTestBase { |
return tooltip_manager_->timer_.get() != NULL; |
} |
+ aura::EventFilter* GetEventFilter() { |
+ return tooltip_manager_.get(); |
+ } |
+ |
+ views::Widget* GetTooltipWidget() { |
+ return tooltip_manager_->widget_; |
+ } |
+ |
protected: |
scoped_ptr<views::View> dummy_anchor_; |
scoped_ptr<internal::LauncherTooltipManager> tooltip_manager_; |
@@ -112,5 +133,67 @@ TEST_F(LauncherTooltipManagerTest, HideWhenShelfIsAutoHide) { |
EXPECT_FALSE(IsTimerRunning()); |
} |
+TEST_F(LauncherTooltipManagerTest, ShouldHideForEvents) { |
+ ShowImmediately(); |
+ ASSERT_TRUE(TooltipIsVisible()); |
+ |
+ aura::RootWindow* root_window = Shell::GetInstance()->GetPrimaryRootWindow(); |
+ aura::EventFilter* event_filter = GetEventFilter(); |
+ |
+ // Should not hide for key events. |
+ aura::KeyEvent key_event(ui::ET_KEY_PRESSED, ui::VKEY_A, ui::EF_NONE); |
+ EXPECT_FALSE(event_filter->PreHandleKeyEvent(root_window, &key_event)); |
+ EXPECT_TRUE(TooltipIsVisible()); |
+ |
+ // Should hide for touch events. |
+ aura::TouchEvent touch_event( |
+ ui::ET_TOUCH_PRESSED, gfx::Point(), 0, base::TimeDelta()); |
+ EXPECT_EQ(ui::TOUCH_STATUS_UNKNOWN, |
+ event_filter->PreHandleTouchEvent(root_window, &touch_event)); |
+ EXPECT_FALSE(TooltipIsVisible()); |
+ |
+ // Shouldn't hide if the touch happens on the tooltip. |
+ ShowImmediately(); |
+ views::Widget* tooltip_widget = GetTooltipWidget(); |
+ EXPECT_EQ(ui::TOUCH_STATUS_UNKNOWN, |
+ event_filter->PreHandleTouchEvent( |
+ tooltip_widget->GetNativeWindow(), &touch_event)); |
+ EXPECT_TRUE(TooltipIsVisible()); |
+ |
+ // Should hide for gesture events. |
+ aura::GestureEvent gesture_event( |
+ ui::ET_GESTURE_BEGIN, 0, 0, ui::EF_NONE, base::Time(), |
+ ui::GestureEventDetails(ui::ET_GESTURE_BEGIN, 0.0f, 0.0f), 0); |
+ EXPECT_EQ(ui::GESTURE_STATUS_UNKNOWN, |
+ event_filter->PreHandleGestureEvent(root_window, &gesture_event)); |
+ RunAllPendingInMessageLoop(); |
+ EXPECT_FALSE(TooltipIsVisible()); |
+} |
+ |
+TEST_F(LauncherTooltipManagerTest, HideForMouseEvent) { |
+ ShowImmediately(); |
+ ASSERT_TRUE(TooltipIsVisible()); |
+ |
+ aura::RootWindow* root_window = Shell::GetInstance()->GetPrimaryRootWindow(); |
+ aura::EventFilter* event_filter = GetEventFilter(); |
+ |
+ gfx::Rect tooltip_rect = GetTooltipWidget()->GetNativeWindow()->bounds(); |
+ ASSERT_FALSE(tooltip_rect.IsEmpty()); |
+ |
+ // Shouldn't hide if the mouse is in the tooltip. |
+ aura::MouseEvent mouse_event(ui::ET_MOUSE_MOVED, tooltip_rect.CenterPoint(), |
+ tooltip_rect.CenterPoint(), ui::EF_NONE); |
+ aura::LocatedEvent::TestApi test_api(&mouse_event); |
+ |
+ EXPECT_FALSE(event_filter->PreHandleMouseEvent(root_window, &mouse_event)); |
+ EXPECT_TRUE(TooltipIsVisible()); |
+ |
+ // Should hide if the mouse is out of the tooltip. |
+ test_api.set_location(tooltip_rect.origin().Add(gfx::Point(-1, -1))); |
+ EXPECT_FALSE(event_filter->PreHandleMouseEvent(root_window, &mouse_event)); |
+ RunAllPendingInMessageLoop(); |
+ EXPECT_FALSE(TooltipIsVisible()); |
+} |
+ |
} // namespace test |
} // namespace ash |