OLD | NEW |
| (Empty) |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include <stdint.h> | |
6 | |
7 #include <string> | |
8 | |
9 #include "base/macros.h" | |
10 #include "base/message_loop/message_loop.h" | |
11 #include "components/mus/common/types.h" | |
12 #include "components/mus/common/util.h" | |
13 #include "components/mus/public/interfaces/window_tree.mojom.h" | |
14 #include "components/mus/surfaces/surfaces_state.h" | |
15 #include "components/mus/ws/display_manager.h" | |
16 #include "components/mus/ws/ids.h" | |
17 #include "components/mus/ws/platform_display.h" | |
18 #include "components/mus/ws/platform_display_factory.h" | |
19 #include "components/mus/ws/server_window.h" | |
20 #include "components/mus/ws/server_window_surface_manager_test_api.h" | |
21 #include "components/mus/ws/test_utils.h" | |
22 #include "components/mus/ws/window_manager_display_root.h" | |
23 #include "components/mus/ws/window_manager_state.h" | |
24 #include "components/mus/ws/window_server.h" | |
25 #include "components/mus/ws/window_server_delegate.h" | |
26 #include "components/mus/ws/window_tree.h" | |
27 #include "components/mus/ws/window_tree_binding.h" | |
28 #include "testing/gtest/include/gtest/gtest.h" | |
29 #include "ui/events/event.h" | |
30 #include "ui/gfx/geometry/rect.h" | |
31 | |
32 namespace mus { | |
33 namespace ws { | |
34 namespace test { | |
35 | |
36 const UserId kTestId1 = "20"; | |
37 | |
38 class CursorTest : public testing::Test { | |
39 public: | |
40 CursorTest() : cursor_id_(-1), platform_display_factory_(&cursor_id_) {} | |
41 ~CursorTest() override {} | |
42 | |
43 protected: | |
44 // testing::Test: | |
45 void SetUp() override { | |
46 PlatformDisplay::set_factory_for_testing(&platform_display_factory_); | |
47 window_server_.reset( | |
48 new WindowServer(&window_server_delegate_, | |
49 scoped_refptr<SurfacesState>(new SurfacesState))); | |
50 window_server_delegate_.set_window_server(window_server_.get()); | |
51 | |
52 window_server_delegate_.set_num_displays_to_create(1); | |
53 | |
54 // As a side effect, this allocates Displays. | |
55 WindowManagerWindowTreeFactorySetTestApi( | |
56 window_server_->window_manager_window_tree_factory_set()) | |
57 .Add(kTestId1); | |
58 window_server_->user_id_tracker()->AddUserId(kTestId1); | |
59 window_server_->user_id_tracker()->SetActiveUserId(kTestId1); | |
60 } | |
61 | |
62 ServerWindow* GetRoot() { | |
63 DisplayManager* display_manager = window_server_->display_manager(); | |
64 // ASSERT_EQ(1u, display_manager->displays().size()); | |
65 Display* display = *display_manager->displays().begin(); | |
66 return display->GetWindowManagerDisplayRootForUser(kTestId1)->root(); | |
67 } | |
68 | |
69 // Create a 30x30 window where the outer 10 pixels is non-client. | |
70 ServerWindow* BuildServerWindow() { | |
71 DisplayManager* display_manager = window_server_->display_manager(); | |
72 Display* display = *display_manager->displays().begin(); | |
73 WindowManagerDisplayRoot* active_display_root = | |
74 display->GetActiveWindowManagerDisplayRoot(); | |
75 WindowTree* tree = | |
76 active_display_root->window_manager_state()->window_tree(); | |
77 ClientWindowId child_window_id; | |
78 if (!NewWindowInTree(tree, &child_window_id)) | |
79 return nullptr; | |
80 | |
81 ServerWindow* w = tree->GetWindowByClientId(child_window_id); | |
82 w->SetBounds(gfx::Rect(10, 10, 30, 30)); | |
83 w->SetClientArea(gfx::Insets(10, 10), std::vector<gfx::Rect>()); | |
84 w->SetVisible(true); | |
85 | |
86 ServerWindowSurfaceManagerTestApi test_api(w->GetOrCreateSurfaceManager()); | |
87 test_api.CreateEmptyDefaultSurface(); | |
88 | |
89 return w; | |
90 } | |
91 | |
92 void MoveCursorTo(const gfx::Point& p) { | |
93 DisplayManager* display_manager = window_server_->display_manager(); | |
94 ASSERT_EQ(1u, display_manager->displays().size()); | |
95 Display* display = *display_manager->displays().begin(); | |
96 WindowManagerDisplayRoot* active_display_root = | |
97 display->GetActiveWindowManagerDisplayRoot(); | |
98 ASSERT_TRUE(active_display_root); | |
99 static_cast<PlatformDisplayDelegate*>(display)->OnEvent(ui::PointerEvent( | |
100 ui::MouseEvent(ui::ET_MOUSE_MOVED, p, p, base::TimeTicks(), 0, 0))); | |
101 WindowManagerState* wms = active_display_root->window_manager_state(); | |
102 wms->OnEventAck(wms->window_tree(), mojom::EventResult::HANDLED); | |
103 } | |
104 | |
105 protected: | |
106 int32_t cursor_id_; | |
107 TestPlatformDisplayFactory platform_display_factory_; | |
108 TestWindowServerDelegate window_server_delegate_; | |
109 std::unique_ptr<WindowServer> window_server_; | |
110 base::MessageLoop message_loop_; | |
111 | |
112 private: | |
113 DISALLOW_COPY_AND_ASSIGN(CursorTest); | |
114 }; | |
115 | |
116 TEST_F(CursorTest, ChangeByMouseMove) { | |
117 ServerWindow* win = BuildServerWindow(); | |
118 win->SetPredefinedCursor(mojom::Cursor::IBEAM); | |
119 EXPECT_EQ(mojom::Cursor::IBEAM, mojom::Cursor(win->cursor())); | |
120 win->SetNonClientCursor(mojom::Cursor::EAST_RESIZE); | |
121 EXPECT_EQ(mojom::Cursor::EAST_RESIZE, | |
122 mojom::Cursor(win->non_client_cursor())); | |
123 | |
124 // Non client area | |
125 MoveCursorTo(gfx::Point(15, 15)); | |
126 EXPECT_EQ(mojom::Cursor::EAST_RESIZE, mojom::Cursor(cursor_id_)); | |
127 | |
128 // Client area | |
129 MoveCursorTo(gfx::Point(25, 25)); | |
130 EXPECT_EQ(mojom::Cursor::IBEAM, mojom::Cursor(cursor_id_)); | |
131 } | |
132 | |
133 TEST_F(CursorTest, ChangeByClientAreaChange) { | |
134 ServerWindow* win = BuildServerWindow(); | |
135 win->SetPredefinedCursor(mojom::Cursor::IBEAM); | |
136 EXPECT_EQ(mojom::Cursor::IBEAM, mojom::Cursor(win->cursor())); | |
137 win->SetNonClientCursor(mojom::Cursor::EAST_RESIZE); | |
138 EXPECT_EQ(mojom::Cursor::EAST_RESIZE, | |
139 mojom::Cursor(win->non_client_cursor())); | |
140 | |
141 // Non client area before we move. | |
142 MoveCursorTo(gfx::Point(15, 15)); | |
143 EXPECT_EQ(mojom::Cursor::EAST_RESIZE, mojom::Cursor(cursor_id_)); | |
144 | |
145 // Changing the client area should cause a change. | |
146 win->SetClientArea(gfx::Insets(1, 1), std::vector<gfx::Rect>()); | |
147 EXPECT_EQ(mojom::Cursor::IBEAM, mojom::Cursor(cursor_id_)); | |
148 } | |
149 | |
150 TEST_F(CursorTest, NonClientCursorChange) { | |
151 ServerWindow* win = BuildServerWindow(); | |
152 win->SetPredefinedCursor(mojom::Cursor::IBEAM); | |
153 EXPECT_EQ(mojom::Cursor::IBEAM, mojom::Cursor(win->cursor())); | |
154 win->SetNonClientCursor(mojom::Cursor::EAST_RESIZE); | |
155 EXPECT_EQ(mojom::Cursor::EAST_RESIZE, | |
156 mojom::Cursor(win->non_client_cursor())); | |
157 | |
158 MoveCursorTo(gfx::Point(15, 15)); | |
159 EXPECT_EQ(mojom::Cursor::EAST_RESIZE, mojom::Cursor(cursor_id_)); | |
160 | |
161 win->SetNonClientCursor(mojom::Cursor::WEST_RESIZE); | |
162 EXPECT_EQ(mojom::Cursor::WEST_RESIZE, mojom::Cursor(cursor_id_)); | |
163 } | |
164 | |
165 TEST_F(CursorTest, IgnoreClientCursorChangeInNonClientArea) { | |
166 ServerWindow* win = BuildServerWindow(); | |
167 win->SetPredefinedCursor(mojom::Cursor::IBEAM); | |
168 EXPECT_EQ(mojom::Cursor::IBEAM, mojom::Cursor(win->cursor())); | |
169 win->SetNonClientCursor(mojom::Cursor::EAST_RESIZE); | |
170 EXPECT_EQ(mojom::Cursor::EAST_RESIZE, | |
171 mojom::Cursor(win->non_client_cursor())); | |
172 | |
173 MoveCursorTo(gfx::Point(15, 15)); | |
174 EXPECT_EQ(mojom::Cursor::EAST_RESIZE, mojom::Cursor(cursor_id_)); | |
175 | |
176 win->SetPredefinedCursor(mojom::Cursor::HELP); | |
177 EXPECT_EQ(mojom::Cursor::EAST_RESIZE, mojom::Cursor(cursor_id_)); | |
178 } | |
179 | |
180 TEST_F(CursorTest, NonClientToClientByBoundsChange) { | |
181 ServerWindow* win = BuildServerWindow(); | |
182 win->SetPredefinedCursor(mojom::Cursor::IBEAM); | |
183 EXPECT_EQ(mojom::Cursor::IBEAM, mojom::Cursor(win->cursor())); | |
184 win->SetNonClientCursor(mojom::Cursor::EAST_RESIZE); | |
185 EXPECT_EQ(mojom::Cursor::EAST_RESIZE, | |
186 mojom::Cursor(win->non_client_cursor())); | |
187 | |
188 // Non client area before we move. | |
189 MoveCursorTo(gfx::Point(15, 15)); | |
190 EXPECT_EQ(mojom::Cursor::EAST_RESIZE, mojom::Cursor(cursor_id_)); | |
191 | |
192 win->SetBounds(gfx::Rect(0, 0, 30, 30)); | |
193 EXPECT_EQ(mojom::Cursor::IBEAM, mojom::Cursor(cursor_id_)); | |
194 } | |
195 | |
196 } // namespace test | |
197 } // namespace ws | |
198 } // namespace mus | |
OLD | NEW |