OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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/display/cursor_window_controller.h" | 5 #include "ash/display/cursor_window_controller.h" |
6 | 6 |
7 #include "ash/display/display_controller.h" | 7 #include "ash/display/display_controller.h" |
8 #include "ash/screen_util.h" | 8 #include "ash/screen_util.h" |
9 #include "ash/shell.h" | 9 #include "ash/shell.h" |
10 #include "ash/test/ash_test_base.h" | 10 #include "ash/test/ash_test_base.h" |
11 #include "ui/aura/window.h" | 11 #include "ui/aura/window.h" |
12 #include "ui/aura/window_tree_host.h" | 12 #include "ui/aura/window_tree_host.h" |
13 #include "ui/base/cursor/cursor.h" | 13 #include "ui/base/cursor/cursor.h" |
14 #include "ui/events/test/event_generator.h" | 14 #include "ui/events/test/event_generator.h" |
15 #include "ui/gfx/display.h" | 15 #include "ui/gfx/display.h" |
16 #include "ui/wm/core/coordinate_conversion.h" | 16 #include "ui/wm/core/coordinate_conversion.h" |
17 | 17 |
18 namespace ash { | 18 namespace ash { |
19 | 19 |
20 class CursorWindowControllerTest : public test::AshTestBase { | 20 class CursorWindowControllerTest : public test::AshTestBase { |
21 public: | 21 public: |
22 CursorWindowControllerTest() {} | 22 CursorWindowControllerTest() {} |
23 ~CursorWindowControllerTest() override {} | 23 ~CursorWindowControllerTest() override {} |
24 | 24 |
25 // test::AshTestBase: | 25 // test::AshTestBase: |
26 void SetUp() override { | 26 void SetUp() override { |
27 AshTestBase::SetUp(); | 27 AshTestBase::SetUp(); |
28 cursor_window_controller_ = | 28 SetCursorCompositionEnabled(true); |
29 Shell::GetInstance()->display_controller()->cursor_window_controller(); | |
30 cursor_window_controller_->SetCursorCompositingEnabled(true); | |
31 } | 29 } |
32 | 30 |
33 int GetCursorType() const { return cursor_window_controller_->cursor_type_; } | 31 int GetCursorType() const { return cursor_window_controller_->cursor_type_; } |
34 | 32 |
35 const gfx::Point& GetCursorHotPoint() const { | 33 const gfx::Point& GetCursorHotPoint() const { |
36 return cursor_window_controller_->hot_point_; | 34 return cursor_window_controller_->hot_point_; |
37 } | 35 } |
38 | 36 |
39 aura::Window* GetCursorWindow() const { | 37 aura::Window* GetCursorWindow() const { |
40 return cursor_window_controller_->cursor_window_.get(); | 38 return cursor_window_controller_->cursor_window_.get(); |
41 } | 39 } |
42 | 40 |
43 int64 GetCursorDisplayId() const { | 41 int64 GetCursorDisplayId() const { |
44 return cursor_window_controller_->display_.id(); | 42 return cursor_window_controller_->display_.id(); |
45 } | 43 } |
46 | 44 |
| 45 void SetCursorCompositionEnabled(bool enabled) { |
| 46 cursor_window_controller_ = |
| 47 Shell::GetInstance()->display_controller()->cursor_window_controller(); |
| 48 cursor_window_controller_->SetCursorCompositingEnabled(enabled); |
| 49 } |
| 50 |
47 private: | 51 private: |
48 // Not owned. | 52 // Not owned. |
49 CursorWindowController* cursor_window_controller_; | 53 CursorWindowController* cursor_window_controller_; |
50 | 54 |
51 DISALLOW_COPY_AND_ASSIGN(CursorWindowControllerTest); | 55 DISALLOW_COPY_AND_ASSIGN(CursorWindowControllerTest); |
52 }; | 56 }; |
53 | 57 |
54 // Test that the composited cursor moves to another display when the real cursor | 58 // Test that the composited cursor moves to another display when the real cursor |
55 // moves to another display. | 59 // moves to another display. |
56 TEST_F(CursorWindowControllerTest, MoveToDifferentDisplay) { | 60 TEST_F(CursorWindowControllerTest, MoveToDifferentDisplay) { |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 EXPECT_TRUE(secondary_root->Contains(GetCursorWindow())); | 102 EXPECT_TRUE(secondary_root->Contains(GetCursorWindow())); |
99 EXPECT_EQ(secondary_display_id, GetCursorDisplayId()); | 103 EXPECT_EQ(secondary_display_id, GetCursorDisplayId()); |
100 EXPECT_EQ(ui::kCursorNull, GetCursorType()); | 104 EXPECT_EQ(ui::kCursorNull, GetCursorType()); |
101 hot_point = GetCursorHotPoint(); | 105 hot_point = GetCursorHotPoint(); |
102 EXPECT_EQ("8,9", hot_point.ToString()); | 106 EXPECT_EQ("8,9", hot_point.ToString()); |
103 cursor_bounds = GetCursorWindow()->GetBoundsInScreen(); | 107 cursor_bounds = GetCursorWindow()->GetBoundsInScreen(); |
104 EXPECT_EQ(220, cursor_bounds.x() + hot_point.x()); | 108 EXPECT_EQ(220, cursor_bounds.x() + hot_point.x()); |
105 EXPECT_EQ(50, cursor_bounds.y() + hot_point.y()); | 109 EXPECT_EQ(50, cursor_bounds.y() + hot_point.y()); |
106 } | 110 } |
107 | 111 |
| 112 // Windows doesn't support compositor based cursor. |
| 113 #if !defined(OS_WIN) |
| 114 // Make sure that composition cursor inherits the visibility state. |
| 115 TEST_F(CursorWindowControllerTest, VisibilityTest) { |
| 116 ASSERT_TRUE(GetCursorWindow()); |
| 117 EXPECT_TRUE(GetCursorWindow()->IsVisible()); |
| 118 aura::client::CursorClient* client = Shell::GetInstance()->cursor_manager(); |
| 119 client->HideCursor(); |
| 120 ASSERT_TRUE(GetCursorWindow()); |
| 121 EXPECT_FALSE(GetCursorWindow()->IsVisible()); |
| 122 |
| 123 // Normal cursor should be in the correct state. |
| 124 SetCursorCompositionEnabled(false); |
| 125 ASSERT_FALSE(GetCursorWindow()); |
| 126 ASSERT_FALSE(client->IsCursorVisible()); |
| 127 |
| 128 // Cursor was hidden. |
| 129 SetCursorCompositionEnabled(true); |
| 130 ASSERT_TRUE(GetCursorWindow()); |
| 131 EXPECT_FALSE(GetCursorWindow()->IsVisible()); |
| 132 |
| 133 // Goback to normal cursor and show the cursor. |
| 134 SetCursorCompositionEnabled(false); |
| 135 ASSERT_FALSE(GetCursorWindow()); |
| 136 ASSERT_FALSE(client->IsCursorVisible()); |
| 137 client->ShowCursor(); |
| 138 ASSERT_TRUE(client->IsCursorVisible()); |
| 139 |
| 140 // Cursor was shown. |
| 141 SetCursorCompositionEnabled(true); |
| 142 ASSERT_TRUE(GetCursorWindow()); |
| 143 EXPECT_TRUE(GetCursorWindow()->IsVisible()); |
| 144 } |
| 145 #endif |
| 146 |
108 } // namespace ash | 147 } // namespace ash |
OLD | NEW |