1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ash/wm/window_cycle_controller.h"
#include <algorithm>
#include "ash/shell.h"
#include "ash/shell_window_ids.h"
#include "ash/test/ash_test_base.h"
#include "ash/test/test_shell_delegate.h"
#include "ash/wm/window_util.h"
#include "base/memory/scoped_ptr.h"
#include "ui/aura/test/test_windows.h"
#include "ui/aura/window.h"
#include "ui/gfx/rect.h"
namespace ash {
namespace {
using aura::test::CreateTestWindowWithId;
using aura::test::TestWindowDelegate;
using aura::Window;
class WindowCycleControllerTest : public test::AshTestBase {
public:
WindowCycleControllerTest() {}
virtual ~WindowCycleControllerTest() {}
private:
DISALLOW_COPY_AND_ASSIGN(WindowCycleControllerTest);
};
TEST_F(WindowCycleControllerTest, HandleCycleWindowBaseCases) {
WindowCycleController* controller =
Shell::GetInstance()->window_cycle_controller();
// Cycling doesn't crash if there are no windows.
std::vector<Window*> windows = Shell::GetInstance()->delegate()->
GetCycleWindowList(ShellDelegate::SOURCE_KEYBOARD);
EXPECT_TRUE(windows.empty());
controller->HandleCycleWindow(WindowCycleController::FORWARD, false);
// Create a single test window.
Window* default_container =
ash::Shell::GetInstance()->GetContainer(
internal::kShellWindowId_DefaultContainer);
scoped_ptr<Window> window0(CreateTestWindowWithId(0, default_container));
wm::ActivateWindow(window0.get());
EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
// Cycling works for a single window, even though nothing changes.
controller->HandleCycleWindow(WindowCycleController::FORWARD, false);
EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
}
TEST_F(WindowCycleControllerTest, HandleCycleWindow) {
WindowCycleController* controller =
Shell::GetInstance()->window_cycle_controller();
// Set up several windows to use to test cycling. Create them in reverse
// order so they are stacked 0 over 1 over 2.
Window* default_container =
Shell::GetInstance()->GetContainer(
internal::kShellWindowId_DefaultContainer);
scoped_ptr<Window> window2(CreateTestWindowWithId(2, default_container));
scoped_ptr<Window> window1(CreateTestWindowWithId(1, default_container));
scoped_ptr<Window> window0(CreateTestWindowWithId(0, default_container));
wm::ActivateWindow(window0.get());
// Window lists should return the topmost window in front.
std::vector<Window*> windows = Shell::GetInstance()->delegate()->
GetCycleWindowList(ShellDelegate::SOURCE_KEYBOARD);
ASSERT_EQ(3u, windows.size());
ASSERT_EQ(window0.get(), windows[0]);
ASSERT_EQ(window1.get(), windows[1]);
ASSERT_EQ(window2.get(), windows[2]);
// Simulate pressing and releasing Alt-tab.
EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
controller->HandleCycleWindow(WindowCycleController::FORWARD, true);
controller->AltKeyReleased();
EXPECT_TRUE(wm::IsActiveWindow(window1.get()));
// Pressing and releasing Alt-tab again should cycle back to the most-
// recently-used window in the current child order.
controller->HandleCycleWindow(WindowCycleController::FORWARD, true);
controller->AltKeyReleased();
EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
// Pressing Alt-tab multiple times without releasing Alt should cycle through
// all the windows and wrap around.
controller->HandleCycleWindow(WindowCycleController::FORWARD, true);
EXPECT_TRUE(controller->IsCycling());
EXPECT_TRUE(wm::IsActiveWindow(window1.get()));
controller->HandleCycleWindow(WindowCycleController::FORWARD, true);
EXPECT_TRUE(controller->IsCycling());
EXPECT_TRUE(wm::IsActiveWindow(window2.get()));
controller->HandleCycleWindow(WindowCycleController::FORWARD, true);
EXPECT_TRUE(controller->IsCycling());
EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
controller->AltKeyReleased();
EXPECT_FALSE(controller->IsCycling());
EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
// Reset our stacking order.
wm::ActivateWindow(window2.get());
wm::ActivateWindow(window1.get());
wm::ActivateWindow(window0.get());
// Likewise we can cycle backwards through all the windows.
controller->HandleCycleWindow(WindowCycleController::BACKWARD, true);
EXPECT_TRUE(wm::IsActiveWindow(window2.get()));
controller->HandleCycleWindow(WindowCycleController::BACKWARD, true);
EXPECT_TRUE(wm::IsActiveWindow(window1.get()));
controller->HandleCycleWindow(WindowCycleController::BACKWARD, true);
EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
controller->AltKeyReleased();
EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
// Passing false for is_alt_down does not start a cycle gesture.
controller->HandleCycleWindow(WindowCycleController::FORWARD, false);
EXPECT_FALSE(controller->IsCycling());
EXPECT_TRUE(wm::IsActiveWindow(window1.get()));
controller->HandleCycleWindow(WindowCycleController::FORWARD, false);
EXPECT_FALSE(controller->IsCycling());
EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
// When the screen is locked, cycling window does not take effect.
Shell::GetInstance()->delegate()->LockScreen();
EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
controller->HandleCycleWindow(WindowCycleController::FORWARD, false);
EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
controller->HandleCycleWindow(WindowCycleController::BACKWARD, false);
EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
Shell::GetInstance()->delegate()->UnlockScreen();
EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
controller->HandleCycleWindow(WindowCycleController::FORWARD, false);
EXPECT_TRUE(wm::IsActiveWindow(window1.get()));
controller->HandleCycleWindow(WindowCycleController::FORWARD, false);
EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
// When a modal window is active, cycling window does not take effect.
aura::Window* modal_container =
ash::Shell::GetInstance()->GetContainer(
internal::kShellWindowId_SystemModalContainer);
scoped_ptr<Window> modal_window(
CreateTestWindowWithId(-2, modal_container));
wm::ActivateWindow(modal_window.get());
EXPECT_TRUE(wm::IsActiveWindow(modal_window.get()));
controller->HandleCycleWindow(WindowCycleController::FORWARD, false);
EXPECT_TRUE(wm::IsActiveWindow(modal_window.get()));
EXPECT_FALSE(wm::IsActiveWindow(window0.get()));
EXPECT_FALSE(wm::IsActiveWindow(window1.get()));
EXPECT_FALSE(wm::IsActiveWindow(window2.get()));
controller->HandleCycleWindow(WindowCycleController::BACKWARD, false);
EXPECT_TRUE(wm::IsActiveWindow(modal_window.get()));
EXPECT_FALSE(wm::IsActiveWindow(window0.get()));
EXPECT_FALSE(wm::IsActiveWindow(window1.get()));
EXPECT_FALSE(wm::IsActiveWindow(window2.get()));
}
} // namespace
} // namespace ash
|