OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 "ash/wm/ash_native_cursor_manager.h" | 5 #include "ash/wm/ash_native_cursor_manager.h" |
6 | 6 |
7 #include "ash/shell.h" | 7 #include "ash/shell.h" |
8 #include "ash/test/ash_test_base.h" | 8 #include "ash/test/ash_test_base.h" |
9 #include "ash/test/cursor_manager_test_api.h" | 9 #include "ash/test/cursor_manager_test_api.h" |
10 #include "ash/wm/image_cursors.h" | 10 #include "ash/wm/image_cursors.h" |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 DISALLOW_COPY_AND_ASSIGN(MouseEventLocationDelegate); | 47 DISALLOW_COPY_AND_ASSIGN(MouseEventLocationDelegate); |
48 }; | 48 }; |
49 | 49 |
50 } // namespace | 50 } // namespace |
51 | 51 |
52 typedef test::AshTestBase AshNativeCursorManagerTest; | 52 typedef test::AshTestBase AshNativeCursorManagerTest; |
53 | 53 |
54 TEST_F(AshNativeCursorManagerTest, LockCursor) { | 54 TEST_F(AshNativeCursorManagerTest, LockCursor) { |
55 ::wm::CursorManager* cursor_manager = Shell::GetInstance()->cursor_manager(); | 55 ::wm::CursorManager* cursor_manager = Shell::GetInstance()->cursor_manager(); |
56 CursorManagerTestApi test_api(cursor_manager); | 56 CursorManagerTestApi test_api(cursor_manager); |
57 gfx::Display display(0); | 57 |
58 #if defined(OS_WIN) | 58 #if defined(OS_WIN) |
59 ui::CursorLoaderWin::SetCursorResourceModule(L"ash_unittests.exe"); | 59 ui::CursorLoaderWin::SetCursorResourceModule(L"ash_unittests.exe"); |
60 #endif | 60 #endif |
61 cursor_manager->SetCursor(ui::kCursorCopy); | 61 cursor_manager->SetCursor(ui::kCursorCopy); |
62 EXPECT_EQ(ui::kCursorCopy, test_api.GetCurrentCursor().native_type()); | 62 EXPECT_EQ(ui::kCursorCopy, test_api.GetCurrentCursor().native_type()); |
63 display.set_device_scale_factor(2.0f); | 63 UpdateDisplay("800x800*2/r"); |
64 display.set_rotation(gfx::Display::ROTATE_90); | 64 EXPECT_EQ(2.0f, test_api.GetCurrentCursor().device_scale_factor()); |
65 cursor_manager->SetDisplay(display); | |
66 EXPECT_EQ(2.0f, test_api.GetDisplay().device_scale_factor()); | |
67 EXPECT_EQ(ui::CURSOR_SET_NORMAL, test_api.GetCurrentCursorSet()); | 65 EXPECT_EQ(ui::CURSOR_SET_NORMAL, test_api.GetCurrentCursorSet()); |
68 EXPECT_EQ(gfx::Display::ROTATE_90, test_api.GetDisplay().rotation()); | 66 EXPECT_EQ(gfx::Display::ROTATE_90, test_api.GetCurrentCursorRotation()); |
69 EXPECT_TRUE(test_api.GetCurrentCursor().platform()); | 67 EXPECT_TRUE(test_api.GetCurrentCursor().platform()); |
70 | 68 |
71 cursor_manager->LockCursor(); | 69 cursor_manager->LockCursor(); |
72 EXPECT_TRUE(cursor_manager->IsCursorLocked()); | 70 EXPECT_TRUE(cursor_manager->IsCursorLocked()); |
73 | 71 |
74 // Cursor type does not change while cursor is locked. | 72 // Cursor type does not change while cursor is locked. |
75 EXPECT_EQ(ui::CURSOR_SET_NORMAL, test_api.GetCurrentCursorSet()); | 73 EXPECT_EQ(ui::CURSOR_SET_NORMAL, test_api.GetCurrentCursorSet()); |
76 cursor_manager->SetCursorSet(ui::CURSOR_SET_NORMAL); | 74 cursor_manager->SetCursorSet(ui::CURSOR_SET_NORMAL); |
77 EXPECT_EQ(ui::CURSOR_SET_NORMAL, test_api.GetCurrentCursorSet()); | 75 EXPECT_EQ(ui::CURSOR_SET_NORMAL, test_api.GetCurrentCursorSet()); |
78 cursor_manager->SetCursorSet(ui::CURSOR_SET_LARGE); | 76 cursor_manager->SetCursorSet(ui::CURSOR_SET_LARGE); |
79 EXPECT_EQ(ui::CURSOR_SET_LARGE, test_api.GetCurrentCursorSet()); | 77 EXPECT_EQ(ui::CURSOR_SET_LARGE, test_api.GetCurrentCursorSet()); |
80 cursor_manager->SetCursorSet(ui::CURSOR_SET_NORMAL); | 78 cursor_manager->SetCursorSet(ui::CURSOR_SET_NORMAL); |
81 EXPECT_EQ(ui::CURSOR_SET_NORMAL, test_api.GetCurrentCursorSet()); | 79 EXPECT_EQ(ui::CURSOR_SET_NORMAL, test_api.GetCurrentCursorSet()); |
82 | 80 |
83 // Cursor type does not change while cursor is locked. | 81 // Cursor type does not change while cursor is locked. |
84 cursor_manager->SetCursor(ui::kCursorPointer); | 82 cursor_manager->SetCursor(ui::kCursorPointer); |
85 EXPECT_EQ(ui::kCursorCopy, test_api.GetCurrentCursor().native_type()); | 83 EXPECT_EQ(ui::kCursorCopy, test_api.GetCurrentCursor().native_type()); |
86 | 84 |
87 // Device scale factor and rotation do change even while cursor is locked. | 85 // Device scale factor and rotation do change even while cursor is locked. |
88 display.set_device_scale_factor(1.0f); | 86 UpdateDisplay("800x800/u"); |
89 display.set_rotation(gfx::Display::ROTATE_180); | 87 EXPECT_EQ(1.0f, test_api.GetCurrentCursor().device_scale_factor()); |
90 cursor_manager->SetDisplay(display); | 88 EXPECT_EQ(gfx::Display::ROTATE_180, test_api.GetCurrentCursorRotation()); |
91 EXPECT_EQ(1.0f, test_api.GetDisplay().device_scale_factor()); | |
92 EXPECT_EQ(gfx::Display::ROTATE_180, test_api.GetDisplay().rotation()); | |
93 | 89 |
94 cursor_manager->UnlockCursor(); | 90 cursor_manager->UnlockCursor(); |
95 EXPECT_FALSE(cursor_manager->IsCursorLocked()); | 91 EXPECT_FALSE(cursor_manager->IsCursorLocked()); |
96 | 92 |
97 // Cursor type changes to the one specified while cursor is locked. | 93 // Cursor type changes to the one specified while cursor is locked. |
98 EXPECT_EQ(ui::kCursorPointer, test_api.GetCurrentCursor().native_type()); | 94 EXPECT_EQ(ui::kCursorPointer, test_api.GetCurrentCursor().native_type()); |
99 EXPECT_EQ(1.0f, test_api.GetDisplay().device_scale_factor()); | 95 EXPECT_EQ(1.0f, test_api.GetCurrentCursor().device_scale_factor()); |
100 EXPECT_TRUE(test_api.GetCurrentCursor().platform()); | 96 EXPECT_TRUE(test_api.GetCurrentCursor().platform()); |
101 } | 97 } |
102 | 98 |
103 TEST_F(AshNativeCursorManagerTest, SetCursor) { | 99 TEST_F(AshNativeCursorManagerTest, SetCursor) { |
104 ::wm::CursorManager* cursor_manager = Shell::GetInstance()->cursor_manager(); | 100 ::wm::CursorManager* cursor_manager = Shell::GetInstance()->cursor_manager(); |
105 CursorManagerTestApi test_api(cursor_manager); | 101 CursorManagerTestApi test_api(cursor_manager); |
106 #if defined(OS_WIN) | 102 #if defined(OS_WIN) |
107 ui::CursorLoaderWin::SetCursorResourceModule(L"ash_unittests.exe"); | 103 ui::CursorLoaderWin::SetCursorResourceModule(L"ash_unittests.exe"); |
108 #endif | 104 #endif |
109 cursor_manager->SetCursor(ui::kCursorCopy); | 105 cursor_manager->SetCursor(ui::kCursorCopy); |
(...skipping 16 matching lines...) Expand all Loading... |
126 cursor_manager->SetCursorSet(ui::CURSOR_SET_LARGE); | 122 cursor_manager->SetCursorSet(ui::CURSOR_SET_LARGE); |
127 EXPECT_EQ(ui::CURSOR_SET_LARGE, test_api.GetCurrentCursorSet()); | 123 EXPECT_EQ(ui::CURSOR_SET_LARGE, test_api.GetCurrentCursorSet()); |
128 | 124 |
129 cursor_manager->SetCursorSet(ui::CURSOR_SET_NORMAL); | 125 cursor_manager->SetCursorSet(ui::CURSOR_SET_NORMAL); |
130 EXPECT_EQ(ui::CURSOR_SET_NORMAL, test_api.GetCurrentCursorSet()); | 126 EXPECT_EQ(ui::CURSOR_SET_NORMAL, test_api.GetCurrentCursorSet()); |
131 } | 127 } |
132 | 128 |
133 TEST_F(AshNativeCursorManagerTest, SetDeviceScaleFactorAndRotation) { | 129 TEST_F(AshNativeCursorManagerTest, SetDeviceScaleFactorAndRotation) { |
134 ::wm::CursorManager* cursor_manager = Shell::GetInstance()->cursor_manager(); | 130 ::wm::CursorManager* cursor_manager = Shell::GetInstance()->cursor_manager(); |
135 CursorManagerTestApi test_api(cursor_manager); | 131 CursorManagerTestApi test_api(cursor_manager); |
| 132 UpdateDisplay("800x100*2"); |
| 133 EXPECT_EQ(2.0f, test_api.GetCurrentCursor().device_scale_factor()); |
| 134 EXPECT_EQ(gfx::Display::ROTATE_0, test_api.GetCurrentCursorRotation()); |
136 | 135 |
137 gfx::Display display(0); | 136 UpdateDisplay("800x100/l"); |
138 display.set_device_scale_factor(2.0f); | 137 EXPECT_EQ(1.0f, test_api.GetCurrentCursor().device_scale_factor()); |
139 cursor_manager->SetDisplay(display); | 138 EXPECT_EQ(gfx::Display::ROTATE_270, test_api.GetCurrentCursorRotation()); |
140 EXPECT_EQ(2.0f, test_api.GetDisplay().device_scale_factor()); | |
141 EXPECT_EQ(gfx::Display::ROTATE_0, test_api.GetDisplay().rotation()); | |
142 | |
143 display.set_device_scale_factor(1.0f); | |
144 display.set_rotation(gfx::Display::ROTATE_270); | |
145 cursor_manager->SetDisplay(display); | |
146 EXPECT_EQ(1.0f, test_api.GetDisplay().device_scale_factor()); | |
147 EXPECT_EQ(gfx::Display::ROTATE_270, test_api.GetDisplay().rotation()); | |
148 } | 139 } |
149 | 140 |
150 TEST_F(AshNativeCursorManagerTest, DisabledQueryMouseLocation) { | 141 TEST_F(AshNativeCursorManagerTest, DisabledQueryMouseLocation) { |
151 aura::Window* root_window = Shell::GetInstance()->GetPrimaryRootWindow(); | 142 aura::Window* root_window = Shell::GetInstance()->GetPrimaryRootWindow(); |
152 #if defined(OS_WIN) | 143 #if defined(OS_WIN) |
153 if (base::win::GetVersion() < base::win::VERSION_WIN8) | 144 if (base::win::GetVersion() < base::win::VERSION_WIN8) |
154 return; | 145 return; |
155 // On Windows 8 the ASH environment has two processes, the viewer process | 146 // On Windows 8 the ASH environment has two processes, the viewer process |
156 // which runs in Windows 8 mode and the browser process. The initialization | 147 // which runs in Windows 8 mode and the browser process. The initialization |
157 // happens when the viewer process connects to the browser channel and sends | 148 // happens when the viewer process connects to the browser channel and sends |
(...skipping 14 matching lines...) Expand all Loading... |
172 gfx::Point mouse_location; | 163 gfx::Point mouse_location; |
173 EXPECT_TRUE(host->QueryMouseLocation(&mouse_location)); | 164 EXPECT_TRUE(host->QueryMouseLocation(&mouse_location)); |
174 EXPECT_EQ("10,10", mouse_location.ToString()); | 165 EXPECT_EQ("10,10", mouse_location.ToString()); |
175 Shell::GetInstance()->cursor_manager()->DisableMouseEvents(); | 166 Shell::GetInstance()->cursor_manager()->DisableMouseEvents(); |
176 EXPECT_FALSE(host->QueryMouseLocation(&mouse_location)); | 167 EXPECT_FALSE(host->QueryMouseLocation(&mouse_location)); |
177 EXPECT_EQ("0,0", mouse_location.ToString()); | 168 EXPECT_EQ("0,0", mouse_location.ToString()); |
178 } | 169 } |
179 | 170 |
180 } // namespace test | 171 } // namespace test |
181 } // namespace ash | 172 } // namespace ash |
OLD | NEW |