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