Allow only one bookmark to be added for multiple fast starring
[chromium-blink-merge.git] / ash / display / cursor_window_controller_unittest.cc
blobd822bce5611565e98ef34129d2d833cfcbb51b42
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/window_tree_host_manager.h"
8 #include "ash/screen_util.h"
9 #include "ash/shell.h"
10 #include "ash/test/ash_test_base.h"
11 #include "ui/aura/window.h"
12 #include "ui/aura/window_tree_host.h"
13 #include "ui/base/cursor/cursor.h"
14 #include "ui/events/test/event_generator.h"
15 #include "ui/gfx/display.h"
16 #include "ui/wm/core/coordinate_conversion.h"
18 namespace ash {
20 class CursorWindowControllerTest : public test::AshTestBase {
21 public:
22 CursorWindowControllerTest() {}
23 ~CursorWindowControllerTest() override {}
25 // test::AshTestBase:
26 void SetUp() override {
27 AshTestBase::SetUp();
28 SetCursorCompositionEnabled(true);
31 int GetCursorType() const { return cursor_window_controller_->cursor_type_; }
33 const gfx::Point& GetCursorHotPoint() const {
34 return cursor_window_controller_->hot_point_;
37 aura::Window* GetCursorWindow() const {
38 return cursor_window_controller_->cursor_window_.get();
41 int64 GetCursorDisplayId() const {
42 return cursor_window_controller_->display_.id();
45 void SetCursorCompositionEnabled(bool enabled) {
46 cursor_window_controller_ = Shell::GetInstance()
47 ->window_tree_host_manager()
48 ->cursor_window_controller();
49 cursor_window_controller_->SetCursorCompositingEnabled(enabled);
52 private:
53 // Not owned.
54 CursorWindowController* cursor_window_controller_;
56 DISALLOW_COPY_AND_ASSIGN(CursorWindowControllerTest);
59 // Test that the composited cursor moves to another display when the real cursor
60 // moves to another display.
61 TEST_F(CursorWindowControllerTest, MoveToDifferentDisplay) {
62 if (!SupportsMultipleDisplays())
63 return;
65 UpdateDisplay("200x200,200x200*2/r");
67 WindowTreeHostManager* window_tree_host_manager =
68 Shell::GetInstance()->window_tree_host_manager();
69 int64 primary_display_id = window_tree_host_manager->GetPrimaryDisplayId();
70 int64 secondary_display_id = ScreenUtil::GetSecondaryDisplay().id();
71 aura::Window* primary_root =
72 window_tree_host_manager->GetRootWindowForDisplayId(primary_display_id);
73 aura::Window* secondary_root =
74 window_tree_host_manager->GetRootWindowForDisplayId(secondary_display_id);
76 ui::test::EventGenerator primary_generator(primary_root);
77 primary_generator.MoveMouseToInHost(20, 50);
79 EXPECT_TRUE(primary_root->Contains(GetCursorWindow()));
80 EXPECT_EQ(primary_display_id, GetCursorDisplayId());
81 EXPECT_EQ(ui::kCursorNull, GetCursorType());
82 gfx::Point hot_point = GetCursorHotPoint();
83 EXPECT_EQ("4,4", hot_point.ToString());
84 gfx::Rect cursor_bounds = GetCursorWindow()->GetBoundsInScreen();
85 EXPECT_EQ(20, cursor_bounds.x() + hot_point.x());
86 EXPECT_EQ(50, cursor_bounds.y() + hot_point.y());
88 // The cursor can only be moved between displays via
89 // WindowTreeHost::MoveCursorTo(). EventGenerator uses a hack to move the
90 // cursor between displays.
91 // Screen location: 220, 50
92 // Root location: 20, 50
93 secondary_root->MoveCursorTo(gfx::Point(20, 50));
95 // Chrome relies on WindowTreeHost::MoveCursorTo() dispatching a mouse move
96 // asynchronously. This is implemented in a platform specific way. Generate a
97 // fake mouse move instead of waiting.
98 gfx::Point new_cursor_position_in_host(20, 50);
99 secondary_root->GetHost()->ConvertPointToHost(&new_cursor_position_in_host);
100 ui::test::EventGenerator secondary_generator(secondary_root);
101 secondary_generator.MoveMouseToInHost(new_cursor_position_in_host);
103 EXPECT_TRUE(secondary_root->Contains(GetCursorWindow()));
104 EXPECT_EQ(secondary_display_id, GetCursorDisplayId());
105 EXPECT_EQ(ui::kCursorNull, GetCursorType());
106 hot_point = GetCursorHotPoint();
107 EXPECT_EQ("7,7", hot_point.ToString());
108 cursor_bounds = GetCursorWindow()->GetBoundsInScreen();
109 EXPECT_EQ(220, cursor_bounds.x() + hot_point.x());
110 EXPECT_EQ(50, cursor_bounds.y() + hot_point.y());
113 // Windows doesn't support compositor based cursor.
114 #if !defined(OS_WIN)
115 // Make sure that composition cursor inherits the visibility state.
116 TEST_F(CursorWindowControllerTest, VisibilityTest) {
117 ASSERT_TRUE(GetCursorWindow());
118 EXPECT_TRUE(GetCursorWindow()->IsVisible());
119 aura::client::CursorClient* client = Shell::GetInstance()->cursor_manager();
120 client->HideCursor();
121 ASSERT_TRUE(GetCursorWindow());
122 EXPECT_FALSE(GetCursorWindow()->IsVisible());
124 // Normal cursor should be in the correct state.
125 SetCursorCompositionEnabled(false);
126 ASSERT_FALSE(GetCursorWindow());
127 ASSERT_FALSE(client->IsCursorVisible());
129 // Cursor was hidden.
130 SetCursorCompositionEnabled(true);
131 ASSERT_TRUE(GetCursorWindow());
132 EXPECT_FALSE(GetCursorWindow()->IsVisible());
134 // Goback to normal cursor and show the cursor.
135 SetCursorCompositionEnabled(false);
136 ASSERT_FALSE(GetCursorWindow());
137 ASSERT_FALSE(client->IsCursorVisible());
138 client->ShowCursor();
139 ASSERT_TRUE(client->IsCursorVisible());
141 // Cursor was shown.
142 SetCursorCompositionEnabled(true);
143 ASSERT_TRUE(GetCursorWindow());
144 EXPECT_TRUE(GetCursorWindow()->IsVisible());
146 #endif
148 } // namespace ash