OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/root_window_controller.h" | 5 #include "ash/root_window_controller.h" |
6 #include "ash/screen_ash.h" | 6 #include "ash/screen_ash.h" |
7 #include "ash/shell.h" | 7 #include "ash/shell.h" |
8 #include "ash/test/ash_test_base.h" | 8 #include "ash/test/ash_test_base.h" |
9 #include "ash/test/shell_test_api.h" | 9 #include "ash/test/shell_test_api.h" |
10 #include "ash/wm/mru_window_tracker.h" | 10 #include "ash/wm/mru_window_tracker.h" |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 ScopedVector<LayerAnimationObserver> animations; | 100 ScopedVector<LayerAnimationObserver> animations; |
101 for (size_t i = 0; i < windows.size(); ++i) { | 101 for (size_t i = 0; i < windows.size(); ++i) { |
102 animations.push_back(new LayerAnimationObserver(windows[i]->layer())); | 102 animations.push_back(new LayerAnimationObserver(windows[i]->layer())); |
103 } | 103 } |
104 ash::Shell::GetInstance()->window_selector_controller()->ToggleOverview(); | 104 ash::Shell::GetInstance()->window_selector_controller()->ToggleOverview(); |
105 for (size_t i = 0; i < animations.size(); ++i) { | 105 for (size_t i = 0; i < animations.size(); ++i) { |
106 animations[i]->WaitUntilDone(); | 106 animations[i]->WaitUntilDone(); |
107 } | 107 } |
108 } | 108 } |
109 | 109 |
110 void Cycle(WindowSelector::Direction direction) { | |
111 if (!IsSelecting()) { | |
112 std::vector<aura::Window*> windows = ash::Shell::GetInstance()-> | |
113 mru_window_tracker()->BuildMruWindowList(); | |
114 ScopedVector<LayerAnimationObserver> animations; | |
115 for (size_t i = 0; i < windows.size(); ++i) | |
116 animations.push_back(new LayerAnimationObserver(windows[i]->layer())); | |
117 ash::Shell::GetInstance()->window_selector_controller()-> | |
118 HandleCycleWindow(direction); | |
119 for (size_t i = 0; i < animations.size(); ++i) | |
120 animations[i]->WaitUntilDone(); | |
121 } else { | |
122 ash::Shell::GetInstance()->window_selector_controller()-> | |
123 HandleCycleWindow(direction); | |
124 } | |
125 } | |
126 | |
127 void StopCycling() { | |
128 ash::Shell::GetInstance()->window_selector_controller()->AltKeyReleased(); | |
129 } | |
130 | |
131 gfx::RectF GetTransformedBounds(aura::Window* window) { | 110 gfx::RectF GetTransformedBounds(aura::Window* window) { |
132 gfx::RectF bounds(window->layer()->bounds()); | 111 gfx::RectF bounds(window->layer()->bounds()); |
133 window->layer()->transform().TransformRect(&bounds); | 112 window->layer()->transform().TransformRect(&bounds); |
134 return bounds; | 113 return bounds; |
135 } | 114 } |
136 | 115 |
137 gfx::RectF GetTransformedTargetBounds(aura::Window* window) { | 116 gfx::RectF GetTransformedTargetBounds(aura::Window* window) { |
138 gfx::RectF bounds(window->layer()->GetTargetBounds()); | 117 gfx::RectF bounds(window->layer()->GetTargetBounds()); |
139 window->layer()->GetTargetTransform().TransformRect(&bounds); | 118 window->layer()->GetTargetTransform().TransformRect(&bounds); |
140 return bounds; | 119 return bounds; |
141 } | 120 } |
142 | 121 |
143 void ClickWindow(aura::Window* window) { | 122 void ClickWindow(aura::Window* window) { |
144 aura::test::EventGenerator event_generator(window->GetRootWindow(), window); | 123 aura::test::EventGenerator event_generator(window->GetRootWindow(), window); |
145 gfx::RectF target = GetTransformedBounds(window); | 124 gfx::RectF target = GetTransformedBounds(window); |
146 event_generator.ClickLeftButton(); | 125 event_generator.ClickLeftButton(); |
147 } | 126 } |
148 | 127 |
149 bool IsSelecting() { | |
150 return ash::Shell::GetInstance()->window_selector_controller()-> | |
151 IsSelecting(); | |
152 } | |
153 | |
154 private: | 128 private: |
155 aura::test::TestWindowDelegate wd; | 129 aura::test::TestWindowDelegate wd; |
156 | 130 |
157 DISALLOW_COPY_AND_ASSIGN(WindowSelectorTest); | 131 DISALLOW_COPY_AND_ASSIGN(WindowSelectorTest); |
158 }; | 132 }; |
159 | 133 |
160 // Tests entering overview mode with two windows and selecting one. | 134 // Tests entering overview mode with two windows and selecting one. |
161 TEST_F(WindowSelectorTest, Basic) { | 135 TEST_F(WindowSelectorTest, Basic) { |
162 gfx::Rect bounds(0, 0, 400, 400); | 136 gfx::Rect bounds(0, 0, 400, 400); |
163 scoped_ptr<aura::Window> window1(CreateWindow(bounds)); | 137 scoped_ptr<aura::Window> window1(CreateWindow(bounds)); |
164 scoped_ptr<aura::Window> window2(CreateWindow(bounds)); | 138 scoped_ptr<aura::Window> window2(CreateWindow(bounds)); |
165 EXPECT_TRUE(WindowsOverlapping(window1.get(), window2.get())); | 139 EXPECT_TRUE(WindowsOverlapping(window1.get(), window2.get())); |
166 wm::ActivateWindow(window2.get()); | 140 wm::ActivateWindow(window2.get()); |
167 EXPECT_FALSE(wm::IsActiveWindow(window1.get())); | 141 EXPECT_FALSE(wm::IsActiveWindow(window1.get())); |
168 EXPECT_TRUE(wm::IsActiveWindow(window2.get())); | 142 EXPECT_TRUE(wm::IsActiveWindow(window2.get())); |
169 | 143 |
170 // In overview mode the windows should no longer overlap. | 144 // In overview mode the windows should no longer overlap. |
171 ToggleOverview(); | 145 ToggleOverview(); |
172 EXPECT_FALSE(WindowsOverlapping(window1.get(), window2.get())); | 146 EXPECT_FALSE(WindowsOverlapping(window1.get(), window2.get())); |
173 | 147 |
174 // Clicking window 1 should activate it. | 148 // Clicking window 1 should activate it. |
175 ClickWindow(window1.get()); | 149 ClickWindow(window1.get()); |
176 EXPECT_TRUE(wm::IsActiveWindow(window1.get())); | 150 EXPECT_TRUE(wm::IsActiveWindow(window1.get())); |
177 EXPECT_FALSE(wm::IsActiveWindow(window2.get())); | 151 EXPECT_FALSE(wm::IsActiveWindow(window2.get())); |
178 } | 152 } |
179 | 153 |
180 // Tests entering overview mode with three windows and cycling through them. | |
181 TEST_F(WindowSelectorTest, BasicCycle) { | |
182 gfx::Rect bounds(0, 0, 400, 400); | |
183 scoped_ptr<aura::Window> window1(CreateWindow(bounds)); | |
184 scoped_ptr<aura::Window> window2(CreateWindow(bounds)); | |
185 scoped_ptr<aura::Window> window3(CreateWindow(bounds)); | |
186 wm::ActivateWindow(window3.get()); | |
187 wm::ActivateWindow(window2.get()); | |
188 wm::ActivateWindow(window1.get()); | |
189 EXPECT_TRUE(wm::IsActiveWindow(window1.get())); | |
190 EXPECT_FALSE(wm::IsActiveWindow(window2.get())); | |
191 EXPECT_FALSE(wm::IsActiveWindow(window3.get())); | |
192 | |
193 Cycle(WindowSelector::FORWARD); | |
194 EXPECT_TRUE(IsSelecting()); | |
195 Cycle(WindowSelector::FORWARD); | |
196 StopCycling(); | |
197 EXPECT_FALSE(IsSelecting()); | |
198 EXPECT_FALSE(wm::IsActiveWindow(window1.get())); | |
199 EXPECT_FALSE(wm::IsActiveWindow(window2.get())); | |
200 EXPECT_TRUE(wm::IsActiveWindow(window3.get())); | |
201 } | |
202 | |
203 // Tests that overview mode is exited if the last remaining window is destroyed. | 154 // Tests that overview mode is exited if the last remaining window is destroyed. |
204 TEST_F(WindowSelectorTest, LastWindowDestroyed) { | 155 TEST_F(WindowSelectorTest, LastWindowDestroyed) { |
205 gfx::Rect bounds(0, 0, 400, 400); | 156 gfx::Rect bounds(0, 0, 400, 400); |
206 scoped_ptr<aura::Window> window1(CreateWindow(bounds)); | 157 scoped_ptr<aura::Window> window1(CreateWindow(bounds)); |
207 scoped_ptr<aura::Window> window2(CreateWindow(bounds)); | 158 scoped_ptr<aura::Window> window2(CreateWindow(bounds)); |
208 ToggleOverview(); | 159 ToggleOverview(); |
209 | 160 |
210 window1.reset(); | 161 window1.reset(); |
211 window2.reset(); | 162 window2.reset(); |
212 EXPECT_FALSE(IsSelecting()); | 163 EXPECT_FALSE(ash::Shell::GetInstance()->window_selector_controller()-> |
| 164 IsSelecting()); |
213 } | 165 } |
214 | 166 |
215 // Tests that windows remain on the display they are currently on in overview | 167 // Tests that windows remain on the display they are currently on in overview |
216 // mode. | 168 // mode. |
217 TEST_F(WindowSelectorTest, MultipleDisplays) { | 169 TEST_F(WindowSelectorTest, MultipleDisplays) { |
218 if (!SupportsMultipleDisplays()) | 170 if (!SupportsMultipleDisplays()) |
219 return; | 171 return; |
220 | 172 |
221 UpdateDisplay("400x400,400x400"); | 173 UpdateDisplay("400x400,400x400"); |
222 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); | 174 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
(...skipping 18 matching lines...) Expand all Loading... |
241 root_windows[0]->bounds().Contains( | 193 root_windows[0]->bounds().Contains( |
242 ToEnclosingRect(GetTransformedBounds(window2.get()))); | 194 ToEnclosingRect(GetTransformedBounds(window2.get()))); |
243 root_windows[1]->bounds().Contains( | 195 root_windows[1]->bounds().Contains( |
244 ToEnclosingRect(GetTransformedBounds(window3.get()))); | 196 ToEnclosingRect(GetTransformedBounds(window3.get()))); |
245 root_windows[1]->bounds().Contains( | 197 root_windows[1]->bounds().Contains( |
246 ToEnclosingRect(GetTransformedBounds(window4.get()))); | 198 ToEnclosingRect(GetTransformedBounds(window4.get()))); |
247 } | 199 } |
248 | 200 |
249 } // namespace internal | 201 } // namespace internal |
250 } // namespace ash | 202 } // namespace ash |
OLD | NEW |