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" |
11 #include "ash/wm/window_util.h" | 11 #include "ash/wm/window_util.h" |
| 12 #include "ui/aura/client/aura_constants.h" |
12 #include "ui/aura/focus_manager.h" | 13 #include "ui/aura/focus_manager.h" |
13 #include "ui/aura/root_window.h" | 14 #include "ui/aura/root_window.h" |
14 #include "ui/aura/test/event_generator.h" | 15 #include "ui/aura/test/event_generator.h" |
15 #include "ui/aura/test/test_window_delegate.h" | 16 #include "ui/aura/test/test_window_delegate.h" |
16 #include "ui/aura/test/test_windows.h" | 17 #include "ui/aura/test/test_windows.h" |
17 #include "ui/gfx/compositor/layer.h" | 18 #include "ui/gfx/compositor/layer.h" |
18 | 19 |
19 #if defined(OS_WIN) | 20 #if defined(OS_WIN) |
20 // Windows headers define macros for these function names which screw with us. | 21 // Windows headers define macros for these function names which screw with us. |
21 #if defined(CreateWindow) | 22 #if defined(CreateWindow) |
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
311 EXPECT_TRUE(wm::IsActiveWindow(w2.get())); | 312 EXPECT_TRUE(wm::IsActiveWindow(w2.get())); |
312 EXPECT_TRUE(w21->HasFocus()); | 313 EXPECT_TRUE(w21->HasFocus()); |
313 } | 314 } |
314 | 315 |
315 // Verifies that we prevent all attempts to focus a child of a non-activatable | 316 // Verifies that we prevent all attempts to focus a child of a non-activatable |
316 // window from claiming focus to that window. | 317 // window from claiming focus to that window. |
317 TEST_F(ActivationControllerTest, PreventFocusToNonActivatableWindow) { | 318 TEST_F(ActivationControllerTest, PreventFocusToNonActivatableWindow) { |
318 aura::test::TestWindowDelegate wd; | 319 aura::test::TestWindowDelegate wd; |
319 scoped_ptr<aura::Window> w1(aura::test::CreateTestWindowWithDelegate( | 320 scoped_ptr<aura::Window> w1(aura::test::CreateTestWindowWithDelegate( |
320 &wd, -1, gfx::Rect(50, 50), NULL)); | 321 &wd, -1, gfx::Rect(50, 50), NULL)); |
321 // The RootWindow itself is a non-activatable parent. | 322 // The RootWindow is a non-activatable parent. |
322 scoped_ptr<aura::Window> w2(aura::test::CreateTestWindowWithDelegate( | 323 scoped_ptr<aura::Window> w2(aura::test::CreateTestWindowWithDelegate( |
323 &wd, -2, gfx::Rect(50, 50), Shell::GetRootWindow())); | 324 &wd, -2, gfx::Rect(50, 50), Shell::GetRootWindow())); |
324 scoped_ptr<aura::Window> w21(aura::test::CreateTestWindowWithDelegate( | 325 scoped_ptr<aura::Window> w21(aura::test::CreateTestWindowWithDelegate( |
325 &wd, -21, gfx::Rect(50, 50), w2.get())); | 326 &wd, -21, gfx::Rect(50, 50), w2.get())); |
326 | 327 |
327 wm::ActivateWindow(w1.get()); | 328 wm::ActivateWindow(w1.get()); |
328 EXPECT_TRUE(wm::IsActiveWindow(w1.get())); | 329 EXPECT_TRUE(wm::IsActiveWindow(w1.get())); |
329 EXPECT_TRUE(w1->HasFocus()); | 330 EXPECT_TRUE(w1->HasFocus()); |
330 | 331 |
331 // Try activating |w2|. It's not a child of an activatable container, so it | 332 // Try activating |w2|. It's not a child of an activatable container, so it |
(...skipping 11 matching lines...) Expand all Loading... |
343 EXPECT_TRUE(wm::IsActiveWindow(w1.get())); | 344 EXPECT_TRUE(wm::IsActiveWindow(w1.get())); |
344 EXPECT_TRUE(w1->HasFocus()); | 345 EXPECT_TRUE(w1->HasFocus()); |
345 | 346 |
346 // Try focusing |w21|. Same rules apply. | 347 // Try focusing |w21|. Same rules apply. |
347 EXPECT_FALSE(wm::IsActiveWindow(w2.get())); | 348 EXPECT_FALSE(wm::IsActiveWindow(w2.get())); |
348 EXPECT_FALSE(w21->HasFocus()); | 349 EXPECT_FALSE(w21->HasFocus()); |
349 EXPECT_TRUE(wm::IsActiveWindow(w1.get())); | 350 EXPECT_TRUE(wm::IsActiveWindow(w1.get())); |
350 EXPECT_TRUE(w1->HasFocus()); | 351 EXPECT_TRUE(w1->HasFocus()); |
351 } | 352 } |
352 | 353 |
| 354 TEST_F(ActivationControllerTest, CanActivateWindowIteselfTest) |
| 355 { |
| 356 aura::test::TestWindowDelegate wd; |
| 357 |
| 358 // Normal Window |
| 359 scoped_ptr<aura::Window> w1(aura::test::CreateTestWindowWithDelegate( |
| 360 &wd, -1, gfx::Rect(50, 50), NULL)); |
| 361 EXPECT_TRUE(wm::CanActivateWindow(w1.get())); |
| 362 |
| 363 // The RootWindow is a non-activatable parent. |
| 364 scoped_ptr<aura::Window> w2(aura::test::CreateTestWindowWithDelegate( |
| 365 &wd, -2, gfx::Rect(50, 50), Shell::GetRootWindow())); |
| 366 scoped_ptr<aura::Window> w21(aura::test::CreateTestWindowWithDelegate( |
| 367 &wd, -21, gfx::Rect(50, 50), w2.get())); |
| 368 EXPECT_FALSE(wm::CanActivateWindow(w2.get())); |
| 369 EXPECT_FALSE(wm::CanActivateWindow(w21.get())); |
| 370 |
| 371 // The window has a transient child. |
| 372 scoped_ptr<aura::Window> w3(aura::test::CreateTestWindowWithDelegate( |
| 373 &wd, -3, gfx::Rect(50, 50), NULL)); |
| 374 scoped_ptr<aura::Window> w31(aura::test::CreateTestWindowWithDelegate( |
| 375 &wd, -31, gfx::Rect(50, 50), NULL)); |
| 376 w3->AddTransientChild(w31.get()); |
| 377 EXPECT_TRUE(wm::CanActivateWindow(w3.get())); |
| 378 EXPECT_TRUE(wm::CanActivateWindow(w31.get())); |
| 379 |
| 380 // The window has a transient window-modal child. |
| 381 scoped_ptr<aura::Window> w4(aura::test::CreateTestWindowWithDelegate( |
| 382 &wd, -4, gfx::Rect(50, 50), NULL)); |
| 383 scoped_ptr<aura::Window> w41(aura::test::CreateTestWindowWithDelegate( |
| 384 &wd, -41, gfx::Rect(50, 50), NULL)); |
| 385 w4->AddTransientChild(w41.get()); |
| 386 w41->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_WINDOW); |
| 387 EXPECT_FALSE(wm::CanActivateWindow(w4.get())); |
| 388 EXPECT_TRUE(wm::CanActivateWindow(w41.get())); |
| 389 |
| 390 // The window has a transient system-modal child. |
| 391 scoped_ptr<aura::Window> w5(aura::test::CreateTestWindowWithDelegate( |
| 392 &wd, -5, gfx::Rect(50, 50), NULL)); |
| 393 scoped_ptr<aura::Window> w51(aura::test::CreateTestWindowWithDelegate( |
| 394 &wd, -51, gfx::Rect(50, 50), NULL)); |
| 395 w5->AddTransientChild(w51.get()); |
| 396 w51->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_SYSTEM); |
| 397 EXPECT_TRUE(wm::CanActivateWindow(w5.get())); |
| 398 EXPECT_TRUE(wm::CanActivateWindow(w51.get())); |
| 399 } |
| 400 |
353 // Verifies code in ActivationController::OnWindowVisibilityChanged() that keeps | 401 // Verifies code in ActivationController::OnWindowVisibilityChanged() that keeps |
354 // hiding windows layers stacked above the newly active window while they | 402 // hiding windows layers stacked above the newly active window while they |
355 // animate away. | 403 // animate away. |
356 TEST_F(ActivationControllerTest, AnimateHideMaintainsStacking) { | 404 TEST_F(ActivationControllerTest, AnimateHideMaintainsStacking) { |
357 aura::test::TestWindowDelegate wd; | 405 aura::test::TestWindowDelegate wd; |
358 scoped_ptr<aura::Window> w1(aura::test::CreateTestWindowWithDelegate( | 406 scoped_ptr<aura::Window> w1(aura::test::CreateTestWindowWithDelegate( |
359 &wd, -1, gfx::Rect(50, 50, 50, 50), NULL)); | 407 &wd, -1, gfx::Rect(50, 50, 50, 50), NULL)); |
360 scoped_ptr<aura::Window> w2(aura::test::CreateTestWindowWithDelegate( | 408 scoped_ptr<aura::Window> w2(aura::test::CreateTestWindowWithDelegate( |
361 &wd, -2, gfx::Rect(75, 75, 50, 50), NULL)); | 409 &wd, -2, gfx::Rect(75, 75, 50, 50), NULL)); |
362 wm::ActivateWindow(w2.get()); | 410 wm::ActivateWindow(w2.get()); |
363 EXPECT_TRUE(wm::IsActiveWindow(w2.get())); | 411 EXPECT_TRUE(wm::IsActiveWindow(w2.get())); |
364 w2->Hide(); | 412 w2->Hide(); |
365 typedef std::vector<ui::Layer*> Layers; | 413 typedef std::vector<ui::Layer*> Layers; |
366 const Layers& children = w1->parent()->layer()->children(); | 414 const Layers& children = w1->parent()->layer()->children(); |
367 Layers::const_iterator w1_iter = | 415 Layers::const_iterator w1_iter = |
368 std::find(children.begin(), children.end(), w1->layer()); | 416 std::find(children.begin(), children.end(), w1->layer()); |
369 Layers::const_iterator w2_iter = | 417 Layers::const_iterator w2_iter = |
370 std::find(children.begin(), children.end(), w2->layer()); | 418 std::find(children.begin(), children.end(), w2->layer()); |
371 EXPECT_TRUE(w2_iter > w1_iter); | 419 EXPECT_TRUE(w2_iter > w1_iter); |
372 } | 420 } |
373 | 421 |
374 } // namespace test | 422 } // namespace test |
375 } // namespace ash | 423 } // namespace ash |
OLD | NEW |