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

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

Issue 948583005: Add more tests for mouse rotation,scale&position after display change (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 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
(Empty)
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.
4
5 #include "ash/display/cursor_window_controller.h"
6
7 #include "ash/display/display_controller.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"
17
18 namespace ash {
19
20 class CursorWindowControllerTest : public test::AshTestBase {
21 public:
22 CursorWindowControllerTest() {}
23 ~CursorWindowControllerTest() override {}
24
25 // test::AshTestBase:
26 void SetUp() override {
27 AshTestBase::SetUp();
28 cursor_window_controller_ =
29 Shell::GetInstance()->display_controller()->cursor_window_controller();
30 }
31
32 int GetCursorType() const { return cursor_window_controller_->cursor_type_; }
33
34 const gfx::Point& GetCursorHotPoint() const {
35 return cursor_window_controller_->hot_point_;
36 }
37
38 aura::Window* GetCursorWindow() const {
39 return cursor_window_controller_->cursor_window_.get();
40 }
41
42 int64 GetCursorDisplayId() const {
43 return cursor_window_controller_->display_.id();
44 }
45
46 private:
47 // Not owned.
48 CursorWindowController* cursor_window_controller_;
49
50 DISALLOW_COPY_AND_ASSIGN(CursorWindowControllerTest);
51 };
52
53 // Test that the composited cursor moves to another display when the real cursor
54 // moves to another display.
55 TEST_F(CursorWindowControllerTest, MoveToDifferentDisplay) {
56 if (!SupportsMultipleDisplays())
57 return;
58
59 UpdateDisplay("200x200,200x200*2/r");
60
61 Shell* shell = Shell::GetInstance();
62 shell->SetCursorCompositingEnabled(true);
63 DisplayController* display_controller = shell->display_controller();
64 int64 primary_display_id = display_controller->GetPrimaryDisplayId();
65 int64 secondary_display_id = ScreenUtil::GetSecondaryDisplay().id();
66 aura::Window* primary_root =
67 display_controller->GetRootWindowForDisplayId(primary_display_id);
68 aura::Window* secondary_root =
69 display_controller->GetRootWindowForDisplayId(secondary_display_id);
70
71 ui::test::EventGenerator primary_generator(primary_root);
72 primary_generator.MoveMouseToInHost(20, 50);
73
74 EXPECT_TRUE(primary_root->Contains(GetCursorWindow()));
75 EXPECT_EQ(primary_display_id, GetCursorDisplayId());
76 EXPECT_EQ(ui::kCursorNull, GetCursorType());
77 gfx::Point hot_point = GetCursorHotPoint();
78 EXPECT_EQ("4,4", hot_point.ToString());
79 gfx::Rect cursor_bounds = GetCursorWindow()->GetBoundsInScreen();
80 EXPECT_EQ(20, cursor_bounds.x() + hot_point.x());
81 EXPECT_EQ(50, cursor_bounds.y() + hot_point.y());
82
83 // The cursor can only be moved between displays via
84 // WindowTreeHost::MoveCursorTo(). EventGenerator uses a hack to move the
85 // cursor between displays.
86 // Screen location: 220, 50
87 // Root location: 20, 50
88 secondary_root->MoveCursorTo(gfx::Point(20, 50));
89
90 // Chrome relies on WindowTreeHost::MoveCursorTo() dispatching a mouse move
91 // asynchronously. This is implemented in a platform specific way. Generate a
92 // fake mouse move instead of waiting.
93 gfx::Point new_cursor_position_in_host(20, 50);
94 secondary_root->GetHost()->ConvertPointToHost(&new_cursor_position_in_host);
95 ui::test::EventGenerator secondary_generator(secondary_root);
96 secondary_generator.MoveMouseToInHost(new_cursor_position_in_host);
97
98 EXPECT_TRUE(secondary_root->Contains(GetCursorWindow()));
99 EXPECT_EQ(secondary_display_id, GetCursorDisplayId());
100 EXPECT_EQ(ui::kCursorNull, GetCursorType());
101 hot_point = GetCursorHotPoint();
102 EXPECT_EQ("8,9", hot_point.ToString());
103 cursor_bounds = GetCursorWindow()->GetBoundsInScreen();
104 EXPECT_EQ(220, cursor_bounds.x() + hot_point.x());
105 EXPECT_EQ(50, cursor_bounds.y() + hot_point.y());
106 }
107
108 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698