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/focus_cycler.h" | 5 #include "ash/focus_cycler.h" |
6 | 6 |
7 #include "ash/launcher/launcher.h" | 7 #include "ash/launcher/launcher.h" |
8 #include "ash/shell.h" | 8 #include "ash/shell.h" |
9 #include "ash/shell_window_ids.h" | 9 #include "ash/shell_window_ids.h" |
10 #include "ash/status_area/status_area_view.h" | 10 #include "ash/system/tray/system_tray.h" |
| 11 #include "ash/system/tray/system_tray_widget_delegate.h" |
11 #include "ash/wm/window_util.h" | 12 #include "ash/wm/window_util.h" |
12 #include "ash/test/ash_test_base.h" | 13 #include "ash/test/ash_test_base.h" |
13 #include "ash/shell_factory.h" | 14 #include "ash/shell_factory.h" |
14 #include "ui/aura/test/test_windows.h" | 15 #include "ui/aura/test/test_windows.h" |
15 #include "ui/aura/window.h" | 16 #include "ui/aura/window.h" |
16 #include "ui/views/controls/button/menu_button.h" | 17 #include "ui/views/controls/button/menu_button.h" |
17 #include "ui/views/widget/widget.h" | 18 #include "ui/views/widget/widget.h" |
18 | 19 |
19 namespace ash { | 20 namespace ash { |
20 namespace test { | 21 namespace test { |
21 | 22 |
22 using aura::test::CreateTestWindowWithId; | 23 using aura::test::CreateTestWindowWithId; |
23 using aura::Window; | 24 using aura::Window; |
24 using internal::FocusCycler; | 25 using internal::FocusCycler; |
25 | 26 |
26 namespace { | 27 namespace { |
27 | 28 |
28 internal::StatusAreaView* GetStatusAreaView(views::Widget* widget) { | 29 internal::StatusAreaView* GetStatusAreaView(views::Widget* widget) { |
29 return static_cast<internal::StatusAreaView*>( | 30 return static_cast<internal::StatusAreaView*>( |
30 widget->GetContentsView()); | 31 widget->GetContentsView()); |
31 } | 32 } |
32 | 33 |
| 34 SystemTray* CreateSystemTray() { |
| 35 SystemTray* tray = new SystemTray; |
| 36 tray->CreateWidget(); |
| 37 return tray; |
| 38 } |
| 39 |
33 } // namespace | 40 } // namespace |
34 | 41 |
35 typedef AshTestBase FocusCyclerTest; | 42 typedef AshTestBase FocusCyclerTest; |
36 | 43 |
37 TEST_F(FocusCyclerTest, CycleFocusBrowserOnly) { | 44 TEST_F(FocusCyclerTest, CycleFocusBrowserOnly) { |
38 scoped_ptr<FocusCycler> focus_cycler(new FocusCycler()); | 45 scoped_ptr<FocusCycler> focus_cycler(new FocusCycler()); |
39 | 46 |
40 // Create a single test window. | 47 // Create a single test window. |
41 Window* default_container = | 48 Window* default_container = |
42 ash::Shell::GetInstance()->GetContainer( | 49 ash::Shell::GetInstance()->GetContainer( |
43 internal::kShellWindowId_DefaultContainer); | 50 internal::kShellWindowId_DefaultContainer); |
44 scoped_ptr<Window> window0(CreateTestWindowWithId(0, default_container)); | 51 scoped_ptr<Window> window0(CreateTestWindowWithId(0, default_container)); |
45 wm::ActivateWindow(window0.get()); | 52 wm::ActivateWindow(window0.get()); |
46 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); | 53 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); |
47 | 54 |
48 // Cycle the window | 55 // Cycle the window |
49 focus_cycler->RotateFocus(FocusCycler::FORWARD); | 56 focus_cycler->RotateFocus(FocusCycler::FORWARD); |
50 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); | 57 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); |
51 } | 58 } |
52 | 59 |
53 TEST_F(FocusCyclerTest, CycleFocusForward) { | 60 TEST_F(FocusCyclerTest, CycleFocusForward) { |
54 scoped_ptr<FocusCycler> focus_cycler(new FocusCycler()); | 61 scoped_ptr<FocusCycler> focus_cycler(new FocusCycler()); |
55 | 62 |
56 // Add the Status area | 63 // Add the Status area |
57 views::Widget* status_widget = internal::CreateStatusArea(NULL); | 64 scoped_ptr<SystemTray> tray(CreateSystemTray()); |
58 ASSERT_TRUE(status_widget); | 65 ASSERT_TRUE(tray->widget()); |
59 focus_cycler->AddWidget(status_widget); | 66 focus_cycler->AddWidget(tray->widget()); |
60 GetStatusAreaView(status_widget)->SetFocusCyclerForTesting( | 67 GetStatusAreaView(tray->widget())->SetFocusCyclerForTesting( |
61 focus_cycler.get()); | 68 focus_cycler.get()); |
62 | 69 |
63 // Add the launcher | 70 // Add the launcher |
64 Launcher* launcher = Shell::GetInstance()->launcher(); | 71 Launcher* launcher = Shell::GetInstance()->launcher(); |
65 ASSERT_TRUE(launcher); | 72 ASSERT_TRUE(launcher); |
66 views::Widget* launcher_widget = launcher->widget(); | 73 views::Widget* launcher_widget = launcher->widget(); |
67 ASSERT_TRUE(launcher_widget); | 74 ASSERT_TRUE(launcher_widget); |
68 launcher->SetFocusCycler(focus_cycler.get()); | 75 launcher->SetFocusCycler(focus_cycler.get()); |
69 | 76 |
70 // Create a single test window. | 77 // Create a single test window. |
71 Window* default_container = | 78 Window* default_container = |
72 ash::Shell::GetInstance()->GetContainer( | 79 ash::Shell::GetInstance()->GetContainer( |
73 internal::kShellWindowId_DefaultContainer); | 80 internal::kShellWindowId_DefaultContainer); |
74 scoped_ptr<Window> window0(CreateTestWindowWithId(0, default_container)); | 81 scoped_ptr<Window> window0(CreateTestWindowWithId(0, default_container)); |
75 wm::ActivateWindow(window0.get()); | 82 wm::ActivateWindow(window0.get()); |
76 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); | 83 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); |
77 | 84 |
78 // Cycle focus to the status area | 85 // Cycle focus to the status area |
79 focus_cycler->RotateFocus(FocusCycler::FORWARD); | 86 focus_cycler->RotateFocus(FocusCycler::FORWARD); |
80 EXPECT_TRUE(status_widget->IsActive()); | 87 EXPECT_TRUE(tray->widget()->IsActive()); |
81 | 88 |
82 // Cycle focus to the launcher | 89 // Cycle focus to the launcher |
83 focus_cycler->RotateFocus(FocusCycler::FORWARD); | 90 focus_cycler->RotateFocus(FocusCycler::FORWARD); |
84 EXPECT_TRUE(launcher_widget->IsActive()); | 91 EXPECT_TRUE(launcher_widget->IsActive()); |
85 | 92 |
86 // Cycle focus to the browser | 93 // Cycle focus to the browser |
87 focus_cycler->RotateFocus(FocusCycler::FORWARD); | 94 focus_cycler->RotateFocus(FocusCycler::FORWARD); |
88 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); | 95 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); |
89 } | 96 } |
90 | 97 |
91 TEST_F(FocusCyclerTest, CycleFocusBackward) { | 98 TEST_F(FocusCyclerTest, CycleFocusBackward) { |
92 scoped_ptr<FocusCycler> focus_cycler(new FocusCycler()); | 99 scoped_ptr<FocusCycler> focus_cycler(new FocusCycler()); |
93 | 100 |
94 // Add the Status area | 101 // Add the Status area |
95 views::Widget* status_widget = internal::CreateStatusArea(NULL); | 102 scoped_ptr<SystemTray> tray(CreateSystemTray()); |
96 ASSERT_TRUE(status_widget); | 103 ASSERT_TRUE(tray->widget()); |
97 focus_cycler->AddWidget(status_widget); | 104 focus_cycler->AddWidget(tray->widget()); |
98 GetStatusAreaView(status_widget)->SetFocusCyclerForTesting( | 105 GetStatusAreaView(tray->widget())->SetFocusCyclerForTesting( |
99 focus_cycler.get()); | 106 focus_cycler.get()); |
100 | 107 |
101 // Add the launcher | 108 // Add the launcher |
102 Launcher* launcher = Shell::GetInstance()->launcher(); | 109 Launcher* launcher = Shell::GetInstance()->launcher(); |
103 ASSERT_TRUE(launcher); | 110 ASSERT_TRUE(launcher); |
104 views::Widget* launcher_widget = launcher->widget(); | 111 views::Widget* launcher_widget = launcher->widget(); |
105 ASSERT_TRUE(launcher_widget); | 112 ASSERT_TRUE(launcher_widget); |
106 launcher->SetFocusCycler(focus_cycler.get()); | 113 launcher->SetFocusCycler(focus_cycler.get()); |
107 | 114 |
108 // Create a single test window. | 115 // Create a single test window. |
109 Window* default_container = | 116 Window* default_container = |
110 ash::Shell::GetInstance()->GetContainer( | 117 ash::Shell::GetInstance()->GetContainer( |
111 internal::kShellWindowId_DefaultContainer); | 118 internal::kShellWindowId_DefaultContainer); |
112 scoped_ptr<Window> window0(CreateTestWindowWithId(0, default_container)); | 119 scoped_ptr<Window> window0(CreateTestWindowWithId(0, default_container)); |
113 wm::ActivateWindow(window0.get()); | 120 wm::ActivateWindow(window0.get()); |
114 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); | 121 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); |
115 | 122 |
116 // Cycle focus to the launcher | 123 // Cycle focus to the launcher |
117 focus_cycler->RotateFocus(FocusCycler::BACKWARD); | 124 focus_cycler->RotateFocus(FocusCycler::BACKWARD); |
118 EXPECT_TRUE(launcher_widget->IsActive()); | 125 EXPECT_TRUE(launcher_widget->IsActive()); |
119 | 126 |
120 // Cycle focus to the status area | 127 // Cycle focus to the status area |
121 focus_cycler->RotateFocus(FocusCycler::BACKWARD); | 128 focus_cycler->RotateFocus(FocusCycler::BACKWARD); |
122 EXPECT_TRUE(status_widget->IsActive()); | 129 EXPECT_TRUE(tray->widget()->IsActive()); |
123 | 130 |
124 // Cycle focus to the browser | 131 // Cycle focus to the browser |
125 focus_cycler->RotateFocus(FocusCycler::BACKWARD); | 132 focus_cycler->RotateFocus(FocusCycler::BACKWARD); |
126 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); | 133 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); |
127 } | 134 } |
128 | 135 |
129 class FocusCyclerLauncherTest : public AshTestBase { | 136 class FocusCyclerLauncherTest : public AshTestBase { |
130 public: | 137 public: |
131 FocusCyclerLauncherTest() : AshTestBase() {} | 138 FocusCyclerLauncherTest() : AshTestBase() {} |
132 virtual ~FocusCyclerLauncherTest() {} | 139 virtual ~FocusCyclerLauncherTest() {} |
(...skipping 21 matching lines...) Expand all Loading... |
154 } | 161 } |
155 | 162 |
156 private: | 163 private: |
157 DISALLOW_COPY_AND_ASSIGN(FocusCyclerLauncherTest); | 164 DISALLOW_COPY_AND_ASSIGN(FocusCyclerLauncherTest); |
158 }; | 165 }; |
159 | 166 |
160 TEST_F(FocusCyclerLauncherTest, CycleFocusForwardInvisible) { | 167 TEST_F(FocusCyclerLauncherTest, CycleFocusForwardInvisible) { |
161 scoped_ptr<FocusCycler> focus_cycler(new FocusCycler()); | 168 scoped_ptr<FocusCycler> focus_cycler(new FocusCycler()); |
162 | 169 |
163 // Add the Status area | 170 // Add the Status area |
164 views::Widget* status_widget = internal::CreateStatusArea(NULL); | 171 scoped_ptr<SystemTray> tray(CreateSystemTray()); |
165 ASSERT_TRUE(status_widget); | 172 ASSERT_TRUE(tray->widget()); |
166 focus_cycler->AddWidget(status_widget); | 173 focus_cycler->AddWidget(tray->widget()); |
167 GetStatusAreaView(status_widget)->SetFocusCyclerForTesting( | 174 GetStatusAreaView(tray->widget())->SetFocusCyclerForTesting( |
168 focus_cycler.get()); | 175 focus_cycler.get()); |
169 | 176 |
170 // Add the launcher | 177 // Add the launcher |
171 Launcher* launcher = Shell::GetInstance()->launcher(); | 178 Launcher* launcher = Shell::GetInstance()->launcher(); |
172 ASSERT_TRUE(launcher); | 179 ASSERT_TRUE(launcher); |
173 views::Widget* launcher_widget = launcher->widget(); | 180 views::Widget* launcher_widget = launcher->widget(); |
174 ASSERT_TRUE(launcher_widget); | 181 ASSERT_TRUE(launcher_widget); |
175 launcher->SetFocusCycler(focus_cycler.get()); | 182 launcher->SetFocusCycler(focus_cycler.get()); |
176 | 183 |
177 // Create a single test window. | 184 // Create a single test window. |
178 Window* default_container = | 185 Window* default_container = |
179 ash::Shell::GetInstance()->GetContainer( | 186 ash::Shell::GetInstance()->GetContainer( |
180 internal::kShellWindowId_DefaultContainer); | 187 internal::kShellWindowId_DefaultContainer); |
181 scoped_ptr<Window> window0(CreateTestWindowWithId(0, default_container)); | 188 scoped_ptr<Window> window0(CreateTestWindowWithId(0, default_container)); |
182 wm::ActivateWindow(window0.get()); | 189 wm::ActivateWindow(window0.get()); |
183 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); | 190 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); |
184 | 191 |
185 // Cycle focus to the status area | 192 // Cycle focus to the status area |
186 focus_cycler->RotateFocus(FocusCycler::FORWARD); | 193 focus_cycler->RotateFocus(FocusCycler::FORWARD); |
187 EXPECT_TRUE(status_widget->IsActive()); | 194 EXPECT_TRUE(tray->widget()->IsActive()); |
188 | 195 |
189 // Cycle focus to the browser | 196 // Cycle focus to the browser |
190 focus_cycler->RotateFocus(FocusCycler::FORWARD); | 197 focus_cycler->RotateFocus(FocusCycler::FORWARD); |
191 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); | 198 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); |
192 } | 199 } |
193 | 200 |
194 TEST_F(FocusCyclerLauncherTest, CycleFocusBackwardInvisible) { | 201 TEST_F(FocusCyclerLauncherTest, CycleFocusBackwardInvisible) { |
195 scoped_ptr<FocusCycler> focus_cycler(new FocusCycler()); | 202 scoped_ptr<FocusCycler> focus_cycler(new FocusCycler()); |
196 | 203 |
197 // Add the Status area | 204 // Add the Status area |
198 views::Widget* status_widget = internal::CreateStatusArea(NULL); | 205 scoped_ptr<SystemTray> tray(CreateSystemTray()); |
199 ASSERT_TRUE(status_widget); | 206 ASSERT_TRUE(tray->widget()); |
200 focus_cycler->AddWidget(status_widget); | 207 focus_cycler->AddWidget(tray->widget()); |
201 GetStatusAreaView(status_widget)->SetFocusCyclerForTesting( | 208 GetStatusAreaView(tray->widget())->SetFocusCyclerForTesting( |
202 focus_cycler.get()); | 209 focus_cycler.get()); |
203 | 210 |
204 // Add the launcher | 211 // Add the launcher |
205 Launcher* launcher = Shell::GetInstance()->launcher(); | 212 Launcher* launcher = Shell::GetInstance()->launcher(); |
206 ASSERT_TRUE(launcher); | 213 ASSERT_TRUE(launcher); |
207 views::Widget* launcher_widget = launcher->widget(); | 214 views::Widget* launcher_widget = launcher->widget(); |
208 ASSERT_TRUE(launcher_widget); | 215 ASSERT_TRUE(launcher_widget); |
209 launcher->SetFocusCycler(focus_cycler.get()); | 216 launcher->SetFocusCycler(focus_cycler.get()); |
210 | 217 |
211 // Create a single test window. | 218 // Create a single test window. |
212 Window* default_container = | 219 Window* default_container = |
213 ash::Shell::GetInstance()->GetContainer( | 220 ash::Shell::GetInstance()->GetContainer( |
214 internal::kShellWindowId_DefaultContainer); | 221 internal::kShellWindowId_DefaultContainer); |
215 scoped_ptr<Window> window0(CreateTestWindowWithId(0, default_container)); | 222 scoped_ptr<Window> window0(CreateTestWindowWithId(0, default_container)); |
216 wm::ActivateWindow(window0.get()); | 223 wm::ActivateWindow(window0.get()); |
217 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); | 224 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); |
218 | 225 |
219 // Cycle focus to the status area | 226 // Cycle focus to the status area |
220 focus_cycler->RotateFocus(FocusCycler::BACKWARD); | 227 focus_cycler->RotateFocus(FocusCycler::BACKWARD); |
221 EXPECT_TRUE(status_widget->IsActive()); | 228 EXPECT_TRUE(tray->widget()->IsActive()); |
222 | 229 |
223 // Cycle focus to the browser | 230 // Cycle focus to the browser |
224 focus_cycler->RotateFocus(FocusCycler::BACKWARD); | 231 focus_cycler->RotateFocus(FocusCycler::BACKWARD); |
225 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); | 232 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); |
226 } | 233 } |
227 | 234 |
228 } // namespace test | 235 } // namespace test |
229 } // namespace ash | 236 } // namespace ash |
OLD | NEW |