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