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/display/display_manager.h" | 5 #include "ash/display/display_manager.h" |
6 | 6 |
7 #include "ash/display/display_controller.h" | 7 #include "ash/display/display_controller.h" |
8 #include "ash/screen_ash.h" | 8 #include "ash/screen_ash.h" |
9 #include "ash/shell.h" | 9 #include "ash/shell.h" |
10 #include "ash/test/ash_test_base.h" | 10 #include "ash/test/ash_test_base.h" |
11 #include "ash/test/display_manager_test_api.h" | 11 #include "ash/test/display_manager_test_api.h" |
12 #include "base/format_macros.h" | 12 #include "base/format_macros.h" |
13 #include "base/stringprintf.h" | 13 #include "base/stringprintf.h" |
14 #include "ui/aura/env.h" | 14 #include "ui/aura/env.h" |
15 #include "ui/aura/root_window.h" | 15 #include "ui/aura/root_window.h" |
| 16 #include "ui/aura/test/event_generator.h" |
16 #include "ui/aura/window_observer.h" | 17 #include "ui/aura/window_observer.h" |
17 #include "ui/gfx/display_observer.h" | 18 #include "ui/gfx/display_observer.h" |
18 #include "ui/gfx/display.h" | 19 #include "ui/gfx/display.h" |
19 | 20 |
20 namespace ash { | 21 namespace ash { |
21 namespace internal { | 22 namespace internal { |
22 | 23 |
23 using std::vector; | 24 using std::vector; |
24 using std::string; | 25 using std::string; |
25 | 26 |
(...skipping 524 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
550 EXPECT_EQ("100x100", | 551 EXPECT_EQ("100x100", |
551 ash::Shell::GetPrimaryRootWindow()->GetHostSize().ToString()); | 552 ash::Shell::GetPrimaryRootWindow()->GetHostSize().ToString()); |
552 } | 553 } |
553 | 554 |
554 TEST_F(DisplayManagerTest, EnsurePointerInDisplays) { | 555 TEST_F(DisplayManagerTest, EnsurePointerInDisplays) { |
555 UpdateDisplay("200x200,300x300"); | 556 UpdateDisplay("200x200,300x300"); |
556 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); | 557 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
557 | 558 |
558 aura::Env* env = aura::Env::GetInstance(); | 559 aura::Env* env = aura::Env::GetInstance(); |
559 | 560 |
| 561 aura::test::EventGenerator generator(root_windows[0]); |
| 562 |
560 // Set the initial position. | 563 // Set the initial position. |
561 root_windows[0]->MoveCursorTo(gfx::Point(350, 150)); | 564 generator.MoveMouseToInHost(350, 150); |
562 EXPECT_EQ("350,150", env->last_mouse_location().ToString()); | 565 EXPECT_EQ("350,150", env->last_mouse_location().ToString()); |
563 | 566 |
564 // A mouse pointer will be inside 2nd display. | 567 // A mouse pointer will be inside 2nd display. |
565 UpdateDisplay("300x300,200x200"); | 568 UpdateDisplay("300x300,200x200"); |
566 EXPECT_EQ("350,150", env->last_mouse_location().ToString()); | 569 EXPECT_EQ("350,150", env->last_mouse_location().ToString()); |
567 | 570 |
568 // A mouse pointer will be outside of displays and move to the | 571 // A mouse pointer will be outside of displays and move to the |
569 // center of 2nd display. | 572 // center of 2nd display. |
570 UpdateDisplay("300x300,100x100"); | 573 UpdateDisplay("300x300,100x100"); |
571 EXPECT_EQ("350,50", env->last_mouse_location().ToString()); | 574 EXPECT_EQ("350,50", env->last_mouse_location().ToString()); |
572 | 575 |
573 // 2nd display was disconnected, but the mouse pointer says in the | 576 // 2nd display was disconnected, but the mouse pointer says in the |
574 // 1st display. | 577 // 1st display. |
575 UpdateDisplay("400x400"); | 578 UpdateDisplay("400x400"); |
576 EXPECT_EQ("350,50", env->last_mouse_location().ToString()); | 579 EXPECT_EQ("350,50", env->last_mouse_location().ToString()); |
577 | 580 |
578 // 1st display's resolution has changed, and the mouse pointer is | 581 // 1st display's resolution has changed, and the mouse pointer is |
579 // now outside. Move the mouse pointer to the center of 1st display. | 582 // now outside. Move the mouse pointer to the center of 1st display. |
580 UpdateDisplay("300x300"); | 583 UpdateDisplay("300x300"); |
581 EXPECT_EQ("150,150", env->last_mouse_location().ToString()); | 584 EXPECT_EQ("150,150", env->last_mouse_location().ToString()); |
582 | 585 |
583 // Move the mouse pointer to the bottom of 1st display. | 586 // Move the mouse pointer to the bottom of 1st display. |
584 root_windows[0]->MoveCursorTo(gfx::Point(150, 290)); | 587 generator.MoveMouseToInHost(150, 290); |
585 EXPECT_EQ("150,290", env->last_mouse_location().ToString()); | 588 EXPECT_EQ("150,290", env->last_mouse_location().ToString()); |
586 | 589 |
587 // The mouse pointer is outside and closest display is 1st one. | 590 // The mouse pointer is outside and closest display is 1st one. |
588 UpdateDisplay("300x280,200x200"); | 591 UpdateDisplay("300x280,200x200"); |
589 EXPECT_EQ("150,140", env->last_mouse_location().ToString()); | 592 EXPECT_EQ("150,140", env->last_mouse_location().ToString()); |
590 } | 593 } |
591 | 594 |
592 TEST_F(DisplayManagerTest, EnsurePointerInDisplays_2ndOnLeft) { | 595 TEST_F(DisplayManagerTest, EnsurePointerInDisplays_2ndOnLeft) { |
593 // Set the 2nd display on the left. | 596 // Set the 2nd display on the left. |
594 DisplayController* display_controller = | 597 DisplayController* display_controller = |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
789 #else | 792 #else |
790 #define MAYBE_UpdateMouseCursorAfterRotateZoom UpdateMouseCursorAfterRotateZoom | 793 #define MAYBE_UpdateMouseCursorAfterRotateZoom UpdateMouseCursorAfterRotateZoom |
791 #endif | 794 #endif |
792 | 795 |
793 TEST_F(DisplayManagerTest, MAYBE_UpdateMouseCursorAfterRotateZoom) { | 796 TEST_F(DisplayManagerTest, MAYBE_UpdateMouseCursorAfterRotateZoom) { |
794 // Make sure just rotating will not change native location. | 797 // Make sure just rotating will not change native location. |
795 UpdateDisplay("300x200,200x150"); | 798 UpdateDisplay("300x200,200x150"); |
796 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); | 799 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
797 aura::Env* env = aura::Env::GetInstance(); | 800 aura::Env* env = aura::Env::GetInstance(); |
798 | 801 |
| 802 aura::test::EventGenerator generator1(root_windows[0]); |
| 803 aura::test::EventGenerator generator2(root_windows[1]); |
| 804 |
799 // Test on 1st display. | 805 // Test on 1st display. |
800 root_windows[0]->MoveCursorTo(gfx::Point(150, 50)); | 806 generator1.MoveMouseToInHost(150, 50); |
801 EXPECT_EQ("150,50", env->last_mouse_location().ToString()); | 807 EXPECT_EQ("150,50", env->last_mouse_location().ToString()); |
802 UpdateDisplay("300x200/r,200x150"); | 808 UpdateDisplay("300x200/r,200x150"); |
803 EXPECT_EQ("50,149", env->last_mouse_location().ToString()); | 809 EXPECT_EQ("50,149", env->last_mouse_location().ToString()); |
804 | 810 |
805 // Test on 2nd display. | 811 // Test on 2nd display. |
806 root_windows[1]->MoveCursorTo(gfx::Point(50, 100)); | 812 generator2.MoveMouseToInHost(50, 100); |
807 EXPECT_EQ("250,100", env->last_mouse_location().ToString()); | 813 EXPECT_EQ("250,100", env->last_mouse_location().ToString()); |
808 UpdateDisplay("300x200/r,200x150/l"); | 814 UpdateDisplay("300x200/r,200x150/l"); |
809 EXPECT_EQ("249,50", env->last_mouse_location().ToString()); | 815 EXPECT_EQ("249,50", env->last_mouse_location().ToString()); |
810 | 816 |
811 // Make sure just zooming will not change native location. | 817 // Make sure just zooming will not change native location. |
812 UpdateDisplay("600x400*2,400x300"); | 818 UpdateDisplay("600x400*2,400x300"); |
813 | 819 |
814 // Test on 1st display. | 820 // Test on 1st display. |
815 root_windows[0]->MoveCursorTo(gfx::Point(100, 150)); | 821 generator1.MoveMouseToInHost(200, 300); |
816 EXPECT_EQ("100,150", env->last_mouse_location().ToString()); | 822 EXPECT_EQ("100,150", env->last_mouse_location().ToString()); |
817 UpdateDisplay("600x400*2@1.5,400x300"); | 823 UpdateDisplay("600x400*2@1.5,400x300"); |
818 EXPECT_EQ("150,225", env->last_mouse_location().ToString()); | 824 EXPECT_EQ("150,225", env->last_mouse_location().ToString()); |
819 | 825 |
820 // Test on 2nd display. | 826 // Test on 2nd display. |
821 UpdateDisplay("600x400,400x300*2"); | 827 UpdateDisplay("600x400,400x300*2"); |
822 root_windows[1]->MoveCursorTo(gfx::Point(100, 50)); | 828 generator2.MoveMouseToInHost(200, 100); |
823 EXPECT_EQ("700,50", env->last_mouse_location().ToString()); | 829 EXPECT_EQ("700,50", env->last_mouse_location().ToString()); |
824 UpdateDisplay("600x400,400x300*2@1.5"); | 830 UpdateDisplay("600x400,400x300*2@1.5"); |
825 EXPECT_EQ("750,75", env->last_mouse_location().ToString()); | 831 EXPECT_EQ("750,75", env->last_mouse_location().ToString()); |
826 } | 832 } |
827 | 833 |
828 } // namespace internal | 834 } // namespace internal |
829 } // namespace ash | 835 } // namespace ash |
OLD | NEW |