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/test/ash_test_base.h" | 7 #include "ash/test/ash_test_base.h" |
8 #include "ash/wm/shelf_layout_manager.h" | 8 #include "ash/wm/shelf_layout_manager.h" |
9 #include "ash/wm/window_util.h" | 9 #include "ash/wm/window_util.h" |
10 #include "base/string16.h" | 10 #include "base/string16.h" |
| 11 #include "base/time.h" |
| 12 #include "ui/aura/event.h" |
| 13 #include "ui/aura/event_filter.h" |
| 14 #include "ui/aura/root_window.h" |
| 15 #include "ui/base/events.h" |
| 16 #include "ui/base/keycodes/keyboard_codes.h" |
11 #include "ui/views/widget/widget.h" | 17 #include "ui/views/widget/widget.h" |
12 | 18 |
13 namespace ash { | 19 namespace ash { |
14 namespace test { | 20 namespace test { |
15 | 21 |
16 class LauncherTooltipManagerTest : public AshTestBase { | 22 class LauncherTooltipManagerTest : public AshTestBase { |
17 public: | 23 public: |
18 LauncherTooltipManagerTest() {} | 24 LauncherTooltipManagerTest() {} |
19 virtual ~LauncherTooltipManagerTest() {} | 25 virtual ~LauncherTooltipManagerTest() {} |
20 | 26 |
21 virtual void SetUp() OVERRIDE { | 27 virtual void SetUp() OVERRIDE { |
22 ash::test::AshTestBase::SetUp(); | 28 AshTestBase::SetUp(); |
23 | 29 |
24 tooltip_manager_.reset(new internal::LauncherTooltipManager( | 30 tooltip_manager_.reset(new internal::LauncherTooltipManager( |
25 SHELF_ALIGNMENT_BOTTOM, Shell::GetInstance()->shelf())); | 31 SHELF_ALIGNMENT_BOTTOM, |
| 32 Shell::GetInstance()->shelf(), |
| 33 Shell::GetInstance()->launcher()->GetLauncherViewForTest())); |
| 34 } |
| 35 |
| 36 virtual void TearDown() OVERRIDE { |
| 37 tooltip_manager_.reset(); |
| 38 AshTestBase::TearDown(); |
26 } | 39 } |
27 | 40 |
28 void ShowDelayed() { | 41 void ShowDelayed() { |
29 dummy_anchor_.reset(new views::View); | 42 dummy_anchor_.reset(new views::View); |
30 tooltip_manager_->ShowDelayed(dummy_anchor_.get(), string16()); | 43 tooltip_manager_->ShowDelayed(dummy_anchor_.get(), string16()); |
31 } | 44 } |
32 | 45 |
33 void ShowImmediately() { | 46 void ShowImmediately() { |
34 dummy_anchor_.reset(new views::View); | 47 dummy_anchor_.reset(new views::View); |
35 tooltip_manager_->ShowImmediately(dummy_anchor_.get(), string16()); | 48 tooltip_manager_->ShowImmediately(dummy_anchor_.get(), string16()); |
36 } | 49 } |
37 | 50 |
38 bool TooltipIsVisible() { | 51 bool TooltipIsVisible() { |
39 return tooltip_manager_->IsVisible(); | 52 return tooltip_manager_->IsVisible(); |
40 } | 53 } |
41 | 54 |
42 bool IsTimerRunning() { | 55 bool IsTimerRunning() { |
43 return tooltip_manager_->timer_.get() != NULL; | 56 return tooltip_manager_->timer_.get() != NULL; |
44 } | 57 } |
45 | 58 |
| 59 aura::EventFilter* GetEventFilter() { |
| 60 return tooltip_manager_.get(); |
| 61 } |
| 62 |
| 63 views::Widget* GetTooltipWidget() { |
| 64 return tooltip_manager_->widget_; |
| 65 } |
| 66 |
46 protected: | 67 protected: |
47 scoped_ptr<views::View> dummy_anchor_; | 68 scoped_ptr<views::View> dummy_anchor_; |
48 scoped_ptr<internal::LauncherTooltipManager> tooltip_manager_; | 69 scoped_ptr<internal::LauncherTooltipManager> tooltip_manager_; |
49 | 70 |
50 private: | 71 private: |
51 DISALLOW_COPY_AND_ASSIGN(LauncherTooltipManagerTest); | 72 DISALLOW_COPY_AND_ASSIGN(LauncherTooltipManagerTest); |
52 }; | 73 }; |
53 | 74 |
54 TEST_F(LauncherTooltipManagerTest, ShowingBasics) { | 75 TEST_F(LauncherTooltipManagerTest, ShowingBasics) { |
55 // ShowDelayed() should just start the timer instead of showing immediately. | 76 // ShowDelayed() should just start the timer instead of showing immediately. |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 | 126 |
106 // Do not show the view if the shelf is hidden. | 127 // Do not show the view if the shelf is hidden. |
107 ShowImmediately(); | 128 ShowImmediately(); |
108 EXPECT_FALSE(TooltipIsVisible()); | 129 EXPECT_FALSE(TooltipIsVisible()); |
109 | 130 |
110 // ShowDelayed doesn't even run the timer for the hidden shelf. | 131 // ShowDelayed doesn't even run the timer for the hidden shelf. |
111 ShowDelayed(); | 132 ShowDelayed(); |
112 EXPECT_FALSE(IsTimerRunning()); | 133 EXPECT_FALSE(IsTimerRunning()); |
113 } | 134 } |
114 | 135 |
| 136 TEST_F(LauncherTooltipManagerTest, ShouldHideForEvents) { |
| 137 ShowImmediately(); |
| 138 ASSERT_TRUE(TooltipIsVisible()); |
| 139 |
| 140 aura::RootWindow* root_window = Shell::GetInstance()->GetPrimaryRootWindow(); |
| 141 aura::EventFilter* event_filter = GetEventFilter(); |
| 142 |
| 143 // Should not hide for key events. |
| 144 aura::KeyEvent key_event(ui::ET_KEY_PRESSED, ui::VKEY_A, ui::EF_NONE); |
| 145 EXPECT_FALSE(event_filter->PreHandleKeyEvent(root_window, &key_event)); |
| 146 EXPECT_TRUE(TooltipIsVisible()); |
| 147 |
| 148 // Should hide for touch events. |
| 149 aura::TouchEvent touch_event( |
| 150 ui::ET_TOUCH_PRESSED, gfx::Point(), 0, base::TimeDelta()); |
| 151 EXPECT_EQ(ui::TOUCH_STATUS_UNKNOWN, |
| 152 event_filter->PreHandleTouchEvent(root_window, &touch_event)); |
| 153 EXPECT_FALSE(TooltipIsVisible()); |
| 154 |
| 155 // Shouldn't hide if the touch happens on the tooltip. |
| 156 ShowImmediately(); |
| 157 views::Widget* tooltip_widget = GetTooltipWidget(); |
| 158 EXPECT_EQ(ui::TOUCH_STATUS_UNKNOWN, |
| 159 event_filter->PreHandleTouchEvent( |
| 160 tooltip_widget->GetNativeWindow(), &touch_event)); |
| 161 EXPECT_TRUE(TooltipIsVisible()); |
| 162 |
| 163 // Should hide for gesture events. |
| 164 aura::GestureEvent gesture_event( |
| 165 ui::ET_GESTURE_BEGIN, 0, 0, ui::EF_NONE, base::Time(), |
| 166 ui::GestureEventDetails(ui::ET_GESTURE_BEGIN, 0.0f, 0.0f), 0); |
| 167 EXPECT_EQ(ui::GESTURE_STATUS_UNKNOWN, |
| 168 event_filter->PreHandleGestureEvent(root_window, &gesture_event)); |
| 169 RunAllPendingInMessageLoop(); |
| 170 EXPECT_FALSE(TooltipIsVisible()); |
| 171 } |
| 172 |
| 173 TEST_F(LauncherTooltipManagerTest, HideForMouseEvent) { |
| 174 ShowImmediately(); |
| 175 ASSERT_TRUE(TooltipIsVisible()); |
| 176 |
| 177 aura::RootWindow* root_window = Shell::GetInstance()->GetPrimaryRootWindow(); |
| 178 aura::EventFilter* event_filter = GetEventFilter(); |
| 179 |
| 180 gfx::Rect tooltip_rect = GetTooltipWidget()->GetNativeWindow()->bounds(); |
| 181 ASSERT_FALSE(tooltip_rect.IsEmpty()); |
| 182 |
| 183 // Shouldn't hide if the mouse is in the tooltip. |
| 184 aura::MouseEvent mouse_event(ui::ET_MOUSE_MOVED, tooltip_rect.CenterPoint(), |
| 185 tooltip_rect.CenterPoint(), ui::EF_NONE); |
| 186 aura::LocatedEvent::TestApi test_api(&mouse_event); |
| 187 |
| 188 EXPECT_FALSE(event_filter->PreHandleMouseEvent(root_window, &mouse_event)); |
| 189 EXPECT_TRUE(TooltipIsVisible()); |
| 190 |
| 191 // Should hide if the mouse is out of the tooltip. |
| 192 test_api.set_location(tooltip_rect.origin().Add(gfx::Point(-1, -1))); |
| 193 EXPECT_FALSE(event_filter->PreHandleMouseEvent(root_window, &mouse_event)); |
| 194 RunAllPendingInMessageLoop(); |
| 195 EXPECT_FALSE(TooltipIsVisible()); |
| 196 } |
| 197 |
115 } // namespace test | 198 } // namespace test |
116 } // namespace ash | 199 } // namespace ash |
OLD | NEW |