Cast: Stop logging kVideoFrameSentToEncoder and rename a couple events.
[chromium-blink-merge.git] / ash / wm / ash_native_cursor_manager_unittest.cc
blobe31d81437759b3967c2c57106f9dde4663c2ec83
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/display/display_info.h"
8 #include "ash/display/display_manager.h"
9 #include "ash/shell.h"
10 #include "ash/test/ash_test_base.h"
11 #include "ash/test/cursor_manager_test_api.h"
12 #include "ui/aura/test/aura_test_utils.h"
13 #include "ui/aura/test/test_window_delegate.h"
14 #include "ui/aura/test/test_windows.h"
15 #include "ui/aura/window.h"
16 #include "ui/aura/window_event_dispatcher.h"
17 #include "ui/base/cursor/image_cursors.h"
18 #include "ui/gfx/screen.h"
20 #if defined(OS_WIN)
21 #include "base/win/windows_version.h"
22 #include "ui/base/cursor/cursor_loader_win.h"
23 #endif
25 namespace ash {
26 namespace test {
28 namespace {
30 // A delegate for recording a mouse event location.
31 class MouseEventLocationDelegate : public aura::test::TestWindowDelegate {
32 public:
33 MouseEventLocationDelegate() {}
34 virtual ~MouseEventLocationDelegate() {}
36 gfx::Point GetMouseEventLocationAndReset() {
37 gfx::Point p = mouse_event_location_;
38 mouse_event_location_.SetPoint(-100, -100);
39 return p;
42 virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE {
43 mouse_event_location_ = event->location();
44 event->SetHandled();
47 private:
48 gfx::Point mouse_event_location_;
50 DISALLOW_COPY_AND_ASSIGN(MouseEventLocationDelegate);
53 } // namespace
55 typedef test::AshTestBase AshNativeCursorManagerTest;
57 TEST_F(AshNativeCursorManagerTest, LockCursor) {
58 ::wm::CursorManager* cursor_manager = Shell::GetInstance()->cursor_manager();
59 CursorManagerTestApi test_api(cursor_manager);
61 #if defined(OS_WIN)
62 ui::CursorLoaderWin::SetCursorResourceModule(L"ash_unittests.exe");
63 #endif
64 cursor_manager->SetCursor(ui::kCursorCopy);
65 EXPECT_EQ(ui::kCursorCopy, test_api.GetCurrentCursor().native_type());
66 UpdateDisplay("800x800*2/r");
67 EXPECT_EQ(2.0f, test_api.GetCurrentCursor().device_scale_factor());
68 EXPECT_EQ(ui::CURSOR_SET_NORMAL, test_api.GetCurrentCursorSet());
69 EXPECT_EQ(gfx::Display::ROTATE_90, test_api.GetCurrentCursorRotation());
70 EXPECT_TRUE(test_api.GetCurrentCursor().platform());
72 cursor_manager->LockCursor();
73 EXPECT_TRUE(cursor_manager->IsCursorLocked());
75 // Cursor type does not change while cursor is locked.
76 EXPECT_EQ(ui::CURSOR_SET_NORMAL, test_api.GetCurrentCursorSet());
77 cursor_manager->SetCursorSet(ui::CURSOR_SET_NORMAL);
78 EXPECT_EQ(ui::CURSOR_SET_NORMAL, test_api.GetCurrentCursorSet());
79 cursor_manager->SetCursorSet(ui::CURSOR_SET_LARGE);
80 EXPECT_EQ(ui::CURSOR_SET_LARGE, test_api.GetCurrentCursorSet());
81 cursor_manager->SetCursorSet(ui::CURSOR_SET_NORMAL);
82 EXPECT_EQ(ui::CURSOR_SET_NORMAL, test_api.GetCurrentCursorSet());
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 UpdateDisplay("800x800/u");
90 EXPECT_EQ(1.0f, test_api.GetCurrentCursor().device_scale_factor());
91 EXPECT_EQ(gfx::Display::ROTATE_180, test_api.GetCurrentCursorRotation());
93 cursor_manager->UnlockCursor();
94 EXPECT_FALSE(cursor_manager->IsCursorLocked());
96 // Cursor type changes to the one specified while cursor is locked.
97 EXPECT_EQ(ui::kCursorPointer, test_api.GetCurrentCursor().native_type());
98 EXPECT_EQ(1.0f, test_api.GetCurrentCursor().device_scale_factor());
99 EXPECT_TRUE(test_api.GetCurrentCursor().platform());
102 TEST_F(AshNativeCursorManagerTest, SetCursor) {
103 ::wm::CursorManager* cursor_manager = Shell::GetInstance()->cursor_manager();
104 CursorManagerTestApi test_api(cursor_manager);
105 #if defined(OS_WIN)
106 ui::CursorLoaderWin::SetCursorResourceModule(L"ash_unittests.exe");
107 #endif
108 cursor_manager->SetCursor(ui::kCursorCopy);
109 EXPECT_EQ(ui::kCursorCopy, test_api.GetCurrentCursor().native_type());
110 EXPECT_TRUE(test_api.GetCurrentCursor().platform());
111 cursor_manager->SetCursor(ui::kCursorPointer);
112 EXPECT_EQ(ui::kCursorPointer, test_api.GetCurrentCursor().native_type());
113 EXPECT_TRUE(test_api.GetCurrentCursor().platform());
116 TEST_F(AshNativeCursorManagerTest, SetCursorSet) {
117 ::wm::CursorManager* cursor_manager = Shell::GetInstance()->cursor_manager();
118 CursorManagerTestApi test_api(cursor_manager);
120 EXPECT_EQ(ui::CURSOR_SET_NORMAL, test_api.GetCurrentCursorSet());
122 cursor_manager->SetCursorSet(ui::CURSOR_SET_NORMAL);
123 EXPECT_EQ(ui::CURSOR_SET_NORMAL, test_api.GetCurrentCursorSet());
125 cursor_manager->SetCursorSet(ui::CURSOR_SET_LARGE);
126 EXPECT_EQ(ui::CURSOR_SET_LARGE, test_api.GetCurrentCursorSet());
128 cursor_manager->SetCursorSet(ui::CURSOR_SET_NORMAL);
129 EXPECT_EQ(ui::CURSOR_SET_NORMAL, test_api.GetCurrentCursorSet());
132 TEST_F(AshNativeCursorManagerTest, SetDeviceScaleFactorAndRotation) {
133 ::wm::CursorManager* cursor_manager = Shell::GetInstance()->cursor_manager();
134 CursorManagerTestApi test_api(cursor_manager);
135 UpdateDisplay("800x100*2");
136 EXPECT_EQ(2.0f, test_api.GetCurrentCursor().device_scale_factor());
137 EXPECT_EQ(gfx::Display::ROTATE_0, test_api.GetCurrentCursorRotation());
139 UpdateDisplay("800x100/l");
140 EXPECT_EQ(1.0f, test_api.GetCurrentCursor().device_scale_factor());
141 EXPECT_EQ(gfx::Display::ROTATE_270, test_api.GetCurrentCursorRotation());
144 TEST_F(AshNativeCursorManagerTest, UIScaleShouldNotChangeCursor) {
145 int64 display_id = Shell::GetScreen()->GetPrimaryDisplay().id();
146 gfx::Display::SetInternalDisplayId(display_id);
148 ::wm::CursorManager* cursor_manager = Shell::GetInstance()->cursor_manager();
149 CursorManagerTestApi test_api(cursor_manager);
150 DisplayManager* display_manager = Shell::GetInstance()->display_manager();
152 DisplayInfo::SetAllowUpgradeToHighDPI(false);
153 display_manager->SetDisplayUIScale(display_id, 0.5f);
154 EXPECT_EQ(1.0f,
155 Shell::GetScreen()->GetPrimaryDisplay().device_scale_factor());
156 EXPECT_EQ(1.0f, test_api.GetCurrentCursor().device_scale_factor());
158 display_manager->SetDisplayUIScale(display_id, 1.0f);
160 DisplayInfo::SetAllowUpgradeToHighDPI(true);
161 // 1x display should keep using 1x cursor even if the DSF is upgraded to 2x.
162 display_manager->SetDisplayUIScale(display_id, 0.5f);
163 EXPECT_EQ(2.0f,
164 Shell::GetScreen()->GetPrimaryDisplay().device_scale_factor());
165 EXPECT_EQ(1.0f, test_api.GetCurrentCursor().device_scale_factor());
167 // 2x display should keep using 2x cursor regardless of the UI scale.
168 UpdateDisplay("800x800*2");
169 EXPECT_EQ(2.0f,
170 Shell::GetScreen()->GetPrimaryDisplay().device_scale_factor());
171 EXPECT_EQ(2.0f, test_api.GetCurrentCursor().device_scale_factor());
172 display_manager->SetDisplayUIScale(display_id, 2.0f);
173 EXPECT_EQ(1.0f,
174 Shell::GetScreen()->GetPrimaryDisplay().device_scale_factor());
175 EXPECT_EQ(2.0f, test_api.GetCurrentCursor().device_scale_factor());
178 } // namespace test
179 } // namespace ash