OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "ash/launcher/launcher_tooltip_manager.h" | |
6 | |
7 #include "ash/test/ash_test_base.h" | |
8 #include "ash/wm/shelf_layout_manager.h" | |
9 #include "ash/wm/window_util.h" | |
10 #include "base/string16.h" | |
11 #include "ui/views/widget/widget.h" | |
12 | |
13 namespace ash { | |
14 namespace test { | |
15 | |
16 class LauncherTooltipManagerTest : public AshTestBase { | |
17 public: | |
18 LauncherTooltipManagerTest() {} | |
19 virtual ~LauncherTooltipManagerTest() {} | |
20 | |
21 virtual void SetUp() OVERRIDE { | |
22 ash::test::AshTestBase::SetUp(); | |
23 | |
24 tooltip_manager_.reset(new internal::LauncherTooltipManager( | |
25 SHELF_ALIGNMENT_BOTTOM, Shell::GetInstance()->shelf())); | |
26 } | |
27 | |
28 void ShowDelayed() { | |
29 dummy_anchor_.reset(new views::View); | |
30 tooltip_manager_->ShowDelayed(dummy_anchor_.get(), string16()); | |
31 } | |
32 | |
33 void ShowImmediately() { | |
34 dummy_anchor_.reset(new views::View); | |
35 tooltip_manager_->ShowImmediately(dummy_anchor_.get(), string16()); | |
36 } | |
37 | |
38 bool TooltipIsVisible() { | |
39 return tooltip_manager_->IsVisible(); | |
40 } | |
41 | |
42 bool IsTimerRunning() { | |
43 return tooltip_manager_->timer_.get() != NULL; | |
44 } | |
45 | |
46 protected: | |
47 scoped_ptr<views::View> dummy_anchor_; | |
48 scoped_ptr<internal::LauncherTooltipManager> tooltip_manager_; | |
49 | |
50 private: | |
51 DISALLOW_COPY_AND_ASSIGN(LauncherTooltipManagerTest); | |
52 }; | |
53 | |
54 TEST_F(LauncherTooltipManagerTest, ShowingBasics) { | |
55 // Show delayed do not show at that time, but just run the timer to show. | |
Daniel Erat
2012/07/04 16:31:44
nit: change to something like "ShowDelayed() shoul
Jun Mukai
2012/07/05 02:33:15
Done.
| |
56 ShowDelayed(); | |
57 EXPECT_FALSE(TooltipIsVisible()); | |
58 EXPECT_TRUE(IsTimerRunning()); | |
59 | |
60 ShowImmediately(); | |
61 EXPECT_TRUE(TooltipIsVisible()); | |
62 EXPECT_FALSE(IsTimerRunning()); | |
63 } | |
64 | |
65 TEST_F(LauncherTooltipManagerTest, HideWhenShelfIsHidden) { | |
66 ShowImmediately(); | |
67 ASSERT_TRUE(TooltipIsVisible()); | |
68 | |
69 // Create a full-screen window to show the shelf. | |
70 scoped_ptr<views::Widget> widget(new views::Widget); | |
71 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); | |
72 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | |
73 widget->Init(params); | |
74 widget->SetFullscreen(true); | |
75 widget->Show(); | |
76 | |
77 // Once the shelf is hidden, the tooltip should be invisible. | |
78 ASSERT_EQ(internal::ShelfLayoutManager::HIDDEN, | |
79 Shell::GetInstance()->shelf()->visibility_state()); | |
80 EXPECT_FALSE(TooltipIsVisible()); | |
81 | |
82 // Do not show the view if the shelf is hidden. | |
83 ShowImmediately(); | |
84 EXPECT_FALSE(TooltipIsVisible()); | |
85 | |
86 // ShowDelayed doesn't even run the timer for the hidden shelf. | |
87 ShowDelayed(); | |
88 EXPECT_FALSE(IsTimerRunning()); | |
89 } | |
90 | |
91 TEST_F(LauncherTooltipManagerTest, HideWhenShelfIsAutoHide) { | |
92 ShowImmediately(); | |
93 ASSERT_TRUE(TooltipIsVisible()); | |
94 | |
95 internal::ShelfLayoutManager* shelf = Shell::GetInstance()->shelf(); | |
96 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); | |
97 shelf->UpdateAutoHideState(); | |
98 ASSERT_EQ(internal::ShelfLayoutManager::AUTO_HIDE_HIDDEN, | |
99 shelf->auto_hide_state()); | |
100 | |
101 // Tooltip visibility change for auto hide may take time. | |
102 EXPECT_TRUE(TooltipIsVisible()); | |
103 RunAllPendingInMessageLoop(); | |
104 EXPECT_FALSE(TooltipIsVisible()); | |
105 | |
106 // Do not show the view if the shelf is hidden. | |
107 ShowImmediately(); | |
108 EXPECT_FALSE(TooltipIsVisible()); | |
109 | |
110 // ShowDelayed doesn't even run the timer for the hidden shelf. | |
111 ShowDelayed(); | |
112 EXPECT_FALSE(IsTimerRunning()); | |
113 } | |
114 | |
115 } // namespace test | |
116 } // namespace ash | |
OLD | NEW |