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

Side by Side Diff: ui/wm/core/cursor_manager_unittest.cc

Issue 2071553002: Initial support of large mouse cursor on Exosphere (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: for comment #13 Created 4 years, 6 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
« ui/wm/core/cursor_manager.cc ('K') | « ui/wm/core/cursor_manager.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 "ui/wm/core/cursor_manager.h" 5 #include "ui/wm/core/cursor_manager.h"
6 6
7 #include "base/macros.h" 7 #include "base/macros.h"
8 #include "base/memory/ptr_util.h" 8 #include "base/memory/ptr_util.h"
9 #include "ui/aura/client/cursor_client_observer.h" 9 #include "ui/aura/client/cursor_client_observer.h"
10 #include "ui/aura/test/aura_test_base.h" 10 #include "ui/aura/test/aura_test_base.h"
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 class CursorManagerTest : public aura::test::AuraTestBase { 45 class CursorManagerTest : public aura::test::AuraTestBase {
46 protected: 46 protected:
47 CursorManagerTest() 47 CursorManagerTest()
48 : delegate_(new TestingCursorManager), 48 : delegate_(new TestingCursorManager),
49 cursor_manager_(base::WrapUnique(delegate_)) {} 49 cursor_manager_(base::WrapUnique(delegate_)) {}
50 50
51 TestingCursorManager* delegate_; 51 TestingCursorManager* delegate_;
52 wm::CursorManager cursor_manager_; 52 wm::CursorManager cursor_manager_;
53 }; 53 };
54 54
55 class TestingCursorClientObserver : public aura::client::CursorClientObserver { 55 class TestingCursorClientObserver : public aura::client::CursorClientObserver {
sky 2016/06/20 15:27:51 How about moving this into testing_cursor_client_o
yoshiki 2016/06/28 02:12:42 Done.
56 public: 56 public:
57 TestingCursorClientObserver() 57 TestingCursorClientObserver()
58 : cursor_visibility_(false), 58 : cursor_visibility_(false),
59 did_visibility_change_(false) {} 59 did_visibility_change_(false),
60 void reset() { cursor_visibility_ = did_visibility_change_ = false; } 60 cursor_set_(ui::CURSOR_SET_NORMAL),
61 did_cursor_set_change_(false) {}
62 void reset() {
63 cursor_visibility_ = did_visibility_change_ = false;
64 did_cursor_set_change_ = false;
sky 2016/06/20 15:27:51 Shouldn't you reset cursor_set_ here too?
yoshiki 2016/06/28 02:12:42 Done.
65 }
61 bool is_cursor_visible() const { return cursor_visibility_; } 66 bool is_cursor_visible() const { return cursor_visibility_; }
62 bool did_visibility_change() const { return did_visibility_change_; } 67 bool did_visibility_change() const { return did_visibility_change_; }
68 ui::CursorSetType cursor_set() const { return cursor_set_; }
69 bool did_cursor_set_change() const { return did_cursor_set_change_; }
63 70
64 // Overridden from aura::client::CursorClientObserver: 71 // Overridden from aura::client::CursorClientObserver:
65 void OnCursorVisibilityChanged(bool is_visible) override { 72 void OnCursorVisibilityChanged(bool is_visible) override {
66 cursor_visibility_ = is_visible; 73 cursor_visibility_ = is_visible;
67 did_visibility_change_ = true; 74 did_visibility_change_ = true;
68 } 75 }
76 void OnCursorSetChanged(ui::CursorSetType cursor_set) override {
77 cursor_set_ = cursor_set;
78 did_cursor_set_change_ = true;
79 }
69 80
70 private: 81 private:
71 bool cursor_visibility_; 82 bool cursor_visibility_;
72 bool did_visibility_change_; 83 bool did_visibility_change_;
84 ui::CursorSetType cursor_set_;
85 bool did_cursor_set_change_;
73 86
74 DISALLOW_COPY_AND_ASSIGN(TestingCursorClientObserver); 87 DISALLOW_COPY_AND_ASSIGN(TestingCursorClientObserver);
75 }; 88 };
76 89
77 TEST_F(CursorManagerTest, ShowHideCursor) { 90 TEST_F(CursorManagerTest, ShowHideCursor) {
78 cursor_manager_.SetCursor(ui::kCursorCopy); 91 cursor_manager_.SetCursor(ui::kCursorCopy);
79 EXPECT_EQ(ui::kCursorCopy, cursor_manager_.GetCursor().native_type()); 92 EXPECT_EQ(ui::kCursorCopy, cursor_manager_.GetCursor().native_type());
80 93
81 cursor_manager_.ShowCursor(); 94 cursor_manager_.ShowCursor();
82 EXPECT_TRUE(cursor_manager_.IsCursorVisible()); 95 EXPECT_TRUE(cursor_manager_.IsCursorVisible());
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 cursor_manager_.UnlockCursor(); 181 cursor_manager_.UnlockCursor();
169 EXPECT_TRUE(cursor_manager_.IsMouseEventsEnabled()); 182 EXPECT_TRUE(cursor_manager_.IsMouseEventsEnabled());
170 183
171 cursor_manager_.DisableMouseEvents(); 184 cursor_manager_.DisableMouseEvents();
172 cursor_manager_.LockCursor(); 185 cursor_manager_.LockCursor();
173 cursor_manager_.UnlockCursor(); 186 cursor_manager_.UnlockCursor();
174 EXPECT_FALSE(cursor_manager_.IsMouseEventsEnabled()); 187 EXPECT_FALSE(cursor_manager_.IsMouseEventsEnabled());
175 } 188 }
176 189
177 TEST_F(CursorManagerTest, SetCursorSet) { 190 TEST_F(CursorManagerTest, SetCursorSet) {
191 TestingCursorClientObserver observer;
192 cursor_manager_.AddObserver(&observer);
193
178 EXPECT_EQ(ui::CURSOR_SET_NORMAL, cursor_manager_.GetCursorSet()); 194 EXPECT_EQ(ui::CURSOR_SET_NORMAL, cursor_manager_.GetCursorSet());
195 EXPECT_EQ(ui::CURSOR_SET_NORMAL, observer.cursor_set());
179 196
180 cursor_manager_.SetCursorSet(ui::CURSOR_SET_NORMAL); 197 cursor_manager_.SetCursorSet(ui::CURSOR_SET_NORMAL);
181 EXPECT_EQ(ui::CURSOR_SET_NORMAL, cursor_manager_.GetCursorSet()); 198 EXPECT_EQ(ui::CURSOR_SET_NORMAL, cursor_manager_.GetCursorSet());
199 EXPECT_EQ(ui::CURSOR_SET_NORMAL, observer.cursor_set());
182 200
183 cursor_manager_.SetCursorSet(ui::CURSOR_SET_LARGE); 201 cursor_manager_.SetCursorSet(ui::CURSOR_SET_LARGE);
184 EXPECT_EQ(ui::CURSOR_SET_LARGE, cursor_manager_.GetCursorSet()); 202 EXPECT_EQ(ui::CURSOR_SET_LARGE, cursor_manager_.GetCursorSet());
203 EXPECT_EQ(ui::CURSOR_SET_LARGE, observer.cursor_set());
185 204
186 cursor_manager_.SetCursorSet(ui::CURSOR_SET_NORMAL); 205 cursor_manager_.SetCursorSet(ui::CURSOR_SET_NORMAL);
187 EXPECT_EQ(ui::CURSOR_SET_NORMAL, cursor_manager_.GetCursorSet()); 206 EXPECT_EQ(ui::CURSOR_SET_NORMAL, cursor_manager_.GetCursorSet());
207 EXPECT_EQ(ui::CURSOR_SET_NORMAL, observer.cursor_set());
188 } 208 }
189 209
190 TEST_F(CursorManagerTest, IsMouseEventsEnabled) { 210 TEST_F(CursorManagerTest, IsMouseEventsEnabled) {
191 cursor_manager_.EnableMouseEvents(); 211 cursor_manager_.EnableMouseEvents();
192 EXPECT_TRUE(cursor_manager_.IsMouseEventsEnabled()); 212 EXPECT_TRUE(cursor_manager_.IsMouseEventsEnabled());
193 cursor_manager_.DisableMouseEvents(); 213 cursor_manager_.DisableMouseEvents();
194 EXPECT_FALSE(cursor_manager_.IsMouseEventsEnabled()); 214 EXPECT_FALSE(cursor_manager_.IsMouseEventsEnabled());
195 } 215 }
196 216
197 // Verifies that the mouse events enable state changes correctly when 217 // Verifies that the mouse events enable state changes correctly when
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 cursor_manager_.AddObserver(&observer_a); 300 cursor_manager_.AddObserver(&observer_a);
281 cursor_manager_.AddObserver(&observer_b); 301 cursor_manager_.AddObserver(&observer_b);
282 302
283 // Initial state before any events have been sent. 303 // Initial state before any events have been sent.
284 observer_a.reset(); 304 observer_a.reset();
285 observer_b.reset(); 305 observer_b.reset();
286 EXPECT_FALSE(observer_a.did_visibility_change()); 306 EXPECT_FALSE(observer_a.did_visibility_change());
287 EXPECT_FALSE(observer_b.did_visibility_change()); 307 EXPECT_FALSE(observer_b.did_visibility_change());
288 EXPECT_FALSE(observer_a.is_cursor_visible()); 308 EXPECT_FALSE(observer_a.is_cursor_visible());
289 EXPECT_FALSE(observer_b.is_cursor_visible()); 309 EXPECT_FALSE(observer_b.is_cursor_visible());
310 EXPECT_FALSE(observer_a.did_cursor_set_change());
311 EXPECT_FALSE(observer_b.did_cursor_set_change());
312 EXPECT_EQ(ui::CURSOR_SET_NORMAL, observer_a.cursor_set());
313 EXPECT_EQ(ui::CURSOR_SET_NORMAL, observer_b.cursor_set());
290 314
291 // Hide the cursor using HideCursor(). 315 // Hide the cursor using HideCursor().
292 cursor_manager_.HideCursor(); 316 cursor_manager_.HideCursor();
293 EXPECT_TRUE(observer_a.did_visibility_change()); 317 EXPECT_TRUE(observer_a.did_visibility_change());
294 EXPECT_TRUE(observer_b.did_visibility_change()); 318 EXPECT_TRUE(observer_b.did_visibility_change());
295 EXPECT_FALSE(observer_a.is_cursor_visible()); 319 EXPECT_FALSE(observer_a.is_cursor_visible());
296 EXPECT_FALSE(observer_b.is_cursor_visible()); 320 EXPECT_FALSE(observer_b.is_cursor_visible());
297 321
322 // Set the cursor set.
323 cursor_manager_.SetCursorSet(ui::CURSOR_SET_LARGE);
324 EXPECT_TRUE(observer_a.did_cursor_set_change());
325 EXPECT_TRUE(observer_b.did_cursor_set_change());
326 EXPECT_EQ(ui::CURSOR_SET_LARGE, observer_a.cursor_set());
327 EXPECT_EQ(ui::CURSOR_SET_LARGE, observer_b.cursor_set());
328
298 // Show the cursor using ShowCursor(). 329 // Show the cursor using ShowCursor().
299 observer_a.reset(); 330 observer_a.reset();
300 observer_b.reset(); 331 observer_b.reset();
301 cursor_manager_.ShowCursor(); 332 cursor_manager_.ShowCursor();
302 EXPECT_TRUE(observer_a.did_visibility_change()); 333 EXPECT_TRUE(observer_a.did_visibility_change());
303 EXPECT_TRUE(observer_b.did_visibility_change()); 334 EXPECT_TRUE(observer_b.did_visibility_change());
304 EXPECT_TRUE(observer_a.is_cursor_visible()); 335 EXPECT_TRUE(observer_a.is_cursor_visible());
305 EXPECT_TRUE(observer_b.is_cursor_visible()); 336 EXPECT_TRUE(observer_b.is_cursor_visible());
306 337
307 // Remove observer_b. Its OnCursorVisibilityChanged() should 338 // Remove observer_b. Its OnCursorVisibilityChanged() should
308 // not be invoked past this point. 339 // not be invoked past this point.
309 cursor_manager_.RemoveObserver(&observer_b); 340 cursor_manager_.RemoveObserver(&observer_b);
310 341
311 // Hide the cursor using HideCursor(). 342 // Hide the cursor using HideCursor().
312 observer_a.reset(); 343 observer_a.reset();
313 observer_b.reset(); 344 observer_b.reset();
314 cursor_manager_.HideCursor(); 345 cursor_manager_.HideCursor();
315 EXPECT_TRUE(observer_a.did_visibility_change()); 346 EXPECT_TRUE(observer_a.did_visibility_change());
316 EXPECT_FALSE(observer_b.did_visibility_change()); 347 EXPECT_FALSE(observer_b.did_visibility_change());
317 EXPECT_FALSE(observer_a.is_cursor_visible()); 348 EXPECT_FALSE(observer_a.is_cursor_visible());
318 349
350 // Set back the cursor set to normal.
351 cursor_manager_.SetCursorSet(ui::CURSOR_SET_NORMAL);
352 EXPECT_TRUE(observer_a.did_cursor_set_change());
353 EXPECT_FALSE(observer_b.did_cursor_set_change());
354 EXPECT_EQ(ui::CURSOR_SET_NORMAL, observer_a.cursor_set());
355 EXPECT_EQ(ui::CURSOR_SET_LARGE, observer_b.cursor_set());
356
319 // Show the cursor using ShowCursor(). 357 // Show the cursor using ShowCursor().
320 observer_a.reset(); 358 observer_a.reset();
321 observer_b.reset(); 359 observer_b.reset();
322 cursor_manager_.ShowCursor(); 360 cursor_manager_.ShowCursor();
323 EXPECT_TRUE(observer_a.did_visibility_change()); 361 EXPECT_TRUE(observer_a.did_visibility_change());
324 EXPECT_FALSE(observer_b.did_visibility_change()); 362 EXPECT_FALSE(observer_b.did_visibility_change());
325 EXPECT_TRUE(observer_a.is_cursor_visible()); 363 EXPECT_TRUE(observer_a.is_cursor_visible());
326 } 364 }
327 365
328 // This test validates that the cursor visiblity state is restored when a 366 // This test validates that the cursor visiblity state is restored when a
(...skipping 23 matching lines...) Expand all
352 // This block validates that the cursor is visible initially. It then 390 // This block validates that the cursor is visible initially. It then
353 // performs normal cursor visibility operations. 391 // performs normal cursor visibility operations.
354 { 392 {
355 wm::CursorManager cursor_manager3( 393 wm::CursorManager cursor_manager3(
356 base::WrapUnique(new TestingCursorManager)); 394 base::WrapUnique(new TestingCursorManager));
357 EXPECT_TRUE(cursor_manager3.IsCursorVisible()); 395 EXPECT_TRUE(cursor_manager3.IsCursorVisible());
358 cursor_manager3.HideCursor(); 396 cursor_manager3.HideCursor();
359 EXPECT_FALSE(cursor_manager3.IsCursorVisible()); 397 EXPECT_FALSE(cursor_manager3.IsCursorVisible());
360 } 398 }
361 } 399 }
OLDNEW
« ui/wm/core/cursor_manager.cc ('K') | « ui/wm/core/cursor_manager.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698