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

Side by Side Diff: ui/views/corewm/cursor_manager_unittest.cc

Issue 92413002: Cursor state should be global for all CursorManagers (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: comments addressed Created 7 years 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 | Annotate | Revision Log
« no previous file with comments | « ui/views/corewm/cursor_manager.cc ('k') | ui/views/corewm/native_cursor_manager_delegate.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 (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/views/corewm/cursor_manager.h" 5 #include "ui/views/corewm/cursor_manager.h"
6 6
7 #include "ui/aura/client/cursor_client_observer.h" 7 #include "ui/aura/client/cursor_client_observer.h"
8 #include "ui/views/corewm/native_cursor_manager.h" 8 #include "ui/views/corewm/native_cursor_manager.h"
9 #include "ui/views/test/views_test_base.h" 9 #include "ui/views/test/views_test_base.h"
10 10
11 namespace { 11 namespace {
12 12
13 class TestingCursorManager : public views::corewm::NativeCursorManager { 13 class TestingCursorManager : public views::corewm::NativeCursorManager {
14 public: 14 public:
15 gfx::NativeCursor current_cursor() { return cursor_; }
16
17 // Overridden from views::corewm::NativeCursorManager: 15 // Overridden from views::corewm::NativeCursorManager:
18 virtual void SetDisplay( 16 virtual void SetDisplay(
19 const gfx::Display& display, 17 const gfx::Display& display,
20 views::corewm::NativeCursorManagerDelegate* delegate) OVERRIDE {} 18 views::corewm::NativeCursorManagerDelegate* delegate) OVERRIDE {}
21 19
22 virtual void SetCursor( 20 virtual void SetCursor(
23 gfx::NativeCursor cursor, 21 gfx::NativeCursor cursor,
24 views::corewm::NativeCursorManagerDelegate* delegate) OVERRIDE { 22 views::corewm::NativeCursorManagerDelegate* delegate) OVERRIDE {
25 cursor_ = cursor;
26 delegate->CommitCursor(cursor); 23 delegate->CommitCursor(cursor);
27 } 24 }
28 25
29 virtual void SetVisibility( 26 virtual void SetVisibility(
30 bool visible, 27 bool visible,
31 views::corewm::NativeCursorManagerDelegate* delegate) OVERRIDE { 28 views::corewm::NativeCursorManagerDelegate* delegate) OVERRIDE {
32 delegate->CommitVisibility(visible); 29 delegate->CommitVisibility(visible);
33 } 30 }
34 31
35 virtual void SetMouseEventsEnabled( 32 virtual void SetMouseEventsEnabled(
36 bool enabled, 33 bool enabled,
37 views::corewm::NativeCursorManagerDelegate* delegate) OVERRIDE { 34 views::corewm::NativeCursorManagerDelegate* delegate) OVERRIDE {
38 delegate->CommitMouseEventsEnabled(enabled); 35 delegate->CommitMouseEventsEnabled(enabled);
39 } 36 }
40 37
41 virtual void SetCursorSet( 38 virtual void SetCursorSet(
42 ui::CursorSetType cursor_set, 39 ui::CursorSetType cursor_set,
43 views::corewm::NativeCursorManagerDelegate* delegate) OVERRIDE { 40 views::corewm::NativeCursorManagerDelegate* delegate) OVERRIDE {
44 delegate->CommitCursorSet(cursor_set); 41 delegate->CommitCursorSet(cursor_set);
45 } 42 }
46 43
47 virtual void SetScale( 44 virtual void SetScale(
48 float scale, 45 float scale,
49 views::corewm::NativeCursorManagerDelegate* delegate) OVERRIDE { 46 views::corewm::NativeCursorManagerDelegate* delegate) OVERRIDE {
50 delegate->CommitScale(scale); 47 delegate->CommitScale(scale);
51 } 48 }
52
53 private:
54 gfx::NativeCursor cursor_;
55 }; 49 };
56 50
57 } // namespace 51 } // namespace
58 52
59 class CursorManagerTest : public views::ViewsTestBase { 53 class CursorManagerTest : public views::ViewsTestBase {
60 protected: 54 protected:
61 CursorManagerTest() 55 CursorManagerTest()
62 : delegate_(new TestingCursorManager), 56 : delegate_(new TestingCursorManager),
57 delegate_second_(new TestingCursorManager),
63 cursor_manager_(scoped_ptr<views::corewm::NativeCursorManager>( 58 cursor_manager_(scoped_ptr<views::corewm::NativeCursorManager>(
64 delegate_)) { 59 delegate_)),
60 cursor_manager_second_(scoped_ptr<views::corewm::NativeCursorManager>(
61 delegate_second_)) {
65 } 62 }
66 63
67 gfx::NativeCursor current_cursor() { return delegate_->current_cursor(); }
68
69 TestingCursorManager* delegate_; 64 TestingCursorManager* delegate_;
65 TestingCursorManager* delegate_second_;
70 views::corewm::CursorManager cursor_manager_; 66 views::corewm::CursorManager cursor_manager_;
67 views::corewm::CursorManager cursor_manager_second_;
71 }; 68 };
72 69
73 class TestingCursorClientObserver : public aura::client::CursorClientObserver { 70 class TestingCursorClientObserver : public aura::client::CursorClientObserver {
74 public: 71 public:
75 TestingCursorClientObserver() 72 TestingCursorClientObserver()
76 : cursor_visibility_(false), 73 : cursor_visibility_(false),
77 did_visibility_change_(false) {} 74 did_visibility_change_(false) {}
78 void reset() { cursor_visibility_ = did_visibility_change_ = false; } 75 void reset() { cursor_visibility_ = did_visibility_change_ = false; }
79 bool is_cursor_visible() const { return cursor_visibility_; } 76 bool is_cursor_visible() const { return cursor_visibility_; }
80 bool did_visibility_change() const { return did_visibility_change_; } 77 bool did_visibility_change() const { return did_visibility_change_; }
81 78
82 // Overridden from aura::client::CursorClientObserver: 79 // Overridden from aura::client::CursorClientObserver:
83 virtual void OnCursorVisibilityChanged(bool is_visible) OVERRIDE { 80 virtual void OnCursorVisibilityChanged(bool is_visible) OVERRIDE {
84 cursor_visibility_ = is_visible; 81 cursor_visibility_ = is_visible;
85 did_visibility_change_ = true; 82 did_visibility_change_ = true;
86 } 83 }
87 84
88 private: 85 private:
89 bool cursor_visibility_; 86 bool cursor_visibility_;
90 bool did_visibility_change_; 87 bool did_visibility_change_;
91 88
92 DISALLOW_COPY_AND_ASSIGN(TestingCursorClientObserver); 89 DISALLOW_COPY_AND_ASSIGN(TestingCursorClientObserver);
93 }; 90 };
94 91
95 TEST_F(CursorManagerTest, ShowHideCursor) { 92 TEST_F(CursorManagerTest, ShowHideCursor) {
93 views::corewm::CursorManager::TestApi api(&cursor_manager_);
94 api.ResetState();
95
96 cursor_manager_.SetCursor(ui::kCursorCopy); 96 cursor_manager_.SetCursor(ui::kCursorCopy);
97 EXPECT_EQ(ui::kCursorCopy, current_cursor().native_type()); 97 EXPECT_EQ(ui::kCursorCopy, cursor_manager_.GetCursor().native_type());
98 98
99 cursor_manager_.ShowCursor(); 99 cursor_manager_.ShowCursor();
100 EXPECT_TRUE(cursor_manager_.IsCursorVisible()); 100 EXPECT_TRUE(cursor_manager_.IsCursorVisible());
101 cursor_manager_.HideCursor(); 101 cursor_manager_.HideCursor();
102 EXPECT_FALSE(cursor_manager_.IsCursorVisible()); 102 EXPECT_FALSE(cursor_manager_.IsCursorVisible());
103 // The current cursor does not change even when the cursor is not shown. 103 // The current cursor does not change even when the cursor is not shown.
104 EXPECT_EQ(ui::kCursorCopy, current_cursor().native_type()); 104 EXPECT_EQ(ui::kCursorCopy, cursor_manager_.GetCursor().native_type());
105 105
106 // Check if cursor visibility is locked. 106 // Check if cursor visibility is locked.
107 cursor_manager_.LockCursor(); 107 cursor_manager_.LockCursor();
108 EXPECT_FALSE(cursor_manager_.IsCursorVisible()); 108 EXPECT_FALSE(cursor_manager_.IsCursorVisible());
109 cursor_manager_.ShowCursor(); 109 cursor_manager_.ShowCursor();
110 EXPECT_FALSE(cursor_manager_.IsCursorVisible()); 110 EXPECT_FALSE(cursor_manager_.IsCursorVisible());
111 cursor_manager_.UnlockCursor(); 111 cursor_manager_.UnlockCursor();
112 EXPECT_TRUE(cursor_manager_.IsCursorVisible()); 112 EXPECT_TRUE(cursor_manager_.IsCursorVisible());
113 113
114 cursor_manager_.LockCursor(); 114 cursor_manager_.LockCursor();
(...skipping 22 matching lines...) Expand all
137 137
138 cursor_manager_.HideCursor(); 138 cursor_manager_.HideCursor();
139 cursor_manager_.LockCursor(); 139 cursor_manager_.LockCursor();
140 cursor_manager_.UnlockCursor(); 140 cursor_manager_.UnlockCursor();
141 EXPECT_FALSE(cursor_manager_.IsCursorVisible()); 141 EXPECT_FALSE(cursor_manager_.IsCursorVisible());
142 } 142 }
143 143
144 // Verifies that LockCursor/UnlockCursor work correctly with 144 // Verifies that LockCursor/UnlockCursor work correctly with
145 // EnableMouseEvents and DisableMouseEvents 145 // EnableMouseEvents and DisableMouseEvents
146 TEST_F(CursorManagerTest, EnableDisableMouseEvents) { 146 TEST_F(CursorManagerTest, EnableDisableMouseEvents) {
147 views::corewm::CursorManager::TestApi api(&cursor_manager_);
148 api.ResetState();
149
147 cursor_manager_.SetCursor(ui::kCursorCopy); 150 cursor_manager_.SetCursor(ui::kCursorCopy);
148 EXPECT_EQ(ui::kCursorCopy, current_cursor().native_type()); 151 EXPECT_EQ(ui::kCursorCopy, cursor_manager_.GetCursor().native_type());
149 152
150 cursor_manager_.EnableMouseEvents(); 153 cursor_manager_.EnableMouseEvents();
151 EXPECT_TRUE(cursor_manager_.IsMouseEventsEnabled()); 154 EXPECT_TRUE(cursor_manager_.IsMouseEventsEnabled());
152 cursor_manager_.DisableMouseEvents(); 155 cursor_manager_.DisableMouseEvents();
153 EXPECT_FALSE(cursor_manager_.IsMouseEventsEnabled()); 156 EXPECT_FALSE(cursor_manager_.IsMouseEventsEnabled());
154 // The current cursor does not change even when the cursor is not shown. 157 // The current cursor does not change even when the cursor is not shown.
155 EXPECT_EQ(ui::kCursorCopy, current_cursor().native_type()); 158 EXPECT_EQ(ui::kCursorCopy, cursor_manager_.GetCursor().native_type());
156 159
157 // Check if cursor enable state is locked. 160 // Check if cursor enable state is locked.
158 cursor_manager_.LockCursor(); 161 cursor_manager_.LockCursor();
159 EXPECT_FALSE(cursor_manager_.IsMouseEventsEnabled()); 162 EXPECT_FALSE(cursor_manager_.IsMouseEventsEnabled());
160 cursor_manager_.EnableMouseEvents(); 163 cursor_manager_.EnableMouseEvents();
161 EXPECT_FALSE(cursor_manager_.IsMouseEventsEnabled()); 164 EXPECT_FALSE(cursor_manager_.IsMouseEventsEnabled());
162 cursor_manager_.UnlockCursor(); 165 cursor_manager_.UnlockCursor();
163 EXPECT_TRUE(cursor_manager_.IsMouseEventsEnabled()); 166 EXPECT_TRUE(cursor_manager_.IsMouseEventsEnabled());
164 167
165 cursor_manager_.LockCursor(); 168 cursor_manager_.LockCursor();
(...skipping 20 matching lines...) Expand all
186 cursor_manager_.UnlockCursor(); 189 cursor_manager_.UnlockCursor();
187 EXPECT_TRUE(cursor_manager_.IsMouseEventsEnabled()); 190 EXPECT_TRUE(cursor_manager_.IsMouseEventsEnabled());
188 191
189 cursor_manager_.DisableMouseEvents(); 192 cursor_manager_.DisableMouseEvents();
190 cursor_manager_.LockCursor(); 193 cursor_manager_.LockCursor();
191 cursor_manager_.UnlockCursor(); 194 cursor_manager_.UnlockCursor();
192 EXPECT_FALSE(cursor_manager_.IsMouseEventsEnabled()); 195 EXPECT_FALSE(cursor_manager_.IsMouseEventsEnabled());
193 } 196 }
194 197
195 TEST_F(CursorManagerTest, SetCursorSet) { 198 TEST_F(CursorManagerTest, SetCursorSet) {
196 EXPECT_EQ(ui::CURSOR_SET_NORMAL, cursor_manager_.GetCurrentCursorSet()); 199 views::corewm::CursorManager::TestApi api(&cursor_manager_);
200 api.ResetState();
201
202 EXPECT_EQ(ui::CURSOR_SET_NORMAL, cursor_manager_.GetCursorSet());
197 203
198 cursor_manager_.SetCursorSet(ui::CURSOR_SET_NORMAL); 204 cursor_manager_.SetCursorSet(ui::CURSOR_SET_NORMAL);
199 EXPECT_EQ(ui::CURSOR_SET_NORMAL, cursor_manager_.GetCurrentCursorSet()); 205 EXPECT_EQ(ui::CURSOR_SET_NORMAL, cursor_manager_.GetCursorSet());
200 206
201 cursor_manager_.SetCursorSet(ui::CURSOR_SET_LARGE); 207 cursor_manager_.SetCursorSet(ui::CURSOR_SET_LARGE);
202 EXPECT_EQ(ui::CURSOR_SET_LARGE, cursor_manager_.GetCurrentCursorSet()); 208 EXPECT_EQ(ui::CURSOR_SET_LARGE, cursor_manager_.GetCursorSet());
203 209
204 cursor_manager_.SetCursorSet(ui::CURSOR_SET_NORMAL); 210 cursor_manager_.SetCursorSet(ui::CURSOR_SET_NORMAL);
205 EXPECT_EQ(ui::CURSOR_SET_NORMAL, cursor_manager_.GetCurrentCursorSet()); 211 EXPECT_EQ(ui::CURSOR_SET_NORMAL, cursor_manager_.GetCursorSet());
206 } 212 }
207 213
208 TEST_F(CursorManagerTest, SetScale) { 214 TEST_F(CursorManagerTest, SetScale) {
209 EXPECT_EQ(1.f, cursor_manager_.GetCurrentScale()); 215 views::corewm::CursorManager::TestApi api(&cursor_manager_);
216 api.ResetState();
217
218 EXPECT_EQ(1.f, cursor_manager_.GetScale());
210 cursor_manager_.SetScale(2.f); 219 cursor_manager_.SetScale(2.f);
211 EXPECT_EQ(2.f, cursor_manager_.GetCurrentScale()); 220 EXPECT_EQ(2.f, cursor_manager_.GetScale());
212 221
213 // Cusror scale does change even while cursor is locked. 222 // Cusror scale does change even while cursor is locked.
214 cursor_manager_.LockCursor(); 223 cursor_manager_.LockCursor();
215 EXPECT_EQ(2.f, cursor_manager_.GetCurrentScale()); 224 EXPECT_EQ(2.f, cursor_manager_.GetScale());
216 cursor_manager_.SetScale(2.5f); 225 cursor_manager_.SetScale(2.5f);
217 EXPECT_EQ(2.5f, cursor_manager_.GetCurrentScale()); 226 EXPECT_EQ(2.5f, cursor_manager_.GetScale());
218 cursor_manager_.UnlockCursor(); 227 cursor_manager_.UnlockCursor();
219 228
220 EXPECT_EQ(2.5f, cursor_manager_.GetCurrentScale()); 229 EXPECT_EQ(2.5f, cursor_manager_.GetScale());
221 cursor_manager_.SetScale(1.f); 230 cursor_manager_.SetScale(1.f);
222 EXPECT_EQ(1.f, cursor_manager_.GetCurrentScale()); 231 EXPECT_EQ(1.f, cursor_manager_.GetScale());
223 } 232 }
224 233
225 TEST_F(CursorManagerTest, IsMouseEventsEnabled) { 234 TEST_F(CursorManagerTest, IsMouseEventsEnabled) {
235 views::corewm::CursorManager::TestApi api(&cursor_manager_);
236 api.ResetState();
237
226 cursor_manager_.EnableMouseEvents(); 238 cursor_manager_.EnableMouseEvents();
227 EXPECT_TRUE(cursor_manager_.IsMouseEventsEnabled()); 239 EXPECT_TRUE(cursor_manager_.IsMouseEventsEnabled());
228 cursor_manager_.DisableMouseEvents(); 240 cursor_manager_.DisableMouseEvents();
229 EXPECT_FALSE(cursor_manager_.IsMouseEventsEnabled()); 241 EXPECT_FALSE(cursor_manager_.IsMouseEventsEnabled());
230 } 242 }
231 243
232 // Verifies that the mouse events enable state changes correctly when 244 // Verifies that the mouse events enable state changes correctly when
233 // ShowCursor/HideCursor and EnableMouseEvents/DisableMouseEvents are used 245 // ShowCursor/HideCursor and EnableMouseEvents/DisableMouseEvents are used
234 // together. 246 // together.
235 TEST_F(CursorManagerTest, ShowAndEnable) { 247 TEST_F(CursorManagerTest, ShowAndEnable) {
248 views::corewm::CursorManager::TestApi api(&cursor_manager_);
249 api.ResetState();
250
236 // Changing the visibility of the cursor does not affect the enable state. 251 // Changing the visibility of the cursor does not affect the enable state.
237 cursor_manager_.EnableMouseEvents(); 252 cursor_manager_.EnableMouseEvents();
238 cursor_manager_.ShowCursor(); 253 cursor_manager_.ShowCursor();
239 EXPECT_TRUE(cursor_manager_.IsCursorVisible()); 254 EXPECT_TRUE(cursor_manager_.IsCursorVisible());
240 EXPECT_TRUE(cursor_manager_.IsMouseEventsEnabled()); 255 EXPECT_TRUE(cursor_manager_.IsMouseEventsEnabled());
241 cursor_manager_.HideCursor(); 256 cursor_manager_.HideCursor();
242 EXPECT_FALSE(cursor_manager_.IsCursorVisible()); 257 EXPECT_FALSE(cursor_manager_.IsCursorVisible());
243 EXPECT_TRUE(cursor_manager_.IsMouseEventsEnabled()); 258 EXPECT_TRUE(cursor_manager_.IsMouseEventsEnabled());
244 cursor_manager_.ShowCursor(); 259 cursor_manager_.ShowCursor();
245 EXPECT_TRUE(cursor_manager_.IsCursorVisible()); 260 EXPECT_TRUE(cursor_manager_.IsCursorVisible());
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 EXPECT_FALSE(cursor_manager_.IsMouseEventsEnabled()); 296 EXPECT_FALSE(cursor_manager_.IsMouseEventsEnabled());
282 cursor_manager_.DisableMouseEvents(); 297 cursor_manager_.DisableMouseEvents();
283 EXPECT_FALSE(cursor_manager_.IsCursorVisible()); 298 EXPECT_FALSE(cursor_manager_.IsCursorVisible());
284 EXPECT_FALSE(cursor_manager_.IsMouseEventsEnabled()); 299 EXPECT_FALSE(cursor_manager_.IsMouseEventsEnabled());
285 } 300 }
286 301
287 // Verifies that calling DisableMouseEvents multiple times in a row makes no 302 // Verifies that calling DisableMouseEvents multiple times in a row makes no
288 // difference compared with calling it once. 303 // difference compared with calling it once.
289 // This is a regression test for http://crbug.com/169404. 304 // This is a regression test for http://crbug.com/169404.
290 TEST_F(CursorManagerTest, MultipleDisableMouseEvents) { 305 TEST_F(CursorManagerTest, MultipleDisableMouseEvents) {
306 views::corewm::CursorManager::TestApi api(&cursor_manager_);
307 api.ResetState();
308
291 cursor_manager_.DisableMouseEvents(); 309 cursor_manager_.DisableMouseEvents();
292 cursor_manager_.DisableMouseEvents(); 310 cursor_manager_.DisableMouseEvents();
293 cursor_manager_.EnableMouseEvents(); 311 cursor_manager_.EnableMouseEvents();
294 cursor_manager_.LockCursor(); 312 cursor_manager_.LockCursor();
295 cursor_manager_.UnlockCursor(); 313 cursor_manager_.UnlockCursor();
296 EXPECT_TRUE(cursor_manager_.IsCursorVisible()); 314 EXPECT_TRUE(cursor_manager_.IsCursorVisible());
297 } 315 }
298 316
299 // Verifies that calling EnableMouseEvents multiple times in a row makes no 317 // Verifies that calling EnableMouseEvents multiple times in a row makes no
300 // difference compared with calling it once. 318 // difference compared with calling it once.
301 TEST_F(CursorManagerTest, MultipleEnableMouseEvents) { 319 TEST_F(CursorManagerTest, MultipleEnableMouseEvents) {
320 views::corewm::CursorManager::TestApi api(&cursor_manager_);
321 api.ResetState();
322
302 cursor_manager_.DisableMouseEvents(); 323 cursor_manager_.DisableMouseEvents();
303 cursor_manager_.EnableMouseEvents(); 324 cursor_manager_.EnableMouseEvents();
304 cursor_manager_.EnableMouseEvents(); 325 cursor_manager_.EnableMouseEvents();
305 cursor_manager_.LockCursor(); 326 cursor_manager_.LockCursor();
306 cursor_manager_.UnlockCursor(); 327 cursor_manager_.UnlockCursor();
307 EXPECT_TRUE(cursor_manager_.IsCursorVisible()); 328 EXPECT_TRUE(cursor_manager_.IsCursorVisible());
308 } 329 }
309 330
310 TEST_F(CursorManagerTest, TestCursorClientObserver) { 331 TEST_F(CursorManagerTest, TestCursorClientObserver) {
332 views::corewm::CursorManager::TestApi api(&cursor_manager_);
333 api.ResetState();
334
311 // Add two observers. Both should have OnCursorVisibilityChanged() 335 // Add two observers. Both should have OnCursorVisibilityChanged()
312 // invoked when the visibility of the cursor changes. 336 // invoked when the visibility of the cursor changes.
313 TestingCursorClientObserver observer_a; 337 TestingCursorClientObserver observer_a;
314 TestingCursorClientObserver observer_b; 338 TestingCursorClientObserver observer_b;
315 cursor_manager_.AddObserver(&observer_a); 339 cursor_manager_.AddObserver(&observer_a);
316 cursor_manager_.AddObserver(&observer_b); 340 cursor_manager_.AddObserver(&observer_b);
317 341
318 // Initial state before any events have been sent. 342 // Initial state before any events have been sent.
319 observer_a.reset(); 343 observer_a.reset();
320 observer_b.reset(); 344 observer_b.reset();
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
352 EXPECT_FALSE(observer_a.is_cursor_visible()); 376 EXPECT_FALSE(observer_a.is_cursor_visible());
353 377
354 // Show the cursor using ShowCursor(). 378 // Show the cursor using ShowCursor().
355 observer_a.reset(); 379 observer_a.reset();
356 observer_b.reset(); 380 observer_b.reset();
357 cursor_manager_.ShowCursor(); 381 cursor_manager_.ShowCursor();
358 EXPECT_TRUE(observer_a.did_visibility_change()); 382 EXPECT_TRUE(observer_a.did_visibility_change());
359 EXPECT_FALSE(observer_b.did_visibility_change()); 383 EXPECT_FALSE(observer_b.did_visibility_change());
360 EXPECT_TRUE(observer_a.is_cursor_visible()); 384 EXPECT_TRUE(observer_a.is_cursor_visible());
361 } 385 }
386
387 // Verifies that the cursor state is global among all CursorManager instances.
388 TEST_F(CursorManagerTest, CursorManagerGlobalState) {
389 views::corewm::CursorManager::TestApi api(&cursor_manager_);
390 api.ResetState();
391 api = views::corewm::CursorManager::TestApi(&cursor_manager_second_);
392 api.ResetState();
393
394 // Verify the cursor can be locked using one cursor manager and
395 // unlocked using another.
396 EXPECT_FALSE(cursor_manager_.IsCursorLocked());
397 EXPECT_FALSE(cursor_manager_second_.IsCursorLocked());
398
399 cursor_manager_.LockCursor();
400 EXPECT_TRUE(cursor_manager_.IsCursorLocked());
401 EXPECT_TRUE(cursor_manager_second_.IsCursorLocked());
402
403 cursor_manager_second_.UnlockCursor();
404 EXPECT_FALSE(cursor_manager_.IsCursorLocked());
405 EXPECT_FALSE(cursor_manager_second_.IsCursorLocked());
406
407 // Verify that mouse events can be disabled using one cursor manager
408 // and re-enabled using another.
409 EXPECT_TRUE(cursor_manager_.IsCursorVisible());
410 EXPECT_TRUE(cursor_manager_.IsMouseEventsEnabled());
411 EXPECT_TRUE(cursor_manager_second_.IsCursorVisible());
412 EXPECT_TRUE(cursor_manager_second_.IsMouseEventsEnabled());
413
414 cursor_manager_second_.DisableMouseEvents();
415 EXPECT_FALSE(cursor_manager_.IsCursorVisible());
416 EXPECT_FALSE(cursor_manager_.IsMouseEventsEnabled());
417 EXPECT_FALSE(cursor_manager_second_.IsCursorVisible());
418 EXPECT_FALSE(cursor_manager_second_.IsMouseEventsEnabled());
419
420 cursor_manager_.EnableMouseEvents();
421 EXPECT_TRUE(cursor_manager_.IsCursorVisible());
422 EXPECT_TRUE(cursor_manager_.IsMouseEventsEnabled());
423 EXPECT_TRUE(cursor_manager_second_.IsCursorVisible());
424 EXPECT_TRUE(cursor_manager_second_.IsMouseEventsEnabled());
425
426 // Verify that setting the cursor on one cursor manager will set
427 // it on another.
428 EXPECT_EQ(ui::kCursorNone, cursor_manager_.GetCursor().native_type());
429 EXPECT_EQ(ui::kCursorNone, cursor_manager_second_.GetCursor().native_type());
430
431 cursor_manager_.SetCursor(ui::kCursorPointer);
432 EXPECT_EQ(ui::kCursorPointer, cursor_manager_.GetCursor().native_type());
433 EXPECT_EQ(ui::kCursorPointer,
434 cursor_manager_second_.GetCursor().native_type());
435
436 // Verify that hiding the cursor using one cursor manager will
437 // also hide it on the other.
438 cursor_manager_second_.HideCursor();
439 EXPECT_FALSE(cursor_manager_.IsCursorVisible());
440 EXPECT_TRUE(cursor_manager_.IsMouseEventsEnabled());
441 EXPECT_FALSE(cursor_manager_second_.IsCursorVisible());
442 EXPECT_TRUE(cursor_manager_second_.IsMouseEventsEnabled());
443
444 // Verify that the visibility cannot be changed by one cursor
445 // manager if the cursor has been locked by another.
446 cursor_manager_second_.LockCursor();
447 cursor_manager_.ShowCursor();
448 EXPECT_FALSE(cursor_manager_.IsCursorVisible());
449 EXPECT_FALSE(cursor_manager_second_.IsCursorVisible());
450
451 // Verify the cursor is visible on unlock.
452 cursor_manager_.UnlockCursor();
453 EXPECT_TRUE(cursor_manager_.IsCursorVisible());
454 EXPECT_TRUE(cursor_manager_second_.IsCursorVisible());
455 }
OLDNEW
« no previous file with comments | « ui/views/corewm/cursor_manager.cc ('k') | ui/views/corewm/native_cursor_manager_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698