Windows should animate when they are about to get docked at screen edges.
[chromium-blink-merge.git] / ash / wm / ash_native_cursor_manager_unittest.cc
blobbd748ed194400efd00b2909f05edc7c9497607cc
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.
5 #include "ash/wm/ash_native_cursor_manager.h"
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 #include "ui/gfx/screen.h"
17 #if defined(OS_WIN)
18 #include "base/win/windows_version.h"
19 #include "ui/base/cursor/cursor_loader_win.h"
20 #endif
22 using views::corewm::CursorManager;
24 namespace ash {
25 namespace test {
27 namespace {
29 // A delegate for recording a mouse event location.
30 class MouseEventLocationDelegate : public aura::test::TestWindowDelegate {
31 public:
32 MouseEventLocationDelegate() {}
33 virtual ~MouseEventLocationDelegate() {}
35 gfx::Point GetMouseEventLocationAndReset() {
36 gfx::Point p = mouse_event_location_;
37 mouse_event_location_.SetPoint(-100, -100);
38 return p;
41 virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE {
42 mouse_event_location_ = event->location();
43 event->SetHandled();
46 private:
47 gfx::Point mouse_event_location_;
49 DISALLOW_COPY_AND_ASSIGN(MouseEventLocationDelegate);
52 } // namespace
54 typedef test::AshTestBase AshNativeCursorManagerTest;
56 TEST_F(AshNativeCursorManagerTest, LockCursor) {
57 CursorManager* cursor_manager = Shell::GetInstance()->cursor_manager();
58 CursorManagerTestApi test_api(cursor_manager);
59 gfx::Display display(0);
60 #if defined(OS_WIN)
61 ui::CursorLoaderWin::SetCursorResourceModule(L"ash_unittests.exe");
62 #endif
63 cursor_manager->SetCursor(ui::kCursorCopy);
64 EXPECT_EQ(ui::kCursorCopy, test_api.GetCurrentCursor().native_type());
65 display.set_device_scale_factor(2.0f);
66 display.set_rotation(gfx::Display::ROTATE_90);
67 cursor_manager->SetScale(2.5f);
68 cursor_manager->SetDisplay(display);
69 EXPECT_EQ(2.5f, test_api.GetCurrentScale());
70 EXPECT_EQ(2.0f, test_api.GetDisplay().device_scale_factor());
71 EXPECT_EQ(gfx::Display::ROTATE_90, test_api.GetDisplay().rotation());
72 EXPECT_TRUE(test_api.GetCurrentCursor().platform());
74 cursor_manager->LockCursor();
75 EXPECT_TRUE(cursor_manager->is_cursor_locked());
77 // Cusror scale does change even while cursor is locked.
78 EXPECT_EQ(2.5f, test_api.GetCurrentScale());
79 cursor_manager->SetScale(1.f);
80 EXPECT_EQ(1.f, test_api.GetCurrentScale());
81 cursor_manager->SetScale(1.5f);
82 EXPECT_EQ(1.5f, test_api.GetCurrentScale());
84 // Cursor type does not change while cursor is locked.
85 cursor_manager->SetCursor(ui::kCursorPointer);
86 EXPECT_EQ(ui::kCursorCopy, test_api.GetCurrentCursor().native_type());
88 // Device scale factor and rotation do change even while cursor is locked.
89 display.set_device_scale_factor(1.0f);
90 display.set_rotation(gfx::Display::ROTATE_180);
91 cursor_manager->SetDisplay(display);
92 EXPECT_EQ(1.0f, test_api.GetDisplay().device_scale_factor());
93 EXPECT_EQ(gfx::Display::ROTATE_180, test_api.GetDisplay().rotation());
95 cursor_manager->UnlockCursor();
96 EXPECT_FALSE(cursor_manager->is_cursor_locked());
98 // Cursor type changes to the one specified while cursor is locked.
99 EXPECT_EQ(1.5f, test_api.GetCurrentScale());
100 EXPECT_EQ(ui::kCursorPointer, test_api.GetCurrentCursor().native_type());
101 EXPECT_EQ(1.0f, test_api.GetDisplay().device_scale_factor());
102 EXPECT_TRUE(test_api.GetCurrentCursor().platform());
105 TEST_F(AshNativeCursorManagerTest, SetCursor) {
106 CursorManager* cursor_manager = Shell::GetInstance()->cursor_manager();
107 CursorManagerTestApi test_api(cursor_manager);
108 #if defined(OS_WIN)
109 ui::CursorLoaderWin::SetCursorResourceModule(L"ash_unittests.exe");
110 #endif
111 cursor_manager->SetCursor(ui::kCursorCopy);
112 EXPECT_EQ(ui::kCursorCopy, test_api.GetCurrentCursor().native_type());
113 EXPECT_TRUE(test_api.GetCurrentCursor().platform());
114 cursor_manager->SetCursor(ui::kCursorPointer);
115 EXPECT_EQ(ui::kCursorPointer, test_api.GetCurrentCursor().native_type());
116 EXPECT_TRUE(test_api.GetCurrentCursor().platform());
119 TEST_F(AshNativeCursorManagerTest, SetScale) {
120 CursorManager* cursor_manager = Shell::GetInstance()->cursor_manager();
121 CursorManagerTestApi test_api(cursor_manager);
123 EXPECT_EQ(1.f, test_api.GetCurrentScale());
125 cursor_manager->SetScale(2.5f);
126 EXPECT_EQ(2.5f, test_api.GetCurrentScale());
128 cursor_manager->SetScale(1.f);
129 EXPECT_EQ(1.f, test_api.GetCurrentScale());
132 TEST_F(AshNativeCursorManagerTest, SetDeviceScaleFactorAndRotation) {
133 CursorManager* cursor_manager = Shell::GetInstance()->cursor_manager();
134 CursorManagerTestApi test_api(cursor_manager);
136 gfx::Display display(0);
137 display.set_device_scale_factor(2.0f);
138 cursor_manager->SetDisplay(display);
139 EXPECT_EQ(2.0f, test_api.GetDisplay().device_scale_factor());
140 EXPECT_EQ(gfx::Display::ROTATE_0, test_api.GetDisplay().rotation());
142 display.set_device_scale_factor(1.0f);
143 display.set_rotation(gfx::Display::ROTATE_270);
144 cursor_manager->SetDisplay(display);
145 EXPECT_EQ(1.0f, test_api.GetDisplay().device_scale_factor());
146 EXPECT_EQ(gfx::Display::ROTATE_270, test_api.GetDisplay().rotation());
149 TEST_F(AshNativeCursorManagerTest, DisabledQueryMouseLocation) {
150 aura::RootWindow* root_window = Shell::GetInstance()->GetPrimaryRootWindow();
151 #if defined(OS_WIN)
152 if (base::win::GetVersion() < base::win::VERSION_WIN8)
153 return;
154 // On Windows 8 the ASH environment has two processes, the viewer process
155 // which runs in Windows 8 mode and the browser process. The initialization
156 // happens when the viewer process connects to the browser channel and sends
157 // the initial IPC message.
158 RunAllPendingInMessageLoop();
159 #endif
160 root_window->MoveCursorTo(gfx::Point(10, 10));
161 #if defined(OS_WIN)
162 // The MoveCursor operation on Windows 8 is implemented in the viewer process
163 // which is notified by an IPC message to perform the MoveCursor operation.
164 // We need to ensure that the IPC is delivered to the viewer process and it
165 // the ACK is sent back from the viewer indicating that the operation
166 // completed.
167 Sleep(100);
168 RunAllPendingInMessageLoop();
169 #endif
170 gfx::Point mouse_location;
171 EXPECT_TRUE(root_window->QueryMouseLocationForTest(&mouse_location));
172 EXPECT_EQ("10,10", mouse_location.ToString());
173 Shell::GetInstance()->cursor_manager()->DisableMouseEvents();
174 EXPECT_FALSE(root_window->QueryMouseLocationForTest(&mouse_location));
175 EXPECT_EQ("0,0", mouse_location.ToString());
178 } // namespace test
179 } // namespace ash