Move policy and rationale permission handling to public Window class.
[chromium-blink-merge.git] / ash / wm / window_cycle_controller_unittest.cc
blob6a19cbbcfa9ab370008e1aa832254b6c16dc100f
1 // Copyright 2014 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.
5 #include "ash/wm/window_cycle_controller.h"
7 #include <algorithm>
9 #include "ash/session/session_state_delegate.h"
10 #include "ash/shelf/shelf.h"
11 #include "ash/shelf/shelf_widget.h"
12 #include "ash/shell.h"
13 #include "ash/shell_window_ids.h"
14 #include "ash/test/ash_test_base.h"
15 #include "ash/test/shelf_test_api.h"
16 #include "ash/test/shelf_view_test_api.h"
17 #include "ash/test/test_shelf_delegate.h"
18 #include "ash/test/test_shell_delegate.h"
19 #include "ash/wm/window_cycle_list.h"
20 #include "ash/wm/window_state.h"
21 #include "ash/wm/window_util.h"
22 #include "base/memory/scoped_ptr.h"
23 #include "ui/aura/client/aura_constants.h"
24 #include "ui/aura/client/screen_position_client.h"
25 #include "ui/aura/env.h"
26 #include "ui/aura/test/test_windows.h"
27 #include "ui/aura/window.h"
28 #include "ui/aura/window_event_dispatcher.h"
29 #include "ui/gfx/geometry/rect.h"
30 #include "ui/gfx/screen.h"
32 namespace ash {
34 using aura::test::CreateTestWindowWithId;
35 using aura::test::TestWindowDelegate;
36 using aura::Window;
38 class WindowCycleControllerTest : public test::AshTestBase {
39 public:
40 WindowCycleControllerTest() {}
41 ~WindowCycleControllerTest() override {}
43 void SetUp() override {
44 test::AshTestBase::SetUp();
45 ASSERT_TRUE(test::TestShelfDelegate::instance());
47 shelf_view_test_.reset(new test::ShelfViewTestAPI(
48 test::ShelfTestAPI(Shelf::ForPrimaryDisplay()).shelf_view()));
49 shelf_view_test_->SetAnimationDuration(1);
52 aura::Window* CreatePanelWindow() {
53 gfx::Rect rect(100, 100);
54 aura::Window* window = CreateTestWindowInShellWithDelegateAndType(
55 NULL, ui::wm::WINDOW_TYPE_PANEL, 0, rect);
56 test::TestShelfDelegate::instance()->AddShelfItem(window);
57 shelf_view_test_->RunMessageLoopUntilAnimationsDone();
58 return window;
61 const WindowCycleList::WindowList& GetWindows(
62 WindowCycleController* controller) {
63 return controller->window_cycle_list()->windows();
66 private:
67 scoped_ptr<test::ShelfViewTestAPI> shelf_view_test_;
69 DISALLOW_COPY_AND_ASSIGN(WindowCycleControllerTest);
72 TEST_F(WindowCycleControllerTest, HandleCycleWindowBaseCases) {
73 WindowCycleController* controller =
74 Shell::GetInstance()->window_cycle_controller();
76 // Cycling doesn't crash if there are no windows.
77 controller->HandleCycleWindow(WindowCycleController::FORWARD);
79 // Create a single test window.
80 scoped_ptr<Window> window0(CreateTestWindowInShellWithId(0));
81 wm::ActivateWindow(window0.get());
82 EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
84 // Cycling works for a single window, even though nothing changes.
85 controller->HandleCycleWindow(WindowCycleController::FORWARD);
86 EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
89 // Verifies if there is only one window and it isn't active that cycling
90 // activates it.
91 TEST_F(WindowCycleControllerTest, SingleWindowNotActive) {
92 WindowCycleController* controller =
93 Shell::GetInstance()->window_cycle_controller();
95 // Create a single test window.
96 scoped_ptr<Window> window0(CreateTestWindowInShellWithId(0));
97 wm::ActivateWindow(window0.get());
98 EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
100 // Rotate focus, this should move focus to another window that isn't part of
101 // the default container.
102 Shell::GetInstance()->RotateFocus(Shell::FORWARD);
103 EXPECT_FALSE(wm::IsActiveWindow(window0.get()));
105 // Cycling should activate the window.
106 controller->HandleCycleWindow(WindowCycleController::FORWARD);
107 EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
110 TEST_F(WindowCycleControllerTest, HandleCycleWindow) {
111 WindowCycleController* controller =
112 Shell::GetInstance()->window_cycle_controller();
114 // Set up several windows to use to test cycling. Create them in reverse
115 // order so they are stacked 0 over 1 over 2.
116 scoped_ptr<Window> window2(CreateTestWindowInShellWithId(2));
117 scoped_ptr<Window> window1(CreateTestWindowInShellWithId(1));
118 scoped_ptr<Window> window0(CreateTestWindowInShellWithId(0));
119 wm::ActivateWindow(window0.get());
121 // Simulate pressing and releasing Alt-tab.
122 EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
123 controller->HandleCycleWindow(WindowCycleController::FORWARD);
125 // Window lists should return the topmost window in front.
126 ASSERT_TRUE(controller->window_cycle_list());
127 ASSERT_EQ(3u, GetWindows(controller).size());
128 ASSERT_EQ(window0.get(), GetWindows(controller)[0]);
129 ASSERT_EQ(window1.get(), GetWindows(controller)[1]);
130 ASSERT_EQ(window2.get(), GetWindows(controller)[2]);
132 controller->StopCycling();
133 EXPECT_TRUE(wm::IsActiveWindow(window1.get()));
135 // Pressing and releasing Alt-tab again should cycle back to the most-
136 // recently-used window in the current child order.
137 controller->HandleCycleWindow(WindowCycleController::FORWARD);
138 controller->StopCycling();
139 EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
141 // Pressing Alt-tab multiple times without releasing Alt should cycle through
142 // all the windows and wrap around.
143 controller->HandleCycleWindow(WindowCycleController::FORWARD);
144 EXPECT_TRUE(controller->IsCycling());
145 EXPECT_TRUE(wm::IsActiveWindow(window1.get()));
147 controller->HandleCycleWindow(WindowCycleController::FORWARD);
148 EXPECT_TRUE(controller->IsCycling());
149 EXPECT_TRUE(wm::IsActiveWindow(window2.get()));
151 controller->HandleCycleWindow(WindowCycleController::FORWARD);
152 EXPECT_TRUE(controller->IsCycling());
153 EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
155 controller->StopCycling();
156 EXPECT_FALSE(controller->IsCycling());
157 EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
159 // Reset our stacking order.
160 wm::ActivateWindow(window2.get());
161 wm::ActivateWindow(window1.get());
162 wm::ActivateWindow(window0.get());
164 // Likewise we can cycle backwards through all the windows.
165 controller->HandleCycleWindow(WindowCycleController::BACKWARD);
166 EXPECT_TRUE(wm::IsActiveWindow(window2.get()));
167 controller->HandleCycleWindow(WindowCycleController::BACKWARD);
168 EXPECT_TRUE(wm::IsActiveWindow(window1.get()));
169 controller->HandleCycleWindow(WindowCycleController::BACKWARD);
170 EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
171 controller->StopCycling();
172 EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
174 // When the screen is locked, cycling window does not take effect.
175 Shell::GetInstance()->session_state_delegate()->LockScreen();
176 EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
177 controller->HandleCycleWindow(WindowCycleController::FORWARD);
178 EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
179 controller->HandleCycleWindow(WindowCycleController::BACKWARD);
180 EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
182 Shell::GetInstance()->session_state_delegate()->UnlockScreen();
183 EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
184 controller->HandleCycleWindow(WindowCycleController::FORWARD);
185 EXPECT_TRUE(wm::IsActiveWindow(window1.get()));
186 controller->HandleCycleWindow(WindowCycleController::FORWARD);
187 EXPECT_TRUE(wm::IsActiveWindow(window2.get()));
189 // When a modal window is active, cycling window does not take effect.
190 aura::Window* modal_container =
191 ash::Shell::GetContainer(
192 Shell::GetPrimaryRootWindow(),
193 kShellWindowId_SystemModalContainer);
194 scoped_ptr<Window> modal_window(
195 CreateTestWindowWithId(-2, modal_container));
196 modal_window->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_SYSTEM);
197 wm::ActivateWindow(modal_window.get());
198 EXPECT_TRUE(wm::IsActiveWindow(modal_window.get()));
199 controller->HandleCycleWindow(WindowCycleController::FORWARD);
200 EXPECT_TRUE(wm::IsActiveWindow(modal_window.get()));
201 EXPECT_FALSE(wm::IsActiveWindow(window0.get()));
202 EXPECT_FALSE(wm::IsActiveWindow(window1.get()));
203 EXPECT_FALSE(wm::IsActiveWindow(window2.get()));
204 controller->HandleCycleWindow(WindowCycleController::BACKWARD);
205 EXPECT_TRUE(wm::IsActiveWindow(modal_window.get()));
206 EXPECT_FALSE(wm::IsActiveWindow(window0.get()));
207 EXPECT_FALSE(wm::IsActiveWindow(window1.get()));
208 EXPECT_FALSE(wm::IsActiveWindow(window2.get()));
211 // Cycles between a maximized and normal window.
212 TEST_F(WindowCycleControllerTest, MaximizedWindow) {
213 // Create a couple of test windows.
214 scoped_ptr<Window> window0(CreateTestWindowInShellWithId(0));
215 scoped_ptr<Window> window1(CreateTestWindowInShellWithId(1));
216 wm::WindowState* window1_state = wm::GetWindowState(window1.get());
217 window1_state->Maximize();
218 window1_state->Activate();
219 EXPECT_TRUE(window1_state->IsActive());
221 // Rotate focus, this should move focus to window0.
222 WindowCycleController* controller =
223 Shell::GetInstance()->window_cycle_controller();
224 controller->HandleCycleWindow(WindowCycleController::FORWARD);
225 EXPECT_TRUE(wm::GetWindowState(window0.get())->IsActive());
227 // One more time.
228 controller->HandleCycleWindow(WindowCycleController::FORWARD);
229 EXPECT_TRUE(window1_state->IsActive());
232 // Cycles to a minimized window.
233 TEST_F(WindowCycleControllerTest, Minimized) {
234 // Create a couple of test windows.
235 scoped_ptr<Window> window0(CreateTestWindowInShellWithId(0));
236 scoped_ptr<Window> window1(CreateTestWindowInShellWithId(1));
237 wm::WindowState* window0_state = wm::GetWindowState(window0.get());
238 wm::WindowState* window1_state = wm::GetWindowState(window1.get());
240 window1_state->Minimize();
241 window0_state->Activate();
242 EXPECT_TRUE(window0_state->IsActive());
244 // Rotate focus, this should move focus to window1 and unminimize it.
245 WindowCycleController* controller =
246 Shell::GetInstance()->window_cycle_controller();
247 controller->HandleCycleWindow(WindowCycleController::FORWARD);
248 EXPECT_FALSE(window1_state->IsMinimized());
249 EXPECT_TRUE(window1_state->IsActive());
251 // One more time back to w0.
252 controller->HandleCycleWindow(WindowCycleController::FORWARD);
253 EXPECT_TRUE(window0_state->IsActive());
256 TEST_F(WindowCycleControllerTest, AlwaysOnTopWindow) {
257 WindowCycleController* controller =
258 Shell::GetInstance()->window_cycle_controller();
260 // Set up several windows to use to test cycling.
261 scoped_ptr<Window> window0(CreateTestWindowInShellWithId(0));
262 scoped_ptr<Window> window1(CreateTestWindowInShellWithId(1));
264 Window* top_container =
265 Shell::GetContainer(
266 Shell::GetPrimaryRootWindow(),
267 kShellWindowId_AlwaysOnTopContainer);
268 scoped_ptr<Window> window2(CreateTestWindowWithId(2, top_container));
269 wm::ActivateWindow(window0.get());
271 // Simulate pressing and releasing Alt-tab.
272 EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
273 controller->HandleCycleWindow(WindowCycleController::FORWARD);
275 // Window lists should return the topmost window in front.
276 ASSERT_TRUE(controller->window_cycle_list());
277 ASSERT_EQ(3u, GetWindows(controller).size());
278 EXPECT_EQ(window0.get(), GetWindows(controller)[0]);
279 EXPECT_EQ(window2.get(), GetWindows(controller)[1]);
280 EXPECT_EQ(window1.get(), GetWindows(controller)[2]);
282 controller->StopCycling();
283 EXPECT_TRUE(wm::IsActiveWindow(window2.get()));
285 controller->HandleCycleWindow(WindowCycleController::FORWARD);
286 EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
288 controller->StopCycling();
290 controller->HandleCycleWindow(WindowCycleController::FORWARD);
291 EXPECT_TRUE(wm::IsActiveWindow(window2.get()));
293 controller->HandleCycleWindow(WindowCycleController::FORWARD);
294 EXPECT_TRUE(wm::IsActiveWindow(window1.get()));
296 controller->HandleCycleWindow(WindowCycleController::FORWARD);
297 EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
300 TEST_F(WindowCycleControllerTest, AlwaysOnTopMultiWindow) {
301 WindowCycleController* controller =
302 Shell::GetInstance()->window_cycle_controller();
304 // Set up several windows to use to test cycling.
305 scoped_ptr<Window> window0(CreateTestWindowInShellWithId(0));
306 scoped_ptr<Window> window1(CreateTestWindowInShellWithId(1));
308 Window* top_container =
309 Shell::GetContainer(
310 Shell::GetPrimaryRootWindow(),
311 kShellWindowId_AlwaysOnTopContainer);
312 scoped_ptr<Window> window2(CreateTestWindowWithId(2, top_container));
313 scoped_ptr<Window> window3(CreateTestWindowWithId(3, top_container));
314 wm::ActivateWindow(window0.get());
316 // Simulate pressing and releasing Alt-tab.
317 EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
318 controller->HandleCycleWindow(WindowCycleController::FORWARD);
320 // Window lists should return the topmost window in front.
321 ASSERT_TRUE(controller->window_cycle_list());
322 ASSERT_EQ(4u, GetWindows(controller).size());
323 EXPECT_EQ(window0.get(), GetWindows(controller)[0]);
324 EXPECT_EQ(window3.get(), GetWindows(controller)[1]);
325 EXPECT_EQ(window2.get(), GetWindows(controller)[2]);
326 EXPECT_EQ(window1.get(), GetWindows(controller)[3]);
328 controller->StopCycling();
329 EXPECT_TRUE(wm::IsActiveWindow(window3.get()));
331 controller->HandleCycleWindow(WindowCycleController::FORWARD);
332 EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
334 controller->StopCycling();
336 controller->HandleCycleWindow(WindowCycleController::FORWARD);
337 EXPECT_TRUE(wm::IsActiveWindow(window3.get()));
339 controller->HandleCycleWindow(WindowCycleController::FORWARD);
340 EXPECT_TRUE(wm::IsActiveWindow(window2.get()));
342 controller->HandleCycleWindow(WindowCycleController::FORWARD);
343 EXPECT_TRUE(wm::IsActiveWindow(window1.get()));
345 controller->HandleCycleWindow(WindowCycleController::FORWARD);
346 EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
349 TEST_F(WindowCycleControllerTest, AlwaysOnTopMultipleRootWindows) {
350 if (!SupportsMultipleDisplays())
351 return;
353 // Set up a second root window
354 UpdateDisplay("1000x600,600x400");
355 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
356 ASSERT_EQ(2U, root_windows.size());
358 WindowCycleController* controller =
359 Shell::GetInstance()->window_cycle_controller();
361 Shell::GetInstance()->set_target_root_window(root_windows[0]);
363 // Create two windows in the primary root.
364 scoped_ptr<Window> window0(CreateTestWindowInShellWithId(0));
365 EXPECT_EQ(root_windows[0], window0->GetRootWindow());
366 Window* top_container0 =
367 Shell::GetContainer(
368 root_windows[0],
369 kShellWindowId_AlwaysOnTopContainer);
370 scoped_ptr<Window> window1(CreateTestWindowWithId(1, top_container0));
371 EXPECT_EQ(root_windows[0], window1->GetRootWindow());
373 // And two on the secondary root.
374 Shell::GetInstance()->set_target_root_window(root_windows[1]);
375 scoped_ptr<Window> window2(CreateTestWindowInShellWithId(2));
376 EXPECT_EQ(root_windows[1], window2->GetRootWindow());
378 Window* top_container1 =
379 Shell::GetContainer(
380 root_windows[1],
381 kShellWindowId_AlwaysOnTopContainer);
382 scoped_ptr<Window> window3(CreateTestWindowWithId(3, top_container1));
383 EXPECT_EQ(root_windows[1], window3->GetRootWindow());
385 // Move the active root window to the secondary.
386 Shell::GetInstance()->set_target_root_window(root_windows[1]);
388 wm::ActivateWindow(window2.get());
390 EXPECT_EQ(root_windows[0], window0->GetRootWindow());
391 EXPECT_EQ(root_windows[0], window1->GetRootWindow());
392 EXPECT_EQ(root_windows[1], window2->GetRootWindow());
393 EXPECT_EQ(root_windows[1], window3->GetRootWindow());
395 // Simulate pressing and releasing Alt-tab.
396 EXPECT_TRUE(wm::IsActiveWindow(window2.get()));
397 controller->HandleCycleWindow(WindowCycleController::FORWARD);
399 // Window lists should return the topmost window in front.
400 ASSERT_TRUE(controller->window_cycle_list());
401 ASSERT_EQ(4u, GetWindows(controller).size());
402 EXPECT_EQ(window2.get(), GetWindows(controller)[0]);
403 EXPECT_EQ(window3.get(), GetWindows(controller)[1]);
404 EXPECT_EQ(window1.get(), GetWindows(controller)[2]);
405 EXPECT_EQ(window0.get(), GetWindows(controller)[3]);
407 controller->StopCycling();
408 EXPECT_TRUE(wm::IsActiveWindow(window3.get()));
410 controller->HandleCycleWindow(WindowCycleController::FORWARD);
411 EXPECT_TRUE(wm::IsActiveWindow(window2.get()));
413 controller->StopCycling();
415 controller->HandleCycleWindow(WindowCycleController::FORWARD);
416 EXPECT_TRUE(wm::IsActiveWindow(window3.get()));
418 controller->HandleCycleWindow(WindowCycleController::FORWARD);
419 EXPECT_TRUE(wm::IsActiveWindow(window1.get()));
421 controller->HandleCycleWindow(WindowCycleController::FORWARD);
422 EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
424 controller->HandleCycleWindow(WindowCycleController::FORWARD);
425 EXPECT_TRUE(wm::IsActiveWindow(window2.get()));
428 TEST_F(WindowCycleControllerTest, MostRecentlyUsed) {
429 WindowCycleController* controller =
430 Shell::GetInstance()->window_cycle_controller();
432 // Set up several windows to use to test cycling.
433 scoped_ptr<Window> window0(CreateTestWindowInShellWithId(0));
434 scoped_ptr<Window> window1(CreateTestWindowInShellWithId(1));
435 scoped_ptr<Window> window2(CreateTestWindowInShellWithId(2));
437 wm::ActivateWindow(window0.get());
439 // Simulate pressing and releasing Alt-tab.
440 EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
441 controller->HandleCycleWindow(WindowCycleController::FORWARD);
443 // Window lists should return the topmost window in front.
444 ASSERT_TRUE(controller->window_cycle_list());
445 ASSERT_EQ(3u, GetWindows(controller).size());
446 EXPECT_EQ(window0.get(), GetWindows(controller)[0]);
447 EXPECT_EQ(window2.get(), GetWindows(controller)[1]);
448 EXPECT_EQ(window1.get(), GetWindows(controller)[2]);
450 controller->HandleCycleWindow(WindowCycleController::FORWARD);
451 controller->StopCycling();
452 EXPECT_TRUE(wm::IsActiveWindow(window1.get()));
455 controller->HandleCycleWindow(WindowCycleController::FORWARD);
456 EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
458 controller->StopCycling();
460 controller->HandleCycleWindow(WindowCycleController::FORWARD);
461 EXPECT_TRUE(wm::IsActiveWindow(window1.get()));
463 controller->HandleCycleWindow(WindowCycleController::FORWARD);
464 EXPECT_TRUE(wm::IsActiveWindow(window2.get()));
466 controller->HandleCycleWindow(WindowCycleController::FORWARD);
467 EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
470 // Tests that beginning window selection hides the app list.
471 TEST_F(WindowCycleControllerTest, SelectingHidesAppList) {
472 WindowCycleController* controller =
473 Shell::GetInstance()->window_cycle_controller();
475 scoped_ptr<aura::Window> window0(CreateTestWindowInShellWithId(0));
476 scoped_ptr<aura::Window> window1(CreateTestWindowInShellWithId(1));
477 Shell::GetInstance()->ShowAppList(NULL);
478 EXPECT_TRUE(Shell::GetInstance()->GetAppListTargetVisibility());
479 controller->HandleCycleWindow(WindowCycleController::FORWARD);
480 EXPECT_FALSE(Shell::GetInstance()->GetAppListTargetVisibility());
483 // Tests that cycling through windows shows and minimizes windows as they
484 // are passed.
485 TEST_F(WindowCycleControllerTest, CyclePreservesMinimization) {
486 WindowCycleController* controller =
487 Shell::GetInstance()->window_cycle_controller();
489 scoped_ptr<aura::Window> window0(CreateTestWindowInShellWithId(0));
490 scoped_ptr<aura::Window> window1(CreateTestWindowInShellWithId(1));
491 wm::ActivateWindow(window1.get());
492 wm::GetWindowState(window1.get())->Minimize();
493 wm::ActivateWindow(window0.get());
494 EXPECT_TRUE(wm::IsWindowMinimized(window1.get()));
496 // On window 2.
497 controller->HandleCycleWindow(WindowCycleController::FORWARD);
498 EXPECT_FALSE(wm::IsWindowMinimized(window1.get()));
500 // Back on window 1.
501 controller->HandleCycleWindow(WindowCycleController::FORWARD);
502 EXPECT_TRUE(wm::IsWindowMinimized(window1.get()));
504 controller->StopCycling();
506 EXPECT_TRUE(wm::IsWindowMinimized(window1.get()));
509 // Tests cycles between panel and normal windows.
510 TEST_F(WindowCycleControllerTest, CyclePanels) {
511 WindowCycleController* controller =
512 Shell::GetInstance()->window_cycle_controller();
514 scoped_ptr<aura::Window> window0(CreateTestWindowInShellWithId(0));
515 scoped_ptr<aura::Window> panel0(CreatePanelWindow());
516 scoped_ptr<aura::Window> panel1(CreatePanelWindow());
517 wm::ActivateWindow(window0.get());
518 wm::ActivateWindow(panel1.get());
519 wm::ActivateWindow(panel0.get());
520 EXPECT_TRUE(wm::IsActiveWindow(panel0.get()));
522 controller->HandleCycleWindow(WindowCycleController::FORWARD);
523 controller->StopCycling();
524 EXPECT_TRUE(wm::IsActiveWindow(panel1.get()));
526 // Cycling again should select the most recently used panel.
527 controller->HandleCycleWindow(WindowCycleController::FORWARD);
528 controller->StopCycling();
529 EXPECT_TRUE(wm::IsActiveWindow(panel0.get()));
531 // Cycling twice again should select the first window.
532 controller->HandleCycleWindow(WindowCycleController::FORWARD);
533 controller->HandleCycleWindow(WindowCycleController::FORWARD);
534 controller->StopCycling();
535 EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
538 // Tests cycles between panel and normal windows.
539 TEST_F(WindowCycleControllerTest, CyclePanelsDestroyed) {
540 WindowCycleController* controller =
541 Shell::GetInstance()->window_cycle_controller();
543 scoped_ptr<aura::Window> window0(CreateTestWindowInShellWithId(0));
544 scoped_ptr<aura::Window> window1(CreateTestWindowInShellWithId(1));
545 scoped_ptr<aura::Window> window2(CreateTestWindowInShellWithId(2));
546 scoped_ptr<aura::Window> panel0(CreatePanelWindow());
547 scoped_ptr<aura::Window> panel1(CreatePanelWindow());
548 wm::ActivateWindow(window2.get());
549 wm::ActivateWindow(panel1.get());
550 wm::ActivateWindow(panel0.get());
551 wm::ActivateWindow(window1.get());
552 wm::ActivateWindow(window0.get());
553 EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
555 // Cycling once highlights window2.
556 controller->HandleCycleWindow(WindowCycleController::FORWARD);
557 // All panels are destroyed.
558 panel0.reset();
559 panel1.reset();
560 // Cycling again should now select window2.
561 controller->HandleCycleWindow(WindowCycleController::FORWARD);
562 controller->StopCycling();
563 EXPECT_TRUE(wm::IsActiveWindow(window2.get()));
566 // Tests cycles between panel and normal windows.
567 TEST_F(WindowCycleControllerTest, CycleMruPanelDestroyed) {
568 WindowCycleController* controller =
569 Shell::GetInstance()->window_cycle_controller();
571 scoped_ptr<aura::Window> window0(CreateTestWindowInShellWithId(0));
572 scoped_ptr<aura::Window> window1(CreateTestWindowInShellWithId(1));
573 scoped_ptr<aura::Window> panel0(CreatePanelWindow());
574 scoped_ptr<aura::Window> panel1(CreatePanelWindow());
575 wm::ActivateWindow(panel1.get());
576 wm::ActivateWindow(panel0.get());
577 wm::ActivateWindow(window1.get());
578 wm::ActivateWindow(window0.get());
579 EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
581 // Cycling once highlights window2.
582 controller->HandleCycleWindow(WindowCycleController::FORWARD);
584 // Panel 1 is the next item as the MRU panel, removing it should make panel 2
585 // the next window to be selected.
586 panel0.reset();
587 // Cycling again should now select panel1.
588 controller->HandleCycleWindow(WindowCycleController::FORWARD);
589 controller->StopCycling();
590 EXPECT_TRUE(wm::IsActiveWindow(panel1.get()));
593 } // namespace ash