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/public/cpp/shell_window_ids.h" | 5 #include "ash/public/cpp/shell_window_ids.h" |
6 #include "ash/shell.h" | 6 #include "ash/shell.h" |
7 #include "ash/shell_port.h" | 7 #include "ash/shell_port.h" |
8 #include "ash/test/ash_test_base.h" | 8 #include "ash/test/ash_test_base.h" |
9 #include "ash/test/test_activation_delegate.h" | 9 #include "ash/test/test_activation_delegate.h" |
10 #include "ash/wm/window_util.h" | 10 #include "ash/wm/window_util.h" |
| 11 #include "ui/aura/client/aura_constants.h" |
11 #include "ui/aura/client/cursor_client_observer.h" | 12 #include "ui/aura/client/cursor_client_observer.h" |
12 #include "ui/aura/client/focus_client.h" | 13 #include "ui/aura/client/focus_client.h" |
13 #include "ui/aura/env.h" | 14 #include "ui/aura/env.h" |
14 #include "ui/aura/test/aura_test_base.h" | 15 #include "ui/aura/test/aura_test_base.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/base/cursor/cursor.h" | 18 #include "ui/base/cursor/cursor.h" |
18 #include "ui/base/hit_test.h" | 19 #include "ui/base/hit_test.h" |
19 #include "ui/display/screen.h" | 20 #include "ui/display/screen.h" |
20 #include "ui/events/event.h" | 21 #include "ui/events/event.h" |
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
342 EXPECT_EQ(w2.get(), focus_client->GetFocusedWindow()); | 343 EXPECT_EQ(w2.get(), focus_client->GetFocusedWindow()); |
343 EXPECT_FALSE(w11->CanFocus()); | 344 EXPECT_FALSE(w11->CanFocus()); |
344 | 345 |
345 // Click on |w11|. This should focus w1. | 346 // Click on |w11|. This should focus w1. |
346 generator.MoveMouseToCenterOf(w11.get()); | 347 generator.MoveMouseToCenterOf(w11.get()); |
347 generator.ClickLeftButton(); | 348 generator.ClickLeftButton(); |
348 EXPECT_EQ(w1.get(), focus_client->GetFocusedWindow()); | 349 EXPECT_EQ(w1.get(), focus_client->GetFocusedWindow()); |
349 } | 350 } |
350 } | 351 } |
351 | 352 |
| 353 // Tests that Set window property |kActivateOnClickKey| to false could properly |
| 354 // ignore mouse click window activation. |
| 355 TEST_F(WindowManagerTest, ActivateOnClickWindowProperty) { |
| 356 aura::Window* root_window = Shell::GetPrimaryRootWindow(); |
| 357 |
| 358 // Create two test windows, window1 and window2. |
| 359 aura::test::TestWindowDelegate wd; |
| 360 std::unique_ptr<aura::Window> w1( |
| 361 CreateTestWindowInShellWithDelegate(&wd, -1, gfx::Rect(10, 10, 50, 50))); |
| 362 std::unique_ptr<aura::Window> w2( |
| 363 CreateTestWindowInShellWithDelegate(&wd, -2, gfx::Rect(70, 70, 50, 50))); |
| 364 |
| 365 // Activate window1. |
| 366 wm::ActivateWindow(w1.get()); |
| 367 EXPECT_TRUE(wm::IsActiveWindow(w1.get())); |
| 368 EXPECT_FALSE(wm::IsActiveWindow(w2.get())); |
| 369 |
| 370 // Set window2 not click activatable. |
| 371 w2->SetProperty(aura::client::kActivateOnClickKey, false); |
| 372 // Click on window2. |
| 373 ui::test::EventGenerator generator(root_window, w2.get()); |
| 374 generator.ClickLeftButton(); |
| 375 // Window2 should not become active. |
| 376 EXPECT_FALSE(wm::IsActiveWindow(w2.get())); |
| 377 EXPECT_TRUE(wm::IsActiveWindow(w1.get())); |
| 378 |
| 379 // Other input events, like a gesture tap on window2 should activate window2. |
| 380 generator.GestureTapAt(w2->bounds().CenterPoint()); |
| 381 EXPECT_TRUE(wm::IsActiveWindow(w2.get())); |
| 382 EXPECT_FALSE(wm::IsActiveWindow(w1.get())); |
| 383 |
| 384 // Activate window1 again to deactivate window2. |
| 385 wm::ActivateWindow(w1.get()); |
| 386 EXPECT_TRUE(wm::IsActiveWindow(w1.get())); |
| 387 EXPECT_FALSE(wm::IsActiveWindow(w2.get())); |
| 388 |
| 389 // Set window2 now click activatable. |
| 390 w2->SetProperty(aura::client::kActivateOnClickKey, true); |
| 391 // Click on window2. |
| 392 generator.ClickLeftButton(); |
| 393 // Window2 should become active. |
| 394 EXPECT_TRUE(wm::IsActiveWindow(w2.get())); |
| 395 EXPECT_FALSE(wm::IsActiveWindow(w1.get())); |
| 396 } |
| 397 |
352 TEST_F(WindowManagerTest, PanelActivation) { | 398 TEST_F(WindowManagerTest, PanelActivation) { |
353 aura::test::TestWindowDelegate wd; | 399 aura::test::TestWindowDelegate wd; |
354 std::unique_ptr<aura::Window> w1( | 400 std::unique_ptr<aura::Window> w1( |
355 CreateTestWindowInShellWithDelegate(&wd, -1, gfx::Rect(10, 10, 50, 50))); | 401 CreateTestWindowInShellWithDelegate(&wd, -1, gfx::Rect(10, 10, 50, 50))); |
356 aura::test::TestWindowDelegate pd; | 402 aura::test::TestWindowDelegate pd; |
357 std::unique_ptr<aura::Window> p1(CreateTestWindowInShellWithDelegateAndType( | 403 std::unique_ptr<aura::Window> p1(CreateTestWindowInShellWithDelegateAndType( |
358 &pd, ui::wm::WINDOW_TYPE_PANEL, -1, gfx::Rect(10, 10, 50, 50))); | 404 &pd, ui::wm::WINDOW_TYPE_PANEL, -1, gfx::Rect(10, 10, 50, 50))); |
359 aura::client::FocusClient* focus_client = | 405 aura::client::FocusClient* focus_client = |
360 aura::client::GetFocusClient(w1.get()); | 406 aura::client::GetFocusClient(w1.get()); |
361 | 407 |
(...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
853 observer_b.reset(); | 899 observer_b.reset(); |
854 generator.MoveMouseTo(50, 50); | 900 generator.MoveMouseTo(50, 50); |
855 EXPECT_TRUE(observer_a.did_visibility_change()); | 901 EXPECT_TRUE(observer_a.did_visibility_change()); |
856 EXPECT_FALSE(observer_b.did_visibility_change()); | 902 EXPECT_FALSE(observer_b.did_visibility_change()); |
857 EXPECT_TRUE(observer_a.is_cursor_visible()); | 903 EXPECT_TRUE(observer_a.is_cursor_visible()); |
858 | 904 |
859 cursor_manager->RemoveObserver(&observer_a); | 905 cursor_manager->RemoveObserver(&observer_a); |
860 } | 906 } |
861 | 907 |
862 } // namespace ash | 908 } // namespace ash |
OLD | NEW |