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

Side by Side Diff: ash/wm/ash_native_cursor_manager_unittest.cc

Issue 12263050: Rework ash::CursorManager into a corewm object, to share code with desktop. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase to ToT Created 7 years, 10 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 | Annotate | Revision Log
« no previous file with comments | « ash/wm/ash_native_cursor_manager.cc ('k') | ash/wm/cursor_manager.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2012 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 "ash/wm/ash_native_cursor_manager.h"
6
7 #include "ash/shell.h"
8 #include "ash/test/ash_test_base.h"
9 #include "ash/test/cursor_manager_test_api.h"
10 #include "ash/wm/image_cursors.h"
11 #include "ui/aura/root_window.h"
12 #include "ui/aura/test/test_window_delegate.h"
13 #include "ui/aura/test/test_windows.h"
14 #include "ui/aura/window.h"
15
16 using views::corewm::CursorManager;
17
18 namespace ash {
19 namespace test {
20
21 namespace {
22
23 // A delegate for recording a mouse event location.
24 class MouseEventLocationDelegate : public aura::test::TestWindowDelegate {
25 public:
26 MouseEventLocationDelegate() {}
27 virtual ~MouseEventLocationDelegate() {}
28
29 const gfx::Point& mouse_event_location() const {
30 return mouse_event_location_;
31 }
32
33 virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE {
34 mouse_event_location_ = event->location();
35 event->SetHandled();
36 }
37
38 private:
39 gfx::Point mouse_event_location_;
40
41 DISALLOW_COPY_AND_ASSIGN(MouseEventLocationDelegate);
42 };
43
44 } // namespace
45
46 typedef test::AshTestBase AshNativeCursorManagerTest;
47
48 TEST_F(AshNativeCursorManagerTest, LockCursor) {
49 CursorManager* cursor_manager = Shell::GetInstance()->cursor_manager();
50 CursorManagerTestApi test_api(cursor_manager);
51
52 cursor_manager->SetCursor(ui::kCursorCopy);
53 EXPECT_EQ(ui::kCursorCopy, test_api.GetCurrentCursor().native_type());
54 cursor_manager->SetDeviceScaleFactor(2.0f);
55 EXPECT_EQ(2.0f, test_api.GetDeviceScaleFactor());
56 EXPECT_TRUE(test_api.GetCurrentCursor().platform());
57
58 cursor_manager->LockCursor();
59 EXPECT_TRUE(cursor_manager->is_cursor_locked());
60
61 // Cursor type does not change while cursor is locked.
62 cursor_manager->SetCursor(ui::kCursorPointer);
63 EXPECT_EQ(ui::kCursorCopy, test_api.GetCurrentCursor().native_type());
64
65 // Device scale factor does change even while cursor is locked.
66 cursor_manager->SetDeviceScaleFactor(1.0f);
67 EXPECT_EQ(1.0f, test_api.GetDeviceScaleFactor());
68
69 cursor_manager->UnlockCursor();
70 EXPECT_FALSE(cursor_manager->is_cursor_locked());
71
72 // Cursor type changes to the one specified while cursor is locked.
73 EXPECT_EQ(ui::kCursorPointer, test_api.GetCurrentCursor().native_type());
74 EXPECT_EQ(1.0f, test_api.GetDeviceScaleFactor());
75 EXPECT_TRUE(test_api.GetCurrentCursor().platform());
76 }
77
78 TEST_F(AshNativeCursorManagerTest, SetCursor) {
79 CursorManager* cursor_manager = Shell::GetInstance()->cursor_manager();
80 CursorManagerTestApi test_api(cursor_manager);
81
82 cursor_manager->SetCursor(ui::kCursorCopy);
83 EXPECT_EQ(ui::kCursorCopy, test_api.GetCurrentCursor().native_type());
84 EXPECT_TRUE(test_api.GetCurrentCursor().platform());
85 cursor_manager->SetCursor(ui::kCursorPointer);
86 EXPECT_EQ(ui::kCursorPointer, test_api.GetCurrentCursor().native_type());
87 EXPECT_TRUE(test_api.GetCurrentCursor().platform());
88 }
89
90 TEST_F(AshNativeCursorManagerTest, SetDeviceScaleFactor) {
91 CursorManager* cursor_manager = Shell::GetInstance()->cursor_manager();
92 CursorManagerTestApi test_api(cursor_manager);
93
94 cursor_manager->SetDeviceScaleFactor(2.0f);
95 EXPECT_EQ(2.0f, test_api.GetDeviceScaleFactor());
96 cursor_manager->SetDeviceScaleFactor(1.0f);
97 EXPECT_EQ(1.0f, test_api.GetDeviceScaleFactor());
98 }
99
100 #if defined(OS_WIN)
101 // Temporarily disabled for windows. See crbug.com/112222.
102 #define MAYBE_DisabledMouseEventsLocation DISABLED_DisabledMouseEventsLocation
103 #else
104 #define MAYBE_DisabledMouseEventsLocation DisabledMouseEventsLocation
105 #endif // defined(OS_WIN)
106
107 // Verifies that RootWindow generates a mouse event located outside of a window
108 // when mouse events are disabled.
109 TEST_F(AshNativeCursorManagerTest, MAYBE_DisabledMouseEventsLocation) {
110 scoped_ptr<MouseEventLocationDelegate> delegate(
111 new MouseEventLocationDelegate());
112 const int kWindowWidth = 123;
113 const int kWindowHeight = 45;
114 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
115 scoped_ptr<aura::Window> window(aura::test::CreateTestWindowWithDelegate(
116 delegate.get(), 1, bounds, Shell::GetInstance()->GetPrimaryRootWindow()));
117
118 CursorManager* cursor_manager = Shell::GetInstance()->cursor_manager();
119 cursor_manager->EnableMouseEvents();
120 // Send a mouse event to window.
121 gfx::Point point(101, 201);
122 gfx::Point local_point;
123 ui::MouseEvent event(ui::ET_MOUSE_MOVED, point, point, 0);
124 aura::RootWindow* root_window = window->GetRootWindow();
125 root_window->AsRootWindowHostDelegate()->OnHostMouseEvent(&event);
126
127 // Location was in window.
128 local_point = delegate->mouse_event_location();
129 aura::Window::ConvertPointToTarget(window.get(), root_window, &local_point);
130 EXPECT_TRUE(window->bounds().Contains(local_point));
131
132 // Location is now out of window.
133 cursor_manager->DisableMouseEvents();
134 RunAllPendingInMessageLoop();
135 local_point = delegate->mouse_event_location();
136 aura::Window::ConvertPointToTarget(window.get(), root_window, &local_point);
137 EXPECT_FALSE(window->bounds().Contains(local_point));
138
139 // Location is back in window.
140 cursor_manager->EnableMouseEvents();
141 RunAllPendingInMessageLoop();
142 local_point = delegate->mouse_event_location();
143 aura::Window::ConvertPointToTarget(window.get(), root_window, &local_point);
144 EXPECT_TRUE(window->bounds().Contains(local_point));
145 }
146
147 #if defined(OS_WIN)
148 // Disable on Win because RootWindow::MoveCursorTo is not implemented.
149 #define MAYBE_DisabledQueryMouseLocation DISABLED_DisabledQueryMouseLocation
150 #else
151 #define MAYBE_DisabledQueryMouseLocation DisabledQueryMouseLocation
152 #endif // defined(OS_WIN)
153
154 TEST_F(AshNativeCursorManagerTest, MAYBE_DisabledQueryMouseLocation) {
155 aura::RootWindow* root_window = Shell::GetInstance()->GetPrimaryRootWindow();
156 root_window->MoveCursorTo(gfx::Point(10, 10));
157 gfx::Point mouse_location;
158 EXPECT_TRUE(root_window->QueryMouseLocationForTest(&mouse_location));
159 EXPECT_EQ("10,10", mouse_location.ToString());
160 Shell::GetInstance()->cursor_manager()->DisableMouseEvents();
161 EXPECT_FALSE(root_window->QueryMouseLocationForTest(&mouse_location));
162 EXPECT_EQ("0,0", mouse_location.ToString());
163 }
164
165 } // namespace test
166 } // namespace ash
OLDNEW
« no previous file with comments | « ash/wm/ash_native_cursor_manager.cc ('k') | ash/wm/cursor_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698