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/wm/activation_controller.h" | 5 #include "ash/wm/activation_controller.h" |
6 | 6 |
7 #include "ash/shell.h" | 7 #include "ash/shell.h" |
8 #include "ash/shell_window_ids.h" | 8 #include "ash/shell_window_ids.h" |
9 #include "ash/test/ash_test_base.h" | 9 #include "ash/test/ash_test_base.h" |
10 #include "ash/test/test_activation_delegate.h" | 10 #include "ash/test/test_activation_delegate.h" |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 aura::Window* w7() { return w7_.get(); } | 64 aura::Window* w7() { return w7_.get(); } |
65 | 65 |
66 void DestroyWindow2() { | 66 void DestroyWindow2() { |
67 w2_.reset(); | 67 w2_.reset(); |
68 } | 68 } |
69 | 69 |
70 private: | 70 private: |
71 void CreateWindows() { | 71 void CreateWindows() { |
72 // Create four windows, the first and third are not activatable, the second | 72 // Create four windows, the first and third are not activatable, the second |
73 // and fourth are. | 73 // and fourth are. |
74 w1_.reset(CreateWindow(1, &ad_1_, kDefaultContainerID)); | 74 w1_.reset(CreateWindowInShell(1, &ad_1_)); |
75 w2_.reset(CreateWindow(2, &ad_2_, kDefaultContainerID)); | 75 w2_.reset(CreateWindowInShell(2, &ad_2_)); |
76 w3_.reset(CreateWindow(3, &ad_3_, kDefaultContainerID)); | 76 w3_.reset(CreateWindowInShell(3, &ad_3_)); |
77 w4_.reset(CreateWindow(4, &ad_4_, kDefaultContainerID)); | 77 w4_.reset(CreateWindowInShell(4, &ad_4_)); |
78 w5_.reset(CreateWindow(5, &ad_5_, c2)); | 78 w5_.reset(CreateWindowWithID(5, &ad_5_, c2)); |
79 w6_.reset(CreateWindow(6, &ad_6_, c2)); | 79 w6_.reset(CreateWindowWithID(6, &ad_6_, c2)); |
80 w7_.reset(CreateWindow(7, &ad_7_, c3)); | 80 w7_.reset(CreateWindowWithID(7, &ad_7_, c3)); |
81 } | 81 } |
82 | 82 |
83 aura::Window* CreateWindow(int id, | 83 aura::Window* CreateWindowInShell(int id, |
84 TestActivationDelegate* delegate, | 84 TestActivationDelegate* delegate) { |
85 int container_id) { | 85 aura::Window* window = CreateTestWindowInShellWithDelegate( |
86 aura::Window* parent = container_id == kDefaultContainerID ? NULL : | 86 &delegate_, |
| 87 id, |
| 88 gfx::Rect()); |
| 89 delegate->SetWindow(window); |
| 90 return window; |
| 91 } |
| 92 |
| 93 aura::Window* CreateWindowWithID(int id, |
| 94 TestActivationDelegate* delegate, |
| 95 int container_id) { |
| 96 aura::Window* parent = |
87 Shell::GetContainer(Shell::GetPrimaryRootWindow(), container_id); | 97 Shell::GetContainer(Shell::GetPrimaryRootWindow(), container_id); |
88 aura::Window* window = aura::test::CreateTestWindowWithDelegate( | 98 aura::Window* window = aura::test::CreateTestWindowWithDelegate( |
89 &delegate_, | 99 &delegate_, |
90 id, | 100 id, |
91 gfx::Rect(), | 101 gfx::Rect(), |
92 parent); | 102 parent); |
93 delegate->SetWindow(window); | 103 delegate->SetWindow(window); |
94 return window; | 104 return window; |
95 } | 105 } |
96 | 106 |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 EXPECT_TRUE(wm::IsActiveWindow(w4())); | 194 EXPECT_TRUE(wm::IsActiveWindow(w4())); |
185 } | 195 } |
186 | 196 |
187 // Test if the clicking on a menu picks the transient parent as activatable | 197 // Test if the clicking on a menu picks the transient parent as activatable |
188 // window. | 198 // window. |
189 TEST_F(ActivationControllerTest, ClickOnMenu) { | 199 TEST_F(ActivationControllerTest, ClickOnMenu) { |
190 aura::test::TestWindowDelegate wd; | 200 aura::test::TestWindowDelegate wd; |
191 TestActivationDelegate ad1; | 201 TestActivationDelegate ad1; |
192 TestActivationDelegate ad2(false); | 202 TestActivationDelegate ad2(false); |
193 | 203 |
194 scoped_ptr<aura::Window> w1(aura::test::CreateTestWindowWithDelegate( | 204 scoped_ptr<aura::Window> w1(CreateTestWindowInShellWithDelegate( |
195 &wd, 1, gfx::Rect(100, 100), NULL)); | 205 &wd, 1, gfx::Rect(100, 100))); |
196 ad1.SetWindow(w1.get()); | 206 ad1.SetWindow(w1.get()); |
197 EXPECT_EQ(NULL, wm::GetActiveWindow()); | 207 EXPECT_EQ(NULL, wm::GetActiveWindow()); |
198 | 208 |
199 // Clicking on an activatable window activates the window. | 209 // Clicking on an activatable window activates the window. |
200 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), w1.get()); | 210 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), w1.get()); |
201 generator.ClickLeftButton(); | 211 generator.ClickLeftButton(); |
202 EXPECT_TRUE(wm::IsActiveWindow(w1.get())); | 212 EXPECT_TRUE(wm::IsActiveWindow(w1.get())); |
203 | 213 |
204 // Creates a menu that covers the transient parent. | 214 // Creates a menu that covers the transient parent. |
205 scoped_ptr<aura::Window> menu(aura::test::CreateTestWindowWithDelegateAndType( | 215 scoped_ptr<aura::Window> menu(CreateTestWindowInShellWithDelegateAndType( |
206 &wd, aura::client::WINDOW_TYPE_MENU, 2, gfx::Rect(100, 100), NULL)); | 216 &wd, aura::client::WINDOW_TYPE_MENU, 2, gfx::Rect(100, 100))); |
207 ad2.SetWindow(menu.get()); | 217 ad2.SetWindow(menu.get()); |
208 w1->AddTransientChild(menu.get()); | 218 w1->AddTransientChild(menu.get()); |
209 | 219 |
210 // Clicking on a menu whose transient parent is active window shouldn't | 220 // Clicking on a menu whose transient parent is active window shouldn't |
211 // change the active window. | 221 // change the active window. |
212 generator.ClickLeftButton(); | 222 generator.ClickLeftButton(); |
213 EXPECT_TRUE(wm::IsActiveWindow(w1.get())); | 223 EXPECT_TRUE(wm::IsActiveWindow(w1.get())); |
214 } | 224 } |
215 | 225 |
216 // Various assertions for activating/deactivating. | 226 // Various assertions for activating/deactivating. |
217 TEST_F(ActivationControllerTest, Deactivate) { | 227 TEST_F(ActivationControllerTest, Deactivate) { |
218 aura::test::TestWindowDelegate d1; | 228 aura::test::TestWindowDelegate d1; |
219 aura::test::TestWindowDelegate d2; | 229 aura::test::TestWindowDelegate d2; |
220 scoped_ptr<aura::Window> w1(aura::test::CreateTestWindowWithDelegate( | 230 scoped_ptr<aura::Window> w1(CreateTestWindowInShellWithDelegate( |
221 &d1, 1, gfx::Rect(), NULL)); | 231 &d1, 1, gfx::Rect())); |
222 scoped_ptr<aura::Window> w2(aura::test::CreateTestWindowWithDelegate( | 232 scoped_ptr<aura::Window> w2(CreateTestWindowInShellWithDelegate( |
223 &d2, 2, gfx::Rect(), NULL)); | 233 &d2, 2, gfx::Rect())); |
224 aura::Window* parent = w1->parent(); | 234 aura::Window* parent = w1->parent(); |
225 parent->Show(); | 235 parent->Show(); |
226 ASSERT_TRUE(parent); | 236 ASSERT_TRUE(parent); |
227 ASSERT_EQ(2u, parent->children().size()); | 237 ASSERT_EQ(2u, parent->children().size()); |
228 // Activate w2 and make sure it's active and frontmost. | 238 // Activate w2 and make sure it's active and frontmost. |
229 wm::ActivateWindow(w2.get()); | 239 wm::ActivateWindow(w2.get()); |
230 EXPECT_TRUE(wm::IsActiveWindow(w2.get())); | 240 EXPECT_TRUE(wm::IsActiveWindow(w2.get())); |
231 EXPECT_FALSE(wm::IsActiveWindow(w1.get())); | 241 EXPECT_FALSE(wm::IsActiveWindow(w1.get())); |
232 EXPECT_EQ(w2.get(), parent->children()[1]); | 242 EXPECT_EQ(w2.get(), parent->children()[1]); |
233 | 243 |
234 // Activate w1 and make sure it's active and frontmost. | 244 // Activate w1 and make sure it's active and frontmost. |
235 wm::ActivateWindow(w1.get()); | 245 wm::ActivateWindow(w1.get()); |
236 EXPECT_TRUE(wm::IsActiveWindow(w1.get())); | 246 EXPECT_TRUE(wm::IsActiveWindow(w1.get())); |
237 EXPECT_FALSE(wm::IsActiveWindow(w2.get())); | 247 EXPECT_FALSE(wm::IsActiveWindow(w2.get())); |
238 EXPECT_EQ(w1.get(), parent->children()[1]); | 248 EXPECT_EQ(w1.get(), parent->children()[1]); |
239 | 249 |
240 // Deactivate w1 and make sure w2 becomes active and frontmost. | 250 // Deactivate w1 and make sure w2 becomes active and frontmost. |
241 wm::DeactivateWindow(w1.get()); | 251 wm::DeactivateWindow(w1.get()); |
242 EXPECT_FALSE(wm::IsActiveWindow(w1.get())); | 252 EXPECT_FALSE(wm::IsActiveWindow(w1.get())); |
243 EXPECT_TRUE(wm::IsActiveWindow(w2.get())); | 253 EXPECT_TRUE(wm::IsActiveWindow(w2.get())); |
244 EXPECT_EQ(w2.get(), parent->children()[1]); | 254 EXPECT_EQ(w2.get(), parent->children()[1]); |
245 } | 255 } |
246 | 256 |
247 // Verifies that when WindowDelegate::OnLostActive is invoked the window is not | 257 // Verifies that when WindowDelegate::OnLostActive is invoked the window is not |
248 // active. | 258 // active. |
249 TEST_F(ActivationControllerTest, NotActiveInLostActive) { | 259 TEST_F(ActivationControllerTest, NotActiveInLostActive) { |
250 TestActivationDelegate ad1; | 260 TestActivationDelegate ad1; |
251 aura::test::TestWindowDelegate wd; | 261 aura::test::TestWindowDelegate wd; |
252 scoped_ptr<aura::Window> w1(aura::test::CreateTestWindowWithDelegate( | 262 scoped_ptr<aura::Window> w1(CreateTestWindowInShellWithDelegate( |
253 &wd, 1, gfx::Rect(10, 10, 50, 50), NULL)); | 263 &wd, 1, gfx::Rect(10, 10, 50, 50))); |
254 ad1.SetWindow(w1.get()); | 264 ad1.SetWindow(w1.get()); |
255 scoped_ptr<aura::Window> w2(aura::test::CreateTestWindowWithDelegate( | 265 scoped_ptr<aura::Window> w2(CreateTestWindowInShellWithDelegate( |
256 NULL, 1, gfx::Rect(10, 10, 50, 50), NULL)); | 266 NULL, 1, gfx::Rect(10, 10, 50, 50))); |
257 | 267 |
258 // Activate w1. | 268 // Activate w1. |
259 wm::ActivateWindow(w1.get()); | 269 wm::ActivateWindow(w1.get()); |
260 EXPECT_TRUE(wm::IsActiveWindow(w1.get())); | 270 EXPECT_TRUE(wm::IsActiveWindow(w1.get())); |
261 EXPECT_EQ(1, ad1.activated_count()); | 271 EXPECT_EQ(1, ad1.activated_count()); |
262 // Should not have gotten a OnLostActive yet. | 272 // Should not have gotten a OnLostActive yet. |
263 EXPECT_EQ(0, ad1.lost_active_count()); | 273 EXPECT_EQ(0, ad1.lost_active_count()); |
264 | 274 |
265 // Deactivate the active window. | 275 // Deactivate the active window. |
266 wm::DeactivateWindow(w1.get()); | 276 wm::DeactivateWindow(w1.get()); |
(...skipping 16 matching lines...) Expand all Loading... |
283 // active window in OnLostActive. | 293 // active window in OnLostActive. |
284 EXPECT_EQ(0, ad1.activated_count()); | 294 EXPECT_EQ(0, ad1.activated_count()); |
285 EXPECT_EQ(1, ad1.lost_active_count()); | 295 EXPECT_EQ(1, ad1.lost_active_count()); |
286 EXPECT_FALSE(ad1.window_was_active()); | 296 EXPECT_FALSE(ad1.window_was_active()); |
287 } | 297 } |
288 | 298 |
289 // Verifies that focusing another window or its children causes it to become | 299 // Verifies that focusing another window or its children causes it to become |
290 // active. | 300 // active. |
291 TEST_F(ActivationControllerTest, FocusTriggersActivation) { | 301 TEST_F(ActivationControllerTest, FocusTriggersActivation) { |
292 aura::test::TestWindowDelegate wd; | 302 aura::test::TestWindowDelegate wd; |
293 scoped_ptr<aura::Window> w1(aura::test::CreateTestWindowWithDelegate( | 303 scoped_ptr<aura::Window> w1(CreateTestWindowInShellWithDelegate( |
294 &wd, -1, gfx::Rect(50, 50), NULL)); | 304 &wd, -1, gfx::Rect(50, 50))); |
295 scoped_ptr<aura::Window> w2(aura::test::CreateTestWindowWithDelegate( | 305 scoped_ptr<aura::Window> w2(CreateTestWindowInShellWithDelegate( |
296 &wd, -2, gfx::Rect(50, 50), NULL)); | 306 &wd, -2, gfx::Rect(50, 50))); |
297 scoped_ptr<aura::Window> w21(aura::test::CreateTestWindowWithDelegate( | 307 scoped_ptr<aura::Window> w21(aura::test::CreateTestWindowWithDelegate( |
298 &wd, -21, gfx::Rect(50, 50), w2.get())); | 308 &wd, -21, gfx::Rect(50, 50), w2.get())); |
299 | 309 |
300 wm::ActivateWindow(w1.get()); | 310 wm::ActivateWindow(w1.get()); |
301 EXPECT_TRUE(wm::IsActiveWindow(w1.get())); | 311 EXPECT_TRUE(wm::IsActiveWindow(w1.get())); |
302 EXPECT_TRUE(w1->HasFocus()); | 312 EXPECT_TRUE(w1->HasFocus()); |
303 | 313 |
304 w2->Focus(); | 314 w2->Focus(); |
305 EXPECT_TRUE(wm::IsActiveWindow(w2.get())); | 315 EXPECT_TRUE(wm::IsActiveWindow(w2.get())); |
306 EXPECT_TRUE(w2->HasFocus()); | 316 EXPECT_TRUE(w2->HasFocus()); |
307 | 317 |
308 wm::ActivateWindow(w1.get()); | 318 wm::ActivateWindow(w1.get()); |
309 EXPECT_TRUE(wm::IsActiveWindow(w1.get())); | 319 EXPECT_TRUE(wm::IsActiveWindow(w1.get())); |
310 EXPECT_TRUE(w1->HasFocus()); | 320 EXPECT_TRUE(w1->HasFocus()); |
311 | 321 |
312 w21->Focus(); | 322 w21->Focus(); |
313 EXPECT_TRUE(wm::IsActiveWindow(w2.get())); | 323 EXPECT_TRUE(wm::IsActiveWindow(w2.get())); |
314 EXPECT_TRUE(w21->HasFocus()); | 324 EXPECT_TRUE(w21->HasFocus()); |
315 } | 325 } |
316 | 326 |
317 // Verifies that we prevent all attempts to focus a child of a non-activatable | 327 // Verifies that we prevent all attempts to focus a child of a non-activatable |
318 // window from claiming focus to that window. | 328 // window from claiming focus to that window. |
319 TEST_F(ActivationControllerTest, PreventFocusToNonActivatableWindow) { | 329 TEST_F(ActivationControllerTest, PreventFocusToNonActivatableWindow) { |
320 aura::test::TestWindowDelegate wd; | 330 aura::test::TestWindowDelegate wd; |
321 scoped_ptr<aura::Window> w1(aura::test::CreateTestWindowWithDelegate( | 331 scoped_ptr<aura::Window> w1(CreateTestWindowInShellWithDelegate( |
322 &wd, -1, gfx::Rect(50, 50), NULL)); | 332 &wd, -1, gfx::Rect(50, 50))); |
323 // The RootWindow is a non-activatable parent. | 333 // The RootWindow is a non-activatable parent. |
324 scoped_ptr<aura::Window> w2(aura::test::CreateTestWindowWithDelegate( | 334 scoped_ptr<aura::Window> w2(aura::test::CreateTestWindowWithDelegate( |
325 &wd, -2, gfx::Rect(50, 50), Shell::GetPrimaryRootWindow())); | 335 &wd, -2, gfx::Rect(50, 50), Shell::GetPrimaryRootWindow())); |
326 scoped_ptr<aura::Window> w21(aura::test::CreateTestWindowWithDelegate( | 336 scoped_ptr<aura::Window> w21(aura::test::CreateTestWindowWithDelegate( |
327 &wd, -21, gfx::Rect(50, 50), w2.get())); | 337 &wd, -21, gfx::Rect(50, 50), w2.get())); |
328 | 338 |
329 wm::ActivateWindow(w1.get()); | 339 wm::ActivateWindow(w1.get()); |
330 EXPECT_TRUE(wm::IsActiveWindow(w1.get())); | 340 EXPECT_TRUE(wm::IsActiveWindow(w1.get())); |
331 EXPECT_TRUE(w1->HasFocus()); | 341 EXPECT_TRUE(w1->HasFocus()); |
332 | 342 |
(...skipping 17 matching lines...) Expand all Loading... |
350 EXPECT_FALSE(w21->HasFocus()); | 360 EXPECT_FALSE(w21->HasFocus()); |
351 EXPECT_TRUE(wm::IsActiveWindow(w1.get())); | 361 EXPECT_TRUE(wm::IsActiveWindow(w1.get())); |
352 EXPECT_TRUE(w1->HasFocus()); | 362 EXPECT_TRUE(w1->HasFocus()); |
353 } | 363 } |
354 | 364 |
355 TEST_F(ActivationControllerTest, CanActivateWindowIteselfTest) | 365 TEST_F(ActivationControllerTest, CanActivateWindowIteselfTest) |
356 { | 366 { |
357 aura::test::TestWindowDelegate wd; | 367 aura::test::TestWindowDelegate wd; |
358 | 368 |
359 // Normal Window | 369 // Normal Window |
360 scoped_ptr<aura::Window> w1(aura::test::CreateTestWindowWithDelegate( | 370 scoped_ptr<aura::Window> w1(CreateTestWindowInShellWithDelegate( |
361 &wd, -1, gfx::Rect(50, 50), NULL)); | 371 &wd, -1, gfx::Rect(50, 50))); |
362 EXPECT_TRUE(wm::CanActivateWindow(w1.get())); | 372 EXPECT_TRUE(wm::CanActivateWindow(w1.get())); |
363 | 373 |
364 // The RootWindow is a non-activatable parent. | 374 // The RootWindow is a non-activatable parent. |
365 scoped_ptr<aura::Window> w2(aura::test::CreateTestWindowWithDelegate( | 375 scoped_ptr<aura::Window> w2(aura::test::CreateTestWindowWithDelegate( |
366 &wd, -2, gfx::Rect(50, 50), Shell::GetPrimaryRootWindow())); | 376 &wd, -2, gfx::Rect(50, 50), Shell::GetPrimaryRootWindow())); |
367 scoped_ptr<aura::Window> w21(aura::test::CreateTestWindowWithDelegate( | 377 scoped_ptr<aura::Window> w21(aura::test::CreateTestWindowWithDelegate( |
368 &wd, -21, gfx::Rect(50, 50), w2.get())); | 378 &wd, -21, gfx::Rect(50, 50), w2.get())); |
369 EXPECT_FALSE(wm::CanActivateWindow(w2.get())); | 379 EXPECT_FALSE(wm::CanActivateWindow(w2.get())); |
370 EXPECT_FALSE(wm::CanActivateWindow(w21.get())); | 380 EXPECT_FALSE(wm::CanActivateWindow(w21.get())); |
371 | 381 |
372 // The window has a transient child. | 382 // The window has a transient child. |
373 scoped_ptr<aura::Window> w3(aura::test::CreateTestWindowWithDelegate( | 383 scoped_ptr<aura::Window> w3(CreateTestWindowInShellWithDelegate( |
374 &wd, -3, gfx::Rect(50, 50), NULL)); | 384 &wd, -3, gfx::Rect(50, 50))); |
375 scoped_ptr<aura::Window> w31(aura::test::CreateTestWindowWithDelegate( | 385 scoped_ptr<aura::Window> w31(CreateTestWindowInShellWithDelegate( |
376 &wd, -31, gfx::Rect(50, 50), NULL)); | 386 &wd, -31, gfx::Rect(50, 50))); |
377 w3->AddTransientChild(w31.get()); | 387 w3->AddTransientChild(w31.get()); |
378 EXPECT_TRUE(wm::CanActivateWindow(w3.get())); | 388 EXPECT_TRUE(wm::CanActivateWindow(w3.get())); |
379 EXPECT_TRUE(wm::CanActivateWindow(w31.get())); | 389 EXPECT_TRUE(wm::CanActivateWindow(w31.get())); |
380 | 390 |
381 // The window has a transient window-modal child. | 391 // The window has a transient window-modal child. |
382 scoped_ptr<aura::Window> w4(aura::test::CreateTestWindowWithDelegate( | 392 scoped_ptr<aura::Window> w4(CreateTestWindowInShellWithDelegate( |
383 &wd, -4, gfx::Rect(50, 50), NULL)); | 393 &wd, -4, gfx::Rect(50, 50))); |
384 scoped_ptr<aura::Window> w41(aura::test::CreateTestWindowWithDelegate( | 394 scoped_ptr<aura::Window> w41(CreateTestWindowInShellWithDelegate( |
385 &wd, -41, gfx::Rect(50, 50), NULL)); | 395 &wd, -41, gfx::Rect(50, 50))); |
386 w4->AddTransientChild(w41.get()); | 396 w4->AddTransientChild(w41.get()); |
387 w41->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_WINDOW); | 397 w41->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_WINDOW); |
388 EXPECT_FALSE(wm::CanActivateWindow(w4.get())); | 398 EXPECT_FALSE(wm::CanActivateWindow(w4.get())); |
389 EXPECT_TRUE(wm::CanActivateWindow(w41.get())); | 399 EXPECT_TRUE(wm::CanActivateWindow(w41.get())); |
390 | 400 |
391 // The window has a transient system-modal child. | 401 // The window has a transient system-modal child. |
392 scoped_ptr<aura::Window> w5(aura::test::CreateTestWindowWithDelegate( | 402 scoped_ptr<aura::Window> w5(CreateTestWindowInShellWithDelegate( |
393 &wd, -5, gfx::Rect(50, 50), NULL)); | 403 &wd, -5, gfx::Rect(50, 50))); |
394 scoped_ptr<aura::Window> w51(aura::test::CreateTestWindowWithDelegate( | 404 scoped_ptr<aura::Window> w51(CreateTestWindowInShellWithDelegate( |
395 &wd, -51, gfx::Rect(50, 50), NULL)); | 405 &wd, -51, gfx::Rect(50, 50))); |
396 w5->AddTransientChild(w51.get()); | 406 w5->AddTransientChild(w51.get()); |
397 w51->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_SYSTEM); | 407 w51->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_SYSTEM); |
398 EXPECT_TRUE(wm::CanActivateWindow(w5.get())); | 408 EXPECT_TRUE(wm::CanActivateWindow(w5.get())); |
399 EXPECT_TRUE(wm::CanActivateWindow(w51.get())); | 409 EXPECT_TRUE(wm::CanActivateWindow(w51.get())); |
400 } | 410 } |
401 | 411 |
402 // Verifies code in ActivationController::OnWindowVisibilityChanged() that keeps | 412 // Verifies code in ActivationController::OnWindowVisibilityChanged() that keeps |
403 // hiding windows layers stacked above the newly active window while they | 413 // hiding windows layers stacked above the newly active window while they |
404 // animate away. | 414 // animate away. |
405 TEST_F(ActivationControllerTest, AnimateHideMaintainsStacking) { | 415 TEST_F(ActivationControllerTest, AnimateHideMaintainsStacking) { |
406 aura::test::TestWindowDelegate wd; | 416 aura::test::TestWindowDelegate wd; |
407 scoped_ptr<aura::Window> w1(aura::test::CreateTestWindowWithDelegate( | 417 scoped_ptr<aura::Window> w1(CreateTestWindowInShellWithDelegate( |
408 &wd, -1, gfx::Rect(50, 50, 50, 50), NULL)); | 418 &wd, -1, gfx::Rect(50, 50, 50, 50))); |
409 scoped_ptr<aura::Window> w2(aura::test::CreateTestWindowWithDelegate( | 419 scoped_ptr<aura::Window> w2(CreateTestWindowInShellWithDelegate( |
410 &wd, -2, gfx::Rect(75, 75, 50, 50), NULL)); | 420 &wd, -2, gfx::Rect(75, 75, 50, 50))); |
411 wm::ActivateWindow(w2.get()); | 421 wm::ActivateWindow(w2.get()); |
412 EXPECT_TRUE(wm::IsActiveWindow(w2.get())); | 422 EXPECT_TRUE(wm::IsActiveWindow(w2.get())); |
413 w2->Hide(); | 423 w2->Hide(); |
414 typedef std::vector<ui::Layer*> Layers; | 424 typedef std::vector<ui::Layer*> Layers; |
415 const Layers& children = w1->parent()->layer()->children(); | 425 const Layers& children = w1->parent()->layer()->children(); |
416 Layers::const_iterator w1_iter = | 426 Layers::const_iterator w1_iter = |
417 std::find(children.begin(), children.end(), w1->layer()); | 427 std::find(children.begin(), children.end(), w1->layer()); |
418 Layers::const_iterator w2_iter = | 428 Layers::const_iterator w2_iter = |
419 std::find(children.begin(), children.end(), w2->layer()); | 429 std::find(children.begin(), children.end(), w2->layer()); |
420 EXPECT_TRUE(w2_iter > w1_iter); | 430 EXPECT_TRUE(w2_iter > w1_iter); |
421 } | 431 } |
422 | 432 |
423 // Verifies that activating a minimized window would restore it. | 433 // Verifies that activating a minimized window would restore it. |
424 TEST_F(ActivationControllerTest, ActivateMinimizedWindow) { | 434 TEST_F(ActivationControllerTest, ActivateMinimizedWindow) { |
425 aura::test::TestWindowDelegate wd; | 435 aura::test::TestWindowDelegate wd; |
426 scoped_ptr<aura::Window> w1(aura::test::CreateTestWindowWithDelegate( | 436 scoped_ptr<aura::Window> w1(CreateTestWindowInShellWithDelegate( |
427 &wd, -1, gfx::Rect(50, 50), NULL)); | 437 &wd, -1, gfx::Rect(50, 50))); |
428 | 438 |
429 wm::MinimizeWindow(w1.get()); | 439 wm::MinimizeWindow(w1.get()); |
430 EXPECT_TRUE(wm::IsWindowMinimized(w1.get())); | 440 EXPECT_TRUE(wm::IsWindowMinimized(w1.get())); |
431 | 441 |
432 wm::ActivateWindow(w1.get()); | 442 wm::ActivateWindow(w1.get()); |
433 EXPECT_TRUE(wm::IsActiveWindow(w1.get())); | 443 EXPECT_TRUE(wm::IsActiveWindow(w1.get())); |
434 EXPECT_FALSE(wm::IsWindowMinimized(w1.get())); | 444 EXPECT_FALSE(wm::IsWindowMinimized(w1.get())); |
435 } | 445 } |
436 | 446 |
437 // Verifies that a minimized window would not be automatically activated as | 447 // Verifies that a minimized window would not be automatically activated as |
438 // a replacement active window. | 448 // a replacement active window. |
439 TEST_F(ActivationControllerTest, NoAutoActivateMinimizedWindow) { | 449 TEST_F(ActivationControllerTest, NoAutoActivateMinimizedWindow) { |
440 aura::test::TestWindowDelegate wd; | 450 aura::test::TestWindowDelegate wd; |
441 scoped_ptr<aura::Window> w1(aura::test::CreateTestWindowWithDelegate( | 451 scoped_ptr<aura::Window> w1(CreateTestWindowInShellWithDelegate( |
442 &wd, -1, gfx::Rect(50, 50, 50, 50), NULL)); | 452 &wd, -1, gfx::Rect(50, 50, 50, 50))); |
443 scoped_ptr<aura::Window> w2(aura::test::CreateTestWindowWithDelegate( | 453 scoped_ptr<aura::Window> w2(CreateTestWindowInShellWithDelegate( |
444 &wd, -2, gfx::Rect(75, 75, 50, 50), NULL)); | 454 &wd, -2, gfx::Rect(75, 75, 50, 50))); |
445 | 455 |
446 wm::MinimizeWindow(w1.get()); | 456 wm::MinimizeWindow(w1.get()); |
447 EXPECT_TRUE(wm::IsWindowMinimized(w1.get())); | 457 EXPECT_TRUE(wm::IsWindowMinimized(w1.get())); |
448 | 458 |
449 wm::ActivateWindow(w2.get()); | 459 wm::ActivateWindow(w2.get()); |
450 EXPECT_TRUE(wm::IsActiveWindow(w2.get())); | 460 EXPECT_TRUE(wm::IsActiveWindow(w2.get())); |
451 | 461 |
452 w2->Hide(); | 462 w2->Hide(); |
453 | 463 |
454 EXPECT_FALSE(wm::IsActiveWindow(w1.get())); | 464 EXPECT_FALSE(wm::IsActiveWindow(w1.get())); |
455 EXPECT_TRUE(wm::IsWindowMinimized(w1.get())); | 465 EXPECT_TRUE(wm::IsWindowMinimized(w1.get())); |
456 } | 466 } |
457 | 467 |
458 // Verifies that a window with a hidden layer can be activated. | 468 // Verifies that a window with a hidden layer can be activated. |
459 TEST_F(ActivationControllerTest, ActivateWithHiddenLayer) { | 469 TEST_F(ActivationControllerTest, ActivateWithHiddenLayer) { |
460 aura::test::TestWindowDelegate wd; | 470 aura::test::TestWindowDelegate wd; |
461 scoped_ptr<aura::Window> w1(aura::test::CreateTestWindowWithDelegate( | 471 scoped_ptr<aura::Window> w1(CreateTestWindowInShellWithDelegate( |
462 &wd, -1, gfx::Rect(50, 50, 50, 50), NULL)); | 472 &wd, -1, gfx::Rect(50, 50, 50, 50))); |
463 | 473 |
464 EXPECT_TRUE(wm::CanActivateWindow(w1.get())); | 474 EXPECT_TRUE(wm::CanActivateWindow(w1.get())); |
465 w1->layer()->SetVisible(false); | 475 w1->layer()->SetVisible(false); |
466 EXPECT_TRUE(wm::CanActivateWindow(w1.get())); | 476 EXPECT_TRUE(wm::CanActivateWindow(w1.get())); |
467 } | 477 } |
468 | 478 |
469 // Verifies that a unrelated window cannot be activated when in a system modal | 479 // Verifies that a unrelated window cannot be activated when in a system modal |
470 // dialog. | 480 // dialog. |
471 TEST_F(ActivationControllerTest, DontActivateWindowWhenInSystemModalDialog) { | 481 TEST_F(ActivationControllerTest, DontActivateWindowWhenInSystemModalDialog) { |
472 scoped_ptr<aura::Window> normal_window( | 482 scoped_ptr<aura::Window> normal_window(CreateTestWindowInShellWithId(-1)); |
473 aura::test::CreateTestWindowWithId(-1, NULL)); | |
474 EXPECT_FALSE(wm::IsActiveWindow(normal_window.get())); | 483 EXPECT_FALSE(wm::IsActiveWindow(normal_window.get())); |
475 wm::ActivateWindow(normal_window.get()); | 484 wm::ActivateWindow(normal_window.get()); |
476 EXPECT_TRUE(wm::IsActiveWindow(normal_window.get())); | 485 EXPECT_TRUE(wm::IsActiveWindow(normal_window.get())); |
477 | 486 |
478 // Create and activate a system modal window. | 487 // Create and activate a system modal window. |
479 aura::Window* modal_container = | 488 aura::Window* modal_container = |
480 ash::Shell::GetContainer( | 489 ash::Shell::GetContainer( |
481 Shell::GetPrimaryRootWindow(), | 490 Shell::GetPrimaryRootWindow(), |
482 ash::internal::kShellWindowId_SystemModalContainer); | 491 ash::internal::kShellWindowId_SystemModalContainer); |
483 scoped_ptr<aura::Window> modal_window( | 492 scoped_ptr<aura::Window> modal_window( |
(...skipping 26 matching lines...) Expand all Loading... |
510 scoped_ptr<aura::Window> w1(aura::test::CreateTestWindowWithDelegate( | 519 scoped_ptr<aura::Window> w1(aura::test::CreateTestWindowWithDelegate( |
511 &wd, -1, gfx::Rect(50, 50, 50, 50), lock_container)); | 520 &wd, -1, gfx::Rect(50, 50, 50, 50), lock_container)); |
512 | 521 |
513 lock_container->layer()->SetVisible(false); | 522 lock_container->layer()->SetVisible(false); |
514 w1->Focus(); | 523 w1->Focus(); |
515 EXPECT_TRUE(w1->HasFocus()); | 524 EXPECT_TRUE(w1->HasFocus()); |
516 } | 525 } |
517 | 526 |
518 } // namespace test | 527 } // namespace test |
519 } // namespace ash | 528 } // namespace ash |
OLD | NEW |