| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/mirror_window_controller.h" | 5 #include "ash/display/mirror_window_controller.h" |
| 6 | 6 |
| 7 #include "ash/display/display_manager.h" | 7 #include "ash/display/display_manager.h" |
| 8 #include "ash/shell.h" | 8 #include "ash/shell.h" |
| 9 #include "ash/test/ash_test_base.h" | 9 #include "ash/test/ash_test_base.h" |
| 10 #include "ash/test/mirror_window_test_api.h" | 10 #include "ash/test/mirror_window_test_api.h" |
| 11 #include "ui/aura/root_window.h" | 11 #include "ui/aura/root_window.h" |
| 12 #include "ui/aura/test/event_generator.h" | 12 #include "ui/aura/test/event_generator.h" |
| 13 #include "ui/aura/test/test_window_delegate.h" | 13 #include "ui/aura/test/test_window_delegate.h" |
| 14 #include "ui/aura/test/test_windows.h" | 14 #include "ui/aura/test/test_windows.h" |
| 15 #include "ui/aura/window.h" | 15 #include "ui/aura/window.h" |
| 16 #include "ui/base/hit_test.h" | 16 #include "ui/base/hit_test.h" |
| 17 | 17 |
| 18 namespace ash { | 18 namespace ash { |
| 19 namespace internal { | 19 namespace internal { |
| 20 | 20 |
| 21 typedef test::AshTestBase MirrorWindowControllerTest; | 21 typedef test::AshTestBase MirrorWindowControllerTest; |
| 22 | 22 |
| 23 #if defined(OS_WIN) | 23 #if defined(OS_WIN) |
| 24 // Software mirroring does not work on win. | 24 // Software mirroring does not work on win. |
| 25 #define MAYBE_MirrorCursor DISABLED_MirrorCursor | 25 #define MAYBE_MirrorCursorBasic DISABLED_MirrorCursorBasic |
| 26 #define MAYBE_MirrorCursorWithDSF DISABLED_MirrorCursorBasicWithSDF |
| 27 #define MAYBE_MirrorCursorWithUIScale DISABLED_MirrorCursorBasicWithUISCale |
| 28 #define MAYBE_MirrorCursorWithRotate DISABLED_MirrorCursorBasicWithRotate |
| 26 #else | 29 #else |
| 27 #define MAYBE_MirrorCursor MirrorCursor | 30 #define MAYBE_MirrorCursorBasic MirrorCursorBasic |
| 31 #define MAYBE_MirrorCursorWithDSF MirrorCursorBasicWithSDF |
| 32 #define MAYBE_MirrorCursorWithUIScale MirrorCursorBasicWithUISCale |
| 33 #define MAYBE_MirrorCursorWithRotate MirrorCursorBasicWithRotate |
| 28 #endif | 34 #endif |
| 29 | 35 |
| 30 TEST_F(MirrorWindowControllerTest, MAYBE_MirrorCursor) { | 36 TEST_F(MirrorWindowControllerTest, MAYBE_MirrorCursorBasic) { |
| 31 test::MirrorWindowTestApi test_api; | 37 test::MirrorWindowTestApi test_api; |
| 32 aura::test::TestWindowDelegate test_window_delegate; | 38 aura::test::TestWindowDelegate test_window_delegate; |
| 33 test_window_delegate.set_window_component(HTTOP); | 39 test_window_delegate.set_window_component(HTTOP); |
| 34 | 40 |
| 35 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); | 41 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); |
| 36 display_manager->SetSoftwareMirroring(true); | 42 display_manager->SetSoftwareMirroring(true); |
| 37 UpdateDisplay("400x400,400x400"); | 43 UpdateDisplay("400x400,400x400"); |
| 38 aura::RootWindow* root = Shell::GetInstance()->GetPrimaryRootWindow(); | 44 aura::RootWindow* root = Shell::GetInstance()->GetPrimaryRootWindow(); |
| 39 scoped_ptr<aura::Window> window(aura::test::CreateTestWindowWithDelegate( | 45 scoped_ptr<aura::Window> window(aura::test::CreateTestWindowWithDelegate( |
| 40 &test_window_delegate, | 46 &test_window_delegate, |
| 41 0, | 47 0, |
| 42 gfx::Rect(50, 50, 100, 100), | 48 gfx::Rect(50, 50, 100, 100), |
| 43 root)); | 49 root)); |
| 44 window->Show(); | 50 window->Show(); |
| 45 window->SetName("foo"); | 51 window->SetName("foo"); |
| 46 | 52 |
| 47 EXPECT_TRUE(test_api.GetCursorWindow()); | 53 EXPECT_TRUE(test_api.GetCursorWindow()); |
| 48 EXPECT_EQ("50,50 100x100", window->bounds().ToString()); | 54 EXPECT_EQ("50,50 100x100", window->bounds().ToString()); |
| 49 | 55 |
| 50 aura::test::EventGenerator generator(root); | 56 aura::test::EventGenerator generator(root); |
| 51 generator.MoveMouseTo(10, 10); | 57 generator.MoveMouseTo(10, 10); |
| 52 | 58 |
| 53 // Test if cursor movement is propertly reflected in mirror window. | 59 // Test if cursor movement is propertly reflected in mirror window. |
| 54 gfx::Point hot_point = test_api.GetCursorHotPoint(); | 60 gfx::Point hot_point = test_api.GetCursorHotPoint(); |
| 55 gfx::Point cursor_window_origin = | 61 gfx::Point cursor_window_origin = |
| 56 test_api.GetCursorWindow()->bounds().origin(); | 62 test_api.GetCursorWindow()->bounds().origin(); |
| 63 EXPECT_EQ("4,4", hot_point.ToString()); |
| 57 EXPECT_EQ(10 - hot_point.x(), cursor_window_origin.x()); | 64 EXPECT_EQ(10 - hot_point.x(), cursor_window_origin.x()); |
| 58 EXPECT_EQ(10 - hot_point.y(), cursor_window_origin.y()); | 65 EXPECT_EQ(10 - hot_point.y(), cursor_window_origin.y()); |
| 59 EXPECT_EQ(ui::kCursorNull, test_api.GetCurrentCursorType()); | 66 EXPECT_EQ(ui::kCursorNull, test_api.GetCurrentCursorType()); |
| 60 EXPECT_TRUE(test_api.GetCursorWindow()->IsVisible()); | 67 EXPECT_TRUE(test_api.GetCursorWindow()->IsVisible()); |
| 61 | 68 |
| 62 // Test if cursor type change is propertly reflected in mirror window. | 69 // Test if cursor type change is propertly reflected in mirror window. |
| 63 generator.MoveMouseTo(100, 100); | 70 generator.MoveMouseTo(100, 100); |
| 64 hot_point = test_api.GetCursorHotPoint(); | 71 hot_point = test_api.GetCursorHotPoint(); |
| 65 cursor_window_origin = test_api.GetCursorWindow()->bounds().origin(); | 72 cursor_window_origin = test_api.GetCursorWindow()->bounds().origin(); |
| 66 EXPECT_EQ(100 - hot_point.x(), cursor_window_origin.x()); | 73 EXPECT_EQ(100 - hot_point.x(), cursor_window_origin.x()); |
| 67 EXPECT_EQ(100 - hot_point.y(), cursor_window_origin.y()); | 74 EXPECT_EQ(100 - hot_point.y(), cursor_window_origin.y()); |
| 68 EXPECT_EQ(ui::kCursorNorthResize, test_api.GetCurrentCursorType()); | 75 EXPECT_EQ(ui::kCursorNorthResize, test_api.GetCurrentCursorType()); |
| 69 | 76 |
| 70 // Test if visibility change is propertly reflected in mirror window. | 77 // Test if visibility change is propertly reflected in mirror window. |
| 71 // A key event hides cursor. | 78 // A key event hides cursor. |
| 72 generator.PressKey(ui::VKEY_A, 0); | 79 generator.PressKey(ui::VKEY_A, 0); |
| 73 generator.ReleaseKey(ui::VKEY_A, 0); | 80 generator.ReleaseKey(ui::VKEY_A, 0); |
| 74 EXPECT_FALSE(test_api.GetCursorWindow()->IsVisible()); | 81 EXPECT_FALSE(test_api.GetCursorWindow()->IsVisible()); |
| 75 | 82 |
| 76 // Mouse event makes it visible again. | 83 // Mouse event makes it visible again. |
| 77 generator.MoveMouseTo(300, 300); | 84 generator.MoveMouseTo(300, 300); |
| 78 hot_point = test_api.GetCursorHotPoint(); | 85 hot_point = test_api.GetCursorHotPoint(); |
| 79 cursor_window_origin = test_api.GetCursorWindow()->bounds().origin(); | 86 cursor_window_origin = test_api.GetCursorWindow()->bounds().origin(); |
| 80 EXPECT_EQ(300 - hot_point.x(), cursor_window_origin.x()); | 87 EXPECT_EQ(300 - hot_point.x(), cursor_window_origin.x()); |
| 81 EXPECT_EQ(300 - hot_point.y(), cursor_window_origin.y()); | 88 EXPECT_EQ(300 - hot_point.y(), cursor_window_origin.y()); |
| 82 EXPECT_EQ(ui::kCursorNull, test_api.GetCurrentCursorType()); | 89 EXPECT_EQ(ui::kCursorNull, test_api.GetCurrentCursorType()); |
| 83 EXPECT_TRUE(test_api.GetCursorWindow()->IsVisible()); | 90 EXPECT_TRUE(test_api.GetCursorWindow()->IsVisible()); |
| 84 } | 91 } |
| 85 | 92 |
| 93 // Make sure that the mirror cursor's location is same as |
| 94 // the source display's host location in the mirror root window's |
| 95 // coordinates. |
| 96 TEST_F(MirrorWindowControllerTest, MAYBE_MirrorCursorLocations) { |
| 97 test::MirrorWindowTestApi test_api; |
| 98 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); |
| 99 display_manager->SetSoftwareMirroring(true); |
| 100 |
| 101 // Test with device scale factor. |
| 102 UpdateDisplay("400x600*2,400x600"); |
| 103 |
| 104 aura::RootWindow* root = Shell::GetInstance()->GetPrimaryRootWindow(); |
| 105 aura::test::EventGenerator generator(root); |
| 106 generator.MoveMouseToInHost(10, 20); |
| 107 |
| 108 gfx::Point hot_point = test_api.GetCursorHotPoint(); |
| 109 EXPECT_EQ("8,9", hot_point.ToString()); |
| 110 gfx::Point cursor_window_origin = |
| 111 test_api.GetCursorWindow()->bounds().origin(); |
| 112 EXPECT_EQ(10 - hot_point.x(), cursor_window_origin.x()); |
| 113 EXPECT_EQ(20 - hot_point.y(), cursor_window_origin.y()); |
| 114 |
| 115 // Test with ui scale |
| 116 UpdateDisplay("400x600*0.5,400x600"); |
| 117 generator.MoveMouseToInHost(20, 30); |
| 118 |
| 119 hot_point = test_api.GetCursorHotPoint(); |
| 120 EXPECT_EQ("4,4", hot_point.ToString()); |
| 121 cursor_window_origin = test_api.GetCursorWindow()->bounds().origin(); |
| 122 EXPECT_EQ(20 - hot_point.x(), cursor_window_origin.x()); |
| 123 EXPECT_EQ(30 - hot_point.y(), cursor_window_origin.y()); |
| 124 |
| 125 // Test with rotation |
| 126 UpdateDisplay("400x600/r,400x600"); |
| 127 generator.MoveMouseToInHost(30, 40); |
| 128 |
| 129 hot_point = test_api.GetCursorHotPoint(); |
| 130 EXPECT_EQ("4,4", hot_point.ToString()); |
| 131 cursor_window_origin = test_api.GetCursorWindow()->bounds().origin(); |
| 132 EXPECT_EQ(30 - hot_point.x(), cursor_window_origin.x()); |
| 133 EXPECT_EQ(40 - hot_point.y(), cursor_window_origin.y()); |
| 134 } |
| 135 |
| 86 } // namsspace internal | 136 } // namsspace internal |
| 87 } // namespace ash | 137 } // namespace ash |
| OLD | NEW |