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

Side by Side Diff: services/ui/ws/cursor_unittest.cc

Issue 2830703003: [views-mus] Support custom cursors. (Closed)
Patch Set: fix cast_shell_linux Created 3 years, 7 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
« no previous file with comments | « services/ui/public/interfaces/window_tree.mojom ('k') | services/ui/ws/display.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 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 <stdint.h> 5 #include <stdint.h>
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
11 #include "services/ui/common/types.h" 11 #include "services/ui/common/types.h"
12 #include "services/ui/common/util.h" 12 #include "services/ui/common/util.h"
13 #include "services/ui/public/interfaces/window_tree.mojom.h" 13 #include "services/ui/public/interfaces/window_tree.mojom.h"
14 #include "services/ui/ws/display_manager.h" 14 #include "services/ui/ws/display_manager.h"
15 #include "services/ui/ws/ids.h" 15 #include "services/ui/ws/ids.h"
16 #include "services/ui/ws/platform_display.h" 16 #include "services/ui/ws/platform_display.h"
17 #include "services/ui/ws/platform_display_factory.h" 17 #include "services/ui/ws/platform_display_factory.h"
18 #include "services/ui/ws/server_window.h" 18 #include "services/ui/ws/server_window.h"
19 #include "services/ui/ws/test_utils.h" 19 #include "services/ui/ws/test_utils.h"
20 #include "services/ui/ws/window_manager_display_root.h" 20 #include "services/ui/ws/window_manager_display_root.h"
21 #include "services/ui/ws/window_manager_state.h" 21 #include "services/ui/ws/window_manager_state.h"
22 #include "services/ui/ws/window_server.h" 22 #include "services/ui/ws/window_server.h"
23 #include "services/ui/ws/window_server_delegate.h" 23 #include "services/ui/ws/window_server_delegate.h"
24 #include "services/ui/ws/window_tree.h" 24 #include "services/ui/ws/window_tree.h"
25 #include "services/ui/ws/window_tree_binding.h" 25 #include "services/ui/ws/window_tree_binding.h"
26 #include "testing/gtest/include/gtest/gtest.h" 26 #include "testing/gtest/include/gtest/gtest.h"
27 #include "ui/base/cursor/cursor.h"
27 #include "ui/events/event.h" 28 #include "ui/events/event.h"
28 #include "ui/gfx/geometry/rect.h" 29 #include "ui/gfx/geometry/rect.h"
29 30
30 namespace ui { 31 namespace ui {
31 namespace ws { 32 namespace ws {
32 namespace test { 33 namespace test {
33 34
34 const UserId kTestId1 = "20"; 35 const UserId kTestId1 = "20";
35 36
36 class CursorTest : public testing::Test { 37 class CursorTest : public testing::Test {
37 public: 38 public:
38 CursorTest() {} 39 CursorTest() {}
39 ~CursorTest() override {} 40 ~CursorTest() override {}
40 41
41 WindowServer* window_server() { return ws_test_helper_.window_server(); } 42 WindowServer* window_server() { return ws_test_helper_.window_server(); }
42 TestWindowServerDelegate* window_server_delegate() { 43 TestWindowServerDelegate* window_server_delegate() {
43 return ws_test_helper_.window_server_delegate(); 44 return ws_test_helper_.window_server_delegate();
44 } 45 }
45 mojom::CursorType cursor() const { return ws_test_helper_.cursor(); } 46 ui::CursorType cursor_type() const {
47 return ws_test_helper_.cursor().cursor_type();
48 }
46 49
47 protected: 50 protected:
48 // testing::Test: 51 // testing::Test:
49 void SetUp() override { 52 void SetUp() override {
50 screen_manager_.Init(window_server()->display_manager()); 53 screen_manager_.Init(window_server()->display_manager());
51 screen_manager_.AddDisplay(); 54 screen_manager_.AddDisplay();
52 55
53 // As a side effect, this allocates Displays. 56 // As a side effect, this allocates Displays.
54 AddWindowManager(window_server(), kTestId1); 57 AddWindowManager(window_server(), kTestId1);
55 window_server()->user_id_tracker()->AddUserId(kTestId1); 58 window_server()->user_id_tracker()->AddUserId(kTestId1);
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 } 104 }
102 105
103 private: 106 private:
104 WindowServerTestHelper ws_test_helper_; 107 WindowServerTestHelper ws_test_helper_;
105 TestScreenManager screen_manager_; 108 TestScreenManager screen_manager_;
106 DISALLOW_COPY_AND_ASSIGN(CursorTest); 109 DISALLOW_COPY_AND_ASSIGN(CursorTest);
107 }; 110 };
108 111
109 TEST_F(CursorTest, ChangeByMouseMove) { 112 TEST_F(CursorTest, ChangeByMouseMove) {
110 ServerWindow* win = BuildServerWindow(); 113 ServerWindow* win = BuildServerWindow();
111 win->SetPredefinedCursor(mojom::CursorType::kIBeam); 114 win->SetCursor(ui::CursorData(ui::CursorType::kIBeam));
112 win->parent()->SetPredefinedCursor(mojom::CursorType::kCell); 115 win->parent()->SetCursor(ui::CursorData(ui::CursorType::kCell));
113 EXPECT_EQ(mojom::CursorType::kIBeam, win->cursor()); 116 EXPECT_EQ(ui::CursorType::kIBeam, win->cursor().cursor_type());
114 win->SetNonClientCursor(mojom::CursorType::kEastResize); 117 win->SetNonClientCursor(ui::CursorData(ui::CursorType::kEastResize));
115 EXPECT_EQ(mojom::CursorType::kEastResize, win->non_client_cursor()); 118 EXPECT_EQ(ui::CursorType::kEastResize,
119 win->non_client_cursor().cursor_type());
116 120
117 // Non client area 121 // Non client area
118 MoveCursorTo(gfx::Point(15, 15)); 122 MoveCursorTo(gfx::Point(15, 15));
119 EXPECT_EQ(mojom::CursorType::kEastResize, cursor()); 123 EXPECT_EQ(ui::CursorType::kEastResize, cursor_type());
120 124
121 // Client area, which comes from win->parent(). 125 // Client area, which comes from win->parent().
122 MoveCursorTo(gfx::Point(25, 25)); 126 MoveCursorTo(gfx::Point(25, 25));
123 EXPECT_EQ(mojom::CursorType::kCell, cursor()); 127 EXPECT_EQ(ui::CursorType::kCell, cursor_type());
124 } 128 }
125 129
126 TEST_F(CursorTest, ChangeByClientAreaChange) { 130 TEST_F(CursorTest, ChangeByClientAreaChange) {
127 ServerWindow* win = BuildServerWindow(); 131 ServerWindow* win = BuildServerWindow();
128 win->parent()->SetPredefinedCursor(mojom::CursorType::kCross); 132 win->parent()->SetCursor(ui::CursorData(ui::CursorType::kCross));
129 win->SetPredefinedCursor(mojom::CursorType::kIBeam); 133 win->SetCursor(ui::CursorData(ui::CursorType::kIBeam));
130 EXPECT_EQ(mojom::CursorType::kIBeam, mojom::CursorType(win->cursor())); 134 EXPECT_EQ(ui::CursorType::kIBeam, win->cursor().cursor_type());
131 win->SetNonClientCursor(mojom::CursorType::kEastResize); 135 win->SetNonClientCursor(ui::CursorData(ui::CursorType::kEastResize));
132 EXPECT_EQ(mojom::CursorType::kEastResize, win->non_client_cursor()); 136 EXPECT_EQ(ui::CursorType::kEastResize,
137 win->non_client_cursor().cursor_type());
133 138
134 // Non client area before we move. 139 // Non client area before we move.
135 MoveCursorTo(gfx::Point(15, 15)); 140 MoveCursorTo(gfx::Point(15, 15));
136 EXPECT_EQ(mojom::CursorType::kEastResize, cursor()); 141 EXPECT_EQ(ui::CursorType::kEastResize, cursor_type());
137 142
138 // Changing the client area should cause a change. The cursor for the client 143 // Changing the client area should cause a change. The cursor for the client
139 // area comes from root ancestor, which is win->parent(). 144 // area comes from root ancestor, which is win->parent().
140 win->SetClientArea(gfx::Insets(1, 1), std::vector<gfx::Rect>()); 145 win->SetClientArea(gfx::Insets(1, 1), std::vector<gfx::Rect>());
141 EXPECT_EQ(mojom::CursorType::kCross, cursor()); 146 EXPECT_EQ(ui::CursorType::kCross, cursor_type());
142 } 147 }
143 148
144 TEST_F(CursorTest, NonClientCursorChange) { 149 TEST_F(CursorTest, NonClientCursorChange) {
145 ServerWindow* win = BuildServerWindow(); 150 ServerWindow* win = BuildServerWindow();
146 win->SetPredefinedCursor(mojom::CursorType::kIBeam); 151 win->SetCursor(ui::CursorData(ui::CursorType::kIBeam));
147 EXPECT_EQ(mojom::CursorType::kIBeam, win->cursor()); 152 EXPECT_EQ(ui::CursorType::kIBeam, win->cursor().cursor_type());
148 win->SetNonClientCursor(mojom::CursorType::kEastResize); 153 win->SetNonClientCursor(ui::CursorData(ui::CursorType::kEastResize));
149 EXPECT_EQ(mojom::CursorType::kEastResize, win->non_client_cursor()); 154 EXPECT_EQ(ui::CursorType::kEastResize,
155 win->non_client_cursor().cursor_type());
150 156
151 MoveCursorTo(gfx::Point(15, 15)); 157 MoveCursorTo(gfx::Point(15, 15));
152 EXPECT_EQ(mojom::CursorType::kEastResize, cursor()); 158 EXPECT_EQ(ui::CursorType::kEastResize, cursor_type());
153 159
154 win->SetNonClientCursor(mojom::CursorType::kWestResize); 160 win->SetNonClientCursor(ui::CursorData(ui::CursorType::kWestResize));
155 EXPECT_EQ(mojom::CursorType::kWestResize, cursor()); 161 EXPECT_EQ(ui::CursorType::kWestResize, cursor_type());
156 } 162 }
157 163
158 TEST_F(CursorTest, IgnoreClientCursorChangeInNonClientArea) { 164 TEST_F(CursorTest, IgnoreClientCursorChangeInNonClientArea) {
159 ServerWindow* win = BuildServerWindow(); 165 ServerWindow* win = BuildServerWindow();
160 win->SetPredefinedCursor(mojom::CursorType::kIBeam); 166 win->SetCursor(ui::CursorData(ui::CursorType::kIBeam));
161 EXPECT_EQ(mojom::CursorType::kIBeam, win->cursor()); 167 EXPECT_EQ(ui::CursorType::kIBeam, win->cursor().cursor_type());
162 win->SetNonClientCursor(mojom::CursorType::kEastResize); 168 win->SetNonClientCursor(ui::CursorData(ui::CursorType::kEastResize));
163 EXPECT_EQ(mojom::CursorType::kEastResize, win->non_client_cursor()); 169 EXPECT_EQ(ui::CursorType::kEastResize,
170 win->non_client_cursor().cursor_type());
164 171
165 MoveCursorTo(gfx::Point(15, 15)); 172 MoveCursorTo(gfx::Point(15, 15));
166 EXPECT_EQ(mojom::CursorType::kEastResize, cursor()); 173 EXPECT_EQ(ui::CursorType::kEastResize, cursor_type());
167 174
168 win->SetPredefinedCursor(mojom::CursorType::kHelp); 175 win->SetCursor(ui::CursorData(ui::CursorType::kHelp));
169 EXPECT_EQ(mojom::CursorType::kEastResize, cursor()); 176 EXPECT_EQ(ui::CursorType::kEastResize, cursor_type());
170 } 177 }
171 178
172 TEST_F(CursorTest, NonClientToClientByBoundsChange) { 179 TEST_F(CursorTest, NonClientToClientByBoundsChange) {
173 ServerWindow* win = BuildServerWindow(); 180 ServerWindow* win = BuildServerWindow();
174 win->parent()->SetPredefinedCursor(mojom::CursorType::kCopy); 181 win->parent()->SetCursor(ui::CursorData(ui::CursorType::kCopy));
175 win->SetPredefinedCursor(mojom::CursorType::kIBeam); 182 win->SetCursor(ui::CursorData(ui::CursorType::kIBeam));
176 EXPECT_EQ(mojom::CursorType::kIBeam, win->cursor()); 183 EXPECT_EQ(ui::CursorType::kIBeam, win->cursor().cursor_type());
177 win->SetNonClientCursor(mojom::CursorType::kEastResize); 184 win->SetNonClientCursor(ui::CursorData(ui::CursorType::kEastResize));
178 EXPECT_EQ(mojom::CursorType::kEastResize, win->non_client_cursor()); 185 EXPECT_EQ(ui::CursorType::kEastResize,
186 win->non_client_cursor().cursor_type());
179 187
180 // Non client area before we move. 188 // Non client area before we move.
181 MoveCursorTo(gfx::Point(15, 15)); 189 MoveCursorTo(gfx::Point(15, 15));
182 EXPECT_EQ(mojom::CursorType::kEastResize, cursor()); 190 EXPECT_EQ(ui::CursorType::kEastResize, cursor_type());
183 191
184 win->SetBounds(gfx::Rect(0, 0, 30, 30)); 192 win->SetBounds(gfx::Rect(0, 0, 30, 30));
185 EXPECT_EQ(mojom::CursorType::kCopy, cursor()); 193 EXPECT_EQ(ui::CursorType::kCopy, cursor_type());
186 } 194 }
187 195
188 } // namespace test 196 } // namespace test
189 } // namespace ws 197 } // namespace ws
190 } // namespace ui 198 } // namespace ui
OLDNEW
« no previous file with comments | « services/ui/public/interfaces/window_tree.mojom ('k') | services/ui/ws/display.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698