Switch global error menu icon to vectorized MD asset
[chromium-blink-merge.git] / ash / display / cursor_window_controller_unittest.cc
blobd1f94458d569da8a9bcb5ffa8f8fde114b409c41
1 // Copyright 2015 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/display/cursor_window_controller.h"
7 #include "ash/display/display_util.h"
8 #include "ash/display/window_tree_host_manager.h"
9 #include "ash/screen_util.h"
10 #include "ash/shell.h"
11 #include "ash/test/ash_test_base.h"
12 #include "ash/test/display_manager_test_api.h"
13 #include "ui/aura/window.h"
14 #include "ui/aura/window_tree_host.h"
15 #include "ui/base/cursor/cursor.h"
16 #include "ui/events/test/event_generator.h"
17 #include "ui/gfx/display.h"
18 #include "ui/wm/core/coordinate_conversion.h"
20 namespace ash {
22 class CursorWindowControllerTest : public test::AshTestBase {
23 public:
24 CursorWindowControllerTest() {}
25 ~CursorWindowControllerTest() override {}
27 // test::AshTestBase:
28 void SetUp() override {
29 AshTestBase::SetUp();
30 SetCursorCompositionEnabled(true);
33 int GetCursorType() const { return cursor_window_controller_->cursor_type_; }
35 const gfx::Point& GetCursorHotPoint() const {
36 return cursor_window_controller_->hot_point_;
39 aura::Window* GetCursorWindow() const {
40 return cursor_window_controller_->cursor_window_.get();
43 const gfx::ImageSkia& GetCursorImage() const {
44 return cursor_window_controller_->GetCursorImageForTest();
47 int64 GetCursorDisplayId() const {
48 return cursor_window_controller_->display_.id();
51 void SetCursorCompositionEnabled(bool enabled) {
52 cursor_window_controller_ = Shell::GetInstance()
53 ->window_tree_host_manager()
54 ->cursor_window_controller();
55 cursor_window_controller_->SetCursorCompositingEnabled(enabled);
58 private:
59 // Not owned.
60 CursorWindowController* cursor_window_controller_;
62 DISALLOW_COPY_AND_ASSIGN(CursorWindowControllerTest);
65 // Test that the composited cursor moves to another display when the real cursor
66 // moves to another display.
67 TEST_F(CursorWindowControllerTest, MoveToDifferentDisplay) {
68 if (!SupportsMultipleDisplays())
69 return;
71 UpdateDisplay("200x200,200x200*2/r");
73 WindowTreeHostManager* window_tree_host_manager =
74 Shell::GetInstance()->window_tree_host_manager();
75 int64 primary_display_id = window_tree_host_manager->GetPrimaryDisplayId();
76 int64 secondary_display_id = ScreenUtil::GetSecondaryDisplay().id();
77 aura::Window* primary_root =
78 window_tree_host_manager->GetRootWindowForDisplayId(primary_display_id);
79 aura::Window* secondary_root =
80 window_tree_host_manager->GetRootWindowForDisplayId(secondary_display_id);
82 ui::test::EventGenerator primary_generator(primary_root);
83 primary_generator.MoveMouseToInHost(20, 50);
85 EXPECT_TRUE(primary_root->Contains(GetCursorWindow()));
86 EXPECT_EQ(primary_display_id, GetCursorDisplayId());
87 EXPECT_EQ(ui::kCursorNull, GetCursorType());
88 gfx::Point hot_point = GetCursorHotPoint();
89 EXPECT_EQ("4,4", hot_point.ToString());
90 gfx::Rect cursor_bounds = GetCursorWindow()->GetBoundsInScreen();
91 EXPECT_EQ(20, cursor_bounds.x() + hot_point.x());
92 EXPECT_EQ(50, cursor_bounds.y() + hot_point.y());
94 // The cursor can only be moved between displays via
95 // WindowTreeHost::MoveCursorTo(). EventGenerator uses a hack to move the
96 // cursor between displays.
97 // Screen location: 220, 50
98 // Root location: 20, 50
99 secondary_root->MoveCursorTo(gfx::Point(20, 50));
101 // Chrome relies on WindowTreeHost::MoveCursorTo() dispatching a mouse move
102 // asynchronously. This is implemented in a platform specific way. Generate a
103 // fake mouse move instead of waiting.
104 gfx::Point new_cursor_position_in_host(20, 50);
105 secondary_root->GetHost()->ConvertPointToHost(&new_cursor_position_in_host);
106 ui::test::EventGenerator secondary_generator(secondary_root);
107 secondary_generator.MoveMouseToInHost(new_cursor_position_in_host);
109 EXPECT_TRUE(secondary_root->Contains(GetCursorWindow()));
110 EXPECT_EQ(secondary_display_id, GetCursorDisplayId());
111 EXPECT_EQ(ui::kCursorNull, GetCursorType());
112 hot_point = GetCursorHotPoint();
113 EXPECT_EQ("3,3", hot_point.ToString());
114 cursor_bounds = GetCursorWindow()->GetBoundsInScreen();
115 EXPECT_EQ(220, cursor_bounds.x() + hot_point.x());
116 EXPECT_EQ(50, cursor_bounds.y() + hot_point.y());
119 // Windows doesn't support compositor based cursor.
120 #if !defined(OS_WIN)
121 // Make sure that composition cursor inherits the visibility state.
122 TEST_F(CursorWindowControllerTest, VisibilityTest) {
123 ASSERT_TRUE(GetCursorWindow());
124 EXPECT_TRUE(GetCursorWindow()->IsVisible());
125 aura::client::CursorClient* client = Shell::GetInstance()->cursor_manager();
126 client->HideCursor();
127 ASSERT_TRUE(GetCursorWindow());
128 EXPECT_FALSE(GetCursorWindow()->IsVisible());
130 // Normal cursor should be in the correct state.
131 SetCursorCompositionEnabled(false);
132 ASSERT_FALSE(GetCursorWindow());
133 ASSERT_FALSE(client->IsCursorVisible());
135 // Cursor was hidden.
136 SetCursorCompositionEnabled(true);
137 ASSERT_TRUE(GetCursorWindow());
138 EXPECT_FALSE(GetCursorWindow()->IsVisible());
140 // Goback to normal cursor and show the cursor.
141 SetCursorCompositionEnabled(false);
142 ASSERT_FALSE(GetCursorWindow());
143 ASSERT_FALSE(client->IsCursorVisible());
144 client->ShowCursor();
145 ASSERT_TRUE(client->IsCursorVisible());
147 // Cursor was shown.
148 SetCursorCompositionEnabled(true);
149 ASSERT_TRUE(GetCursorWindow());
150 EXPECT_TRUE(GetCursorWindow()->IsVisible());
153 // Make sure that composition cursor stays big even when
154 // the DSF becomes 1x as a result of zooming out.
155 TEST_F(CursorWindowControllerTest, DSF) {
156 UpdateDisplay("1000x500*2");
157 int64 primary_id = Shell::GetScreen()->GetPrimaryDisplay().id();
159 test::ScopedSetInternalDisplayId set_internal(primary_id);
160 SetCursorCompositionEnabled(true);
161 ASSERT_EQ(2.0f,
162 Shell::GetScreen()->GetPrimaryDisplay().device_scale_factor());
163 EXPECT_TRUE(GetCursorImage().HasRepresentation(2.0f));
165 ASSERT_TRUE(SetDisplayUIScale(primary_id, 2.0f));
166 ASSERT_EQ(1.0f,
167 Shell::GetScreen()->GetPrimaryDisplay().device_scale_factor());
168 EXPECT_TRUE(GetCursorImage().HasRepresentation(2.0f));
170 #endif
172 } // namespace ash