Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1108)

Side by Side Diff: ash/wm/window_manager_unittest.cc

Issue 2739703003: Last sets of tests that can move to common_unittests (Closed)
Patch Set: comments Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/common/wm_shell.h"
5 #include "ash/public/cpp/shell_window_ids.h" 6 #include "ash/public/cpp/shell_window_ids.h"
6 #include "ash/shell.h" 7 #include "ash/shell.h"
7 #include "ash/test/ash_test_base.h" 8 #include "ash/test/ash_test_base.h"
8 #include "ash/test/test_activation_delegate.h" 9 #include "ash/test/test_activation_delegate.h"
9 #include "ash/wm/window_util.h" 10 #include "ash/wm/window_util.h"
10 #include "ui/aura/client/cursor_client_observer.h" 11 #include "ui/aura/client/cursor_client_observer.h"
11 #include "ui/aura/client/focus_client.h" 12 #include "ui/aura/client/focus_client.h"
12 #include "ui/aura/env.h" 13 #include "ui/aura/env.h"
13 #include "ui/aura/test/aura_test_base.h" 14 #include "ui/aura/test/aura_test_base.h"
14 #include "ui/aura/test/test_window_delegate.h" 15 #include "ui/aura/test/test_window_delegate.h"
(...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after
454 w2.reset(); 455 w2.reset();
455 EXPECT_EQ(0, d2.activated_count()); 456 EXPECT_EQ(0, d2.activated_count());
456 EXPECT_EQ(1, d2.lost_active_count()); 457 EXPECT_EQ(1, d2.lost_active_count());
457 EXPECT_TRUE(wm::IsActiveWindow(w1.get())); 458 EXPECT_TRUE(wm::IsActiveWindow(w1.get()));
458 EXPECT_EQ(w1.get(), focus_client->GetFocusedWindow()); 459 EXPECT_EQ(w1.get(), focus_client->GetFocusedWindow());
459 EXPECT_EQ(1, d1.activated_count()); 460 EXPECT_EQ(1, d1.activated_count());
460 EXPECT_EQ(0, d1.lost_active_count()); 461 EXPECT_EQ(0, d1.lost_active_count());
461 } 462 }
462 463
463 TEST_F(WindowManagerTest, MouseEventCursors) { 464 TEST_F(WindowManagerTest, MouseEventCursors) {
465 // TODO: investigate failure in mash. http://crbug.com/698895.
466 if (WmShell::Get()->IsRunningInMash())
467 return;
468
464 aura::Window* root_window = Shell::GetPrimaryRootWindow(); 469 aura::Window* root_window = Shell::GetPrimaryRootWindow();
465 470
466 // Create a window. 471 // Create a window.
467 const int kWindowLeft = 123; 472 const int kWindowLeft = 123;
468 const int kWindowTop = 45; 473 const int kWindowTop = 45;
469 HitTestWindowDelegate window_delegate; 474 HitTestWindowDelegate window_delegate;
470 std::unique_ptr<aura::Window> window(CreateTestWindowInShellWithDelegate( 475 std::unique_ptr<aura::Window> window(CreateTestWindowInShellWithDelegate(
471 &window_delegate, -1, gfx::Rect(kWindowLeft, kWindowTop, 640, 480))); 476 &window_delegate, -1, gfx::Rect(kWindowLeft, kWindowTop, 640, 480)));
472 477
473 // Create two mouse movement events we can switch between. 478 // Create two mouse movement events we can switch between.
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
689 EXPECT_EQ(0, f1->num_key_events()); 694 EXPECT_EQ(0, f1->num_key_events());
690 EXPECT_EQ(0, f1->num_mouse_events()); 695 EXPECT_EQ(0, f1->num_mouse_events());
691 EXPECT_EQ(1, f2->num_key_events()); 696 EXPECT_EQ(1, f2->num_key_events());
692 EXPECT_EQ(1, f2->num_mouse_events()); 697 EXPECT_EQ(1, f2->num_mouse_events());
693 698
694 env_filter->RemoveHandler(f2.get()); 699 env_filter->RemoveHandler(f2.get());
695 } 700 }
696 701
697 // Touch visually hides the cursor. 702 // Touch visually hides the cursor.
698 TEST_F(WindowManagerTest, UpdateCursorVisibility) { 703 TEST_F(WindowManagerTest, UpdateCursorVisibility) {
704 // TODO: mash doesn't support CursorManager. http://crbug.com/631103.
705 if (WmShell::Get()->IsRunningInMash())
706 return;
707
699 ui::test::EventGenerator& generator = GetEventGenerator(); 708 ui::test::EventGenerator& generator = GetEventGenerator();
700 ::wm::CursorManager* cursor_manager = 709 ::wm::CursorManager* cursor_manager =
701 ash::Shell::GetInstance()->cursor_manager(); 710 ash::Shell::GetInstance()->cursor_manager();
702 711
703 generator.MoveMouseTo(gfx::Point(0, 0)); 712 generator.MoveMouseTo(gfx::Point(0, 0));
704 EXPECT_TRUE(cursor_manager->IsCursorVisible()); 713 EXPECT_TRUE(cursor_manager->IsCursorVisible());
705 EXPECT_TRUE(cursor_manager->IsMouseEventsEnabled()); 714 EXPECT_TRUE(cursor_manager->IsMouseEventsEnabled());
706 generator.PressTouch(); 715 generator.PressTouch();
707 EXPECT_FALSE(cursor_manager->IsCursorVisible()); 716 EXPECT_FALSE(cursor_manager->IsCursorVisible());
708 EXPECT_FALSE(cursor_manager->IsMouseEventsEnabled()); 717 EXPECT_FALSE(cursor_manager->IsMouseEventsEnabled());
709 generator.MoveMouseTo(gfx::Point(0, 0)); 718 generator.MoveMouseTo(gfx::Point(0, 0));
710 EXPECT_TRUE(cursor_manager->IsCursorVisible()); 719 EXPECT_TRUE(cursor_manager->IsCursorVisible());
711 EXPECT_TRUE(cursor_manager->IsMouseEventsEnabled()); 720 EXPECT_TRUE(cursor_manager->IsMouseEventsEnabled());
712 generator.ReleaseTouch(); 721 generator.ReleaseTouch();
713 EXPECT_TRUE(cursor_manager->IsCursorVisible()); 722 EXPECT_TRUE(cursor_manager->IsCursorVisible());
714 EXPECT_TRUE(cursor_manager->IsMouseEventsEnabled()); 723 EXPECT_TRUE(cursor_manager->IsMouseEventsEnabled());
715 } 724 }
716 725
717 // Cursor is hidden on keypress. 726 // Cursor is hidden on keypress.
718 TEST_F(WindowManagerTest, UpdateCursorVisibilityOnKeyEvent) { 727 TEST_F(WindowManagerTest, UpdateCursorVisibilityOnKeyEvent) {
728 // TODO: mash doesn't support CursorManager. http://crbug.com/631103.
729 if (WmShell::Get()->IsRunningInMash())
730 return;
731
719 ui::test::EventGenerator& generator = GetEventGenerator(); 732 ui::test::EventGenerator& generator = GetEventGenerator();
720 ::wm::CursorManager* cursor_manager = 733 ::wm::CursorManager* cursor_manager =
721 ash::Shell::GetInstance()->cursor_manager(); 734 ash::Shell::GetInstance()->cursor_manager();
722 735
723 // Pressing a key hides the cursor but does not disable mouse events. 736 // Pressing a key hides the cursor but does not disable mouse events.
724 generator.PressKey(ui::VKEY_A, ui::EF_NONE); 737 generator.PressKey(ui::VKEY_A, ui::EF_NONE);
725 EXPECT_FALSE(cursor_manager->IsCursorVisible()); 738 EXPECT_FALSE(cursor_manager->IsCursorVisible());
726 EXPECT_TRUE(cursor_manager->IsMouseEventsEnabled()); 739 EXPECT_TRUE(cursor_manager->IsMouseEventsEnabled());
727 // Moving mouse shows the cursor. 740 // Moving mouse shows the cursor.
728 generator.MoveMouseTo(gfx::Point(0, 0)); 741 generator.MoveMouseTo(gfx::Point(0, 0));
729 EXPECT_TRUE(cursor_manager->IsCursorVisible()); 742 EXPECT_TRUE(cursor_manager->IsCursorVisible());
730 EXPECT_TRUE(cursor_manager->IsMouseEventsEnabled()); 743 EXPECT_TRUE(cursor_manager->IsMouseEventsEnabled());
731 // Releasing a key does does not hide the cursor and does not disable mouse 744 // Releasing a key does does not hide the cursor and does not disable mouse
732 // events. 745 // events.
733 generator.ReleaseKey(ui::VKEY_A, ui::EF_NONE); 746 generator.ReleaseKey(ui::VKEY_A, ui::EF_NONE);
734 EXPECT_TRUE(cursor_manager->IsCursorVisible()); 747 EXPECT_TRUE(cursor_manager->IsCursorVisible());
735 EXPECT_TRUE(cursor_manager->IsMouseEventsEnabled()); 748 EXPECT_TRUE(cursor_manager->IsMouseEventsEnabled());
736 } 749 }
737 750
738 // Test that pressing an accelerator does not hide the cursor. 751 // Test that pressing an accelerator does not hide the cursor.
739 TEST_F(WindowManagerTest, UpdateCursorVisibilityAccelerator) { 752 TEST_F(WindowManagerTest, UpdateCursorVisibilityAccelerator) {
753 // TODO: mash doesn't support CursorManager. http://crbug.com/631103.
754 if (WmShell::Get()->IsRunningInMash())
755 return;
756
740 ui::test::EventGenerator& generator = GetEventGenerator(); 757 ui::test::EventGenerator& generator = GetEventGenerator();
741 ::wm::CursorManager* cursor_manager = Shell::GetInstance()->cursor_manager(); 758 ::wm::CursorManager* cursor_manager = Shell::GetInstance()->cursor_manager();
742 759
743 ASSERT_TRUE(cursor_manager->IsCursorVisible()); 760 ASSERT_TRUE(cursor_manager->IsCursorVisible());
744 761
745 // Press Ctrl+A, release A first. 762 // Press Ctrl+A, release A first.
746 generator.PressKey(ui::VKEY_CONTROL, ui::EF_CONTROL_DOWN); 763 generator.PressKey(ui::VKEY_CONTROL, ui::EF_CONTROL_DOWN);
747 generator.PressKey(ui::VKEY_A, ui::EF_CONTROL_DOWN); 764 generator.PressKey(ui::VKEY_A, ui::EF_CONTROL_DOWN);
748 generator.ReleaseKey(ui::VKEY_A, ui::EF_CONTROL_DOWN); 765 generator.ReleaseKey(ui::VKEY_A, ui::EF_CONTROL_DOWN);
749 generator.ReleaseKey(ui::VKEY_CONTROL, ui::EF_NONE); 766 generator.ReleaseKey(ui::VKEY_CONTROL, ui::EF_NONE);
750 EXPECT_TRUE(cursor_manager->IsCursorVisible()); 767 EXPECT_TRUE(cursor_manager->IsCursorVisible());
751 768
752 // Press Ctrl+A, release Ctrl first. 769 // Press Ctrl+A, release Ctrl first.
753 generator.PressKey(ui::VKEY_CONTROL, ui::EF_CONTROL_DOWN); 770 generator.PressKey(ui::VKEY_CONTROL, ui::EF_CONTROL_DOWN);
754 generator.PressKey(ui::VKEY_A, ui::EF_CONTROL_DOWN); 771 generator.PressKey(ui::VKEY_A, ui::EF_CONTROL_DOWN);
755 generator.ReleaseKey(ui::VKEY_CONTROL, ui::EF_NONE); 772 generator.ReleaseKey(ui::VKEY_CONTROL, ui::EF_NONE);
756 generator.ReleaseKey(ui::VKEY_A, ui::EF_NONE); 773 generator.ReleaseKey(ui::VKEY_A, ui::EF_NONE);
757 EXPECT_TRUE(cursor_manager->IsCursorVisible()); 774 EXPECT_TRUE(cursor_manager->IsCursorVisible());
758 } 775 }
759 776
760 TEST_F(WindowManagerTest, TestCursorClientObserver) { 777 TEST_F(WindowManagerTest, TestCursorClientObserver) {
778 // TODO: mash doesn't support CursorManager. http://crbug.com/631103.
779 if (WmShell::Get()->IsRunningInMash())
780 return;
781
761 ui::test::EventGenerator& generator = GetEventGenerator(); 782 ui::test::EventGenerator& generator = GetEventGenerator();
762 ::wm::CursorManager* cursor_manager = 783 ::wm::CursorManager* cursor_manager =
763 ash::Shell::GetInstance()->cursor_manager(); 784 ash::Shell::GetInstance()->cursor_manager();
764 785
765 std::unique_ptr<aura::Window> w1( 786 std::unique_ptr<aura::Window> w1(
766 CreateTestWindowInShell(SK_ColorWHITE, -1, gfx::Rect(0, 0, 100, 100))); 787 CreateTestWindowInShell(SK_ColorWHITE, -1, gfx::Rect(0, 0, 100, 100)));
767 wm::ActivateWindow(w1.get()); 788 wm::ActivateWindow(w1.get());
768 789
769 // Add two observers. Both should have OnCursorVisibilityChanged() 790 // Add two observers. Both should have OnCursorVisibilityChanged()
770 // invoked when an event changes the visibility of the cursor. 791 // invoked when an event changes the visibility of the cursor.
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
829 observer_b.reset(); 850 observer_b.reset();
830 generator.MoveMouseTo(50, 50); 851 generator.MoveMouseTo(50, 50);
831 EXPECT_TRUE(observer_a.did_visibility_change()); 852 EXPECT_TRUE(observer_a.did_visibility_change());
832 EXPECT_FALSE(observer_b.did_visibility_change()); 853 EXPECT_FALSE(observer_b.did_visibility_change());
833 EXPECT_TRUE(observer_a.is_cursor_visible()); 854 EXPECT_TRUE(observer_a.is_cursor_visible());
834 855
835 cursor_manager->RemoveObserver(&observer_a); 856 cursor_manager->RemoveObserver(&observer_a);
836 } 857 }
837 858
838 } // namespace ash 859 } // namespace ash
OLDNEW
« no previous file with comments | « ash/wm/window_cycle_controller_unittest.cc ('k') | ash/wm/window_modality_controller_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698