OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/unified_mouse_warp_controller.h" | 5 #include "ash/display/unified_mouse_warp_controller.h" |
6 | 6 |
7 #include "ash/display/mouse_cursor_event_filter.h" | 7 #include "ash/display/mouse_cursor_event_filter.h" |
8 #include "ash/shell.h" | 8 #include "ash/shell.h" |
9 #include "ash/test/ash_test_base.h" | 9 #include "ash/test/ash_test_base.h" |
10 #include "ash/test/display_manager_test_api.h" | 10 #include "ash/test/display_manager_test_api.h" |
(...skipping 22 matching lines...) Expand all Loading... | |
33 | 33 |
34 MouseCursorEventFilter* event_filter() { | 34 MouseCursorEventFilter* event_filter() { |
35 return Shell::GetInstance()->mouse_cursor_filter(); | 35 return Shell::GetInstance()->mouse_cursor_filter(); |
36 } | 36 } |
37 | 37 |
38 UnifiedMouseWarpController* mouse_warp_controller() { | 38 UnifiedMouseWarpController* mouse_warp_controller() { |
39 return static_cast<UnifiedMouseWarpController*>( | 39 return static_cast<UnifiedMouseWarpController*>( |
40 event_filter()->mouse_warp_controller_for_test()); | 40 event_filter()->mouse_warp_controller_for_test()); |
41 } | 41 } |
42 | 42 |
43 void BoundaryTestBody(const std::string& displays_with_same_height, | |
44 const std::string& displays_with_different_heights) { | |
45 UpdateDisplay(displays_with_same_height); | |
46 aura::Window::Windows root_windows = Shell::GetAllRootWindows(); | |
47 // Let the UnifiedMouseWarpController compute the bounds by | |
48 // generating a mouse move event. | |
49 GetEventGenerator().MoveMouseTo(gfx::Point(0, 0)); | |
50 EXPECT_EQ("399,0 1x400", | |
51 mouse_warp_controller()->first_edge_bounds_in_native_.ToString()); | |
52 EXPECT_EQ( | |
53 "0,450 1x400", | |
54 mouse_warp_controller()->second_edge_bounds_in_native_.ToString()); | |
55 | |
56 // Scaled. | |
57 UpdateDisplay(displays_with_different_heights); | |
58 root_windows = Shell::GetAllRootWindows(); | |
59 // Let the UnifiedMouseWarpController compute the bounds by | |
60 // generating a mouse move event. | |
61 GetEventGenerator().MoveMouseTo(gfx::Point(1, 1)); | |
62 | |
63 EXPECT_EQ("399,0 1x400", | |
64 mouse_warp_controller()->first_edge_bounds_in_native_.ToString()); | |
65 EXPECT_EQ( | |
66 "0,450 1x600", | |
67 mouse_warp_controller()->second_edge_bounds_in_native_.ToString()); | |
68 } | |
69 | |
43 private: | 70 private: |
44 DISALLOW_COPY_AND_ASSIGN(UnifiedMouseWarpControllerTest); | 71 DISALLOW_COPY_AND_ASSIGN(UnifiedMouseWarpControllerTest); |
45 }; | 72 }; |
46 | 73 |
47 // Verifies if MouseCursorEventFilter's bounds calculation works correctly. | 74 // Verifies if MouseCursorEventFilter's bounds calculation works correctly. |
48 TEST_F(UnifiedMouseWarpControllerTest, BoundaryTest) { | 75 TEST_F(UnifiedMouseWarpControllerTest, BoundaryTest) { |
49 if (!SupportsMultipleDisplays()) | 76 if (!SupportsMultipleDisplays()) |
50 return; | 77 return; |
51 | 78 |
52 UpdateDisplay("400x400,0+450-700x400"); | 79 { |
53 aura::Window::Windows root_windows = Shell::GetAllRootWindows(); | 80 SCOPED_TRACE("1x1"); |
54 // Let the UnifiedMouseWarpController compute the bounds by | 81 BoundaryTestBody("400x400,0+450-700x400", "400x400,0+450-700x600"); |
55 // generating a mouse move event. | 82 } |
56 GetEventGenerator().MoveMouseTo(gfx::Point(0, 0)); | 83 { |
57 | 84 SCOPED_TRACE("2x1"); |
58 EXPECT_EQ("399,0 1x400", | 85 BoundaryTestBody("400x400*2,0+450-700x400", "400x400*2,0+450-700x600"); |
59 mouse_warp_controller()->first_edge_bounds_in_native_.ToString()); | 86 } |
60 EXPECT_EQ("0,450 1x400", | 87 { |
61 mouse_warp_controller()->second_edge_bounds_in_native_.ToString()); | 88 SCOPED_TRACE("1x2"); |
62 | 89 BoundaryTestBody("400x400,0+450-700x400*2", "400x400,0+450-700x600*2"); |
63 // Scaled. | 90 } |
64 UpdateDisplay("400x400,0+450-700x600"); | 91 { |
65 root_windows = Shell::GetAllRootWindows(); | 92 SCOPED_TRACE("2x2"); |
66 // Let the UnifiedMouseWarpController compute the bounds by | 93 BoundaryTestBody("400x400*2,0+450-700x400*2", "400x400*2,0+450-700x600*2"); |
67 // generating a mouse move event. | 94 } |
68 GetEventGenerator().MoveMouseTo(gfx::Point(1, 1)); | |
69 | |
70 EXPECT_EQ("399,0 1x400", | |
71 mouse_warp_controller()->first_edge_bounds_in_native_.ToString()); | |
72 EXPECT_EQ("0,450 1x600", | |
73 mouse_warp_controller()->second_edge_bounds_in_native_.ToString()); | |
74 | |
75 // Shell::GetInstace()->display_manager() | |
76 } | 95 } |
77 | 96 |
78 // Verifies if the mouse pointer correctly moves to another display in | 97 // Verifies if the mouse pointer correctly moves to another display in |
79 // unified desktop mode. | 98 // unified desktop mode. |
80 TEST_F(UnifiedMouseWarpControllerTest, WarpMouse) { | 99 TEST_F(UnifiedMouseWarpControllerTest, WarpMouse) { |
81 if (!SupportsMultipleDisplays()) | 100 if (!SupportsMultipleDisplays()) |
82 return; | 101 return; |
83 | 102 |
84 UpdateDisplay("500x500,500x500"); | 103 UpdateDisplay("500x500,500x500"); |
85 ASSERT_EQ(1, gfx::Screen::GetScreenFor(Shell::GetPrimaryRootWindow()) | 104 ASSERT_EQ(1, gfx::Screen::GetScreenFor(Shell::GetPrimaryRootWindow()) |
86 ->GetNumDisplays()); | 105 ->GetNumDisplays()); |
87 | 106 |
88 EXPECT_FALSE(TestIfMouseWarpsAt(gfx::Point(11, 11))); | 107 EXPECT_FALSE(TestIfMouseWarpsAt(gfx::Point(11, 11))); |
oshima
2015/07/29 20:20:52
TestIfMouseWarp currently doesn't work with dsf x.
| |
89 | 108 |
90 // Touch the right edge of the first display. Pointer should warp. | 109 // Touch the right edge of the first display. Pointer should warp. |
91 EXPECT_TRUE(TestIfMouseWarpsAt(gfx::Point(499, 11))); | 110 EXPECT_TRUE(TestIfMouseWarpsAt(gfx::Point(499, 11))); |
92 EXPECT_EQ("501,11", // by 2px. | 111 EXPECT_EQ("501,11", // by 2px. |
93 aura::Env::GetInstance()->last_mouse_location().ToString()); | 112 aura::Env::GetInstance()->last_mouse_location().ToString()); |
94 | 113 |
95 // Touch the left edge of the second display. Pointer should warp. | 114 // Touch the left edge of the second display. Pointer should warp. |
96 EXPECT_TRUE(TestIfMouseWarpsAt(gfx::Point(500, 11))); | 115 EXPECT_TRUE(TestIfMouseWarpsAt(gfx::Point(500, 11))); |
97 EXPECT_EQ("498,11", // by 2px. | 116 EXPECT_EQ("498,11", // by 2px. |
98 aura::Env::GetInstance()->last_mouse_location().ToString()); | 117 aura::Env::GetInstance()->last_mouse_location().ToString()); |
99 | 118 |
100 // Touch the left edge of the first display. | 119 // Touch the left edge of the first display. |
101 EXPECT_FALSE(TestIfMouseWarpsAt(gfx::Point(0, 11))); | 120 EXPECT_FALSE(TestIfMouseWarpsAt(gfx::Point(0, 11))); |
102 // Touch the top edge of the first display. | 121 // Touch the top edge of the first display. |
103 EXPECT_FALSE(TestIfMouseWarpsAt(gfx::Point(11, 0))); | 122 EXPECT_FALSE(TestIfMouseWarpsAt(gfx::Point(11, 0))); |
104 // Touch the bottom edge of the first display. | 123 // Touch the bottom edge of the first display. |
105 EXPECT_FALSE(TestIfMouseWarpsAt(gfx::Point(11, 499))); | 124 EXPECT_FALSE(TestIfMouseWarpsAt(gfx::Point(11, 499))); |
106 // Touch the right edge of the second display. | 125 // Touch the right edge of the second display. |
107 EXPECT_FALSE(TestIfMouseWarpsAt(gfx::Point(999, 11))); | 126 EXPECT_FALSE(TestIfMouseWarpsAt(gfx::Point(999, 11))); |
108 // Touch the top edge of the second display. | 127 // Touch the top edge of the second display. |
109 EXPECT_FALSE(TestIfMouseWarpsAt(gfx::Point(11, 0))); | 128 EXPECT_FALSE(TestIfMouseWarpsAt(gfx::Point(11, 0))); |
110 // Touch the bottom edge of the second display. | 129 // Touch the bottom edge of the second display. |
111 EXPECT_FALSE(TestIfMouseWarpsAt(gfx::Point(11, 499))); | 130 EXPECT_FALSE(TestIfMouseWarpsAt(gfx::Point(11, 499))); |
112 } | 131 } |
113 | 132 |
114 } // namespace aura | 133 } // namespace aura |
OLD | NEW |