Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(548)

Side by Side Diff: ash/display/cursor_window_controller_unittest.cc

Issue 1137303004: Always update cursor visibility (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 // Make sure that composition cursor inherits the visibility state.
113 TEST_F(CursorWindowControllerTest, VisibilityTest) {
114 ASSERT_TRUE(GetCursorWindow());
115 EXPECT_TRUE(GetCursorWindow()->IsVisible());
116 aura::client::CursorClient* client = Shell::GetInstance()->cursor_manager();
117 client->HideCursor();
118 ASSERT_TRUE(GetCursorWindow());
119 EXPECT_FALSE(GetCursorWindow()->IsVisible());
120
121 // Normal cursor should be in the correct state.
122 SetCursorCompositionEnabled(false);
123 ASSERT_FALSE(GetCursorWindow());
124 ASSERT_FALSE(client->IsCursorVisible());
125
126 // Cursor was hidden.
127 SetCursorCompositionEnabled(true);
128 ASSERT_TRUE(GetCursorWindow());
129 EXPECT_FALSE(GetCursorWindow()->IsVisible());
130
131 // Goback to normal cursor and show the cursor.
132 SetCursorCompositionEnabled(false);
133 ASSERT_FALSE(GetCursorWindow());
134 ASSERT_FALSE(client->IsCursorVisible());
135 client->ShowCursor();
136 ASSERT_TRUE(client->IsCursorVisible());
137
138 // Cursor was shown.
139 SetCursorCompositionEnabled(true);
140 ASSERT_TRUE(GetCursorWindow());
141 EXPECT_TRUE(GetCursorWindow()->IsVisible());
142 }
143
108 } // namespace ash 144 } // namespace ash
OLDNEW
« ash/display/cursor_window_controller.cc ('K') | « ash/display/cursor_window_controller.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698