OLD | NEW |
(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 cursor_window_controller_->SetCursorCompositingEnabled(true); |
| 31 } |
| 32 |
| 33 int GetCursorType() const { return cursor_window_controller_->cursor_type_; } |
| 34 |
| 35 const gfx::Point& GetCursorHotPoint() const { |
| 36 return cursor_window_controller_->hot_point_; |
| 37 } |
| 38 |
| 39 aura::Window* GetCursorWindow() const { |
| 40 return cursor_window_controller_->cursor_window_.get(); |
| 41 } |
| 42 |
| 43 int64 GetCursorDisplayId() const { |
| 44 return cursor_window_controller_->display_.id(); |
| 45 } |
| 46 |
| 47 private: |
| 48 // Not owned. |
| 49 CursorWindowController* cursor_window_controller_; |
| 50 |
| 51 DISALLOW_COPY_AND_ASSIGN(CursorWindowControllerTest); |
| 52 }; |
| 53 |
| 54 // Test that the composited cursor moves to another display when the real cursor |
| 55 // moves to another display. |
| 56 TEST_F(CursorWindowControllerTest, MoveToDifferentDisplay) { |
| 57 if (!SupportsMultipleDisplays()) |
| 58 return; |
| 59 |
| 60 UpdateDisplay("200x200,200x200*2/r"); |
| 61 |
| 62 DisplayController* display_controller = |
| 63 Shell::GetInstance()->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 |
OLD | NEW |