| 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" |
| 9 #include "ash/shelf/shelf_widget.h" |
| 8 #include "ash/shell.h" | 10 #include "ash/shell.h" |
| 9 #include "ash/shell_window_ids.h" | 11 #include "ash/shell_window_ids.h" |
| 10 #include "ash/test/ash_test_base.h" | 12 #include "ash/test/ash_test_base.h" |
| 11 #include "ash/wm/shelf_layout_manager.h" | |
| 12 #include "ash/wm/window_util.h" | 13 #include "ash/wm/window_util.h" |
| 13 #include "base/string16.h" | 14 #include "base/string16.h" |
| 14 #include "base/time.h" | 15 #include "base/time.h" |
| 15 #include "ui/aura/root_window.h" | 16 #include "ui/aura/root_window.h" |
| 16 #include "ui/base/events/event.h" | 17 #include "ui/base/events/event.h" |
| 17 #include "ui/base/events/event_constants.h" | 18 #include "ui/base/events/event_constants.h" |
| 18 #include "ui/base/events/event_handler.h" | 19 #include "ui/base/events/event_handler.h" |
| 19 #include "ui/base/keycodes/keyboard_codes.h" | 20 #include "ui/base/keycodes/keyboard_codes.h" |
| 20 #include "ui/views/widget/widget.h" | 21 #include "ui/views/widget/widget.h" |
| 21 | 22 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 35 class LauncherTooltipManagerTest : public AshTestBase { | 36 class LauncherTooltipManagerTest : public AshTestBase { |
| 36 public: | 37 public: |
| 37 LauncherTooltipManagerTest() {} | 38 LauncherTooltipManagerTest() {} |
| 38 virtual ~LauncherTooltipManagerTest() {} | 39 virtual ~LauncherTooltipManagerTest() {} |
| 39 | 40 |
| 40 virtual void SetUp() OVERRIDE { | 41 virtual void SetUp() OVERRIDE { |
| 41 AshTestBase::SetUp(); | 42 AshTestBase::SetUp(); |
| 42 internal::RootWindowController* controller = | 43 internal::RootWindowController* controller = |
| 43 Shell::GetPrimaryRootWindowController(); | 44 Shell::GetPrimaryRootWindowController(); |
| 44 tooltip_manager_.reset(new internal::LauncherTooltipManager( | 45 tooltip_manager_.reset(new internal::LauncherTooltipManager( |
| 45 controller->shelf(), | 46 controller->GetShelfLayoutManager(), |
| 46 controller->launcher()->GetLauncherViewForTest())); | 47 controller->shelf()->launcher()->GetLauncherViewForTest())); |
| 47 } | 48 } |
| 48 | 49 |
| 49 virtual void TearDown() OVERRIDE { | 50 virtual void TearDown() OVERRIDE { |
| 50 tooltip_manager_.reset(); | 51 tooltip_manager_.reset(); |
| 51 AshTestBase::TearDown(); | 52 AshTestBase::TearDown(); |
| 52 } | 53 } |
| 53 | 54 |
| 54 void ShowDelayed() { | 55 void ShowDelayed() { |
| 55 CreateWidget(); | 56 CreateWidget(); |
| 56 tooltip_manager_->ShowDelayed(dummy_anchor_.get(), string16()); | 57 tooltip_manager_->ShowDelayed(dummy_anchor_.get(), string16()); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 86 void CreateWidget() { | 87 void CreateWidget() { |
| 87 dummy_anchor_.reset(new views::View); | 88 dummy_anchor_.reset(new views::View); |
| 88 | 89 |
| 89 widget_.reset(new views::Widget); | 90 widget_.reset(new views::Widget); |
| 90 views::Widget::InitParams params( | 91 views::Widget::InitParams params( |
| 91 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); | 92 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); |
| 92 params.transparent = true; | 93 params.transparent = true; |
| 93 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 94 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
| 94 params.parent = Shell::GetContainer( | 95 params.parent = Shell::GetContainer( |
| 95 Shell::GetPrimaryRootWindow(), | 96 Shell::GetPrimaryRootWindow(), |
| 96 ash::internal::kShellWindowId_LauncherContainer); | 97 ash::internal::kShellWindowId_ShelfContainer); |
| 97 | 98 |
| 98 widget_->Init(params); | 99 widget_->Init(params); |
| 99 widget_->SetContentsView(dummy_anchor_.get()); | 100 widget_->SetContentsView(dummy_anchor_.get()); |
| 100 } | 101 } |
| 101 | 102 |
| 102 DISALLOW_COPY_AND_ASSIGN(LauncherTooltipManagerTest); | 103 DISALLOW_COPY_AND_ASSIGN(LauncherTooltipManagerTest); |
| 103 }; | 104 }; |
| 104 | 105 |
| 105 TEST_F(LauncherTooltipManagerTest, ShowingBasics) { | 106 TEST_F(LauncherTooltipManagerTest, ShowingBasics) { |
| 106 // ShowDelayed() should just start the timer instead of showing immediately. | 107 // ShowDelayed() should just start the timer instead of showing immediately. |
| (...skipping 15 matching lines...) Expand all Loading... |
| 122 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); | 123 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); |
| 123 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 124 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
| 124 params.context = CurrentContext(); | 125 params.context = CurrentContext(); |
| 125 widget->Init(params); | 126 widget->Init(params); |
| 126 widget->SetFullscreen(true); | 127 widget->SetFullscreen(true); |
| 127 widget->Show(); | 128 widget->Show(); |
| 128 | 129 |
| 129 // Once the shelf is hidden, the tooltip should be invisible. | 130 // Once the shelf is hidden, the tooltip should be invisible. |
| 130 ASSERT_EQ( | 131 ASSERT_EQ( |
| 131 SHELF_HIDDEN, | 132 SHELF_HIDDEN, |
| 132 Shell::GetPrimaryRootWindowController()->shelf()->visibility_state()); | 133 Shell::GetPrimaryRootWindowController()-> |
| 134 GetShelfLayoutManager()->visibility_state()); |
| 133 EXPECT_FALSE(TooltipIsVisible()); | 135 EXPECT_FALSE(TooltipIsVisible()); |
| 134 | 136 |
| 135 // Do not show the view if the shelf is hidden. | 137 // Do not show the view if the shelf is hidden. |
| 136 ShowImmediately(); | 138 ShowImmediately(); |
| 137 EXPECT_FALSE(TooltipIsVisible()); | 139 EXPECT_FALSE(TooltipIsVisible()); |
| 138 | 140 |
| 139 // ShowDelayed() doesn't even start the timer for the hidden shelf. | 141 // ShowDelayed() doesn't even start the timer for the hidden shelf. |
| 140 ShowDelayed(); | 142 ShowDelayed(); |
| 141 EXPECT_FALSE(IsTimerRunning()); | 143 EXPECT_FALSE(IsTimerRunning()); |
| 142 } | 144 } |
| 143 | 145 |
| 144 TEST_F(LauncherTooltipManagerTest, HideWhenShelfIsAutoHide) { | 146 TEST_F(LauncherTooltipManagerTest, HideWhenShelfIsAutoHide) { |
| 145 // Create a visible window so auto-hide behavior is enforced. | 147 // Create a visible window so auto-hide behavior is enforced. |
| 146 views::Widget* dummy = new views::Widget; | 148 views::Widget* dummy = new views::Widget; |
| 147 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); | 149 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); |
| 148 params.bounds = gfx::Rect(0, 0, 200, 200); | 150 params.bounds = gfx::Rect(0, 0, 200, 200); |
| 149 params.context = CurrentContext(); | 151 params.context = CurrentContext(); |
| 150 dummy->Init(params); | 152 dummy->Init(params); |
| 151 dummy->Show(); | 153 dummy->Show(); |
| 152 | 154 |
| 153 ShowImmediately(); | 155 ShowImmediately(); |
| 154 ASSERT_TRUE(TooltipIsVisible()); | 156 ASSERT_TRUE(TooltipIsVisible()); |
| 155 | 157 |
| 156 internal::ShelfLayoutManager* shelf = | 158 internal::ShelfLayoutManager* shelf = |
| 157 Shell::GetPrimaryRootWindowController()->shelf(); | 159 Shell::GetPrimaryRootWindowController()->GetShelfLayoutManager(); |
| 158 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); | 160 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); |
| 159 shelf->UpdateAutoHideState(); | 161 shelf->UpdateAutoHideState(); |
| 160 ASSERT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state()); | 162 ASSERT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state()); |
| 161 | 163 |
| 162 // Tooltip visibility change for auto hide may take time. | 164 // Tooltip visibility change for auto hide may take time. |
| 163 EXPECT_TRUE(TooltipIsVisible()); | 165 EXPECT_TRUE(TooltipIsVisible()); |
| 164 RunAllPendingInMessageLoop(); | 166 RunAllPendingInMessageLoop(); |
| 165 EXPECT_FALSE(TooltipIsVisible()); | 167 EXPECT_FALSE(TooltipIsVisible()); |
| 166 | 168 |
| 167 // Do not show the view if the shelf is hidden. | 169 // Do not show the view if the shelf is hidden. |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 // Should hide if the mouse is out of the tooltip. | 240 // Should hide if the mouse is out of the tooltip. |
| 239 test_api.set_location(tooltip_rect.origin() + gfx::Vector2d(-1, -1)); | 241 test_api.set_location(tooltip_rect.origin() + gfx::Vector2d(-1, -1)); |
| 240 event_handler->OnMouseEvent(&mouse_event); | 242 event_handler->OnMouseEvent(&mouse_event); |
| 241 EXPECT_FALSE(mouse_event.handled()); | 243 EXPECT_FALSE(mouse_event.handled()); |
| 242 RunAllPendingInMessageLoop(); | 244 RunAllPendingInMessageLoop(); |
| 243 EXPECT_FALSE(TooltipIsVisible()); | 245 EXPECT_FALSE(TooltipIsVisible()); |
| 244 } | 246 } |
| 245 | 247 |
| 246 } // namespace test | 248 } // namespace test |
| 247 } // namespace ash | 249 } // namespace ash |
| OLD | NEW |