| 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/root_window_controller.h" | 8 #include "ash/root_window_controller.h" |
| 9 #include "ash/shelf/shelf_widget.h" |
| 9 #include "ash/shell.h" | 10 #include "ash/shell.h" |
| 10 #include "ash/shell_window_ids.h" | 11 #include "ash/shell_window_ids.h" |
| 11 #include "ash/system/status_area_widget.h" | 12 #include "ash/system/status_area_widget.h" |
| 12 #include "ash/system/status_area_widget_delegate.h" | 13 #include "ash/system/status_area_widget_delegate.h" |
| 13 #include "ash/system/tray/system_tray.h" | 14 #include "ash/system/tray/system_tray.h" |
| 14 #include "ash/wm/window_util.h" | 15 #include "ash/wm/window_util.h" |
| 15 #include "ash/test/ash_test_base.h" | 16 #include "ash/test/ash_test_base.h" |
| 16 #include "ash/shell_factory.h" | 17 #include "ash/shell_factory.h" |
| 17 #include "ui/aura/test/test_windows.h" | 18 #include "ui/aura/test/test_windows.h" |
| 18 #include "ui/aura/window.h" | 19 #include "ui/aura/window.h" |
| (...skipping 28 matching lines...) Expand all Loading... |
| 47 ASSERT_TRUE(Launcher::ForPrimaryDisplay()); | 48 ASSERT_TRUE(Launcher::ForPrimaryDisplay()); |
| 48 } | 49 } |
| 49 | 50 |
| 50 virtual void TearDown() OVERRIDE { | 51 virtual void TearDown() OVERRIDE { |
| 51 if (tray_.get()) { | 52 if (tray_.get()) { |
| 52 GetStatusAreaWidgetDelegate(tray_->GetWidget())-> | 53 GetStatusAreaWidgetDelegate(tray_->GetWidget())-> |
| 53 SetFocusCyclerForTesting(NULL); | 54 SetFocusCyclerForTesting(NULL); |
| 54 tray_.reset(); | 55 tray_.reset(); |
| 55 } | 56 } |
| 56 | 57 |
| 57 Launcher::ForPrimaryDisplay()->SetFocusCycler(NULL); | 58 shelf_widget()->SetFocusCycler(NULL); |
| 58 | 59 |
| 59 focus_cycler_.reset(); | 60 focus_cycler_.reset(); |
| 60 | 61 |
| 61 AshTestBase::TearDown(); | 62 AshTestBase::TearDown(); |
| 62 } | 63 } |
| 63 | 64 |
| 64 protected: | 65 protected: |
| 65 // Creates the system tray, returning true on success. | 66 // Creates the system tray, returning true on success. |
| 66 bool CreateTray() { | 67 bool CreateTray() { |
| 67 if (tray_.get()) | 68 if (tray_.get()) |
| (...skipping 10 matching lines...) Expand all Loading... |
| 78 focus_cycler_->AddWidget(tray()->GetWidget()); | 79 focus_cycler_->AddWidget(tray()->GetWidget()); |
| 79 GetStatusAreaWidgetDelegate(tray_->GetWidget())->SetFocusCyclerForTesting( | 80 GetStatusAreaWidgetDelegate(tray_->GetWidget())->SetFocusCyclerForTesting( |
| 80 focus_cycler()); | 81 focus_cycler()); |
| 81 return true; | 82 return true; |
| 82 } | 83 } |
| 83 | 84 |
| 84 FocusCycler* focus_cycler() { return focus_cycler_.get(); } | 85 FocusCycler* focus_cycler() { return focus_cycler_.get(); } |
| 85 | 86 |
| 86 SystemTray* tray() { return tray_.get(); } | 87 SystemTray* tray() { return tray_.get(); } |
| 87 | 88 |
| 88 views::Widget* launcher_widget() { | 89 ShelfWidget* shelf_widget() { |
| 89 return Launcher::ForPrimaryDisplay()->widget(); | 90 return Launcher::ForPrimaryDisplay()->shelf_widget(); |
| 90 } | 91 } |
| 91 | 92 |
| 92 void InstallFocusCycleOnLauncher() { | 93 void InstallFocusCycleOnShelf() { |
| 93 // Add the launcher | 94 // Add the shelf. |
| 94 Launcher* launcher = Launcher::ForPrimaryDisplay(); | 95 shelf_widget()->SetFocusCycler(focus_cycler()); |
| 95 launcher->SetFocusCycler(focus_cycler()); | |
| 96 } | 96 } |
| 97 | 97 |
| 98 private: | 98 private: |
| 99 scoped_ptr<FocusCycler> focus_cycler_; | 99 scoped_ptr<FocusCycler> focus_cycler_; |
| 100 scoped_ptr<SystemTray> tray_; | 100 scoped_ptr<SystemTray> tray_; |
| 101 | 101 |
| 102 DISALLOW_COPY_AND_ASSIGN(FocusCyclerTest); | 102 DISALLOW_COPY_AND_ASSIGN(FocusCyclerTest); |
| 103 }; | 103 }; |
| 104 | 104 |
| 105 TEST_F(FocusCyclerTest, CycleFocusBrowserOnly) { | 105 TEST_F(FocusCyclerTest, CycleFocusBrowserOnly) { |
| 106 // Create a single test window. | 106 // Create a single test window. |
| 107 scoped_ptr<Window> window0(CreateTestWindowInShellWithId(0)); | 107 scoped_ptr<Window> window0(CreateTestWindowInShellWithId(0)); |
| 108 wm::ActivateWindow(window0.get()); | 108 wm::ActivateWindow(window0.get()); |
| 109 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); | 109 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); |
| 110 | 110 |
| 111 // Cycle the window | 111 // Cycle the window |
| 112 focus_cycler()->RotateFocus(FocusCycler::FORWARD); | 112 focus_cycler()->RotateFocus(FocusCycler::FORWARD); |
| 113 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); | 113 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); |
| 114 } | 114 } |
| 115 | 115 |
| 116 TEST_F(FocusCyclerTest, CycleFocusForward) { | 116 TEST_F(FocusCyclerTest, CycleFocusForward) { |
| 117 ASSERT_TRUE(CreateTray()); | 117 ASSERT_TRUE(CreateTray()); |
| 118 | 118 |
| 119 InstallFocusCycleOnLauncher(); | 119 InstallFocusCycleOnShelf(); |
| 120 | 120 |
| 121 // Create a single test window. | 121 // Create a single test window. |
| 122 scoped_ptr<Window> window0(CreateTestWindowInShellWithId(0)); | 122 scoped_ptr<Window> window0(CreateTestWindowInShellWithId(0)); |
| 123 wm::ActivateWindow(window0.get()); | 123 wm::ActivateWindow(window0.get()); |
| 124 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); | 124 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); |
| 125 | 125 |
| 126 // Cycle focus to the status area | 126 // Cycle focus to the status area |
| 127 focus_cycler()->RotateFocus(FocusCycler::FORWARD); | 127 focus_cycler()->RotateFocus(FocusCycler::FORWARD); |
| 128 EXPECT_TRUE(tray()->GetWidget()->IsActive()); | 128 EXPECT_TRUE(tray()->GetWidget()->IsActive()); |
| 129 | 129 |
| 130 // Cycle focus to the launcher | 130 // Cycle focus to the shelf |
| 131 focus_cycler()->RotateFocus(FocusCycler::FORWARD); | 131 focus_cycler()->RotateFocus(FocusCycler::FORWARD); |
| 132 EXPECT_TRUE(launcher_widget()->IsActive()); | 132 EXPECT_TRUE(shelf_widget()->IsActive()); |
| 133 | 133 |
| 134 // Cycle focus to the browser | 134 // Cycle focus to the browser |
| 135 focus_cycler()->RotateFocus(FocusCycler::FORWARD); | 135 focus_cycler()->RotateFocus(FocusCycler::FORWARD); |
| 136 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); | 136 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); |
| 137 } | 137 } |
| 138 | 138 |
| 139 TEST_F(FocusCyclerTest, CycleFocusBackward) { | 139 TEST_F(FocusCyclerTest, CycleFocusBackward) { |
| 140 ASSERT_TRUE(CreateTray()); | 140 ASSERT_TRUE(CreateTray()); |
| 141 | 141 |
| 142 InstallFocusCycleOnLauncher(); | 142 InstallFocusCycleOnShelf(); |
| 143 | 143 |
| 144 // Create a single test window. | 144 // Create a single test window. |
| 145 scoped_ptr<Window> window0(CreateTestWindowInShellWithId(0)); | 145 scoped_ptr<Window> window0(CreateTestWindowInShellWithId(0)); |
| 146 wm::ActivateWindow(window0.get()); | 146 wm::ActivateWindow(window0.get()); |
| 147 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); | 147 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); |
| 148 | 148 |
| 149 // Cycle focus to the launcher | 149 // Cycle focus to the launcher |
| 150 focus_cycler()->RotateFocus(FocusCycler::BACKWARD); | 150 focus_cycler()->RotateFocus(FocusCycler::BACKWARD); |
| 151 EXPECT_TRUE(launcher_widget()->IsActive()); | 151 EXPECT_TRUE(shelf_widget()->IsActive()); |
| 152 | 152 |
| 153 // Cycle focus to the status area | 153 // Cycle focus to the status area |
| 154 focus_cycler()->RotateFocus(FocusCycler::BACKWARD); | 154 focus_cycler()->RotateFocus(FocusCycler::BACKWARD); |
| 155 EXPECT_TRUE(tray()->GetWidget()->IsActive()); | 155 EXPECT_TRUE(tray()->GetWidget()->IsActive()); |
| 156 | 156 |
| 157 // Cycle focus to the browser | 157 // Cycle focus to the browser |
| 158 focus_cycler()->RotateFocus(FocusCycler::BACKWARD); | 158 focus_cycler()->RotateFocus(FocusCycler::BACKWARD); |
| 159 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); | 159 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); |
| 160 } | 160 } |
| 161 | 161 |
| 162 TEST_F(FocusCyclerTest, CycleFocusForwardBackward) { | 162 TEST_F(FocusCyclerTest, CycleFocusForwardBackward) { |
| 163 ASSERT_TRUE(CreateTray()); | 163 ASSERT_TRUE(CreateTray()); |
| 164 | 164 |
| 165 InstallFocusCycleOnLauncher(); | 165 InstallFocusCycleOnShelf(); |
| 166 | 166 |
| 167 // Create a single test window. | 167 // Create a single test window. |
| 168 scoped_ptr<Window> window0(CreateTestWindowInShellWithId(0)); | 168 scoped_ptr<Window> window0(CreateTestWindowInShellWithId(0)); |
| 169 wm::ActivateWindow(window0.get()); | 169 wm::ActivateWindow(window0.get()); |
| 170 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); | 170 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); |
| 171 | 171 |
| 172 // Cycle focus to the launcher | 172 // Cycle focus to the shelf |
| 173 focus_cycler()->RotateFocus(FocusCycler::BACKWARD); | 173 focus_cycler()->RotateFocus(FocusCycler::BACKWARD); |
| 174 EXPECT_TRUE(launcher_widget()->IsActive()); | 174 EXPECT_TRUE(shelf_widget()->IsActive()); |
| 175 | 175 |
| 176 // Cycle focus to the status area | 176 // Cycle focus to the status area |
| 177 focus_cycler()->RotateFocus(FocusCycler::BACKWARD); | 177 focus_cycler()->RotateFocus(FocusCycler::BACKWARD); |
| 178 EXPECT_TRUE(tray()->GetWidget()->IsActive()); | 178 EXPECT_TRUE(tray()->GetWidget()->IsActive()); |
| 179 | 179 |
| 180 // Cycle focus to the browser | 180 // Cycle focus to the browser |
| 181 focus_cycler()->RotateFocus(FocusCycler::BACKWARD); | 181 focus_cycler()->RotateFocus(FocusCycler::BACKWARD); |
| 182 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); | 182 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); |
| 183 | 183 |
| 184 // Cycle focus to the status area | 184 // Cycle focus to the status area |
| 185 focus_cycler()->RotateFocus(FocusCycler::FORWARD); | 185 focus_cycler()->RotateFocus(FocusCycler::FORWARD); |
| 186 EXPECT_TRUE(tray()->GetWidget()->IsActive()); | 186 EXPECT_TRUE(tray()->GetWidget()->IsActive()); |
| 187 | 187 |
| 188 // Cycle focus to the launcher | 188 // Cycle focus to the launcher |
| 189 focus_cycler()->RotateFocus(FocusCycler::FORWARD); | 189 focus_cycler()->RotateFocus(FocusCycler::FORWARD); |
| 190 EXPECT_TRUE(launcher_widget()->IsActive()); | 190 EXPECT_TRUE(shelf_widget()->IsActive()); |
| 191 | 191 |
| 192 // Cycle focus to the browser | 192 // Cycle focus to the browser |
| 193 focus_cycler()->RotateFocus(FocusCycler::FORWARD); | 193 focus_cycler()->RotateFocus(FocusCycler::FORWARD); |
| 194 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); | 194 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); |
| 195 } | 195 } |
| 196 | 196 |
| 197 TEST_F(FocusCyclerTest, CycleFocusNoBrowser) { | 197 TEST_F(FocusCyclerTest, CycleFocusNoBrowser) { |
| 198 ASSERT_TRUE(CreateTray()); | 198 ASSERT_TRUE(CreateTray()); |
| 199 | 199 |
| 200 InstallFocusCycleOnLauncher(); | 200 InstallFocusCycleOnShelf(); |
| 201 | 201 |
| 202 // Add the launcher and focus it | 202 // Add the launcher and focus it |
| 203 focus_cycler()->FocusWidget(launcher_widget()); | 203 focus_cycler()->FocusWidget(shelf_widget()); |
| 204 | 204 |
| 205 // Cycle focus to the status area | 205 // Cycle focus to the status area |
| 206 focus_cycler()->RotateFocus(FocusCycler::FORWARD); | 206 focus_cycler()->RotateFocus(FocusCycler::FORWARD); |
| 207 EXPECT_TRUE(tray()->GetWidget()->IsActive()); | 207 EXPECT_TRUE(tray()->GetWidget()->IsActive()); |
| 208 | 208 |
| 209 // Cycle focus to the launcher | 209 // Cycle focus to the shelf |
| 210 focus_cycler()->RotateFocus(FocusCycler::FORWARD); | 210 focus_cycler()->RotateFocus(FocusCycler::FORWARD); |
| 211 EXPECT_TRUE(launcher_widget()->IsActive()); | 211 EXPECT_TRUE(shelf_widget()->IsActive()); |
| 212 | 212 |
| 213 // Cycle focus to the status area | 213 // Cycle focus to the status area |
| 214 focus_cycler()->RotateFocus(FocusCycler::FORWARD); | 214 focus_cycler()->RotateFocus(FocusCycler::FORWARD); |
| 215 EXPECT_TRUE(tray()->GetWidget()->IsActive()); | 215 EXPECT_TRUE(tray()->GetWidget()->IsActive()); |
| 216 | 216 |
| 217 // Cycle focus to the launcher | 217 // Cycle focus to the launcher |
| 218 focus_cycler()->RotateFocus(FocusCycler::BACKWARD); | 218 focus_cycler()->RotateFocus(FocusCycler::BACKWARD); |
| 219 EXPECT_TRUE(launcher_widget()->IsActive()); | 219 EXPECT_TRUE(shelf_widget()->IsActive()); |
| 220 | 220 |
| 221 // Cycle focus to the status area | 221 // Cycle focus to the status area |
| 222 focus_cycler()->RotateFocus(FocusCycler::BACKWARD); | 222 focus_cycler()->RotateFocus(FocusCycler::BACKWARD); |
| 223 EXPECT_TRUE(tray()->GetWidget()->IsActive()); | 223 EXPECT_TRUE(tray()->GetWidget()->IsActive()); |
| 224 } | 224 } |
| 225 | 225 |
| 226 TEST_F(FocusCyclerTest, Launcher_CycleFocusForward) { | 226 TEST_F(FocusCyclerTest, Shelf_CycleFocusForward) { |
| 227 ASSERT_TRUE(CreateTray()); | 227 ASSERT_TRUE(CreateTray()); |
| 228 InstallFocusCycleOnLauncher(); | 228 InstallFocusCycleOnShelf(); |
| 229 launcher_widget()->Hide(); | 229 shelf_widget()->Hide(); |
| 230 | 230 |
| 231 // Create a single test window. | 231 // Create a single test window. |
| 232 scoped_ptr<Window> window0(CreateTestWindowInShellWithId(0)); | 232 scoped_ptr<Window> window0(CreateTestWindowInShellWithId(0)); |
| 233 wm::ActivateWindow(window0.get()); | 233 wm::ActivateWindow(window0.get()); |
| 234 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); | 234 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); |
| 235 | 235 |
| 236 // Cycle focus to the status area | 236 // Cycle focus to the status area |
| 237 focus_cycler()->RotateFocus(FocusCycler::FORWARD); | 237 focus_cycler()->RotateFocus(FocusCycler::FORWARD); |
| 238 EXPECT_TRUE(tray()->GetWidget()->IsActive()); | 238 EXPECT_TRUE(tray()->GetWidget()->IsActive()); |
| 239 | 239 |
| 240 // Cycle focus to the browser | 240 // Cycle focus to the browser |
| 241 focus_cycler()->RotateFocus(FocusCycler::FORWARD); | 241 focus_cycler()->RotateFocus(FocusCycler::FORWARD); |
| 242 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); | 242 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); |
| 243 } | 243 } |
| 244 | 244 |
| 245 TEST_F(FocusCyclerTest, Launcher_CycleFocusBackwardInvisible) { | 245 TEST_F(FocusCyclerTest, Shelf_CycleFocusBackwardInvisible) { |
| 246 ASSERT_TRUE(CreateTray()); | 246 ASSERT_TRUE(CreateTray()); |
| 247 InstallFocusCycleOnLauncher(); | 247 InstallFocusCycleOnShelf(); |
| 248 launcher_widget()->Hide(); | 248 shelf_widget()->Hide(); |
| 249 | 249 |
| 250 // Create a single test window. | 250 // Create a single test window. |
| 251 scoped_ptr<Window> window0(CreateTestWindowInShellWithId(0)); | 251 scoped_ptr<Window> window0(CreateTestWindowInShellWithId(0)); |
| 252 wm::ActivateWindow(window0.get()); | 252 wm::ActivateWindow(window0.get()); |
| 253 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); | 253 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); |
| 254 | 254 |
| 255 // Cycle focus to the status area | 255 // Cycle focus to the status area |
| 256 focus_cycler()->RotateFocus(FocusCycler::BACKWARD); | 256 focus_cycler()->RotateFocus(FocusCycler::BACKWARD); |
| 257 EXPECT_TRUE(tray()->GetWidget()->IsActive()); | 257 EXPECT_TRUE(tray()->GetWidget()->IsActive()); |
| 258 | 258 |
| 259 // Cycle focus to the browser | 259 // Cycle focus to the browser |
| 260 focus_cycler()->RotateFocus(FocusCycler::BACKWARD); | 260 focus_cycler()->RotateFocus(FocusCycler::BACKWARD); |
| 261 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); | 261 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); |
| 262 } | 262 } |
| 263 | 263 |
| 264 } // namespace test | 264 } // namespace test |
| 265 } // namespace ash | 265 } // namespace ash |
| OLD | NEW |